Skip to content

Commit

Permalink
omegastrikers
Browse files Browse the repository at this point in the history
  • Loading branch information
hjpalpha committed Dec 15, 2024
1 parent fb0dcb2 commit a6b7391
Showing 1 changed file with 12 additions and 47 deletions.
59 changes: 12 additions & 47 deletions components/match2/wikis/omegastrikers/match_group_input_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ local MatchGroupInputUtil = Lua.import('Module:MatchGroup/Input/Util')

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

local DEFAULT_BESTOF_MATCH = 5
local DEFAULT_BESTOF_MAP = 3
Expand All @@ -36,41 +38,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.bestof = MapFunctions.getBestOf(map)
map.extradata = MapFunctions.getExtraData(map, #opponents)

map.opponents = Array.map(opponents, function(opponent, opponentIndex)
local score, status = MatchGroupInputUtil.computeOpponentScore({
walkover = map.walkover,
winner = map.winner,
opponentIndex = opponentIndex,
score = map['score' .. opponentIndex],
})
local players = MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex)
return {score = score, status = status, players = players}
end)

map.finished = MatchGroupInputUtil.mapIsFinished(map, map.opponents)

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

--
Expand Down Expand Up @@ -99,30 +67,31 @@ end

---@param map table
---@return integer
function MapFunctions.getBestOf(map)
function MapFunctions.getMapBestOf(map)
local bestof = tonumber(Logic.emptyOr(map.bestof, Variables.varDefault('map_bestof')))
Variables.varDefine('map_bestof', bestof)
return bestof or DEFAULT_BESTOF_MAP
end

---@param match table
---@param map table
---@param opponentCount integer
---@param opponents table[]
---@return table
function MapFunctions.getExtraData(map, opponentCount)
function MapFunctions.getExtraData(match, map, opponents)
local extradata = {
bestof = map.bestof,
comment = map.comment,
}

local bans = {}
local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, StrikerNames)
for opponentIndex = 1, opponentCount do
Array.forEach(opponents, function(_, opponentIndex)
bans['team' .. opponentIndex] = {}
for _, ban in Table.iter.pairsByPrefix(map, 't' .. opponentIndex .. 'b') do
ban = getCharacterName(ban)
table.insert(bans['team' .. opponentIndex], ban)
end
end
end)

extradata.bans = bans

Expand All @@ -136,9 +105,9 @@ end
function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex)
local getCharacterName = FnUtil.curry(MatchGroupInputUtil.getCharacterName, StrikerNames)
local players = Array.mapIndexes(function(playerIndex)
return opponent.match2players[playerIndex] or Logic.nilIfEmpty(map['t' .. opponentIndex .. 'c' .. playerIndex])
return map['t' .. opponentIndex .. 'p' .. playerIndex] or map['t' .. opponentIndex .. 'c' .. playerIndex]
end)
local participants, unattachedParticipants = MatchGroupInputUtil.parseParticipants(
return MatchGroupInputUtil.parseMapPlayers(
opponent.match2players,
players,
function(playerIndex)
Expand All @@ -153,10 +122,6 @@ function MapFunctions.getPlayersOfMapOpponent(map, opponent, opponentIndex)
}
end
)
Array.forEach(unattachedParticipants, function(participant)
table.insert(participants, participant)
end)
return participants
end

return CustomMatchGroupInput

0 comments on commit a6b7391

Please sign in to comment.