Модуль:Песочница/Pok

Материал из Space Station 14 Вики

Для документации этого модуля может быть создана страница Модуль:Песочница/Pok/doc

-- Загрузка данных
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")

local p = {}

-- Функция для поиска данных по ID
local function findDataById(itemData, id)
    if not itemData then return nil end
    for _, item in ipairs(itemData) do
        if item.id == id then
            return item
        end
    end
    return nil
end

-- Функция обработки содержимого
local function processNestedSelectors(children)
    if not children or #children == 0 then return "" end
    local results = {}

    for _, child in ipairs(children) do
        if child.id then
            results[#results + 1] = string.format("Обнаружен элемент: %s", child.id)
        elseif child["!type"] == "GroupSelector" then
            results[#results + 1] = processNestedSelectors(child.children)
        end
    end

    return table.concat(results, ", ")
end

-- Обработка контейнеров
local function getContainedOutput(id)
    local item = findDataById(itemData, id)
    if not item then return "ID не найден." end

    if item.EntityTableContainerFill and item.EntityTableContainerFill.containers then
        local containers = item.EntityTableContainerFill.containers
        
        if containers.entity_storage and containers.entity_storage.children then
            return processNestedSelectors(containers.entity_storage.children)
        end
    end

    return "Нет вложенных элементов."
end

-- Основная функция
function p.main(frame)
    local id = frame.args[1]
    if not id then return "Не указан ID." end
    return getContainedOutput(id)
end

return p