Module:ChainChallengeList

local cargo = mw.ext.cargo local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local Datetime = require 'Module:DatetimeUtil'

local book = function (args, frame) local ROMAN_NUMERAL = {'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X'} local booknum = tonumber(args[1]) local maps = cargo.query('Maps=M,MapDates=D', 'M.Map=map,M.MapGroup=group,M.StageTitle=name,M._pageName=page,D.StartTime=t0', {		join = 'M._pageName=D._pageName',		where = ("M.MapGroup LIKE 'Chain Challenge%%' AND M.BookGroup='%s'"):format('Book ' .. ROMAN_NUMERAL[booknum]),		orderBy = 'map',		limit = 300,	}) local mapGroups = List.group_by(maps, function (v) return v.group end)

local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):css('text-align', 'center') local row = tbl:tag('tr') row:tag('th'):attr('colspan', '3'):attr('scope', 'colgroup'):wikitext('Chain Challenges') row:tag('th'):wikitext('Release date')

local group = 1 for _, vs in Hash.sorted_pairs(mapGroups, function (vs1, vs2) return vs1[1].map < vs2[1].map end) do		local fname = ('ST_C%02d%02d.webp'):format(booknum == 1 and 0 or booknum, group) row = tbl:tag('tr') for i = 1, 3 do			local cell = row:tag('td') if vs[i] then cell:wikitext(frame:expandTemplate {title = 'Banner CC', args = {file = fname, text = vs[i].name, link = vs[i].page, difficulty = 'Normal'}}) end end row:tag('td'):wikitext(Datetime.ht(vs[1].t0)) if booknum <= 3 then group = group + 1 elseif booknum == 4 then group = group == 1 and 4 or (group == 12 and 13 or (group + 2)) else group = group + 2 end end

return tbl end

local paralogue = function (_, frame) local maps = cargo.query('Maps=M,MapDates=D', 'M.Map=map,M.MapGroup=group,M.StageTitle=name,M._pageName=page,D.StartTime=t0', {		join = 'M._pageName=D._pageName',		where = "M.MapGroup LIKE 'Chain Challenge%' AND M.BookGroup IS NULL",		orderBy = 'map',		limit = 300,	}) local mapGroups = List.group_by(maps, function (v) return v.group end)

local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):css('text-align', 'center') local row = tbl:tag('tr') row:tag('th'):attr('colspan', '3'):attr('scope', 'colgroup'):wikitext('Chain Challenges') row:tag('th'):wikitext('Release date')

local group = 1 for _, vs in Hash.sorted_pairs(mapGroups, function (vs1, vs2) return vs1[1].map < vs2[1].map end) do		local fname = ('ST_CX%03d.webp'):format(group) row = tbl:tag('tr') for i = 1, 3 do			local cell = row:tag('td') if vs[i] then cell:wikitext(frame:expandTemplate {title = 'Banner CC', args = {file = fname, text = vs[i].name, link = vs[i].page, difficulty = 'Normal'}}) end end row:tag('td'):wikitext(Datetime.ht(vs[1].t0)) group = group + 1 end

return tbl end

return require 'Module:MakeMWModule'.makeMWModule { book = book, paralogue = paralogue, }