@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.
Files changed (296) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -0
  3. package/ai/package.json +7 -0
  4. package/client/package.json +7 -0
  5. package/core/package.json +7 -0
  6. package/debug/package.json +7 -0
  7. package/dist/boardgameio.es.js +14238 -0
  8. package/dist/boardgameio.js +14277 -0
  9. package/dist/boardgameio.min.js +16 -0
  10. package/dist/cjs/Debug-9d141c06.js +9586 -0
  11. package/dist/cjs/ai-e0e8a768.js +377 -0
  12. package/dist/cjs/ai.js +20 -0
  13. package/dist/cjs/client-76dec77b.js +258 -0
  14. package/dist/cjs/client-a22d7500.js +524 -0
  15. package/dist/cjs/client.js +26 -0
  16. package/dist/cjs/core.js +52 -0
  17. package/dist/cjs/debug.js +18 -0
  18. package/dist/cjs/filter-player-view-bb02e2f6.js +89 -0
  19. package/dist/cjs/initialize-267fcd69.js +61 -0
  20. package/dist/cjs/internal.js +25 -0
  21. package/dist/cjs/master-2904879d.js +320 -0
  22. package/dist/cjs/master.js +18 -0
  23. package/dist/cjs/multiplayer.js +23 -0
  24. package/dist/cjs/plugin-random-7425844d.js +229 -0
  25. package/dist/cjs/plugins.js +59 -0
  26. package/dist/cjs/react-native.js +182 -0
  27. package/dist/cjs/react.js +727 -0
  28. package/dist/cjs/reducer-16eec232.js +1203 -0
  29. package/dist/cjs/server.js +4087 -0
  30. package/dist/cjs/socketio-7a0837eb.js +478 -0
  31. package/dist/cjs/testing.js +30 -0
  32. package/dist/cjs/transport-b1874dfa.js +37 -0
  33. package/dist/cjs/turn-order-b2ff8740.js +1136 -0
  34. package/dist/cjs/util-fcfd8fb8.js +140 -0
  35. package/dist/esm/Debug-0141fe2d.js +9577 -0
  36. package/dist/esm/ai-5c06e761.js +371 -0
  37. package/dist/esm/ai.js +8 -0
  38. package/dist/esm/client-2e653027.js +522 -0
  39. package/dist/esm/client-5f57c3f2.js +255 -0
  40. package/dist/esm/client.js +16 -0
  41. package/dist/esm/core.js +40 -0
  42. package/dist/esm/debug.js +10 -0
  43. package/dist/esm/filter-player-view-2c6cc96f.js +87 -0
  44. package/dist/esm/initialize-11d626ca.js +59 -0
  45. package/dist/esm/internal.js +10 -0
  46. package/dist/esm/master-fa8f2e43.js +318 -0
  47. package/dist/esm/master.js +10 -0
  48. package/dist/esm/multiplayer.js +14 -0
  49. package/dist/esm/plugin-random-087f861e.js +226 -0
  50. package/dist/esm/plugins.js +55 -0
  51. package/dist/esm/react-native.js +173 -0
  52. package/dist/esm/react.js +716 -0
  53. package/dist/esm/reducer-c46da7e5.js +1198 -0
  54. package/dist/esm/socketio-c22ffa65.js +455 -0
  55. package/dist/esm/testing.js +26 -0
  56. package/dist/esm/transport-ce07b771.js +35 -0
  57. package/dist/esm/turn-order-376d315e.js +1091 -0
  58. package/dist/esm/util-b6147cef.js +135 -0
  59. package/dist/types/packages/ai.d.ts +5 -0
  60. package/dist/types/packages/client.d.ts +3 -0
  61. package/dist/types/packages/core.d.ts +5 -0
  62. package/dist/types/packages/debug.d.ts +2 -0
  63. package/dist/types/packages/internal.d.ts +8 -0
  64. package/dist/types/packages/master.d.ts +2 -0
  65. package/dist/types/packages/multiplayer.d.ts +3 -0
  66. package/dist/types/packages/plugins.d.ts +3 -0
  67. package/dist/types/packages/react-native.d.ts +2 -0
  68. package/dist/types/packages/react.d.ts +3 -0
  69. package/dist/types/packages/server.d.ts +6 -0
  70. package/dist/types/packages/testing.d.ts +1 -0
  71. package/dist/types/src/ai/ai.d.ts +53 -0
  72. package/dist/types/src/ai/ai.test.d.ts +1 -0
  73. package/dist/types/src/ai/bot.d.ts +40 -0
  74. package/dist/types/src/ai/mcts-bot.d.ts +60 -0
  75. package/dist/types/src/ai/random-bot.d.ts +27 -0
  76. package/dist/types/src/client/client.d.ts +104 -0
  77. package/dist/types/src/client/client.test.d.ts +1 -0
  78. package/dist/types/src/client/debug/tests/debug.test.d.ts +1 -0
  79. package/dist/types/src/client/manager.d.ts +61 -0
  80. package/dist/types/src/client/react.d.ts +75 -0
  81. package/dist/types/src/client/react.ssr.test.d.ts +4 -0
  82. package/dist/types/src/client/react.test.d.ts +1 -0
  83. package/dist/types/src/client/transport/dummy.d.ts +18 -0
  84. package/dist/types/src/client/transport/local.d.ts +59 -0
  85. package/dist/types/src/client/transport/local.test.d.ts +1 -0
  86. package/dist/types/src/client/transport/socketio.d.ts +45 -0
  87. package/dist/types/src/client/transport/socketio.test.d.ts +1 -0
  88. package/dist/types/src/client/transport/transport.d.ts +50 -0
  89. package/dist/types/src/client/transport/transport.test.d.ts +1 -0
  90. package/dist/types/src/core/action-creators.d.ts +144 -0
  91. package/dist/types/src/core/action-types.d.ts +10 -0
  92. package/dist/types/src/core/backwards-compatibility.d.ts +12 -0
  93. package/dist/types/src/core/constants.d.ts +6 -0
  94. package/dist/types/src/core/errors.d.ts +15 -0
  95. package/dist/types/src/core/flow.d.ts +28 -0
  96. package/dist/types/src/core/flow.test.d.ts +1 -0
  97. package/dist/types/src/core/game-methods.d.ts +9 -0
  98. package/dist/types/src/core/game.d.ts +26 -0
  99. package/dist/types/src/core/game.test.d.ts +1 -0
  100. package/dist/types/src/core/initialize.d.ts +9 -0
  101. package/dist/types/src/core/logger.d.ts +2 -0
  102. package/dist/types/src/core/player-view.d.ts +7 -0
  103. package/dist/types/src/core/player-view.test.d.ts +1 -0
  104. package/dist/types/src/core/reducer.d.ts +155 -0
  105. package/dist/types/src/core/reducer.test.d.ts +1 -0
  106. package/dist/types/src/core/turn-order.d.ts +179 -0
  107. package/dist/types/src/core/turn-order.test.d.ts +8 -0
  108. package/dist/types/src/lobby/client.d.ts +194 -0
  109. package/dist/types/src/lobby/client.test.d.ts +1 -0
  110. package/dist/types/src/lobby/connection.d.ts +44 -0
  111. package/dist/types/src/lobby/connection.test.d.ts +1 -0
  112. package/dist/types/src/lobby/create-match-form.d.ts +26 -0
  113. package/dist/types/src/lobby/login-form.d.ts +23 -0
  114. package/dist/types/src/lobby/match-instance.d.ts +31 -0
  115. package/dist/types/src/lobby/react.d.ts +113 -0
  116. package/dist/types/src/lobby/react.ssr.test.d.ts +4 -0
  117. package/dist/types/src/lobby/react.test.d.ts +1 -0
  118. package/dist/types/src/master/filter-player-view.d.ts +96 -0
  119. package/dist/types/src/master/filter-player-view.test.d.ts +1 -0
  120. package/dist/types/src/master/master.d.ts +94 -0
  121. package/dist/types/src/master/master.test.d.ts +1 -0
  122. package/dist/types/src/plugins/events/events.d.ts +54 -0
  123. package/dist/types/src/plugins/events/events.test.d.ts +1 -0
  124. package/dist/types/src/plugins/main.d.ts +75 -0
  125. package/dist/types/src/plugins/main.test.d.ts +1 -0
  126. package/dist/types/src/plugins/plugin-events.d.ts +5 -0
  127. package/dist/types/src/plugins/plugin-immer.d.ts +7 -0
  128. package/dist/types/src/plugins/plugin-immer.test.d.ts +1 -0
  129. package/dist/types/src/plugins/plugin-log.d.ts +14 -0
  130. package/dist/types/src/plugins/plugin-log.test.d.ts +1 -0
  131. package/dist/types/src/plugins/plugin-player.d.ts +29 -0
  132. package/dist/types/src/plugins/plugin-player.test.d.ts +1 -0
  133. package/dist/types/src/plugins/plugin-random.d.ts +4 -0
  134. package/dist/types/src/plugins/plugin-serializable.d.ts +7 -0
  135. package/dist/types/src/plugins/plugin-serializable.test.d.ts +1 -0
  136. package/dist/types/src/plugins/random/random.alea.d.ts +19 -0
  137. package/dist/types/src/plugins/random/random.d.ts +54 -0
  138. package/dist/types/src/plugins/random/random.test.d.ts +1 -0
  139. package/dist/types/src/server/api.d.ts +13 -0
  140. package/dist/types/src/server/api.test.d.ts +1 -0
  141. package/dist/types/src/server/auth.d.ts +38 -0
  142. package/dist/types/src/server/auth.test.d.ts +1 -0
  143. package/dist/types/src/server/cors.d.ts +4 -0
  144. package/dist/types/src/server/cors.test.d.ts +1 -0
  145. package/dist/types/src/server/db/base.d.ts +192 -0
  146. package/dist/types/src/server/db/flatfile.d.ts +44 -0
  147. package/dist/types/src/server/db/flatfile.test.d.ts +1 -0
  148. package/dist/types/src/server/db/index.d.ts +4 -0
  149. package/dist/types/src/server/db/index.test.d.ts +1 -0
  150. package/dist/types/src/server/db/inmemory.d.ts +43 -0
  151. package/dist/types/src/server/db/inmemory.test.d.ts +1 -0
  152. package/dist/types/src/server/db/localstorage.d.ts +7 -0
  153. package/dist/types/src/server/db/localstorage.test.d.ts +1 -0
  154. package/dist/types/src/server/index.d.ts +68 -0
  155. package/dist/types/src/server/index.test.d.ts +1 -0
  156. package/dist/types/src/server/transport/pubsub/generic-pub-sub.d.ts +6 -0
  157. package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.d.ts +7 -0
  158. package/dist/types/src/server/transport/pubsub/in-memory-pub-sub.test.d.ts +1 -0
  159. package/dist/types/src/server/transport/socketio-simultaneous.test.d.ts +1 -0
  160. package/dist/types/src/server/transport/socketio.d.ts +65 -0
  161. package/dist/types/src/server/transport/socketio.test.d.ts +1 -0
  162. package/dist/types/src/server/util.d.ts +35 -0
  163. package/dist/types/src/testing/mock-random.d.ts +15 -0
  164. package/dist/types/src/testing/mock-random.test.d.ts +1 -0
  165. package/dist/types/src/types.d.ts +387 -0
  166. package/internal/package.json +7 -0
  167. package/master/package.json +7 -0
  168. package/multiplayer/package.json +7 -0
  169. package/package.json +211 -0
  170. package/plugins/package.json +7 -0
  171. package/react/package.json +7 -0
  172. package/react-native/package.json +7 -0
  173. package/server/package.json +6 -0
  174. package/src/ai/ai.test.ts +433 -0
  175. package/src/ai/ai.ts +84 -0
  176. package/src/ai/bot.ts +122 -0
  177. package/src/ai/mcts-bot.ts +331 -0
  178. package/src/ai/random-bot.ts +20 -0
  179. package/src/client/client.test.ts +993 -0
  180. package/src/client/client.ts +588 -0
  181. package/src/client/debug/Debug.svelte +239 -0
  182. package/src/client/debug/Menu.svelte +65 -0
  183. package/src/client/debug/ai/AI.svelte +215 -0
  184. package/src/client/debug/ai/Options.svelte +48 -0
  185. package/src/client/debug/info/Info.svelte +22 -0
  186. package/src/client/debug/info/Item.svelte +24 -0
  187. package/src/client/debug/log/Log.svelte +157 -0
  188. package/src/client/debug/log/LogEvent.svelte +149 -0
  189. package/src/client/debug/log/LogMetadata.svelte +7 -0
  190. package/src/client/debug/log/PhaseMarker.svelte +27 -0
  191. package/src/client/debug/log/TurnMarker.svelte +23 -0
  192. package/src/client/debug/main/ClientSwitcher.svelte +59 -0
  193. package/src/client/debug/main/Controls.svelte +58 -0
  194. package/src/client/debug/main/Hotkey.svelte +84 -0
  195. package/src/client/debug/main/InteractiveFunction.svelte +85 -0
  196. package/src/client/debug/main/Main.svelte +121 -0
  197. package/src/client/debug/main/Move.svelte +68 -0
  198. package/src/client/debug/main/PlayerInfo.svelte +70 -0
  199. package/src/client/debug/mcts/Action.svelte +22 -0
  200. package/src/client/debug/mcts/MCTS.svelte +78 -0
  201. package/src/client/debug/mcts/Table.svelte +98 -0
  202. package/src/client/debug/tests/JSONTree.mock.svelte +3 -0
  203. package/src/client/debug/tests/debug.test.ts +183 -0
  204. package/src/client/debug/utils/shortcuts.js +50 -0
  205. package/src/client/debug/utils/shortcuts.test.js +49 -0
  206. package/src/client/manager.ts +177 -0
  207. package/src/client/react-native.js +136 -0
  208. package/src/client/react-native.test.js +229 -0
  209. package/src/client/react.ssr.test.tsx +24 -0
  210. package/src/client/react.test.tsx +213 -0
  211. package/src/client/react.tsx +192 -0
  212. package/src/client/transport/dummy.ts +19 -0
  213. package/src/client/transport/local.test.ts +353 -0
  214. package/src/client/transport/local.ts +230 -0
  215. package/src/client/transport/socketio.test.ts +328 -0
  216. package/src/client/transport/socketio.ts +210 -0
  217. package/src/client/transport/transport.test.ts +27 -0
  218. package/src/client/transport/transport.ts +95 -0
  219. package/src/core/action-creators.ts +159 -0
  220. package/src/core/action-types.ts +18 -0
  221. package/src/core/backwards-compatibility.ts +23 -0
  222. package/src/core/constants.ts +6 -0
  223. package/src/core/errors.ts +35 -0
  224. package/src/core/flow.test.ts +2433 -0
  225. package/src/core/flow.ts +897 -0
  226. package/src/core/game-methods.ts +9 -0
  227. package/src/core/game.test.ts +286 -0
  228. package/src/core/game.ts +114 -0
  229. package/src/core/initialize.ts +77 -0
  230. package/src/core/logger.test.js +90 -0
  231. package/src/core/logger.ts +18 -0
  232. package/src/core/player-view.test.ts +50 -0
  233. package/src/core/player-view.ts +39 -0
  234. package/src/core/reducer.test.ts +991 -0
  235. package/src/core/reducer.ts +532 -0
  236. package/src/core/turn-order.test.ts +1123 -0
  237. package/src/core/turn-order.ts +473 -0
  238. package/src/lobby/client.test.ts +385 -0
  239. package/src/lobby/client.ts +358 -0
  240. package/src/lobby/connection.test.ts +207 -0
  241. package/src/lobby/connection.ts +162 -0
  242. package/src/lobby/create-match-form.tsx +122 -0
  243. package/src/lobby/login-form.tsx +75 -0
  244. package/src/lobby/match-instance.tsx +135 -0
  245. package/src/lobby/react.ssr.test.tsx +22 -0
  246. package/src/lobby/react.test.tsx +594 -0
  247. package/src/lobby/react.tsx +402 -0
  248. package/src/master/filter-player-view.test.ts +381 -0
  249. package/src/master/filter-player-view.ts +102 -0
  250. package/src/master/master.test.ts +1068 -0
  251. package/src/master/master.ts +492 -0
  252. package/src/plugins/events/events.test.ts +108 -0
  253. package/src/plugins/events/events.ts +209 -0
  254. package/src/plugins/main.test.ts +411 -0
  255. package/src/plugins/main.ts +314 -0
  256. package/src/plugins/plugin-events.ts +40 -0
  257. package/src/plugins/plugin-immer.test.ts +86 -0
  258. package/src/plugins/plugin-immer.ts +37 -0
  259. package/src/plugins/plugin-log.test.ts +37 -0
  260. package/src/plugins/plugin-log.ts +40 -0
  261. package/src/plugins/plugin-player.test.ts +172 -0
  262. package/src/plugins/plugin-player.ts +100 -0
  263. package/src/plugins/plugin-random.ts +40 -0
  264. package/src/plugins/plugin-serializable.test.ts +40 -0
  265. package/src/plugins/plugin-serializable.ts +55 -0
  266. package/src/plugins/random/random.alea.ts +109 -0
  267. package/src/plugins/random/random.test.ts +167 -0
  268. package/src/plugins/random/random.ts +198 -0
  269. package/src/server/api.test.ts +1699 -0
  270. package/src/server/api.ts +527 -0
  271. package/src/server/auth.test.ts +275 -0
  272. package/src/server/auth.ts +89 -0
  273. package/src/server/cors.test.ts +121 -0
  274. package/src/server/cors.ts +7 -0
  275. package/src/server/db/base.ts +296 -0
  276. package/src/server/db/flatfile.test.ts +221 -0
  277. package/src/server/db/flatfile.ts +228 -0
  278. package/src/server/db/index.test.ts +8 -0
  279. package/src/server/db/index.ts +12 -0
  280. package/src/server/db/inmemory.test.ts +143 -0
  281. package/src/server/db/inmemory.ts +143 -0
  282. package/src/server/db/localstorage.test.ts +73 -0
  283. package/src/server/db/localstorage.ts +44 -0
  284. package/src/server/index.test.ts +265 -0
  285. package/src/server/index.ts +175 -0
  286. package/src/server/transport/pubsub/generic-pub-sub.ts +11 -0
  287. package/src/server/transport/pubsub/in-memory-pub-sub.test.ts +47 -0
  288. package/src/server/transport/pubsub/in-memory-pub-sub.ts +28 -0
  289. package/src/server/transport/socketio-simultaneous.test.ts +603 -0
  290. package/src/server/transport/socketio.test.ts +303 -0
  291. package/src/server/transport/socketio.ts +279 -0
  292. package/src/server/util.ts +85 -0
  293. package/src/testing/mock-random.test.ts +45 -0
  294. package/src/testing/mock-random.ts +27 -0
  295. package/src/types.ts +511 -0
  296. 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,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,6 @@
1
+ /**
2
+ * Moves can return this when they want to indicate
3
+ * that the combination of arguments is illegal and
4
+ * the move ought to be discarded.
5
+ */
6
+ export declare const INVALID_MOVE = "INVALID_MOVE";
@@ -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,9 @@
1
+ export declare enum GameMethod {
2
+ MOVE = "MOVE",
3
+ GAME_ON_END = "GAME_ON_END",
4
+ PHASE_ON_BEGIN = "PHASE_ON_BEGIN",
5
+ PHASE_ON_END = "PHASE_ON_END",
6
+ TURN_ON_BEGIN = "TURN_ON_BEGIN",
7
+ TURN_ON_MOVE = "TURN_ON_MOVE",
8
+ TURN_ON_END = "TURN_ON_END"
9
+ }
@@ -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,9 @@
1
+ import type { Game, State } from '../types';
2
+ /**
3
+ * Creates the initial game state.
4
+ */
5
+ export declare function InitializeGame({ game, numPlayers, setupData, }: {
6
+ game: Game;
7
+ numPlayers?: number;
8
+ setupData?: any;
9
+ }): State<any>;
@@ -0,0 +1,2 @@
1
+ export declare function info(msg: string): void;
2
+ export declare function error(error: string): void;
@@ -0,0 +1,7 @@
1
+ import type { Game } from '../types';
2
+ /**
3
+ * PlayerView reducers.
4
+ */
5
+ export declare const PlayerView: {
6
+ STRIP_SECRETS: Game['playerView'];
7
+ };
@@ -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 {};