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

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


local function processAllSelectors(children) end
local function processAllSelectors(children)
 
-- AllSelectors
function processAllSelectors(children)
     local result = ''
     local result = ''
     for _, child in ipairs(children) do
     for _, child in ipairs(children) do
Строка 94: Строка 91:
             result = result .. processAllSelectors(child.children)
             result = result .. processAllSelectors(child.children)
         elseif child["!type"] == "NestedSelector" and child.tableId then
         elseif child["!type"] == "NestedSelector" and child.tableId then
             local nestedRolls
             local nestedRolls = child.rolls and (child.rolls.value or (child.rolls.range and math.random(string.match(child.rolls.range, "(%d+),%s*(%d+)")))) or 1
            if child.rolls then
                if child.rolls.value then
                    nestedRolls = child.rolls.value
                elseif child.rolls.range then
                    local rangeParts = {string.match(child.rolls.range, "(%d+),%s*(%d+)")}
                    nestedRolls = math.random(tonumber(rangeParts[1]), tonumber(rangeParts[2]))
                else
                    nestedRolls = 1
                end
            else
                nestedRolls = 1
            end
             result = result .. getTableOutput(child.tableId, nestedRolls)
             result = result .. getTableOutput(child.tableId, nestedRolls)
         end
         end
Строка 126: Строка 111:
                 result = result .. processAllSelectors(selectedChild.children)
                 result = result .. processAllSelectors(selectedChild.children)
             elseif selectedChild["!type"] == "NestedSelector" and selectedChild.tableId then
             elseif selectedChild["!type"] == "NestedSelector" and selectedChild.tableId then
                 local nestedRolls
                 local nestedRolls = selectedChild.rolls and (selectedChild.rolls.value or (selectedChild.rolls.range and math.random(string.match(selectedChild.rolls.range, "(%d+),%s*(%d+)")))) or 1
                if selectedChild.rolls then
                    if selectedChild.rolls.value then
                        nestedRolls = selectedChild.rolls.value
                    elseif selectedChild.rolls.range then
                        local rangeParts = {string.match(selectedChild.rolls.range, "(%d+),%s*(%d+)")}
                        nestedRolls = math.random(tonumber(rangeParts[1]), tonumber(rangeParts[2]))
                    else
                        nestedRolls = 1
                    end
                else
                    nestedRolls = 1
                end
                 result = result .. getTableOutput(selectedChild.tableId, nestedRolls)
                 result = result .. getTableOutput(selectedChild.tableId, nestedRolls)
             end
             end
        end
    end
    return result
end
-- Функция обработки всех селекторов
local function processAllSelectors(children)
    local result = ''
    for _, child in ipairs(children) do
        if child.id then
            result = result .. formatContent(child)
        elseif child["!type"] == "GroupSelector" and child.children then
            result = result .. processNestedSelectors(child.children, 1)
        elseif child["!type"] == "AllSelector" and child.children then
            result = result .. processAllSelectors(child.children)
        elseif child["!type"] == "NestedSelector" and child.tableId then
            local nestedRolls
            if child.rolls then
                if child.rolls.value then
                    nestedRolls = child.rolls.value
                elseif child.rolls.range then
                    local rangeParts = {string.match(child.rolls.range, "(%d+),%s*(%d+)")}
                    nestedRolls = math.random(tonumber(rangeParts[1]), tonumber(rangeParts[2]))
                else
                    nestedRolls = 1
                end
            else
                nestedRolls = 1
            end
            result = result .. getTableOutput(child.tableId, nestedRolls)
         end
         end
     end
     end
Строка 191: Строка 134:
end
end


-- Формирование списка химии
-- Формирование списка содержащихся предметов или таблиц
local function getChemOutput(data, id)
local function getContainedOutput(data, id, wrapped)
     local item = findDataById(data, id)
     local item = findDataById(data, id)
     if not item then return '' end
     if not item then return '' end


     local solutions = item.SolutionContainerManager and item.SolutionContainerManager.solutions
     local result = ''
     if not solutions then return '' end
    if item.StorageFill and item.StorageFill.contents then
        result = result .. getContentsOutput(item.StorageFill.contents)
     elseif item.EntityTableContainerFill and item.EntityTableContainerFill.containers then
        local containers = item.EntityTableContainerFill.containers
        local tableId = containers.storagebase and containers.storagebase.tableId or containers.entity_storage and containers.entity_storage.tableId or containers.other_storage and containers.other_storage.tableId
        local rolls = containers.storagebase and containers.storagebase.rolls and containers.storagebase.rolls.value or containers.entity_storage and containers.entity_storage.rolls and containers.entity_storage.rolls.value or 1


    local result = '<ul class="1">'
        if tableId then
    for _, solution in pairs(solutions) do
            result = result .. getTableOutput(tableId, rolls)
         for _, reagent in ipairs(solution.reagents) do
         else
             result = result .. string.format('<li>[[Химия#chem_%s|%s]] (%d ед.)</li>', reagent.ReagentId, reagent.ReagentId, reagent.Quantity)
             result = result .. 'Таблица не найдена.'
         end
         end
     end
     end
    result = result .. '</ul>'
     return result
     return result
end
end
Строка 213: Строка 160:
     local mode = frame.args[1]
     local mode = frame.args[1]
     local id = frame.args[2]
     local id = frame.args[2]
     if not id then return 'Не указан ID.' end
     if not id then return 'Не указан ID.' end
     local data = loadData('User:IanComradeBot/prototypes/fills/Item.json', 'items')
     local data = loadData('User:IanComradeBot/prototypes/fills/Item.json', 'items')
     if not data then return 'Не удалось загрузить данные.' end
     if not data then return 'Не удалось загрузить данные.' end
 
     if mode == 'contained' then
     -- При режиме framing
    if mode == 'framing' then
        local subMode = frame.args[2]
        local id = frame.args[3]
   
        if not id then
            return 'Не указан ID для режима framing.'
        end
   
        if subMode == 'chem' then
            return frame:preprocess('{{СollapsibleMenu|' .. getChemOutput(data, id) .. '}}')
        elseif subMode == 'contained' then
            return frame:preprocess('{{СollapsibleMenu|' .. getContainedOutput(data, id, false) .. '}}')
        else
            return 'Неизвестный подрежим для framing: ' .. subMode
        end
    end
 
    -- При нормальном режиме
    if mode == 'chem' then
        return frame:preprocess(getChemOutput(data, id))
    elseif mode == 'contained' then
         return frame:preprocess(getContainedOutput(data, id, false))
         return frame:preprocess(getContainedOutput(data, id, false))
     else
     else