Модуль: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 (обсуждение | вклад) мНет описания правки |
||
Строка 1: | Строка 1: | ||
local p = {} | |||
local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data") | local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data") | ||
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data") | local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data") | ||
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data") | local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data") | ||
function p.getEquipment(searchKey, roleId) | |||
if not roleId then | |||
function p. | return '<div class="role">Параметр roleId не указан</div>' | ||
end | |||
local results = {} | |||
local role = nil | |||
for _, r in ipairs(gearRoleLoadout) do | |||
if r.id == roleId then | |||
role = r | |||
break | |||
end | |||
end | |||
if not role then | |||
return '<div class="role">Роль с id "' .. tostring(roleId) .. '" не найдена</div>' | |||
end | |||
for _, groupId in ipairs(role.groups or {}) do | |||
local group = nil | |||
for _, g in ipairs(gearloadoutGroup) do | |||
if g.id == groupId then | |||
group = g | |||
break | |||
end | |||
end | |||
if group then | |||
for _, loadoutId in ipairs(group.loadouts or {}) do | |||
local loadout = nil | |||
for _, l in ipairs(gearloadout) do | |||
if l.id == loadoutId then | |||
loadout = l | |||
break | |||
end | |||
end | |||
if loadout and loadout.equipment then | |||
local eqValue = loadout.equipment[searchKey] | |||
if eqValue then | |||
table.insert(results, eqValue) | |||
end | |||
end | |||
end | |||
end | |||
end | |||
local output = {} | |||
for _, eq in ipairs(results) do | |||
table.insert(output, '<div class="role">' .. eq .. '</div>') | |||
end | |||
return table.concat(output, "\n") | |||
end | end | ||
return p | return p |
Версия от 20:24, 13 февраля 2025
Для документации этого модуля может быть создана страница Модуль:Prototypes/Роль/Лодаут/doc
local p = {}
local gearRoleLoadout = mw.loadData("Модуль:IanComradeBot/roleLoadout.json/data")
local gearloadoutGroup = mw.loadData("Модуль:IanComradeBot/loadoutGroup.json/data")
local gearloadout = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
function p.getEquipment(searchKey, roleId)
if not roleId then
return '<div class="role">Параметр roleId не указан</div>'
end
local results = {}
local role = nil
for _, r in ipairs(gearRoleLoadout) do
if r.id == roleId then
role = r
break
end
end
if not role then
return '<div class="role">Роль с id "' .. tostring(roleId) .. '" не найдена</div>'
end
for _, groupId in ipairs(role.groups or {}) do
local group = nil
for _, g in ipairs(gearloadoutGroup) do
if g.id == groupId then
group = g
break
end
end
if group then
for _, loadoutId in ipairs(group.loadouts or {}) do
local loadout = nil
for _, l in ipairs(gearloadout) do
if l.id == loadoutId then
loadout = l
break
end
end
if loadout and loadout.equipment then
local eqValue = loadout.equipment[searchKey]
if eqValue then
table.insert(results, eqValue)
end
end
end
end
end
local output = {}
for _, eq in ipairs(results) do
table.insert(output, '<div class="role">' .. eq .. '</div>')
end
return table.concat(output, "\n")
end
return p