Skip to content

Commit

Permalink
osu (+ commons adjust for it)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpalpha committed Dec 15, 2024
1 parent 0d18aaa commit 1914138
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 40 deletions.
7 changes: 6 additions & 1 deletion components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ end
---@field mapIsFinished? fun(map: table, opponents: table[], finishedInput: string?, winnerInput: string?): boolean
---@field extendMapOpponent? fun(map: table, opponentIndex: integer): table
---@field getMapBestOf? fun(map: table): integer?
---@field computeOpponentScore? fun(props: table, autoScore?: fun(opponentIndex: integer):integer?): integer?, string?
---@field ADD_SUB_GROUP? boolean
---@field BREAK_ON_EMPTY? boolean

Expand All @@ -1179,6 +1180,9 @@ end
--- - getPlayersOfMapOpponent(map, opponent, opponentIndex): table[]?
--- - getPatch(game): string?
--- - mapIsFinished(map, opponents): boolean
--- - extendMapOpponent(map, opponentIndex): table
--- - getMapBestOf(map): integer?
--- - computeOpponentScore(props, autoScore): integer?, string?
---
--- Additionally, the Parser may have the following properties:
--- - ADD_SUB_GROUP boolean?
Expand Down Expand Up @@ -1221,7 +1225,8 @@ function MatchGroupInputUtil.standardProcessMaps(match, opponents, Parser)
end

map.opponents = Array.map(opponents, function(opponent, opponentIndex)
local score, status = MatchGroupInputUtil.computeOpponentScore({
local computeOpponentScore = Parser.computeOpponentScore or MatchGroupInputUtil.computeOpponentScore
local score, status = computeOpponentScore({
walkover = map.walkover,
winner = map.winner,
opponentIndex = opponentIndex,
Expand Down
60 changes: 21 additions & 39 deletions components/match2/wikis/osu/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')

local CustomMatchGroupInput = {}
local MatchFunctions = {}
local MapFunctions = {}
local MapFunctions = {
BREAK_ON_EMPTY = true,
}

local ALLOWED_VETOES = Array.append(MatchGroupInputUtil.DEFAULT_ALLOWED_VETOES, 'protect')
local DEFAULT_BESTOF = 3
Expand All @@ -37,43 +39,7 @@ end
---@param opponents table[]
---@return table[]
function MatchFunctions.extractMaps(match, opponents)
local maps = {}
for key, map in Table.iter.pairsByPrefix(match, 'map', {requireIndex = true}) do
if not map.map then
break
end
local finishedInput = map.finished --[[@as string?]]
local winnerInput = map.winner --[[@as string?]]

map.extradata = MapFunctions.getExtraData(map)
map.finished = MatchGroupInputUtil.mapIsFinished(map)

map.opponents = Array.map(opponents, function(_, opponentIndex)
local percentageScore = (map['score' .. opponentIndex] or ''):match('(%d+)%%')
if percentageScore then
return {score = map['score' .. opponentIndex], status = MatchGroupInputUtil.STATUS.SCORE}
end
local scoreInput = string.gsub(map['score' .. opponentIndex] or '', ',', '')
local score, status = MatchGroupInputUtil.computeOpponentScore({
walkover = map.walkover,
winner = map.winner,
opponentIndex = opponentIndex,
score = scoreInput,
})
return {score = score, status = status}
end)

map.scores = Array.map(map.opponents, Operator.property('score'))
if map.finished then
map.status = MatchGroupInputUtil.getMatchStatus(winnerInput, finishedInput)
map.winner = MatchGroupInputUtil.getWinner(map.status, winnerInput, map.opponents)
end

table.insert(maps, map)
match[key] = nil
end

return maps
return MatchGroupInputUtil.standardProcessMaps(match, opponents, MapFunctions)
end

---@param bestofInput string|integer?
Expand Down Expand Up @@ -113,12 +79,28 @@ end
-- map related functions
--

---@param match table
---@param map table
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(map)
function MapFunctions.getExtraData(match, map, opponents)
return {
comment = map.comment,
}
end
---@param props {walkover: string|integer?, winner: string|integer?, score: string|integer?, opponentIndex: integer}
---@param autoScore? fun(opponentIndex: integer): integer?
---@return integer|string? #SCORE
---@return string? #STATUS
function MapFunctions.computeOpponentScore(props, autoScore)
local percentageScore = (props.score or ''):match('(%d+)%%')
if percentageScore then
return props.score, MatchGroupInputUtil.STATUS.SCORE
end

props.score = string.gsub(props.score or '', ',', '')

return MatchGroupInputUtil.computeOpponentScore(props)
end

return CustomMatchGroupInput

0 comments on commit 1914138

Please sign in to comment.