Module:Ability

-- --Start Module local p = {} local loader = require('Module:Loader') local getArgs = require('Module:Arguments').getArgs

local string, yesno = loader.require('String', 'Yesno')

--Define basic styling for each module local styling = { ['abilityName'] = { name = 'Ability', color = '#FFA500', noshow = true, },	['full_set'] = { name = 'Full Set Bonus', color = '#FFA500' },	['piece'] = { name = 'Piece Bonus', color = '#FFA500' },	['tiered_armor'] = { name = 'Tiered Armor Bonus', color = '#FFA500' },	['ability'] = { name = 'Ability', color = '#FFA500' },	['secret'] = { name = 'Secret', color = '#FF0000' }, } -- Apply fomatting function applyFormat(text, color) local ifSecret = styling['secret'] if color == ifSecret.color then return ' .. ifSecret.name .. ' ' .. text .. ' 	else return ' .. text .. ' 	end end

- -- Template:Ability -- -- Formats the ability - function p.ability(frame) local args = getArgs(frame) local text = args[1] local secret = args['secret'] or args['s'] secret = yesno(secret) return p._ability(text, secret, 'ability') end - -- Template:Full Set Bonus -- --Formats the full set bonus - function p.fullSetBonus(frame) local args = getArgs(frame) local text = args[1] local secret = args['secret'] or args['s'] secret = yesno(secret) return p._ability(text, secret, 'full_set') end - -- Template:Piece Bonus -- -- Formats the piece bonus - function p.pieceBonus(frame) local args = getArgs(frame) local text = args[1] local secret = args['secret'] or args['s'] secret = yesno(secret) return p._ability(text, secret, 'piece') end - -- Template:Tiered Armor Bonus -- -- Formats the tiered armor bonus - function p.tieredArmorBonus(frame) local args = getArgs(frame) local text = args[1] local secret = args['secret'] or args['s'] secret = yesno(secret) return p._ability(text, secret, 'tiered_armor') end - -- Template:AbilityName -- -- Formats just the text, or returns 'AbilityName' string if no text is provided - function p.abilityName(frame) local args = getArgs(frame) local text = args[1] local secret = args['secret'] or args['s'] secret = yesno(secret) return p._ability(text, secret, 'abilityName') end

--Main function processing the information provided by template access points function p._ability(text, secret, outputType) --check if outputType is valid. if invalid, return error outputType = styling[outputType] or styling.ability --apply correct color local textColor if secret then textColor = styling['secret']['color'] else textColor = outputType.color end --check if ability name is not present. if so, leave only the template name. e.g just if not text then return applyFormat(outputType.name, textColor) else --if the outputType == 'ability', then format just the text. if not, then do the full formating if text:match('[Aa]bilit[yi]e?s?') or outputType.noshow == true and not secret then return applyFormat(text, textColor) else return applyFormat(outputType.name .. ': ' .. text, textColor) end end end

--Finish Module return p