Module:PassivesTable

local p = {} local cargo = mw.ext.cargo local Util = require 'Module:Util'

local function isNilOrBlank(value) return (value == nil or value == '') end

local function queryPassive(name) local queryResults = cargo.query('Skills', '_pageName=fullname,Description,SP', {   where = 'Name="' .. name .. '"',    groupBy = '_pageName',    limit = 50  }) if queryResults[1] == nil and name ~= nil and name ~='' then queryResults = end return queryResults end p.queryPassive = queryPassive

local function getFullLevelInfo(levelInfo) if not isNilOrBlank(levelInfo.name) then local level = levelInfo.level local name = levelInfo.name local queryResults = queryPassive(name)

if next(queryResults) ~= nil then local result = queryResults[1] levelInfo.fullname = result.fullname levelInfo.desc = result.Description local cost = result.SP     if cost == '0' then cost = '-' end levelInfo.cost = cost

return levelInfo end end

return nil end

local function makePassivesObject(slot, name1, name2, name3, name4, unlock1, unlock2, unlock3, unlock4) if isNilOrBlank(name1) and isNilOrBlank(name2) and isNilOrBlank(name3) and isNilOrBlank(name4) then return nil end

local levels = { {level = 1, name = name1, unlockRarity = unlock1}, {level = 2, name = name2, unlockRarity = unlock2}, {level = 3, name = name3, unlockRarity = unlock3}, {level = 4, name = name4, unlockRarity = unlock4}, } local passive = { slot = slot, levels = {}, }

local first = true local count = 0 for level,levelInfo in ipairs(levels) do   local fullLevelInfo = getFullLevelInfo(levelInfo) if fullLevelInfo ~= nil then count = count + 1 fullLevelInfo.first = first passive.levels[count] = fullLevelInfo first = false end end

passive.levelCount = count

return passive end

function p._passivesList(args) local passives = { makePassivesObject( 'A',     args.passiveA1,      args.passiveA2,      args.passiveA3,      args.passiveA4,      args.passiveA1Unlock,      args.passiveA2Unlock,      args.passiveA3Unlock,      args.passiveA4Unlock), makePassivesObject( 'B',     args.passiveB1,      args.passiveB2,      args.passiveB3,      args.passiveB4,      args.passiveB1Unlock,      args.passiveB2Unlock,      args.passiveB3Unlock,      args.passiveB4Unlock), makePassivesObject( 'C',     args.passiveC1,      args.passiveC2,      args.passiveC3,      args.passiveC4,      args.passiveC1Unlock,      args.passiveC2Unlock,      args.passiveC3Unlock,      args.passiveC4Unlock) }

local RARITY_TXT = Util.getRarityTexts

-- 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('Description') tbl:tag('th') :wikitext('SP') :css('width', '64px') 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.' } }) tbl:tag('th') :wikitext('Type')

local test = ''

local atLeastOnePassive = false for i = 1, 3 do   local passive = passives[i] if passive ~= nil then atLeastOnePassive = true if passive.levelCount > 0 then -- Go through all the query results for this passive for level,levelInfo in ipairs( passive.levels ) do         local tr = tbl:tag('tr')

-- Name tr:tag('td') :wikitext(  .. levelInfo.name ..  )

-- Description tr:tag('td') :wikitext( levelInfo.desc )

-- SP Cost tr:tag('td') :wikitext( levelInfo.cost )

-- Unlock Rarity local unlockRarity = levelInfo.unlockRarity tr:tag('td'):wikitext(isNilOrBlank(unlockRarity) and '-' or RARITY_TXT[tonumber(unlockRarity)])

-- Type if levelInfo.first then tr:tag('td') :wikitext(..passive.slot..) :attr('rowspan', tostring(passive.levelCount)) end end end else test = test..i..' is missing, ' end end

if (atLeastOnePassive) then return tostring(tbl) else return ' This hero has no Passive skills. ' end end

function p.passivesList(frame) local args = frame.args return p._passivesList(args) end

return p