Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
-- | -- Функция для загрузки данных исследований из JSON-файла | ||
local function | local function loadResearchData() | ||
local | local content = mw.title.new("User:IanComradeBot/Песочница.json"):getContent() | ||
if not content or content == "" then | |||
error("JSON-файл пуст или отсутствует!") | |||
end | |||
local data = mw.text.jsonDecode(content) | |||
if not data then | |||
error("Ошибка парсинга JSON!") | |||
end | |||
return data | |||
end | end | ||
| Строка 67: | Строка 73: | ||
}) | }) | ||
local dataCache = | local dataCache = loadResearchData() | ||
if not | |||
return ' | if not dataCache or #dataCache == 0 then | ||
return cssLink .. '<div style="color:red;">Данные исследований не загружены или пусты.</div>' | |||
end | end | ||
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">' | ||
| Строка 90: | Строка 98: | ||
-- Генерация строк prerequisites и unlocks | -- Генерация строк prerequisites и unlocks | ||
local prerequisitesStr = generateTemplate(tech.technologyPrerequisites, "prerequisite") | local prerequisitesStr = "" | ||
local unlocksStr = generateTemplate(tech.recipeUnlocks, "unlock") | if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then | ||
prerequisitesStr = generateTemplate(tech.technologyPrerequisites, "prerequisite") | |||
end | |||
local unlocksStr = "" | |||
if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then | |||
unlocksStr = generateTemplate(tech.recipeUnlocks, "unlock") | |||
end | |||
-- Формируем вывод с использованием шаблона | -- Формируем вывод с использованием шаблона | ||
| Строка 110: | Строка 125: | ||
end | end | ||
out = out .. '</div>' | out = out .. '</div>' -- Закрываем блок research-group | ||
return out | return out | ||
else | else | ||