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

Материал из Space Station 14 Вики
мНет описания правки
Нет описания правки
 
(не показаны 424 промежуточные версии этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs


-- Функция для загрузки данных исследований из JSON-файла
function p.main(frame)
local function loadResearchData()
    local args = getArgs(frame, { removeBlanks = false })
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/Песочница.json"):getContent())
    local name = args[1] or ""
end
    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 = {}
local function findResearchByDiscipline(dataCache, discipline)
local results = {}
for _, research in ipairs(dataCache) do
if research.technology and research.technology.discipline == discipline then
table.insert(results, research.technology)
end
end
return results
end
 
-- Таблица для перевода названий дисциплин
local disciplineMapping = {
Arsenal = "Арсенал",
Industrial = "Промышленность",
Experimental = "Экспериментальное",
CivilianServices = "Обслуживание персонала"
}
 
-- Таблица для цветов по уровню
local tierColors = {
[1] = "#54d554",
[2] = "#ed9000",
[3] = "#d72a2a"
}
 
function p.main(frame)
-- Подключение CSS
local cssLink = frame:extensionTag('templatestyles', '', {
src = 'Шаблон:Research/styles.css'
})


local dataCache = loadResearchData()
    if include_base then
local discipline = frame.args[1] or ""
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
        if t and t.exists then
            table.insert(found, "")
        end
    end


if discipline then
    for i = 1, max do
-- Если это дисциплина, выводим все исследования данной группы
        local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
local researches = findResearchByDiscipline(dataCache, discipline)
        if t and t.exists then
            table.insert(found, "-" .. i)
        end
    end


for _, tech in ipairs(researches) do
    if #found == 0 then
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестное исследование"
        return ""
local tierColor = tierColors[tech.tier] or "#FFFFFF"
    end
local iconPath = tech.icon.sprite


out = out .. '<div class="research" id="' .. tech.discipline .. '">'
    local before = "[[" .. namespace .. ":" .. name
out = out .. '<div class="research__images">{{#invoke:Entity Sprite|main|path|' .. iconPath .. '}}</div>'
    local after = "." .. ext .. "|" .. attributes .. "]]"
out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. tech.discipline .. '.png|16px|link=]]</div>'
out = out .. '<div class="research__type">'
out = out .. '<div>Уровень: <span style="color:' .. tierColor .. ';">' .. tech.tier .. '</span></div>'
out = out .. '<div class="research__technology">' .. disciplineName .. '</div>'
out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>'
out = out .. '</div>'
out = out .. '</div>'
end


-- Блок необходимых исследований
    local parts = {}
if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
out = out .. '<div class="research__technologies-prerequisites">Необходимые исследования:'
    for _, suf in ipairs(found) do
out = out .. '<ul>'
        table.insert(parts, "<option>" .. suf .. "</option>")
    end
for _, prerequisiteId in ipairs(tech.technologyPrerequisites) do
    table.insert(parts, "</choose>")
local prerequisiteTech = findResearchById(dataCache, prerequisiteId)
if prerequisiteTech then
out = out .. '<li>' .. prerequisiteTech.name .. '</li>'
else
out = out .. '<li>Неизвестное исследование (' .. prerequisiteId .. ')</li>'
end
end
out = out .. '</ul>'
out = out .. '</div>'
else
out = out .. ''
end
-- Блок открываемых рецептов
if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
out = out .. '<div class="research__technologies-unlocks">Разблокирует:'
out = out .. '<ul>'
for _, recipe in ipairs(tech.recipeUnlocks) do
out = out .. '<li>' .. recipe .. '</li>'
end
out = out .. '</ul>'
out = out .. '</div>'
else
out = out .. '<div class="research__technologies-unlocks">Не разблокирует ничего.</div>'
end


return out
    return frame:preprocess(table.concat(parts, "\n"))
else
return cssLink .. '<div style="color:red;">Дисциплина "' .. discipline .. '" не найдена.</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