Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
-- Загрузка данных | -- Загрузка данных | ||
local p = {} | local p = {} | ||
| Строка 20: | Строка 18: | ||
function p.main(frame) | function p.main(frame) | ||
local input = frame.args[1] or "" | local input = frame.args[1] or "" | ||
local manualIcon = frame.args[2] or "" | local manualIcon = frame.args[2] or "" | ||
local out = "" | local out = "" | ||
if input == "" then | if input == "" then | ||
return '<div style="color:red;">Не указан идентификатор исследования или дисциплина.</div>' | return '<div style="color:red;">Не указан идентификатор исследования или дисциплина.</div>' | ||
end | end | ||
-- Получение актуальных данных | |||
local researchData = mw.loadData("Модуль:IanComradeBot/prototypes/research.json/data") | |||
-- Если первый параметр соответствует дисциплине, работаем в режиме категории | -- Если первый параметр соответствует дисциплине, работаем в режиме категории | ||
if disciplineMapping[input] then | if disciplineMapping[input] then | ||
local found = false | local found = false | ||
for _, research in ipairs( | for _, research in ipairs(researchData) do | ||
if research.technology and research.technology.discipline == input then | if research.technology and research.technology.discipline == input then | ||
found = true | found = true | ||
| Строка 39: | Строка 39: | ||
local tierColor = tierColors[tech.tier] or "#FFFFFF" | local tierColor = tierColors[tech.tier] or "#FFFFFF" | ||
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина" | local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина" | ||
-- Формирование строки необходимых исследований (prerequisites) | -- Формирование строки необходимых исследований (prerequisites) | ||
local prerequisites = "" | local prerequisites = "" | ||
| Строка 47: | Строка 47: | ||
if prerequisiteId and prerequisiteId ~= "" then | if prerequisiteId and prerequisiteId ~= "" then | ||
local prerequisiteName = "" | local prerequisiteName = "" | ||
for _, r in ipairs( | for _, r in ipairs(researchData) do | ||
if r.technology and r.technology.id == prerequisiteId then | if r.technology and r.technology.id == prerequisiteId then | ||
prerequisiteName = r.technology.name | prerequisiteName = r.technology.name | ||
| Строка 60: | Строка 60: | ||
prerequisites = prerequisites .. '</ul>' | prerequisites = prerequisites .. '</ul>' | ||
end | end | ||
-- Формирование строки открываемых исследований (unlocks) | -- Формирование строки открываемых исследований (unlocks) | ||
local unlocks = "" | local unlocks = "" | ||
| Строка 67: | Строка 67: | ||
for _, recipe in ipairs(tech.recipeUnlocks) do | for _, recipe in ipairs(tech.recipeUnlocks) do | ||
if recipe and recipe ~= "" then | if recipe and recipe ~= "" then | ||
unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' | unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. recipe .. '.png|' .. recipe .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' .. recipe .. '}}</li>' | ||
end | end | ||
end | end | ||
unlocks = unlocks .. '</ul>' | unlocks = unlocks .. '</ul>' | ||
end | end | ||
local templateArgs = { | local templateArgs = { | ||
id = tech.id, | id = tech.id, | ||
| Строка 90: | Строка 87: | ||
templateArgs.prerequisites = prerequisites | templateArgs.prerequisites = prerequisites | ||
end | end | ||
out = out .. frame:expandTemplate({ | out = out .. frame:expandTemplate({ | ||
title = 'Prototypes/Механика/Исследование', | title = 'Prototypes/Механика/Исследование', | ||
| Строка 104: | Строка 101: | ||
-- Режим поиска по ID исследования | -- Режим поиска по ID исследования | ||
local tech = nil | local tech = nil | ||
for _, research in ipairs( | for _, research in ipairs(researchData) do | ||
if research.technology and research.technology.id == input then | if research.technology and research.technology.id == input then | ||
tech = research.technology | tech = research.technology | ||
| Строка 110: | Строка 107: | ||
end | end | ||
end | end | ||
if not tech then | if not tech then | ||
out = out .. '<div style="color:red;">Исследование с ID "' .. input .. '" не найдено.</div>' | out = out .. '<div style="color:red;">Исследование с ID "' .. input .. '" не найдено.</div>' | ||
| Строка 117: | Строка 114: | ||
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина" | local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина" | ||
local iconPath = manualIcon ~= "" and manualIcon or (tech.icon and tech.icon.sprite or nil) | local iconPath = manualIcon ~= "" and manualIcon or (tech.icon and tech.icon.sprite or nil) | ||
local prerequisites = "" | local prerequisites = "" | ||
if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then | if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then | ||
| Строка 124: | Строка 121: | ||
if prerequisiteId and prerequisiteId ~= "" then | if prerequisiteId and prerequisiteId ~= "" then | ||
local prerequisiteName = "" | local prerequisiteName = "" | ||
for _, research in ipairs( | for _, research in ipairs(researchData) do | ||
if research.technology and research.technology.id == prerequisiteId then | if research.technology and research.technology.id == prerequisiteId then | ||
prerequisiteName = research.technology.name | prerequisiteName = research.technology.name | ||
| Строка 137: | Строка 134: | ||
prerequisites = prerequisites .. '</ul>' | prerequisites = prerequisites .. '</ul>' | ||
end | end | ||
local unlocks = "" | local unlocks = "" | ||
if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then | if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then | ||
| Строка 143: | Строка 140: | ||
for _, recipe in ipairs(tech.recipeUnlocks) do | for _, recipe in ipairs(tech.recipeUnlocks) do | ||
if recipe and recipe ~= "" then | if recipe and recipe ~= "" then | ||
unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' | unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. recipe .. '.png|' .. recipe .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' .. recipe .. '}}</li>' | ||
end | end | ||
end | end | ||
unlocks = unlocks .. '</ul>' | unlocks = unlocks .. '</ul>' | ||
end | end | ||
local templateArgs = { | local templateArgs = { | ||
id = tech.id, | id = tech.id, | ||
| Строка 166: | Строка 160: | ||
templateArgs.prerequisites = prerequisites | templateArgs.prerequisites = prerequisites | ||
end | end | ||
out = out .. frame:expandTemplate({ | out = out .. frame:expandTemplate({ | ||
title = 'Prototypes/Механика/Исследование', | title = 'Prototypes/Механика/Исследование', | ||