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

мНет описания правки
Нет описания правки
Строка 22: Строка 22:


function p.main(frame)
function p.main(frame)
local tierColor = tierColors[tech.tier] or "#FFFFFF"
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
     -- Подключение CSS
     -- Подключение CSS
     local cssLink = frame:extensionTag('templatestyles', '', {
     local cssLink = frame:extensionTag('templatestyles', '', {
Строка 36: Строка 39:
         local out = cssLink .. '<div class="research-group">'
         local out = cssLink .. '<div class="research-group">'


-- Поиск исследования по ID
        -- Поиск исследования по ID
local tech = nil
        local tech = nil
for _, research in ipairs(dataCache) do
        for _, research in ipairs(dataCache) do
    if research.technology and research.technology.id == researchId then
            if research.technology and research.technology.id == researchId then
        tech = research.technology
                tech = research.technology
        break
                break
    end
            end
end
        end
 
if not tech then
        if not tech then
    out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>'
            out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>'
else
        else
    local tierColor = tierColors[tech.tier] or "#FFFFFF"
            local tierColor = tierColors[tech.tier] or "#FFFFFF"
    local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
             local iconPath = icon ~= "" and icon or (tech.icon and tech.icon.sprite or nil)
             local iconPath = icon ~= "" and icon or (tech.icon and tech.icon.sprite or nil)


             -- Формирование строки prerequisites
             -- Формирование строки необходимых исследований
             local prerequisitesStr = ""
             local prerequisites = ""
             if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
             if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
                 prerequisitesStr = '<ul>'
                 prerequisites = '<ul>'
                 for _, prerequisite in ipairs(tech.technologyPrerequisites) do
                 for _, prerequisiteId in ipairs(tech.technologyPrerequisites) do
                     if prerequisite and prerequisite ~= "" then  
                     if prerequisiteId and prerequisiteId ~= "" then  
                         prerequisitesStr = prerequisitesStr .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
                         -- Находим название исследования по ID
                            .. prerequisite .. '.png|' .. prerequisite
                        local prerequisiteName = ""
                            .. '|Мета=32x32px,link=}}'
                        for _, research in ipairs(dataCache) do
                            .. prerequisite .. '</li>'
                            if research.technology and research.technology.id == prerequisiteId then
                                prerequisiteName = research.technology.name
                                break
                            end
                        end
 
                        -- Если название найдено, выводим его
                        if prerequisiteName ~= "" then
                            prerequisites = prerequisites .. '<li>{{#invoke:Ftl|main|translation|'.. prerequisiteName .. '}}</li>'
                        end
                     end
                     end
                 end
                 end
                 prerequisitesStr = prerequisitesStr .. '</ul>'
                 prerequisites = prerequisites .. '</ul>'
             end
             end


             -- Формирование строки unlocks
             -- Формирование строки открываемых исследований
             local unlocksStr = ""
             local unlocks = ""
             if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
             if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
                 unlocksStr = '<ul>'
                 unlocks = '<ul>'
                 for _, recipe in ipairs(tech.recipeUnlocks) do
                 for _, recipe in ipairs(tech.recipeUnlocks) do
                     if recipe and recipe ~= "" then  
                     if recipe and recipe ~= "" then  
                         unlocksStr = unlocksStr .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'  
                         unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'  
                             .. recipe .. '.png|' .. recipe  
                             .. recipe .. '.png|' .. recipe  
                             .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|'  
                             .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|'  
Строка 79: Строка 90:
                     end
                     end
                 end
                 end
                 unlocksStr = unlocksStr .. '</ul>'
                 unlocks = unlocks .. '</ul>'
             end
             end


             -- Шаблон для отображения блока исследования
             -- Шаблон для отображения блока исследования
            local templateArgs = {
                id = tech.id,
                icon = iconPath,
                name = tech.name,
                discipline = tech.discipline,
                tier = tech.tier,
                tierColor = tierColor,
                disciplineName = tech.discipline,
                cost = tech.cost,
                unlocks = unlocks
            }
            -- Добавление prerequisites только если он существует
            if prerequisites ~= "" then
                templateArgs.prerequisites = prerequisites
            end
             out = out .. frame:expandTemplate({
             out = out .. frame:expandTemplate({
                 title = 'Prototypes/Механика/Исследование',
                 title = 'Prototypes/Механика/Исследование',
                 args = {
                 args = templateArgs
                    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
end
 
         return mw.getCurrentFrame():preprocess(out)
         return out
     else
     else
         return cssLink .. '<div style="color:red;">Не указан ID исследования.</div>'
         return cssLink .. '<div style="color:red;">Не указан ID исследования.</div>'