bdd-creature/classes/dataholders/listholder.lua
2024-08-02 08:34:54 +02:00

39 lines
No EOL
758 B
Lua

local ListHolder = Object:extend()
function ListHolder:new(key, datas)
self.key = key
self.datas = datas
self.list = {}
end
function ListHolder:applyCommand(command, args)
if (command == "") then
self:add(args)
elseif (command == "reset") then
self:reset()
elseif (command == "replace") then
self:replace(args)
end
end
function ListHolder:reset()
self.list = {}
end
function ListHolder:add(datas)
table.insert(self.list, datas)
end
function ListHolder:replace(datas)
for index, args in ipairs(self.list) do
if (args[1] == datas[1]) then
self.list[index] = args
end
end
end
function ListHolder:reduce(list, level)
return self.list
end
return ListHolder