board-game-engine-react 1.0.3 → 2.0.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/.storybook/webpack.config.js +1 -1
- package/babel.config.js +2 -1
- package/dist/board-game-engine-react.cjs +100 -90
- package/dist/board-game-engine-react.mjs +103 -78
- package/dist/components/abstract-choices/abstract-choices.d.ts +2 -0
- package/dist/components/abstract-choices/abstract-choices.d.ts.map +1 -0
- package/dist/components/board/grid.d.ts +5 -0
- package/dist/components/board/grid.d.ts.map +1 -0
- package/dist/components/entity/entity.d.ts +5 -0
- package/dist/components/entity/entity.d.ts.map +1 -0
- package/dist/components/game/game.d.ts +8 -0
- package/dist/components/game/game.d.ts.map +1 -0
- package/dist/components/game-status/game-status.d.ts +5 -0
- package/dist/components/game-status/game-status.d.ts.map +1 -0
- package/dist/components/space/space.d.ts +5 -0
- package/dist/components/space/space.d.ts.map +1 -0
- package/dist/contexts/game-context.d.ts +15 -0
- package/dist/contexts/game-context.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/use-gameserver-connection.d.ts +8 -0
- package/dist/use-gameserver-connection.d.ts.map +1 -0
- package/examples/checkers.json +2 -2
- package/examples/connect-four.json +1 -1
- package/examples/eights.json +15 -15
- package/examples/index.html +219 -0
- package/package.json +12 -10
- package/scripts/build.mjs +3 -3
- package/src/components/abstract-choices/{abstract-choices.js → abstract-choices.tsx} +12 -8
- package/src/components/board/grid.tsx +29 -0
- package/src/components/entity/entity.tsx +40 -0
- package/src/components/game/{game.js → game.tsx} +22 -9
- package/src/components/game-status/game-status.tsx +30 -0
- package/src/components/space/space.tsx +52 -0
- package/src/contexts/game-context.tsx +60 -0
- package/src/global.d.ts +1 -0
- package/src/index.ts +8 -0
- package/src/types.ts +25 -0
- package/src/use-gameserver-connection.ts +82 -0
- package/stories/BoardGameEngineReact.stories.tsx +85 -0
- package/test-app/index.html +1 -1
- package/test-app/{main.jsx → main.tsx} +13 -11
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +34 -0
- package/board-game-engine-react.test.js +0 -12
- package/jest.config.js +0 -13
- package/src/components/board/grid.js +0 -28
- package/src/components/entity/entity.js +0 -38
- package/src/components/game-status/game-status.js +0 -20
- package/src/components/space/space.js +0 -68
- package/src/contexts/game-context.js +0 -35
- package/src/index.js +0 -5
- package/src/use-gameserver-connection.js +0 -74
- package/stories/BoardGameEngineReact.stories.js +0 -72
|
@@ -1,45 +1,59 @@
|
|
|
1
|
-
// src/index.
|
|
1
|
+
// src/index.ts
|
|
2
2
|
import { Client as Client2, gameFactory } from "board-game-engine";
|
|
3
3
|
|
|
4
|
-
// src/
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// src/contexts/game-context.js
|
|
11
|
-
import React, { createContext, useContext, useEffect } from "react";
|
|
4
|
+
// src/contexts/game-context.tsx
|
|
5
|
+
import {
|
|
6
|
+
createContext,
|
|
7
|
+
useContext,
|
|
8
|
+
useEffect
|
|
9
|
+
} from "react";
|
|
12
10
|
import { jsx } from "react/jsx-runtime";
|
|
13
11
|
var GameContext = createContext({
|
|
14
12
|
clickTarget: () => {
|
|
15
|
-
}
|
|
13
|
+
},
|
|
14
|
+
undoStep: () => {
|
|
15
|
+
},
|
|
16
|
+
allClickable: /* @__PURE__ */ new Set(),
|
|
17
|
+
currentMoveTargets: []
|
|
16
18
|
});
|
|
17
|
-
function GameProvider({
|
|
19
|
+
function GameProvider({
|
|
20
|
+
gameConnection,
|
|
21
|
+
children,
|
|
22
|
+
isSpectator
|
|
23
|
+
}) {
|
|
18
24
|
useEffect(() => {
|
|
19
|
-
if (gameConnection.state
|
|
25
|
+
if (gameConnection.state?._stateID === 0) {
|
|
20
26
|
gameConnection.reset();
|
|
21
27
|
}
|
|
22
|
-
}, [gameConnection.state
|
|
23
|
-
return /* @__PURE__ */ jsx(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
}, [gameConnection.state?._stateID]);
|
|
29
|
+
return /* @__PURE__ */ jsx(
|
|
30
|
+
GameContext.Provider,
|
|
31
|
+
{
|
|
32
|
+
value: {
|
|
33
|
+
clickTarget: (target) => {
|
|
34
|
+
if (!isSpectator) {
|
|
35
|
+
gameConnection.doStep(target);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
undoStep: () => {
|
|
39
|
+
gameConnection.undoStep();
|
|
40
|
+
},
|
|
41
|
+
allClickable: gameConnection.optimisticWinner || isSpectator ? /* @__PURE__ */ new Set() : gameConnection.allClickable ?? /* @__PURE__ */ new Set(),
|
|
42
|
+
currentMoveTargets: gameConnection.optimisticWinner || isSpectator ? [] : gameConnection.moveBuilder?.targets ?? []
|
|
43
|
+
},
|
|
44
|
+
children
|
|
45
|
+
}
|
|
46
|
+
);
|
|
35
47
|
}
|
|
36
48
|
var useGame = () => useContext(GameContext);
|
|
37
49
|
|
|
38
|
-
// src/components/board/grid.
|
|
39
|
-
import React2 from "react";
|
|
50
|
+
// src/components/board/grid.tsx
|
|
40
51
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
41
52
|
function Grid({ grid }) {
|
|
42
53
|
const { width, height, spaces } = grid.attributes;
|
|
54
|
+
const w = Number(width ?? 0);
|
|
55
|
+
const h = Number(height ?? 0);
|
|
56
|
+
const spaceList = spaces ?? [];
|
|
43
57
|
return /* @__PURE__ */ jsx2(
|
|
44
58
|
"div",
|
|
45
59
|
{
|
|
@@ -47,31 +61,29 @@ function Grid({ grid }) {
|
|
|
47
61
|
style: {
|
|
48
62
|
display: "inline-grid",
|
|
49
63
|
width: "100%",
|
|
50
|
-
gridTemplateColumns: `repeat(${
|
|
51
|
-
gridTemplateRows: `repeat(${
|
|
64
|
+
gridTemplateColumns: `repeat(${w}, 1fr)`,
|
|
65
|
+
gridTemplateRows: `repeat(${h}, 1fr)`
|
|
52
66
|
},
|
|
53
|
-
children:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
);
|
|
62
|
-
})
|
|
67
|
+
children: spaceList.map((space, index) => /* @__PURE__ */ jsx2(
|
|
68
|
+
"div",
|
|
69
|
+
{
|
|
70
|
+
className: "grid__cell",
|
|
71
|
+
children: /* @__PURE__ */ jsx2(Entity, { entity: space })
|
|
72
|
+
},
|
|
73
|
+
index
|
|
74
|
+
))
|
|
63
75
|
}
|
|
64
76
|
);
|
|
65
77
|
}
|
|
66
78
|
|
|
67
|
-
// src/components/space/space.
|
|
68
|
-
import React3 from "react";
|
|
79
|
+
// src/components/space/space.tsx
|
|
69
80
|
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
70
81
|
function Space({ space }) {
|
|
71
82
|
const { clickTarget, allClickable, currentMoveTargets } = useGame();
|
|
72
83
|
const { entities, entityId } = space.attributes;
|
|
84
|
+
const entityList = entities ?? [];
|
|
73
85
|
const clickable = allClickable.has(space);
|
|
74
|
-
const targeted = currentMoveTargets
|
|
86
|
+
const targeted = currentMoveTargets.map((e) => e.entityId ?? e.attributes?.entityId).includes(entityId);
|
|
75
87
|
return /* @__PURE__ */ jsx3(
|
|
76
88
|
"a",
|
|
77
89
|
{
|
|
@@ -96,18 +108,18 @@ function Space({ space }) {
|
|
|
96
108
|
flexWrap: "wrap"
|
|
97
109
|
},
|
|
98
110
|
children: [
|
|
99
|
-
Array.from({ length:
|
|
111
|
+
Array.from({ length: entityList.length }, (_, i) => /* @__PURE__ */ jsx3(
|
|
100
112
|
"div",
|
|
101
113
|
{
|
|
102
114
|
className: "space__entity-grid__cell",
|
|
103
115
|
style: {
|
|
104
116
|
display: "inline-block"
|
|
105
117
|
},
|
|
106
|
-
children: /* @__PURE__ */ jsx3(Entity, { entity:
|
|
118
|
+
children: /* @__PURE__ */ jsx3(Entity, { entity: entityList[i] })
|
|
107
119
|
},
|
|
108
120
|
i
|
|
109
121
|
)),
|
|
110
|
-
!
|
|
122
|
+
!entityList.length && String(space.attributes.name ?? "")
|
|
111
123
|
]
|
|
112
124
|
}
|
|
113
125
|
)
|
|
@@ -115,7 +127,7 @@ function Space({ space }) {
|
|
|
115
127
|
);
|
|
116
128
|
}
|
|
117
129
|
|
|
118
|
-
// src/components/entity/entity.
|
|
130
|
+
// src/components/entity/entity.tsx
|
|
119
131
|
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
120
132
|
function Entity({ entity }) {
|
|
121
133
|
const { clickTarget, allClickable } = useGame();
|
|
@@ -124,9 +136,9 @@ function Entity({ entity }) {
|
|
|
124
136
|
const entityType = attributes.entityType ?? attributes.type;
|
|
125
137
|
switch (entityType) {
|
|
126
138
|
case "Grid":
|
|
127
|
-
return /* @__PURE__ */ jsx4(Grid, { grid: entity
|
|
139
|
+
return /* @__PURE__ */ jsx4(Grid, { grid: entity });
|
|
128
140
|
case "Space":
|
|
129
|
-
return /* @__PURE__ */ jsx4(Space, { space: entity
|
|
141
|
+
return /* @__PURE__ */ jsx4(Space, { space: entity });
|
|
130
142
|
default:
|
|
131
143
|
return /* @__PURE__ */ jsx4(
|
|
132
144
|
"div",
|
|
@@ -139,31 +151,33 @@ function Entity({ entity }) {
|
|
|
139
151
|
},
|
|
140
152
|
className: [
|
|
141
153
|
"entity",
|
|
142
|
-
attributes.player && `player-${attributes.player}`,
|
|
154
|
+
attributes.player !== void 0 && `player-${String(attributes.player)}`,
|
|
143
155
|
isClickable && "entity--clickable"
|
|
144
156
|
].filter(Boolean).join(" "),
|
|
145
157
|
children: entity.rule.displayProperties?.map((property, i) => /* @__PURE__ */ jsxs2("div", { children: [
|
|
146
158
|
property,
|
|
147
159
|
": ",
|
|
148
|
-
|
|
160
|
+
String(attributes[property] ?? "")
|
|
149
161
|
] }, i))
|
|
150
162
|
}
|
|
151
163
|
);
|
|
152
164
|
}
|
|
153
165
|
}
|
|
154
166
|
|
|
155
|
-
// src/components/abstract-choices/abstract-choices.
|
|
156
|
-
import React5 from "react";
|
|
167
|
+
// src/components/abstract-choices/abstract-choices.tsx
|
|
157
168
|
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
158
169
|
function AbstractChoices() {
|
|
159
170
|
const { clickTarget, allClickable, undoStep, currentMoveTargets } = useGame();
|
|
160
|
-
const abstractChoices = [...allClickable].filter(
|
|
171
|
+
const abstractChoices = [...allClickable].filter(
|
|
172
|
+
(c) => c.abstract
|
|
173
|
+
);
|
|
161
174
|
return /* @__PURE__ */ jsxs3("div", { style: { position: "relative" }, children: [
|
|
162
175
|
/* @__PURE__ */ jsx5(
|
|
163
176
|
"button",
|
|
164
177
|
{
|
|
165
178
|
style: { visibility: "hidden" },
|
|
166
179
|
className: "button button--style-b button--x-small abstract-choices__choice",
|
|
180
|
+
type: "button",
|
|
167
181
|
children: "Spacer"
|
|
168
182
|
}
|
|
169
183
|
),
|
|
@@ -179,6 +193,7 @@ function AbstractChoices() {
|
|
|
179
193
|
!!currentMoveTargets.length && /* @__PURE__ */ jsx5(
|
|
180
194
|
"button",
|
|
181
195
|
{
|
|
196
|
+
type: "button",
|
|
182
197
|
className: "button button--style-c button--x-small abstract-choices__choice abstract-choices__choice--undo",
|
|
183
198
|
onClick: undoStep,
|
|
184
199
|
children: "Undo"
|
|
@@ -187,9 +202,10 @@ function AbstractChoices() {
|
|
|
187
202
|
abstractChoices.map((choice, i) => /* @__PURE__ */ jsx5(
|
|
188
203
|
"button",
|
|
189
204
|
{
|
|
205
|
+
type: "button",
|
|
190
206
|
className: "button button--style-b button--x-small abstract-choices__choice",
|
|
191
207
|
onClick: () => clickTarget(choice),
|
|
192
|
-
children: choice.value
|
|
208
|
+
children: String(choice.value ?? "")
|
|
193
209
|
},
|
|
194
210
|
i
|
|
195
211
|
))
|
|
@@ -199,28 +215,36 @@ function AbstractChoices() {
|
|
|
199
215
|
] });
|
|
200
216
|
}
|
|
201
217
|
|
|
202
|
-
// src/components/game-status/game-status.
|
|
203
|
-
import React6 from "react";
|
|
218
|
+
// src/components/game-status/game-status.tsx
|
|
204
219
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
205
|
-
function GameStatus({
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const
|
|
220
|
+
function GameStatus({
|
|
221
|
+
gameConnection
|
|
222
|
+
}) {
|
|
223
|
+
const state = gameConnection.state;
|
|
224
|
+
if (!state) return null;
|
|
225
|
+
const players = gameConnection.client?.matchData;
|
|
226
|
+
const winner = state.ctx.gameover?.winner;
|
|
227
|
+
const draw = state.ctx.gameover?.draw;
|
|
209
228
|
let winnerString = "";
|
|
210
229
|
if (draw) {
|
|
211
230
|
winnerString = "Draw!";
|
|
212
|
-
} else if (players && winner) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
231
|
+
} else if (players != null && winner != null && winner !== "") {
|
|
232
|
+
const key = String(winner);
|
|
233
|
+
winnerString = `${players[key]?.name ?? ""} Wins!`;
|
|
234
|
+
} else if (winner != null && winner !== "") {
|
|
235
|
+
winnerString = `Player ${String(winner)} Wins!`;
|
|
216
236
|
}
|
|
217
|
-
return
|
|
237
|
+
return state.ctx.gameover && /* @__PURE__ */ jsx6("div", { className: "game-status", children: winnerString });
|
|
218
238
|
}
|
|
219
239
|
|
|
220
|
-
// src/components/game/game.
|
|
240
|
+
// src/components/game/game.tsx
|
|
221
241
|
import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
222
|
-
function Game({
|
|
223
|
-
|
|
242
|
+
function Game({
|
|
243
|
+
gameConnection,
|
|
244
|
+
loading,
|
|
245
|
+
isSpectator
|
|
246
|
+
}) {
|
|
247
|
+
const G = gameConnection && "state" in gameConnection ? gameConnection.state?.G : void 0;
|
|
224
248
|
return G ? /* @__PURE__ */ jsx7(
|
|
225
249
|
GameProvider,
|
|
226
250
|
{
|
|
@@ -264,10 +288,12 @@ function Game({ gameConnection, loading, isSpectator }) {
|
|
|
264
288
|
) : loading;
|
|
265
289
|
}
|
|
266
290
|
|
|
267
|
-
// src/use-gameserver-connection.
|
|
291
|
+
// src/use-gameserver-connection.ts
|
|
268
292
|
import { useEffect as useEffect2, useReducer, useState } from "react";
|
|
269
|
-
import {
|
|
270
|
-
|
|
293
|
+
import {
|
|
294
|
+
Client
|
|
295
|
+
} from "board-game-engine";
|
|
296
|
+
function useGameserverConnection({
|
|
271
297
|
server,
|
|
272
298
|
multiplayer,
|
|
273
299
|
matchID,
|
|
@@ -279,8 +305,8 @@ var useGameserverConnection = ({
|
|
|
279
305
|
numPlayers,
|
|
280
306
|
debug,
|
|
281
307
|
enabled = true
|
|
282
|
-
})
|
|
283
|
-
const [
|
|
308
|
+
}) {
|
|
309
|
+
const [_tick, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
284
310
|
const [connection, setConnection] = useState(null);
|
|
285
311
|
useEffect2(() => {
|
|
286
312
|
if (!gameRules && !boardgameIOGame || credentials && !(matchID && enabled && server)) {
|
|
@@ -305,7 +331,7 @@ var useGameserverConnection = ({
|
|
|
305
331
|
newConnection.connect();
|
|
306
332
|
setConnection(newConnection);
|
|
307
333
|
return () => {
|
|
308
|
-
|
|
334
|
+
newConnection.client?.stop();
|
|
309
335
|
setConnection(null);
|
|
310
336
|
};
|
|
311
337
|
}, [
|
|
@@ -321,12 +347,11 @@ var useGameserverConnection = ({
|
|
|
321
347
|
if (connection) {
|
|
322
348
|
return Object.assign(
|
|
323
349
|
connection,
|
|
324
|
-
connection
|
|
350
|
+
connection.getState?.()
|
|
325
351
|
);
|
|
326
|
-
} else {
|
|
327
|
-
return {};
|
|
328
352
|
}
|
|
329
|
-
};
|
|
353
|
+
return {};
|
|
354
|
+
}
|
|
330
355
|
export {
|
|
331
356
|
Client2 as Client,
|
|
332
357
|
Game,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-choices.d.ts","sourceRoot":"","sources":["../../../src/components/abstract-choices/abstract-choices.tsx"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,eAAe,4CA6CtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../../src/components/board/grid.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,CAAC,OAAO,UAAU,IAAI,CAAE,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,2CAyB3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/components/entity/entity.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,CAAC,OAAO,UAAU,MAAM,CAAE,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,2CAkCjE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { GameserverConnection } from '../../types';
|
|
3
|
+
export default function Game({ gameConnection, loading, isSpectator, }: {
|
|
4
|
+
gameConnection?: GameserverConnection | Record<string, never> | null;
|
|
5
|
+
loading?: ReactNode;
|
|
6
|
+
isSpectator?: boolean;
|
|
7
|
+
}): string | number | boolean | Iterable<ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
8
|
+
//# sourceMappingURL=game.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"game.d.ts","sourceRoot":"","sources":["../../../src/components/game/game.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtC,OAAO,KAAK,EAAc,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEnE,MAAM,CAAC,OAAO,UAAU,IAAI,CAAE,EAC5B,cAAc,EACd,OAAO,EACP,WAAW,GACZ,EAAE;IACD,cAAc,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAA;IACpE,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,gHAsDA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"game-status.d.ts","sourceRoot":"","sources":["../../../src/components/game-status/game-status.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEvD,MAAM,CAAC,OAAO,UAAU,UAAU,CAAE,EAClC,cAAc,GACf,EAAE;IACD,cAAc,EAAE,oBAAoB,CAAA;CACrC,OAuBA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../../../src/components/space/space.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,CAAC,OAAO,UAAU,KAAK,CAAE,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,UAAU,CAAA;CAAE,2CA+C9D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { GameserverConnection } from '../types';
|
|
3
|
+
export interface GameContextValue {
|
|
4
|
+
clickTarget: (target: unknown) => void;
|
|
5
|
+
undoStep: () => void;
|
|
6
|
+
allClickable: Set<unknown>;
|
|
7
|
+
currentMoveTargets: unknown[];
|
|
8
|
+
}
|
|
9
|
+
export declare function GameProvider({ gameConnection, children, isSpectator, }: {
|
|
10
|
+
gameConnection: GameserverConnection;
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
isSpectator?: boolean;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const useGame: () => GameContextValue;
|
|
15
|
+
//# sourceMappingURL=game-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"game-context.d.ts","sourceRoot":"","sources":["../../src/contexts/game-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AACd,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,YAAY,EAAE,GAAG,CAAC,OAAO,CAAC,CAAA;IAC1B,kBAAkB,EAAE,OAAO,EAAE,CAAA;CAC9B;AASD,wBAAgB,YAAY,CAAE,EAC5B,cAAc,EACd,QAAQ,EACR,WAAW,GACZ,EAAE;IACD,cAAc,EAAE,oBAAoB,CAAA;IACpC,QAAQ,EAAE,SAAS,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,2CA2BA;AAED,eAAO,MAAM,OAAO,wBAAgC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import './styles.css';
|
|
2
|
+
export { Client, gameFactory } from 'board-game-engine';
|
|
3
|
+
export type { ClientOptions, GameFactoryInput } from 'board-game-engine';
|
|
4
|
+
export { default as Game } from './components/game/game';
|
|
5
|
+
export { useGameserverConnection } from './use-gameserver-connection';
|
|
6
|
+
export type { UseGameserverConnectionParams } from './use-gameserver-connection';
|
|
7
|
+
export type { GameserverConnection } from './types';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAA;AACrB,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACvD,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAExE,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AACrE,YAAY,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAA;AAChF,YAAY,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Client } from 'board-game-engine';
|
|
2
|
+
export type GameserverConnection = Client & ReturnType<Client['getState']>;
|
|
3
|
+
/** Bagel / board entity passed through the React tree */
|
|
4
|
+
export interface GameEntity {
|
|
5
|
+
attributes: {
|
|
6
|
+
entityType?: string;
|
|
7
|
+
type?: string;
|
|
8
|
+
player?: string | number;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
spaces?: GameEntity[];
|
|
12
|
+
entities?: GameEntity[];
|
|
13
|
+
entityId?: unknown;
|
|
14
|
+
name?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
};
|
|
17
|
+
rule: {
|
|
18
|
+
displayProperties?: string[];
|
|
19
|
+
};
|
|
20
|
+
entityId?: unknown;
|
|
21
|
+
abstract?: boolean;
|
|
22
|
+
value?: unknown;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAA;AAE1E,yDAAyD;AACzD,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE;QACV,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;QACxB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,MAAM,CAAC,EAAE,UAAU,EAAE,CAAA;QACrB,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAA;QACvB,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,CAAA;IACD,IAAI,EAAE;QACJ,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAA;KAC7B,CAAA;IACD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ClientOptions, type GameFactoryInput } from 'board-game-engine';
|
|
2
|
+
import type { GameserverConnection } from './types';
|
|
3
|
+
export type UseGameserverConnectionParams = Omit<ClientOptions, 'gameRules'> & {
|
|
4
|
+
gameRules?: GameFactoryInput;
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function useGameserverConnection({ server, multiplayer, matchID, gameRules, gameName, boardgameIOGame, playerID, credentials, numPlayers, debug, enabled, }: UseGameserverConnectionParams): GameserverConnection | Record<string, never>;
|
|
8
|
+
//# sourceMappingURL=use-gameserver-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-gameserver-connection.d.ts","sourceRoot":"","sources":["../src/use-gameserver-connection.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEnD,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,GAAG;IAC7E,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,wBAAgB,uBAAuB,CAAE,EACvC,MAAM,EACN,WAAW,EACX,OAAO,EACP,SAAS,EACT,QAAQ,EACR,eAAe,EACf,QAAQ,EACR,WAAW,EACX,UAAU,EACV,KAAK,EACL,OAAc,GACf,EAAE,6BAA6B,GAAG,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAwD9E"}
|
package/examples/checkers.json
CHANGED
|
@@ -719,7 +719,7 @@
|
|
|
719
719
|
"expression": "(player == '0' and destinationCoordinates[1] == 0) or (player == '1' and destinationCoordinates[1] == 7)",
|
|
720
720
|
"arguments": {
|
|
721
721
|
"player": {
|
|
722
|
-
"type": "
|
|
722
|
+
"type": "relativePath",
|
|
723
723
|
"target": {
|
|
724
724
|
"type": "contextPath",
|
|
725
725
|
"path": ["originalTarget"]
|
|
@@ -727,7 +727,7 @@
|
|
|
727
727
|
"path": ["entities", 0, "rule", "player"]
|
|
728
728
|
},
|
|
729
729
|
"destinationCoordinates": {
|
|
730
|
-
"type": "
|
|
730
|
+
"type": "coordinates",
|
|
731
731
|
"target": {
|
|
732
732
|
"type": "contextPath",
|
|
733
733
|
"path": ["target"]
|
package/examples/eights.json
CHANGED
|
@@ -161,7 +161,7 @@
|
|
|
161
161
|
"conditions": [
|
|
162
162
|
{
|
|
163
163
|
"conditionType": "Is",
|
|
164
|
-
"target": { "type": "
|
|
164
|
+
"target": { "type": "parent" },
|
|
165
165
|
"matcher": { "name": "stock" }
|
|
166
166
|
},
|
|
167
167
|
{
|
|
@@ -195,7 +195,7 @@
|
|
|
195
195
|
"conditions": [
|
|
196
196
|
{
|
|
197
197
|
"conditionType": "Is",
|
|
198
|
-
"target": { "type": "
|
|
198
|
+
"target": { "type": "parent" },
|
|
199
199
|
"matcher": { "name": "stock" }
|
|
200
200
|
},
|
|
201
201
|
{
|
|
@@ -231,7 +231,7 @@
|
|
|
231
231
|
"conditions": [
|
|
232
232
|
{
|
|
233
233
|
"conditionType": "Is",
|
|
234
|
-
"target": { "type": "
|
|
234
|
+
"target": { "type": "parent" },
|
|
235
235
|
"matcher": { "name": "discard" }
|
|
236
236
|
},
|
|
237
237
|
{
|
|
@@ -298,7 +298,7 @@
|
|
|
298
298
|
"conditions": [
|
|
299
299
|
{
|
|
300
300
|
"conditionType": "Is",
|
|
301
|
-
"target": { "type": "
|
|
301
|
+
"target": { "type": "parent" },
|
|
302
302
|
"matcher": {
|
|
303
303
|
"name": "hand",
|
|
304
304
|
"player": {
|
|
@@ -319,13 +319,13 @@
|
|
|
319
319
|
{
|
|
320
320
|
"conditionType": "Is",
|
|
321
321
|
"matcher": {
|
|
322
|
-
"type": "
|
|
322
|
+
"type": "pick",
|
|
323
323
|
"properties": ["suit"],
|
|
324
324
|
"target": {
|
|
325
325
|
"conditions": [
|
|
326
326
|
{
|
|
327
327
|
"conditionType": "Is",
|
|
328
|
-
"target": { "type": "
|
|
328
|
+
"target": { "type": "parent" },
|
|
329
329
|
"matcher": { "name": "discard" }
|
|
330
330
|
},
|
|
331
331
|
{
|
|
@@ -339,13 +339,13 @@
|
|
|
339
339
|
{
|
|
340
340
|
"conditionType": "Is",
|
|
341
341
|
"matcher": {
|
|
342
|
-
"type": "
|
|
342
|
+
"type": "pick",
|
|
343
343
|
"properties": ["value"],
|
|
344
344
|
"target": {
|
|
345
345
|
"conditions": [
|
|
346
346
|
{
|
|
347
347
|
"conditionType": "Is",
|
|
348
|
-
"target": { "type": "
|
|
348
|
+
"target": { "type": "parent" },
|
|
349
349
|
"matcher": { "name": "discard" }
|
|
350
350
|
},
|
|
351
351
|
{
|
|
@@ -452,7 +452,7 @@
|
|
|
452
452
|
"conditions": [
|
|
453
453
|
{
|
|
454
454
|
"conditionType": "Is",
|
|
455
|
-
"target": { "type": "
|
|
455
|
+
"target": { "type": "parent" },
|
|
456
456
|
"matcher": { "name": "discard" }
|
|
457
457
|
},
|
|
458
458
|
{
|
|
@@ -512,7 +512,7 @@
|
|
|
512
512
|
"matcher": {
|
|
513
513
|
"name": "score",
|
|
514
514
|
"player": {
|
|
515
|
-
"type": "
|
|
515
|
+
"type": "relativePath",
|
|
516
516
|
"target": {
|
|
517
517
|
"conditions": [
|
|
518
518
|
{
|
|
@@ -538,7 +538,7 @@
|
|
|
538
538
|
"expression": "existingScore + sum(faceValues)",
|
|
539
539
|
"arguments": {
|
|
540
540
|
"existingScore": {
|
|
541
|
-
"type": "
|
|
541
|
+
"type": "relativePath",
|
|
542
542
|
"target": {
|
|
543
543
|
"conditions": [
|
|
544
544
|
{
|
|
@@ -546,7 +546,7 @@
|
|
|
546
546
|
"matcher": {
|
|
547
547
|
"name": "score",
|
|
548
548
|
"player": {
|
|
549
|
-
"type": "
|
|
549
|
+
"type": "relativePath",
|
|
550
550
|
"target": {
|
|
551
551
|
"conditions": [
|
|
552
552
|
{
|
|
@@ -574,7 +574,7 @@
|
|
|
574
574
|
"conditions": [
|
|
575
575
|
{
|
|
576
576
|
"conditionType": "Is",
|
|
577
|
-
"target": { "type": "
|
|
577
|
+
"target": { "type": "parent" },
|
|
578
578
|
"matcher": {
|
|
579
579
|
"name": "hand",
|
|
580
580
|
"player": {
|
|
@@ -590,7 +590,7 @@
|
|
|
590
590
|
"expression": "cardValue == 8 ? 50 : (cardValue >= 10 and cardValue <= 13) ? 10 : cardValue",
|
|
591
591
|
"arguments": {
|
|
592
592
|
"cardValue": {
|
|
593
|
-
"
|
|
593
|
+
"type": "relativePath",
|
|
594
594
|
"target": {
|
|
595
595
|
|
|
596
596
|
"type": "contextPath",
|
|
@@ -627,7 +627,7 @@
|
|
|
627
627
|
"expression": "score >= numPlayers * 50",
|
|
628
628
|
"arguments": {
|
|
629
629
|
"score": {
|
|
630
|
-
"type": "
|
|
630
|
+
"type": "relativePath",
|
|
631
631
|
"target": {
|
|
632
632
|
"type": "contextPath",
|
|
633
633
|
"path": ["loopTarget"]
|