Модуль:Prototypes/Роль/Экипировка: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
Строка 21: | Строка 21: | ||
if not str or str == "" then return "" end | if not str or str == "" then return "" end | ||
return str:sub(1,1):upper() .. str:sub(2) | return str:sub(1,1):upper() .. str:sub(2) | ||
end | end | ||
function p.main(frame) | function p.main(frame) | ||
local args = frame.args | local args = frame.args | ||
local | local slot = mw.text.trim(args[1] or "") | ||
local jobId = mw.text.trim(args[2] or "") | local jobId = mw.text.trim(args[2] or "") | ||
Строка 82: | Строка 36: | ||
if not job then | if not job then | ||
return "Ошибка: не найдена должность с id " .. jobId | return "Ошибка: не найдена должность с id " .. jobId | ||
end | |||
-- Новый режим обработки special | |||
if slot == "special" then | |||
local implants = {} | |||
if job.special then | |||
for _, special in ipairs(job.special) do | |||
if special["!type"] == "AddImplantSpecial" and special.implants then | |||
for _, implant in ipairs(special.implants) do | |||
table.insert(implants, string.format("{{#invoke:Entity Lookup|getname|%s}}", implant)) | |||
end | |||
end | |||
end | |||
end | |||
return table.concat(implants, ", ") | |||
end | end | ||
Строка 96: | Строка 65: | ||
local gearEquipment = gear.equipment or {} | local gearEquipment = gear.equipment or {} | ||
local itemId = gearEquipment[slot] or "" | local itemId = gearEquipment[slot] or "" | ||
local sourceGear = gear | local sourceGear = gear | ||
if itemId == "" then | if itemId == "" then | ||
local function capitalize(s) | |||
return (s:gsub("^%l", string.upper)) | |||
end | |||
local groupID = jobId .. capitalize(slot) | local groupID = jobId .. capitalize(slot) | ||
local groupFound = nil | local groupFound = nil | ||
for _, group in ipairs(gearloadoutGroup) do | for _, group in ipairs(gearloadoutGroup) do | ||
Строка 110: | Строка 83: | ||
if not groupFound then | if not groupFound then | ||
return " | return "" | ||
end | end | ||
Строка 131: | Строка 104: | ||
end | end | ||
if slot == "back" and sourceGear.storage and sourceGear.storage.back then | if slot == "back" and sourceGear.storage and sourceGear.storage.back then | ||
local storageBack = "" | local storageBack = "" |
Версия от 13:06, 13 февраля 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Роль/Экипировка/doc
-- Загрузка данных
local jobData = mw.loadData("Модуль:IanComradeBot/job.json/data")
local gearData = mw.loadData("Модуль:IanComradeBot/startingGear.json/data")
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local p = {}
-- Функция для поиска объекта по id
local function findById(tbl, id)
for k, v in pairs(tbl) do
if k == id or (v.id and v.id == id) then
return v
end
end
return nil
end
-- Функция для преобразования первой буквы строки в заглавную
local function capitalizeFirst(str)
if not str or str == "" then return "" end
return str:sub(1,1):upper() .. str:sub(2)
end
function p.main(frame)
local args = frame.args
local slot = mw.text.trim(args[1] or "")
local jobId = mw.text.trim(args[2] or "")
if slot == "" or jobId == "" then
return "Ошибка: Не заданы необходимые параметры. Используйте: {{#invoke:Prototypes/Роль/Экипировка|main|<slot>|<jobId>}}"
end
jobId = capitalizeFirst(jobId)
local job = findById(jobData, jobId)
if not job then
return "Ошибка: не найдена должность с id " .. jobId
end
-- Новый режим обработки special
if slot == "special" then
local implants = {}
if job.special then
for _, special in ipairs(job.special) do
if special["!type"] == "AddImplantSpecial" and special.implants then
for _, implant in ipairs(special.implants) do
table.insert(implants, string.format("{{#invoke:Entity Lookup|getname|%s}}", implant))
end
end
end
end
return table.concat(implants, ", ")
end
local gearId = job.startingGear
if not gearId then
return "Ошибка: у должности с id " .. jobId .. " не указан startingGear"
end
local gear = findById(gearData, gearId)
if not gear then
return "Ошибка: не найдена экипировка с id " .. gearId
end
local gearEquipment = gear.equipment or {}
local itemId = gearEquipment[slot] or ""
local sourceGear = gear
if itemId == "" then
local function capitalize(s)
return (s:gsub("^%l", string.upper))
end
local groupID = jobId .. capitalize(slot)
local groupFound = nil
for _, group in ipairs(gearloadoutGroup) do
if group.id == groupID then
groupFound = group
break
end
end
if not groupFound then
return ""
end
for _, loadoutID in ipairs(groupFound.loadouts) do
for _, loadout in ipairs(gearloadout) do
if loadout.id == loadoutID then
if loadout.equipment and loadout.equipment[slot] then
itemId = loadout.equipment[slot]
sourceGear = loadout
break
end
end
end
if itemId ~= "" then break end
end
end
if itemId == "" then
return ""
end
if slot == "back" and sourceGear.storage and sourceGear.storage.back then
local storageBack = ""
for _, storageItem in ipairs(sourceGear.storage.back) do
storageBack = storageBack .. string.format("{{#invoke:Prototypes/Предмет/Содержание|main|%s}}", storageItem)
end
return frame:preprocess(string.format("{{#invoke:Prototypes/Предмет/Содержание|image|%s|%s}}", itemId, storageBack))
else
return frame:preprocess(string.format("{{#invoke:Prototypes/Предмет/Содержание|image|%s}}", itemId))
end
end
return p