Модуль:Prototypes/Роль/Лодаут: различия между версиями

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
Строка 5: Строка 5:
local gearloadout      = mw.loadData("Модуль:IanComradeBot/loadout.json/data")
local gearloadout      = mw.loadData("Модуль:IanComradeBot/loadout.json/data")


function p.getEquipment(searchKey, roleId)
function p.getEquipment(frame)
local args = frame.args
local searchKey = args[1]
local roleId = args[2]
if not roleId then
if not roleId then
return '<div class="role">Параметр roleId не указан</div>'
return '<div class="role">Параметр roleId не указан</div>'

Версия от 20:26, 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(frame)
	local args = frame.args
	local searchKey = args[1]
	local roleId = args[2]
	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