Module:TapBattleTable

local cargo = mw.ext.cargo local list = require 'Module:ListUtil' local datetime = require 'Module:DatetimeUtil' local toboolean = require 'Module:Bool'.toboolean local rewardText = require 'Module:RewardText'._main

local upcoming = function (args, frame) local tbs = cargo.query('TapBattles', '_pageName,WikiName,Name,BGM__full=BGM,BGMBoss__full=BGMBoss,StartTime=t0,EndTime=t1', {		where = 'DATEDIFF(EndTime,NOW)>=0',		orderBy = 't0',		limit = 100,	}) if #tbs == 0 then return 'Currently none.' end for _, v in ipairs(tbs) do		v.BGM = mw.text.split(v.BGM, '%s*,%s*') list.map_self(v.BGM, function (bgm) return frame:expandTemplate { title = 'BGMPage', args = { bgm } } end) v.BGMBoss = mw.text.split(v.BGMBoss, '%s*,%s*') list.map_self(v.BGMBoss, function (bgm) return frame:expandTemplate { title = 'BGMPage', args = { bgm } } end) end local TBRewards = list.group_by(cargo.query('TapBattleRewards=R,Units', R.WikiName=WikiName,			IF (Item IS NOT NULL, CONCAT('{kind=', Item, ';count=', SUM(Amount), '}'),			IF (Unit IS NOT NULL, CONCAT('{hero=', IFNULL(CONCAT(Name,': ',Title), Name), ';rarity=', Rarity, '}'),			IF (SacredSeal IS NOT NULL, CONCAT('{seal=', SacredSeal, '}'), 			IF (Accessory IS NOT NULL, CONCAT('{accessory=', Accessory, '}'), '{}'))))=reward, { join = 'R.Unit=Units.WikiName', orderBy = R.WikiName,If(Item='Orb', 1,								IF (Item LIKE '%Shard', 3,								IF (Item LIKE '%Crystal', 4,								IF (Item LIKE 'Great%Badge', 6,								IF (Item LIKE '%Badge', 5, 2))))), limit = 5000, groupBy = "R.WikiName,Item,R.Unit,SacredSeal,Accessory" }), function (v) return v.WikiName end)

local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):css('text-align', 'center') local row = tbl:tag('tr') row:tag('th'):wikitext('Event Name') row:tag('th'):css('max-width', '30%'):wikitext('Rewards') row:tag('th'):wikitext(' Background Music ') row:tag('th'):wikitext('Boss Music') row:tag('th'):wikitext('Event Dates')

for _, tb in ipairs(tbs) do		row = tbl:tag('tr') local cell = row:tag('td') cell:wikitext(frame:expandTemplate { title = 'Banner Event', args = {			bannerType = 'Tap Battle', text1 = tb.Name, link = tb._pageName, fontSize = 4		} })

local rewards = TBRewards[tb.WikiName] or {} row:tag('td'):wikitext(rewardText({'[' .. list.reduce(list.sub(rewards, 2), function (s1, s2) return s1 .. ';' .. s2.reward end, rewards[1].reward) .. ']'}, frame)) row:tag('td'):wikitext(list.reduce(tb.BGM, function (s, s2) return s .. ' ' .. s2 end)) row:tag('td'):wikitext(list.reduce(tb.BGMBoss, function (s, s2) return s .. ' ' .. s2 end))

row:tag('td'):wikitext(datetime.ht_range(tb.t0, tb.t1)) end return tostring(tbl) end

local past = function (args, frame) local tbs = cargo.query('TapBattles',		"_pageName,GROUP_CONCAT(WikiName ORDER BY StartTime SEPARATOR ',')=WikiName,Name,BGM__full=BGM,BGMBoss__full=BGMBoss,GROUP_CONCAT(StartTime ORDER BY StartTime SEPARATOR ',')=t0,GROUP_CONCAT(EndTime ORDER BY StartTime SEPARATOR ',')=t1", {		where = 'DATEDIFF(EndTime,NOW)<0',		orderBy = 't0',		limit = 100,		groupBy = '_pageName',	}) for _, v in ipairs(tbs) do		v.BGM = mw.text.split(v.BGM, '%s*,%s*') list.map_self(v.BGM, function (bgm) return frame:expandTemplate { title = 'BGMPage', args = { bgm } } end) v.BGMBoss = mw.text.split(v.BGMBoss, '%s*,%s*') list.map_self(v.BGMBoss, function (bgm) return frame:expandTemplate { title = 'BGMPage', args = { bgm } } end) v.WikiName = mw.text.split(v.WikiName, '%s*,%s*') v.t0 = mw.text.split(v.t0, '%s*,%s*') v.t1 = mw.text.split(v.t1, '%s*,%s*') v.t = list.map(v.t0, function (t, i) return datetime.ht_range(t, v.t1[i]) end) end local TBRewards = list.group_by(cargo.query('TapBattleRewards=R,Units', R.WikiName=WikiName,			IF (Item IS NOT NULL, CONCAT('{kind=', Item, ';count=', SUM(Amount), '}'),			IF (Unit IS NOT NULL, CONCAT('{hero=', IFNULL(CONCAT(Name,': ',Title), Name), ';rarity=', Rarity, '}'),			IF (SacredSeal IS NOT NULL, CONCAT('{seal=', SacredSeal, '}'), 			IF (Accessory IS NOT NULL, CONCAT('{accessory=', Accessory, '}'), '{}'))))=reward, { join = 'R.Unit=Units.WikiName', orderBy = R.WikiName,If(Item='Orb', 1,								IF (Item LIKE '%Shard', 3,								IF (Item LIKE '%Crystal', 4,								IF (Item LIKE 'Great%Badge', 6,								IF (Item LIKE '%Badge', 5, 2))))), limit = 5000, groupBy = "R.WikiName,Item,R.Unit,SacredSeal,Accessory" }), function (v) return v.WikiName end) local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):css('text-align', 'center') local row = tbl:tag('tr') row:tag('th'):wikitext('Event Name') row:tag('th'):css('max-width', '20%'):wikitext('Original Rewards') row:tag('th'):css('max-width', '20%'):wikitext('Encore Rewards') row:tag('th'):wikitext(' Background Music ') row:tag('th'):wikitext('Boss Music') row:tag('th'):wikitext('Event Dates')

for name, tb in pairs(tbs) do		row = tbl:tag('tr') local cell = row:tag('td') cell:wikitext(frame:expandTemplate { title = 'Banner Event', args = {			bannerType = 'Tap Battle', text1 = tb.Name, link = tb._pageName, fontSize = 4		} })

local rewards = TBRewards[tb.WikiName[1]] or {} row:tag('td'):wikitext(rewardText({'[' .. list.reduce(list.sub(rewards, 2), function (s1, s2) return s1 .. ';' .. s2.reward end, rewards[1].reward) .. ']'}, frame)) rewards = TBRewards[tb.WikiName[2]] or {} row:tag('td'):wikitext(rewardText({'[' .. (rewards[1] and list.reduce(list.sub(rewards, 2), function (s1, s2) return s1 .. ';' .. s2.reward end, rewards[1].reward) or '') .. ']'}, frame)) row:tag('td'):wikitext(list.reduce(tb.BGM, function (s, s2) return s .. ' ' .. s2 end)) row:tag('td'):wikitext(list.reduce(tb.BGMBoss, function (s, s2) return s .. ' ' .. s2 end))

row:tag('td'):wikitext(list.reduce(tb.t, function (s1, s2) return s1 .. ' ' .. s2 end)) end return tostring(tbl) end

return require 'Module:MakeMWModule'.makeMWModule { upcoming = upcoming, past = past, }