Module:Infobox ability

local getArgs = require('Module:Arguments').getArgs local formatOrbIcon = require("Module:Orb")._main local formatJobType = require("Module:Job type")._main

local lower = mw.ustring.lower local lang = mw.getContentLanguage local title = mw.title.getCurrentTitle local namespace = title.namespace local pagename = title.pagename

-- TODO: Use CSS. local glow_styles = { fire = "text-shadow: 1px 1px 4px #f35076, -1px -1px 4px #fd3c3c;", water = "text-shadow: 1px 1px 4px #436ea5, -1px -1px 4px #6eace0;", wind = "text-shadow: 1px 1px 4px #157b55, -1px -1px 4px #58d89f;", earth = "text-shadow: 1px 1px 4px #8c6c3f, -1px -1px 4px #e0bf8f;", light = "text-shadow: 1px 1px 4px #fcfae0, -1px -1px 4px #fff69e;", dark = "text-shadow: 1px 1px 4px #d7b6f9, -1px -1px 4px #993bfd;", life = "text-shadow: 1px 1px 4px #e811b1, -1px -1px 4px #e689e1;", }

local function formatName(element, name) local element = lower(element or "") local name = name or "" if element == "restoration" then element = "life" end local glow_style = glow_styles[element] or '' local root = mw.html.create("div") :cssText("font-size:1.3em") :cssText(glow_style) :wikitext(formatOrbIcon{element}.." "..name) return tostring(root) end

local p = {} function p.main(frame) local args = getArgs(frame, {		wrappers = 'Template:Infobox ability'	}) return p._main(args) end

function p._main(args) local name = args.name or pagename or "" local element = lower(args.element or "") local jobtype = lower(args.jobtype or args.job or "") local target = args.target or args.range or "" local info = args.info or args.description or "" local stats = { ["Orbs"] = {}, ["Attack"] = {}, ["Break Power"] = {}, ["Crit Chance"] = {}, ["Cooldown"] = {}, }	local has_orbs = false local has_attack = false local has_break = false local has_crit = false local has_cooldown = false local min_rarity local max_rarity for i=1,5 do		local orb = args['orbs'..i] or args[i..'orbs'] or '' local atk = args['attack'..i] or args[i..'attack'] or '' local brk = args['break'..i] or args[i..'break'] or '' local crit = args['crit'..i] or args[i..'crit'] or '' local cd = args['cooldown'..i] or args[i..'cooldown'] or '' if orb ~= "" then orb = formatOrbIcon({element, size=15}) .. '&times;' .. orb has_orbs = true if min_rarity == nil then min_rarity = i			end max_rarity = i		end if atk ~= "" then has_attack = true end if brk ~= "" then has_break = true end if crit ~= "" then has_crit = true end if cd ~= "" then has_cooldown = true end stats["Orbs"][i] = orb stats["Attack"][i] = atk stats["Break Power"][i] = brk stats["Crit Chance"][i] = crit stats["Cooldown"][i] = cd	end local lesser = args.advancedfm or '' local greater = args.advancedto or '' if namespace == 0 or lower(args.demospace or '') == 'main' then -- Cargo storage local cargo_job_types = { warrior = "Warrior", graff = "Warrior", mage = "Mage", meia = "Mage", ranger = "Ranger", sarah = "Ranger", monk = "Monk", sophie = "Monk", support = "Support", healer = "Support", }		local cargo_data = { _table = 'abilities', name = name, element = lang:ucfirst(element), job_type = cargo_job_types[jobtype], target = lang:ucfirst(tostring(target):lower), description = info --mw.text.nowiki(info), }		mw.logObject(cargo_data, "Storing cargo data") local frame = mw.getCurrentFrame frame:callParserFunction('#cargo_store:', cargo_data) end

-- root node local root = mw.html.create -- infobox local headers = {} if has_orbs or has_attack or has_break or has_crit or has_cooldown then headers[1] = "" stats[""] = {} for i=1,5 do			stats[""][i] = "★"..i		end if has_orbs then headers[#headers+1] = "Orbs" end if has_attack then headers[#headers+1] = "Attack" end if has_break then headers[#headers+1] = "Break Power" end if has_crit then headers[#headers+1] = "Crit Chance" end if has_cooldown then headers[#headers+1] = "Cooldown" end end local ibox = mw.html.create("div") :cssText("box-sizing:border-box;background-color:#2fa3bc; box-shadow:0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24); border-radius:4px; padding:10px; width:300px;float:right; margin:0 10px 10px; color:white;") :tag("div") :cssText("text-align:right; line-height:95%; font-size:95%; border-bottom:2px solid rgba(255, 255, 255, 0.5);") :wikitext("Ability") :done :node(formatName(element, name)) :tag("div") --:cssText("background:#356d9e") :cssText("padding-left:6px") :wikitext(formatJobType{jobtype} .. info) :done if #headers > 0 then local stats_table = mw.html.create("table") for _,key in ipairs(headers) do			local row = stats_table:tag("tr") :tag("th") :cssText("width:80px") :wikitext(key):done for i=min_rarity,max_rarity do				local tag_name = "td" if key == "" then tag_name = "th" end row:tag(tag_name) :cssText("width:40px") :wikitext(stats[key][i]) end end stats_table:allDone

ibox:tag("div") :cssText("text-align:center; line-height:95%; border-bottom:1px solid rgba(255, 255, 255, 0.5); font-size:95%; padding-top:6px;") :wikitext("Stats") :done :tag("div") :node(stats_table) :done end if lesser ~= "" then ibox:tag("div") :cssText("text-align:center; line-height:95%; border-bottom:1px solid rgba(255, 255, 255, 0.5); font-size:95%; padding-top:6px;") :wikitext("Advanced From") :done :tag("div") :wikitext(lesser) :done end if greater ~= "" then ibox:tag("div") :cssText("text-align:center; line-height:95%; border-bottom:1px solid rgba(255, 255, 255, 0.5); font-size:95%; padding-top:6px;") :wikitext("Advanced To") :done :tag("div") :wikitext(greater) :done end root:node(ibox) -- auto cats if namespace == 0 or lower(args.demospace or '') == 'main' then root:wikitext("") if element == "fire" or element == "water" or element == "wind" or element == "earth" or element == "light" or element == "dark" then root:wikitext("") elseif element == "restoration" or element == "life" then -- Official summon chances info uses "Restoration" as element name. root:wikitext("") -- "Life" is the orb-element, as in "Life Orbs". root:wikitext("") end if jobtype == "warrior" or jobtype == "mage" or jobtype == "ranger" or jobtype == "monk" then root:wikitext("") elseif jobtype == "healer" or jobtype == "support" then -- Official name. root:wikitext("") elseif jobtype == "meia" then root:wikitext("") root:wikitext("") elseif jobtype == "sarah" then -- will these ever be used? Who knows root:wikitext("") root:wikitext("") end end return tostring(root) end return p