Skip to content

Commit

Permalink
Unified variation move number settings, moved undo request indicator …
Browse files Browse the repository at this point in the history
…setting to callbacks
  • Loading branch information
anoek committed Aug 13, 2024
1 parent e5df12f commit 2c148cc
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 19 deletions.
2 changes: 1 addition & 1 deletion engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "goban-engine",
"version": "8.3.20",
"version": "8.3.21",
"description": "",
"main": "build/goban-engine.js",
"types": "build/engine/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "goban",
"version": "8.3.20",
"version": "8.3.21",
"description": "",
"main": "build/goban.js",
"types": "build/src/index.d.ts",
Expand Down
13 changes: 10 additions & 3 deletions src/Goban/CanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ export class GobanCanvas extends Goban implements GobanCanvasInterface {
if (cur.x === i && cur.y === j) {
const move_diff = cur.getMoveNumberDifferenceFromTrunk();
if (move_diff !== cur.move_number) {
if (!cur.edited && this.show_move_numbers) {
if (!cur.edited && this.show_variation_move_numbers) {
alt_marking = cur.getMoveNumberDifferenceFromTrunk().toString();
}
}
Expand Down Expand Up @@ -2184,7 +2184,7 @@ export class GobanCanvas extends Goban implements GobanCanvasInterface {
} else {
if (
this.engine.undo_requested &&
this.visual_undo_request_indicator &&
this.getShowUndoRequestIndicator() &&
this.engine.undo_requested === this.engine.cur_move.move_number
) {
const letter = "?";
Expand Down Expand Up @@ -2307,7 +2307,7 @@ export class GobanCanvas extends Goban implements GobanCanvasInterface {
if (cur.x === i && cur.y === j) {
const move_diff = cur.getMoveNumberDifferenceFromTrunk();
if (move_diff !== cur.move_number) {
if (!cur.edited && this.show_move_numbers) {
if (!cur.edited && this.show_variation_move_numbers) {
alt_marking = cur.getMoveNumberDifferenceFromTrunk().toString();
}
}
Expand Down Expand Up @@ -2664,6 +2664,13 @@ export class GobanCanvas extends Goban implements GobanCanvasInterface {
(this.engine.phase === "play" || this.engine.phase === "finished")
) {
ret += "last_move,";
if (
this.engine.undo_requested &&
this.getShowUndoRequestIndicator() &&
this.engine.undo_requested === this.engine.cur_move.move_number
) {
ret += "?" + ",";
}
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/Goban/InteractiveBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export abstract class GobanInteractive extends GobanBase {
public draw_left_labels: boolean;
public draw_right_labels: boolean;
public draw_top_labels: boolean;
public visual_undo_request_indicator: boolean;
public height: number;
public last_clock?: AdHocClock;
public last_emitted_clock?: JGOFClockWithTransmitting;
Expand Down Expand Up @@ -273,7 +272,7 @@ export abstract class GobanInteractive extends GobanBase {
protected review_had_gamedata: boolean;
protected scoring_mode: boolean | "stalling-scoring-mode";
protected shift_key_is_down: boolean;
protected show_move_numbers: boolean;
//protected show_move_numbers: boolean;
protected show_variation_move_numbers: boolean;
protected square_size: number = 10;
protected stone_placement_enabled: boolean;
Expand Down Expand Up @@ -337,10 +336,6 @@ export abstract class GobanInteractive extends GobanBase {
typeof config.variation_stone_opacity !== "undefined"
? config.variation_stone_opacity
: 0.6;
this.visual_undo_request_indicator =
"visual_undo_request_indicator" in config
? !!config.visual_undo_request_indicator
: false;
this.original_square_size = config.square_size || "auto";
//this.square_size = config["square_size"] || "auto";
this.interactive = !!config.interactive;
Expand Down Expand Up @@ -410,7 +405,7 @@ export abstract class GobanInteractive extends GobanBase {
this.draw_right_labels = "draw_right_labels" in config ? !!config.draw_right_labels : true;
this.draw_bottom_labels =
"draw_bottom_labels" in config ? !!config.draw_bottom_labels : true;
this.show_move_numbers = this.getShowMoveNumbers();
//this.show_move_numbers = this.getShowMoveNumbers();
this.show_variation_move_numbers = this.getShowVariationMoveNumbers();

if (this.bounds.left > 0) {
Expand Down Expand Up @@ -475,12 +470,20 @@ export abstract class GobanInteractive extends GobanBase {
}
return "A1";
}
protected getShowUndoRequestIndicator(): boolean {
if (callbacks.getShowUndoRequestIndicator) {
return callbacks.getShowUndoRequestIndicator();
}
return true;
}
/*
protected getShowMoveNumbers(): boolean {
if (callbacks.getShowMoveNumbers) {
return callbacks.getShowMoveNumbers();
}
return false;
}
*/
protected getShowVariationMoveNumbers(): boolean {
if (callbacks.getShowVariationMoveNumbers) {
return callbacks.getShowVariationMoveNumbers();
Expand Down
4 changes: 2 additions & 2 deletions src/Goban/OGSConnectivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export abstract class OGSConnectivity extends GobanInteractive {
this.engine.undo_requested = parseInt(move_number);
this.emit("update");
this.emit("audio-undo-requested");
if (this.visual_undo_request_indicator) {
if (this.getShowUndoRequestIndicator()) {
this.redraw(true); // need to update the mark on the last move
}
},
Expand All @@ -403,7 +403,7 @@ export abstract class OGSConnectivity extends GobanInteractive {
this.engine.undo_requested = undefined; // can't call delete here because this is a getter/setter
this.emit("update");
this.emit("undo_canceled");
if (this.visual_undo_request_indicator) {
if (this.getShowUndoRequestIndicator()) {
this.redraw(true);
}
});
Expand Down
19 changes: 15 additions & 4 deletions src/Goban/SVGRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,8 +1069,10 @@ export class SVGRenderer extends Goban implements GobanSVGInterface {

if (this.mode === "analyze" && this.analyze_tool === "stone") {
let c: MoveTree | null = this.engine.cur_move;

while (c && !c.trunk) {
let mark: any = c.getMoveNumberDifferenceFromTrunk();

if (c.edited) {
mark = "triangle";
}
Expand Down Expand Up @@ -1261,14 +1263,16 @@ export class SVGRenderer extends Goban implements GobanSVGInterface {
this.engine &&
this.engine.cur_move &&
(this.mode !== "play" ||
(typeof this.isInPushedAnalysis() !== "undefined" && this.isInPushedAnalysis()))
(typeof this.isInPushedAnalysis() !== "undefined" &&
this.isInPushedAnalysis() &&
this.show_variation_move_numbers))
) {
let cur: MoveTree | null = this.engine.cur_move;
for (; cur && !cur.trunk; cur = cur.parent) {
if (cur.x === i && cur.y === j) {
const move_diff = cur.getMoveNumberDifferenceFromTrunk();
if (move_diff !== cur.move_number) {
if (!cur.edited && this.show_move_numbers) {
if (!cur.edited && this.show_variation_move_numbers) {
alt_marking = cur.getMoveNumberDifferenceFromTrunk().toString();
}
}
Expand Down Expand Up @@ -2176,7 +2180,7 @@ export class SVGRenderer extends Goban implements GobanSVGInterface {
} else {
if (
this.engine.undo_requested &&
this.visual_undo_request_indicator &&
this.getShowUndoRequestIndicator() &&
this.engine.undo_requested === this.engine.cur_move.move_number
) {
const letter = "?";
Expand Down Expand Up @@ -2318,7 +2322,7 @@ export class SVGRenderer extends Goban implements GobanSVGInterface {
if (cur.x === i && cur.y === j) {
const move_diff = cur.getMoveNumberDifferenceFromTrunk();
if (move_diff !== cur.move_number) {
if (!cur.edited && this.show_move_numbers) {
if (!cur.edited && this.show_variation_move_numbers) {
alt_marking = cur.getMoveNumberDifferenceFromTrunk().toString();
}
}
Expand Down Expand Up @@ -2686,6 +2690,13 @@ export class SVGRenderer extends Goban implements GobanSVGInterface {
(this.engine.phase === "play" || this.engine.phase === "finished")
) {
ret += "last_move,";
if (
this.engine.undo_requested &&
this.getShowUndoRequestIndicator() &&
this.engine.undo_requested === this.engine.cur_move.move_number
) {
ret += "?" + ",";
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Goban/callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export interface GobanCallbacks {
getClockDrift?: () => number;
getNetworkLatency?: () => number;
getLocation?: () => string;
getShowMoveNumbers?: () => boolean;
// getShowMoveNumbers?: () => boolean;
getShowVariationMoveNumbers?: () => boolean;
getShowUndoRequestIndicator?: () => boolean;
getMoveTreeNumbering?: () => "move-coordinates" | "none" | "move-number";
getCDNReleaseBase?: () => string;
getSoundEnabled?: () => boolean;
Expand Down

0 comments on commit 2c148cc

Please sign in to comment.