Модуль:Prototypes/Механика/Исследование
Версия от 11:32, 6 октября 2024; Pok (обсуждение | вклад)
Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Исследование/doc
local p = {}
-- Функция для загрузки JSON-данных
local function loadJsonData()
local jsonData = mw.title.new('User:IanComradeBot/research prototypes.json'):getContent() or "{}"
return mw.text.jsonDecode(jsonData)
end
function p.main(frame)
-- Подключение CSS файла
local cssLink = frame:extensionTag('templatestyles', '', {
src = 'Шаблон:Research/styles.css'
})
local discipline = frame.args.discipline or ""
local data = loadJsonData() -- Загружаем JSON-данные
local out = cssLink
-- Фильтрация данных по дисциплине
for _, item in ipairs(data) do
if item.discipline == discipline then
local icon = item.icon or ""
local name = item.name or ""
local tier = item.tier or ""
local cost = item.cost or ""
local recipeUnlocks = item.recipeUnlocks or {}
local disciplineName = ""
if discipline == "Arsenal" then
disciplineName = "Арсенал"
elseif discipline == "Industrial" then
disciplineName = "Промышленность"
elseif discipline == "Experimental" then
disciplineName = "Экспериментальное"
elseif discipline == "CivilianServices" then
disciplineName = "Обслуживание персонала"
end
-- Формирование HTML
out = out .. '<div class="research" id="' .. discipline .. '">'
out = out .. '<div class="research__images">[[Файл:' .. icon .. '.png|64px|центр|link=]]</div>'
out = out .. '<div class="research__name">' .. name .. '[[Файл:' .. discipline .. '.png|16px|link=]]</div>'
out = out .. '<div class="research__type">'
out = out .. '<div>Уровень: ' .. tier .. ' ,</div>'
out = out .. '<div class="research__category">' .. disciplineName .. '</div>'
out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. cost .. '</span></div>'
out = out .. '</div>'
out = out .. '<div class="research__unblocks">Разблокирует:'
out = out .. '<ul>'
for _, recipe in ipairs(recipeUnlocks) do
out = out .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. recipe .. '.png|' .. recipe .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' .. recipe .. '}}</li>'
end
out = out .. '</ul>'
out = out .. '</div>'
out = out .. '</div>'
end
end
return out
end
return p