Module:HeroList

From Fire Emblem Heroes Wiki
Jump to: navigation, search
Template-info.svg Documentation

Collects all heroes and builds the table shown at Hero List.

local Util = require 'Module:Util'
local List = require 'Module:ListUtil'
local HeroTableBuilder = require 'Module:HeroTableBuilder'
local p = {}
local cargo = mw.ext.cargo
local CargoUtil = require 'Module:CargoUtil'
local HeroUtil = require 'Module:HeroUtil'

local SUFFIXES = {
	story = '[[Story Maps|Story]]',
	ghb = '[[Grand Hero Battle maps|Grand Hero Battle]]',
	tempest = '[[Tempest Trials]]',
	special = '[[:Category:Special Heroes|Special]]',
	legendary = '[[:Category:Legendary Heroes|Legendary]]',
	mythic = '[[:Category:Mythic Heroes|Mythic]]',
--	demoted_240 = '<span title="This Hero\'s rarity changed from 4★-5★, on April 10, 2018." style="border-bottom:0;text-decoration:underline dotted;cursor:help;">*</span>',
}

local getRarityWikitext = function (rarities, properties)
	local wikitexts = {HeroUtil._availabilityText {avail = rarities}}

	-- Get suffix
	for _, p in ipairs(properties) do
		if SUFFIXES[p] then
			wikitexts[#wikitexts + 1] = SUFFIXES[p]
		end
	end

	return table.concat(wikitexts, '<br>')
end

local heroList = function ()
	local ORIGIN_SORT = Util.getOriginSortOrder()

	local heroQueryResult = cargo.query('Units', "_pageName=Page,IFNULL(CONCAT(Name,': ',Title),Name)=Hero,MoveType,WeaponType,Origin,Properties__full", {
		where = "IFNULL(Properties__full,'') NOT LIKE '%enemy%'",
		groupBy = '_pageName',
		limit = 1000,
	})
	local avail = HeroUtil.getLowestRarities {current = true}
	local releaseTimes = HeroUtil.getReleaseTimes {}

	local theUnit = nil
	local builder = HeroTableBuilder.new()

	builder:heroIcon('75px')
	builder:heroLink():css('width', '30%')
	builder:column('Appears in', function (elem)
		elem:attr('data-sort-value', ORIGIN_SORT[theUnit.Origin]):wikitext(('<i>[[%s]]</i>'):format(theUnit.Origin))
	end):css('width', '30%')
	builder:moveType():css('width', '9%')
	builder:weaponType('35px'):css('width', '9%')
	builder:column('Rarities', function (elem)
		elem:wikitext(getRarityWikitext(avail[theUnit.Page], mw.text.split(theUnit.Properties__full, '%s*,%s*')))
	end):css('width', '10%')
	builder:column('Release date', function (elem)
		local heroReleaseTime = releaseTimes[theUnit.Page] and releaseTimes[theUnit.Page]:earliest() or 0x7FFFFFFF
		elem:wikitext(heroReleaseTime < 0x7FFFFFFF and os.date('%Y-%m-%d', heroReleaseTime) or 'N/A')
	end):css('width', '12%')

	for _, v in ipairs(heroQueryResult) do
		theUnit = v
		builder:addHero(v.Page, v.Hero, v.MoveType, v.WeaponType)
	end

	return builder:build():addClass('wikitable'):addClass('default'):css('text-align', 'center'):css('width', '100%')
end

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