Module:TempestTrialsTable

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

Displays a list of Tempest Trials events.

Parameters[edit source]

  • past: If true, displays past events instead of current or upcoming events.
local Util = require 'Module:Util'
local List = require 'Module:ListUtil'
local cargo = mw.ext.cargo
local CargoUtil = require 'Module:CargoUtil'
local toboolean = require 'Module:Bool'.toboolean

local main = function (args, frame)
	local tts = cargo.query('TempestTrials', '_pageName,Name,BonusHeroes__full=bh,StartTime=t0,EndTime=t1,Maps', {
		where = toboolean(args.past) and 'DATEDIFF(EndTime,NOW())<=0' or 'DATEDIFF(EndTime,NOW())>0',
		orderBy = 't0',
		limit = 100,
	})
	if #tts == 0 then
		return 'Currently none.'
	end
	for _, v in ipairs(tts) do
		v.bh = mw.text.split(v.bh, '%s*,%s*')
	end

	local ttRewards = List.group_by(cargo.query('TempestTrialsRewards=TTR,Units', "TTR._pageName=page,Item,IFNULL(CONCAT(Name,': ',Title),Name)=Unit,Rarity,SacredSeal,Accessory", {
		join = 'TTR.Unit=Units.WikiName',
		where = "NOT (Kind='item' AND (Item='Light\\'s Blessing' OR Item NOT LIKE '% Blessing')) AND NOT (TTR.Unit IS NOT NULL AND TTR.Kind!='unit')",
		orderBy = 'page,IF(Unit IS NOT NULL,1,IF(Item IS NOT NULL,2,3)),Score',
		limit = 5000,
	}), function (v) return v.page end)

	local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):css('text-align', 'center')
	local row = tbl:tag('tr')
	row:tag('th'):wikitext('Name')
	row:tag('th'):wikitext('Featured bonus Heroes')
	row:tag('th'):wikitext(frame:expandTemplate {title = 'Hover', args = {'Notable rewards', 'Rewarded Heroes, blessings, and Sacred Seals'}})
	row:tag('th'):wikitext('Maps')
	row:tag('th'):wikitext('Event dates')

	for _, tt in ipairs(tts) do
		row = tbl:tag('tr')
		local cell = row:tag('td')
		cell:wikitext(frame:expandTemplate {title = 'Banner TT', args = {bannerName = tt.Name, link = tt._pageName}})

		cell = row:tag('td')
		for i, hero in ipairs(tt.bh) do
			if i > 1 then
				cell:wikitext(i % 4 == 1 and '<br>' or ' ')
			end
			cell:wikitext(Util.getHeroIcon(hero, '40px'))
		end

		local rewards = ttRewards[tt._pageName] or {}
		cell = row:tag('td')
		for i, v in ipairs(rewards) do
			if i > 1 then
				cell:wikitext(i % 3 == 1 and '<br>' or ' ')
			end
			if v.Unit ~= '' then
				cell:wikitext(frame:expandTemplate {title = 'IconFrame', args = {hero = v.Unit, rarity = v.Rarity}})
			elseif v.SacredSeal ~= '' then
				cell:wikitext(frame:expandTemplate {title = 'SkillIcon', args = {v.SacredSeal, size = '40px'}})
			elseif v.Item ~= '' then
				cell:wikitext(frame:expandTemplate {title = 'ItemIcon', args = {v.Item, size = '40px'}})
			end
		end

		cell = row:tag('td')
		cell:wikitext(tt.Maps)

		cell = row:tag('td')
		cell:wikitext(frame:expandTemplate {title = 'HT', args = {Util.formatTime(CargoUtil.parse_datetime(tt.t0))}})
		cell:wikitext(' –<br>')
		cell:wikitext(frame:expandTemplate {title = 'HT', args = {Util.formatTime(CargoUtil.parse_datetime(tt.t1))}})
	end

	return tostring(tbl)
end

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