Module:GameUtil
Documentation for this module may be created at Module:GameUtil/doc
local util_args = require('Module:ArgsUtil')
local util_footnote = require('Module:FootnoteUtil')
local util_table = require('Module:TableUtil')
local util_text = require('Module:TextUtil')
local util_toggle = require('Module:ToggleUtil')
local i18n = require('Module:i18nUtil')
local h = {}
local p = {
players_per_team = 4,
side_names = {
'Blue', 'Red',
['1'] = 'Blue',
['2'] = 'Red'
},
years = { 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 },
store_player_league_history = true, -- do we store to PlayerLeagueHistory from InfoboxPlayer? will prevent needing to sync a normally-unneeded dependency
}
function p.linkPatch(str)
if not str then return nil end
return util_text.intLink(('Patch %s'):format(str), str)
end
---------------------------------------------------------
------------------ MatchList hooks ---------------------
---------------------------------------------------------
local MATCHLIST_PATCH_TOGGLES = {
init = 'patch_number',
order = { 'patch_all', 'patch_number', 'patch_none' },
showall = 'patch_all',
}
function p.onMatchListProcessTabRow(row, i, j, args, tab)
-- add patch as a table caption
util_table.initTable(tab, 'patchinfo', { patches = {}, hotfixes = {}, disabled = {}, footnotes = {} })
if not row.Patch then return true end
MATCH_LIST_HAS_PATCH = true
util_table.initDict(tab.patchinfo.patches, row.Patch)
if row.Hotfix then
util_table.initDict(tab.patchinfo.hotfixes, row.Hotfix)
end
if row.PatchFootnote then
util_table.initDict(tab.patchinfo.footnotes, row.PatchFootnote)
end
util_table.merge(tab.patchinfo.disabled, util_text.split(row.Disabled))
return true
end
function p.onMatchListPrintCaption(tbl, tab)
if not MATCH_LIST_HAS_PATCH then return true end
local caption = tbl:tag('caption')
-- the toggle here is needed because footnotes are attached only to the parent element, not the spans
-- since it's impossible to show disabled champions but not patch number,
-- we don't need to add patch_disabled since that would be showall, and showall is auto added
util_toggle.oflCellClasses(caption, MATCHLIST_PATCH_TOGGLES, 'patch_number')
h.printPatchNumber(caption, tab.patchinfo)
h.printDisabledText(caption, tab.patchinfo)
util_footnote.tagFootnotes(caption, tab.patchinfo.footnotes)
return true
end
function h.printPatchNumber(caption, patchinfo)
local span = caption:tag('span')
:addClass('matchlist-patch-number')
:wikitext(i18n.print('patchCaption', h.getPatchText(patchinfo.patches)))
util_toggle.oflCellClasses(span, MATCHLIST_PATCH_TOGGLES, 'patch_number')
end
function h.getPatchText(patches)
return util_table.concatNonempty(patches, ', ', p.linkPatch) or i18n.print('tbd')
end
function h.printDisabledText(caption, patchinfo)
if not patchinfo.disabled or not next(patchinfo.disabled) then return end
local span = caption:tag('span')
:addClass('matchlist-patch-disabled')
:wikitext(i18n.print('patchDisabled', h.getDisabledText(patchinfo.disabled)))
util_toggle.oflCellClasses(span, MATCHLIST_PATCH_TOGGLES, 'patch_disabled')
end
function h.getDisabledText(disabled)
return util_table.concat(disabled, '', m_champion.onlyimagelinked)
end
function p.onMatchListPrintTogglesEnd(tbl)
div = tbl:tag('div'):addClass('toggle-button')
-- div:wikitext(i18n.print('patchToggleLabel'))
util_toggle.printOptionFromListTogglers(div, MATCHLIST_PATCH_TOGGLES)
end
return p