@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,179 @@
1
+ import type { Ctx, ActivePlayersArg, PlayerID, State, TurnConfig, FnContext } from '../types';
2
+ export declare function SetActivePlayers(ctx: Ctx, arg: ActivePlayersArg): Ctx;
3
+ /**
4
+ * Update activePlayers, setting it to previous, next or null values
5
+ * when it becomes empty.
6
+ * @param ctx
7
+ */
8
+ export declare function UpdateActivePlayersOnceEmpty(ctx: Ctx): {
9
+ activePlayers: import("../types").ActivePlayers;
10
+ _activePlayersMinMoves: Record<string, number>;
11
+ _activePlayersMaxMoves: Record<string, number>;
12
+ _activePlayersNumMoves: Record<string, number>;
13
+ _prevActivePlayers: {
14
+ activePlayers: import("../types").ActivePlayers;
15
+ _activePlayersMinMoves?: Record<string, number>;
16
+ _activePlayersMaxMoves?: Record<string, number>;
17
+ _activePlayersNumMoves?: Record<string, number>;
18
+ }[];
19
+ numPlayers: number;
20
+ playOrder: string[];
21
+ playOrderPos: number;
22
+ currentPlayer: string;
23
+ numMoves?: number;
24
+ gameover?: any;
25
+ turn: number;
26
+ phase: string;
27
+ _nextActivePlayers?: ActivePlayersArg;
28
+ _random?: {
29
+ seed: string | number;
30
+ };
31
+ };
32
+ /**
33
+ * Called at the start of a turn to initialize turn order state.
34
+ *
35
+ * TODO: This is called inside StartTurn, which is called from
36
+ * both UpdateTurn and StartPhase (so it's called at the beginning
37
+ * of a new phase as well as between turns). We should probably
38
+ * split it into two.
39
+ */
40
+ export declare function InitTurnOrderState(state: State, turn: TurnConfig): Ctx;
41
+ /**
42
+ * Called at the end of each turn to update the turn order state.
43
+ * @param {object} G - The game object G.
44
+ * @param {object} ctx - The game object ctx.
45
+ * @param {object} turn - A turn object for this phase.
46
+ * @param {string} endTurnArg - An optional argument to endTurn that
47
+ may specify the next player.
48
+ */
49
+ export declare function UpdateTurnOrderState(state: State, currentPlayer: PlayerID, turn: TurnConfig, endTurnArg?: true | {
50
+ remove?: any;
51
+ next?: string;
52
+ }): {
53
+ endPhase: boolean;
54
+ ctx: Ctx;
55
+ };
56
+ /**
57
+ * Set of different turn orders possible in a phase.
58
+ * These are meant to be passed to the `turn` setting
59
+ * in the flow objects.
60
+ *
61
+ * Each object defines the first player when the phase / game
62
+ * begins, and also a function `next` to determine who the
63
+ * next player is when the turn ends.
64
+ *
65
+ * The phase ends if next() returns undefined.
66
+ */
67
+ export declare const TurnOrder: {
68
+ /**
69
+ * DEFAULT
70
+ *
71
+ * The default round-robin turn order.
72
+ */
73
+ DEFAULT: {
74
+ first: ({ ctx }: FnContext) => number;
75
+ next: ({ ctx }: FnContext) => number;
76
+ };
77
+ /**
78
+ * RESET
79
+ *
80
+ * Similar to DEFAULT, but starts from 0 each time.
81
+ */
82
+ RESET: {
83
+ first: () => number;
84
+ next: ({ ctx }: FnContext) => number;
85
+ };
86
+ /**
87
+ * CONTINUE
88
+ *
89
+ * Similar to DEFAULT, but starts with the player who ended the last phase.
90
+ */
91
+ CONTINUE: {
92
+ first: ({ ctx }: FnContext) => number;
93
+ next: ({ ctx }: FnContext) => number;
94
+ };
95
+ /**
96
+ * ONCE
97
+ *
98
+ * Another round-robin turn order, but goes around just once.
99
+ * The phase ends after all players have played.
100
+ */
101
+ ONCE: {
102
+ first: () => number;
103
+ next: ({ ctx }: FnContext) => number;
104
+ };
105
+ /**
106
+ * CUSTOM
107
+ *
108
+ * Identical to DEFAULT, but also sets playOrder at the
109
+ * beginning of the phase.
110
+ *
111
+ * @param {Array} playOrder - The play order.
112
+ */
113
+ CUSTOM: (playOrder: string[]) => {
114
+ playOrder: () => string[];
115
+ first: () => number;
116
+ next: ({ ctx }: FnContext) => number;
117
+ };
118
+ /**
119
+ * CUSTOM_FROM
120
+ *
121
+ * Identical to DEFAULT, but also sets playOrder at the
122
+ * beginning of the phase to a value specified by a field
123
+ * in G.
124
+ *
125
+ * @param {string} playOrderField - Field in G.
126
+ */
127
+ CUSTOM_FROM: (playOrderField: string) => {
128
+ playOrder: ({ G }: FnContext) => any;
129
+ first: () => number;
130
+ next: ({ ctx }: FnContext) => number;
131
+ };
132
+ };
133
+ export declare const Stage: {
134
+ NULL: any;
135
+ };
136
+ export declare const ActivePlayers: {
137
+ /**
138
+ * ALL
139
+ *
140
+ * The turn stays with one player, but any player can play (in any order)
141
+ * until the phase ends.
142
+ */
143
+ ALL: {
144
+ all: any;
145
+ };
146
+ /**
147
+ * ALL_ONCE
148
+ *
149
+ * The turn stays with one player, but any player can play (once, and in any order).
150
+ * This is typically used in a phase where you want to elicit a response
151
+ * from every player in the game.
152
+ */
153
+ ALL_ONCE: {
154
+ all: any;
155
+ minMoves: number;
156
+ maxMoves: number;
157
+ };
158
+ /**
159
+ * OTHERS
160
+ *
161
+ * The turn stays with one player, and every *other* player can play (in any order)
162
+ * until the phase ends.
163
+ */
164
+ OTHERS: {
165
+ others: any;
166
+ };
167
+ /**
168
+ * OTHERS_ONCE
169
+ *
170
+ * The turn stays with one player, and every *other* player can play (once, and in any order).
171
+ * This is typically used in a phase where you want to elicit a response
172
+ * from every *other* player in the game.
173
+ */
174
+ OTHERS_ONCE: {
175
+ others: any;
176
+ minMoves: number;
177
+ maxMoves: number;
178
+ };
179
+ };
@@ -0,0 +1,8 @@
1
+ declare global {
2
+ namespace jest {
3
+ interface Matchers<R> {
4
+ toHaveUndefinedProperties(): R;
5
+ }
6
+ }
7
+ }
8
+ export {};
@@ -0,0 +1,194 @@
1
+ import type { LobbyAPI } from '../types';
2
+ export declare class LobbyClientError extends Error {
3
+ readonly details: any;
4
+ constructor(message: string, details: any);
5
+ }
6
+ /**
7
+ * Create a boardgame.io Lobby API client.
8
+ * @param server The API’s base URL, e.g. `http://localhost:8000`.
9
+ */
10
+ export declare class LobbyClient {
11
+ private server;
12
+ constructor({ server }?: {
13
+ server?: string;
14
+ });
15
+ private request;
16
+ private post;
17
+ /**
18
+ * Get a list of the game names available on this server.
19
+ * @param init Optional RequestInit interface to override defaults.
20
+ * @return Array of game names.
21
+ *
22
+ * @example
23
+ * lobbyClient.listGames()
24
+ * .then(console.log); // => ['chess', 'tic-tac-toe']
25
+ */
26
+ listGames(init?: RequestInit): Promise<string[]>;
27
+ /**
28
+ * Get a list of the matches for a specific game type on the server.
29
+ * @param gameName The game to list for, e.g. 'tic-tac-toe'.
30
+ * @param where Options to filter matches by update time or gameover state
31
+ * @param init Optional RequestInit interface to override defaults.
32
+ * @return Array of match metadata objects.
33
+ *
34
+ * @example
35
+ * lobbyClient.listMatches('tic-tac-toe', where: { isGameover: false })
36
+ * .then(data => console.log(data.matches));
37
+ * // => [
38
+ * // {
39
+ * // matchID: 'xyz',
40
+ * // gameName: 'tic-tac-toe',
41
+ * // players: [{ id: 0, name: 'Alice' }, { id: 1 }]
42
+ * // },
43
+ * // ...
44
+ * // ]
45
+ */
46
+ listMatches(gameName: string, where?: {
47
+ /**
48
+ * If true, only games that have ended will be returned.
49
+ * If false, only games that have not yet ended will be returned.
50
+ * Leave undefined to receive both finished and unfinished games.
51
+ */
52
+ isGameover?: boolean;
53
+ /**
54
+ * List matches last updated before a specific time.
55
+ * Value should be a timestamp in milliseconds after January 1, 1970.
56
+ */
57
+ updatedBefore?: number;
58
+ /**
59
+ * List matches last updated after a specific time.
60
+ * Value should be a timestamp in milliseconds after January 1, 1970.
61
+ */
62
+ updatedAfter?: number;
63
+ }, init?: RequestInit): Promise<LobbyAPI.MatchList>;
64
+ /**
65
+ * Get metadata for a specific match.
66
+ * @param gameName The match’s game type, e.g. 'tic-tac-toe'.
67
+ * @param matchID Match ID for the match to fetch.
68
+ * @param init Optional RequestInit interface to override defaults.
69
+ * @return A match metadata object.
70
+ *
71
+ * @example
72
+ * lobbyClient.getMatch('tic-tac-toe', 'xyz').then(console.log);
73
+ * // => {
74
+ * // matchID: 'xyz',
75
+ * // gameName: 'tic-tac-toe',
76
+ * // players: [{ id: 0, name: 'Alice' }, { id: 1 }]
77
+ * // }
78
+ */
79
+ getMatch(gameName: string, matchID: string, init?: RequestInit): Promise<LobbyAPI.Match>;
80
+ /**
81
+ * Create a new match for a specific game type.
82
+ * @param gameName The game to create a match for, e.g. 'tic-tac-toe'.
83
+ * @param body Options required to configure match creation.
84
+ * @param init Optional RequestInit interface to override defaults.
85
+ * @return An object containing the created `matchID`.
86
+ *
87
+ * @example
88
+ * lobbyClient.createMatch('tic-tac-toe', { numPlayers: 2 })
89
+ * .then(console.log);
90
+ * // => { matchID: 'xyz' }
91
+ */
92
+ createMatch(gameName: string, body: {
93
+ numPlayers: number;
94
+ setupData?: any;
95
+ unlisted?: boolean;
96
+ [key: string]: any;
97
+ }, init?: RequestInit): Promise<LobbyAPI.CreatedMatch>;
98
+ /**
99
+ * Join a match using its matchID.
100
+ * @param gameName The match’s game type, e.g. 'tic-tac-toe'.
101
+ * @param matchID Match ID for the match to join.
102
+ * @param body Options required to join match.
103
+ * @param init Optional RequestInit interface to override defaults.
104
+ * @return Object containing `playerCredentials` for the player who joined.
105
+ *
106
+ * @example
107
+ * lobbyClient.joinMatch('tic-tac-toe', 'xyz', {
108
+ * playerID: '1',
109
+ * playerName: 'Bob',
110
+ * }).then(console.log);
111
+ * // => { playerID: '1', playerCredentials: 'random-string' }
112
+ */
113
+ joinMatch(gameName: string, matchID: string, body: {
114
+ playerID?: string;
115
+ playerName: string;
116
+ data?: any;
117
+ [key: string]: any;
118
+ }, init?: RequestInit): Promise<LobbyAPI.JoinedMatch>;
119
+ /**
120
+ * Leave a previously joined match.
121
+ * @param gameName The match’s game type, e.g. 'tic-tac-toe'.
122
+ * @param matchID Match ID for the match to leave.
123
+ * @param body Options required to leave match.
124
+ * @param init Optional RequestInit interface to override defaults.
125
+ * @return Promise resolves if successful.
126
+ *
127
+ * @example
128
+ * lobbyClient.leaveMatch('tic-tac-toe', 'xyz', {
129
+ * playerID: '1',
130
+ * credentials: 'credentials-returned-when-joining',
131
+ * })
132
+ * .then(() => console.log('Left match.'))
133
+ * .catch(error => console.error('Error leaving match', error));
134
+ */
135
+ leaveMatch(gameName: string, matchID: string, body: {
136
+ playerID: string;
137
+ credentials: string;
138
+ [key: string]: any;
139
+ }, init?: RequestInit): Promise<void>;
140
+ /**
141
+ * Update a player’s name or custom metadata.
142
+ * @param gameName The match’s game type, e.g. 'tic-tac-toe'.
143
+ * @param matchID Match ID for the match to update.
144
+ * @param body Options required to update player.
145
+ * @param init Optional RequestInit interface to override defaults.
146
+ * @return Promise resolves if successful.
147
+ *
148
+ * @example
149
+ * lobbyClient.updatePlayer('tic-tac-toe', 'xyz', {
150
+ * playerID: '0',
151
+ * credentials: 'credentials-returned-when-joining',
152
+ * newName: 'Al',
153
+ * })
154
+ * .then(() => console.log('Updated player data.'))
155
+ * .catch(error => console.error('Error updating data', error));
156
+ */
157
+ updatePlayer(gameName: string, matchID: string, body: {
158
+ playerID: string;
159
+ credentials: string;
160
+ newName?: string;
161
+ data?: any;
162
+ [key: string]: any;
163
+ }, init?: RequestInit): Promise<void>;
164
+ /**
165
+ * Create a new match based on the configuration of the current match.
166
+ * @param gameName The match’s game type, e.g. 'tic-tac-toe'.
167
+ * @param matchID Match ID for the match to play again.
168
+ * @param body Options required to configure match.
169
+ * @param init Optional RequestInit interface to override defaults.
170
+ * @return Object containing `nextMatchID`.
171
+ *
172
+ * @example
173
+ * lobbyClient.playAgain('tic-tac-toe', 'xyz', {
174
+ * playerID: '0',
175
+ * credentials: 'credentials-returned-when-joining',
176
+ * })
177
+ * .then(({ nextMatchID }) => {
178
+ * return lobbyClient.joinMatch('tic-tac-toe', nextMatchID, {
179
+ * playerID: '0',
180
+ * playerName: 'Al',
181
+ * })
182
+ * })
183
+ * .then({ playerCredentials } => {
184
+ * console.log(playerCredentials);
185
+ * })
186
+ * .catch(console.error);
187
+ */
188
+ playAgain(gameName: string, matchID: string, body: {
189
+ playerID: string;
190
+ credentials: string;
191
+ unlisted?: boolean;
192
+ [key: string]: any;
193
+ }, init?: RequestInit): Promise<LobbyAPI.NextMatch>;
194
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import type { ComponentType } from 'react';
2
+ import { LobbyClient } from './client';
3
+ import type { Game, LobbyAPI } from '../types';
4
+ export interface GameComponent {
5
+ game: Game;
6
+ board: ComponentType<any>;
7
+ }
8
+ interface LobbyConnectionOpts {
9
+ server: string;
10
+ playerName?: string;
11
+ playerCredentials?: string;
12
+ gameComponents: GameComponent[];
13
+ }
14
+ declare class _LobbyConnectionImpl {
15
+ client: LobbyClient;
16
+ gameComponents: GameComponent[];
17
+ playerName: string;
18
+ playerCredentials?: string;
19
+ matches: LobbyAPI.MatchList['matches'];
20
+ constructor({ server, gameComponents, playerName, playerCredentials, }: LobbyConnectionOpts);
21
+ refresh(): Promise<void>;
22
+ _getMatchInstance(matchID: string): LobbyAPI.Match;
23
+ _getGameComponents(gameName: string): GameComponent;
24
+ _findPlayer(playerName: string): LobbyAPI.Match;
25
+ join(gameName: string, matchID: string, playerID: string): Promise<void>;
26
+ leave(gameName: string, matchID: string): Promise<void>;
27
+ disconnect(): Promise<void>;
28
+ create(gameName: string, numPlayers: number): Promise<void>;
29
+ }
30
+ /**
31
+ * LobbyConnection
32
+ *
33
+ * Lobby model.
34
+ *
35
+ * @param {string} server - '<host>:<port>' of the server.
36
+ * @param {Array} gameComponents - A map of Board and Game objects for the supported games.
37
+ * @param {string} playerName - The name of the player.
38
+ * @param {string} playerCredentials - The credentials currently used by the player, if any.
39
+ *
40
+ * Returns:
41
+ * A JS object that synchronizes the list of running game instances with the server and provides an API to create/join/start instances.
42
+ */
43
+ export declare function LobbyConnection(opts: LobbyConnectionOpts): _LobbyConnectionImpl;
44
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import type { Game } from '../types';
3
+ import type { GameComponent } from './connection';
4
+ declare type CreateMatchProps = {
5
+ games: GameComponent[];
6
+ createMatch: (gameName: string, numPlayers: number) => Promise<void>;
7
+ };
8
+ declare type CreateMatchState = {
9
+ selectedGame: number;
10
+ numPlayers: number;
11
+ };
12
+ declare class LobbyCreateMatchForm extends React.Component<CreateMatchProps, CreateMatchState> {
13
+ state: {
14
+ selectedGame: number;
15
+ numPlayers: number;
16
+ };
17
+ constructor(props: CreateMatchProps);
18
+ _createGameNameOption: (game: GameComponent, idx: number) => JSX.Element;
19
+ _createNumPlayersOption: (idx: number) => JSX.Element;
20
+ _createNumPlayersRange: (game: Game) => number[];
21
+ render(): JSX.Element;
22
+ onChangeNumPlayers: (event: React.ChangeEvent<HTMLSelectElement>) => void;
23
+ onChangeSelectedGame: (event: React.ChangeEvent<HTMLSelectElement>) => void;
24
+ onClickCreate: () => void;
25
+ }
26
+ export default LobbyCreateMatchForm;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ declare type LoginFormProps = {
3
+ playerName?: string;
4
+ onEnter: (playerName: string) => void;
5
+ };
6
+ declare type LoginFormState = {
7
+ playerName?: string;
8
+ nameErrorMsg: string;
9
+ };
10
+ declare class LobbyLoginForm extends React.Component<LoginFormProps, LoginFormState> {
11
+ static defaultProps: {
12
+ playerName: string;
13
+ };
14
+ state: {
15
+ playerName: string;
16
+ nameErrorMsg: string;
17
+ };
18
+ render(): JSX.Element;
19
+ onClickEnter: () => void;
20
+ onKeyPress: (event: React.KeyboardEvent<HTMLInputElement>) => void;
21
+ onChangePlayerName: (event: React.ChangeEvent<HTMLInputElement>) => void;
22
+ }
23
+ export default LobbyLoginForm;
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ import type { LobbyAPI } from '../types';
3
+ export declare type MatchOpts = {
4
+ numPlayers: number;
5
+ matchID: string;
6
+ playerID?: string;
7
+ };
8
+ declare type Match = {
9
+ gameName: string;
10
+ matchID: string;
11
+ players: LobbyAPI.Match['players'];
12
+ };
13
+ declare type MatchInstanceProps = {
14
+ match: Match;
15
+ playerName: string;
16
+ onClickJoin: (gameName: string, matchID: string, playerID: string) => void;
17
+ onClickLeave: (gameName: string, matchID: string) => void;
18
+ onClickPlay: (gameName: string, matchOpts: MatchOpts) => void;
19
+ };
20
+ declare class LobbyMatchInstance extends React.Component<MatchInstanceProps> {
21
+ _createSeat: (player: {
22
+ name?: string;
23
+ }) => string;
24
+ _createButtonJoin: (inst: Match, seatId: number) => JSX.Element;
25
+ _createButtonLeave: (inst: Match) => JSX.Element;
26
+ _createButtonPlay: (inst: Match, seatId: number) => JSX.Element;
27
+ _createButtonSpectate: (inst: Match) => JSX.Element;
28
+ _createInstanceButtons: (inst: Match) => JSX.Element;
29
+ render(): JSX.Element;
30
+ }
31
+ export default LobbyMatchInstance;
@@ -0,0 +1,113 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import type { DebugOpt } from '../client/client';
4
+ import { Client } from '../client/react';
5
+ import type { GameComponent } from './connection';
6
+ import type { MatchOpts } from './match-instance';
7
+ import type { LobbyAPI } from '../types';
8
+ declare enum LobbyPhases {
9
+ ENTER = "enter",
10
+ PLAY = "play",
11
+ LIST = "list"
12
+ }
13
+ declare type RunningMatch = {
14
+ app: ReturnType<typeof Client>;
15
+ matchID: string;
16
+ playerID: string;
17
+ credentials?: string;
18
+ };
19
+ declare type LobbyProps = {
20
+ gameComponents: GameComponent[];
21
+ lobbyServer?: string;
22
+ gameServer?: string;
23
+ debug?: DebugOpt | boolean;
24
+ clientFactory?: typeof Client;
25
+ refreshInterval?: number;
26
+ renderer?: (args: {
27
+ errorMsg: string;
28
+ gameComponents: GameComponent[];
29
+ matches: LobbyAPI.MatchList['matches'];
30
+ phase: LobbyPhases;
31
+ playerName: string;
32
+ runningMatch?: RunningMatch;
33
+ handleEnterLobby: (playerName: string) => void;
34
+ handleExitLobby: () => Promise<void>;
35
+ handleCreateMatch: (gameName: string, numPlayers: number) => Promise<void>;
36
+ handleJoinMatch: (gameName: string, matchID: string, playerID: string) => Promise<void>;
37
+ handleLeaveMatch: (gameName: string, matchID: string) => Promise<void>;
38
+ handleExitMatch: () => void;
39
+ handleRefreshMatches: () => Promise<void>;
40
+ handleStartMatch: (gameName: string, matchOpts: MatchOpts) => void;
41
+ }) => JSX.Element;
42
+ };
43
+ declare type LobbyState = {
44
+ phase: LobbyPhases;
45
+ playerName: string;
46
+ runningMatch?: RunningMatch;
47
+ errorMsg: string;
48
+ credentialStore?: {
49
+ [playerName: string]: string;
50
+ };
51
+ };
52
+ /**
53
+ * Lobby
54
+ *
55
+ * React lobby component.
56
+ *
57
+ * @param {Array} gameComponents - An array of Board and Game objects for the supported games.
58
+ * @param {string} lobbyServer - Address of the lobby server (for example 'localhost:8000').
59
+ * If not set, defaults to the server that served the page.
60
+ * @param {string} gameServer - Address of the game server (for example 'localhost:8001').
61
+ * If not set, defaults to the server that served the page.
62
+ * @param {function} clientFactory - Function that is used to create the game clients.
63
+ * @param {number} refreshInterval - Interval between server updates (default: 2000ms).
64
+ * @param {bool} debug - Enable debug information (default: false).
65
+ *
66
+ * Returns:
67
+ * A React component that provides a UI to create, list, join, leave, play or
68
+ * spectate matches (game instances).
69
+ */
70
+ declare class Lobby extends React.Component<LobbyProps, LobbyState> {
71
+ static propTypes: {
72
+ gameComponents: PropTypes.Validator<any[]>;
73
+ lobbyServer: PropTypes.Requireable<string>;
74
+ gameServer: PropTypes.Requireable<string>;
75
+ debug: PropTypes.Requireable<boolean>;
76
+ clientFactory: PropTypes.Requireable<(...args: any[]) => any>;
77
+ refreshInterval: PropTypes.Requireable<number>;
78
+ };
79
+ static defaultProps: {
80
+ debug: boolean;
81
+ clientFactory: typeof Client;
82
+ refreshInterval: number;
83
+ };
84
+ state: {
85
+ phase: LobbyPhases;
86
+ playerName: string;
87
+ runningMatch: any;
88
+ errorMsg: string;
89
+ credentialStore: {};
90
+ };
91
+ private connection?;
92
+ private _currentInterval?;
93
+ constructor(props: LobbyProps);
94
+ componentDidMount(): void;
95
+ componentDidUpdate(prevProps: LobbyProps, prevState: LobbyState): void;
96
+ componentWillUnmount(): void;
97
+ _startRefreshInterval(): void;
98
+ _clearRefreshInterval(): void;
99
+ _createConnection: (props: LobbyProps) => void;
100
+ _updateCredentials: (playerName: string, credentials: string) => void;
101
+ _updateConnection: () => Promise<void>;
102
+ _enterLobby: (playerName: string) => void;
103
+ _exitLobby: () => Promise<void>;
104
+ _createMatch: (gameName: string, numPlayers: number) => Promise<void>;
105
+ _joinMatch: (gameName: string, matchID: string, playerID: string) => Promise<void>;
106
+ _leaveMatch: (gameName: string, matchID: string) => Promise<void>;
107
+ _startMatch: (gameName: string, matchOpts: MatchOpts) => void;
108
+ _exitMatch: () => void;
109
+ _getPhaseVisibility: (phase: LobbyPhases) => "hidden" | "phase";
110
+ renderMatches: (matches: LobbyAPI.MatchList['matches'], playerName: string) => JSX.Element[];
111
+ render(): JSX.Element;
112
+ }
113
+ export default Lobby;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ export {};
@@ -0,0 +1 @@
1
+ export {};