Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki

To edit the documentation or categories for this module, click here.


local util_args = require('Module:ArgsUtil')
local util_cargo = require('Module:CargoUtil')
local util_form = require('Module:FormUtil')
local util_game = require('Module:GameUtil')
local util_esports = require('Module:EsportsUtil')
local util_map = require('Module:MapUtil')
local util_table = require('Module:TableUtil')
local util_text = require("Module:TextUtil")
local util_vars = require('Module:VarsUtil')
local i18n = require('Module:i18nUtil')
local m_team = require('Module:Team')
local Sprite = require('Module:Sprite').spriteImage

local COLORS = { 'red', 'blue', 'green', 'yellow' }

local PBHF = require('Module:PickBanHistoryFormatterAbstract'):extends()

local h = {}

function h.ChampionSprite(id)
	return Sprite{
		id,
		size = '25',
		type = 'Champion',
		notext = true,
		nolink = true,
		nosize = true
	}
end

function PBHF:formatRow(row)
	row.data = {
		Phase = row.Tab and ('[[%s#%s|%s]]'):format(row._pageName,row.Tab,row.Tab) or '',
		Blue = m_team.onlyimage(row.Team1) or row.Team1,
		Red = m_team.onlyimage(row.Team2) or row.Team2,
		Score = self:getScore(row),
		Patch = util_game.linkPatch(row.Patch) or '',
		SB = row.ScoreboardPage and util_text.intLink(row.ScoreboardPage, 'SB'),
		MH = util_text.extLink(row.MatchHistory, 'MH'),
		VOD = util_text.extLink(row.VOD, 'VOD'),
	}
	row.classes = self:initColumnClasses(row.Winner)
	row.attrs = {
		Blue = { title = m_team.teamname(row.Team1) },
		Red = { title = m_team.teamname(row.Team2) },
	}
	for label, cellPreload in pairs(self.CELLORDER) do
		local c1 = cellPreload[1] and row[cellPreload[1]]
		local c2 = cellPreload[2] and row[cellPreload[2]]
		row.data[label] = self:getChampionDisplays(c1, c2)
		self:initCellClasses(row.classes, label)
		util_table.mergeArrays(row.classes[label], cellPreload.classes or {}, h.getChampionClasses(c1, c2))
		row.attrs[label] = h.getChampAttrs(c1, c2)
	end
	if self.DEBUG then util_table.push(row.data, row._pageName) end
end

function PBHF:getChampionDisplays(a, b)
	return self:getOneChampionDisplay(a) .. self:getOneChampionDisplay(b)
end

function PBHF:getOneChampionDisplay(champ)
	if not champ then return '' end
	local span = mw.html.create('span')
		:addClass('pbh-cn') -- cn short for pbh-champion
		:attr('data-champion',h.escapeChampForClass(champ))
		:wikitext(h.ChampionSprite(champ))
	return tostring(span)
end

function h.escapeChampForClass(champ)
	if not champ then return nil end
	return champ:gsub("[ '.]",''):lower()
end

function h.addClassesToCell(classes, cellPreload)
	util_table.mergeArrays(classes, cellPreload.classes)
end

function h.getChampionClasses(a, b)
	local ret = {}
	ret[#ret+1] = h.toClass(h.escapeChampForClass(a))
	ret[#ret+1] = h.toClass(h.escapeChampForClass(b))
	return ret
end

function h.toClass(str)
	if not str then return nil end
	return ('pbh-%s'):format(str)
end

function h.getChampAttrs(c1, c2)
	return {
		['data-c1'] = h.escapeChampForClass(c1),
		['data-c2'] = h.escapeChampForClass(c2),
	}
end

function PBHF:printLinkToTextOnly(th, formInfo, entityName)
	th:wikitext(string.format(
		' <span class="plainlinks">([%s View Text-Only Version])</span>',
		util_form.fullURL(formInfo, { textonly = 'Yes', page = entityName })
	))
end

function PBHF:makeColorPicker()
	local tbl = mw.html.create('div')
	tbl:attr('id','pbh-setcolor-box')
	for k, cellPreload in ipairs(COLORS) do
		tbl:tag('div')
			:addClass('pbh-setcolor')
			:addClass(k == 1 and 'pbh-current-tool' or '')
			:attr('data-pbhcolor', cellPreload)
			:css('background-color',cellPreload)
	end
	tbl:tag('div')
		:attr('id','pbh-remove')
		:attr('title','Clear')
	tbl:tag('div')
		:attr('id','pbh-removeall')
		:attr('title','Clear All')
	tbl:tag('div')
		:attr('id','pbh-undo')
		:attr('title','Undo Clear All')
		:css('display','none')
	return tbl
end

return PBHF
Advertisement