Модуль:Prototypes/Механика/Исследование: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
-- Функция для загрузки данных плат из JSON-файла | -- Функция для загрузки данных плат из JSON-файла | ||
local function | local function loadBoardData() | ||
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/entity_prototypes.json"):getContent()) | |||
end | end | ||
-- Функция для загрузки данных исследований из JSON-файла | -- Функция для загрузки данных исследований из JSON-файла | ||
local function loadResearchData() | local function loadResearchData() | ||
return mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research_prototypes.json"):getContent()) | |||
end | |||
-- Функция для поиска данных по ID | |||
local function findResearchById(dataCache, id) | |||
for _, discipline in pairs(dataCache) do | |||
for _, tech in ipairs(discipline) do | |||
if tech.id == id then | |||
return tech | |||
end | |||
end | |||
end | end | ||
return | return nil | ||
end | end | ||
-- Функция для перевода ID плат в ID машин | -- Кэш для ID машин | ||
local machineIDCache = {} | |||
-- Функция для перевода ID плат в ID машин | |||
local function translateBoardIDToMachineID(boardID) | local function translateBoardIDToMachineID(boardID) | ||
if machineIDCache[boardID] then | if machineIDCache[boardID] then | ||
| Строка 30: | Строка 34: | ||
-- Загружаем данные плат | -- Загружаем данные плат | ||
local data = | local data = loadBoardData() | ||
-- Поиск платы по ID | -- Поиск платы по ID | ||
| Строка 70: | Строка 74: | ||
return nil | return nil | ||
end | end | ||
-- Таблица для перевода названий дисциплин | |||
local disciplineMapping = { | |||
Arsenal = "Арсенал", | |||
Industrial = "Промышленность", | |||
Experimental = "Экспериментальное", | |||
CivilianServices = "Обслуживание персонала" | |||
} | |||
-- Таблица для цветов по уровню | |||
local tierColors = { | |||
[1] = "#54d554", | |||
[2] = "#ed9000", | |||
[3] = "#d72a2a" | |||
} | |||
function p.main(frame) | function p.main(frame) | ||
-- | -- Загрузка данных исследований | ||
local | local dataCache = loadResearchData() | ||
-- Получаем ID исследования | |||
local id = frame.args.id or "" | local id = frame.args.id or "" | ||
local icon = frame.args.icon or "" | local icon = frame.args.icon or "" | ||
local customRecipeUnlocks = frame.args.customRecipeUnlocks or nil | local customRecipeUnlocks = frame.args.customRecipeUnlocks or nil | ||
-- | -- Поиск данных исследования по ID | ||
local | local tech = findResearchById(dataCache, id) | ||
if not tech then | |||
return '<div style="color:red;">Нет доступных исследований.</div>' | |||
end | end | ||
-- | -- Получение локализованного имени дисциплины | ||
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина" | |||
local disciplineName = | |||
-- Получение цвета для уровня | |||
local tierColor = tierColors[tech.tier] or "#FFFFFF" | |||
-- Формирование вывода | |||
local out = '<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__unblocks">Разблокирует:' | |||
out = out .. '<ul>' | |||
-- Используем кастомные recipeUnlocks или значения из json | |||
local recipeUnlocks = customRecipeUnlocks and mw.text.split(customRecipeUnlocks, " ") or tech.recipeUnlocks | |||
-- Формируем список рецептов | |||
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 | end | ||
out = out .. '</ul>' | |||
out = out .. '</div>' | |||
out = out .. '</div>' | |||
return out | return out | ||
Версия от 11:55, 21 ноября 2024
Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Исследование/doc
local p = {}
-- Функция для загрузки данных плат из JSON-файла
local function loadBoardData()
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
local function findResearchById(dataCache, id)
for _, discipline in pairs(dataCache) do
for _, tech in ipairs(discipline) do
if tech.id == id then
return tech
end
end
end
return nil
end
-- Кэш для ID машин
local machineIDCache = {}
-- Функция для перевода ID плат в ID машин
local function translateBoardIDToMachineID(boardID)
if machineIDCache[boardID] then
-- Если ID машины уже есть в кэше, возвращаем его
return machineIDCache[boardID]
end
-- Загружаем данные плат
local data = loadBoardData()
-- Поиск платы по 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
-- Кэширование ID машины
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)
-- Загрузка данных исследований
local dataCache = loadResearchData()
-- Получаем ID исследования
local id = frame.args.id or ""
local icon = frame.args.icon or ""
local customRecipeUnlocks = frame.args.customRecipeUnlocks or nil
-- Поиск данных исследования по ID
local tech = findResearchById(dataCache, id)
if not tech then
return '<div style="color:red;">Нет доступных исследований.</div>'
end
-- Получение локализованного имени дисциплины
local disciplineName = disciplineMapping[tech.discipline] or "Неизвестная дисциплина"
-- Получение цвета для уровня
local tierColor = tierColors[tech.tier] or "#FFFFFF"
-- Формирование вывода
local out = '<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__unblocks">Разблокирует:'
out = out .. '<ul>'
-- Используем кастомные recipeUnlocks или значения из json
local recipeUnlocks = customRecipeUnlocks and mw.text.split(customRecipeUnlocks, " ") or tech.recipeUnlocks
-- Формируем список рецептов
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>'
return out
end
return p