Модуль:Prototypes/Механика/Исследование
Материал из Space Station 14 Вики
Версия от 15:40, 9 октября 2024; Pok (обсуждение | вклад)
Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Исследование/doc
local p = {}
-- Функция для загрузки данных плат из JSON-файла
local function loadData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/entity_prototypes.json"):getContent())
end
-- Функция для загрузки данных исследований из JSON-файла
local function loadResearchData()
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research_prototypes.json"):getContent())
end
-- Функция для перевода ID плат в ID машин без кэширования
local function translateBoardIDToMachineID(boardID)
-- Загруза данных плат
local data = loadData()
-- Поиск платы по ID
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
return entity.id
end
end
end
return nil
end
function p.main(frame)
-- Подключение CSS
local cssLink = frame:extensionTag('templatestyles', '', {
src = 'Шаблон:Research/styles.css'
})
local id = frame.args.id or ""
local icon = frame.args.icon or ""
local customRecipeUnlocks = frame.args.customRecipeUnlocks or nil
-- Обработка индексов для замены рецептов
local customRecipeUnlocksIndexes = {}
local i = 1
while true do
local customIndex = frame.args["customRecipeUnlocksIndex" .. i]
if not customIndex then
break
end
table.insert(customRecipeUnlocksIndexes, {index = i, recipe = customIndex})
i = i + 1 -- Увеличиваем индекс
end
-- Загружаем данные исследований
local data = loadResearchData()
local out = cssLink
local found = false
local disciplineName = ""
-- Определение дисциплины и отображение исследований
for discipline, technologies in pairs(data) do
for _, tech in ipairs(technologies) do
if tech.id == id then
found = true
disciplineName = ({
Arsenal = "Арсенал",
Industrial = "Промышленность",
Experimental = "Экспериментальное",
CivilianServices = "Обслуживание персонала"
})[discipline]
local tierColor = ({
[1] = "#54d554",
[2] = "#ed9000",
[3] = "#d72a2a"
})[tech.tier]
out = out .. '<div class="research" id="' .. discipline .. '">'
out = out .. '<div class="research__images">[[Файл:' .. icon .. '.png|64x64px|центр|link=]]</div>'
out = out .. '<div class="research__name">' .. tech.name .. '[[Файл:' .. 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__unblocks">Разблокирует:'
out = out .. '<ul>'
-- Используем кастомные recipeUnlocks или значения из json файла
local recipeUnlocks = customRecipeUnlocks and mw.text.split(customRecipeUnlocks, " ") or tech.recipeUnlocks
-- Замена рецептов по индексам
for _, customIndex in ipairs(customRecipeUnlocksIndexes) do
if recipeUnlocks[customIndex.index] then
recipeUnlocks[customIndex.index] = customIndex.recipe
end
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>'
end
end
end
if not found then
out = out .. '<div style="color:red;">Нет доступных исследований.</div>'
end
return out
end
return p