FANDOM


local utils = require('Module:Utils')
local yesno = require('Dev:Yesno')
 
local categorize = utils.categorize('Catalog')
 
local p = {}
 
local gear_types = {'Melee weapon', 'Ranged weapon', 'Explosive', 'Building tool', 'Power up', 'Navigation enhancer', 'Musical instrument', 'Social item', 'Personal transport'}
 
function p._format_gear_type(args)
	if args.gear_type then
		local gear_type_string = args.gear_type:lower() -- Use the lowercase string for comparisons.
		for _, gear_type in next, gear_types do
			if gear_type:lower() == gear_type_string then
				local output = "[[File:" .. gear_type .. " icon.png]] " .. gear_type
				if yesno(args.categorize) then
					output = output .. categorize(gear_type .. "s")
				end
				return output
			end
		end
		-- If the function didn't return in the loop, the gear_type string corresponded to none of the recognized gear types.
		return error("Invalid gear type")
	end
end
 
p.format_gear_type = utils.make_wrapper_function(p._format_gear_type)
 
function p._enumerate_gear_types(args)
	if args.gear_types then
		local output = ""
		-- If there are multiple gear types, list them.
		-- Otherwise, we want to format the only gear type without putting it in a list.
		if args.gear_types:find('/') or args.gear_types:find(',') then
			for gear_type in args.gear_types:gmatch('%s*([^/,]+)') do
				output = output .. "\n* " .. p._format_gear_type {gear_type = gear_type, categorize = args.categorize}
			end
			output = output:sub(2) -- Remove the initial newline.
		else
			output = p._format_gear_type {gear_type = args.gear_types, categorize = args.categorize}
		end
		return output
	end
end
 
p.enumerate_gear_types = utils.make_wrapper_function(p._enumerate_gear_types)
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.