Module:Ability

local p = {} local cargo = mw.ext.cargo

function p.get_description(PAGENAME) local tables = "abilities" local fields = "description" local args = { where = string.format("_pageName = %q", PAGENAME), groupBy = "_pageName", }	local abilities = cargo.query(tables, fields, args) local count = #abilities mw.log(string.format("Number of abilities with PAGENAME %q: %d", PAGENAME, count)) mw.logObject(abilities) if count == 1 then return abilities[1].description elseif count == 0 then return nil else return ' Too many results for '..PAGENAME..' ' end end

function p.get_stats(PAGENAME) local tables = "ability_stats" local fields = "level, attack, break_power, crit_chance, cooldown" local args = { where = string.format("_pageName = %q", PAGENAME), }	local results = cargo.query(tables, fields, args) local row_count = #results mw.log(string.format("Number of stat rows for ability %q: %d", PAGENAME, row_count)) mw.logObject(results) return results end

function p._query(tpl_args) local PAGENAME = tpl_args[1] or mw.title.getCurrentTitle.fullText local description = p.get_description(PAGENAME) local stats = p.get_stats(PAGENAME) if not description then description = "No description found on "..PAGENAME.."" end local root = mw.html.create("") root:tag("blockquote"):wikitext(description):done if #stats > 0 then local wikitable = root:tag("table") :addClass("wikitable") :tag("tr") :tag("th"):wikitext("ALv."):done :tag("th"):wikitext("Attack"):done :tag("th"):wikitext("Break Power"):done :tag("th"):wikitext("Crit Chance"):done :tag("th"):wikitext("Cooldown"):done for i,stat in ipairs(stats) do			wikitable:tag("tr") :tag('td'):wikitext(stat.level):done :tag('td'):wikitext(stat.attack):done :tag('td'):wikitext(stat.break_power):done :tag('td'):wikitext(stat.crit_chance):done :tag('td'):wikitext(stat.cooldown):done end else root:wikitext("No stats found on "..PAGENAME..""):done end root = tostring(root) mw.log(root) return root end

function p.query(frame) local tpl_args = require("Module:Arguments").getArgs(frame) return p._query(tpl_args) end

return p