Модуль:Prototypes/Механика/Исследование: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) м Pok переименовал страницу Модуль:Research в Модуль:Prototypes/Механика/Исследование без оставления перенаправления |
(нет различий)
| |
Версия от 23:53, 25 января 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Исследование/doc
local p = {}
-- Функция для загрузки данных исследований из JSON-файла
local function loadResearchData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research_prototypes.json"):getContent())
end
-- Функция для поиска исследования по ID
local function findResearchById(dataCache, id)
for _, research in ipairs(dataCache) do
if research.id == id then
return research
end
end
return nil
end
-- Кэш для ID машин
local machineIDCache = {}
-- Функция для перевода ID плат в ID машин
local function translateBoardIDToMachineID(boardID)
if machineIDCache[boardID] then
return machineIDCache[boardID]
end
local data = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/entity_prototypes.json"):getContent())
local board = data[boardID]
if not board or not board.name then
return nil
end
if not board.name:find("%(машинная плата%)") and not board.name:find("%(консольная плата%)") then
return nil
end
local machineName = board.name:gsub(" %(машинная плата%)", ""):gsub(" %(консольная плата%)", "")
local excludeWords = {"Unanchored", "Debug", "Admin", "Enabled"}
for _, entity in pairs(data) do
if entity.name == machineName then
local shouldExclude = false
for _, word in ipairs(excludeWords) do
if entity.id:find(word) then
shouldExclude = true
break
end
end
if not shouldExclude then
machineIDCache[boardID] = entity.id
return entity.id
end
end
end
return nil
end
-- Таблица для перевода названий дисциплин
local disciplineMapping = {
Arsenal = "Арсенал",
Industrial = "Промышленность",
Experimental = "Экспериментальное",
CivilianServices = "Обслуживание персонала"
}
-- Таблица для цветов по уровню
local tierColors = {
[1] = "#54d554",
[2] = "#ed9000",
[3] = "#d72a2a"
}
function p.main(frame)
-- Подключение CSS
local cssLink = frame:extensionTag('templatestyles', '', {
src = 'Шаблон:Research/styles.css'
})
local dataCache = loadResearchData()
local id = frame.args.id or ""
local icon = frame.args.icon or ""
-- Получение кастомных рецептов с индексами (если они есть)
local customRecipeUnlocks = {}
for i = 1, 100 do
local indexKey = "customRecipeUnlocksIndex" .. i
if frame.args[indexKey] then
table.insert(customRecipeUnlocks, frame.args[indexKey])
end
end
-- Получение кастомных рецептов без индексации
if frame.args.customRecipeUnlocks then
local tempUnlocks = mw.text.split(frame.args.customRecipeUnlocks, " ")
for _, item in ipairs(tempUnlocks) do
table.insert(customRecipeUnlocks, item)
end
end
local tech = findResearchById(dataCache, id)
if not tech then
return cssLink .. '<div style="color:red;">Исследование с ID "' .. id .. '" не найдено.</div>'
end
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестное исследование"
local tierColor = tierColors[tech.tier] or "#FFFFFF"
-- Блок данных
local out = cssLink .. '<div class="research" id="' .. tech.discipline .. '">'
out = out .. '<div class="research__images">[[Файл:' .. icon .. '.png|64x64px|центр|link=]]</div>'
out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. tech.discipline .. '.png|16px|link=]]</div>'
out = out .. '<div class="research__type">'
out = out .. '<div>Уровень: <span style="color:' .. tierColor .. ';">' .. tech.tier .. '</span></div>'
out = out .. '<div class="research__technology">' .. disciplineName .. '</div>'
out = out .. '<div>Стоимость: <span style="color:#DA70D6;">' .. tech.cost .. '</span></div>'
out = out .. '</div>'
out = out .. '<div class="research__technologies">'
-- Блок необходимых технологий для открытия исследования
if tech.technologyPrerequisites and #tech.technologyPrerequisites > 0 then
out = out .. '<div class="research__technologies-prerequisites">Необходимые исследования:'
for _, prerequisiteId in ipairs(tech.technologyPrerequisites) do
local prerequisiteTech = findResearchById(dataCache, prerequisiteId)
out = out .. '<span> ' .. prerequisiteTech.name .. '</span>'
end
out = out .. '</div>'
end
-- Блок открываемых технологий
out = out .. '<div class="research__technologies-unblocks">Разблокирует:'
out = out .. '<ul>'
local recipeUnlocks = customRecipeUnlocks
if #customRecipeUnlocks == 0 then
recipeUnlocks = tech.recipeUnlocks
end
for _, recipe in ipairs(recipeUnlocks) do
local machineID = translateBoardIDToMachineID(recipe) or recipe
out = out .. frame:preprocess('<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. machineID .. '.png|' .. machineID .. '|Мета=32x32px,link=}} {{#invoke:Entity Lookup|getname|' .. machineID .. '}}</li>')
end
out = out .. '</ul>'
out = out .. '</div>'
out = out .. '</div>'
out = out .. '</div>'
return out
end
return p