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