Модуль:Prototypes/Механика/Исследование: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
-- Функция для перевода ID плат в ID машин | |||
local function translateBoardIDToMachineID(boardID) | |||
-- Загрузка данных из JSON | |||
local data = mw.text.jsonDecode(mw.title.new("Участник:IanComradeBot/entity_prototypes.json"):getContent()) | |||
-- Проход по всем данным | |||
for _, entity in pairs(data) do | |||
-- Если найдено соответствие плате | |||
if entity.name == boardID then | |||
-- Удаляем "(машинная плата)" из названия | |||
local machineName = entity.displayName:gsub(" %(машинная плата%)", "") | |||
-- Поиск ID машины по новому названию | |||
for _, machineEntity in pairs(data) do | |||
if machineEntity.displayName == machineName then | |||
return machineEntity.name -- Возвращаем ID машины | |||
end | |||
end | |||
end | |||
end | |||
return nil -- Если ничего не найдено, возвращаем nil | |||
end | |||
function p.main(frame) | function p.main(frame) | ||
| Строка 11: | Строка 34: | ||
-- Названия технологий | -- Названия технологий | ||
local disciplineName = ({ | local disciplineName = ({ | ||
Arsenal = "Арсенал", | |||
Industrial = "Промышленность", | |||
Experimental = "Экспериментальное", | |||
CivilianServices = "Обслуживание персонала" | |||
})[discipline] | })[discipline] | ||
| Строка 27: | Строка 50: | ||
for _, tech in ipairs(data[discipline]) do | for _, tech in ipairs(data[discipline]) do | ||
found = true | found = true | ||
-- Цвета для номеров уровней | -- Цвета для номеров уровней | ||
local tierColor = ({ | local tierColor = ({ | ||
[1] = "#54d554", -- зеленый | |||
[2] = "#ed9000", -- оранжевый | |||
[3] = "#d72a2a" -- красный | |||
})[tech.tier] | })[tech.tier] | ||
-- Формирование HTML для каждой технологии | -- Формирование HTML для каждой технологии | ||
out = out .. '<div class="research" id="' .. discipline .. '">' | out = out .. '<div class="research" id="' .. discipline .. '">' | ||
| Строка 46: | Строка 69: | ||
out = out .. '<div class="research__unblocks">Разблокирует:' | out = out .. '<div class="research__unblocks">Разблокирует:' | ||
out = out .. '<ul>' | out = out .. '<ul>' | ||
-- Проверка каждого ID в recipeUnlocks | |||
for _, recipe in ipairs(tech.recipeUnlocks) do | for _, recipe in ipairs(tech.recipeUnlocks) do | ||
out = out .. frame:preprocess('<li>{{#invoke:Entity Lookup|createimagetooltip|Файл:' .. | 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 .. '</ul>' | ||
out = out .. '</div>' | out = out .. '</div>' | ||
Версия от 06:49, 9 октября 2024
Для документации этого модуля может быть создана страница Модуль:Prototypes/Механика/Исследование/doc
local p = {}
-- Функция для перевода ID плат в ID машин
local function translateBoardIDToMachineID(boardID)
-- Загрузка данных из JSON
local data = mw.text.jsonDecode(mw.title.new("Участник:IanComradeBot/entity_prototypes.json"):getContent())
-- Проход по всем данным
for _, entity in pairs(data) do
-- Если найдено соответствие плате
if entity.name == boardID then
-- Удаляем "(машинная плата)" из названия
local machineName = entity.displayName:gsub(" %(машинная плата%)", "")
-- Поиск ID машины по новому названию
for _, machineEntity in pairs(data) do
if machineEntity.displayName == machineName then
return machineEntity.name -- Возвращаем ID машины
end
end
end
end
return nil -- Если ничего не найдено, возвращаем nil
end
function p.main(frame)
-- Подключение CSS файла
local cssLink = frame:extensionTag('templatestyles', '', {
src = 'Шаблон:Research/styles.css'
})
local discipline = frame.args.discipline or ""
-- Названия технологий
local disciplineName = ({
Arsenal = "Арсенал",
Industrial = "Промышленность",
Experimental = "Экспериментальное",
CivilianServices = "Обслуживание персонала"
})[discipline]
-- Загрузка данных из JSON
local data = mw.text.jsonDecode(mw.title.new("User:IanComradeBot/research prototypes.json"):getContent())
local out = cssLink
local found = false -- Флаг для отслеживания наличия элементов
-- Обработка данных
if data[discipline] then -- Проверяем, существует ли ключ для discipline
for _, tech in ipairs(data[discipline]) do
found = true
-- Цвета для номеров уровней
local tierColor = ({
[1] = "#54d554", -- зеленый
[2] = "#ed9000", -- оранжевый
[3] = "#d72a2a" -- красный
})[tech.tier]
-- Формирование HTML для каждой технологии
out = out .. '<div class="research" id="' .. discipline .. '">'
out = out .. '<div class="research__images">[[Файл:' .. tech.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>'
-- Проверка каждого ID в recipeUnlocks
for _, recipe in ipairs(tech.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
if not found then
out = out .. '<div>Нет доступных технологий.</div>'
end
return out
end
return p