Модуль:Prototypes/Механика/Исследование: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) м Pok переименовал страницу Модуль:Research в Модуль:Prototypes/Механика/Исследование без оставления перенаправления |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 3: | Строка 3: | ||
-- Функция для загрузки данных исследований из JSON-файла | -- Функция для загрузки данных исследований из JSON-файла | ||
local function loadResearchData() | local function loadResearchData() | ||
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/Песочница.json"):getContent()) | |||
end | end | ||
-- Таблица для перевода названий дисциплин | -- Таблица для перевода названий дисциплин | ||
local disciplineMapping = { | local disciplineMapping = { | ||
Arsenal = "Арсенал", | |||
Industrial = "Промышленность", | |||
Experimental = "Экспериментальное", | |||
CivilianServices = "Обслуживание персонала" | |||
} | } | ||
-- Таблица для цветов по | -- Таблица для цветов по уровням | ||
local tierColors = { | local tierColors = { | ||
[1] = "#54d554", | |||
[2] = "#ed9000", | |||
[3] = "#d72a2a" | |||
} | } | ||
function p.main(frame) | function p.main(frame) | ||
local dataCache = loadResearchData() | |||
-- Получаем ID и иконку из параметров | |||
local researchId = frame.args[1] or "" | |||
local icon = frame.args[2] or "" | |||
if researchId and researchId ~= "" then | |||
local out = "" | |||
-- Поиск исследования по ID | |||
local tech = nil | |||
for _, research in ipairs(dataCache) do | |||
if research.technology and research.technology.id == researchId then | |||
tech = research.technology | |||
break | |||
end | |||
end | |||
if not tech then | |||
out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>' | |||
else | |||
local tierColor = tierColors[tech.tier] or "#FFFFFF" | |||
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина" | |||
local iconPath = icon ~= "" and icon or (tech.icon and tech.icon.sprite or nil) | |||
-- Формирование строки необходимых исследований | |||
local prerequisites = "" | |||
if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then | |||
prerequisites = '<ul>' | |||
for _, prerequisiteId in ipairs(tech.technologyPrerequisites) do | |||
if prerequisiteId and prerequisiteId ~= "" then | |||
-- Находим название исследования по ID | |||
local prerequisiteName = "" | |||
for _, research in ipairs(dataCache) do | |||
if research.technology and research.technology.id == prerequisiteId then | |||
prerequisiteName = research.technology.name | |||
break | |||
end | |||
end | |||
-- Если название найдено, выводим его | |||
if prerequisiteName ~= "" then | |||
prerequisites = prerequisites .. '<li>{{#invoke:Ftl|main|translation|'.. prerequisiteName .. '}}</li>' | |||
end | |||
end | |||
end | |||
prerequisites = prerequisites .. '</ul>' | |||
end | |||
-- Формирование строки открываемых исследований | |||
local unlocks = "" | |||
if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then | |||
unlocks = '<ul>' | |||
for _, recipe in ipairs(tech.recipeUnlocks) do | |||
if recipe and recipe ~= "" then | |||
unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' | |||
.. recipe .. '.png|' .. recipe | |||
.. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' | |||
.. recipe .. '}}</li>' | |||
end | |||
end | |||
unlocks = unlocks .. '</ul>' | |||
end | |||
-- Шаблон для отображения блока исследования | |||
local templateArgs = { | |||
id = tech.id, | |||
icon = iconPath, | |||
name = tech.name, | |||
discipline = tech.discipline, | |||
tier = tech.tier, | |||
tierColor = tierColor, | |||
disciplineName = disciplineName, | |||
cost = tech.cost, | |||
unlocks = unlocks | |||
} | |||
-- Добавление prerequisites только если он существует | |||
if prerequisites ~= "" then | |||
templateArgs.prerequisites = prerequisites | |||
end | |||
out = out .. frame:expandTemplate({ | |||
title = 'Prototypes/Механика/Исследование', | |||
args = templateArgs | |||
}) | |||
end | |||
return mw.getCurrentFrame():preprocess(out) | |||
else | |||
return '<div style="color:red;">Не указан ID исследования.</div>' | |||
end | |||
end | end | ||
return p | return p | ||
Версия от 23:53, 25 января 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Исследование/doc
local p = {}
-- Функция для загрузки данных исследований из JSON-файла
local function loadResearchData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/Песочница.json"):getContent())
end
-- Таблица для перевода названий дисциплин
local disciplineMapping = {
Arsenal = "Арсенал",
Industrial = "Промышленность",
Experimental = "Экспериментальное",
CivilianServices = "Обслуживание персонала"
}
-- Таблица для цветов по уровням
local tierColors = {
[1] = "#54d554",
[2] = "#ed9000",
[3] = "#d72a2a"
}
function p.main(frame)
local dataCache = loadResearchData()
-- Получаем ID и иконку из параметров
local researchId = frame.args[1] or ""
local icon = frame.args[2] or ""
if researchId and researchId ~= "" then
local out = ""
-- Поиск исследования по ID
local tech = nil
for _, research in ipairs(dataCache) do
if research.technology and research.technology.id == researchId then
tech = research.technology
break
end
end
if not tech then
out = out .. '<div style="color:red;">Исследование с ID "' .. researchId .. '" не найдено.</div>'
else
local tierColor = tierColors[tech.tier] or "#FFFFFF"
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
local iconPath = icon ~= "" and icon or (tech.icon and tech.icon.sprite or nil)
-- Формирование строки необходимых исследований
local prerequisites = ""
if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
prerequisites = '<ul>'
for _, prerequisiteId in ipairs(tech.technologyPrerequisites) do
if prerequisiteId and prerequisiteId ~= "" then
-- Находим название исследования по ID
local prerequisiteName = ""
for _, research in ipairs(dataCache) do
if research.technology and research.technology.id == prerequisiteId then
prerequisiteName = research.technology.name
break
end
end
-- Если название найдено, выводим его
if prerequisiteName ~= "" then
prerequisites = prerequisites .. '<li>{{#invoke:Ftl|main|translation|'.. prerequisiteName .. '}}</li>'
end
end
end
prerequisites = prerequisites .. '</ul>'
end
-- Формирование строки открываемых исследований
local unlocks = ""
if tech.recipeUnlocks and #tech.recipeUnlocks > 0 then
unlocks = '<ul>'
for _, recipe in ipairs(tech.recipeUnlocks) do
if recipe and recipe ~= "" then
unlocks = unlocks .. '<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:'
.. recipe .. '.png|' .. recipe
.. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|'
.. recipe .. '}}</li>'
end
end
unlocks = unlocks .. '</ul>'
end
-- Шаблон для отображения блока исследования
local templateArgs = {
id = tech.id,
icon = iconPath,
name = tech.name,
discipline = tech.discipline,
tier = tech.tier,
tierColor = tierColor,
disciplineName = disciplineName,
cost = tech.cost,
unlocks = unlocks
}
-- Добавление prerequisites только если он существует
if prerequisites ~= "" then
templateArgs.prerequisites = prerequisites
end
out = out .. frame:expandTemplate({
title = 'Prototypes/Механика/Исследование',
args = templateArgs
})
end
return mw.getCurrentFrame():preprocess(out)
else
return '<div style="color:red;">Не указан ID исследования.</div>'
end
end
return p