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

мНет описания правки
мНет описания правки
Строка 77: Строка 77:
         for _, child in ipairs(tableData['!type:GroupSelector'].children) do
         for _, child in ipairs(tableData['!type:GroupSelector'].children) do
             if child["!type"] == "GroupSelector" then
             if child["!type"] == "GroupSelector" then
                 local weight = child.weight or "default"
                 local weight = tostring(child.weight or "default")
                 groupSelectors[weight] = groupSelectors[weight] or {}
                 groupSelectors[weight] = groupSelectors[weight] or {}
                 for _, subChild in ipairs(child.children) do
                 table.insert(groupSelectors[weight], child.children)
                    table.insert(groupSelectors[weight], subChild)
                end
            elseif child.id then
                -- Если это просто элемент с id
                result = result .. formatContent(child)
             end
             end
         end
         end
Строка 91: Строка 86:
         for weight, groups in pairs(groupSelectors) do
         for weight, groups in pairs(groupSelectors) do
             result = result .. string.format('<div class="together" id="%s">', weight)
             result = result .. string.format('<div class="together" id="%s">', weight)
             result = result .. getContentsOutput(groups)
             for _, group in ipairs(groups) do
                result = result .. getContentsOutput(group)
            end
             result = result .. '</div>'
             result = result .. '</div>'
         end
         end
Строка 109: Строка 106:


     local result = ''
     local result = ''
    -- Обработка StorageFill
     if item.StorageFill and item.StorageFill.contents then
     if item.StorageFill and item.StorageFill.contents then
         result = result .. getContentsOutput(item.StorageFill.contents)
         result = result .. getContentsOutput(item.StorageFill.contents)
    -- Обработка EntityTableContainerFill
     elseif item.EntityTableContainerFill and item.EntityTableContainerFill.containers then
     elseif item.EntityTableContainerFill and item.EntityTableContainerFill.containers then
         local containers = item.EntityTableContainerFill.containers
         local containers = item.EntityTableContainerFill.containers
        -- Обработка entity_storage
         if containers.entity_storage then
         if containers.entity_storage then
             local children = containers.entity_storage.children
             local children = containers.entity_storage.children
            -- Если есть `children`, обрабатываем их
             if children then
             if children then
                 for _, child in ipairs(children) do
                 for _, child in ipairs(children) do
Строка 120: Строка 125:
                         result = result .. getTableOutput(child.tableId)
                         result = result .. getTableOutput(child.tableId)
                     elseif child["!type"] == "GroupSelector" then
                     elseif child["!type"] == "GroupSelector" then
                        local groupSelectors = {}
                         -- Обработка GroupSelector
                        local weight = child.weight or "default"
                         result = result .. handleGroupSelector(child)
                        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
                     elseif child.id then
                         result = result .. formatContent(child)
                         result = result .. formatContent(child)
                     end
                     end
                 end
                 end
            end
            -- Если указан tableId
            if containers.entity_storage.tableId then
                result = result .. getTableOutput(containers.entity_storage.tableId)
             end
             end
         end
         end


         if containers.storagebase then
        -- Обработка storagebase
             local tableId = containers.storagebase.tableId
         if containers.storagebase and containers.storagebase.tableId then
            if tableId then
             result = result .. getTableOutput(containers.storagebase.tableId)
                result = result .. getTableOutput(tableId)
        end
             end
    end
 
    return result
end
 
-- Обработка GroupSelector
handleGroupSelector = function(groupSelector)
    local result = ''
    local groupSelectors = {}
    local weight = tostring(groupSelector.weight or "default")
   
    -- Группировка элементов по весу
    groupSelectors[weight] = groupSelectors[weight] or {}
    table.insert(groupSelectors[weight], groupSelector.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
         end
        result = result .. '</div>'
     end
     end