bdd-creature/classes/beastfile.lua

57 lines
1.5 KiB
Lua
Raw Permalink 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-06 21:00:05 +02:00
function BeastFile:new(folder, name, forceLevel)
2024-08-01 23:14:47 +02:00
self.filepath = folder .. "/" .. name
print("Loading " .. self.filepath)
2024-08-06 21:00:05 +02:00
self.datas = DataList(forceLevel)
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-12 13:08:29 +02:00
function BeastFile:forceName(name)
self.datas:forceName(name)
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
2024-08-06 21:00:05 +02:00
function BeastFile:getRawData()
local content = {}
self.datas:prepareJson({}, content, "Nothing")
return content[1]
end
2024-08-01 23:14:47 +02:00
return BeastFile