@mnbroatch/boardgame.io 0.0.1
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 +21 -0
- package/README.md +102 -0
- package/ai/package.json +7 -0
- package/client/package.json +7 -0
- package/core/package.json +7 -0
- package/debug/package.json +7 -0
- package/dist/boardgameio.es.js +14238 -0
- package/dist/boardgameio.js +14277 -0
- package/dist/boardgameio.min.js +16 -0
- package/dist/cjs/Debug-9d141c06.js +9586 -0
- package/dist/cjs/ai-e0e8a768.js +377 -0
- package/dist/cjs/ai.js +20 -0
- package/dist/cjs/client-76dec77b.js +258 -0
- package/dist/cjs/client-a22d7500.js +524 -0
- package/dist/cjs/client.js +26 -0
- package/dist/cjs/core.js +52 -0
- package/dist/cjs/debug.js +18 -0
- package/dist/cjs/filter-player-view-bb02e2f6.js +89 -0
- package/dist/cjs/initialize-267fcd69.js +61 -0
- package/dist/cjs/internal.js +25 -0
- package/dist/cjs/master-2904879d.js +320 -0
- package/dist/cjs/master.js +18 -0
- package/dist/cjs/multiplayer.js +23 -0
- package/dist/cjs/plugin-random-7425844d.js +229 -0
- package/dist/cjs/plugins.js +59 -0
- package/dist/cjs/react-native.js +182 -0
- package/dist/cjs/react.js +727 -0
- package/dist/cjs/reducer-16eec232.js +1203 -0
- package/dist/cjs/server.js +4087 -0
- package/dist/cjs/socketio-7a0837eb.js +478 -0
- package/dist/cjs/testing.js +30 -0
- package/dist/cjs/transport-b1874dfa.js +37 -0
- package/dist/cjs/turn-order-b2ff8740.js +1136 -0
- package/dist/cjs/util-fcfd8fb8.js +140 -0
- package/dist/esm/Debug-0141fe2d.js +9577 -0
- package/dist/esm/ai-5c06e761.js +371 -0
- package/dist/esm/ai.js +8 -0
- package/dist/esm/client-2e653027.js +522 -0
- package/dist/esm/client-5f57c3f2.js +255 -0
- package/dist/esm/client.js +16 -0
- package/dist/esm/core.js +40 -0
- package/dist/esm/debug.js +10 -0
- package/dist/esm/filter-player-view-2c6cc96f.js +87 -0
- package/dist/esm/initialize-11d626ca.js +59 -0
- package/dist/esm/internal.js +10 -0
- package/dist/esm/master-fa8f2e43.js +318 -0
- package/dist/esm/master.js +10 -0
- package/dist/esm/multiplayer.js +14 -0
- package/dist/esm/plugin-random-087f861e.js +226 -0
- package/dist/esm/plugins.js +55 -0
- package/dist/esm/react-native.js +173 -0
- package/dist/esm/react.js +716 -0
- package/dist/esm/reducer-c46da7e5.js +1198 -0
- package/dist/esm/socketio-c22ffa65.js +455 -0
- package/dist/esm/testing.js +26 -0
- package/dist/esm/transport-ce07b771.js +35 -0
- package/dist/esm/turn-order-376d315e.js +1091 -0
- package/dist/esm/util-b6147cef.js +135 -0
- package/dist/types/packages/ai.d.ts +5 -0
- package/dist/types/packages/client.d.ts +3 -0
- package/dist/types/packages/core.d.ts +5 -0
- package/dist/types/packages/debug.d.ts +2 -0
- package/dist/types/packages/internal.d.ts +8 -0
- package/dist/types/packages/master.d.ts +2 -0
- package/dist/types/packages/multiplayer.d.ts +3 -0
- package/dist/types/packages/plugins.d.ts +3 -0
- package/dist/types/packages/react-native.d.ts +2 -0
- package/dist/types/packages/react.d.ts +3 -0
- package/dist/types/packages/server.d.ts +6 -0
- package/dist/types/packages/testing.d.ts +1 -0
- package/dist/types/src/ai/ai.d.ts +53 -0
- package/dist/types/src/ai/ai.test.d.ts +1 -0
- package/dist/types/src/ai/bot.d.ts +40 -0
- package/dist/types/src/ai/mcts-bot.d.ts +60 -0
- package/dist/types/src/ai/random-bot.d.ts +27 -0
- package/dist/types/src/client/client.d.ts +104 -0
- package/dist/types/src/client/client.test.d.ts +1 -0
- package/dist/types/src/client/debug/tests/debug.test.d.ts +1 -0
- package/dist/types/src/client/manager.d.ts +61 -0
- package/dist/types/src/client/react.d.ts +75 -0
- package/dist/types/src/client/react.ssr.test.d.ts +4 -0
- package/dist/types/src/client/react.test.d.ts +1 -0
- package/dist/types/src/client/transport/dummy.d.ts +18 -0
- package/dist/types/src/client/transport/local.d.ts +59 -0
- package/dist/types/src/client/transport/local.test.d.ts +1 -0
- package/dist/types/src/client/transport/socketio.d.ts +45 -0
- package/dist/types/src/client/transport/socketio.test.d.ts +1 -0
- package/dist/types/src/client/transport/transport.d.ts +50 -0
- package/dist/types/src/client/transport/transport.test.d.ts +1 -0
- package/dist/types/src/core/action-creators.d.ts +144 -0
- package/dist/types/src/core/action-types.d.ts +10 -0
- package/dist/types/src/core/backwards-compatibility.d.ts +12 -0
- package/dist/types/src/core/constants.d.ts +6 -0
- package/dist/types/src/core/errors.d.ts +15 -0
- package/dist/types/src/core/flow.d.ts +28 -0
- package/dist/types/src/core/flow.test.d.ts +1 -0
- package/dist/types/src/core/game-methods.d.ts +9 -0
- package/dist/types/src/core/game.d.ts +26 -0
- package/dist/types/src/core/game.test.d.ts +1 -0
- package/dist/types/src/core/initialize.d.ts +9 -0
- package/dist/types/src/core/logger.d.ts +2 -0
- package/dist/types/src/core/player-view.d.ts +7 -0
- package/dist/types/src/core/player-view.test.d.ts +1 -0
- package/dist/types/src/core/reducer.d.ts +155 -0
- package/dist/types/src/core/reducer.test.d.ts +1 -0
- package/dist/types/src/core/turn-order.d.ts +179 -0
- package/dist/types/src/core/turn-order.test.d.ts +8 -0
- package/dist/types/src/lobby/client.d.ts +194 -0
- package/dist/types/src/lobby/client.test.d.ts +1 -0
- package/dist/types/src/lobby/connection.d.ts +44 -0
- package/dist/types/src/lobby/connection.test.d.ts +1 -0
- package/dist/types/src/lobby/create-match-form.d.ts +26 -0
- package/dist/types/src/lobby/login-form.d.ts +23 -0
- package/dist/types/src/lobby/match-instance.d.ts +31 -0
- package/dist/types/src/lobby/react.d.ts +113 -0
- package/dist/types/src/lobby/react.ssr.test.d.ts +4 -0
- package/dist/types/src/lobby/react.test.d.ts +1 -0
- package/dist/types/src/master/filter-player-view.d.ts +96 -0
- package/dist/types/src/master/filter-player-view.test.d.ts +1 -0
- package/dist/types/src/master/master.d.ts +94 -0
- package/dist/types/src/master/master.test.d.ts +1 -0
- package/dist/types/src/plugins/events/events.d.ts +54 -0
- package/dist/types/src/plugins/events/events.test.d.ts +1 -0
- package/dist/types/src/plugins/main.d.ts +75 -0
- package/dist/types/src/plugins/main.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-events.d.ts +5 -0
- package/dist/types/src/plugins/plugin-immer.d.ts +7 -0
- package/dist/types/src/plugins/plugin-immer.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-log.d.ts +14 -0
- package/dist/types/src/plugins/plugin-log.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-player.d.ts +29 -0
- package/dist/types/src/plugins/plugin-player.test.d.ts +1 -0
- package/dist/types/src/plugins/plugin-random.d.ts +4 -0
- package/dist/types/src/plugins/plugin-serializable.d.ts +7 -0
- package/dist/types/src/plugins/plugin-serializable.test.d.ts +1 -0
- package/dist/types/src/plugins/random/random.alea.d.ts +19 -0
- package/dist/types/src/plugins/random/random.d.ts +54 -0
- package/dist/types/src/plugins/random/random.test.d.ts +1 -0
- package/dist/types/src/server/api.d.ts +13 -0
- package/dist/types/src/server/api.test.d.ts +1 -0
- package/dist/types/src/server/auth.d.ts +38 -0
- package/dist/types/src/server/auth.test.d.ts +1 -0
- package/dist/types/src/server/cors.d.ts +4 -0
- package/dist/types/src/server/cors.test.d.ts +1 -0
- package/dist/types/src/server/db/base.d.ts +192 -0
- package/dist/types/src/server/db/flatfile.d.ts +44 -0
- package/dist/types/src/server/db/flatfile.test.d.ts +1 -0
- package/dist/types/src/server/db/index.d.ts +4 -0
- package/dist/types/src/server/db/index.test.d.ts +1 -0
- package/dist/types/src/server/db/inmemory.d.ts +43 -0
- package/dist/types/src/server/db/inmemory.test.d.ts +1 -0
- package/dist/types/src/server/db/localstorage.d.ts +7 -0
- package/dist/types/src/server/db/localstorage.test.d.ts +1 -0
- package/dist/types/src/server/index.d.ts +68 -0
- package/dist/types/src/server/index.test.d.ts +1 -0
- package/dist/types/src/server/transport/pubsub/generic-pub-sub.d.ts +6 -0
- package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.d.ts +7 -0
- package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.test.d.ts +1 -0
- package/dist/types/src/server/transport/socketio-simultaneous.test.d.ts +1 -0
- package/dist/types/src/server/transport/socketio.d.ts +65 -0
- package/dist/types/src/server/transport/socketio.test.d.ts +1 -0
- package/dist/types/src/server/util.d.ts +35 -0
- package/dist/types/src/testing/mock-random.d.ts +15 -0
- package/dist/types/src/testing/mock-random.test.d.ts +1 -0
- package/dist/types/src/types.d.ts +387 -0
- package/internal/package.json +7 -0
- package/master/package.json +7 -0
- package/multiplayer/package.json +7 -0
- package/package.json +211 -0
- package/plugins/package.json +7 -0
- package/react/package.json +7 -0
- package/react-native/package.json +7 -0
- package/server/package.json +6 -0
- package/src/ai/ai.test.ts +433 -0
- package/src/ai/ai.ts +84 -0
- package/src/ai/bot.ts +122 -0
- package/src/ai/mcts-bot.ts +331 -0
- package/src/ai/random-bot.ts +20 -0
- package/src/client/client.test.ts +993 -0
- package/src/client/client.ts +588 -0
- package/src/client/debug/Debug.svelte +239 -0
- package/src/client/debug/Menu.svelte +65 -0
- package/src/client/debug/ai/AI.svelte +215 -0
- package/src/client/debug/ai/Options.svelte +48 -0
- package/src/client/debug/info/Info.svelte +22 -0
- package/src/client/debug/info/Item.svelte +24 -0
- package/src/client/debug/log/Log.svelte +157 -0
- package/src/client/debug/log/LogEvent.svelte +149 -0
- package/src/client/debug/log/LogMetadata.svelte +7 -0
- package/src/client/debug/log/PhaseMarker.svelte +27 -0
- package/src/client/debug/log/TurnMarker.svelte +23 -0
- package/src/client/debug/main/ClientSwitcher.svelte +59 -0
- package/src/client/debug/main/Controls.svelte +58 -0
- package/src/client/debug/main/Hotkey.svelte +84 -0
- package/src/client/debug/main/InteractiveFunction.svelte +85 -0
- package/src/client/debug/main/Main.svelte +121 -0
- package/src/client/debug/main/Move.svelte +68 -0
- package/src/client/debug/main/PlayerInfo.svelte +70 -0
- package/src/client/debug/mcts/Action.svelte +22 -0
- package/src/client/debug/mcts/MCTS.svelte +78 -0
- package/src/client/debug/mcts/Table.svelte +98 -0
- package/src/client/debug/tests/JSONTree.mock.svelte +3 -0
- package/src/client/debug/tests/debug.test.ts +183 -0
- package/src/client/debug/utils/shortcuts.js +50 -0
- package/src/client/debug/utils/shortcuts.test.js +49 -0
- package/src/client/manager.ts +177 -0
- package/src/client/react-native.js +136 -0
- package/src/client/react-native.test.js +229 -0
- package/src/client/react.ssr.test.tsx +24 -0
- package/src/client/react.test.tsx +213 -0
- package/src/client/react.tsx +192 -0
- package/src/client/transport/dummy.ts +19 -0
- package/src/client/transport/local.test.ts +353 -0
- package/src/client/transport/local.ts +230 -0
- package/src/client/transport/socketio.test.ts +328 -0
- package/src/client/transport/socketio.ts +210 -0
- package/src/client/transport/transport.test.ts +27 -0
- package/src/client/transport/transport.ts +95 -0
- package/src/core/action-creators.ts +159 -0
- package/src/core/action-types.ts +18 -0
- package/src/core/backwards-compatibility.ts +23 -0
- package/src/core/constants.ts +6 -0
- package/src/core/errors.ts +35 -0
- package/src/core/flow.test.ts +2433 -0
- package/src/core/flow.ts +897 -0
- package/src/core/game-methods.ts +9 -0
- package/src/core/game.test.ts +286 -0
- package/src/core/game.ts +114 -0
- package/src/core/initialize.ts +77 -0
- package/src/core/logger.test.js +90 -0
- package/src/core/logger.ts +18 -0
- package/src/core/player-view.test.ts +50 -0
- package/src/core/player-view.ts +39 -0
- package/src/core/reducer.test.ts +991 -0
- package/src/core/reducer.ts +532 -0
- package/src/core/turn-order.test.ts +1123 -0
- package/src/core/turn-order.ts +473 -0
- package/src/lobby/client.test.ts +385 -0
- package/src/lobby/client.ts +358 -0
- package/src/lobby/connection.test.ts +207 -0
- package/src/lobby/connection.ts +162 -0
- package/src/lobby/create-match-form.tsx +122 -0
- package/src/lobby/login-form.tsx +75 -0
- package/src/lobby/match-instance.tsx +135 -0
- package/src/lobby/react.ssr.test.tsx +22 -0
- package/src/lobby/react.test.tsx +594 -0
- package/src/lobby/react.tsx +402 -0
- package/src/master/filter-player-view.test.ts +381 -0
- package/src/master/filter-player-view.ts +102 -0
- package/src/master/master.test.ts +1068 -0
- package/src/master/master.ts +492 -0
- package/src/plugins/events/events.test.ts +108 -0
- package/src/plugins/events/events.ts +209 -0
- package/src/plugins/main.test.ts +411 -0
- package/src/plugins/main.ts +314 -0
- package/src/plugins/plugin-events.ts +40 -0
- package/src/plugins/plugin-immer.test.ts +86 -0
- package/src/plugins/plugin-immer.ts +37 -0
- package/src/plugins/plugin-log.test.ts +37 -0
- package/src/plugins/plugin-log.ts +40 -0
- package/src/plugins/plugin-player.test.ts +172 -0
- package/src/plugins/plugin-player.ts +100 -0
- package/src/plugins/plugin-random.ts +40 -0
- package/src/plugins/plugin-serializable.test.ts +40 -0
- package/src/plugins/plugin-serializable.ts +55 -0
- package/src/plugins/random/random.alea.ts +109 -0
- package/src/plugins/random/random.test.ts +167 -0
- package/src/plugins/random/random.ts +198 -0
- package/src/server/api.test.ts +1699 -0
- package/src/server/api.ts +527 -0
- package/src/server/auth.test.ts +275 -0
- package/src/server/auth.ts +89 -0
- package/src/server/cors.test.ts +121 -0
- package/src/server/cors.ts +7 -0
- package/src/server/db/base.ts +296 -0
- package/src/server/db/flatfile.test.ts +221 -0
- package/src/server/db/flatfile.ts +228 -0
- package/src/server/db/index.test.ts +8 -0
- package/src/server/db/index.ts +12 -0
- package/src/server/db/inmemory.test.ts +143 -0
- package/src/server/db/inmemory.ts +143 -0
- package/src/server/db/localstorage.test.ts +73 -0
- package/src/server/db/localstorage.ts +44 -0
- package/src/server/index.test.ts +265 -0
- package/src/server/index.ts +175 -0
- package/src/server/transport/pubsub/generic-pub-sub.ts +11 -0
- package/src/server/transport/pubsub/in-memory-pub-sub.test.ts +47 -0
- package/src/server/transport/pubsub/in-memory-pub-sub.ts +28 -0
- package/src/server/transport/socketio-simultaneous.test.ts +603 -0
- package/src/server/transport/socketio.test.ts +303 -0
- package/src/server/transport/socketio.ts +279 -0
- package/src/server/util.ts +85 -0
- package/src/testing/mock-random.test.ts +45 -0
- package/src/testing/mock-random.ts +27 -0
- package/src/types.ts +511 -0
- package/testing/package.json +7 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Transport } from './transport';
|
|
2
|
+
import type { TransportOpts } from './transport';
|
|
3
|
+
/**
|
|
4
|
+
* This class doesn’t do anything, but simplifies the client class by providing
|
|
5
|
+
* dummy functions to call, so we don’t need to mock them in the client.
|
|
6
|
+
*/
|
|
7
|
+
declare class DummyImpl extends Transport {
|
|
8
|
+
connect(): void;
|
|
9
|
+
disconnect(): void;
|
|
10
|
+
sendAction(): void;
|
|
11
|
+
sendChatMessage(): void;
|
|
12
|
+
requestSync(): void;
|
|
13
|
+
updateCredentials(): void;
|
|
14
|
+
updateMatchID(): void;
|
|
15
|
+
updatePlayerID(): void;
|
|
16
|
+
}
|
|
17
|
+
export declare const DummyTransport: (opts: TransportOpts) => DummyImpl;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Master } from '../../master/master';
|
|
2
|
+
import type { TransportData } from '../../master/master';
|
|
3
|
+
import { Transport } from './transport';
|
|
4
|
+
import type { TransportOpts } from './transport';
|
|
5
|
+
import type { ChatMessage, CredentialedActionShape, Game, PlayerID, State } from '../../types';
|
|
6
|
+
/**
|
|
7
|
+
* Returns null if it is not a bot's turn.
|
|
8
|
+
* Otherwise, returns a playerID of a bot that may play now.
|
|
9
|
+
*/
|
|
10
|
+
export declare function GetBotPlayer(state: State, bots: Record<PlayerID, any>): string;
|
|
11
|
+
interface LocalOpts {
|
|
12
|
+
bots?: Record<PlayerID, any>;
|
|
13
|
+
persist?: boolean;
|
|
14
|
+
storageKey?: string;
|
|
15
|
+
}
|
|
16
|
+
declare type LocalMasterOpts = LocalOpts & {
|
|
17
|
+
game: Game;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Creates a local version of the master that the client
|
|
21
|
+
* can interact with.
|
|
22
|
+
*/
|
|
23
|
+
export declare class LocalMaster extends Master {
|
|
24
|
+
connect: (playerID: PlayerID, callback: (data: TransportData) => void) => void;
|
|
25
|
+
constructor({ game, bots, storageKey, persist }: LocalMasterOpts);
|
|
26
|
+
}
|
|
27
|
+
declare type LocalTransportOpts = TransportOpts & {
|
|
28
|
+
master?: LocalMaster;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Local
|
|
32
|
+
*
|
|
33
|
+
* Transport interface that embeds a GameMaster within it
|
|
34
|
+
* that you can connect multiple clients to.
|
|
35
|
+
*/
|
|
36
|
+
export declare class LocalTransport extends Transport {
|
|
37
|
+
master: LocalMaster;
|
|
38
|
+
/**
|
|
39
|
+
* Creates a new Mutiplayer instance.
|
|
40
|
+
* @param {string} matchID - The game ID to connect to.
|
|
41
|
+
* @param {string} playerID - The player ID associated with this client.
|
|
42
|
+
* @param {string} gameName - The game type (the `name` field in `Game`).
|
|
43
|
+
* @param {string} numPlayers - The number of players.
|
|
44
|
+
*/
|
|
45
|
+
constructor({ master, ...opts }: LocalTransportOpts);
|
|
46
|
+
sendChatMessage(matchID: string, chatMessage: ChatMessage): void;
|
|
47
|
+
sendAction(state: State, action: CredentialedActionShape.Any): void;
|
|
48
|
+
requestSync(): void;
|
|
49
|
+
connect(): void;
|
|
50
|
+
disconnect(): void;
|
|
51
|
+
updateMatchID(id: string): void;
|
|
52
|
+
updatePlayerID(id: PlayerID): void;
|
|
53
|
+
updateCredentials(credentials?: string): void;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create a local transport.
|
|
57
|
+
*/
|
|
58
|
+
export declare function Local({ bots, persist, storageKey }?: LocalOpts): (transportOpts: TransportOpts) => LocalTransport;
|
|
59
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as ioNamespace from 'socket.io-client';
|
|
2
|
+
import { Transport } from './transport';
|
|
3
|
+
import type { TransportOpts } from './transport';
|
|
4
|
+
import type { CredentialedActionShape, PlayerID, State, ChatMessage } from '../../types';
|
|
5
|
+
declare type SocketOpts = Partial<ioNamespace.SocketOptions & ioNamespace.ManagerOptions>;
|
|
6
|
+
interface SocketIOOpts {
|
|
7
|
+
server?: string;
|
|
8
|
+
socketOpts?: SocketOpts;
|
|
9
|
+
}
|
|
10
|
+
declare type SocketIOTransportOpts = TransportOpts & SocketIOOpts & {
|
|
11
|
+
socket?: any;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* SocketIO
|
|
15
|
+
*
|
|
16
|
+
* Transport interface that interacts with the Master via socket.io.
|
|
17
|
+
*/
|
|
18
|
+
export declare class SocketIOTransport extends Transport {
|
|
19
|
+
server: string;
|
|
20
|
+
socket: ioNamespace.Socket;
|
|
21
|
+
socketOpts: SocketOpts;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new Multiplayer instance.
|
|
24
|
+
* @param {object} socket - Override for unit tests.
|
|
25
|
+
* @param {object} socketOpts - Options to pass to socket.io.
|
|
26
|
+
* @param {object} store - Redux store
|
|
27
|
+
* @param {string} matchID - The game ID to connect to.
|
|
28
|
+
* @param {string} playerID - The player ID associated with this client.
|
|
29
|
+
* @param {string} credentials - Authentication credentials
|
|
30
|
+
* @param {string} gameName - The game type (the `name` field in `Game`).
|
|
31
|
+
* @param {string} numPlayers - The number of players.
|
|
32
|
+
* @param {string} server - The game server in the form of 'hostname:port'. Defaults to the server serving the client if not provided.
|
|
33
|
+
*/
|
|
34
|
+
constructor({ socket, socketOpts, server, ...opts }: SocketIOTransportOpts);
|
|
35
|
+
sendAction(state: State, action: CredentialedActionShape.Any): void;
|
|
36
|
+
sendChatMessage(matchID: string, chatMessage: ChatMessage): void;
|
|
37
|
+
connect(): void;
|
|
38
|
+
disconnect(): void;
|
|
39
|
+
requestSync(): void;
|
|
40
|
+
updateMatchID(id: string): void;
|
|
41
|
+
updatePlayerID(id: PlayerID): void;
|
|
42
|
+
updateCredentials(credentials?: string): void;
|
|
43
|
+
}
|
|
44
|
+
export declare function SocketIO({ server, socketOpts }?: SocketIOOpts): (transportOpts: SocketIOTransportOpts) => SocketIOTransport;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ProcessGameConfig } from '../../core/game';
|
|
2
|
+
import type { TransportData } from '../../master/master';
|
|
3
|
+
import type { Game, PlayerID, CredentialedActionShape, State, SyncInfo, ChatMessage } from '../../types';
|
|
4
|
+
export declare type MetadataCallback = (metadata: SyncInfo['filteredMetadata']) => void;
|
|
5
|
+
export declare type ChatCallback = (message: ChatMessage) => void;
|
|
6
|
+
export interface TransportOpts {
|
|
7
|
+
transportDataCallback: (data: TransportData) => void;
|
|
8
|
+
gameName?: string;
|
|
9
|
+
gameKey: Game;
|
|
10
|
+
game: ReturnType<typeof ProcessGameConfig>;
|
|
11
|
+
playerID?: PlayerID;
|
|
12
|
+
matchID?: string;
|
|
13
|
+
credentials?: string;
|
|
14
|
+
numPlayers?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare abstract class Transport {
|
|
17
|
+
protected gameName: string;
|
|
18
|
+
protected playerID: PlayerID | null;
|
|
19
|
+
protected matchID: string;
|
|
20
|
+
protected credentials?: string;
|
|
21
|
+
protected numPlayers: number;
|
|
22
|
+
/** Callback to pass transport data back to the client. */
|
|
23
|
+
private transportDataCallback;
|
|
24
|
+
/** Callback to let the client know when the connection status has changed. */
|
|
25
|
+
private connectionStatusCallback;
|
|
26
|
+
isConnected: boolean;
|
|
27
|
+
constructor({ transportDataCallback, gameName, playerID, matchID, credentials, numPlayers, }: TransportOpts);
|
|
28
|
+
/** Subscribe to connection state changes. */
|
|
29
|
+
subscribeToConnectionStatus(fn: () => void): void;
|
|
30
|
+
/** Transport implementations should call this when they connect/disconnect. */
|
|
31
|
+
protected setConnectionStatus(isConnected: boolean): void;
|
|
32
|
+
/** Transport implementations should call this when they receive data from a master. */
|
|
33
|
+
protected notifyClient(data: TransportData): void;
|
|
34
|
+
/** Called by the client to connect the transport. */
|
|
35
|
+
abstract connect(): void;
|
|
36
|
+
/** Called by the client to disconnect the transport. */
|
|
37
|
+
abstract disconnect(): void;
|
|
38
|
+
/** Called by the client to dispatch an action via the transport. */
|
|
39
|
+
abstract sendAction(state: State, action: CredentialedActionShape.Any): void;
|
|
40
|
+
/** Called by the client to dispatch a chat message via the transport. */
|
|
41
|
+
abstract sendChatMessage(matchID: string, chatMessage: ChatMessage): void;
|
|
42
|
+
/** Called by the client to request a sync action from the transport. */
|
|
43
|
+
abstract requestSync(): void;
|
|
44
|
+
/** Called by the client to update the matchID it wants to connect to. */
|
|
45
|
+
abstract updateMatchID(id: string): void;
|
|
46
|
+
/** Called by the client to update the playerID it is playing as. */
|
|
47
|
+
abstract updatePlayerID(id: PlayerID): void;
|
|
48
|
+
/** Called by the client to update the credentials it is using. */
|
|
49
|
+
abstract updateCredentials(credentials?: string): void;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { SyncInfo, State, LogEntry } from '../types';
|
|
2
|
+
import type { Operation } from 'rfc6902';
|
|
3
|
+
/**
|
|
4
|
+
* Generate a move to be dispatched to the game move reducer.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} type - The move type.
|
|
7
|
+
* @param {Array} args - Additional arguments.
|
|
8
|
+
* @param {string} playerID - The ID of the player making this action.
|
|
9
|
+
* @param {string} credentials - (optional) The credentials for the player making this action.
|
|
10
|
+
*/
|
|
11
|
+
export declare const makeMove: (type: string, args?: any, playerID?: string | null, credentials?: string) => {
|
|
12
|
+
type: "MAKE_MOVE";
|
|
13
|
+
payload: {
|
|
14
|
+
type: string;
|
|
15
|
+
args: any;
|
|
16
|
+
playerID: string;
|
|
17
|
+
credentials: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Generate a game event to be dispatched to the flow reducer.
|
|
22
|
+
*
|
|
23
|
+
* @param {string} type - The event type.
|
|
24
|
+
* @param {Array} args - Additional arguments.
|
|
25
|
+
* @param {string} playerID - The ID of the player making this action.
|
|
26
|
+
* @param {string} credentials - (optional) The credentials for the player making this action.
|
|
27
|
+
*/
|
|
28
|
+
export declare const gameEvent: (type: string, args?: any, playerID?: string | null, credentials?: string) => {
|
|
29
|
+
type: "GAME_EVENT";
|
|
30
|
+
payload: {
|
|
31
|
+
type: string;
|
|
32
|
+
args: any;
|
|
33
|
+
playerID: string;
|
|
34
|
+
credentials: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Generate an automatic game event that is a side-effect of a move.
|
|
39
|
+
* @param {string} type - The event type.
|
|
40
|
+
* @param {Array} args - Additional arguments.
|
|
41
|
+
* @param {string} playerID - The ID of the player making this action.
|
|
42
|
+
* @param {string} credentials - (optional) The credentials for the player making this action.
|
|
43
|
+
*/
|
|
44
|
+
export declare const automaticGameEvent: (type: string, args: any, playerID?: string | null, credentials?: string) => {
|
|
45
|
+
type: "GAME_EVENT";
|
|
46
|
+
payload: {
|
|
47
|
+
type: string;
|
|
48
|
+
args: any;
|
|
49
|
+
playerID: string;
|
|
50
|
+
credentials: string;
|
|
51
|
+
};
|
|
52
|
+
automatic: boolean;
|
|
53
|
+
};
|
|
54
|
+
export declare const sync: (info: SyncInfo) => {
|
|
55
|
+
type: "SYNC";
|
|
56
|
+
state: State<any>;
|
|
57
|
+
log: LogEntry[];
|
|
58
|
+
initialState: State<any>;
|
|
59
|
+
clientOnly: true;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Used to update the Redux store's state with patch in response to
|
|
63
|
+
* an action coming from another player.
|
|
64
|
+
* @param prevStateID previous stateID
|
|
65
|
+
* @param stateID stateID after this patch
|
|
66
|
+
* @param {Operation[]} patch - The patch to apply.
|
|
67
|
+
* @param {LogEntry[]} deltalog - A log delta.
|
|
68
|
+
*/
|
|
69
|
+
export declare const patch: (prevStateID: number, stateID: number, patch: Operation[], deltalog: LogEntry[]) => {
|
|
70
|
+
type: "PATCH";
|
|
71
|
+
prevStateID: number;
|
|
72
|
+
stateID: number;
|
|
73
|
+
patch: Operation[];
|
|
74
|
+
deltalog: LogEntry[];
|
|
75
|
+
clientOnly: true;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Used to update the Redux store's state in response to
|
|
79
|
+
* an action coming from another player.
|
|
80
|
+
* @param {object} state - The state to restore.
|
|
81
|
+
* @param {Array} deltalog - A log delta.
|
|
82
|
+
*/
|
|
83
|
+
export declare const update: (state: State, deltalog: LogEntry[]) => {
|
|
84
|
+
type: "UPDATE";
|
|
85
|
+
state: State<any>;
|
|
86
|
+
deltalog: LogEntry[];
|
|
87
|
+
clientOnly: true;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Used to reset the game state.
|
|
91
|
+
* @param {object} state - The initial state.
|
|
92
|
+
*/
|
|
93
|
+
export declare const reset: (state: State) => {
|
|
94
|
+
type: "RESET";
|
|
95
|
+
state: State<any>;
|
|
96
|
+
clientOnly: true;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Used to undo the last move.
|
|
100
|
+
* @param {string} playerID - The ID of the player making this action.
|
|
101
|
+
* @param {string} credentials - (optional) The credentials for the player making this action.
|
|
102
|
+
*/
|
|
103
|
+
export declare const undo: (playerID?: string | null, credentials?: string) => {
|
|
104
|
+
type: "UNDO";
|
|
105
|
+
payload: {
|
|
106
|
+
type: any;
|
|
107
|
+
args: any;
|
|
108
|
+
playerID: string;
|
|
109
|
+
credentials: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Used to redo the last undone move.
|
|
114
|
+
* @param {string} playerID - The ID of the player making this action.
|
|
115
|
+
* @param {string} credentials - (optional) The credentials for the player making this action.
|
|
116
|
+
*/
|
|
117
|
+
export declare const redo: (playerID?: string | null, credentials?: string) => {
|
|
118
|
+
type: "REDO";
|
|
119
|
+
payload: {
|
|
120
|
+
type: any;
|
|
121
|
+
args: any;
|
|
122
|
+
playerID: string;
|
|
123
|
+
credentials: string;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Allows plugins to define their own actions and intercept them.
|
|
128
|
+
*/
|
|
129
|
+
export declare const plugin: (type: string, args?: any, playerID?: string | null, credentials?: string) => {
|
|
130
|
+
type: "PLUGIN";
|
|
131
|
+
payload: {
|
|
132
|
+
type: string;
|
|
133
|
+
args: any;
|
|
134
|
+
playerID: string;
|
|
135
|
+
credentials: string;
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Private action used to strip transient metadata (e.g. errors) from the game
|
|
140
|
+
* state.
|
|
141
|
+
*/
|
|
142
|
+
export declare const stripTransients: () => {
|
|
143
|
+
type: "STRIP_TRANSIENTS";
|
|
144
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const MAKE_MOVE = "MAKE_MOVE";
|
|
2
|
+
export declare const GAME_EVENT = "GAME_EVENT";
|
|
3
|
+
export declare const REDO = "REDO";
|
|
4
|
+
export declare const RESET = "RESET";
|
|
5
|
+
export declare const SYNC = "SYNC";
|
|
6
|
+
export declare const UNDO = "UNDO";
|
|
7
|
+
export declare const UPDATE = "UPDATE";
|
|
8
|
+
export declare const PATCH = "PATCH";
|
|
9
|
+
export declare const PLUGIN = "PLUGIN";
|
|
10
|
+
export declare const STRIP_TRANSIENTS = "STRIP_TRANSIENTS";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare type MoveLimitOptions = {
|
|
2
|
+
minMoves?: number;
|
|
3
|
+
maxMoves?: number;
|
|
4
|
+
moveLimit?: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Adjust the given options to use the new minMoves/maxMoves if a legacy moveLimit was given
|
|
8
|
+
* @param options The options object to apply backwards compatibility to
|
|
9
|
+
* @param enforceMinMoves Use moveLimit to set both minMoves and maxMoves
|
|
10
|
+
*/
|
|
11
|
+
export declare function supportDeprecatedMoveLimit(options: MoveLimitOptions, enforceMinMoves?: boolean): void;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare enum UpdateErrorType {
|
|
2
|
+
UnauthorizedAction = "update/unauthorized_action",
|
|
3
|
+
MatchNotFound = "update/match_not_found",
|
|
4
|
+
PatchFailed = "update/patch_failed"
|
|
5
|
+
}
|
|
6
|
+
export declare enum ActionErrorType {
|
|
7
|
+
StaleStateId = "action/stale_state_id",
|
|
8
|
+
UnavailableMove = "action/unavailable_move",
|
|
9
|
+
InvalidMove = "action/invalid_move",
|
|
10
|
+
InactivePlayer = "action/inactive_player",
|
|
11
|
+
GameOver = "action/gameover",
|
|
12
|
+
ActionDisabled = "action/action_disabled",
|
|
13
|
+
ActionInvalid = "action/action_invalid",
|
|
14
|
+
PluginActionInvalid = "action/plugin_invalid"
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ActionPayload, ActionShape, ActivePlayersArg, State, Ctx, Game, PlayerID, Move } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Flow
|
|
4
|
+
*
|
|
5
|
+
* Creates a reducer that updates ctx (analogous to how moves update G).
|
|
6
|
+
*/
|
|
7
|
+
export declare function Flow({ moves, phases, endIf, onEnd, turn, events, plugins, }: Game): {
|
|
8
|
+
ctx: (numPlayers: number) => Ctx;
|
|
9
|
+
init: (state: State) => State;
|
|
10
|
+
isPlayerActive: (_G: any, ctx: Ctx, playerID: PlayerID) => boolean;
|
|
11
|
+
eventHandlers: {
|
|
12
|
+
endStage: (state: State, playerID: PlayerID) => State;
|
|
13
|
+
setStage: (state: State, playerID: PlayerID, arg: any) => State;
|
|
14
|
+
endTurn: (state: State, _playerID: PlayerID, arg: any) => State;
|
|
15
|
+
pass: (state: State, _playerID: PlayerID, arg: any) => State;
|
|
16
|
+
endPhase: (state: State) => State;
|
|
17
|
+
setPhase: (state: State, _playerID: PlayerID, newPhase: string) => State;
|
|
18
|
+
endGame: (state: State, _playerID: PlayerID, arg: any) => State;
|
|
19
|
+
setActivePlayers: (state: State, _playerID: PlayerID, arg: ActivePlayersArg) => State;
|
|
20
|
+
};
|
|
21
|
+
eventNames: string[];
|
|
22
|
+
enabledEventNames: any[];
|
|
23
|
+
moveMap: {};
|
|
24
|
+
moveNames: unknown[];
|
|
25
|
+
processMove: (state: State, action: ActionPayload.MakeMove) => State;
|
|
26
|
+
processEvent: (state: State, action: ActionShape.GameEvent) => State;
|
|
27
|
+
getMove: (ctx: Ctx, name: string, playerID: PlayerID) => null | Move;
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Flow } from './flow';
|
|
2
|
+
import type { INVALID_MOVE } from './constants';
|
|
3
|
+
import type { ActionPayload, Game, Move, LongFormMove, State } from '../types';
|
|
4
|
+
declare type ProcessedGame = Game & {
|
|
5
|
+
flow: ReturnType<typeof Flow>;
|
|
6
|
+
moveNames: string[];
|
|
7
|
+
pluginNames: string[];
|
|
8
|
+
processMove: (state: State, action: ActionPayload.MakeMove) => State | typeof INVALID_MOVE;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Helper to generate the game move reducer. The returned
|
|
12
|
+
* reducer has the following signature:
|
|
13
|
+
*
|
|
14
|
+
* (G, action, ctx) => {}
|
|
15
|
+
*
|
|
16
|
+
* You can roll your own if you like, or use any Redux
|
|
17
|
+
* addon to generate such a reducer.
|
|
18
|
+
*
|
|
19
|
+
* The convention used in this framework is to
|
|
20
|
+
* have action.type contain the name of the move, and
|
|
21
|
+
* action.args contain any additional arguments as an
|
|
22
|
+
* Array.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ProcessGameConfig(game: Game | ProcessedGame): ProcessedGame;
|
|
25
|
+
export declare function IsLongFormMove(move: Move): move is LongFormMove;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { Dispatch } from 'redux';
|
|
2
|
+
import type { ActionShape, Game, LogEntry, State, Store, TransientMetadata, TransientState } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Middleware for processing TransientState associated with the reducer
|
|
5
|
+
* returned by CreateGameReducer.
|
|
6
|
+
* This should pretty much be used everywhere you want realistic state
|
|
7
|
+
* transitions and error handling.
|
|
8
|
+
*/
|
|
9
|
+
export declare const TransientHandlingMiddleware: (store: Store) => (next: Dispatch<ActionShape.Any>) => (action: ActionShape.Any) => {
|
|
10
|
+
type: "MAKE_MOVE";
|
|
11
|
+
payload: {
|
|
12
|
+
type: string;
|
|
13
|
+
args: any;
|
|
14
|
+
playerID: string;
|
|
15
|
+
};
|
|
16
|
+
} | {
|
|
17
|
+
type: "GAME_EVENT";
|
|
18
|
+
payload: {
|
|
19
|
+
type: string;
|
|
20
|
+
args: any;
|
|
21
|
+
playerID: string;
|
|
22
|
+
};
|
|
23
|
+
} | {
|
|
24
|
+
type: "UNDO";
|
|
25
|
+
payload: {
|
|
26
|
+
type: any;
|
|
27
|
+
args: any;
|
|
28
|
+
playerID: string;
|
|
29
|
+
};
|
|
30
|
+
} | {
|
|
31
|
+
type: "REDO";
|
|
32
|
+
payload: {
|
|
33
|
+
type: any;
|
|
34
|
+
args: any;
|
|
35
|
+
playerID: string;
|
|
36
|
+
};
|
|
37
|
+
} | {
|
|
38
|
+
type: "SYNC";
|
|
39
|
+
state: State<any>;
|
|
40
|
+
log: LogEntry[];
|
|
41
|
+
initialState: State<any>;
|
|
42
|
+
clientOnly: true;
|
|
43
|
+
} | {
|
|
44
|
+
type: "UPDATE";
|
|
45
|
+
state: State<any>;
|
|
46
|
+
deltalog: LogEntry[];
|
|
47
|
+
clientOnly: true;
|
|
48
|
+
} | {
|
|
49
|
+
type: "PATCH";
|
|
50
|
+
prevStateID: number;
|
|
51
|
+
stateID: number;
|
|
52
|
+
patch: import("rfc6902").Operation[];
|
|
53
|
+
deltalog: LogEntry[];
|
|
54
|
+
clientOnly: true;
|
|
55
|
+
} | {
|
|
56
|
+
type: "RESET";
|
|
57
|
+
state: State<any>;
|
|
58
|
+
clientOnly: true;
|
|
59
|
+
} | {
|
|
60
|
+
type: "PLUGIN";
|
|
61
|
+
payload: {
|
|
62
|
+
type: string;
|
|
63
|
+
args: any;
|
|
64
|
+
playerID: string;
|
|
65
|
+
};
|
|
66
|
+
} | {
|
|
67
|
+
type: "STRIP_TRANSIENTS";
|
|
68
|
+
} | {
|
|
69
|
+
transients: TransientMetadata;
|
|
70
|
+
type: "MAKE_MOVE";
|
|
71
|
+
payload: {
|
|
72
|
+
type: string;
|
|
73
|
+
args: any;
|
|
74
|
+
playerID: string;
|
|
75
|
+
};
|
|
76
|
+
} | {
|
|
77
|
+
transients: TransientMetadata;
|
|
78
|
+
type: "GAME_EVENT";
|
|
79
|
+
payload: {
|
|
80
|
+
type: string;
|
|
81
|
+
args: any;
|
|
82
|
+
playerID: string;
|
|
83
|
+
};
|
|
84
|
+
} | {
|
|
85
|
+
transients: TransientMetadata;
|
|
86
|
+
type: "UNDO";
|
|
87
|
+
payload: {
|
|
88
|
+
type: any;
|
|
89
|
+
args: any;
|
|
90
|
+
playerID: string;
|
|
91
|
+
};
|
|
92
|
+
} | {
|
|
93
|
+
transients: TransientMetadata;
|
|
94
|
+
type: "REDO";
|
|
95
|
+
payload: {
|
|
96
|
+
type: any;
|
|
97
|
+
args: any;
|
|
98
|
+
playerID: string;
|
|
99
|
+
};
|
|
100
|
+
} | {
|
|
101
|
+
transients: TransientMetadata;
|
|
102
|
+
type: "GAME_EVENT";
|
|
103
|
+
payload: {
|
|
104
|
+
type: string;
|
|
105
|
+
args: any;
|
|
106
|
+
playerID: string;
|
|
107
|
+
};
|
|
108
|
+
automatic: boolean;
|
|
109
|
+
} | {
|
|
110
|
+
transients: TransientMetadata;
|
|
111
|
+
type: "SYNC";
|
|
112
|
+
state: State<any>;
|
|
113
|
+
log: LogEntry[];
|
|
114
|
+
initialState: State<any>;
|
|
115
|
+
clientOnly: true;
|
|
116
|
+
} | {
|
|
117
|
+
transients: TransientMetadata;
|
|
118
|
+
type: "UPDATE";
|
|
119
|
+
state: State<any>;
|
|
120
|
+
deltalog: LogEntry[];
|
|
121
|
+
clientOnly: true;
|
|
122
|
+
} | {
|
|
123
|
+
transients: TransientMetadata;
|
|
124
|
+
type: "PATCH";
|
|
125
|
+
prevStateID: number;
|
|
126
|
+
stateID: number;
|
|
127
|
+
patch: import("rfc6902").Operation[];
|
|
128
|
+
deltalog: LogEntry[];
|
|
129
|
+
clientOnly: true;
|
|
130
|
+
} | {
|
|
131
|
+
transients: TransientMetadata;
|
|
132
|
+
type: "RESET";
|
|
133
|
+
state: State<any>;
|
|
134
|
+
clientOnly: true;
|
|
135
|
+
} | {
|
|
136
|
+
transients: TransientMetadata;
|
|
137
|
+
type: "PLUGIN";
|
|
138
|
+
payload: {
|
|
139
|
+
type: string;
|
|
140
|
+
args: any;
|
|
141
|
+
playerID: string;
|
|
142
|
+
};
|
|
143
|
+
} | {
|
|
144
|
+
transients: TransientMetadata;
|
|
145
|
+
type: "STRIP_TRANSIENTS";
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* CreateGameReducer
|
|
149
|
+
*
|
|
150
|
+
* Creates the main game state reducer.
|
|
151
|
+
*/
|
|
152
|
+
export declare function CreateGameReducer({ game, isClient, }: {
|
|
153
|
+
game: Game;
|
|
154
|
+
isClient?: boolean;
|
|
155
|
+
}): (stateWithTransients: TransientState | null, action: ActionShape.Any) => TransientState;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|