[teams] bugfix and code clanup
This commit is contained in:
@@ -87,7 +87,8 @@ object PairingHandler: PairgothApiHandler {
|
||||
val playing = (tournament.games(round).values).filter { it.id != gameId }.flatMap {
|
||||
listOf(it.black, it.white)
|
||||
}.toSet()
|
||||
if (game.result != Game.Result.UNKNOWN && (
|
||||
if ((game.result != Game.Result.UNKNOWN ||
|
||||
tournament is TeamTournament && tournament.hasIndividualResults(game.id)) && (
|
||||
game.black != payload.getInt("b") ||
|
||||
game.white != payload.getInt("w") ||
|
||||
game.handicap != payload.getInt("h")
|
||||
@@ -112,6 +113,9 @@ object PairingHandler: PairgothApiHandler {
|
||||
game.table = payload.getString("t")?.toIntOrNull() ?: badRequest("invalid table number")
|
||||
game.forcedTable = true
|
||||
}
|
||||
if (tournament is TeamTournament) {
|
||||
tournament.propagateTeamGameEdition(round, game.id)
|
||||
}
|
||||
tournament.dispatchEvent(GameUpdated, request, Json.Object("round" to round, "game" to game.toJson()))
|
||||
if (game.table != previousTable) {
|
||||
val tableWasOccupied = ( tournament.games(round).values.find { g -> g != game && g.table == game.table } != null )
|
||||
|
@@ -276,6 +276,12 @@ class TeamTournament(
|
||||
super.pair(round, pairables).also { games ->
|
||||
if (type.individual) {
|
||||
games.forEach { game ->
|
||||
pairIndividualGames(round, game)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun pairIndividualGames(round: Int, game: Game) {
|
||||
individualGames.computeIfAbsent(game.id) { id ->
|
||||
// Here white and black just denote the first board color
|
||||
val whitePlayers = teams[game.white]!!.activePlayers(round)
|
||||
@@ -289,8 +295,6 @@ class TeamTournament(
|
||||
}.toMutableSet()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun unpair(round: Int) {
|
||||
games(round).values.forEach { game ->
|
||||
@@ -304,6 +308,19 @@ class TeamTournament(
|
||||
super.unpair(round, id)
|
||||
}
|
||||
|
||||
fun hasIndividualResults(teamGameID: ID): Boolean {
|
||||
return individualGames[teamGameID]?.any { game ->
|
||||
game.result != Game.Result.UNKNOWN
|
||||
} == true
|
||||
}
|
||||
|
||||
fun propagateTeamGameEdition(round: Int, id: ID) {
|
||||
// recreate individual games
|
||||
val teamGame = games(round)[id] ?: error("Game with id $id not found")
|
||||
individualGames.remove(id)
|
||||
pairIndividualGames(round, teamGame)
|
||||
}
|
||||
|
||||
fun pairedTeams() = super.pairedPlayers()
|
||||
|
||||
fun pairedTeams(round: Int) = super.pairedPlayers(round)
|
||||
|
Reference in New Issue
Block a user