Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
-- Функция для загрузки данных исследований из JSON-файла | |||
local function loadResearchData() | local function loadResearchData() | ||
local jsonContent = mw.title.new("User:IanComradeBot/Песочница.json"):getContent() | local jsonContent = mw.title.new("User:IanComradeBot/Песочница.json"):getContent() | ||
| Строка 39: | Строка 40: | ||
} | } | ||
-- | -- Функция для обработки вывода | ||
function p.main(frame) | function p.main(frame) | ||
-- Подключение CSS | -- Подключение CSS | ||
| Строка 72: | Строка 47: | ||
}) | }) | ||
-- Загрузка данных из JSON | |||
local dataCache = loadResearchData() | local dataCache = loadResearchData() | ||
local discipline = frame.args[1] or "" | local discipline = frame.args[1] or "" | ||
if discipline and discipline ~= "" then | if discipline and discipline ~= "" then | ||
-- Инициализация строки вывода | |||
local out = cssLink .. '<div class="research-group">' | local out = cssLink .. '<div class="research-group">' | ||
| Строка 85: | Строка 62: | ||
end | end | ||
-- Перебор всех исследований и формирование их вывода | |||
for _, tech in ipairs(researches) do | for _, tech in ipairs(researches) do | ||
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина" | local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина" | ||
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 = tech.icon and tech.icon.sprite or "" | ||
-- Формирование строки 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>' .. mw.text.encode(prerequisite) .. '</li>' | |||
end | |||
end | |||
prerequisitesStr = prerequisitesStr .. '</ul>' | |||
end | |||
-- | -- Формирование строки unlocks | ||
local | 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>' .. mw.text.encode(recipe) .. '</li>' | |||
end | |||
end | |||
unlocksStr = unlocksStr .. '</ul>' | |||
end | |||
-- Формируем | -- Формируем строку с использованием шаблона | ||
local templateCall = '{{Prototypes/Механика/Исследование' .. | |||
'|id=' .. (tech.id or "") .. | |||
'|id=' .. tech.id .. | '|icon=' .. (iconPath or "") .. | ||
'|icon=' .. iconPath .. | '|name=' .. (tech.name or "") .. | ||
'|name=' .. tech.name .. | '|discipline=' .. (tech.discipline or "") .. | ||
'|discipline=' .. tech.discipline .. | '|tier=' .. (tech.tier or 0) .. | ||
'|tier=' .. tech.tier .. | '|tierColor=' .. (tierColor or "#FFFFFF") .. | ||
'|tierColor=' .. tierColor .. | '|disciplineName=' .. (disciplineName or "") .. | ||
'|disciplineName=' .. disciplineName .. | '|cost=' .. (tech.cost or 0) .. | ||
'|cost=' .. tech.cost .. | '|prerequisites=' .. (prerequisitesStr or "") .. | ||
'|prerequisites=' .. prerequisitesStr .. | '|unlocks=' .. (unlocksStr or "") .. | ||
'|unlocks=' .. unlocksStr .. | |||
'}}' | '}}' | ||
-- Печатаем шаблон в вывод | |||
out = out .. templateCall | |||
end | end | ||
out = out .. '</div>' | out = out .. '</div>' -- Закрываем div | ||
return out | return out | ||
else | else | ||