@dxos/plugin-chess 0.8.4-main.422d1c7879 → 0.8.4-main.43cb759274
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/LICENSE +102 -5
- package/PLUGIN.mdl +526 -0
- package/README.md +1 -1
- package/dist/lib/neutral/ChessArticle-QLLKZGPH.mjs +88 -0
- package/dist/lib/neutral/ChessArticle-QLLKZGPH.mjs.map +7 -0
- package/dist/lib/neutral/ChessCard-I5RSZZIP.mjs +19 -0
- package/dist/lib/neutral/ChessCard-I5RSZZIP.mjs.map +7 -0
- package/dist/lib/neutral/ChessPlugin.mjs +10 -0
- package/dist/lib/neutral/ChessPlugin.node.mjs +23 -0
- package/dist/lib/neutral/ChessPlugin.node.mjs.map +7 -0
- package/dist/lib/neutral/ChessPlugin.workerd.mjs +21 -0
- package/dist/lib/neutral/ChessPlugin.workerd.mjs.map +7 -0
- package/dist/lib/neutral/blueprint-definition-PZXHAYLD.mjs +15 -0
- package/dist/lib/neutral/blueprint-definition-PZXHAYLD.mjs.map +7 -0
- package/dist/lib/neutral/blueprints/index.mjs +8 -0
- package/dist/lib/neutral/capabilities/index.mjs +13 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/neutral/chunk-7XZ4CRDL.mjs +32 -0
- package/dist/lib/neutral/chunk-7XZ4CRDL.mjs.map +7 -0
- package/dist/lib/neutral/chunk-KMHQCP7J.mjs +148 -0
- package/dist/lib/neutral/chunk-KMHQCP7J.mjs.map +7 -0
- package/dist/lib/neutral/chunk-PJOAFP6S.mjs +41 -0
- package/dist/lib/neutral/chunk-PJOAFP6S.mjs.map +7 -0
- package/dist/lib/neutral/chunk-W2JSKHJK.mjs +8 -0
- package/dist/lib/neutral/chunk-W2JSKHJK.mjs.map +7 -0
- package/dist/lib/{browser/chunk-MC7L6JNC.mjs → neutral/chunk-XWKNXG62.mjs} +8 -10
- package/dist/lib/neutral/chunk-XWKNXG62.mjs.map +7 -0
- package/dist/lib/{browser → neutral/components}/index.mjs +8 -158
- package/dist/lib/neutral/components/index.mjs.map +7 -0
- package/dist/lib/neutral/containers/index.mjs +11 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/neutral/game-variant-UMYAK7LT.mjs +41 -0
- package/dist/lib/neutral/game-variant-UMYAK7LT.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +18 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +8 -0
- package/dist/lib/neutral/move-ORBNYB2H.mjs +37 -0
- package/dist/lib/neutral/move-ORBNYB2H.mjs.map +7 -0
- package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs +13 -0
- package/dist/lib/neutral/operation-handler-EKZKFQUG.mjs.map +7 -0
- package/dist/lib/{browser/types → neutral/operations}/index.mjs +3 -3
- package/dist/lib/neutral/play-QJCLEC27.mjs +46 -0
- package/dist/lib/neutral/play-QJCLEC27.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +16 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/{browser/print-EW7LPW4D.mjs → neutral/print-ILCRJUYI.mjs} +5 -6
- package/dist/lib/neutral/print-ILCRJUYI.mjs.map +7 -0
- package/dist/lib/neutral/testing.mjs +8 -0
- package/dist/lib/neutral/translations.mjs +35 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +10 -0
- package/dist/types/src/ChessPlugin.d.ts +1 -0
- package/dist/types/src/ChessPlugin.d.ts.map +1 -1
- package/dist/types/src/ChessPlugin.node.d.ts +8 -0
- package/dist/types/src/ChessPlugin.node.d.ts.map +1 -0
- package/dist/types/src/{cli/plugin.d.ts → ChessPlugin.workerd.d.ts} +2 -1
- package/dist/types/src/ChessPlugin.workerd.d.ts.map +1 -0
- package/dist/types/src/blueprints/chess-blueprint.d.ts +2 -2
- package/dist/types/src/blueprints/chess-blueprint.d.ts.map +1 -1
- package/dist/types/src/blueprints/index.d.ts +0 -1
- package/dist/types/src/blueprints/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/blueprint-definition.d.ts +2 -2
- package/dist/types/src/capabilities/blueprint-definition.d.ts.map +1 -1
- package/dist/types/src/capabilities/game-variant.d.ts +6 -0
- package/dist/types/src/capabilities/game-variant.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +3 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.d.ts +6 -2
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +32 -23
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/Info.d.ts +4 -5
- package/dist/types/src/components/Chessboard/Info.d.ts.map +1 -1
- package/dist/types/src/components/Chessboard/types.d.ts +2 -2
- package/dist/types/src/components/Chessboard/types.d.ts.map +1 -1
- package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts +3 -4
- package/dist/types/src/containers/ChessArticle/ChessArticle.d.ts.map +1 -1
- package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts +32 -23
- package/dist/types/src/containers/ChessArticle/ChessArticle.stories.d.ts.map +1 -1
- package/dist/types/src/containers/ChessCard/ChessCard.d.ts +3 -4
- package/dist/types/src/containers/ChessCard/ChessCard.d.ts.map +1 -1
- package/dist/types/src/containers/ChessCard/ChessCard.stories.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/index.d.ts +2 -3
- package/dist/types/src/operations/index.d.ts.map +1 -1
- package/dist/types/src/operations/move.d.ts +3 -3
- package/dist/types/src/operations/move.d.ts.map +1 -1
- package/dist/types/src/operations/play.d.ts +3 -3
- package/dist/types/src/operations/play.d.ts.map +1 -1
- package/dist/types/src/operations/print.d.ts +3 -3
- package/dist/types/src/operations/print.d.ts.map +1 -1
- package/dist/types/src/plugin.d.ts +4 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +2 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +32 -24
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Chess.d.ts +10 -20
- package/dist/types/src/types/Chess.d.ts.map +1 -1
- package/dist/types/src/types/ChessOperation.d.ts +29 -0
- package/dist/types/src/types/ChessOperation.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +97 -62
- package/src/ChessPlugin.node.ts +23 -0
- package/src/ChessPlugin.test.ts +14 -15
- package/src/ChessPlugin.tsx +15 -32
- package/src/ChessPlugin.workerd.ts +18 -0
- package/src/blueprints/chess-blueprint.ts +6 -9
- package/src/blueprints/index.ts +0 -1
- package/src/capabilities/blueprint-definition.ts +2 -0
- package/src/capabilities/game-variant.ts +43 -0
- package/src/capabilities/index.ts +3 -2
- package/src/capabilities/operation-handler.ts +3 -3
- package/src/components/Chessboard/Chessboard.stories.tsx +3 -3
- package/src/components/Chessboard/Chessboard.tsx +4 -4
- package/src/components/Chessboard/Info.tsx +3 -63
- package/src/components/Chessboard/types.ts +1 -1
- package/src/containers/ChessArticle/ChessArticle.stories.tsx +9 -3
- package/src/containers/ChessArticle/ChessArticle.tsx +45 -10
- package/src/containers/ChessCard/ChessCard.stories.tsx +7 -2
- package/src/containers/ChessCard/ChessCard.tsx +10 -5
- package/src/index.ts +0 -3
- package/src/meta.ts +10 -4
- package/src/operations/index.ts +2 -7
- package/src/operations/move.ts +13 -13
- package/src/operations/play.ts +14 -14
- package/src/operations/print.ts +3 -3
- package/src/plugin.ts +11 -0
- package/src/testing.ts +7 -0
- package/src/translations.ts +7 -10
- package/src/types/Chess.ts +21 -30
- package/src/{operations/definitions.ts → types/ChessOperation.ts} +16 -37
- package/src/types/index.ts +1 -0
- package/src/vite-env.d.ts +10 -0
- package/dist/lib/browser/blueprints/index.mjs +0 -14
- package/dist/lib/browser/chunk-2TJN26DN.mjs +0 -67
- package/dist/lib/browser/chunk-2TJN26DN.mjs.map +0 -7
- package/dist/lib/browser/chunk-JZMN24DY.mjs +0 -28
- package/dist/lib/browser/chunk-JZMN24DY.mjs.map +0 -7
- package/dist/lib/browser/chunk-MC7L6JNC.mjs.map +0 -7
- package/dist/lib/browser/chunk-XAJZK6Z2.mjs +0 -110
- package/dist/lib/browser/chunk-XAJZK6Z2.mjs.map +0 -7
- package/dist/lib/browser/cli/index.mjs +0 -34
- package/dist/lib/browser/cli/index.mjs.map +0 -7
- package/dist/lib/browser/create-AJHN4QT4.mjs +0 -24
- package/dist/lib/browser/create-AJHN4QT4.mjs.map +0 -7
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/move-T2NLRBR4.mjs +0 -36
- package/dist/lib/browser/move-T2NLRBR4.mjs.map +0 -7
- package/dist/lib/browser/operations/index.mjs +0 -19
- package/dist/lib/browser/play-7VTMD3SJ.mjs +0 -45
- package/dist/lib/browser/play-7VTMD3SJ.mjs.map +0 -7
- package/dist/lib/browser/print-EW7LPW4D.mjs.map +0 -7
- package/dist/lib/node-esm/blueprints/index.mjs +0 -15
- package/dist/lib/node-esm/chunk-4HZWCKMR.mjs +0 -38
- package/dist/lib/node-esm/chunk-4HZWCKMR.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-LQEDIKCV.mjs +0 -29
- package/dist/lib/node-esm/chunk-LQEDIKCV.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NYU5JVXP.mjs +0 -111
- package/dist/lib/node-esm/chunk-NYU5JVXP.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-OIRJVY2R.mjs +0 -68
- package/dist/lib/node-esm/chunk-OIRJVY2R.mjs.map +0 -7
- package/dist/lib/node-esm/cli/index.mjs +0 -35
- package/dist/lib/node-esm/cli/index.mjs.map +0 -7
- package/dist/lib/node-esm/create-QSETDT4N.mjs +0 -25
- package/dist/lib/node-esm/create-QSETDT4N.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -390
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/move-5F2ANDTE.mjs +0 -37
- package/dist/lib/node-esm/move-5F2ANDTE.mjs.map +0 -7
- package/dist/lib/node-esm/operations/index.mjs +0 -20
- package/dist/lib/node-esm/play-W4DQCQRX.mjs +0 -46
- package/dist/lib/node-esm/play-W4DQCQRX.mjs.map +0 -7
- package/dist/lib/node-esm/print-UJHXAXMS.mjs +0 -31
- package/dist/lib/node-esm/print-UJHXAXMS.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -9
- package/dist/types/src/capabilities/artifact-definition.d.ts +0 -12
- package/dist/types/src/capabilities/artifact-definition.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -5
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/cli/index.d.ts +0 -2
- package/dist/types/src/cli/index.d.ts.map +0 -1
- package/dist/types/src/cli/plugin.d.ts.map +0 -1
- package/dist/types/src/operations/create.d.ts +0 -5
- package/dist/types/src/operations/create.d.ts.map +0 -1
- package/dist/types/src/operations/definitions.d.ts +0 -51
- package/dist/types/src/operations/definitions.d.ts.map +0 -1
- package/src/capabilities/artifact-definition.ts +0 -135
- package/src/capabilities/react-surface.tsx +0 -35
- package/src/cli/index.ts +0 -5
- package/src/cli/plugin.ts +0 -37
- package/src/operations/create.ts +0 -21
- /package/dist/lib/{browser/blueprints/index.mjs.map → neutral/ChessPlugin.mjs.map} +0 -0
- /package/dist/lib/{browser/operations → neutral/blueprints}/index.mjs.map +0 -0
- /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs +0 -0
- /package/dist/lib/{browser → neutral}/chunk-J5LGTIGS.mjs.map +0 -0
- /package/dist/lib/{browser/types → neutral}/index.mjs.map +0 -0
- /package/dist/lib/{node-esm/blueprints/index.mjs.map → neutral/meta.mjs.map} +0 -0
- /package/dist/lib/{node-esm → neutral}/operations/index.mjs.map +0 -0
- /package/dist/lib/{node-esm/chunk-HSLMI22Q.mjs.map → neutral/testing.mjs.map} +0 -0
- /package/dist/lib/{node-esm → neutral}/types/index.mjs.map +0 -0
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
+
import { type Obj } from '@dxos/echo';
|
|
9
|
+
import { make as makeGame } from '@dxos/plugin-game';
|
|
8
10
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
9
11
|
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
12
|
|
|
13
|
+
import { translations } from '#translations';
|
|
11
14
|
import { Chess } from '#types';
|
|
12
15
|
|
|
13
|
-
import { translations } from '../../translations';
|
|
14
16
|
import { ChessArticle } from './ChessArticle';
|
|
15
17
|
|
|
16
18
|
type DefaultStoryProps = {
|
|
@@ -18,8 +20,12 @@ type DefaultStoryProps = {
|
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
const DefaultStory = ({ pgn }: DefaultStoryProps) => {
|
|
21
|
-
const game = useMemo(() =>
|
|
22
|
-
|
|
23
|
+
const { game, state } = useMemo(() => {
|
|
24
|
+
const state = Chess.make(pgn ? { pgn } : undefined);
|
|
25
|
+
const game = makeGame({ name: 'Story game', variant: state as Obj.Unknown });
|
|
26
|
+
return { game, state };
|
|
27
|
+
}, [pgn]);
|
|
28
|
+
return <ChessArticle role='article' attendableId='story' game={game} variant={state} />;
|
|
23
29
|
};
|
|
24
30
|
|
|
25
31
|
const meta = {
|
|
@@ -2,20 +2,22 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Chess as ChessJS } from 'chess.js';
|
|
5
6
|
import React, { useCallback, useRef, useState } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
9
|
+
import { type GameVariantSurfaceProps } from '@dxos/plugin-game';
|
|
8
10
|
import { Panel, Toolbar, useTranslation } from '@dxos/react-ui';
|
|
9
11
|
import { type Player } from '@dxos/react-ui-gameboard';
|
|
10
12
|
import { mx } from '@dxos/ui-theme';
|
|
11
13
|
|
|
12
14
|
import { Chessboard, type ChessboardController, type ChessboardInfoProps } from '#components';
|
|
13
15
|
import { meta } from '#meta';
|
|
14
|
-
import {
|
|
16
|
+
import { Chess } from '#types';
|
|
15
17
|
|
|
16
|
-
export type ChessArticleProps =
|
|
18
|
+
export type ChessArticleProps = GameVariantSurfaceProps;
|
|
17
19
|
|
|
18
|
-
export const ChessArticle = ({ role,
|
|
20
|
+
export const ChessArticle = ({ role, variant }: ChessArticleProps) => {
|
|
19
21
|
const { t } = useTranslation(meta.id);
|
|
20
22
|
const [orientation, setOrientation] = useState<Player>('white');
|
|
21
23
|
const [showInfo, setShowInfo] = useState(true);
|
|
@@ -25,17 +27,50 @@ export const ChessArticle = ({ role, attendableId: _attendableId, subject: game
|
|
|
25
27
|
controller.current?.setMoveNumber(index);
|
|
26
28
|
}, []);
|
|
27
29
|
|
|
30
|
+
const isGameOver = (() => {
|
|
31
|
+
if (!Obj.instanceOf(Chess.State, variant) || (!variant.pgn && !variant.fen)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const chess = new ChessJS();
|
|
36
|
+
if (variant.pgn) {
|
|
37
|
+
chess.loadPgn(variant.pgn);
|
|
38
|
+
} else if (variant.fen) {
|
|
39
|
+
chess.load(variant.fen);
|
|
40
|
+
}
|
|
41
|
+
return chess.isGameOver();
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
})();
|
|
46
|
+
|
|
47
|
+
const handleNewGame = useCallback(() => {
|
|
48
|
+
if (!Obj.instanceOf(Chess.State, variant)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
Obj.update(variant, (variant) => {
|
|
52
|
+
const mutable = variant as Obj.Mutable<typeof variant>;
|
|
53
|
+
mutable.pgn = undefined;
|
|
54
|
+
mutable.fen = undefined;
|
|
55
|
+
});
|
|
56
|
+
}, [variant]);
|
|
57
|
+
|
|
58
|
+
if (!Obj.instanceOf(Chess.State, variant)) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
28
62
|
return (
|
|
29
|
-
<Chessboard.Root
|
|
63
|
+
<Chessboard.Root state={variant} ref={controller}>
|
|
30
64
|
<Panel.Root role={role} classNames='@container'>
|
|
31
65
|
<Panel.Toolbar asChild>
|
|
32
66
|
<Toolbar.Root>
|
|
67
|
+
{isGameOver && <Toolbar.Button onClick={handleNewGame}>{t('new-game.button')}</Toolbar.Button>}
|
|
68
|
+
<div className='grow' />
|
|
33
69
|
<Toolbar.IconButton
|
|
34
70
|
icon='ph--info--regular'
|
|
35
71
|
iconOnly
|
|
36
72
|
label={t('toggle-info.button')}
|
|
37
|
-
|
|
38
|
-
classNames={mx('invisible @3xl:visible')}
|
|
73
|
+
classNames={mx('invisible @4xl:visible')}
|
|
39
74
|
onClick={() => setShowInfo((open) => !open)}
|
|
40
75
|
/>
|
|
41
76
|
</Toolbar.Root>
|
|
@@ -44,17 +79,17 @@ export const ChessArticle = ({ role, attendableId: _attendableId, subject: game
|
|
|
44
79
|
<div
|
|
45
80
|
className={mx(
|
|
46
81
|
'grid h-full w-full',
|
|
47
|
-
showInfo && '@
|
|
82
|
+
showInfo && '@4xl:grid-cols-[1fr_320px] gap-8',
|
|
48
83
|
role === 'article' && 'p-4',
|
|
49
84
|
role === 'section' && 'aspect-square',
|
|
50
|
-
role === 'section' && showInfo && '@
|
|
85
|
+
role === 'section' && showInfo && '@4xl:aspect-auto',
|
|
51
86
|
)}
|
|
52
87
|
>
|
|
53
88
|
<Chessboard.Content>
|
|
54
89
|
<Chessboard.Board classNames='border rounded-xs' orientation={orientation} />
|
|
55
90
|
</Chessboard.Content>
|
|
56
91
|
{showInfo && (
|
|
57
|
-
<div className='hidden @
|
|
92
|
+
<div className='hidden @4xl:flex flex-col justify-center items-center overflow-hidden'>
|
|
58
93
|
<Chessboard.Info
|
|
59
94
|
orientation={orientation}
|
|
60
95
|
min={8}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
|
|
8
|
+
import { make as makeGame } from '@dxos/plugin-game';
|
|
8
9
|
import { CardContainer } from '@dxos/react-ui-mosaic/testing';
|
|
9
10
|
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
11
|
|
|
@@ -17,10 +18,14 @@ const SAMPLE_PGN =
|
|
|
17
18
|
'1. e4 e5 2. Nf3 Nc6 3. Bc4 Bc5 4. c3 Nf6 5. d4 exd4 6. cxd4 Bb4+ 7. Nc3 d5 8. exd5 Nxd5 9. O-O Be6 10. Qb3 Na5 11. Qa4+ c6 12. Bxd5 Bxc3 13. Bxe6 fxe6 14. d5 Qg5 15. dxe6 Qg4 16. e7 Kf7 17. bxc3 Kg6 *';
|
|
18
19
|
|
|
19
20
|
const CardStory = () => {
|
|
20
|
-
const game = useMemo(() =>
|
|
21
|
+
const { game, state } = useMemo(() => {
|
|
22
|
+
const state = Chess.make({ pgn: SAMPLE_PGN });
|
|
23
|
+
const game = makeGame({ name: 'Story game', variant: state });
|
|
24
|
+
return { game, state };
|
|
25
|
+
}, []);
|
|
21
26
|
return (
|
|
22
27
|
<CardContainer role='popover' icon={pluginMeta.icon}>
|
|
23
|
-
<ChessCard
|
|
28
|
+
<ChessCard role='card--content' game={game} variant={state} />
|
|
24
29
|
</CardContainer>
|
|
25
30
|
);
|
|
26
31
|
};
|
|
@@ -4,16 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Obj } from '@dxos/echo';
|
|
8
|
+
import { type GameVariantSurfaceProps } from '@dxos/plugin-game';
|
|
8
9
|
|
|
9
10
|
import { Chessboard } from '#components';
|
|
10
|
-
import {
|
|
11
|
+
import { Chess } from '#types';
|
|
11
12
|
|
|
12
|
-
export type ChessCardProps =
|
|
13
|
+
export type ChessCardProps = GameVariantSurfaceProps;
|
|
14
|
+
|
|
15
|
+
export const ChessCard = ({ variant }: ChessCardProps) => {
|
|
16
|
+
if (!Obj.instanceOf(Chess.State, variant)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
13
19
|
|
|
14
|
-
export const ChessCard = ({ subject: game }: ChessCardProps) => {
|
|
15
20
|
return (
|
|
16
|
-
<Chessboard.Root
|
|
21
|
+
<Chessboard.Root state={variant}>
|
|
17
22
|
<Chessboard.Content>
|
|
18
23
|
<Chessboard.Board />
|
|
19
24
|
</Chessboard.Content>
|
package/src/index.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Plugin } from '@dxos/app-framework';
|
|
6
|
+
import { DXN } from '@dxos/keys';
|
|
7
|
+
import { meta as gameMeta } from '@dxos/plugin-game';
|
|
6
8
|
import { trim } from '@dxos/util';
|
|
7
9
|
|
|
8
|
-
export const meta
|
|
9
|
-
|
|
10
|
+
export const meta = Plugin.makeMeta({
|
|
11
|
+
key: DXN.make('org.dxos.plugin.chess'),
|
|
10
12
|
name: 'Chess',
|
|
13
|
+
author: 'DXOS',
|
|
11
14
|
description: trim`
|
|
12
15
|
Full-featured chess game supporting multiplayer matches with friends or practice sessions against AI opponents.
|
|
13
16
|
Track game history and analyze moves in real-time.
|
|
@@ -15,5 +18,8 @@ export const meta: Plugin.Meta = {
|
|
|
15
18
|
icon: 'ph--shield-chevron--regular',
|
|
16
19
|
iconHue: 'amber',
|
|
17
20
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-chess',
|
|
21
|
+
spec: 'PLUGIN.mdl',
|
|
18
22
|
screenshots: ['https://dxos.network/plugin-details-chess-dark.png'],
|
|
19
|
-
|
|
23
|
+
dependsOn: [gameMeta.id],
|
|
24
|
+
tags: ['game'],
|
|
25
|
+
});
|
package/src/operations/index.ts
CHANGED
|
@@ -2,15 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { OperationHandlerSet } from '@dxos/
|
|
5
|
+
import { OperationHandlerSet } from '@dxos/compute';
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
() => import('./create'),
|
|
7
|
+
export const ChessOperationHandlerSet = OperationHandlerSet.lazy(
|
|
9
8
|
() => import('./move'),
|
|
10
9
|
() => import('./play'),
|
|
11
10
|
() => import('./print'),
|
|
12
11
|
);
|
|
13
|
-
|
|
14
|
-
export { Create, Move, Play, Print } from './definitions';
|
|
15
|
-
|
|
16
|
-
export const ChessHandlers = Handlers;
|
package/src/operations/move.ts
CHANGED
|
@@ -5,28 +5,28 @@
|
|
|
5
5
|
import { Chess as ChessJS } from 'chess.js';
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
import { loadGame } from '@dxos/plugin-game';
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
-
import { Move } from './definitions';
|
|
12
|
+
import { Chess, ChessOperation } from '../types';
|
|
13
13
|
|
|
14
|
-
const handler: Operation.WithHandler<typeof Move> = Move.pipe(
|
|
14
|
+
const handler: Operation.WithHandler<typeof ChessOperation.Move> = ChessOperation.Move.pipe(
|
|
15
15
|
Operation.withHandler(
|
|
16
16
|
Effect.fn(function* ({ game, move }) {
|
|
17
|
-
const
|
|
17
|
+
const { variant } = yield* loadGame(game, Chess.State);
|
|
18
18
|
const chess = new ChessJS();
|
|
19
|
-
if (
|
|
20
|
-
chess.loadPgn(
|
|
21
|
-
} else if (
|
|
22
|
-
chess.load(
|
|
19
|
+
if (variant.pgn) {
|
|
20
|
+
chess.loadPgn(variant.pgn);
|
|
21
|
+
} else if (variant.fen) {
|
|
22
|
+
chess.load(variant.fen);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
chess.move(move, { strict: false });
|
|
26
26
|
const pgn = chess.pgn();
|
|
27
|
-
Obj.
|
|
28
|
-
const
|
|
29
|
-
|
|
27
|
+
Obj.update(variant, (variant) => {
|
|
28
|
+
const mutable = variant as Obj.Mutable<typeof variant>;
|
|
29
|
+
mutable.pgn = pgn;
|
|
30
30
|
});
|
|
31
31
|
return { pgn };
|
|
32
32
|
}),
|
package/src/operations/play.ts
CHANGED
|
@@ -5,27 +5,27 @@
|
|
|
5
5
|
import { Chess as ChessJS } from 'chess.js';
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
|
+
import { Obj } from '@dxos/echo';
|
|
10
|
+
import { loadGame } from '@dxos/plugin-game';
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
-
import { Play } from './definitions';
|
|
12
|
+
import { Chess, ChessOperation } from '../types';
|
|
13
13
|
|
|
14
|
-
const handler: Operation.WithHandler<typeof Play> = Play.pipe(
|
|
14
|
+
const handler: Operation.WithHandler<typeof ChessOperation.Play> = ChessOperation.Play.pipe(
|
|
15
15
|
Operation.withHandler(
|
|
16
16
|
Effect.fn(function* ({ game, side = 'any' }) {
|
|
17
|
-
const
|
|
17
|
+
const { variant } = yield* loadGame(game, Chess.State);
|
|
18
18
|
const chess = new ChessJS();
|
|
19
|
-
if (
|
|
20
|
-
chess.loadPgn(
|
|
21
|
-
} else if (
|
|
22
|
-
chess.load(
|
|
19
|
+
if (variant.pgn) {
|
|
20
|
+
chess.loadPgn(variant.pgn);
|
|
21
|
+
} else if (variant.fen) {
|
|
22
|
+
chess.load(variant.fen);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
if (
|
|
26
26
|
!(side === 'any' || (chess.turn() === 'w' && side === 'white') || (chess.turn() === 'b' && side === 'black'))
|
|
27
27
|
) {
|
|
28
|
-
return { move: undefined, pgn:
|
|
28
|
+
return { move: undefined, pgn: variant.pgn ?? '' };
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const moves = chess.moves();
|
|
@@ -33,9 +33,9 @@ const handler: Operation.WithHandler<typeof Play> = Play.pipe(
|
|
|
33
33
|
|
|
34
34
|
chess.move(move, { strict: false });
|
|
35
35
|
const pgn = chess.pgn();
|
|
36
|
-
Obj.
|
|
37
|
-
const
|
|
38
|
-
|
|
36
|
+
Obj.update(variant, (variant) => {
|
|
37
|
+
const mutable = variant as Obj.Mutable<typeof variant>;
|
|
38
|
+
mutable.pgn = pgn;
|
|
39
39
|
});
|
|
40
40
|
return { move, pgn };
|
|
41
41
|
}),
|
package/src/operations/print.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
import { Chess as ChessJS } from 'chess.js';
|
|
6
6
|
import * as Effect from 'effect/Effect';
|
|
7
7
|
|
|
8
|
-
import { Operation } from '@dxos/
|
|
8
|
+
import { Operation } from '@dxos/compute';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { ChessOperation } from '../types';
|
|
11
11
|
|
|
12
|
-
const handler: Operation.WithHandler<typeof Print> = Print.pipe(
|
|
12
|
+
const handler: Operation.WithHandler<typeof ChessOperation.Print> = ChessOperation.Print.pipe(
|
|
13
13
|
Operation.withHandler(
|
|
14
14
|
Effect.fn(function* ({ pgn, fen }) {
|
|
15
15
|
try {
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Plugin } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
import { meta } from './meta';
|
|
8
|
+
|
|
9
|
+
export const ChessPlugin = Plugin.lazy(meta, () => import('#plugin'));
|
|
10
|
+
|
|
11
|
+
export { ChessOperationHandlerSet } from './operations';
|
package/src/testing.ts
ADDED
package/src/translations.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { Type } from '@dxos/echo';
|
|
5
6
|
import { type Resource } from '@dxos/react-ui';
|
|
6
7
|
|
|
7
8
|
import { meta } from '#meta';
|
|
@@ -10,19 +11,15 @@ import { Chess } from '#types';
|
|
|
10
11
|
export const translations = [
|
|
11
12
|
{
|
|
12
13
|
'en-US': {
|
|
13
|
-
[Chess.
|
|
14
|
-
'typename.label': '
|
|
15
|
-
'typename.label_zero': '
|
|
16
|
-
'typename.label_one': '
|
|
17
|
-
'typename.label_other': '
|
|
18
|
-
'object-name.placeholder': 'New game',
|
|
19
|
-
'add-object.label': 'Add game',
|
|
20
|
-
'rename-object.label': 'Rename game',
|
|
21
|
-
'delete-object.label': 'Delete game',
|
|
22
|
-
'object-deleted.label': 'Game deleted',
|
|
14
|
+
[Type.getTypename(Chess.State)]: {
|
|
15
|
+
'typename.label': 'Chess',
|
|
16
|
+
'typename.label_zero': 'Chess games',
|
|
17
|
+
'typename.label_one': 'Chess game',
|
|
18
|
+
'typename.label_other': 'Chess games',
|
|
23
19
|
},
|
|
24
20
|
[meta.id]: {
|
|
25
21
|
'plugin.name': 'Chess',
|
|
22
|
+
'new-game.button': 'New game',
|
|
26
23
|
'delete-game.label': 'Delete',
|
|
27
24
|
'game.checkmate.label': 'Checkmate',
|
|
28
25
|
'game.stalemate.label': 'Stalemate',
|
package/src/types/Chess.ts
CHANGED
|
@@ -5,24 +5,18 @@
|
|
|
5
5
|
import { Chess as ChessJS } from 'chess.js';
|
|
6
6
|
import * as Schema from 'effect/Schema';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { BlueprintsAnnotation } from '@dxos/app-toolkit';
|
|
9
|
+
import { DXN, Annotation, Obj, Type } from '@dxos/echo';
|
|
10
|
+
import { FormInputAnnotation, HiddenAnnotation } from '@dxos/echo/internal';
|
|
10
11
|
import { log } from '@dxos/log';
|
|
11
12
|
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
),
|
|
20
|
-
black: Schema.optional(
|
|
21
|
-
Schema.String.annotations({
|
|
22
|
-
description: 'DID of black player',
|
|
23
|
-
}),
|
|
24
|
-
),
|
|
25
|
-
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
13
|
+
export const BLUEPRINT_KEY = 'org.dxos.blueprint.chess';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Chess variant state. Referenced by the base `Game` object via `Game.variant`.
|
|
17
|
+
* Players, name, and other game-shared fields live on the base `Game`.
|
|
18
|
+
*/
|
|
19
|
+
export const State = Schema.Struct({
|
|
26
20
|
pgn: Schema.String.annotations({
|
|
27
21
|
description: 'Portable Game Notation.',
|
|
28
22
|
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
@@ -30,20 +24,19 @@ export const Game = Schema.Struct({
|
|
|
30
24
|
description: 'Forsyth-Edwards Notation.',
|
|
31
25
|
}).pipe(FormInputAnnotation.set(false), Schema.optional),
|
|
32
26
|
}).pipe(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}),
|
|
27
|
+
Annotation.IconAnnotation.set({ icon: 'ph--shield-chevron--regular', hue: 'amber' }),
|
|
28
|
+
BlueprintsAnnotation.set([BLUEPRINT_KEY]),
|
|
29
|
+
// Implementation detail of the unified `Game` schema. The user-facing object is `Game`;
|
|
30
|
+
// this state is only ever referenced via `Game.variant`. HiddenAnnotation keeps it out of the
|
|
31
|
+
// navtree's typed branches so an orphaned state object doesn't reappear after the
|
|
32
|
+
// wrapping Game is deleted.
|
|
33
|
+
HiddenAnnotation.set(true),
|
|
34
|
+
Type.makeObject(DXN.make('org.dxos.type.chess.state', '0.1.0')),
|
|
42
35
|
);
|
|
43
36
|
|
|
44
|
-
export
|
|
37
|
+
export type State = Type.InstanceType<typeof State>;
|
|
45
38
|
|
|
46
|
-
export const make = ({
|
|
39
|
+
export const make = ({ pgn, fen }: { pgn?: string; fen?: string } = {}): State => {
|
|
47
40
|
const chess = new ChessJS();
|
|
48
41
|
if (pgn) {
|
|
49
42
|
try {
|
|
@@ -53,10 +46,8 @@ export const make = ({ name, pgn, fen }: { name?: string; pgn?: string; fen?: st
|
|
|
53
46
|
}
|
|
54
47
|
}
|
|
55
48
|
|
|
56
|
-
return Obj.make(
|
|
57
|
-
name,
|
|
49
|
+
return Obj.make(State, {
|
|
58
50
|
pgn,
|
|
59
51
|
fen,
|
|
60
|
-
players: {},
|
|
61
52
|
});
|
|
62
53
|
};
|
|
@@ -2,49 +2,26 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
// @import-as-namespace
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
import { Operation } from '@dxos/operation';
|
|
7
|
+
import * as Schema from 'effect/Schema';
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { Operation } from '@dxos/compute';
|
|
10
|
+
import { Database, DXN } from '@dxos/echo';
|
|
11
|
+
import { GameRef } from '@dxos/plugin-game';
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
meta: {
|
|
14
|
-
key: 'org.dxos.function.chess.create',
|
|
15
|
-
name: 'Create Chess',
|
|
16
|
-
description: 'Creates a new chess game.',
|
|
17
|
-
},
|
|
18
|
-
input: Schema.Struct({
|
|
19
|
-
name: Schema.optional(
|
|
20
|
-
Schema.String.annotations({
|
|
21
|
-
description: 'Name of the game.',
|
|
22
|
-
}),
|
|
23
|
-
),
|
|
24
|
-
pgn: Schema.optional(
|
|
25
|
-
Schema.String.annotations({
|
|
26
|
-
description: 'Portable Game Notation.',
|
|
27
|
-
}),
|
|
28
|
-
),
|
|
29
|
-
fen: Schema.optional(
|
|
30
|
-
Schema.String.annotations({
|
|
31
|
-
description: 'Forsyth-Edwards Notation.',
|
|
32
|
-
}),
|
|
33
|
-
),
|
|
34
|
-
}),
|
|
35
|
-
output: Chess.Game,
|
|
36
|
-
services: [Database.Service],
|
|
37
|
-
});
|
|
13
|
+
import * as Chess from './Chess';
|
|
38
14
|
|
|
39
15
|
export const Move = Operation.make({
|
|
40
16
|
meta: {
|
|
41
|
-
key: 'org.dxos.function.chess.move',
|
|
17
|
+
key: DXN.make('org.dxos.function.chess.move'),
|
|
42
18
|
name: 'Move',
|
|
43
19
|
description: 'Makes a move in the given chess game.',
|
|
20
|
+
icon: 'ph--play--regular',
|
|
44
21
|
},
|
|
45
22
|
input: Schema.Struct({
|
|
46
|
-
game:
|
|
47
|
-
description: 'The ID of the
|
|
23
|
+
game: GameRef(Chess.State).annotations({
|
|
24
|
+
description: 'The ID of the game object (variant must be Chess).',
|
|
48
25
|
}),
|
|
49
26
|
move: Schema.String.annotations({
|
|
50
27
|
description: 'The move to make in the chess game.',
|
|
@@ -61,13 +38,14 @@ export const Move = Operation.make({
|
|
|
61
38
|
|
|
62
39
|
export const Play = Operation.make({
|
|
63
40
|
meta: {
|
|
64
|
-
key: 'org.dxos.function.chess.play',
|
|
41
|
+
key: DXN.make('org.dxos.function.chess.play'),
|
|
65
42
|
name: 'Play',
|
|
66
43
|
description: 'Uses the chess engine to play the next move.',
|
|
44
|
+
icon: 'ph--play--regular',
|
|
67
45
|
},
|
|
68
46
|
input: Schema.Struct({
|
|
69
|
-
game:
|
|
70
|
-
description: 'The ID of the
|
|
47
|
+
game: GameRef(Chess.State).annotations({
|
|
48
|
+
description: 'The ID of the game object (variant must be Chess).',
|
|
71
49
|
}),
|
|
72
50
|
side: Schema.optional(Schema.Literal('white', 'black', 'any')).annotations({
|
|
73
51
|
description: 'The side to play.',
|
|
@@ -87,9 +65,10 @@ export const Play = Operation.make({
|
|
|
87
65
|
|
|
88
66
|
export const Print = Operation.make({
|
|
89
67
|
meta: {
|
|
90
|
-
key: 'org.dxos.function.chess.print',
|
|
68
|
+
key: DXN.make('org.dxos.function.chess.print'),
|
|
91
69
|
name: 'Print game',
|
|
92
70
|
description: 'Prints the chess game to ASCII.',
|
|
71
|
+
icon: 'ph--clipboard-text--regular',
|
|
93
72
|
},
|
|
94
73
|
input: Schema.Struct({
|
|
95
74
|
pgn: Schema.optional(
|
package/src/types/index.ts
CHANGED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
chess_blueprint_default
|
|
3
|
-
} from "../chunk-MC7L6JNC.mjs";
|
|
4
|
-
import {
|
|
5
|
-
operations_exports
|
|
6
|
-
} from "../chunk-JZMN24DY.mjs";
|
|
7
|
-
import "../chunk-XAJZK6Z2.mjs";
|
|
8
|
-
import "../chunk-2TJN26DN.mjs";
|
|
9
|
-
import "../chunk-J5LGTIGS.mjs";
|
|
10
|
-
export {
|
|
11
|
-
chess_blueprint_default as ChessBlueprint,
|
|
12
|
-
operations_exports as ChessFunctions
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=index.mjs.map
|