Module:AssistsTable

local p = {} local cargo = mw.ext.cargo local getArgs = require 'Module:Arguments'.getArgs local Util = require('Module:Util') local ListUtil = require 'Module:ListUtil' local escq = Util.escq

local MAX_ASSISTS = 4

local assistsList = function (args) local RARITY_TXT = Util.getRarityTexts

local assists = ListUtil.select(ListUtil.generate(MAX_ASSISTS, function (i) return Util.isNilOrEmpty(args[i * 3 - 2]) and {} or { skill = args[i * 3 - 2], default = tonumber(args[i * 3 - 1]), unlock = tonumber(args[i * 3]), } end), function (x) return not Util.isNilOrEmpty(x.skill) end) if #assists == 0 then return ' This Hero has no Assist skills. ' end local assistsQueryResult = ListUtil.map(assists, function (w)   local queryResult = cargo.query('Skills', '_pageName,Name,UseRange,Description,SP', { where = ("Scategory='assist' AND _pageName='%s'"):format(escq(w.skill)), groupBy = '_pageName', limit = 1, })   return #queryResult > 0 and queryResult[1] or {_pageName = w.skill, AssistName = w.skill}  end)

-- Initialize the table local tbl = mw.html.create('table') :addClass('wikitable default unsortable skills-table') :css('text-align','center')

-- Table Headers tbl:tag('th'):wikitext('Name') tbl:tag('th'):wikitext('Range') tbl:tag('th'):wikitext('Description') tbl:tag('th'):wikitext('SP') tbl:tag('th'):wikitext(mw.getCurrentFrame:expandTemplate{title = 'Hover', args = {'Default',   'Skills are listed at the lowest rarity they are automatically learned at, regardless of whether or not the Hero can be obtained at that rarity.'}}) tbl:tag('th'):wikitext(mw.getCurrentFrame:expandTemplate{title = 'Hover', args = {'Unlock',   'Skills are listed at the lowest rarity they can be learned at, regardless of whether or not the Hero can be obtained at that rarity.'}})

-- Go through all the assists in the query result for i, q in ipairs(assistsQueryResult) do   local as = assists[i] local tr = tbl:tag('tr')

tr:tag('td'):wikitext( .. (q.Name or q._pageName) .. ) -- Name tr:tag('td'):wikitext(tonumber(q.UseRange) or '-') -- Range tr:tag('td'):wikitext(Util.returnDefaultIfEmpty(q.Description)) -- Effect local cost = tonumber(q.SP) or '-' tr:tag('td'):wikitext(cost == 0 and '-' or cost) -- SP   tr:tag('td'):wikitext(RARITY_TXT[as.default] or '-') -- Default tr:tag('td'):wikitext(RARITY_TXT[as.unlock] or '-') -- Unlock end return tostring(tbl) end

return require 'Module:MakeMWModule'.makeMWModule {assistsList = assistsList}