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

Материал из Space Station 14 Вики
Нет описания правки
Нет описания правки
 
(не показана 371 промежуточная версия этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}
 
local getArgs = require('Module:Arguments').getArgs
-- Функция для загрузки данных исследований из JSON-файла
local function loadResearchData()
    return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/Песочница.json"):getContent())
end
 
-- Таблица для перевода названий дисциплин
local disciplineMapping = {
    Arsenal = "Арсенал",
    Industrial = "Промышленность",
    Experimental = "Экспериментальное",
    CivilianServices = "Обслуживание персонала"
}
 
-- Таблица для цветов по уровням
local tierColors = {
    [1] = "#54d554",
    [2] = "#ed9000",
    [3] = "#d72a2a"
}


function p.main(frame)
function p.main(frame)
local tierColor = tierColors[tech.tier] or "#FFFFFF"
    local args = getArgs(frame, { removeBlanks = false })
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
    local name = args[1] or ""
    local attributes = args[2] or ""
     -- Подключение CSS
    if name == "" then
     local cssLink = frame:extensionTag('templatestyles', '', {
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
        src = 'Шаблон:Research/styles.css'
     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 dataCache = loadResearchData()
     local found = {}


     -- Получаем ID и иконку из параметров
     if include_base then
    local researchId = frame.args[1] or ""
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
    local icon = frame.args[2] or ""
        if t and t.exists then
            table.insert(found, "")
        end
    end


     if researchId and researchId ~= "" then
     for i = 1, max do
         local out = cssLink .. '<div class="research-group">'
         local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
 
         if t and t.exists then
         -- Поиск исследования по ID
            table.insert(found, "-" .. i)
        local tech = nil
        for _, research in ipairs(dataCache) do
            if research.technology and research.technology.id == researchId then
                tech = research.technology
                break
            end
         end
         end
    end


        if not tech then
    if #found == 0 then
            out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>'
         return ""
         else
    end
            local tierColor = tierColors[tech.tier] or "#FFFFFF"
            local iconPath = icon ~= "" and icon or (tech.icon and tech.icon.sprite or nil)


            -- Формирование строки prerequisites
    local before = "[[" .. namespace .. ":" .. name
            local prerequisitesStr = ""
    local after = "." .. ext .. "|" .. attributes .. "]]"
            if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
                prerequisitesStr = '<ul>'
                for _, prerequisite in ipairs(tech.technologyPrerequisites) do
                    if prerequisite and prerequisite ~= "" then
                        prerequisitesStr = prerequisitesStr .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
                            .. prerequisite .. '.png|' .. prerequisite
                            .. '|Мета=32x32px,link=}}'
                            .. prerequisite .. '</li>'
                    end
                end
                prerequisitesStr = prerequisitesStr .. '</ul>'
            end


            -- Формирование строки unlocks
    local parts = {}
            local unlocksStr = ""
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
            if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
    for _, suf in ipairs(found) do
                unlocksStr = '<ul>'
        table.insert(parts, "<option>" .. suf .. "</option>")
                for _, recipe in ipairs(tech.recipeUnlocks) do
    end
                    if recipe and recipe ~= "" then
    table.insert(parts, "</choose>")
                        unlocksStr = unlocksStr .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
                            .. recipe .. '.png|' .. recipe
                            .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|'
                            .. recipe .. '}}</li>'
                    end
                end
                unlocksStr = unlocksStr .. '</ul>'
            end
 
            -- Шаблон для отображения блока исследования
            out = out .. frame:expandTemplate({
                title = 'Prototypes/Механика/Исследование',
                args = {
                    id = tech.id,
                    icon = iconPath,
                    name = tech.name,
                    discipline = tech.discipline,
                    tier = tech.tier,
                    tierColor = tierColor,
                    disciplineName = tech.discipline,
                    cost = tech.cost,
                    prerequisites = mw.getCurrentFrame():preprocess(prerequisitesStr),
                    unlocks = mw.getCurrentFrame():preprocess(unlocksStr)
                }
            })
        end


        return out
     return frame:preprocess(table.concat(parts, "\n"))
     else
        return cssLink .. '<div style="color:red;">Не указан ID исследования.</div>'
    end
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