Модуль:Песочница/Pok: различия между версиями

Материал из Space Station 14 Вики
Нет описания правки
Нет описания правки
 
(не показано 298 промежуточных версий этого же участника)
Строка 1: Строка 1:
-- Загрузка данных
local p = {}
local itemData = mw.loadData("Модуль:IanComradeBot/prototypes/fills/Item.json/data")
local getArgs = require('Module:Arguments').getArgs


local p = {}
function p.main(frame)
    local args = getArgs(frame, { removeBlanks = false })
    local name = args[1] or ""
    local attributes = args[2] or ""
    if name == "" then
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
    end
    local ext = (args["ext"] or "png"):gsub("^%.", "")
    local namespace = args["namespace"] or "Файл"
    local max = tonumber(args["max"]) or 50
    local include_base = (args["base"] ~= "no")
 
    local found = {}


-- Функция для поиска данных по ID
     if include_base then
local function findDataById(itemData, id)
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
     if not itemData then return nil end
         if t and t.exists then
    for _, item in ipairs(itemData) do
             table.insert(found, "")
         if item.id == id then
             return item
         end
         end
     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
     for i = 1, max do
         if child.id then
         local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
            results[#results + 1] = string.format("Обнаружен элемент: %s", child.id)
        if t and t.exists then
        elseif child["!type"] == "GroupSelector" then
             table.insert(found, "-" .. i)
             results[#results + 1] = processNestedSelectors(child.children)
         end
         end
     end
     end


     return table.concat(results, ", ")
     if #found == 0 then
end
        return ""
    end


-- Обработка контейнеров
    local before = "[[" .. namespace .. ":" .. name
local function getContainedOutput(id)
     local after = "." .. ext .. "|" .. attributes .. "]]"
     local item = findDataById(itemData, id)
    if not item then return "ID не найден." end


     if item.EntityTableContainerFill and item.EntityTableContainerFill.containers then
     local parts = {}
        local containers = item.EntityTableContainerFill.containers
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
       
    for _, suf in ipairs(found) do
         if containers.entity_storage and containers.entity_storage.children then
         table.insert(parts, "<option>" .. suf .. "</option>")
            return processNestedSelectors(containers.entity_storage.children)
        end
     end
     end
    table.insert(parts, "</choose>")


     return "Нет вложенных элементов."
     return frame:preprocess(table.concat(parts, "\n"))
end
 
-- Основная функция
function p.main(frame)
    local id = frame.args[1]
    if not id then return "Не указан ID." end
    return getContainedOutput(id)
end
end


return p
return p

Текущая версия от 02:52, 17 марта 2026

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

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.main(frame)
    local args = getArgs(frame, { removeBlanks = false })
    local name = args[1] or ""
    local attributes = args[2] or ""
    if name == "" then
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
    end
    local ext = (args["ext"] or "png"):gsub("^%.", "") 
    local namespace = args["namespace"] or "Файл"
    local max = tonumber(args["max"]) or 50
    local include_base = (args["base"] ~= "no")

    local found = {}

    if include_base then
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
        if t and t.exists then
            table.insert(found, "")
        end
    end

    for i = 1, max do
        local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
        if t and t.exists then
            table.insert(found, "-" .. i)
        end
    end

    if #found == 0 then
        return ""
    end

    local before = "[[" .. namespace .. ":" .. name
    local after = "." .. ext .. "|" .. attributes .. "]]"

    local parts = {}
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
    for _, suf in ipairs(found) do
        table.insert(parts, "<option>" .. suf .. "</option>")
    end
    table.insert(parts, "</choose>")

    return frame:preprocess(table.concat(parts, "\n"))
end

return p