Skip to content

Commit

Permalink
Refactoring of playall references
Browse files Browse the repository at this point in the history
  • Loading branch information
fregerson committed Dec 2, 2024
1 parent e96917a commit 336f9b5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 21 deletions.
21 changes: 4 additions & 17 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ function MatchGroupInputUtil.matchIsFinished(match, opponents)
end

local playall = tonumber(match.playall) or 0
if playall then
if playall > 0 then
return MatchGroupInputUtil.allHasBeenPlayed(playall, opponents)
end

Expand Down Expand Up @@ -902,10 +902,7 @@ end
---@return boolean
function MatchGroupInputUtil.allHasBeenPlayed(playall, opponents)
local scoreSum = Array.reduce(opponents, function(sum, opponent) return sum + (opponent.score or 0) end, 0)
if scoreSum >= playall then
return true
end
return false
return scoreSum >= playall
end

---@param bestOfInput string|integer?
Expand All @@ -915,12 +912,6 @@ function MatchGroupInputUtil.getBestOf(bestOfInput, maps)
return tonumber(bestOfInput) or #maps
end

---@param playAllInput string|integer?
---@return integer?
function MatchGroupInputUtil.getPlayAll(playAllInput)
return tonumber(playAllInput) or 0
end

---@param alias table<string, string>
---@param character string?
---@return string?
Expand Down Expand Up @@ -1069,7 +1060,6 @@ end
---@class MatchParserInterface
---@field extractMaps fun(match: table, opponents: table[], mapProps: any?): table[]
---@field getBestOf fun(bestOfInput: string|integer|nil, maps: table[]): integer?
---@field getPlayAll fun(playAllInput: string|integer|nil): integer?
---@field calculateMatchScore? fun(maps: table[], opponents: table[]): fun(opponentIndex: integer): integer?
---@field removeUnsetMaps? fun(maps: table[]): table[]
---@field getExtraData? fun(match: table, games: table[], opponents: table[]): table?
Expand Down Expand Up @@ -1103,7 +1093,6 @@ end
--- - getHeadToHeadLink(match, opponents): string?
--- - readDate(match): table
--- - getMode(opponents): string?
--- - getPlayAll(playAllinput): integer?
---
--- Additionally, the Parser may have the following properties:
--- - DEFAULT_MODE: string
Expand Down Expand Up @@ -1166,10 +1155,8 @@ function MatchGroupInputUtil.standardProcessMatch(match, Parser, mapProps)

match.stream = Streams.processStreams(match)
match.extradata = Parser.getExtraData and Parser.getExtraData(match, games, opponents) or {}
local playallData = {
playall = Parser.getPlayAll and Parser.getPlayAll(match.playall) or MatchGroupInputUtil.getPlayAll(match.playall)
}
match.extradata = Table.merge(playallData, match.extradata)
match.extradata = Table.merge({playall = tonumber(match.playall)}, match.extradata)
match.bestof = tonumber(match.playall) --For display in existing Bestof?

match.games = games
match.opponents = opponents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ end
function CustomMatchGroupInput._getExtraData(match)
return {
casters = MatchGroupInputUtil.readCasters(match, {noSort = true}),
playall = MatchGroupInputUtil.getPlayAll(match.playall)
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ function MatchFunctions.getExtraData(match, opponents, finishedInput)
status = match.status == MatchGroupInputUtil.MATCH_STATUS.NOT_PLAYED and finishedInput or nil,
overturned = Logic.isNotEmpty(match.overturned),
featured = MatchFunctions.isFeatured(match, opponents),
hidden = Logic.readBool(Variables.varDefault('match_hidden')),
playall = match.playall
hidden = Logic.readBool(Variables.varDefault('match_hidden'))
}
end

Expand Down
2 changes: 1 addition & 1 deletion components/transfer/commons/transfer_references.lua
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,4 @@ function TransferRef._getTextAndLink(reference, options)
end
end

return TransferRef
return TransferRef

0 comments on commit 336f9b5

Please sign in to comment.