From 34f683854ba43f3f54cbf4bc3568c0f6720f7976 Mon Sep 17 00:00:00 2001 From: Jonas <77726472+kobolol@users.noreply.github.com> Date: Thu, 5 Mar 2026 22:07:48 +0100 Subject: [PATCH] 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. --- API/Services/GameManager/GameManager.cs | 13 ++++++++++--- GUI/src/scripts/logic/localMode/LocalGame.ts | 8 ++++---- GUI/src/scripts/logic/signalR/GameConnection.ts | 6 +++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/API/Services/GameManager/GameManager.cs b/API/Services/GameManager/GameManager.cs index 472209d..fb3a54d 100644 --- a/API/Services/GameManager/GameManager.cs +++ b/API/Services/GameManager/GameManager.cs @@ -77,7 +77,16 @@ public class GameManager(IGameRepository gameRepository, IHubContext { 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); } diff --git a/GUI/src/scripts/logic/signalR/GameConnection.ts b/GUI/src/scripts/logic/signalR/GameConnection.ts index 221e6a2..e9ff091 100644 --- a/GUI/src/scripts/logic/signalR/GameConnection.ts +++ b/GUI/src/scripts/logic/signalR/GameConnection.ts @@ -33,7 +33,7 @@ class GameConnection { public onGameJoined?: (gameIdentifier: GameIdentifier) => void; public onGameStarted?: (gameInfo: GameInformationDto) => void; public onGameInformation?: (gameInfo: GameInformationDto) => void; - public onFieldUpdated?: (currentField: number[][]) => void; + public onFieldUpdated?: (currentField: GameInformationDto) => void; public onGameEnded?: (gameEndedInfo: GameEndedDto) => void; public onError?: (error: string) => void; public onGameDestroyed?: () => void; @@ -61,8 +61,8 @@ class GameConnection { this.onGameInformation?.(payload); }); - this.connection.on('FieldUpdated', (currentField: number[][]) => { - this.onFieldUpdated?.(currentField); + this.connection.on('FieldUpdated', (payload: GameInformationDto) => { + this.onFieldUpdated?.(payload); }); this.connection.on('GameEnded', (payload: GameEndedDto) => {