Skip to content

Commit

Permalink
Merge branch 'mgi-split' into attach-participant-properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz authored Aug 26, 2024
2 parents 275184d + 34c655b commit 95a50dc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 76 deletions.
54 changes: 27 additions & 27 deletions components/match2/wikis/dota2/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local Streams = require('Module:Links/Stream')
local Table = require('Module:Table')
local Variables = require('Module:Variables')

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

local OPPONENT_CONFIG = {
Expand Down Expand Up @@ -53,9 +53,9 @@ function CustomMatchGroupInput.processMatch(match, options)
if not options.isMatchPage then
-- See if this match has a standalone match (match page), if so use the data from there
local standaloneMatchId = MatchGroupUtil.getStandaloneId(match.bracketid, match.matchid)
local standaloneMatch = standaloneMatchId and MatchGroupInput.fetchStandaloneMatch(standaloneMatchId) or nil
local standaloneMatch = standaloneMatchId and MatchGroupInputUtil.fetchStandaloneMatch(standaloneMatchId) or nil
if standaloneMatch then
return MatchGroupInput.mergeStandaloneIntoMatch(match, standaloneMatch)
return MatchGroupInputUtil.mergeStandaloneIntoMatch(match, standaloneMatch)
end
end

Expand All @@ -75,36 +75,36 @@ end
function CustomMatchGroupInput.processMatchWithoutStandalone(MatchParser, match)
local finishedInput = match.finished --[[@as string?]]
local winnerInput = match.winner --[[@as string?]]
Table.mergeInto(match, MatchGroupInput.readDate(match.date))
Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date))

local opponents = Array.mapIndexes(function(opponentIndex)
return MatchGroupInput.readOpponent(match, opponentIndex, OPPONENT_CONFIG)
return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG)
end)
local games = MatchFunctions.extractMaps(MatchParser, match, opponents)
match.bestof = MatchGroupInput.getBestOf(match.bestof, games)
match.bestof = MatchGroupInputUtil.getBestOf(match.bestof, games)

local autoScoreFunction = MatchGroupInput.canUseAutoScore(match, games)
local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games)
and MatchFunctions.calculateMatchScore(games)
or nil

Array.forEach(opponents, function(opponent, opponentIndex)
opponent.score, opponent.status = MatchGroupInput.computeOpponentScore({
opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({
walkover = match.walkover,
winner = match.winner,
opponentIndex = opponentIndex,
score = opponent.score,
}, autoScoreFunction)
end)

match.finished = MatchGroupInput.matchIsFinished(match, opponents)
match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents)

if match.finished then
match.resulttype = MatchGroupInput.getResultType(winnerInput, finishedInput, opponents)
match.walkover = MatchGroupInput.getWalkover(match.resulttype, opponents)
match.winner = MatchGroupInput.getWinner(match.resulttype, winnerInput, opponents)
MatchGroupInput.setPlacement(opponents, match.winner, 1, 2)
elseif MatchGroupInput.isNotPlayed(winnerInput, finishedInput) then
match.resulttype = MatchGroupInput.getResultType(winnerInput, finishedInput, opponents)
match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents)
match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents)
match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2)
elseif MatchGroupInputUtil.isNotPlayed(winnerInput, finishedInput) then
match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents)
match.winner = nil
end

Expand Down Expand Up @@ -141,9 +141,9 @@ function MatchFunctions.extractMaps(MatchParser, match, opponents)
map.participants = MapFunctions.getParticipants(MatchParser, map, opponents)
map.extradata = MapFunctions.getExtraData(MatchParser, map, #opponents)

map.finished = MatchGroupInput.mapIsFinished(map)
map.finished = MatchGroupInputUtil.mapIsFinished(map)
local opponentInfo = Array.map(opponents, function(_, opponentIndex)
local score, status = MatchGroupInput.computeOpponentScore({
local score, status = MatchGroupInputUtil.computeOpponentScore({
walkover = map.walkover,
winner = map.winner,
opponentIndex = opponentIndex,
Expand All @@ -153,10 +153,10 @@ function MatchFunctions.extractMaps(MatchParser, match, opponents)
end)

map.scores = Array.map(opponentInfo, Operator.property('score'))
if map.finished or MatchGroupInput.isNotPlayed(map.winner, finishedInput) then
map.resulttype = MatchGroupInput.getResultType(winnerInput, finishedInput, opponentInfo)
map.walkover = MatchGroupInput.getWalkover(map.resulttype, opponentInfo)
map.winner = MatchGroupInput.getWinner(map.resulttype, winnerInput, opponentInfo)
if map.finished or MatchGroupInputUtil.isNotPlayed(map.winner, finishedInput) then
map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo)
map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo)
map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo)
end

table.insert(maps, map)
Expand All @@ -172,7 +172,7 @@ CustomMatchGroupInput.processMap = FnUtil.identity
---@return fun(opponentIndex: integer): integer
function MatchFunctions.calculateMatchScore(maps)
return function(opponentIndex)
return MatchGroupInput.computeMatchScoreFromMapWinners(maps, opponentIndex)
return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex)
end
end

Expand All @@ -181,7 +181,7 @@ end
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 MatchGroupInput.getCommonTournamentVars(match)
return MatchGroupInputUtil.getCommonTournamentVars(match)
end

---@param match table
Expand Down Expand Up @@ -212,7 +212,7 @@ end
---@return table
function MatchFunctions.getExtraData(match)
return {
mvp = MatchGroupInput.readMvp(match),
mvp = MatchGroupInputUtil.readMvp(match),
headtohead = match.headtohead,
}
end
Expand All @@ -226,7 +226,7 @@ function MapFunctions.getExtraData(MatchParser, map, opponentCount)
publisherid = map.publisherid or '',
comment = map.comment,
}
local getCharacterName = FnUtil.curry(MatchGroupInput.getCharacterName, HeroNames)
local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, HeroNames)

local function prefixKeyWithTeam(key, opponentIndex)
return 'team' .. opponentIndex .. key
Expand Down Expand Up @@ -266,12 +266,12 @@ end
---@return table
function MapFunctions.getParticipants(MatchParser, map, opponents)
local participants = {}
local getCharacterName = FnUtil.curry(MatchGroupInput.getCharacterName, HeroNames)
local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, HeroNames)

for opponentIndex, opponent in ipairs(opponents) do
local players = opponent.match2players or {}
for _, participant in ipairs(MatchParser.getParticipants(map, opponentIndex) or {}) do
local playerIndex = MatchGroupInput.findPlayerIndex(players, participant.id, nil, OPPONENT_CONFIG)
local playerIndex = MatchGroupInputUtil.findPlayerIndex(players, participant.id, nil, OPPONENT_CONFIG)
if playerIndex then
participant.character = getCharacterName(participant.character)
participants[opponentIndex .. '_' .. playerIndex] = participant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local Streams = require('Module:Links/Stream')
local Table = require('Module:Table')
local Variables = require('Module:Variables')

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

local OPPONENT_CONFIG = {
Expand Down Expand Up @@ -53,9 +53,9 @@ function CustomMatchGroupInput.processMatch(match, options)
if not options.isMatchPage then
-- See if this match has a standalone match (match page), if so use the data from there
local standaloneMatchId = MatchGroupUtil.getStandaloneId(match.bracketid, match.matchid)
local standaloneMatch = standaloneMatchId and MatchGroupInput.fetchStandaloneMatch(standaloneMatchId) or nil
local standaloneMatch = standaloneMatchId and MatchGroupInputUtil.fetchStandaloneMatch(standaloneMatchId) or nil
if standaloneMatch then
return MatchGroupInput.mergeStandaloneIntoMatch(match, standaloneMatch)
return MatchGroupInputUtil.mergeStandaloneIntoMatch(match, standaloneMatch)
end
end

Expand All @@ -75,36 +75,36 @@ end
function CustomMatchGroupInput.processMatchWithoutStandalone(MatchParser, match)
local finishedInput = match.finished --[[@as string?]]
local winnerInput = match.winner --[[@as string?]]
Table.mergeInto(match, MatchGroupInput.readDate(match.date))
Table.mergeInto(match, MatchGroupInputUtil.readDate(match.date))

local opponents = Array.mapIndexes(function(opponentIndex)
return MatchGroupInput.readOpponent(match, opponentIndex, OPPONENT_CONFIG)
return MatchGroupInputUtil.readOpponent(match, opponentIndex, OPPONENT_CONFIG)
end)
local games = MatchFunctions.extractMaps(MatchParser, match, opponents)
match.bestof = MatchGroupInput.getBestOf(match.bestof, games)
match.bestof = MatchGroupInputUtil.getBestOf(match.bestof, games)

local autoScoreFunction = MatchGroupInput.canUseAutoScore(match, games)
local autoScoreFunction = MatchGroupInputUtil.canUseAutoScore(match, games)
and MatchFunctions.calculateMatchScore(games)
or nil

Array.forEach(opponents, function(opponent, opponentIndex)
opponent.score, opponent.status = MatchGroupInput.computeOpponentScore({
opponent.score, opponent.status = MatchGroupInputUtil.computeOpponentScore({
walkover = match.walkover,
winner = match.winner,
opponentIndex = opponentIndex,
score = opponent.score,
}, autoScoreFunction)
end)

match.finished = MatchGroupInput.matchIsFinished(match, opponents)
match.finished = MatchGroupInputUtil.matchIsFinished(match, opponents)

if match.finished then
match.resulttype = MatchGroupInput.getResultType(winnerInput, finishedInput, opponents)
match.walkover = MatchGroupInput.getWalkover(match.resulttype, opponents)
match.winner = MatchGroupInput.getWinner(match.resulttype, winnerInput, opponents)
MatchGroupInput.setPlacement(opponents, match.winner, 1, 2)
elseif MatchGroupInput.isNotPlayed(winnerInput, finishedInput) then
match.resulttype = MatchGroupInput.getResultType(winnerInput, finishedInput, opponents)
match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents)
match.walkover = MatchGroupInputUtil.getWalkover(match.resulttype, opponents)
match.winner = MatchGroupInputUtil.getWinner(match.resulttype, winnerInput, opponents)
MatchGroupInputUtil.setPlacement(opponents, match.winner, 1, 2)
elseif MatchGroupInputUtil.isNotPlayed(winnerInput, finishedInput) then
match.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponents)
match.winner = nil
end

Expand Down Expand Up @@ -140,9 +140,9 @@ function MatchFunctions.extractMaps(MatchParser, match, opponents)
map.participants = MapFunctions.getParticipants(MatchParser, map, opponents)
map.extradata = MapFunctions.getExtraData(MatchParser, map, #opponents)

map.finished = MatchGroupInput.mapIsFinished(map)
map.finished = MatchGroupInputUtil.mapIsFinished(map)
local opponentInfo = Array.map(opponents, function(_, opponentIndex)
local score, status = MatchGroupInput.computeOpponentScore({
local score, status = MatchGroupInputUtil.computeOpponentScore({
walkover = map.walkover,
winner = map.winner,
opponentIndex = opponentIndex,
Expand All @@ -152,10 +152,10 @@ function MatchFunctions.extractMaps(MatchParser, match, opponents)
end)

map.scores = Array.map(opponentInfo, Operator.property('score'))
if map.finished or MatchGroupInput.isNotPlayed(map.winner, finishedInput) then
map.resulttype = MatchGroupInput.getResultType(winnerInput, finishedInput, opponentInfo)
map.walkover = MatchGroupInput.getWalkover(map.resulttype, opponentInfo)
map.winner = MatchGroupInput.getWinner(map.resulttype, winnerInput, opponentInfo)
if map.finished or MatchGroupInputUtil.isNotPlayed(map.winner, finishedInput) then
map.resulttype = MatchGroupInputUtil.getResultType(winnerInput, finishedInput, opponentInfo)
map.walkover = MatchGroupInputUtil.getWalkover(map.resulttype, opponentInfo)
map.winner = MatchGroupInputUtil.getWinner(map.resulttype, winnerInput, opponentInfo)
end

table.insert(maps, map)
Expand All @@ -171,15 +171,15 @@ CustomMatchGroupInput.processMap = FnUtil.identity
---@return fun(opponentIndex: integer): integer
function MatchFunctions.calculateMatchScore(maps)
return function(opponentIndex)
return MatchGroupInput.computeMatchScoreFromMapWinners(maps, opponentIndex)
return MatchGroupInputUtil.computeMatchScoreFromMapWinners(maps, opponentIndex)
end
end

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

---@param match table
Expand All @@ -196,7 +196,7 @@ end
---@return table
function MatchFunctions.getExtraData(match)
return {
mvp = MatchGroupInput.readMvp(match),
mvp = MatchGroupInputUtil.readMvp(match),
}
end

Expand All @@ -208,7 +208,7 @@ function MapFunctions.getExtraData(MatchParser, map, opponentCount)
local extraData = {
comment = map.comment,
}
local getCharacterName = FnUtil.curry(MatchGroupInput.getCharacterName, HeroNames)
local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, HeroNames)

local function prefixKeyWithTeam(key, opponentIndex)
return 'team' .. opponentIndex .. key
Expand Down Expand Up @@ -248,12 +248,12 @@ end
---@return table
function MapFunctions.getParticipants(MatchParser, map, opponents)
local participants = {}
local getCharacterName = FnUtil.curry(MatchGroupInput.getCharacterName, HeroNames)
local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, HeroNames)

for opponentIndex, opponent in ipairs(opponents) do
local players = opponent.match2players or {}
for _, participant in ipairs(MatchParser.getParticipants(map, opponentIndex) or {}) do
local playerIndex = MatchGroupInput.findPlayerIndex(players, participant.id, nil, OPPONENT_CONFIG)
local playerIndex = MatchGroupInputUtil.findPlayerIndex(players, participant.id, nil, OPPONENT_CONFIG)
if playerIndex then
participant.character = getCharacterName(participant.character)
participants[opponentIndex .. '_' .. playerIndex] = participant
Expand Down
Loading

0 comments on commit 95a50dc

Please sign in to comment.