Модуль:Prototypes/Механика/Исследование: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 3: | Строка 3: | ||
-- Функция для загрузки JSON-данных | -- Функция для загрузки JSON-данных | ||
local function loadJsonData() | local function loadJsonData() | ||
local | local title = mw.title.new('Участник:IanComradeBot/research prototypes.json') | ||
return mw. | local jsonData = title:getContent() or "{}" | ||
return mw.ext.json:decode(jsonData) | |||
end | end | ||
| Строка 14: | Строка 15: | ||
local discipline = frame.args.discipline or "" | local discipline = frame.args.discipline or "" | ||
local data = loadJsonData() -- JSON-данные | local data = loadJsonData() -- Загружаем JSON-данные | ||
local out = cssLink | local out = cssLink | ||
| Строка 25: | Строка 26: | ||
local tier = item.tier or "" | local tier = item.tier or "" | ||
local cost = item.cost or "" | local cost = item.cost or "" | ||
local recipeUnlocks = item.recipeUnlocks or | local recipeUnlocks = item.recipeUnlocks or {} | ||
local disciplineName = "" | local disciplineName = "" | ||
Версия от 11:31, 6 октября 2024
Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Исследование/doc
local p = {}
-- Функция для загрузки JSON-данных
local function loadJsonData()
local title = mw.title.new('Участник:IanComradeBot/research prototypes.json')
local jsonData = title:getContent() or "{}"
return mw.ext.json:decode(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 tier, items in pairs(data) do
for _, item in ipairs(items) 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
end
return out
end
return p