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

мНет описания правки
Нет описания правки
Строка 31: Строка 31:
     [3] = "#d72a2a"
     [3] = "#d72a2a"
}
}
-- Универсальная функция для генерации списков
local function generateTemplate(list, templateType)
    if not list or #list == 0 then
        return ""
    end
    local result = "<ul>"
    for _, entry in ipairs(list) do
        if entry and entry ~= "" then
            if templateType == "prerequisite" then
                result = result .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
                    .. entry .. '.png|' .. entry
                    .. '|Мета=32x32px,link=}} '
                    .. entry .. '</li>'
            elseif templateType == "unlock" then
                result = result .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
                    .. entry .. '.png|' .. entry
                    .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|'
                    .. entry .. '}}</li>'
            end
        end
    end
    result = result .. "</ul>"
    return result
end


function p.main(frame)
function p.main(frame)
Строка 42: Строка 69:


     if discipline and discipline ~= "" then
     if discipline and discipline ~= "" then
        -- Инициализация строки вывода
         local out = cssLink .. '<div class="research-group">'
         local out = cssLink .. '<div class="research-group">'


Строка 57: Строка 83:
             local iconPath = tech.icon and tech.icon.sprite or nil
             local iconPath = tech.icon and tech.icon.sprite or nil


-- Формирование строки prerequisites
            -- Генерация строк prerequisites и unlocks
local prerequisitesStr = ""
            local prerequisitesStr = generateTemplate(tech.technologyPrerequisites, "prerequisite")
if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
            local unlocksStr = generateTemplate(tech.recipeUnlocks, "unlock")
    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 .. mw.getCurrentFrame():preprocess(
             out = out .. mw.getCurrentFrame():preprocess(
    '{{Prototypes/Механика/Исследование' ..
                '{{Prototypes/Механика/Исследование' ..
    '|id=' .. tech.id ..
                '|id=' .. tech.id ..
        '|icon=' .. iconPath ..
                '|icon=' .. iconPath ..
        '|name=' .. tech.name ..
                '|name=' .. tech.name ..
        '|discipline=' .. tech.discipline ..
                '|discipline=' .. tech.discipline ..
        '|tier=' .. tech.tier ..
                '|tier=' .. tech.tier ..
        '|tierColor=' .. tierColor ..
                '|tierColor=' .. tierColor ..
        '|disciplineName=' .. disciplineName ..
                '|disciplineName=' .. disciplineName ..
        '|cost=' .. tech.cost ..
                '|cost=' .. tech.cost ..
        '|prerequisites=' .. prerequisitesStr ..
                '|prerequisites=' .. prerequisitesStr ..
        '|unlocks=' .. unlocksStr ..
                '|unlocks=' .. unlocksStr ..
        '}}'
                '}}'
    )
            )
         end
         end
          
 
         out = out .. '</div>'
         return out
         return out
     else
     else