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

Нет описания правки
Полностью удалено содержимое страницы
Метка: очистка
 
(не показано 345 промежуточных версий этого же участника)
Строка 1: Строка 1:
local p = {}


-- Функция для загрузки данных исследований из 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)
local tierColor = tierColors[tech.tier] or "#FFFFFF"
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
    -- Подключение CSS
    local cssLink = frame:extensionTag('templatestyles', '', {
        src = 'Шаблон:Research/styles.css'
    })
    local dataCache = loadResearchData()
    -- Получаем ID и иконку из параметров
    local researchId = frame.args[1] or ""
    local icon = frame.args[2] or ""
    if researchId and researchId ~= "" then
        local out = cssLink .. '<div class="research-group">'
        -- Поиск исследования по ID
        local tech = nil
        for _, research in ipairs(dataCache) do
            if research.technology and research.technology.id == researchId then
                tech = research.technology
                break
            end
        end
        if not tech then
            out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>'
        else
            local tierColor = tierColors[tech.tier] or "#FFFFFF"
            local iconPath = icon ~= "" and icon or (tech.icon and tech.icon.sprite or nil)
            -- Формирование строки prerequisites
            local prerequisitesStr = ""
            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 unlocksStr = ""
            if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
                unlocksStr = '<ul>'
                for _, recipe in ipairs(tech.recipeUnlocks) do
                    if recipe and recipe ~= "" then
                        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
    else
        return cssLink .. '<div style="color:red;">Не указан ID исследования.</div>'
    end
end
return p