Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 3: | Строка 3: | ||
-- Функция для загрузки данных исследований из JSON-файла | -- Функция для загрузки данных исследований из JSON-файла | ||
local function loadResearchData() | local function loadResearchData() | ||
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/Песочница.json"):getContent()) | |||
end | end | ||
| Строка 40: | Строка 21: | ||
} | } | ||
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', '', { | ||
| Строка 47: | Строка 30: | ||
}) | }) | ||
local dataCache = loadResearchData() | local dataCache = loadResearchData() | ||
if | -- Получаем 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">' | local out = cssLink .. '<div class="research-group">' | ||
-- | -- Поиск исследования по ID | ||
local | local tech = nil | ||
for _, research in ipairs(dataCache) do | |||
if research.technology and research.technology.id == researchId then | |||
tech = research.technology | |||
break | |||
end | |||
end | end | ||
if not tech then | |||
out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>' | |||
else | |||
local tierColor = tierColors[tech.tier] or "#FFFFFF" | local tierColor = tierColors[tech.tier] or "#FFFFFF" | ||
local iconPath = tech.icon and tech.icon.sprite or | local iconPath = icon ~= "" and icon or (tech.icon and tech.icon.sprite or nil) | ||
-- Формирование строки prerequisites | -- Формирование строки prerequisites | ||
| Строка 73: | Строка 59: | ||
prerequisitesStr = '<ul>' | prerequisitesStr = '<ul>' | ||
for _, prerequisite in ipairs(tech.technologyPrerequisites) do | for _, prerequisite in ipairs(tech.technologyPrerequisites) do | ||
if prerequisite and prerequisite ~= "" then | if prerequisite and prerequisite ~= "" then | ||
prerequisitesStr = prerequisitesStr .. '<li>' .. | prerequisitesStr = prerequisitesStr .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' | ||
.. prerequisite .. '.png|' .. prerequisite | |||
.. '|Мета=32x32px,link=}}' | |||
.. prerequisite .. '</li>' | |||
end | end | ||
end | end | ||
| Строка 85: | Строка 74: | ||
unlocksStr = '<ul>' | unlocksStr = '<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 = unlocksStr .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' | ||
.. recipe .. '.png|' .. recipe | |||
.. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' | |||
.. recipe .. '}}</li>' | |||
end | end | ||
end | end | ||
| Строка 95: | Строка 84: | ||
end | 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 | |||
return | |||
else | else | ||
return cssLink .. '<div style="color:red;"> | return cssLink .. '<div style="color:red;">Не указан ID исследования.</div>' | ||
end | end | ||
end | end | ||
return p | return p | ||