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

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


-- Функции как локальные переменные
-- Функции как локальные переменные
local loadData, findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput
local loadData, findDataById, formatContent, getContentsOutput, processNestedSelectors, getTableOutput, getContainedOutput, getChemOutput, handleGroupSelector, handleAllSelector, handleNestedSelector


-- Функция для загрузки данных
-- Функция для загрузки данных
Строка 70: Строка 70:
             result = result .. formatContent(child)
             result = result .. formatContent(child)
         elseif child["!type"] == "NestedSelector" and child.tableId then
         elseif child["!type"] == "NestedSelector" and child.tableId then
             result = result .. handleNestedSelector(child, true)
             result = result .. handleNestedSelector(child)
         elseif child["!type"] == "GroupSelector" then
         elseif child["!type"] == "GroupSelector" then
             result = result .. handleGroupSelector(child)
             result = result .. handleGroupSelector(child)
Строка 86: Строка 86:


     if tableData['!type:GroupSelector'] and tableData['!type:GroupSelector'].children then
     if tableData['!type:GroupSelector'] and tableData['!type:GroupSelector'].children then
         local result = ''
         return handleGroupSelector(tableData['!type:GroupSelector'])
        local groupSelectors = {}
 
        -- Группируем элементы по weight
        for _, child in ipairs(tableData['!type:GroupSelector'].children) do
            if child["!type"] == "GroupSelector" then
                local weight = tostring(child.weight or "default")
                groupSelectors[weight] = groupSelectors[weight] or {}
                table.insert(groupSelectors[weight], child)
            end
        end
 
        -- Генерация 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 .. handleGroupSelector(group)
            end
            result = result .. '</div>'
        end
 
        return result
     elseif tableData['!type:AllSelector'] and tableData['!type:AllSelector'].children then
     elseif tableData['!type:AllSelector'] and tableData['!type:AllSelector'].children then
         return processNestedSelectors(tableData['!type:AllSelector'].children)
         return processNestedSelectors(tableData['!type:AllSelector'].children)
Строка 138: Строка 117:
                 for _, child in ipairs(children) do
                 for _, child in ipairs(children) do
                     if child["!type"] == "NestedSelector" and child.tableId then
                     if child["!type"] == "NestedSelector" and child.tableId then
                         result = result .. handleNestedSelector(child, false)
                         result = result .. handleNestedSelector(child)
                     elseif child["!type"] == "GroupSelector" then
                     elseif child["!type"] == "GroupSelector" then
                         result = result .. handleGroupSelector(child)
                         result = result .. handleGroupSelector(child)
Строка 172: Строка 151:
         return ""
         return ""
     end
     end
    local weight = groupSelector.weight or "default"
    result = result .. string.format('<div class="together" id="%s">', weight)


     for _, child in ipairs(groupSelector.children) do
     for _, child in ipairs(groupSelector.children) do
Строка 181: Строка 156:
             result = result .. handleGroupSelector(child)
             result = result .. handleGroupSelector(child)
         elseif child["!type"] == "AllSelector" then
         elseif child["!type"] == "AllSelector" then
            result = result .. string.format('<div class="AllSelector">')
             result = result .. handleAllSelector(child)
             result = result .. handleAllSelector(child)
            result = result .. '</div>'
         elseif child.id then
         elseif child.id then
             result = result .. formatContent(child)
             result = result .. formatContent(child)
Строка 190: Строка 163:
         end
         end
     end
     end
   
    result = result .. '</div>'


     return result
     return result
Строка 203: Строка 174:
     for _, child in ipairs(allSelector.children) do
     for _, child in ipairs(allSelector.children) do
         if child["!type"] == "NestedSelector" and child.tableId then
         if child["!type"] == "NestedSelector" and child.tableId then
             result = result .. handleNestedSelector(child, true)
             result = result .. handleNestedSelector(child)
         elseif child.id then
         elseif child.id then
             result = result .. formatContent(child)
             result = result .. formatContent(child)
Строка 213: Строка 184:


-- Обработка NestedSelector
-- Обработка NestedSelector
handleNestedSelector = function(nestedSelector, wrap)
handleNestedSelector = function(nestedSelector)
     local result = ''
     local result = ''
     local tableId = nestedSelector.tableId
     local tableId = nestedSelector.tableId
Строка 228: Строка 199:
     end
     end


     -- Обёртка div с классами, если wrap включен
     -- Обёртка div с классами
     if wrap then
     local classString = table.concat(classes, ' ')
        local classString = table.concat(classes, ' ')
    result = result .. string.format('<div class="%s">', classString)
        result = result .. string.format('<div class="%s">', classString)
    end
 
     result = result .. getTableOutput(tableId)
     result = result .. getTableOutput(tableId)
 
     result = result .. '</div>'
     if wrap then
        result = result .. '</div>'
    end


     return result
     return result