feat: ameliore la structure

This commit is contained in:
Kazhnuz 2024-08-06 21:09:49 +02:00
parent ce3d8fda5c
commit 34e7f0d97a

View file

@ -96,7 +96,8 @@ function DataList:reduce()
end
for key, holder in pairs(self.holders) do
self.reducedList[key] = holder:reduce(level)
--self.reducedList[key] = holder:reduce(level)
self:addToReducedList(key, holder:reduce(level))
end
if (self.forceLevel ~= nil) then
@ -104,6 +105,26 @@ function DataList:reduce()
end
end
function DataList:addToReducedList(key, data)
local to = commands.structs[key].to or key
local toSplited = utils.split(to, ".", true)
if (#toSplited == 1) then
self.reducedList[to] = data
else
local list = self.reducedList
for i, toPart in ipairs(toSplited) do
if (i == #toSplited) then
list[toPart] = data
else
if (list[toPart] == nil) then
list[toPart] = {}
end
list = list[toPart]
end
end
end
end
function DataList:prepareJson(simplercreatures, creatures, parent)
self:reduce()