Module:SummoningEvent

local cargo = mw.ext.cargo local Util = require 'Module:Util' local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local escq = require 'Module:EscQ'.main1 local superimposeDiv = require 'Module:Superimpose'.div local memoizer = require 'Module:Memoizer'.memoizer

local memoizeHero = memoizer(function (hero)	return cargo.query('Units', "IFNULL(CONCAT(Name,': ',Title),Name)=name,WeaponType,MoveType", { where = ("'%s' IN (WikiName,_pageName)"):format(escq(hero)), groupBy = 'WikiName', })[1] end)

local cacheAllHeroes = function local cache = Hash.from_ipairs(cargo.query('Units', "WikiName,IFNULL(CONCAT(Name,': ',Title),Name)=name,WeaponType,MoveType", { groupBy = 'WikiName', limit = 1000, }), function (v) return v.WikiName, v end) memoizeHero = function (hero) return cache[hero] end end

-- TODO: use UnitType instead (still needs to be lua-only) local makeHeroIconDiv = function (hero) -- We need to query to get the hero's weapon and move type local heroQuery = memoizeHero(hero) if not heroQuery then return mw.html.create('div'):css('width', '120px'):wikitext( .. hero .. ) end

local heroIconDiv = mw.html.create('div'):css('display', 'inline-block'):css('padding', '5px 0') heroIconDiv:node(superimposeDiv(Util.getHeroIcon(heroQuery.name, '90px'), {, 2, 2},		{, 68, 68}))	heroIconDiv:tag('div'):css('width', '140px'):css('margin', 'auto') :wikitext( .. heroQuery.name .. )

return heroIconDiv end

local makeEventTable = function (event, extratitle, extratext) local heroes = List.select(mw.text.split(event.Units, '%s*;%s*'), function (v) return v ~= '' end)

-- Initialize the table local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):css('text-align', 'center'):css('width', '100%')

-- Header - Name of Summoning Event tbl:tag('tr'):tag('th'):attr('colspan', '3'):tag('b'):wikitext(event.Name)

-- Image of Summoning Event Banner and text link to event page local heroTR = tbl:tag('tr') heroTR:tag('td'):css('text-align', 'center'):css('width', '25%'):attr('rowspan', tostring(extratext and 4 or 3)) :wikitext((' %s'):format( Util.mf(mw.ustring.gsub(event.Page, ' %(Focus%)', '')), event.Page, event.Name))

-- Table Cell w/ Summoning Event Featured Units Label heroTR:tag('th'):css('width', '10%'):wikitext('Featured units')

-- Table Cell w/ Hero Icons of the Featured Units local heroIconTD = heroTR:tag('td'):css('width', '55%') :tag('div'):css('width', '100%'):css('display', 'flex'):css('justify-content', 'space-around'):css('flex-flow', 'wrap') for _, hero in ipairs(heroes) do		heroIconTD:node(makeHeroIconDiv(hero):css('flex-basis', '16.666666%')) end

-- Start Date of Summoning Event tbl:tag('tr'):tag('th'):wikitext('Start date'):done :tag('td'):wikitext(event.DateStart)

-- End Date of Summoning Event tbl:tag('tr'):tag('th'):wikitext('End date'):done :tag('td'):wikitext(event.DateEnd)

if extratext then tbl:tag('tr'):tag('th'):wikitext(extratitle):done :tag('td'):wikitext(extratext) end

return tbl end

-- for Module:SummoningEventList local table_ = function (args) return tostring(makeEventTable({ Page = args.page, Name = args.name, DateStart = args.startDate, DateEnd = args.endDate, Units = type(args.heroes) == 'table' and table.concat(args.heroes, ';') or args.heroes, }, args.extratitle, args.extratext)) end

return require 'Module:MakeMWModule'.makeMWModule { cacheAllHeroes = cacheAllHeroes, table = table_, main = main, -- TODO: merge Module:SummoningFocus into here }