Skip to content

Commit

Permalink
refactor(match2): standarize mapVeto display further (#4960)
Browse files Browse the repository at this point in the history
* reactor(match2): standarize mapVeto display further

* lint

* missed some stuff on osu
  • Loading branch information
Rathoz authored Oct 24, 2024
1 parent b5d0795 commit baed407
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 111 deletions.
29 changes: 21 additions & 8 deletions components/match2/commons/match_summary_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@ end
---@field root Html
---@field table Html
---@field vetoTypeToText table
---@field game string?
---@field emptyMapDisplay string
local MapVeto = Class.new(
function(self, vetoTypeToText)
function(self, options)
self.root = mw.html.create('div')
:addClass('brkts-popup-mapveto')

Expand All @@ -368,7 +370,9 @@ local MapVeto = Class.new(
:addClass('collapsible')
:addClass('collapsed')

self.vetoTypeToText = vetoTypeToText or DEFAULT_VETO_TYPE_TO_TEXT
self.vetoTypeToText = options.vetoTypeToText or DEFAULT_VETO_TYPE_TO_TEXT
self.game = options.game
self.emptyMapDisplay = options.emptyMapDisplay or TBD

self:createHeader()
end
Expand Down Expand Up @@ -452,13 +456,23 @@ end
---@return string
---@return string
function MapVeto:displayMaps(map1, map2)
if Logic.isEmpty(map1) and Logic.isEmpty(map2) then
return TBD, TBD
end

return self:displayMap(map1), self:displayMap(map2)
end

---@param map string?
---@return string
function MapVeto:displayMap(map)
return Page.makeInternalLink(map) or TBD
if not map then
return self.emptyMapDisplay
end
if not self.game then
return Page.makeInternalLink(map) or self.emptyMapDisplay
end
return Page.makeInternalLink(map, map .. '/' .. self.game) or self.emptyMapDisplay
end

---@param row Html
Expand Down Expand Up @@ -723,16 +737,15 @@ function MatchSummary.defaultGetByMatchId(CustomMatchSummary, args, options)
return matchSummary:create()
end

---@param match MatchGroupUtilMatch
---@param mapVeto VetoDisplay?
---@param vetoData table
---@param options {game: string?, vetoTypeToText:table?, emptyMapDisplay: string?}?
---@return VetoDisplay?
function MatchSummary.defaultMapVetoDisplay(match, mapVeto)
local vetoData = match.extradata.mapveto
function MatchSummary.defaultMapVetoDisplay(vetoData, options)
if Logic.isEmpty(vetoData) then
return
end

mapVeto = mapVeto or MapVeto()
local mapVeto = MapVeto(options or {})
Array.forEach(vetoData, function(vetoRound)
if vetoRound.vetostart then
mapVeto:vetoStart(tonumber(vetoRound.vetostart), vetoRound.format)
Expand Down
16 changes: 1 addition & 15 deletions components/match2/wikis/counterstrike/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')
local GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'}
local NO_CHECK = '[[File:NoCheck.png|link=]]'

local TBD = 'TBD'

local CustomMatchSummary = {}

-- Score Class
Expand Down Expand Up @@ -107,18 +105,6 @@ function Score:create()
return self.root
end

---@class CounterstrikeMapVeto: VetoDisplay
---@field game string?
local MapVeto = Class.new(MatchSummary.MapVeto, function(self, game)
self.game = game
end)

---@param map string?
---@return string
function MapVeto:displayMap(map)
return Logic.nilIfEmpty(CustomMatchSummary._createMapLink(map, self.game)) or TBD
end

---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
Expand Down Expand Up @@ -173,7 +159,7 @@ function CustomMatchSummary.createBody(match)
end

-- Add the Map Vetoes
body:addRow(MatchSummary.defaultMapVetoDisplay(match, MapVeto(match.game)))
body:addRow(MatchSummary.defaultMapVetoDisplay(match.extradata.mapveto, {game = match.game}))

-- Match Status (postponed/ cancel(l)ed)
if match.extradata.status then
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/criticalops/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function CustomMatchSummary.createBody(match)
end

-- Add the Map Vetoes
body:addRow(MatchSummary.defaultMapVetoDisplay(match))
body:addRow(MatchSummary.defaultMapVetoDisplay(match.extradata.mapveto))

return body
end
Expand Down
26 changes: 1 addition & 25 deletions components/match2/wikis/heroes/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ local CustomMatchSummary = {}

local Abbreviation = require('Module:Abbreviation')
local Array = require('Module:Array')
local Class = require('Module:Class')
local DateExt = require('Module:Date/Ext')
local DisplayHelper = require('Module:MatchGroup/Display/Helper')
local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Page = require('Module:Page')
local Table = require('Module:Table')

local MatchSummary = Lua.import('Module:MatchSummary/Base')
Expand All @@ -28,28 +26,6 @@ local NUM_CHAMPIONS_PICK = 5
local GREEN_CHECK = Icon.makeIcon{iconName = 'winner', color = 'forest-green-text', size = '110%'}
local NO_CHECK = '[[File:NoCheck.png|link=]]'
local FP = Abbreviation.make('First Pick', 'First Pick for Heroes on this map')
local TBD = Abbreviation.make('TBD', 'To Be Determined')

---@class HeroesOfTheStormMapVeto: VetoDisplay
local MapVeto = Class.new(MatchSummary.MapVeto)

---@param map1 string?
---@param map2 string?
---@return string
---@return string
function MapVeto:displayMaps(map1, map2)
if Logic.isEmpty(map1) and Logic.isEmpty(map2) then
return TBD, TBD
end

return self:displayMap(map1), self:displayMap(map2)
end

---@param map string?
---@return string
function MapVeto:displayMap(map)
return Logic.isEmpty(map) and FP or Page.makeInternalLink(map) --[[@as string]]
end

---@param args table
---@return Html
Expand Down Expand Up @@ -94,7 +70,7 @@ function CustomMatchSummary.createBody(match)
})

-- Add the Map Vetoes
body:addRow(MatchSummary.defaultMapVetoDisplay(match, MapVeto()))
body:addRow(MatchSummary.defaultMapVetoDisplay(match.extradata.mapveto, {emptyMapDisplay = FP}))

return body
end
Expand Down
23 changes: 3 additions & 20 deletions components/match2/wikis/osu/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Abbreviation = require('Module:Abbreviation')
local Class = require('Module:Class')
local DateExt = require('Module:Date/Ext')
local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
Expand All @@ -20,7 +18,6 @@ local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')

local NONE = '-'
local TBD = Abbreviation.make('TBD', 'To Be Determined')

---@enum OsuMatchIcons
local Icons = {
Expand All @@ -33,22 +30,6 @@ VETO_TYPE_TO_TEXT.protect = 'PROTECT'

local CustomMatchSummary = {}

---@class OsuMapVeto: VetoDisplay
local MapVeto = Class.new(MatchSummary.MapVeto)

---@param map1 string?
---@param map2 string?
---@return string
---@return string
function MapVeto:displayMaps(map1, map2)
if Logic.isEmpty(map1) and Logic.isEmpty(map2) then
return TBD, TBD
end

return Page.makeInternalLink(map1) or NONE,
Page.makeInternalLink(map2) or NONE
end

---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
Expand Down Expand Up @@ -85,7 +66,9 @@ function CustomMatchSummary.createBody(match)
body.root:node(MatchSummaryWidgets.Casters{casters = match.extradata.casters})

-- Add the Map Vetoes
body:addRow(MatchSummary.defaultMapVetoDisplay(match, MapVeto(VETO_TYPE_TO_TEXT)))
body:addRow(MatchSummary.defaultMapVetoDisplay(
match.extradata.mapveto, {vetoTypeToText = VETO_TYPE_TO_TEXT, emptyMapDisplay = NONE}
))

return body
end
Expand Down
18 changes: 1 addition & 17 deletions components/match2/wikis/rainbowsix/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Abbreviation = require('Module:Abbreviation')
local CharacterIcon = require('Module:CharacterIcon')
local Class = require('Module:Class')
local DateExt = require('Module:Date/Ext')
local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
local Lua = require('Module:Lua')
local Page = require('Module:Page')
local Table = require('Module:Table')

local DisplayHelper = Lua.import('Module:MatchGroup/Display/Helper')
Expand All @@ -32,8 +30,6 @@ local ROUND_ICONS = {
otdef = '[[File:R6S Para Bellum def logo ot rounds.png|11px|link=]]',
}

local TBD = Abbreviation.make('TBD', 'To Be Determined')

-- Operator Bans Class
---@class R6OperatorBan
---@operator call: R6OperatorBan
Expand Down Expand Up @@ -237,18 +233,6 @@ function Score:create()
return self.root
end

---@class R6MapVeto: VetoDisplay
---@field game string?
local MapVeto = Class.new(MatchSummary.MapVeto, function(self, game)
self.game = game
end)

---@param map string?
---@return string
function MapVeto:displayMap(map)
return Page.makeInternalLink(map, map and (map .. '/siege') or nil) or TBD
end

local CustomMatchSummary = {}

---@param args table
Expand Down Expand Up @@ -287,7 +271,7 @@ function CustomMatchSummary.createBody(match)
body.root:node(MatchSummaryWidgets.Casters{casters = match.extradata.casters})

-- Add the Map Vetoes
body:addRow(MatchSummary.defaultMapVetoDisplay(match, MapVeto()))
body:addRow(MatchSummary.defaultMapVetoDisplay(match.extradata.mapveto, {game = 'siege'}))

return body
end
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/splatoon/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function CustomMatchSummary.createBody(match)
end

-- Add the Map Vetoes
body:addRow(MatchSummary.defaultMapVetoDisplay(match))
body:addRow(MatchSummary.defaultMapVetoDisplay(match.extradata.mapveto))

return body
end
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/valorant/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function CustomMatchSummary.createBody(match)
end

-- Add Map Veto
body:addRow(MatchSummary.defaultMapVetoDisplay(match))
body:addRow(MatchSummary.defaultMapVetoDisplay(match.extradata.mapveto))

body.root:node(MatchSummaryWidgets.Casters{casters = match.extradata.casters})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ local Variables = require('Module:Variables')

local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')

local ALLOWED_VETOES = Array.append(MatchGroupInputUtil.DEFAULT_ALLOWED_VETOES, 'protect')
local DEFAULT_BESTOF = 3
local DEFAULT_MODE = 'team'

Expand Down Expand Up @@ -150,7 +149,7 @@ end
function MatchFunctions.getExtraData(match)
return {
mvp = MatchGroupInputUtil.readMvp(match),
mapveto = MatchGroupInputUtil.getMapVeto(match, ALLOWED_VETOES),
mapveto = MatchGroupInputUtil.getMapVeto(match),
casters = MatchGroupInputUtil.readCasters(match),
}
end
Expand Down
21 changes: 1 addition & 20 deletions components/match2/wikis/worldoftanks/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--

local Abbreviation = require('Module:Abbreviation')
local Class = require('Module:Class')
local DateExt = require('Module:Date/Ext')
local Icon = require('Module:Icon')
local Logic = require('Module:Logic')
Expand All @@ -20,7 +18,6 @@ local MatchSummary = Lua.import('Module:MatchSummary/Base')
local MatchSummaryWidgets = Lua.import('Module:Widget/Match/Summary/All')

local NONE = '-'
local TBD = Abbreviation.make('TBD', 'To Be Determined')

---@enum WoTMatchIcons
local Icons = {
Expand All @@ -30,22 +27,6 @@ local Icons = {

local CustomMatchSummary = {}

---@class WoTMapVeto: VetoDisplay
local MapVeto = Class.new(MatchSummary.MapVeto)

---@param map1 string?
---@param map2 string?
---@return string
---@return string
function MapVeto:displayMaps(map1, map2)
if Logic.isEmpty(map1) and Logic.isEmpty(map2) then
return TBD, TBD
end

return Page.makeInternalLink(map1) or NONE,
Page.makeInternalLink(map2) or NONE
end

---@param args table
---@return Html
function CustomMatchSummary.getByMatchId(args)
Expand Down Expand Up @@ -82,7 +63,7 @@ function CustomMatchSummary.createBody(match)
body.root:node(MatchSummaryWidgets.Casters{casters = match.extradata.casters})

-- Add the Map Vetoes
body:addRow(MatchSummary.defaultMapVetoDisplay(match, MapVeto()))
body:addRow(MatchSummary.defaultMapVetoDisplay(match.extradata.mapveto, {emptyMapDisplay = NONE}))

return body
end
Expand Down
2 changes: 1 addition & 1 deletion components/match2/wikis/zula/match_summary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function CustomMatchSummary.createBody(match)
end

-- Add the Map Vetoes
body:addRow(MatchSummary.defaultMapVetoDisplay(match))
body:addRow(MatchSummary.defaultMapVetoDisplay(match.extradata.mapveto))

return body
end
Expand Down

0 comments on commit baed407

Please sign in to comment.