Модуль:Prototypes/Хранилище/Предмет: различия между версиями

мНет описания правки
мНет описания правки
Строка 71: Строка 71:


     local groupSelector = tableData['!type:GroupSelector']
     local groupSelector = tableData['!type:GroupSelector']
     if not groupSelector or not groupSelector.children then
     if groupSelector and groupSelector.children then
         return 'Таблица не содержит элементов.'
         local result = ''
    end
        local groupSelectors = {}


    local result = ''
        -- Группируем элементы по weight
    local groupSelectors = {}
        for _, child in ipairs(groupSelector.children) do
            if child["!type"] == "GroupSelector" then
                local weight = child.weight or "default"
                groupSelectors[weight] = groupSelectors[weight] or {}
                table.insert(groupSelectors[weight], child.children)
            end
        end


    -- Группируем элементы по weight
        -- Генерация div для каждой группы
    for _, child in ipairs(groupSelector.children) do
        for weight, groups in pairs(groupSelectors) do
        if child["!type"] == "GroupSelector" then
            result = result .. string.format('<div class="together" id="%s">', weight)
             local weight = child.weight or "default"
             for _, group in ipairs(groups) do
             groupSelectors[weight] = groupSelectors[weight] or {}
                result = result .. getContentsOutput(group)
             table.insert(groupSelectors[weight], child.children)
             end
             result = result .. '</div>'
         end
         end
    end


    -- Генерация div для каждой группы
        return result
     for weight, groups in pairs(groupSelectors) do
     elseif tableData['!type:NestedSelector'] and tableData.children then
        result = result .. string.format('<div class="together" id="%s">', weight)
         return processNestedSelectors(tableData.children)
         for _, group in ipairs(groups) do
            result = result .. getContentsOutput(group)
        end
        result = result .. '</div>'
     end
     end


     return result
     return 'Таблица не содержит элементов.'
end
end


Строка 110: Строка 112:
         local containers = item.EntityTableContainerFill.containers
         local containers = item.EntityTableContainerFill.containers
         if containers.entity_storage then
         if containers.entity_storage then
             local tableId = containers.entity_storage.tableId
             local children = containers.entity_storage.children
             if tableId then
             if children then
                result = result .. getTableOutput(tableId)
                for _, child in ipairs(children) do
                    if child["!type"] == "NestedSelector" and child.tableId then
                        result = result .. getTableOutput(child.tableId)
                    elseif child["!type"] == "GroupSelector" then
                        local groupSelectors = {}
                        local weight = child.weight or "default"
                        groupSelectors[weight] = groupSelectors[weight] or {}
                        table.insert(groupSelectors[weight], child.children)
 
                        -- Генерация div для каждой группы
                        for weight, groups in pairs(groupSelectors) do
                            result = result .. string.format('<div class="together" id="%s">', weight)
                            for _, group in ipairs(groups) do
                                result = result .. getContentsOutput(group)
                            end
                            result = result .. '</div>'
                        end
                    elseif child.id then
                        result = result .. formatContent(child)
                    end
                end
             end
             end
         end
         end