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

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


-- Обработка NestedSelector
-- Обработка NestedSelector
processNestedSelectors = function(children)
handleNestedSelector = function(nestedSelector)
     local result = ''
     local result = ''
     local groupSelectors = {}
     local tableId = nestedSelector.tableId
    if not tableId then return result end


     for _, child in ipairs(children) do
     -- Генерация классов для div
        if child["!type"] == "GroupSelector" then
    local classes = {}
            local weight = tostring(child.weight or "default")
 
            groupSelectors[weight] = groupSelectors[weight] or {}
    if nestedSelector.rolls and nestedSelector.rolls.range then
            table.insert(groupSelectors[weight], child.children)
        table.insert(classes, 'rolls-' .. tostring(nestedSelector.rolls.range):gsub(',', '-'))
        elseif child["!type"] == "NestedSelector" and child.tableId then
    end
            -- Если у нас NestedSelector, добавляем его в группу "default"
    if nestedSelector.prob then
            local weight = "default"
        table.insert(classes, 'prob-' .. tostring(math.floor(nestedSelector.prob * 100)) .. 'p')
            groupSelectors[weight] = groupSelectors[weight] or {}
            table.insert(groupSelectors[weight], { child }) -- Оборачиваем, чтобы было в списке
        elseif child.id then
            -- Обычные элементы тоже в "default"
            local weight = "default"
            groupSelectors[weight] = groupSelectors[weight] or {}
            table.insert(groupSelectors[weight], { child })
        end
     end
     end


     -- Генерация div для каждой группы
     -- Обёртка div с классами
     for weight, groups in pairs(groupSelectors) do
     local classString = table.concat(classes, ' ')
        result = result .. string.format('<div class="together" id="%s">', weight)
    result = result .. string.format('<div class="%s">', classString)
        for _, group in ipairs(groups) do
    result = result .. getTableOutput(tableId)
            for _, item in ipairs(group) do
    result = result .. '</div>'
                if item.id then
                    result = result .. formatContent(item)
                elseif item["!type"] == "NestedSelector" then
                    result = result .. getTableOutput(item.tableId) -- Просто вставляем таблицу
                end
            end
        end
        result = result .. '</div>'
    end


     return result
     return result