Module:Navbox

local lang = mw.getLanguage('en') local p = {}

function p.weapons(frame) if frame == mw.getCurrentFrame then args = require('Module:ProcessArgs').merge(true) else frame = mw.getCurrentFrame end local result = p.doQuery('Weapon',nil,nil) local state = args.state or 'collapsed' return p.renderWeaponNavbox(result, frame, state) end

function p.doQuery(category,class,itype) local result = mw.ext.cargo.query('ItemData',		p.cargoFields(category),		{			where = p.cargoWhere(category,class,itype),			orderBy = 'name',			groupBy = '_pageName',			limit = 200		}	) if not next(result) then return nil else return result end end

function p.cargoFields(category) fields = { '_pageName','name', 'category', 'class', 'type' }	return table.concat(fields,',') end

function p.cargoWhere(category,class,itype) local where = string.format('category="%s"', category) return where end

function p.groupWeapons(result) local grouped = { Axe = {}, Bow = {}, Mace = {}, Polearm = {}, Spear = {}, Gauntlet = {}, Shield = {}, Sword = {}, Chakram = {}, Dagger = {}, Pistol = {} }	for k,v in ipairs(result) do		if not p.isempty(v.class) then group = v.class grouped[group][#grouped[group]+1] = string.format('* %s', v._pageName, v.name) end end return grouped end

function p.renderWeaponNavbox(result, frame, state) groupedItems = p.groupWeapons(result) return frame:expandTemplate{ title = 'Navbox', args = { name = 'Navbox weapons', title = 'Weapon list', bodyclass = 'hlist', state = state, list1 = 'Main Weapons', group2 = 'Axes', list2 = table.concat(groupedItems.Axe, '\n'), group3 = 'Bows', list3 = table.concat(groupedItems.Bow, '\n'), group4 = 'Maces', list4 = table.concat(groupedItems.Mace, '\n'), group6 = 'Polearms', list6 = table.concat(groupedItems.Polearm, '\n'), group8 = 'Spears', list8 = table.concat(groupedItems.Spear, '\n'), group9 = 'Swords', list9 = table.concat(groupedItems.Sword, '\n'),

group10 = 'Gauntlets', list10 = table.concat(groupedItems.Gauntlet, '\n'), list11 = 'Off-Hand Weapons', group12 = 'Shields', list12 = table.concat(groupedItems.Shield, '\n'), group13 = 'Chakrams', list13 = table.concat(groupedItems.Chakram, '\n'), group14 = 'Daggers', list14 = table.concat(groupedItems.Dagger, '\n'), group15 = 'Pistols', list15 = table.concat(groupedItems.Pistol, '\n') }	} end

function p.isempty(s) return s == nil or s == '' or s == 0 or s == false end

return p