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()