feat: ajout support fichiers groupes

This commit is contained in:
Kazhnuz 2024-08-12 13:08:29 +02:00
parent 5be98ee175
commit ed7004754d
9 changed files with 91 additions and 19 deletions

View file

@ -38,6 +38,10 @@ function BeastFile:loadMixin(mixin)
end end
end end
function BeastFile:forceName(name)
self.datas:forceName(name)
end
function BeastFile:prepareJson(simplercreatures, creatures, parent) function BeastFile:prepareJson(simplercreatures, creatures, parent)
assert(simplercreatures ~= nil) assert(simplercreatures ~= nil)
assert(creatures ~= nil) assert(creatures ~= nil)

View file

@ -67,7 +67,8 @@ function DataList.getHolder(key, value)
end end
function DataList:new(forceLevel) function DataList:new(forceLevel)
self.forceLevel = forceLevel self.forcedLevel = forceLevel
self.forcedName = nil
self.list = {} self.list = {}
self.holders = {} self.holders = {}
self.reducedList = {} self.reducedList = {}
@ -83,6 +84,10 @@ function DataList:addLine(line)
table.insert(self.list, RawData.fromLine(line)) table.insert(self.list, RawData.fromLine(line))
end end
function DataList:forceName(name)
self.forcedName = name
end
function DataList:reduce() function DataList:reduce()
local level = 0 local level = 0
local mode = "creature" local mode = "creature"
@ -96,8 +101,8 @@ function DataList:reduce()
end end
if (self.forceLevel ~= nil) then if (self.forcedLevel ~= nil) then
level = self.forceLevel level = self.forcedLevel
end end
for _, rawdata in ipairs(self.list) do for _, rawdata in ipairs(self.list) do
@ -111,8 +116,12 @@ function DataList:reduce()
self:addToReducedList(key, holder:reduce(level, mode)) self:addToReducedList(key, holder:reduce(level, mode))
end end
if (self.forceLevel ~= nil) then if (self.forcedLevel ~= nil) then
self.reducedList["level"] = self.forceLevel self.reducedList["level"] = self.forcedLevel
end
if (self.forcedName ~= nil) then
self.reducedList["name"] = self.forcedName
end end
end end

View file

@ -1,5 +1,6 @@
local FolderLoader = Object:extend() local FolderLoader = Object:extend()
local BeastFile = require "classes.beastfile" local BeastFile = require "classes.beastfile"
local GroupFile = require "classes.groupfile"
function FolderLoader.getAllDatas(value, bestiaires, creatures) function FolderLoader.getAllDatas(value, bestiaires, creatures)
local folderLoader = FolderLoader(value) local folderLoader = FolderLoader(value)
@ -21,6 +22,8 @@ function FolderLoader:new(value)
local file = utils.split(filename, ".", true) local file = utils.split(filename, ".", true)
if (file[2] == "beast") then if (file[2] == "beast") then
table.insert(self.files, BeastFile(self.folder, filename)) table.insert(self.files, BeastFile(self.folder, filename))
elseif (file[2] == "group") then
table.insert(self.files, GroupFile(self.folder, filename))
else else
print("[WARNING] Unknown extension " .. file[2] .. " for " .. filename) print("[WARNING] Unknown extension " .. file[2] .. " for " .. filename)
end end

64
classes/groupfile.lua Normal file
View file

@ -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

View file

@ -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

View file

@ -1,3 +0,0 @@
mixins;generique/canides
name;Chien // nom de la créature

View file

@ -1,3 +0,0 @@
mixins;generique/canides
name;Chien-Loup // nom de la créature
level;2

View file

@ -1,3 +0,0 @@
mixins;generique/canides
name;Loup
level;5

View file

@ -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;