Модуль:Prototypes/Роль/Лодаут: различия между версиями
Материал из Space Station 14 Вики
Pok (обсуждение | вклад) Новая страница: «-- Загрузка local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data") local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data") local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data") local p = {} function p.main(searchKey, roleId) local results = {} local role = nil for _, r in ipairs(gearRoleLoadout) do if r.id == roleId then...» |
Pok (обсуждение | вклад) мНет описания правки |
||
(не показаны 33 промежуточные версии этого же участника) | |||
Строка 1: | Строка 1: | ||
-- Загрузка | -- Загрузка данных | ||
local gearRoleLoadout | local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data") | ||
local gearloadoutGroup | local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data") | ||
local gearloadout | local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data") | ||
local p = {} | local p = {} | ||
-- Построение кэш-таблиц для быстрого доступа по id | |||
local | local rolesById = {} | ||
for _, role in ipairs(gearRoleLoadout) do | |||
rolesById[role.id] = role | |||
end | |||
local groupsById = {} | |||
for _, group in ipairs(gearloadoutGroup) do | |||
groupsById[group.id] = group | |||
end | |||
local loadoutsById = {} | |||
for _, loadout in ipairs(gearloadout) do | |||
loadoutsById[loadout.id] = loadout | |||
end | |||
-- Функция для форматирования дополнительной информации (время требования) | |||
local function formatExtraInfo(info) | |||
return (info ~= "" and '<div class="роль-лодаут__time">{{AltTooltip|[[Файл:Small_watch.png|link=]]|' .. info .. '}}</div>') or "" | |||
end | |||
local | -- Функция для получения дополнительной информации по эффектам лодаута | ||
for _, | local function getExtraInfo(loadout) | ||
local extraInfo = "" | |||
if loadout.effects then | |||
for _, effect in ipairs(loadout.effects) do | |||
if effect["!type"] == "GroupLoadoutEffect" then | |||
local proto = effect.proto | |||
if proto then | |||
local candidate = loadoutsById[proto] | |||
if candidate and candidate.effects then | |||
for _, eff in ipairs(candidate.effects) do | |||
if eff["!type"] == "JobRequirementLoadoutEffect" and eff.requirement then | |||
local req = eff.requirement | |||
if req["!type"] == "DepartmentTimeRequirement" and req.department and req.time then | |||
extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|department-" .. req.department .. "}}}}</b>: {{#invoke:Code/Формат/Время|main|seconds|" .. req.time .. "}}<br>" | |||
elseif req["!type"] == "RoleTimeRequirement" and req.role and req.time then | |||
extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|" .. req.role .. "}}}}</b>: {{#invoke:Code/Формат/Время|main|seconds|" .. req.time .. "}}<br>" | |||
end | |||
end | |||
end | |||
end | |||
end | |||
end | |||
end | end | ||
end | end | ||
return extraInfo | |||
end | |||
function p.main(frame) | |||
local args = frame.args | |||
local searchKey = args[1] | |||
local roleParam = args[2] | |||
if not roleParam then | |||
return 'Параметр roleId не указан' | |||
end | |||
local roleId = "Job" .. roleParam | |||
local modeTrinkets = (searchKey == "trinkets") | |||
local modeBackStorage = (searchKey == "backStorage") | |||
local results = {} | |||
local printedTrinkets = {} | |||
local role = rolesById[roleId] | |||
if not role then | if not role then | ||
return ' | return 'Роль с id "' .. roleId .. '" не найдена' | ||
end | end | ||
for _, groupId in ipairs(role.groups or {}) do | for _, groupId in ipairs(role.groups or {}) do | ||
if (modeTrinkets and groupId == "Trinkets") or ((not modeTrinkets) and groupId ~= "Trinkets") then | |||
local group = groupsById[groupId] | |||
if group then | |||
local loadouts = group.loadouts or {} | |||
if type(loadouts) == "string" then | |||
local success, decoded = pcall(mw.text.jsonDecode, loadouts) | |||
loadouts = (success and type(decoded) == "table") and decoded or {} | |||
end | end | ||
for _, loadoutId in ipairs(loadouts) do | |||
local loadout = loadoutsById[loadoutId] | |||
if loadout then | |||
local skipLoadout = false | |||
if loadout.effects then | |||
for _, effect in ipairs(loadout.effects) do | |||
if effect.proto == "EffectSpeciesVox" then | |||
skipLoadout = true | |||
break | |||
end | |||
end | |||
end | |||
if not skipLoadout then | |||
if modeTrinkets then | |||
local items = {} | |||
if loadout.storage and loadout.storage.back then | |||
for _, item in ipairs(loadout.storage.back) do | |||
table.insert(items, item) | |||
end | |||
elseif loadout.equipment then | |||
for _, eqValue in pairs(loadout.equipment) do | |||
table.insert(items, eqValue) | |||
break | |||
end | |||
end | |||
for _, trinket in ipairs(items) do | |||
if not printedTrinkets[trinket] then | |||
printedTrinkets[trinket] = true | |||
table.insert(results, '{{Предмет|' .. trinket .. '|wrapper=|repository=|label=|imageTooltip=}}') | |||
end | |||
end | |||
elseif modeBackStorage then | |||
if loadout.storage and loadout.storage.back then | |||
for _, eqValue in ipairs(loadout.storage.back) do | |||
local extraInfo = getExtraInfo(loadout) | |||
local infoOutput = formatExtraInfo(extraInfo) | |||
table.insert(results, infoOutput .. '{{Предмет|' .. eqValue .. '|size=64px|repository=|label=|imageTooltip=}} [[File:Slot.png|64px|link=]]') | |||
end | |||
end | |||
else | |||
if loadout.equipment then | |||
local eqValue = loadout.equipment[searchKey] | |||
if eqValue then | |||
local extraInfo = getExtraInfo(loadout) | |||
local infoOutput = formatExtraInfo(extraInfo) | |||
table.insert(results, infoOutput .. '{{Предмет|' .. eqValue .. '|size=64px|repository=|label=|imageTooltip=}} [[File:Slot.png|64px|link=]]') | |||
end | |||
end | |||
end | |||
end | |||
end | end | ||
end | end | ||
Строка 51: | Строка 140: | ||
local output = {} | local output = {} | ||
for _, | if modeTrinkets then | ||
table.insert(output, '<div class=" | for _, item in ipairs(results) do | ||
table.insert(output, item) | |||
end | |||
else | |||
for _, item in ipairs(results) do | |||
table.insert(output, '<div class="роль-лодаут__item">' .. item .. '</div>') | |||
end | |||
end | end | ||
return frame:preprocess(table.concat(output)) | |||
return table.concat(output | |||
end | end | ||
return p | return p |
Текущая версия от 10:17, 4 апреля 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Роль/Лодаут/doc
-- Загрузка данных
local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
local p = {}
-- Построение кэш-таблиц для быстрого доступа по id
local rolesById = {}
for _, role in ipairs(gearRoleLoadout) do
rolesById[role.id] = role
end
local groupsById = {}
for _, group in ipairs(gearloadoutGroup) do
groupsById[group.id] = group
end
local loadoutsById = {}
for _, loadout in ipairs(gearloadout) do
loadoutsById[loadout.id] = loadout
end
-- Функция для форматирования дополнительной информации (время требования)
local function formatExtraInfo(info)
return (info ~= "" and '<div class="роль-лодаут__time">{{AltTooltip|[[Файл:Small_watch.png|link=]]|' .. info .. '}}</div>') or ""
end
-- Функция для получения дополнительной информации по эффектам лодаута
local function getExtraInfo(loadout)
local extraInfo = ""
if loadout.effects then
for _, effect in ipairs(loadout.effects) do
if effect["!type"] == "GroupLoadoutEffect" then
local proto = effect.proto
if proto then
local candidate = loadoutsById[proto]
if candidate and candidate.effects then
for _, eff in ipairs(candidate.effects) do
if eff["!type"] == "JobRequirementLoadoutEffect" and eff.requirement then
local req = eff.requirement
if req["!type"] == "DepartmentTimeRequirement" and req.department and req.time then
extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|department-" .. req.department .. "}}}}</b>: {{#invoke:Code/Формат/Время|main|seconds|" .. req.time .. "}}<br>"
elseif req["!type"] == "RoleTimeRequirement" and req.role and req.time then
extraInfo = extraInfo .. "<b>{{ucfirst:{{#invoke:Ftl|main|translation|" .. req.role .. "}}}}</b>: {{#invoke:Code/Формат/Время|main|seconds|" .. req.time .. "}}<br>"
end
end
end
end
end
end
end
end
return extraInfo
end
function p.main(frame)
local args = frame.args
local searchKey = args[1]
local roleParam = args[2]
if not roleParam then
return 'Параметр roleId не указан'
end
local roleId = "Job" .. roleParam
local modeTrinkets = (searchKey == "trinkets")
local modeBackStorage = (searchKey == "backStorage")
local results = {}
local printedTrinkets = {}
local role = rolesById[roleId]
if not role then
return 'Роль с id "' .. roleId .. '" не найдена'
end
for _, groupId in ipairs(role.groups or {}) do
if (modeTrinkets and groupId == "Trinkets") or ((not modeTrinkets) and groupId ~= "Trinkets") then
local group = groupsById[groupId]
if group then
local loadouts = group.loadouts or {}
if type(loadouts) == "string" then
local success, decoded = pcall(mw.text.jsonDecode, loadouts)
loadouts = (success and type(decoded) == "table") and decoded or {}
end
for _, loadoutId in ipairs(loadouts) do
local loadout = loadoutsById[loadoutId]
if loadout then
local skipLoadout = false
if loadout.effects then
for _, effect in ipairs(loadout.effects) do
if effect.proto == "EffectSpeciesVox" then
skipLoadout = true
break
end
end
end
if not skipLoadout then
if modeTrinkets then
local items = {}
if loadout.storage and loadout.storage.back then
for _, item in ipairs(loadout.storage.back) do
table.insert(items, item)
end
elseif loadout.equipment then
for _, eqValue in pairs(loadout.equipment) do
table.insert(items, eqValue)
break
end
end
for _, trinket in ipairs(items) do
if not printedTrinkets[trinket] then
printedTrinkets[trinket] = true
table.insert(results, '{{Предмет|' .. trinket .. '|wrapper=|repository=|label=|imageTooltip=}}')
end
end
elseif modeBackStorage then
if loadout.storage and loadout.storage.back then
for _, eqValue in ipairs(loadout.storage.back) do
local extraInfo = getExtraInfo(loadout)
local infoOutput = formatExtraInfo(extraInfo)
table.insert(results, infoOutput .. '{{Предмет|' .. eqValue .. '|size=64px|repository=|label=|imageTooltip=}} [[File:Slot.png|64px|link=]]')
end
end
else
if loadout.equipment then
local eqValue = loadout.equipment[searchKey]
if eqValue then
local extraInfo = getExtraInfo(loadout)
local infoOutput = formatExtraInfo(extraInfo)
table.insert(results, infoOutput .. '{{Предмет|' .. eqValue .. '|size=64px|repository=|label=|imageTooltip=}} [[File:Slot.png|64px|link=]]')
end
end
end
end
end
end
end
end
end
local output = {}
if modeTrinkets then
for _, item in ipairs(results) do
table.insert(output, item)
end
else
for _, item in ipairs(results) do
table.insert(output, '<div class="роль-лодаут__item">' .. item .. '</div>')
end
end
return frame:preprocess(table.concat(output))
end
return p