Use GameInformationDto for FieldUpdated events

Send a GameInformationDto from the GameManager when broadcasting FieldUpdated (includes players, current field, state and current turn) and move currentTurn toggle before the broadcast. Update client code (GameConnection and LocalGame) to accept GameInformationDto for FieldUpdated, rename handler to updateState and apply the full game state payload. This ensures clients receive consistent game metadata (including current turn) with each field update.
This commit is contained in:
Jonas
2026-03-05 22:07:48 +01:00
parent 0eed8020b8
commit 34f683854b
3 changed files with 17 additions and 10 deletions
+4 -4
View File
@@ -21,12 +21,12 @@ class LocalGame {
this.player1.onGameStarted = (gameInfo: GameInformationDto) => {
console.log('Game started for player 1', gameInfo);
this.gameStarted(gameInfo);
this.updateState(gameInfo);
};
this.player1.onFieldUpdated = (currentField: number[][]) => {
this.player1.onFieldUpdated = (currentState: GameInformationDto) => {
if (this.gameState) {
this.gameState.currentField = currentField;
this.gameState = currentState;
this.onGameStateChanged?.(this.gameState);
}
};
@@ -48,7 +48,7 @@ class LocalGame {
await this.player1.createGame(this._settings.fieldSize);
}
async gameStarted(gameInfo: GameInformationDto) {
async updateState(gameInfo: GameInformationDto) {
this.gameState = gameInfo;
this.onGameStateChanged?.(this.gameState);
}