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

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


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


     -- Создание строки с вероятностью
     for _, child in ipairs(children) do
    local probString = ''
        if child["!type"] == "GroupSelector" then
    if nestedSelector.prob then
            local weight = tostring(child.weight or "default")
        local percentage = nestedSelector.prob * 100
            groupSelectors[weight] = groupSelectors[weight] or {}
         probString = string.format('<div class="probability">Шанс выпадения: %.2f%%</div>', percentage)
            table.insert(groupSelectors[weight], child.children)
        elseif child["!type"] == "NestedSelector" and child.tableId then
            -- Если у нас NestedSelector, добавляем его в группу "default"
            local weight = "default"
            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 для каждой группы
     local rollsString = ''
     for weight, groups in pairs(groupSelectors) do
    if nestedSelector.rolls and nestedSelector.rolls.range then
         result = result .. string.format('<div class="together" id="%s">', weight)
         local min, max = nestedSelector.rolls.range:match("(%d+),%s*(%d+)")
         for _, group in ipairs(groups) do
         min, max = tonumber(min), tonumber(max)
            for _, item in ipairs(group) do
        if min and max then
                if item.id then
            rollsString = string.format('<div class="rolls">Количество предметов: от %d до %d</div>', min, max)
                    result = result .. formatContent(item)
                elseif item["!type"] == "NestedSelector" then
                    result = result .. getTableOutput(item.tableId) -- Просто вставляем таблицу
                end
            end
         end
         end
        result = result .. '</div>'
     end
     end
    -- Обёртка в <div> с дополнительными данными
    result = result .. '<div class="nested-selector">'
    result = result .. probString .. rollsString
    result = result .. getTableOutput(tableId)
    result = result .. '</div>'


     return result
     return result