bdd-creature/classes/datalist.lua
2024-08-01 23:56:04 +02:00

52 lines
No EOL
1.2 KiB
Lua

local Data = Object:extend()
local DataList = Object:extend()
function Data.fromLine(line)
line = utils.removeComment(line)
if (#line == 0) then
return nil
end
local command = utils.split(line, "|")
local datas = utils.split(utils.trim(command[1]), ";")
local args = {}
name = utils.trim(datas[1])
for i, v in ipairs(datas) do
if (i > 1) then
table.insert(args, utils.trim(v))
end
end
local level = 0
if (command[2] ~= nil) then
levelString = utils.trim(command[2]);
level = tonumber(levelString) or 0
end
return Data(name, commands.clean(args, name), level)
end
function Data:new(name, arguments, level)
self.name = name
self.arguments = arguments
self.level = level
end
function DataList:new()
self.list = {}
self.reducedList = {}
for key, value in pairs(commands.getDefaults()) do
table.insert(self.list, Data(key, value, 0))
end
end
function DataList:addLine(line)
table.insert(self.list, Data.fromLine(line))
end
function DataList:reduce()
--TODO
end
function DataList:prepareJson()
return self.list
end
return DataList