Skip to content

Commit

Permalink
Add support for toggling the stone removal graphic and removal scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
anoek committed Jul 30, 2024
1 parent 3bd44e5 commit d93fe4e
Show file tree
Hide file tree
Showing 6 changed files with 33 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.16",
"version": "8.3.19",
"description": "",
"main": "build/goban-engine.js",
"types": "build/engine/index.d.ts",
Expand Down
10 changes: 6 additions & 4 deletions examples/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ try {

Goban.setCallbacks({
getSelectedThemes: () => ({
board: "Kaya",
"board": "Kaya",
//board: "Anime",

white: "Plain",
black: "Plain",
"white": "Plain",
"black": "Plain",
//white: "Glass",
//black: "Glass",
//white: "Worn Glass",
Expand All @@ -63,6 +63,8 @@ Goban.setCallbacks({
//black: "Anime",
//white: "Custom",
//black: "Custom",
"removal-graphic": "square",
"removal-scale": 1.0,
}),

customWhiteStoneUrl: () => {
Expand Down Expand Up @@ -309,7 +311,7 @@ function GobanTestPage(): JSX.Element {
<ReactGobanCanvas key={idx} />
),
)}
{true && (svg_or_canvas === "svg" ? <ReactGobanSVG /> : <ReactGobanCanvas />)}
{svg_or_canvas === "svg" ? <ReactGobanSVG /> : <ReactGobanCanvas />}
</div>
);
}
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.16",
"version": "8.3.19",
"description": "",
"main": "build/goban.js",
"types": "build/src/index.d.ts",
Expand Down
8 changes: 5 additions & 3 deletions src/Goban/CanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ export class GobanCanvas extends Goban implements GobanCanvasInterface {
protected title_div?: HTMLElement;

private themes: GobanSelectedThemes = {
board: "Plain",
black: "Plain",
white: "Plain",
"board": "Plain",
"black": "Plain",
"white": "Plain",
"removal-graphic": "x",
"removal-scale": 1.0,
};
private theme_black!: GobanTheme;
private theme_black_stones: Array<any> = [];
Expand Down
16 changes: 12 additions & 4 deletions src/Goban/Goban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import { THEMES, THEMES_SORTED } from "./themes";

export const GOBAN_FONT = "Verdana,Arial,sans-serif";
export interface GobanSelectedThemes {
board: string;
white: string;
black: string;
"board": string;
"white": string;
"black": string;
"removal-graphic": "square" | "x";
"removal-scale": number;
}
export type LabelPosition =
| "all"
Expand Down Expand Up @@ -85,7 +87,13 @@ export abstract class Goban extends OGSConnectivity {
}
//return {white:'Plain', black:'Plain', board:'Plain'};
//return {white:'Plain', black:'Plain', board:'Kaya'};
return { white: "Shell", black: "Slate", board: "Kaya" };
return {
"white": "Shell",
"black": "Slate",
"board": "Kaya",
"removal-graphic": "square",
"removal-scale": 1.0,
};
}

protected putOrClearLabel(x: number, y: number, mode?: "put" | "clear"): boolean {
Expand Down
14 changes: 8 additions & 6 deletions src/Goban/SVGRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ export class SVGRenderer extends Goban implements GobanSVGInterface {
protected title_div?: HTMLElement;

private themes: GobanSelectedThemes = {
board: "Plain",
black: "Plain",
white: "Plain",
"board": "Plain",
"black": "Plain",
"white": "Plain",
"removal-graphic": "x",
"removal-scale": 1.0,
};
private theme_black!: GobanTheme;
private theme_black_stones: Array<any> = [];
Expand Down Expand Up @@ -1198,7 +1200,7 @@ export class SVGRenderer extends Goban implements GobanSVGInterface {
}
}
private __drawSquare(i: number, j: number): void {
if (!this.drawing_enabled || this.no_display) {
if (!this.drawing_enabled || this.no_display || !this.grid || !this.grid[j]) {
return;
}
if (i < 0 || j < 0) {
Expand All @@ -1218,7 +1220,7 @@ export class SVGRenderer extends Goban implements GobanSVGInterface {
cell = this.grid[j][i] = document.createElementNS("http://www.w3.org/2000/svg", "g");
this.grid_layer!.appendChild(cell);

const removed_stone_scale = 0.9;
const removed_stone_scale = this.themes["removal-scale"];
const ss = this.square_size;
let ox = this.draw_left_labels ? ss : 0;
let oy = this.draw_top_labels ? ss : 0;
Expand Down Expand Up @@ -1662,7 +1664,7 @@ export class SVGRenderer extends Goban implements GobanSVGInterface {
//(this.mode === "analyze" && pos.stone_removed)
pos.stone_removed
) {
draw_removal_x = true;
draw_removal_x = this.themes["removal-graphic"] === "x";
transform = `translate(${l + this.metrics.mid * (1.0 - removed_stone_scale)}, ${
t + this.metrics.mid * (1.0 - removed_stone_scale)
}) scale(${removed_stone_scale})`;
Expand Down

0 comments on commit d93fe4e

Please sign in to comment.