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

мНет описания правки
мНет описания правки
Строка 89: Строка 89:
         local groupSelectors = {}
         local groupSelectors = {}


        -- Группируем элементы по weight
         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
Строка 97: Строка 98:
         end
         end


        -- Генерация div для каждой группы
         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)
             for _, group in ipairs(groups) do
             for _, group in ipairs(groups) do
                 result = result .. handleGroupSelector(group, false)
                 result = result .. handleGroupSelector(group)
             end
             end
             result = result .. '</div>'
             result = result .. '</div>'
Строка 163: Строка 165:


-- Обработка GroupSelector
-- Обработка GroupSelector
handleGroupSelector = function(groupSelector, parentDivOpened)
handleGroupSelector = function(groupSelector)
     local result = ''
     local result = ''
      
 
     -- Проверка на существование children
     if not groupSelector.children then
     if not groupSelector.children then
         return ""
         return ""
Строка 171: Строка 174:


     local weight = groupSelector.weight or "default"
     local weight = groupSelector.weight or "default"
   
 
     if not parentDivOpened then
     result = result .. string.format('<div class="together" id="%s">', weight)
        result = result .. string.format('<div class="together" id="%s">', weight)
    end


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


     return result
     return result