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

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


local function processAllSelectors(children) end
local function processAllSelectors(children) end
-- Обработка таблиц
local function getTableOutput(tableId, rolls)
    local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json', 'selectors')
    local tableData = findDataById(allSelectors, tableId)
    local children = tableData and (tableData['!type:GroupSelector'] and tableData['!type:GroupSelector'].children or tableData['!type:AllSelector'] and tableData['!type:AllSelector'].children)
    if not children then return 'Таблица не содержит элементов.' end
    if tableData['!type:AllSelector'] then
        return processAllSelectors(children)
    else
        return processNestedSelectors(children, rolls)
    end
end


-- AllSelectors
-- AllSelectors
Строка 161: Строка 146:
end
end


-- Формирование списка содержащихся предметов или таблиц
-- Функция обработки всех селекторов
local function getContainedOutput(data, id, wrapped)
local function processAllSelectors(children)
    local item = findDataById(data, id)
    local result = ''
     if not item then return '' end
    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
     return result
end


     local result = ''
-- Обработка таблиц
     if item.StorageFill and item.StorageFill.contents then
local function getTableOutput(tableId, rolls)
        result = result .. getContentsOutput(item.StorageFill.contents)
     local allSelectors = loadData('User:IanComradeBot/prototypes/AllSelector.json', 'selectors')
     elseif item.EntityTableContainerFill and item.EntityTableContainerFill.containers then
     local tableData = findDataById(allSelectors, tableId)
        local containers = item.EntityTableContainerFill.containers
     local children = tableData and (tableData['!type:GroupSelector'] and tableData['!type:GroupSelector'].children or tableData['!type:AllSelector'] and tableData['!type:AllSelector'].children)
        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
    if not children then return 'Таблица не содержит элементов.' end
                  or containers.entity_storage and containers.entity_storage.rolls and containers.entity_storage.rolls.value
                  or 1


        if tableId then
    if tableData['!type:AllSelector'] then
            result = result .. getTableOutput(tableId, rolls)
        return processAllSelectors(children)
        else
    else
            result = result .. 'Таблица не найдена.'
         return processNestedSelectors(children, rolls)
         end
     end
     end
    return result
end
end