bdd-creature/classes/dataholders/listholder.lua

39 lines
753 B
Lua
Raw Normal View History

2024-08-02 08:34:54 +02:00
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] = datas
2024-08-02 08:34:54 +02:00
end
end
end
2024-08-02 08:38:54 +02:00
function ListHolder:reduce(level)
2024-08-02 08:34:54 +02:00
return self.list
end
return ListHolder