Skip to content

Commit

Permalink
Fix fog piece regression
Browse files Browse the repository at this point in the history
  • Loading branch information
gbtami committed Jan 2, 2025
1 parent b2ce43e commit 84c89da
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
8 changes: 7 additions & 1 deletion client/cgCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 1 addition & 3 deletions client/gameCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export abstract class GameController extends ChessgroundController implements Ch
aiLevel: number;
rated: string;
corr : boolean;
fog: boolean;

base: number;
inc: number;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions client/roundCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/bug/game_bug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 84c89da

Please sign in to comment.