Module:Ability

-- --Start Module local p = {} local _error = require('Module:String')._error --Get Other Required Modules local getArgs = require(Module:Arguments).getArgs local yesno = require(Module:Yesno)

--Define basic styling for each module local styling = { ['abilityName'] = { name="Ability​", color="#FFA500" },	['full_set'] = { name="Full Set Bonus", color="#FFA500" },	['piece'] = { name="Piece 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 " " else return " " 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: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'] textColor = textColor.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.name == "Ability​" and not secret then return applyFormat(text, textColor) else return applyFormat(outputType.name .. ": " .. text, textColor) end end end

--Finish Module return p