Module:SpecialsTable

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

local MAX_SPECIALS = 4

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

local specials = List.select(List.generate(MAX_SPECIALS, 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 #specials == 0 then return ' This unit owns no Special skills. ' end local specialsQueryResult = List.map(specials, function (w)   local queryResult = cargo.query('Skills', '_pageName,Cooldown,Description,SP,Name', { where = ("Scategory='special' AND _pageName='%s'"):format(escq(w.skill)), groupBy = '_pageName', limit = 1, })   return #queryResult > 0 and queryResult[1] or {_pageName = w.skill, SpecialName = 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('Cooldown') 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 specials in the query result for i, q in ipairs(specialsQueryResult) do   local as = specials[i] local tr = tbl:tag('tr')

tr:tag('td'):wikitext( .. (q.Name ~=  and q.Name or q._pageName) .. '') -- Name tr:tag('td'):wikitext(tonumber(q.Cooldown) or '—') -- Cooldown tr:tag('td'):wikitext(q.Description == '' and '—' or 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 {specialsList = specialsList}