9b1d92449e
Maintenant utilisation de plutôt deux fichier séparé, un contenant toutes les créatures et un autre contenant les bestiaires
47 lines
No EOL
1.3 KiB
Lua
47 lines
No EOL
1.3 KiB
Lua
local BeastFile = Object:extend()
|
|
local DataList = require "classes.datalist"
|
|
|
|
local parseFile = require "libs.filereader"
|
|
|
|
function BeastFile:new(folder, name)
|
|
self.filepath = folder .. "/" .. name
|
|
print("Loading " .. self.filepath)
|
|
self.datas = DataList()
|
|
|
|
self:readLines()
|
|
end
|
|
|
|
function BeastFile:readLines()
|
|
self:readAllLines(self.filepath)
|
|
end
|
|
|
|
function BeastFile:readAllLines(path)
|
|
parseFile(path, function (line) self:addLine(line) end)
|
|
end
|
|
|
|
function BeastFile:addLine(line)
|
|
if (utils.startswith(line, "mixin;") or utils.startswith(line, "mixins;")) then
|
|
local mixin = utils.split(line, ";", true)[2]
|
|
self:loadMixin(mixin)
|
|
elseif (utils.startswith(line, "type;") or utils.startswith(line, "types;")) then
|
|
local mixin = utils.split(line, ";", true)[2]
|
|
self:loadMixin("types/" .. mixin)
|
|
else
|
|
self.datas:addLine(line)
|
|
end
|
|
end
|
|
|
|
function BeastFile:loadMixin(mixin)
|
|
local testpath = "data/" .. utils.trim(mixin) .. ".beast"
|
|
if (testpath ~= nil) then
|
|
self:readAllLines(testpath)
|
|
end
|
|
end
|
|
|
|
function BeastFile:prepareJson(simplercreatures, creatures)
|
|
assert(simplercreatures ~= nil)
|
|
assert(creatures ~= nil)
|
|
self.datas:prepareJson(simplercreatures, creatures)
|
|
end
|
|
|
|
return BeastFile |