diff --git a/classes/beastfile.lua b/classes/beastfile.lua index c5d34bd..fa7ce28 100644 --- a/classes/beastfile.lua +++ b/classes/beastfile.lua @@ -38,6 +38,10 @@ function BeastFile:loadMixin(mixin) end end +function BeastFile:forceName(name) + self.datas:forceName(name) +end + function BeastFile:prepareJson(simplercreatures, creatures, parent) assert(simplercreatures ~= nil) assert(creatures ~= nil) diff --git a/classes/datalist.lua b/classes/datalist.lua index 7db1f34..a95b2dc 100644 --- a/classes/datalist.lua +++ b/classes/datalist.lua @@ -67,7 +67,8 @@ function DataList.getHolder(key, value) end function DataList:new(forceLevel) - self.forceLevel = forceLevel + self.forcedLevel = forceLevel + self.forcedName = nil self.list = {} self.holders = {} self.reducedList = {} @@ -83,6 +84,10 @@ function DataList:addLine(line) table.insert(self.list, RawData.fromLine(line)) end +function DataList:forceName(name) + self.forcedName = name +end + function DataList:reduce() local level = 0 local mode = "creature" @@ -96,8 +101,8 @@ function DataList:reduce() end - if (self.forceLevel ~= nil) then - level = self.forceLevel + if (self.forcedLevel ~= nil) then + level = self.forcedLevel end for _, rawdata in ipairs(self.list) do @@ -111,8 +116,12 @@ function DataList:reduce() self:addToReducedList(key, holder:reduce(level, mode)) end - if (self.forceLevel ~= nil) then - self.reducedList["level"] = self.forceLevel + if (self.forcedLevel ~= nil) then + self.reducedList["level"] = self.forcedLevel + end + + if (self.forcedName ~= nil) then + self.reducedList["name"] = self.forcedName end end diff --git a/classes/folderloader.lua b/classes/folderloader.lua index 82a5f5d..78d3fed 100644 --- a/classes/folderloader.lua +++ b/classes/folderloader.lua @@ -1,5 +1,6 @@ local FolderLoader = Object:extend() local BeastFile = require "classes.beastfile" +local GroupFile = require "classes.groupfile" function FolderLoader.getAllDatas(value, bestiaires, creatures) local folderLoader = FolderLoader(value) @@ -21,6 +22,8 @@ function FolderLoader:new(value) local file = utils.split(filename, ".", true) if (file[2] == "beast") then table.insert(self.files, BeastFile(self.folder, filename)) + elseif (file[2] == "group") then + table.insert(self.files, GroupFile(self.folder, filename)) else print("[WARNING] Unknown extension " .. file[2] .. " for " .. filename) end diff --git a/classes/groupfile.lua b/classes/groupfile.lua new file mode 100644 index 0000000..ab51810 --- /dev/null +++ b/classes/groupfile.lua @@ -0,0 +1,64 @@ +local GroupFile = Object:extend() +local BeastFile = require "classes.beastfile" + +local parseFile = require "libs.filereader" + +function GroupFile:new(folder, name, forceLevel) + self.filepath = folder .. "/" .. name + print("Loading " .. self.filepath) + self.datas = {} + + self:readLines() +end + +function GroupFile:readLines() + self:readAllLines(self.filepath) +end + +function GroupFile:readAllLines(path) + parseFile(path, function (line) self:addLine(line) end) +end + +function GroupFile:addLine(line) + if (utils.startswith(line, "beast;") or utils.startswith(line, "beasts;")) then + local datas = utils.split(line, ";", true) + self:addBeast(datas[2], datas[3], datas[4], self:getMixins(datas)) + end +end + +function GroupFile:getMixins(datas) + if (#datas < 4) then + return {} + else + local list = {} + for index, value in ipairs(datas) do + if (index > 4) then + table.insert(list, value) + end + end + return list + end +end + +function GroupFile:addBeast(name, level, baseFile, mixins) + local beast = BeastFile("data", baseFile .. ".beast", tonumber(level)) + if (#mixins > 0) then + for index, mixin in ipairs(mixins) do + beast:loadMixin(mixin) + end + end + + beast:forceName(name) + table.insert(self.datas, beast) +end + +function GroupFile:prepareJson(simplercreatures, creatures, parent) + assert(simplercreatures ~= nil) + assert(creatures ~= nil) + --self.datas:prepareJson(simplercreatures, creatures, parent) + for _, beast in ipairs(self.datas) do + beast:prepareJson(simplercreatures, creatures, parent) + end +end + +return GroupFile \ No newline at end of file diff --git a/data/animaux/canides.group b/data/animaux/canides.group new file mode 100644 index 0000000..d2dee36 --- /dev/null +++ b/data/animaux/canides.group @@ -0,0 +1,6 @@ +beast;Chien;0;generique/canides +beast;Petit Chien;0;generique/canides;bases/tailles/petit +beast;Chien-Loup;3;generique/canides +beast;Loup;6;generique/canides +beast;Chef-Loup;7;generique/canides +beast;Loup Géant;9;generique/canides;bases/tailles/grand \ No newline at end of file diff --git a/data/animaux/chien.beast b/data/animaux/chien.beast deleted file mode 100644 index aa813cd..0000000 --- a/data/animaux/chien.beast +++ /dev/null @@ -1,3 +0,0 @@ -mixins;generique/canides - -name;Chien // nom de la créature \ No newline at end of file diff --git a/data/animaux/chienloup.beast b/data/animaux/chienloup.beast deleted file mode 100644 index c1dfda3..0000000 --- a/data/animaux/chienloup.beast +++ /dev/null @@ -1,3 +0,0 @@ -mixins;generique/canides -name;Chien-Loup // nom de la créature -level;2 \ No newline at end of file diff --git a/data/animaux/loup.beast b/data/animaux/loup.beast deleted file mode 100644 index 6ca3ce1..0000000 --- a/data/animaux/loup.beast +++ /dev/null @@ -1,3 +0,0 @@ -mixins;generique/canides -name;Loup -level;5 \ No newline at end of file diff --git a/data/animaux/loupchef.beast b/data/animaux/loupchef.beast deleted file mode 100644 index 5ae7a68..0000000 --- a/data/animaux/loupchef.beast +++ /dev/null @@ -1,5 +0,0 @@ -mixins;animaux/loup -name;Loup en Chef // nom de la créature -level;6 - -skill;Chef de meute;Peut ajouter +1 dégat brut à une attaque par loup présent, mais perdra 50% pour esquiver et encaisser au tour suivant. Cinq tours de cooldown; \ No newline at end of file