Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
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 и unlocks | |||
local prerequisitesStr = generateTemplate(tech.technologyPrerequisites, "prerequisite") | |||
local unlocksStr = generateTemplate(tech.recipeUnlocks, "unlock") | |||
-- Формируем вывод с использованием шаблона | -- Формируем вывод с использованием шаблона | ||
out = out .. mw.getCurrentFrame():preprocess( | out = out .. mw.getCurrentFrame():preprocess( | ||
'{{Prototypes/Механика/Исследование' .. | |||
'|id=' .. tech.id .. | |||
'|icon=' .. iconPath .. | |||
'|name=' .. tech.name .. | |||
'|discipline=' .. tech.discipline .. | |||
'|tier=' .. tech.tier .. | |||
'|tierColor=' .. tierColor .. | |||
'|disciplineName=' .. disciplineName .. | |||
'|cost=' .. tech.cost .. | |||
'|prerequisites=' .. prerequisitesStr .. | |||
'|unlocks=' .. unlocksStr .. | |||
'}}' | |||
) | |||
end | end | ||
out = out .. '</div>' | |||
return out | return out | ||
else | else | ||