Move controller updates into GamesManagerState (#8158)

This commit is contained in:
2026-06-25 07:18:49 -07:00
committed by GitHub
parent b88613a6f1
commit 53180baddd
2 changed files with 34 additions and 23 deletions
@@ -465,25 +465,13 @@ class GamesManager(
updateState(_.withControllerInfo(gameId, controllerInfo))
private def updateController(gameId: GameId, controller: GameController): Unit =
updateState(state =>
state.withControllerRegistry(
state.controllerRegistry.withUpdatedController(gameId, controller)
)
)
updateState(_.withUpdatedController(gameId, controller))
private def updateController(gameId: GameId, update: GameController => GameController): Unit =
updateState(state =>
state.withControllerRegistry(
state.controllerRegistry.withUpdatedController(gameId, update)
)
)
updateState(_.withUpdatedController(gameId, update))
private def updateLastPlayed(gameId: GameId, userId: UserId): Unit =
updateState(state =>
state.withControllerRegistry(
state.controllerRegistry.withUpdatedLastPlayed(gameId, userId, System.currentTimeMillis())
)
)
updateState(_.withUpdatedLastPlayed(gameId, userId, System.currentTimeMillis()))
val shardokClient =
new ShardokInterfaceGrpcClient(shardokInternalInterface, this)
@@ -1384,14 +1372,12 @@ class GamesManager(
maxPlayers: Int,
createdTimestampMillis: Long = 0L
): GameController = this.synchronized {
updateState(state =>
state.withControllerRegistry(
state.controllerRegistry.put(
controller = controller,
isAiGame = isAiGame,
maxPlayers = maxPlayers,
createdTimestampMillis = createdTimestampMillis
)
updateState(
_.withController(
controller = controller,
isAiGame = isAiGame,
maxPlayers = maxPlayers,
createdTimestampMillis = createdTimestampMillis
)
)
controller
@@ -4,6 +4,7 @@ import net.eagle0.common.tutorial_battle_config.TutorialBattleConfig
import net.eagle0.eagle.{GameId, UserId}
import net.eagle0.eagle.internal.hero.Hero
import net.eagle0.eagle.internal.running_games.RunningGame
import net.eagle0.eagle.service.controller.GameController
import net.eagle0.eagle.service.new_game_creation.ExpandedGameParameters
case class WaitingGamePlayerInfo(
@@ -50,6 +51,30 @@ case class GamesManagerState(
def withControllerRegistry(updatedControllerRegistry: GameControllerRegistry): GamesManagerState =
copy(controllerRegistry = updatedControllerRegistry)
def withUpdatedController(gameId: GameId, controller: GameController): GamesManagerState =
withControllerRegistry(controllerRegistry.withUpdatedController(gameId, controller))
def withUpdatedController(gameId: GameId, update: GameController => GameController): GamesManagerState =
withControllerRegistry(controllerRegistry.withUpdatedController(gameId, update))
def withUpdatedLastPlayed(gameId: GameId, userId: UserId, millis: Long): GamesManagerState =
withControllerRegistry(controllerRegistry.withUpdatedLastPlayed(gameId, userId, millis))
def withController(
controller: GameController,
isAiGame: Boolean,
maxPlayers: Int,
createdTimestampMillis: Long = 0L
): GamesManagerState =
withControllerRegistry(
controllerRegistry.put(
controller = controller,
isAiGame = isAiGame,
maxPlayers = maxPlayers,
createdTimestampMillis = createdTimestampMillis
)
)
def withoutControllerInfo(gameId: GameId): (GamesManagerState, Option[ControllerInfo]) = {
val (updatedRegistry, existing) = controllerRegistry.remove(gameId)
withControllerRegistry(updatedRegistry) -> existing