Модуль:Песочница/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 | ||
| Строка 19: | Строка 15: | ||
end | end | ||
return results | return results | ||
end | |||
-- Функция для поиска исследования по ID | |||
local function findResearchById(dataCache, id) | |||
for _, research in ipairs(dataCache) do | |||
if research.technology and research.technology.id == id then | |||
return research.technology | |||
end | |||
end | |||
return nil | |||
end | end | ||
| Строка 42: | Строка 48: | ||
}) | }) | ||
local dataCache = loadResearchData() | local dataCache = loadResearchData() | ||
local discipline = frame.args[1] or "" | |||
if discipline and discipline ~= "" then | |||
-- Инициализация строки вывода | |||
local out = cssLink .. '<div class="research-group">' | |||
-- Получаем список исследований по дисциплине | |||
local researches = findResearchByDiscipline(dataCache, discipline) | |||
if #researches == 0 then | |||
out = out .. '<div style="color:red;">Нет исследований для дисциплины "' .. discipline .. '"</div>' | |||
end | |||
for _, tech in ipairs(researches) do | |||
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина" | |||
local tierColor = tierColors[tech.tier] or "#FFFFFF" | |||
local iconPath = tech.icon and tech.icon.sprite or nil | |||
-- Основной блок исследования | |||
out = out .. '<div class="research" id="' .. tech.id .. '">' | |||
out = out .. frame:preprocess('<div class="research__images">[[Файл:{{#invoke:Entity Sprite|main|path|' .. iconPath .. '}}]]</div>') | |||
out = out .. frame:preprocess('<div class="research__name">{{#invoke:Ftl|main|translation|' .. tech.name .. '}}[[Файл:' .. tech.discipline .. '.png|16px|link=]]</div>') | |||
out = out .. '<div class="research__type">' | |||
out = out .. '<div>Уровень: <span style="color:' .. tierColor .. ';">' .. tech.tier .. '</span></div>' | |||
out = out .. '<div class="research__technology">' .. disciplineName .. '</div>' | |||
out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>' | |||
out = out .. '</div>' | |||
-- Блок необходимых исследований | |||
if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then | |||
out = out .. '<div class="research__technologies-unlocks">Разблокирует:' | |||
out = out .. '<ul>' | |||
for _, recipe in ipairs(tech.recipeUnlocks) do | |||
if recipe and recipe ~= "" then | |||
out = out .. frame:preprocess('<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' | |||
.. recipe .. '.png|' .. recipe | |||
.. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' | |||
.. recipe .. '}}</li>') | |||
end | |||
end | |||
out = out .. '</ul>' | |||
out = out .. '</div>' | |||
end | |||
out = out .. '</div>' | |||
end | end | ||
out = out .. '</div>' | out = out .. '</div>' | ||
return out | |||
else | |||
return cssLink .. '<div style="color:red;">Дисциплина "' .. discipline .. '" не найдена.</div>' | |||
end | end | ||
end | end | ||
return p | return p | ||