Skip to content

Commit

Permalink
URL play parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
MuTsunTsai committed Mar 22, 2024
1 parent edb4c5d commit 0dac0c7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/modules/chess.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/sw.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/js/meta/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ export enum Background {
green = "green",
classic = "classic",
}

export enum Tabs {
edit = 0,
options = 1,
database = 2,
bbs = 4,
api = 5,
play = 6,
compute = 7,
project = 8,
}
1 change: 1 addition & 0 deletions src/js/modules/pgn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function parseMoves(text: string): string[] {
.replace(/\s+/g, " ")
.trim();

if(text === "") return []; // empty game
const tokens = text.split(" ").filter(m => !m.match(/^\$\d+$/)); // ignore NAG

const last = tokens[tokens.length - 1];
Expand Down
11 changes: 10 additions & 1 deletion src/js/tools/play/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { drawTemplate, load } from "js/view/render";
import { orthodoxFEN, parseFullFEN, setFEN, setSquare, squares, toggleReadOnly } from "js/interface/squares";
import { onSession, state, status, store } from "js/store";
import { alert } from "js/meta/dialogs";
import { Color, PlayMode, TemplateRow } from "js/meta/enum";
import { Color, PlayMode, Tabs, TemplateRow } from "js/meta/enum";
import { BOARD_SIZE } from "js/meta/constants";
import { RANK_1ST, RANK_8TH, MASK } from "./data";

Expand Down Expand Up @@ -269,3 +269,12 @@ export const PLAY = {
await importGame(text);
},
};

// Handle URL play parameter
const paramPlay = new URL(location.href).searchParams.get("play");
if(paramPlay !== null) {
setTimeout(() => {
state.tab = Tabs.play;
importGame(paramPlay);
}, 0);
}

0 comments on commit 0dac0c7

Please sign in to comment.