@johnmorrisdotca/sugoroku 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +395 -77
- package/dist/board.d.ts +216 -12
- package/dist/board.js +204 -12
- package/dist/colours.d.ts +80 -8
- package/dist/colours.js +51 -6
- package/dist/computer.d.ts +138 -8
- package/dist/computer.js +109 -7
- package/dist/dice.d.ts +53 -4
- package/dist/dice.js +42 -3
- package/dist/draw.d.ts +43 -3
- package/dist/draw.js +33 -2
- package/dist/element-define.d.ts +1 -1
- package/dist/element-define.js +4 -13
- package/dist/element.d.ts +233 -3
- package/dist/element.js +402 -48
- package/dist/evaluate.d.ts +76 -4
- package/dist/evaluate.js +65 -3
- package/dist/game.d.ts +408 -23
- package/dist/game.js +328 -18
- package/dist/geometry.d.ts +50 -3
- package/dist/geometry.js +20 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/match.d.ts +66 -4
- package/dist/match.js +55 -4
- package/dist/mount.d.ts +75 -4
- package/dist/mount.js +25 -3
- package/dist/moves.d.ts +48 -1
- package/dist/moves.js +35 -1
- package/dist/notation.d.ts +92 -4
- package/dist/notation.js +82 -3
- package/dist/playStyle.d.ts +6 -0
- package/dist/playStyle.js +6 -0
- package/dist/plays.d.ts +108 -3
- package/dist/plays.js +96 -3
- package/dist/positionId.d.ts +29 -1
- package/dist/positionId.js +29 -1
- package/dist/random.d.ts +33 -3
- package/dist/random.js +22 -2
- package/dist/record.d.ts +150 -7
- package/dist/record.js +94 -5
- package/dist/rules.d.ts +130 -10
- package/dist/rules.js +99 -9
- package/dist/side.d.ts +38 -3
- package/dist/side.js +30 -3
- package/dist/sound.d.ts +61 -3
- package/dist/sound.js +27 -2
- package/dist/strings.d.ts +42 -2
- package/dist/strings.js +34 -2
- package/dist/style.d.ts +6 -0
- package/dist/style.js +6 -0
- package/dist/variants.d.ts +113 -8
- package/dist/variants.js +62 -5
- package/dist/version.d.ts +9 -2
- package/dist/version.js +9 -2
- package/package.json +27 -19
package/dist/side.d.ts
CHANGED
|
@@ -3,11 +3,46 @@
|
|
|
3
3
|
* position is kept per side, in that side's own numbering of the points: a
|
|
4
4
|
* side's own point 1 is the one nearest its bearing-off, its own point 24 the
|
|
5
5
|
* one farthest from it, whichever way the board is drawn.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import type { Side } from "@johnmorrisdotca/sugoroku";
|
|
10
|
+
*
|
|
11
|
+
* const value: Side = "white";
|
|
12
|
+
* console.log(value);
|
|
13
|
+
* ```
|
|
6
14
|
*/
|
|
7
15
|
export type Side = "white" | "black";
|
|
8
|
-
/** Both sides, white first.
|
|
16
|
+
/** Both sides, white first.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { SIDES } from "@johnmorrisdotca/sugoroku";
|
|
21
|
+
* console.log(SIDES);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
9
24
|
export declare const SIDES: readonly [Side, Side];
|
|
10
|
-
/** The other side.
|
|
25
|
+
/** The other side.
|
|
26
|
+
*
|
|
27
|
+
* @param side - The side being examined: white or black.
|
|
28
|
+
* @returns The other side.
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { otherSide } from "@johnmorrisdotca/sugoroku";
|
|
32
|
+
*
|
|
33
|
+
* console.log(otherSide("white"));
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
11
36
|
export declare function otherSide(side: Side): Side;
|
|
12
|
-
/** 0 for white and 1 for black: where a side's counts are kept in a position.
|
|
37
|
+
/** 0 for white and 1 for black: where a side's counts are kept in a position.
|
|
38
|
+
*
|
|
39
|
+
* @param side - The side being examined: white or black.
|
|
40
|
+
* @returns 0 for white and 1 for black: where a side's counts are kept in a position.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { sideIndex } from "@johnmorrisdotca/sugoroku";
|
|
44
|
+
*
|
|
45
|
+
* console.log(sideIndex("black"));
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
13
48
|
export declare function sideIndex(side: Side): 0 | 1;
|
package/dist/side.js
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
|
-
/** Both sides, white first.
|
|
1
|
+
/** Both sides, white first.
|
|
2
|
+
*
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { SIDES } from "@johnmorrisdotca/sugoroku";
|
|
6
|
+
* console.log(SIDES);
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
2
9
|
export const SIDES = ["white", "black"];
|
|
3
|
-
/** The other side.
|
|
10
|
+
/** The other side.
|
|
11
|
+
*
|
|
12
|
+
* @param side - The side being examined: white or black.
|
|
13
|
+
* @returns The other side.
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { otherSide } from "@johnmorrisdotca/sugoroku";
|
|
17
|
+
*
|
|
18
|
+
* console.log(otherSide("white"));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
export function otherSide(side) {
|
|
5
22
|
return side === "white" ? "black" : "white";
|
|
6
23
|
}
|
|
7
|
-
/** 0 for white and 1 for black: where a side's counts are kept in a position.
|
|
24
|
+
/** 0 for white and 1 for black: where a side's counts are kept in a position.
|
|
25
|
+
*
|
|
26
|
+
* @param side - The side being examined: white or black.
|
|
27
|
+
* @returns 0 for white and 1 for black: where a side's counts are kept in a position.
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { sideIndex } from "@johnmorrisdotca/sugoroku";
|
|
31
|
+
*
|
|
32
|
+
* console.log(sideIndex("black"));
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
8
35
|
export function sideIndex(side) {
|
|
9
36
|
return side === "white" ? 0 : 1;
|
|
10
37
|
}
|
package/dist/sound.d.ts
CHANGED
|
@@ -5,16 +5,74 @@
|
|
|
5
5
|
* `sounds/CREDITS.txt`) and are found beside the code with `import.meta.url`,
|
|
6
6
|
* so a bundler that follows that pattern ships them. A page that serves them
|
|
7
7
|
* from somewhere else gives their addresses.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import type { SoundName } from "@johnmorrisdotca/sugoroku/play";
|
|
12
|
+
*
|
|
13
|
+
* const value: SoundName = "clack";
|
|
14
|
+
* console.log(value);
|
|
15
|
+
* ```
|
|
8
16
|
*/
|
|
9
17
|
export type SoundName = "clack" | "hit" | "dice" | "cube";
|
|
10
|
-
/** The address of each sound.
|
|
18
|
+
/** The address of each sound.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import type { SoundUrls } from "@johnmorrisdotca/sugoroku/play";
|
|
23
|
+
*
|
|
24
|
+
* const value: SoundUrls = {};
|
|
25
|
+
* console.log(value);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
11
28
|
export type SoundUrls = Partial<Record<SoundName, string>>;
|
|
12
|
-
/** The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
|
|
29
|
+
/** The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
|
|
30
|
+
*
|
|
31
|
+
* @returns The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { packagedSounds } from "@johnmorrisdotca/sugoroku/play";
|
|
35
|
+
*
|
|
36
|
+
* console.log(Object.keys(packagedSounds()));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
13
39
|
export declare function packagedSounds(): SoundUrls;
|
|
40
|
+
/** Optional board-sound playback and cleanup methods.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts no-run
|
|
44
|
+
* import { legalPlaysOf, newGame, rollOpening, settingsFor } from "@johnmorrisdotca/sugoroku";
|
|
45
|
+
* import type { SoundPlayer } from "@johnmorrisdotca/sugoroku/play";
|
|
46
|
+
* import { createSounds } from "@johnmorrisdotca/sugoroku/play";
|
|
47
|
+
*
|
|
48
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
49
|
+
* const game = rollOpening(newGame(settings),[3,1]);
|
|
50
|
+
* const play = legalPlaysOf(game)[0];
|
|
51
|
+
* const sounds: SoundPlayer = createSounds({});
|
|
52
|
+
* console.log(typeof sounds.play);
|
|
53
|
+
* sounds.destroy();
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
14
56
|
export type SoundPlayer = {
|
|
15
57
|
play: (name: SoundName) => void;
|
|
16
58
|
/** Stop and let go of everything. */
|
|
17
59
|
destroy: () => void;
|
|
18
60
|
};
|
|
19
|
-
/** A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
|
|
61
|
+
/** A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
|
|
62
|
+
*
|
|
63
|
+
* @param urls - Optional URLs of the native board sounds.
|
|
64
|
+
* @returns A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts no-run
|
|
67
|
+
* import { legalPlaysOf, newGame, rollOpening, settingsFor } from "@johnmorrisdotca/sugoroku";
|
|
68
|
+
* import { createSounds } from "@johnmorrisdotca/sugoroku/play";
|
|
69
|
+
*
|
|
70
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
71
|
+
* const game = rollOpening(newGame(settings),[3,1]);
|
|
72
|
+
* const play = legalPlaysOf(game)[0];
|
|
73
|
+
* const sounds = createSounds({});
|
|
74
|
+
* console.log(typeof sounds.play);
|
|
75
|
+
* sounds.destroy();
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
20
78
|
export declare function createSounds(urls: SoundUrls): SoundPlayer;
|
package/dist/sound.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
const FILES = { clack: "clack.wav", hit: "hit.wav", dice: "dice.wav", cube: "cube.wav" };
|
|
2
|
-
/** The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
|
|
2
|
+
/** The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
|
|
3
|
+
*
|
|
4
|
+
* @returns The sounds' addresses beside the package's code, or an empty set where `import.meta.url` is not an address (some test runners).
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { packagedSounds } from "@johnmorrisdotca/sugoroku/play";
|
|
8
|
+
*
|
|
9
|
+
* console.log(Object.keys(packagedSounds()));
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
3
12
|
export function packagedSounds() {
|
|
4
13
|
try {
|
|
5
14
|
const urls = {};
|
|
@@ -11,7 +20,23 @@ export function packagedSounds() {
|
|
|
11
20
|
return {};
|
|
12
21
|
}
|
|
13
22
|
}
|
|
14
|
-
/** A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
|
|
23
|
+
/** A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
|
|
24
|
+
*
|
|
25
|
+
* @param urls - Optional URLs of the native board sounds.
|
|
26
|
+
* @returns A player for the sounds, which makes its audio only when first asked to play, as browsers insist on a gesture first. Plays nothing where there is no audio.
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts no-run
|
|
29
|
+
* import { legalPlaysOf, newGame, rollOpening, settingsFor } from "@johnmorrisdotca/sugoroku";
|
|
30
|
+
* import { createSounds } from "@johnmorrisdotca/sugoroku/play";
|
|
31
|
+
*
|
|
32
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
33
|
+
* const game = rollOpening(newGame(settings),[3,1]);
|
|
34
|
+
* const play = legalPlaysOf(game)[0];
|
|
35
|
+
* const sounds = createSounds({});
|
|
36
|
+
* console.log(typeof sounds.play);
|
|
37
|
+
* sounds.destroy();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
15
40
|
export function createSounds(urls) {
|
|
16
41
|
const cache = new Map();
|
|
17
42
|
let gone = false;
|
package/dist/strings.d.ts
CHANGED
|
@@ -6,10 +6,50 @@
|
|
|
6
6
|
*
|
|
7
7
|
* `{name}` in a line is a value filled in. The Japanese is a first draft that no
|
|
8
8
|
* native reader has yet checked.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import type { SugorokuLanguage } from "@johnmorrisdotca/sugoroku/play";
|
|
13
|
+
*
|
|
14
|
+
* const value: SugorokuLanguage = "ja";
|
|
15
|
+
* console.log(value);
|
|
16
|
+
* ```
|
|
9
17
|
*/
|
|
10
18
|
export type SugorokuLanguage = "en" | "ja";
|
|
19
|
+
/** The native English and Japanese labels, announcements and interpolation templates.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { SUGOROKU_STRINGS } from "@johnmorrisdotca/sugoroku/play";
|
|
24
|
+
* console.log(SUGOROKU_STRINGS);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
11
27
|
export declare const SUGOROKU_STRINGS: Record<SugorokuLanguage, Record<string, string>>;
|
|
12
|
-
/** A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
|
|
28
|
+
/** A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
|
|
29
|
+
*
|
|
30
|
+
* @param language - The English or Japanese display language.
|
|
31
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
32
|
+
* @param values - Replacement strings or numbers for brace-delimited placeholders.
|
|
33
|
+
* @returns A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { sugorokuSay } from "@johnmorrisdotca/sugoroku/play";
|
|
37
|
+
*
|
|
38
|
+
* console.log(sugorokuSay("en","roll"));
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
13
41
|
export declare function sugorokuSay(language: SugorokuLanguage, key: string, values?: Record<string, string | number>): string;
|
|
14
|
-
/** The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
|
|
42
|
+
/** The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
|
|
43
|
+
*
|
|
44
|
+
* @param element - The host element whose inherited language is read; null selects the fallback.
|
|
45
|
+
* @returns The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts no-run
|
|
48
|
+
* import { sugorokuLanguageOf } from "@johnmorrisdotca/sugoroku/play";
|
|
49
|
+
*
|
|
50
|
+
* const host = document.createElement("div");
|
|
51
|
+
* host.lang="ja";
|
|
52
|
+
* console.log(sugorokuLanguageOf(host));
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
15
55
|
export declare function sugorokuLanguageOf(element: Element | null): SugorokuLanguage;
|
package/dist/strings.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/** The native English and Japanese labels, announcements and interpolation templates.
|
|
2
|
+
*
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { SUGOROKU_STRINGS } from "@johnmorrisdotca/sugoroku/play";
|
|
6
|
+
* console.log(SUGOROKU_STRINGS);
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
1
9
|
export const SUGOROKU_STRINGS = {
|
|
2
10
|
en: {
|
|
3
11
|
variant_backgammon: "Backgammon",
|
|
@@ -118,12 +126,36 @@ export const SUGOROKU_STRINGS = {
|
|
|
118
126
|
dice: "サイコロ {dice}",
|
|
119
127
|
},
|
|
120
128
|
};
|
|
121
|
-
/** A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
|
|
129
|
+
/** A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
|
|
130
|
+
*
|
|
131
|
+
* @param language - The English or Japanese display language.
|
|
132
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
133
|
+
* @param values - Replacement strings or numbers for brace-delimited placeholders.
|
|
134
|
+
* @returns A line in a language with its `{name}`s filled in. A name left unfilled stays as written, so a missing value is visible.
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { sugorokuSay } from "@johnmorrisdotca/sugoroku/play";
|
|
138
|
+
*
|
|
139
|
+
* console.log(sugorokuSay("en","roll"));
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
122
142
|
export function sugorokuSay(language, key, values = {}) {
|
|
123
143
|
const line = SUGOROKU_STRINGS[language][key] ?? SUGOROKU_STRINGS.en[key] ?? key;
|
|
124
144
|
return line.replace(/\{(\w+)\}/g, (whole, name) => (name in values ? String(values[name]) : whole));
|
|
125
145
|
}
|
|
126
|
-
/** The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
|
|
146
|
+
/** The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
|
|
147
|
+
*
|
|
148
|
+
* @param element - The host element whose inherited language is read; null selects the fallback.
|
|
149
|
+
* @returns The language an element or its page is in: its own `lang`, or the nearest above, and English unless that begins with `ja`.
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts no-run
|
|
152
|
+
* import { sugorokuLanguageOf } from "@johnmorrisdotca/sugoroku/play";
|
|
153
|
+
*
|
|
154
|
+
* const host = document.createElement("div");
|
|
155
|
+
* host.lang="ja";
|
|
156
|
+
* console.log(sugorokuLanguageOf(host));
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
127
159
|
export function sugorokuLanguageOf(element) {
|
|
128
160
|
const tag = element?.closest("[lang]")?.getAttribute("lang") ?? element?.ownerDocument?.documentElement.getAttribute("lang") ?? "en";
|
|
129
161
|
return tag.toLowerCase().startsWith("ja") ? "ja" : "en";
|
package/dist/style.d.ts
CHANGED
|
@@ -8,5 +8,11 @@
|
|
|
8
8
|
* Put it in the page once. Every colour is a custom property on `.sugoroku`,
|
|
9
9
|
* so a page's own style needs only to set the ones it wants different; the
|
|
10
10
|
* felt follows `--felt` where a page defines one.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { SUGOROKU_STYLE } from "@johnmorrisdotca/sugoroku/draw";
|
|
15
|
+
* console.log(SUGOROKU_STYLE.length);
|
|
16
|
+
* ```
|
|
11
17
|
*/
|
|
12
18
|
export declare const SUGOROKU_STYLE = "\n.sugoroku {\n --sg-frame: #5b3a1f; --sg-felt: var(--felt, #2f5d4a); --sg-point-a: #e7d8b1; --sg-point-b: #8e3a2b; --sg-bar: #4a2f19; --sg-tray: #24493a;\n --sg-white: #f6f0df; --sg-white-edge: #b3a888; --sg-black: #2b2724; --sg-black-edge: #0d0b0a;\n --sg-number: #e8dcc0; --sg-selected: #ffd23f; --sg-target: #7fe3a1; --sg-die: #fbf8f1; --sg-pip: #1f2320; --sg-cube: #fbf8f1; --sg-cube-ink: #1f2320;\n display: block; width: 100%; height: auto; overflow: visible;\n user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent;\n font-family: system-ui, -apple-system, \"Segoe UI\", sans-serif;\n}\n@media (prefers-color-scheme: dark) {\n :root:not([data-theme=\"light\"]) .sugoroku:not([data-theme=\"light\"]) {\n --sg-frame: #2b1c0e; --sg-felt: var(--felt, #1f4135); --sg-point-a: #bdad88; --sg-point-b: #6b2a1f; --sg-bar: #21160b; --sg-tray: #173026;\n --sg-white: #e9e3d0; --sg-white-edge: #9a9078; --sg-number: #b9ae92; --sg-die: #e9e3d0; --sg-cube: #e9e3d0;\n }\n}\n:root[data-theme=\"dark\"] .sugoroku:not([data-theme=\"light\"]), .sugoroku[data-theme=\"dark\"] {\n --sg-frame: #2b1c0e; --sg-felt: var(--felt, #1f4135); --sg-point-a: #bdad88; --sg-point-b: #6b2a1f; --sg-bar: #21160b; --sg-tray: #173026;\n --sg-white: #e9e3d0; --sg-white-edge: #9a9078; --sg-number: #b9ae92; --sg-die: #e9e3d0; --sg-cube: #e9e3d0;\n}\n.sugoroku * { user-select: none; -webkit-user-select: none; }\n.sugoroku .sg-frame { fill: var(--sg-frame); }\n.sugoroku .sg-felt { fill: var(--sg-felt); }\n.sugoroku .sg-rail, .sugoroku .sg-tray-well { fill: var(--sg-tray); }\n.sugoroku .sg-bar { fill: var(--sg-bar); }\n.sugoroku .sg-point[data-tone=\"a\"] .sg-triangle { fill: var(--sg-point-a); }\n.sugoroku .sg-point[data-tone=\"b\"] .sg-triangle { fill: var(--sg-point-b); }\n.sugoroku .sg-hit { fill: transparent; }\n.sugoroku .sg-bar-hit { fill: transparent; }\n.sugoroku .sg-tray { fill: rgba(0, 0, 0, .18); stroke: rgba(0, 0, 0, .25); stroke-width: 1; }\n.sugoroku .sg-number { fill: var(--sg-number); font-size: 11px; font-weight: 600; pointer-events: none; }\n.sugoroku .sg-checker { pointer-events: none; }\n.sugoroku .sg-checker[data-side=\"white\"] .sg-face { fill: var(--sg-white); stroke: var(--sg-white-edge); stroke-width: 2; }\n.sugoroku .sg-checker[data-side=\"black\"] .sg-face { fill: var(--sg-black); stroke: var(--sg-black-edge); stroke-width: 2; }\n.sugoroku .sg-checker[data-side=\"white\"] .sg-ring { fill: none; stroke: var(--sg-white-edge); stroke-width: 1.5; opacity: .7; }\n.sugoroku .sg-checker[data-side=\"black\"] .sg-ring { fill: none; stroke: var(--sg-black-edge); stroke-width: 1.5; opacity: .9; }\n.sugoroku .sg-gleam { fill: #fff; opacity: .16; }\n.sugoroku .sg-checker[data-side=\"white\"] .sg-count { fill: var(--sg-pip); }\n.sugoroku .sg-checker[data-side=\"black\"] .sg-count { fill: var(--sg-white); }\n.sugoroku .sg-count { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; pointer-events: none; }\n.sugoroku .sg-off[data-side=\"white\"] { fill: var(--sg-white); stroke: var(--sg-white-edge); stroke-width: 1.5; pointer-events: none; }\n.sugoroku .sg-off[data-side=\"black\"] { fill: var(--sg-black); stroke: var(--sg-black-edge); stroke-width: 1.5; pointer-events: none; }\n.sugoroku .sg-die { pointer-events: none; }\n.sugoroku .sg-die rect { fill: var(--sg-die); stroke: rgba(0, 0, 0, .35); stroke-width: 1.5; }\n.sugoroku .sg-die[data-spent=\"true\"] { opacity: .38; }\n.sugoroku .sg-pip { fill: var(--sg-pip); }\n.sugoroku .sg-cube { pointer-events: none; }\n.sugoroku .sg-cube rect { fill: var(--sg-cube); stroke: rgba(0, 0, 0, .35); stroke-width: 1.5; }\n.sugoroku .sg-cube-text { fill: var(--sg-cube-ink); font-size: 22px; font-weight: 800; pointer-events: none; }\n.sugoroku .sg-point[data-movable=\"true\"] .sg-triangle { stroke: rgba(255, 255, 255, .55); stroke-width: 3; stroke-linejoin: round; }\n.sugoroku .sg-bar-hit[data-movable=\"true\"] { fill: rgba(255, 255, 255, .14); }\n.sugoroku .sg-point[data-selected=\"true\"] .sg-triangle { stroke: var(--sg-selected); stroke-width: 4; stroke-linejoin: round; }\n.sugoroku .sg-point[data-target=\"true\"] .sg-triangle { stroke: var(--sg-target); stroke-width: 4; stroke-linejoin: round; }\n.sugoroku .sg-bar-hit[data-selected=\"true\"] { fill: var(--sg-selected); opacity: .35; }\n.sugoroku .sg-tray[data-target=\"true\"] { stroke: var(--sg-target); stroke-width: 4; fill: rgba(127, 227, 161, .18); }\n.sugoroku .sg-point[data-target=\"true\"], .sugoroku .sg-tray[data-target=\"true\"] { cursor: pointer; }\n";
|
package/dist/style.js
CHANGED
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
* Put it in the page once. Every colour is a custom property on `.sugoroku`,
|
|
9
9
|
* so a page's own style needs only to set the ones it wants different; the
|
|
10
10
|
* felt follows `--felt` where a page defines one.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { SUGOROKU_STYLE } from "@johnmorrisdotca/sugoroku/draw";
|
|
15
|
+
* console.log(SUGOROKU_STYLE.length);
|
|
16
|
+
* ```
|
|
11
17
|
*/
|
|
12
18
|
export const SUGOROKU_STYLE = `
|
|
13
19
|
.sugoroku {
|
package/dist/variants.d.ts
CHANGED
|
@@ -1,26 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THE VARIANTS, AS ROWS OF SETTINGS. Nothing in the engine branches on a
|
|
3
3
|
* variant's name: it reads the row. A new game on the same board is a new row.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { VariantKey } from "@johnmorrisdotca/sugoroku";
|
|
8
|
+
*
|
|
9
|
+
* const value: VariantKey = "tabula";
|
|
10
|
+
* console.log(value);
|
|
11
|
+
* ```
|
|
4
12
|
*/
|
|
5
13
|
export type VariantKey = "backgammon" | "backgammon-race" | "anti-backgammon" | "nackgammon" | "long-gammon" | "hypergammon" | "tabula";
|
|
6
|
-
/** How the sides' tracks lie on the board.
|
|
14
|
+
/** How the sides' tracks lie on the board.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import type { Direction } from "@johnmorrisdotca/sugoroku";
|
|
19
|
+
*
|
|
20
|
+
* const value: Direction = "opposed";
|
|
21
|
+
* console.log(value);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
7
24
|
export type Direction =
|
|
8
25
|
/** Opposite ways round, as in backgammon: one side's 24-point is the other's 1-point. */
|
|
9
26
|
"opposed"
|
|
10
27
|
/** The same way round, from the same start, as in Tabula: both sides' own point 24 is the one place. */
|
|
11
28
|
| "same";
|
|
12
|
-
/** How a game is opened.
|
|
29
|
+
/** How a game is opened.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import type { Opening } from "@johnmorrisdotca/sugoroku";
|
|
34
|
+
*
|
|
35
|
+
* const value: Opening = "roll-off";
|
|
36
|
+
* console.log(value);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
13
39
|
export type Opening =
|
|
14
40
|
/** Each side throws one die; the higher plays both dice as the first roll of the game, as in backgammon. */
|
|
15
41
|
"roll-off"
|
|
16
42
|
/** Each side throws one die; the higher goes first and then rolls a roll of their own. */
|
|
17
43
|
| "die-each";
|
|
18
|
-
/** What it takes to win.
|
|
44
|
+
/** What it takes to win.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import type { Goal } from "@johnmorrisdotca/sugoroku";
|
|
49
|
+
*
|
|
50
|
+
* const value: Goal = "first-off";
|
|
51
|
+
* console.log(value);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
19
54
|
export type Goal =
|
|
20
55
|
/** Bear off every checker first. */
|
|
21
56
|
"first-off"
|
|
22
57
|
/** Be last to bear off: whoever bears off every checker first loses (Anti-Backgammon). */
|
|
23
58
|
| "last-off";
|
|
59
|
+
/** A native variant’s checker counts, starting layout, dice, directions, opening and winning goal.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { settingsFor } from "@johnmorrisdotca/sugoroku";
|
|
64
|
+
* import type { VariantSpec } from "@johnmorrisdotca/sugoroku";
|
|
65
|
+
*
|
|
66
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
67
|
+
* const spec = settings.variant;
|
|
68
|
+
* const value: VariantSpec = spec;
|
|
69
|
+
* console.log(value);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
24
72
|
export type VariantSpec = {
|
|
25
73
|
readonly key: VariantKey;
|
|
26
74
|
/** Checkers each side has. */
|
|
@@ -46,15 +94,72 @@ export type VariantSpec = {
|
|
|
46
94
|
/**
|
|
47
95
|
* Every variant. Where each comes from, and where the sources disagree or say
|
|
48
96
|
* nothing, is in `docs/VARIANTS.md`.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { VARIANTS } from "@johnmorrisdotca/sugoroku";
|
|
101
|
+
* console.log(VARIANTS);
|
|
102
|
+
* ```
|
|
49
103
|
*/
|
|
50
104
|
export declare const VARIANTS: Readonly<Record<VariantKey, VariantSpec>>;
|
|
51
|
-
/** The variants' keys, in the order the demo lists them.
|
|
105
|
+
/** The variants' keys, in the order the demo lists them.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { VARIANT_KEYS } from "@johnmorrisdotca/sugoroku";
|
|
110
|
+
* console.log(VARIANT_KEYS);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
52
113
|
export declare const VARIANT_KEYS: readonly VariantKey[];
|
|
53
|
-
/** Whether `key` names a variant.
|
|
114
|
+
/** Whether `key` names a variant.
|
|
115
|
+
*
|
|
116
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
117
|
+
* @returns Whether `key` names a variant.
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { isVariantKey } from "@johnmorrisdotca/sugoroku";
|
|
121
|
+
*
|
|
122
|
+
* console.log(isVariantKey("tabula"));
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
54
125
|
export declare function isVariantKey(key: unknown): key is VariantKey;
|
|
55
|
-
/** The row for a variant.
|
|
126
|
+
/** The row for a variant.
|
|
127
|
+
*
|
|
128
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
129
|
+
* @returns The row for a variant.
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { variantSpec } from "@johnmorrisdotca/sugoroku";
|
|
133
|
+
*
|
|
134
|
+
* console.log(variantSpec("tabula").dice);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
56
137
|
export declare function variantSpec(key: VariantKey): VariantSpec;
|
|
57
|
-
/** Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
138
|
+
/** Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
139
|
+
*
|
|
140
|
+
* @param spec - The native variant specification.
|
|
141
|
+
* @returns Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* import { settingsFor, startCounts } from "@johnmorrisdotca/sugoroku";
|
|
145
|
+
*
|
|
146
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
147
|
+
* const spec = settings.variant;
|
|
148
|
+
* console.log(startCounts(spec));
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
58
151
|
export declare function startCounts(spec: VariantSpec): number[];
|
|
59
|
-
/** How many checkers each side begins off the board, to be entered with the dice.
|
|
152
|
+
/** How many checkers each side begins off the board, to be entered with the dice.
|
|
153
|
+
*
|
|
154
|
+
* @param spec - The native variant specification.
|
|
155
|
+
* @returns How many checkers each side begins off the board, to be entered with the dice.
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* import { settingsFor, startReserve } from "@johnmorrisdotca/sugoroku";
|
|
159
|
+
*
|
|
160
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
161
|
+
* const spec = settings.variant;
|
|
162
|
+
* console.log(startReserve(spec));
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
60
165
|
export declare function startReserve(spec: VariantSpec): number;
|
package/dist/variants.js
CHANGED
|
@@ -18,6 +18,12 @@ const BASE = {
|
|
|
18
18
|
/**
|
|
19
19
|
* Every variant. Where each comes from, and where the sources disagree or say
|
|
20
20
|
* nothing, is in `docs/VARIANTS.md`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { VARIANTS } from "@johnmorrisdotca/sugoroku";
|
|
25
|
+
* console.log(VARIANTS);
|
|
26
|
+
* ```
|
|
21
27
|
*/
|
|
22
28
|
export const VARIANTS = {
|
|
23
29
|
/** The classic game. */
|
|
@@ -54,24 +60,75 @@ export const VARIANTS = {
|
|
|
54
60
|
/** The Roman game: three dice, no doubles, both sides entering the same way round the same track. */
|
|
55
61
|
tabula: { ...BASE, key: "tabula", layout: [], dice: 3, doubles: "none", direction: "same", opening: "die-each", holdBelow: 12 },
|
|
56
62
|
};
|
|
57
|
-
/** The variants' keys, in the order the demo lists them.
|
|
63
|
+
/** The variants' keys, in the order the demo lists them.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { VARIANT_KEYS } from "@johnmorrisdotca/sugoroku";
|
|
68
|
+
* console.log(VARIANT_KEYS);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
58
71
|
export const VARIANT_KEYS = ["backgammon", "backgammon-race", "anti-backgammon", "nackgammon", "long-gammon", "hypergammon", "tabula"];
|
|
59
|
-
/** Whether `key` names a variant.
|
|
72
|
+
/** Whether `key` names a variant.
|
|
73
|
+
*
|
|
74
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
75
|
+
* @returns Whether `key` names a variant.
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { isVariantKey } from "@johnmorrisdotca/sugoroku";
|
|
79
|
+
*
|
|
80
|
+
* console.log(isVariantKey("tabula"));
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
60
83
|
export function isVariantKey(key) {
|
|
61
84
|
return typeof key === "string" && VARIANT_KEYS.includes(key);
|
|
62
85
|
}
|
|
63
|
-
/** The row for a variant.
|
|
86
|
+
/** The row for a variant.
|
|
87
|
+
*
|
|
88
|
+
* @param key - The native variant, preset or localized-label key specified by the signature.
|
|
89
|
+
* @returns The row for a variant.
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* import { variantSpec } from "@johnmorrisdotca/sugoroku";
|
|
93
|
+
*
|
|
94
|
+
* console.log(variantSpec("tabula").dice);
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
64
97
|
export function variantSpec(key) {
|
|
65
98
|
return VARIANTS[key];
|
|
66
99
|
}
|
|
67
|
-
/** Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
100
|
+
/** Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
101
|
+
*
|
|
102
|
+
* @param spec - The native variant specification.
|
|
103
|
+
* @returns Which points a side's checkers start on, as an array indexed by own point 1 to 24 (index 0 is point 1).
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* import { settingsFor, startCounts } from "@johnmorrisdotca/sugoroku";
|
|
107
|
+
*
|
|
108
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
109
|
+
* const spec = settings.variant;
|
|
110
|
+
* console.log(startCounts(spec));
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
68
113
|
export function startCounts(spec) {
|
|
69
114
|
const counts = new Array(24).fill(0);
|
|
70
115
|
for (const [point, count] of spec.layout)
|
|
71
116
|
counts[point - 1] = count;
|
|
72
117
|
return counts;
|
|
73
118
|
}
|
|
74
|
-
/** How many checkers each side begins off the board, to be entered with the dice.
|
|
119
|
+
/** How many checkers each side begins off the board, to be entered with the dice.
|
|
120
|
+
*
|
|
121
|
+
* @param spec - The native variant specification.
|
|
122
|
+
* @returns How many checkers each side begins off the board, to be entered with the dice.
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* import { settingsFor, startReserve } from "@johnmorrisdotca/sugoroku";
|
|
126
|
+
*
|
|
127
|
+
* const settings = settingsFor("backgammon",{points:5,cube:true});
|
|
128
|
+
* const spec = settings.variant;
|
|
129
|
+
* console.log(startReserve(spec));
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
75
132
|
export function startReserve(spec) {
|
|
76
133
|
return spec.checkers - spec.layout.reduce((sum, [, count]) => sum + count, 0);
|
|
77
134
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
/** The package's version.
|
|
2
|
-
|
|
1
|
+
/** The package's version.
|
|
2
|
+
*
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import { VERSION } from "@johnmorrisdotca/sugoroku";
|
|
6
|
+
* console.log(VERSION);
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare const VERSION = "1.1.0";
|
package/dist/version.js
CHANGED