Module:Gear attribute

local categorization = require('Module:Categorization') local utils = require('Module:Utils') local yesno = require('Dev:Yesno')

local categorize = categorization.categorize_in_namespaces('Catalog')

local p = {}

local gear_attributes = { Melee = { category = "Melee weapons", icon = "Melee gear attribute icon.svg" },   Ranged = { category = "Ranged weapons", icon = "Ranged gear attribute icon.svg" },   Explosive = { category = "Explosives", icon = "Explosive gear attribute icon.svg" },   Building = { category = "Building tools", icon = "Building gear attribute icon.svg" },   ["Power up"] = { category = "Power ups", icon = "Power up gear attribute icon.svg" },   Navigation = { category = "Navigation enhancers", icon = "Navigation gear attribute icon.svg" },   Musical = { category = "Musical instruments", icon = "Musical gear attribute icon.svg" },   Social = { category = "Social items", icon = "Social gear attribute icon.svg" },   Transport = { category = "Personal transports", icon = "Transport gear attribute icon.svg" } }

function p._format_gear_attribute(args) if args.gear_attribute then local gear_attribute_string = args.gear_attribute:lower -- Use the lowercase string for comparisons. if gear_attribute_string == 'melee weapon' then gear_attribute_string = 'melee' elseif gear_attribute_string == 'ranged weapon' then gear_attribute_string = 'ranged' elseif gear_attribute_string == 'building tool' then gear_attribute_string = 'building' elseif gear_attribute_string == 'navigation enhancer' then gear_attribute_string = 'navigation' elseif gear_attribute_string == 'musical instrument' then gear_attribute_string = 'musical' elseif gear_attribute_string == 'social item' then gear_attribute_string = 'social' elseif gear_attribute_string == 'personal transport' then gear_attribute_string = 'transport' end for attribute_name, attribute_info in next, gear_attributes do           if attribute_name:lower == gear_attribute_string then local output = "" if attribute_info.icon then output = output .. " "               end output = output .. attribute_name if yesno(args.categorize) and attribute_info.category then output = output .. categorize(attribute_info.category) end return output end end -- If the function didn't return in the loop, the gear_attribute string corresponded to none of the recognized gear attributes. return error("Invalid gear type") end end

p.format_gear_attribute = utils.make_wrapper_function(p._format_gear_attribute)

function p._enumerate_gear_attributes(args) if args.gear_attributes then local output = "" -- If there are multiple gear attributes, list them. -- Otherwise, we want to format the only gear attribute without putting it in a list. if args.gear_attributes:find('/') or args.gear_attributes:find(',') then for gear_attribute in args.gear_attributes:gmatch('%s*([^/,]+)') do               output = output .. "\n* " .. p._format_gear_attribute {gear_attribute = gear_attribute, categorize = args.categorize} end output = output:sub(2) -- Remove the initial newline. else output = p._format_gear_attribute {gear_attribute = args.gear_attributes, categorize = args.categorize} end return output end end

p.enumerate_gear_attributes = utils.make_wrapper_function(p._enumerate_gear_attributes)

return p