From 34e7f0d97af1902135a674784d4488cd4e673610 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 6 Aug 2024 21:09:49 +0200 Subject: [PATCH] feat: ameliore la structure --- classes/datalist.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/classes/datalist.lua b/classes/datalist.lua index 96c81cb..f61390f 100644 --- a/classes/datalist.lua +++ b/classes/datalist.lua @@ -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()