Skip to content

Commit 606acf9

Browse files
committed
support stopping game button clicks when cg is stopped, e.g. during replay
1 parent c09da9b commit 606acf9

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/board.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ export function stop(state: HeadlessState): void {
458458
state.liftable.liftDests =
459459
state.animation.current =
460460
undefined;
461+
state.gameButtonsActive = false;
461462
cancelMove(state);
462463
}
463464

@@ -545,14 +546,18 @@ export function isPocketAtDomPos(
545546
}
546547

547548
export function reorderDice(state: HeadlessState): void {
548-
if (state.dice.length === 2 && state.dice[0].isAvailable && state.dice[1].isAvailable) {
549-
state.dice = [state.dice[1], state.dice[0]];
549+
if (state.gameButtonsActive) {
550+
if (state.dice.length === 2 && state.dice[0].isAvailable && state.dice[1].isAvailable) {
551+
state.dice = [state.dice[1], state.dice[0]];
552+
}
553+
callUserFunction(state.events.selectDice, state.dice);
550554
}
551-
callUserFunction(state.events.selectDice, state.dice);
552555
}
553556

554557
export function undoButtonPressed(state: HeadlessState): void {
555-
callUserFunction(state.events.undoButton);
558+
if (state.gameButtonsActive) {
559+
callUserFunction(state.events.undoButton);
560+
}
556561
}
557562

558563
export function p1Pov(s: HeadlessState): boolean {

src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface Config {
1717
dice?: cg.Dice[]; // dice to display on the board
1818
canUndo?: boolean; // can user undo thier last action
1919
showUndoButton?: boolean; //show the undo button
20+
gameButtonsActive?: boolean; // can user process game buttons (e.g. swap dice, undo)
2021
autoCastle?: boolean; // immediately complete the castle by moving the rook after king move
2122
viewOnly?: boolean; // don't bind events: the user will never be able to move pieces around
2223
selectOnly?: boolean; // only allow user to select squares/pieces (multiple selection allowed)

src/state.ts

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface HeadlessState {
2222
dice: cg.Dice[]; // dice to display on the board
2323
canUndo: boolean; // can user undo their last action (backgammon)
2424
showUndoButton: boolean; // render the undo button (backgammon)
25+
gameButtonsActive: boolean; // can user process game buttons (e.g. swap dice, undo)
2526
autoCastle: boolean; // immediately complete the castle by moving the rook after king move
2627
viewOnly: boolean; // don't bind events: the user will never be able to move pieces around
2728
selectOnly: boolean; // only allow user to select squares/pieces (multiple selection allowed)
@@ -154,6 +155,7 @@ export function defaults(): HeadlessState {
154155
dice: [],
155156
canUndo: false,
156157
showUndoButton: false,
158+
gameButtonsActive: true,
157159
autoCastle: true,
158160
selectedPieces: new Map<cg.Key, cg.Piece>(),
159161
viewOnly: false,

0 commit comments

Comments
 (0)