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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user