From 84c89da5930c4eb4d36591199dbac28aea636a10 Mon Sep 17 00:00:00 2001 From: gbtami Date: Thu, 2 Jan 2025 16:05:55 +0100 Subject: [PATCH] Fix fog piece regression --- client/cgCtrl.ts | 8 +++++++- client/gameCtrl.ts | 4 +--- client/roundCtrl.ts | 4 ++-- server/bug/game_bug.py | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/client/cgCtrl.ts b/client/cgCtrl.ts index 1d68be630..dcffa70bb 100644 --- a/client/cgCtrl.ts +++ b/client/cgCtrl.ts @@ -27,6 +27,7 @@ export abstract class ChessgroundController implements BoardController { fullfen: string; notation: cg.Notation; + fog: boolean; constructor(el: HTMLElement, model: PyChessModel, fullfen: string, pocket0: HTMLElement, pocket1: HTMLElement, boardName: BoardName = '') { this.boardName = boardName; @@ -40,9 +41,10 @@ export abstract class ChessgroundController implements BoardController { this.oppcolor = 'black'; this.fullfen = fullfen; this.notation = this.variant.notation; + this.fog = model.variant === 'fogofwar'; const parts = this.fullfen.split(" "); - const fen_placement: cg.FEN = parts[0]; + const fen_placement: cg.FEN = (this.fog) ? this.fogFen(parts[0]) : parts[0]; this.chessground = Chessground(el, { fen: fen_placement as cg.FEN, @@ -74,6 +76,10 @@ export abstract class ChessgroundController implements BoardController { window.addEventListener('beforeunload', () => this.ffishBoard.delete()); } + fogFen(currentFen: string): string { + return currentFen.replace(/\*/g, '*~'); + } + toggleOrientation(): void { this.chessground.toggleOrientation(); } diff --git a/client/gameCtrl.ts b/client/gameCtrl.ts index 43c8cc582..5e6a6e991 100644 --- a/client/gameCtrl.ts +++ b/client/gameCtrl.ts @@ -36,7 +36,6 @@ export abstract class GameController extends ChessgroundController implements Ch aiLevel: number; rated: string; corr : boolean; - fog: boolean; base: number; inc: number; @@ -115,7 +114,6 @@ export abstract class GameController extends ChessgroundController implements Ch this.brating = model["brating"]; this.rated = model["rated"]; this.corr = model["corr"] === 'True'; - this.fog = this.variant.name === 'fogofwar'; this.mirrorBoard = false; this.spectator = this.username !== this.wplayer && this.username !== this.bplayer; @@ -320,7 +318,7 @@ export abstract class GameController extends ChessgroundController implements Ch const fen = (this.mirrorBoard) ? this.getAliceFen(step.fen) : step.fen; this.chessground.set({ - fen: fen, + fen: (this.fog) ? this.fogFen(fen) : fen, turnColor: step.turnColor, movable: { color: step.turnColor, diff --git a/client/roundCtrl.ts b/client/roundCtrl.ts index 88aba2b34..adca77da7 100644 --- a/client/roundCtrl.ts +++ b/client/roundCtrl.ts @@ -906,7 +906,7 @@ export class RoundController extends GameController { if (this.turnColor === this.mycolor) { if (latestPly) { this.chessground.set({ - fen: this.fullfen, + fen: (this.fog) ? this.fogFen(this.fullfen) : this.fullfen, turnColor: this.turnColor, movable: { free: false, @@ -941,7 +941,7 @@ export class RoundController extends GameController { } else { this.chessground.set({ // giving fen here will place castling rooks to their destination in chess960 variants - fen: parts[0], + fen: (this.fog) ? this.fogFen(this.fullfen) : parts[0], turnColor: this.turnColor, check: msg.check, lastMove: lastMove, diff --git a/server/bug/game_bug.py b/server/bug/game_bug.py index ecff82e79..111e0a4ea 100644 --- a/server/bug/game_bug.py +++ b/server/bug/game_bug.py @@ -552,7 +552,7 @@ async def game_ended(self, user, reason): ), } - def get_board(self, full=False): + def get_board(self, full=False, persp_color=None): [clocks_a, clocks_b] = self.gameClocks.get_clocks_for_board_msg(full) if full: steps = self.steps