bdd-creature/classes/beastfile.lua

47 lines
1.3 KiB
Lua
Raw Normal View History

2024-08-01 23:14:47 +02:00
local BeastFile = Object:extend()
local DataList = require "classes.datalist"
2024-08-01 23:27:21 +02:00
local parseFile = require "libs.filereader"
2024-08-01 23:14:47 +02:00
function BeastFile:new(folder, name)
self.filepath = folder .. "/" .. name
print("Loading " .. self.filepath)
self.datas = DataList()
2024-08-01 23:27:21 +02:00
self:readLines()
end
function BeastFile:readLines()
2024-08-02 10:03:52 +02:00
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
2024-08-01 23:14:47 +02:00
end
2024-08-02 11:43:34 +02:00
function BeastFile:prepareJson(simplercreatures, creatures, parent)
assert(simplercreatures ~= nil)
assert(creatures ~= nil)
2024-08-02 11:43:34 +02:00
self.datas:prepareJson(simplercreatures, creatures, parent)
2024-08-01 23:14:47 +02:00
end
return BeastFile