Fire Emblem Heroes Wiki
Advertisement
Template-info Documentation

Used on every hero page, to specify and show which specials they learn, and when.

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 getColorText = require('Module:Color')._getText

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 '<div>This unit owns no Special skills.</div>'
  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
  local bg = getColorText('th-color1') -- for FandomMobile
  tbl:tag('th'):wikitext('Name'):cssText(bg)
  tbl:tag('th'):wikitext('Cooldown'):cssText(bg)
  tbl:tag('th'):wikitext('Description'):cssText(bg)
  tbl:tag('th'):wikitext('SP'):cssText(bg)
  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.'}}):cssText(bg)
  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.'}}):cssText(bg)

  -- 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._pageName .. '|' .. (q.Name ~= '' and q.Name or q._pageName) .. ']]') -- Name
    tr:tag('td'):wikitext(tonumber(q.Cooldown) or '—') -- Cooldown
    tr:tag('td'):wikitext(Util.isNilOrEmpty(q.Description) and '—' or '<div style="text-align:left">' .. q.Description .. '</div>') -- 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}
Advertisement