Skip to content

Commit

Permalink
refactor(match2): make tournamentVars into a non-mutating function (#…
Browse files Browse the repository at this point in the history
…4839)

* refactor(match2): make tournamentVars into a non-mutating function

* do tft

* cleanup tft a bit
  • Loading branch information
Rathoz authored Oct 10, 2024
1 parent 2febef7 commit b7209ae
Show file tree
Hide file tree
Showing 47 changed files with 110 additions and 343 deletions.
2 changes: 1 addition & 1 deletion components/match2/commons/match_group_input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local VALID_GSL_GROUP_STYLES = {
---@param match table
function MatchGroupInput._applyTournamentVarsToMaps(match)
for _, map in ipairs(MatchGroupUtil.normalizeSubtype(match, 'map')) do
MatchGroupInputUtil.getCommonTournamentVars(map, match)
Table.mergeInto(map, MatchGroupInputUtil.getTournamentContext(map, match))
end
end

Expand Down
36 changes: 19 additions & 17 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,36 +292,38 @@ end
---@param obj table
---@param parent table?
---@return table
function MatchGroupInputUtil.getCommonTournamentVars(obj, parent)
---@nodiscard
function MatchGroupInputUtil.getTournamentContext(obj, parent)
parent = parent or {}
obj.game = Logic.emptyOr(obj.game, parent.game, globalVars:get('tournament_game'))
obj.icon = Logic.emptyOr(obj.icon, parent.icon, globalVars:get('tournament_icon'))
obj.icondark = Logic.emptyOr(obj.iconDark, parent.icondark, globalVars:get('tournament_icondark'))
obj.liquipediatier = Logic.emptyOr(
local vars = {}
vars.game = Logic.emptyOr(obj.game, parent.game, globalVars:get('tournament_game'))
vars.icon = Logic.emptyOr(obj.icon, parent.icon, globalVars:get('tournament_icon'))
vars.icondark = Logic.emptyOr(obj.iconDark, parent.icondark, globalVars:get('tournament_icondark'))
vars.liquipediatier = Logic.emptyOr(
obj.liquipediatier,
parent.liquipediatier,
globalVars:get('tournament_liquipediatier')
)
obj.liquipediatiertype = Logic.emptyOr(
vars.liquipediatiertype = Logic.emptyOr(
obj.liquipediatiertype,
parent.liquipediatiertype,
globalVars:get('tournament_liquipediatiertype')
)
obj.publishertier = Logic.emptyOr(
vars.publishertier = Logic.emptyOr(
obj.publishertier,
parent.publishertier,
globalVars:get('tournament_publishertier')
)
obj.series = Logic.emptyOr(obj.series, parent.series, globalVars:get('tournament_series'))
obj.shortname = Logic.emptyOr(obj.shortname, parent.shortname, globalVars:get('tournament_shortname'))
obj.tickername = Logic.emptyOr(obj.tickername, parent.tickername, globalVars:get('tournament_tickername'))
obj.tournament = Logic.emptyOr(obj.tournament, parent.tournament, globalVars:get('tournament_name'))
obj.type = Logic.emptyOr(obj.type, parent.type, globalVars:get('tournament_type'))
obj.patch = Logic.emptyOr(obj.patch, parent.patch, globalVars:get('tournament_patch'))
obj.date = Logic.emptyOr(obj.date, parent.date)
obj.mode = Logic.emptyOr(obj.mode, parent.mode)

return obj
vars.series = Logic.emptyOr(obj.series, parent.series, globalVars:get('tournament_series'))
vars.shortname = Logic.emptyOr(obj.shortname, parent.shortname, globalVars:get('tournament_shortname'))
vars.tickername = Logic.emptyOr(obj.tickername, parent.tickername, globalVars:get('tournament_tickername'))
vars.tournament = Logic.emptyOr(obj.tournament, parent.tournament, globalVars:get('tournament_name'))
vars.type = Logic.emptyOr(obj.type, parent.type, globalVars:get('tournament_type'))
vars.patch = Logic.emptyOr(obj.patch, parent.patch, globalVars:get('tournament_patch'))
vars.date = Logic.emptyOr(obj.date, parent.date)
vars.mode = Logic.emptyOr(obj.mode, parent.mode)

return vars
end

---@param match table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function StarcraftMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchGroupInputUtil.getCommonTournamentVars(match)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.vod = Logic.nilIfEmpty(match.vod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function StarcraftFfaMatchGroupInput.processMatch(match, options)
match.vod = Logic.nilIfEmpty(match.vod)
match.links = BaseMatchFunctions.getLinks(match)

MatchGroupInputUtil.getCommonTournamentVars(match)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

local opponents = BaseMatchFunctions.readOpponents(match)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ local OPPONENT_CONFIG = {
---@return table
function CustomMatchGroupInput.processMatch(match, options)
assert(not Logic.readBool(match.ffa), 'FFA is not yet supported in AoE match2.')
MatchGroupInputUtil.getCommonTournamentVars(match)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))
match.game, match.mapsInfo = CustomMatchGroupInput._getMapsAndGame(match)

Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date))
Expand Down Expand Up @@ -154,7 +154,7 @@ function CustomMatchGroupInput.extractMaps(match, opponents)
map.map, map.extradata.displayname = CustomMatchGroupInput._getMapName(map, match.mapsInfo)
map.extradata.mapmode = Table.extract(map, 'mode')

MatchGroupInputUtil.getCommonTournamentVars(map, match)
Table.mergeInto(map, MatchGroupInputUtil.getTournamentContext(map, match))

map.opponents = CustomMatchGroupInput.processPlayerMapData(map, opponents)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchFunctions.setBgForOpponents(opponents, settings.status)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', DEFAULT_MODE))
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)

Expand Down Expand Up @@ -231,12 +232,6 @@ function MatchFunctions.parseSetting(match)
}
end

---@param match table
function MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', DEFAULT_MODE))
MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param settings table
---@return table
function MatchFunctions.getExtraData(settings)
Expand Down
10 changes: 2 additions & 8 deletions components/match2/wikis/arenafps/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.links = MatchFunctions.getLinks(match)
Expand Down Expand Up @@ -131,13 +132,6 @@ function MatchFunctions.getBestOf(bestofInput)
return tonumber(Variables.varDefault('bestof')) or DEFAULT_BESTOF
end

---@param match table
---@return table
function MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(maps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchGroupInputUtil.getCommonTournamentVars(match)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.links = MatchFunctions.getLinks(match)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

CustomMatchGroupInput.getTournamentVars(match)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))
match.mode = Variables.varDefault('tournament_mode', 'singles')

match.stream = Streams.processStreams(match)

Expand All @@ -74,12 +75,6 @@ end

CustomMatchGroupInput.processMap = FnUtil.identity

---@param match table
function CustomMatchGroupInput.getTournamentVars(match)
match = MatchGroupInputUtil.getCommonTournamentVars(match)
match.mode = Variables.varDefault('tournament_mode', 'singles')
end

---@param match table
---@param matchOpponents table[]
---@return table[]
Expand Down
10 changes: 2 additions & 8 deletions components/match2/wikis/brawlstars/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'team'))
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)

Expand Down Expand Up @@ -145,13 +146,6 @@ function MatchFunctions.getBestOf(match)
return bestof or DEFAULT_BESTOF_MATCH
end

---@param match table
---@return table
function MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'team'))
return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param match table
---@return table
function MatchFunctions.getExtraData(match)
Expand Down
10 changes: 2 additions & 8 deletions components/match2/wikis/callofduty/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'team'))
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.links = MatchFunctions.getLinks(match)
Expand Down Expand Up @@ -132,13 +133,6 @@ function MatchFunctions.getBestOf(match)
return bestof or DEFAULT_BESTOF
end

---@param match table
---@return table
function MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'team'))
return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param match table
---@return table
function MatchFunctions.getLinks(match)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.links = MatchFunctions.getLinks(match)
Expand Down Expand Up @@ -154,13 +155,6 @@ function MatchFunctions.getBestOf(bestofInput)
return tonumber(Variables.varDefault('bestof')) or DEFAULT_BESTOF
end

---@param match table
---@return table
function MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(maps)
Expand Down
10 changes: 2 additions & 8 deletions components/match2/wikis/clashroyale/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', DEFAULT_MODE))
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.links = MatchFunctions.getLinks(match)
Expand All @@ -91,13 +92,6 @@ function MatchFunctions.getLinks(match)
}
end

---@param match table
---@return table
function MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', DEFAULT_MODE))
return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param match table
---@param opponents table[]
---@return table[]
Expand Down
14 changes: 4 additions & 10 deletions components/match2/wikis/counterstrike/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'team'))
match.publishertier = Logic.emptyOr(match.publishertier, Variables.varDefault('tournament_valve_tier'))
match.status = Logic.emptyOr(match.status, Variables.varDefault('tournament_status'))
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.links = MatchFunctions.getLinks(match, games)
Expand Down Expand Up @@ -151,15 +154,6 @@ function MatchFunctions.removeUnsetMaps(games)
return Array.filter(games, MapFunctions.keepMap)
end

---@param match table
---@return table
function MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode', 'team'))
match.publishertier = Logic.emptyOr(match.publishertier, Variables.varDefault('tournament_valve_tier'))

return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param match table
---@param maps table[]
---@return table
Expand Down
10 changes: 2 additions & 8 deletions components/match2/wikis/criticalops/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.links = MatchFunctions.getLinks(match)
Expand Down Expand Up @@ -136,13 +137,6 @@ function MatchFunctions.extractMaps(match, opponentCount)
return maps
end

---@param match table
---@return table
function MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(maps)
Expand Down
10 changes: 2 additions & 8 deletions components/match2/wikis/crossfire/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.links = MatchFunctions.getLinks(match)
Expand Down Expand Up @@ -138,13 +139,6 @@ function MatchFunctions.getBestOf(bestofInput)
return tonumber(Variables.varDefault('bestof')) or DEFAULT_BESTOF
end

---@param match table
---@return table
function MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param maps table[]
---@return fun(opponentIndex: integer): integer?
function MatchFunctions.calculateMatchScore(maps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function CustomMatchGroupInput.processMatch(match, options)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchGroupInputUtil.getCommonTournamentVars(match)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)

Expand Down
13 changes: 3 additions & 10 deletions components/match2/wikis/dota2/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ function CustomMatchGroupInput.processMatchWithoutStandalone(MatchParser, match)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2, match.resulttype)
end

MatchFunctions.getTournamentVars(match)
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
Table.mergeInto(match, MatchGroupInputUtil.getTournamentContext(match))

match.stream = Streams.processStreams(match)
match.links = MatchFunctions.getLinks(match, games)
Expand Down Expand Up @@ -173,14 +174,6 @@ function MatchFunctions.calculateMatchScore(maps)
end
end

---@param match table
---@return table
function MatchFunctions.getTournamentVars(match)
match.headtohead = Logic.emptyOr(match.headtohead, Variables.varDefault('headtohead'))
match.mode = Logic.emptyOr(match.mode, Variables.varDefault('tournament_mode'), DEFAULT_MODE)
return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param match table
---@param games table[]
---@return table
Expand Down Expand Up @@ -210,7 +203,7 @@ end
function MatchFunctions.getExtraData(match)
return {
mvp = MatchGroupInputUtil.readMvp(match),
headtohead = match.headtohead,
headtohead = Logic.emptyOr(match.headtohead, Variables.varDefault('headtohead')),
casters = MatchGroupInputUtil.readCasters(match, {noSort = true}),
}
end
Expand Down
Loading

0 comments on commit b7209ae

Please sign in to comment.