@pretty-chitty/core 1.2.18 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) hide show
  1. package/README.md +8 -0
  2. package/dist/components/ActionLogDisplay.d.ts.map +1 -1
  3. package/dist/components/ActionLogDisplay.js +1 -1
  4. package/dist/components/ActionLogDisplay.js.map +1 -1
  5. package/dist/components/BottomBarButton.d.ts +3 -1
  6. package/dist/components/BottomBarButton.d.ts.map +1 -1
  7. package/dist/components/BottomBarButton.js +3 -2
  8. package/dist/components/BottomBarButton.js.map +1 -1
  9. package/dist/components/ClientTrustMatchViewer.d.ts +14 -1
  10. package/dist/components/ClientTrustMatchViewer.d.ts.map +1 -1
  11. package/dist/components/ClientTrustMatchViewer.js +25 -2
  12. package/dist/components/ClientTrustMatchViewer.js.map +1 -1
  13. package/dist/components/ContextGalleryDisplay.d.ts.map +1 -1
  14. package/dist/components/ContextGalleryDisplay.js +1 -1
  15. package/dist/components/ContextGalleryDisplay.js.map +1 -1
  16. package/dist/components/DemoWrapper.d.ts +30 -2
  17. package/dist/components/DemoWrapper.d.ts.map +1 -1
  18. package/dist/components/DemoWrapper.js +79 -43
  19. package/dist/components/DemoWrapper.js.map +1 -1
  20. package/dist/components/FullScreenGalleryDisplay.d.ts.map +1 -1
  21. package/dist/components/FullScreenGalleryDisplay.js +2 -2
  22. package/dist/components/FullScreenGalleryDisplay.js.map +1 -1
  23. package/dist/components/Gallery/BuiltItem.d.ts +6 -2
  24. package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
  25. package/dist/components/Gallery/BuiltItem.js +31 -9
  26. package/dist/components/Gallery/BuiltItem.js.map +1 -1
  27. package/dist/components/Gallery/GalleryController.d.ts +18 -0
  28. package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
  29. package/dist/components/Gallery/GalleryController.js +70 -1
  30. package/dist/components/Gallery/GalleryController.js.map +1 -1
  31. package/dist/components/Gallery/GalleryViewer.d.ts +6 -1
  32. package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -1
  33. package/dist/components/Gallery/GalleryViewer.js +48 -10
  34. package/dist/components/Gallery/GalleryViewer.js.map +1 -1
  35. package/dist/components/Gallery/LayoutManager.d.ts +6 -0
  36. package/dist/components/Gallery/LayoutManager.d.ts.map +1 -1
  37. package/dist/components/Gallery/LayoutManager.js +23 -3
  38. package/dist/components/Gallery/LayoutManager.js.map +1 -1
  39. package/dist/components/Gallery/constants.d.ts +2 -0
  40. package/dist/components/Gallery/constants.d.ts.map +1 -1
  41. package/dist/components/Gallery/constants.js +2 -0
  42. package/dist/components/Gallery/constants.js.map +1 -1
  43. package/dist/components/Gallery/registry.d.ts +34 -0
  44. package/dist/components/Gallery/registry.d.ts.map +1 -0
  45. package/dist/components/Gallery/registry.js +17 -0
  46. package/dist/components/Gallery/registry.js.map +1 -0
  47. package/dist/components/GameDesigner.d.ts.map +1 -1
  48. package/dist/components/GameDesigner.js +42 -10
  49. package/dist/components/GameDesigner.js.map +1 -1
  50. package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
  51. package/dist/components/InlineGalleryDisplay.js +2 -2
  52. package/dist/components/InlineGalleryDisplay.js.map +1 -1
  53. package/dist/components/LiveButton.d.ts.map +1 -1
  54. package/dist/components/LiveButton.js +5 -2
  55. package/dist/components/LiveButton.js.map +1 -1
  56. package/dist/components/MatchViewer.d.ts +6 -1
  57. package/dist/components/MatchViewer.d.ts.map +1 -1
  58. package/dist/components/MatchViewer.js +9 -3
  59. package/dist/components/MatchViewer.js.map +1 -1
  60. package/dist/components/Panel/MultiPanel.d.ts.map +1 -1
  61. package/dist/components/Panel/MultiPanel.js +18 -0
  62. package/dist/components/Panel/MultiPanel.js.map +1 -1
  63. package/dist/components/Panel/PanelContents.d.ts.map +1 -1
  64. package/dist/components/Panel/PanelContents.js +92 -23
  65. package/dist/components/Panel/PanelContents.js.map +1 -1
  66. package/dist/components/Panel/PanelTabStack.d.ts.map +1 -1
  67. package/dist/components/Panel/PanelTabStack.js +1 -1
  68. package/dist/components/Panel/PanelTabStack.js.map +1 -1
  69. package/dist/components/PanelSpark.d.ts.map +1 -1
  70. package/dist/components/PanelSpark.js +3 -2
  71. package/dist/components/PanelSpark.js.map +1 -1
  72. package/dist/components/Playground.d.ts.map +1 -1
  73. package/dist/components/Playground.js +46 -14
  74. package/dist/components/Playground.js.map +1 -1
  75. package/dist/components/PromptControls.d.ts.map +1 -1
  76. package/dist/components/PromptControls.js +4 -2
  77. package/dist/components/PromptControls.js.map +1 -1
  78. package/dist/components/SparkLineChart.d.ts.map +1 -1
  79. package/dist/components/SparkLineChart.js +22 -26
  80. package/dist/components/SparkLineChart.js.map +1 -1
  81. package/dist/components/TimeControlBar.d.ts.map +1 -1
  82. package/dist/components/TimeControlBar.js +5 -3
  83. package/dist/components/TimeControlBar.js.map +1 -1
  84. package/dist/components/TokenizedMarkdown.d.ts +23 -0
  85. package/dist/components/TokenizedMarkdown.d.ts.map +1 -0
  86. package/dist/components/TokenizedMarkdown.js +144 -0
  87. package/dist/components/TokenizedMarkdown.js.map +1 -0
  88. package/dist/components/TokenizedMessage.d.ts +8 -6
  89. package/dist/components/TokenizedMessage.d.ts.map +1 -1
  90. package/dist/components/TokenizedMessage.js +21 -54
  91. package/dist/components/TokenizedMessage.js.map +1 -1
  92. package/dist/components/TopBarPlayers.d.ts.map +1 -1
  93. package/dist/components/TopBarPlayers.js +2 -2
  94. package/dist/components/TopBarPlayers.js.map +1 -1
  95. package/dist/components/Tutorial/BrowserNarration.d.ts +55 -0
  96. package/dist/components/Tutorial/BrowserNarration.d.ts.map +1 -0
  97. package/dist/components/Tutorial/BrowserNarration.js +240 -0
  98. package/dist/components/Tutorial/BrowserNarration.js.map +1 -0
  99. package/dist/components/Tutorial/TutorialBox.d.ts +26 -0
  100. package/dist/components/Tutorial/TutorialBox.d.ts.map +1 -0
  101. package/dist/components/Tutorial/TutorialBox.js +239 -0
  102. package/dist/components/Tutorial/TutorialBox.js.map +1 -0
  103. package/dist/components/Tutorial/TutorialDevPanel.d.ts +9 -0
  104. package/dist/components/Tutorial/TutorialDevPanel.d.ts.map +1 -0
  105. package/dist/components/Tutorial/TutorialDevPanel.js +92 -0
  106. package/dist/components/Tutorial/TutorialDevPanel.js.map +1 -0
  107. package/dist/components/Tutorial/TutorialOverlay.d.ts +7 -0
  108. package/dist/components/Tutorial/TutorialOverlay.d.ts.map +1 -0
  109. package/dist/components/Tutorial/TutorialOverlay.js +1132 -0
  110. package/dist/components/Tutorial/TutorialOverlay.js.map +1 -0
  111. package/dist/components/Tutorial/targetRects.d.ts +67 -0
  112. package/dist/components/Tutorial/targetRects.d.ts.map +1 -0
  113. package/dist/components/Tutorial/targetRects.js +241 -0
  114. package/dist/components/Tutorial/targetRects.js.map +1 -0
  115. package/dist/game/Chit.d.ts +7 -0
  116. package/dist/game/Chit.d.ts.map +1 -1
  117. package/dist/game/Chit.js +22 -7
  118. package/dist/game/Chit.js.map +1 -1
  119. package/dist/game/ClientTimeState.d.ts +14 -0
  120. package/dist/game/ClientTimeState.d.ts.map +1 -1
  121. package/dist/game/ClientTimeState.js +17 -0
  122. package/dist/game/ClientTimeState.js.map +1 -1
  123. package/dist/game/ConnectionTransport.d.ts +3 -0
  124. package/dist/game/ConnectionTransport.d.ts.map +1 -1
  125. package/dist/game/ConnectionTransport.js +13 -4
  126. package/dist/game/ConnectionTransport.js.map +1 -1
  127. package/dist/game/Game.d.ts +14 -1
  128. package/dist/game/Game.d.ts.map +1 -1
  129. package/dist/game/GameTheme.d.ts +3 -0
  130. package/dist/game/GameTheme.d.ts.map +1 -1
  131. package/dist/game/GameTheme.js +2 -0
  132. package/dist/game/GameTheme.js.map +1 -1
  133. package/dist/game/Match.d.ts +74 -2
  134. package/dist/game/Match.d.ts.map +1 -1
  135. package/dist/game/Match.js +155 -4
  136. package/dist/game/Match.js.map +1 -1
  137. package/dist/game/MatchStorage.d.ts +8 -1
  138. package/dist/game/MatchStorage.d.ts.map +1 -1
  139. package/dist/game/MatchStorage.js +11 -3
  140. package/dist/game/MatchStorage.js.map +1 -1
  141. package/dist/game/Pick.d.ts +16 -0
  142. package/dist/game/Pick.d.ts.map +1 -1
  143. package/dist/game/Pick.js +32 -1
  144. package/dist/game/Pick.js.map +1 -1
  145. package/dist/game/PlayerChit.d.ts +3 -0
  146. package/dist/game/PlayerChit.d.ts.map +1 -1
  147. package/dist/game/PlayerChit.js +3 -0
  148. package/dist/game/PlayerChit.js.map +1 -1
  149. package/dist/game/PlayerInfo.d.ts +8 -0
  150. package/dist/game/PlayerInfo.d.ts.map +1 -1
  151. package/dist/game/PlayerInfo.js +6 -3
  152. package/dist/game/PlayerInfo.js.map +1 -1
  153. package/dist/game/PlayerPromptStatusChit.d.ts +8 -0
  154. package/dist/game/PlayerPromptStatusChit.d.ts.map +1 -1
  155. package/dist/game/PlayerPromptStatusChit.js +8 -2
  156. package/dist/game/PlayerPromptStatusChit.js.map +1 -1
  157. package/dist/game/Prompt.d.ts +15 -0
  158. package/dist/game/Prompt.d.ts.map +1 -1
  159. package/dist/game/Prompt.js +16 -0
  160. package/dist/game/Prompt.js.map +1 -1
  161. package/dist/game/Turn.d.ts +20 -4
  162. package/dist/game/Turn.d.ts.map +1 -1
  163. package/dist/game/Turn.js +191 -67
  164. package/dist/game/Turn.js.map +1 -1
  165. package/dist/game/TurnState.d.ts +20 -1
  166. package/dist/game/TurnState.d.ts.map +1 -1
  167. package/dist/game/TurnState.js +22 -3
  168. package/dist/game/TurnState.js.map +1 -1
  169. package/dist/game/ai/AiClientPrompts.d.ts +177 -0
  170. package/dist/game/ai/AiClientPrompts.d.ts.map +1 -0
  171. package/dist/game/ai/AiClientPrompts.js +561 -0
  172. package/dist/game/ai/AiClientPrompts.js.map +1 -0
  173. package/dist/game/ai/AiLiveView.d.ts +2 -0
  174. package/dist/game/ai/AiLiveView.d.ts.map +1 -0
  175. package/dist/game/ai/AiLiveView.js +48 -0
  176. package/dist/game/ai/AiLiveView.js.map +1 -0
  177. package/dist/game/ai/AiPlayerView.d.ts +2 -0
  178. package/dist/game/ai/AiPlayerView.d.ts.map +1 -0
  179. package/dist/game/ai/AiPlayerView.js +91 -0
  180. package/dist/game/ai/AiPlayerView.js.map +1 -0
  181. package/dist/game/ai/connectAiPlayer.d.ts +43 -0
  182. package/dist/game/ai/connectAiPlayer.d.ts.map +1 -0
  183. package/dist/game/ai/connectAiPlayer.js +58 -0
  184. package/dist/game/ai/connectAiPlayer.js.map +1 -0
  185. package/dist/game/ai/defineAi.d.ts +119 -0
  186. package/dist/game/ai/defineAi.d.ts.map +1 -0
  187. package/dist/game/ai/defineAi.js +122 -0
  188. package/dist/game/ai/defineAi.js.map +1 -0
  189. package/dist/game/ai/simulateMatches.d.ts +62 -0
  190. package/dist/game/ai/simulateMatches.d.ts.map +1 -0
  191. package/dist/game/ai/simulateMatches.js +108 -0
  192. package/dist/game/ai/simulateMatches.js.map +1 -0
  193. package/dist/game/badAiTransport/BadAIClientPrompts.d.ts +3 -0
  194. package/dist/game/badAiTransport/BadAIClientPrompts.d.ts.map +1 -1
  195. package/dist/game/badAiTransport/BadAIClientPrompts.js +3 -0
  196. package/dist/game/badAiTransport/BadAIClientPrompts.js.map +1 -1
  197. package/dist/game/clientTransport/ClientPrompts.d.ts +20 -1
  198. package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
  199. package/dist/game/clientTransport/ClientPrompts.js +30 -1
  200. package/dist/game/clientTransport/ClientPrompts.js.map +1 -1
  201. package/dist/game/clientTransport/ClientTime.d.ts +13 -0
  202. package/dist/game/clientTransport/ClientTime.d.ts.map +1 -1
  203. package/dist/game/clientTransport/ClientTime.js +51 -11
  204. package/dist/game/clientTransport/ClientTime.js.map +1 -1
  205. package/dist/game/tutorial/TutorialController.d.ts +300 -0
  206. package/dist/game/tutorial/TutorialController.d.ts.map +1 -0
  207. package/dist/game/tutorial/TutorialController.js +1182 -0
  208. package/dist/game/tutorial/TutorialController.js.map +1 -0
  209. package/dist/game/tutorial/TutorialRuntime.d.ts +89 -0
  210. package/dist/game/tutorial/TutorialRuntime.d.ts.map +1 -0
  211. package/dist/game/tutorial/TutorialRuntime.js +261 -0
  212. package/dist/game/tutorial/TutorialRuntime.js.map +1 -0
  213. package/dist/game/tutorial/TutorialTheme.d.ts +28 -0
  214. package/dist/game/tutorial/TutorialTheme.d.ts.map +1 -0
  215. package/dist/game/tutorial/TutorialTheme.js +39 -0
  216. package/dist/game/tutorial/TutorialTheme.js.map +1 -0
  217. package/dist/game/tutorial/allowed.d.ts +2 -0
  218. package/dist/game/tutorial/allowed.d.ts.map +1 -0
  219. package/dist/game/tutorial/allowed.js +119 -0
  220. package/dist/game/tutorial/allowed.js.map +1 -0
  221. package/dist/game/tutorial/checks.d.ts +58 -0
  222. package/dist/game/tutorial/checks.d.ts.map +1 -0
  223. package/dist/game/tutorial/checks.js +144 -0
  224. package/dist/game/tutorial/checks.js.map +1 -0
  225. package/dist/game/tutorial/createDemoMatch.d.ts +47 -0
  226. package/dist/game/tutorial/createDemoMatch.d.ts.map +1 -0
  227. package/dist/game/tutorial/createDemoMatch.js +67 -0
  228. package/dist/game/tutorial/createDemoMatch.js.map +1 -0
  229. package/dist/game/tutorial/defineTutorial.d.ts +353 -0
  230. package/dist/game/tutorial/defineTutorial.d.ts.map +1 -0
  231. package/dist/game/tutorial/defineTutorial.js +86 -0
  232. package/dist/game/tutorial/defineTutorial.js.map +1 -0
  233. package/dist/game/tutorial/runTutorial.d.ts +63 -0
  234. package/dist/game/tutorial/runTutorial.d.ts.map +1 -0
  235. package/dist/game/tutorial/runTutorial.js +273 -0
  236. package/dist/game/tutorial/runTutorial.js.map +1 -0
  237. package/dist/hooks/usePanelNavigation.d.ts +28 -0
  238. package/dist/hooks/usePanelNavigation.d.ts.map +1 -0
  239. package/dist/hooks/usePanelNavigation.js +36 -0
  240. package/dist/hooks/usePanelNavigation.js.map +1 -0
  241. package/dist/hooks/useTimeController.d.ts +2 -1
  242. package/dist/hooks/useTimeController.d.ts.map +1 -1
  243. package/dist/hooks/useTimeController.js +6 -2
  244. package/dist/hooks/useTimeController.js.map +1 -1
  245. package/dist/hooks/useTokenMap.d.ts +2 -4
  246. package/dist/hooks/useTokenMap.d.ts.map +1 -1
  247. package/dist/hooks/useTokenMap.js +2 -5
  248. package/dist/hooks/useTokenMap.js.map +1 -1
  249. package/dist/hooks/useTutorial.d.ts +48 -0
  250. package/dist/hooks/useTutorial.d.ts.map +1 -0
  251. package/dist/hooks/useTutorial.js +16 -0
  252. package/dist/hooks/useTutorial.js.map +1 -0
  253. package/dist/index.d.ts +57 -1
  254. package/dist/index.d.ts.map +1 -1
  255. package/dist/index.html +12 -0
  256. package/dist/index.js +27 -3
  257. package/dist/index.js.map +1 -1
  258. package/dist/main.0792d734cde2c688d5f7.hot-update.js +16991 -0
  259. package/dist/main.0792d734cde2c688d5f7.hot-update.js.map +1 -0
  260. package/dist/main.0792d734cde2c688d5f7.hot-update.json +1 -0
  261. package/dist/pretty-chitty.js +204513 -0
  262. package/dist/pretty-chitty.js.map +1 -0
  263. package/dist/rendering/CameraWrapperPerspective.d.ts +5 -0
  264. package/dist/rendering/CameraWrapperPerspective.d.ts.map +1 -1
  265. package/dist/rendering/CameraWrapperPerspective.js +16 -0
  266. package/dist/rendering/CameraWrapperPerspective.js.map +1 -1
  267. package/dist/rendering/ChitGalleryItemInstance.d.ts +1 -0
  268. package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
  269. package/dist/rendering/ChitGalleryItemInstance.js +12 -0
  270. package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
  271. package/dist/rendering/ChitRenderInstance.d.ts +9 -1
  272. package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
  273. package/dist/rendering/ChitRenderInstance.js +28 -0
  274. package/dist/rendering/ChitRenderInstance.js.map +1 -1
  275. package/dist/rendering/RootChitRenderInstance.d.ts +2 -0
  276. package/dist/rendering/RootChitRenderInstance.d.ts.map +1 -1
  277. package/dist/rendering/RootChitRenderInstance.js +29 -0
  278. package/dist/rendering/RootChitRenderInstance.js.map +1 -1
  279. package/dist/utilities/Annotations.d.ts +15 -0
  280. package/dist/utilities/Annotations.d.ts.map +1 -1
  281. package/dist/utilities/Annotations.js +31 -7
  282. package/dist/utilities/Annotations.js.map +1 -1
  283. package/dist/utilities/CanvasStack/CanvasStack.d.ts +13 -0
  284. package/dist/utilities/CanvasStack/CanvasStack.d.ts.map +1 -1
  285. package/dist/utilities/CanvasStack/CanvasStack.js +66 -15
  286. package/dist/utilities/CanvasStack/CanvasStack.js.map +1 -1
  287. package/dist/utilities/TokenizedText.d.ts +55 -0
  288. package/dist/utilities/TokenizedText.d.ts.map +1 -0
  289. package/dist/utilities/TokenizedText.js +47 -0
  290. package/dist/utilities/TokenizedText.js.map +1 -0
  291. package/dist/utilities/zIndex.d.ts +1 -0
  292. package/dist/utilities/zIndex.d.ts.map +1 -1
  293. package/dist/utilities/zIndex.js +1 -0
  294. package/dist/utilities/zIndex.js.map +1 -1
  295. package/package.json +3 -2
  296. package/src/library/components/ActionLogDisplay.tsx +1 -0
  297. package/src/library/components/BottomBarButton.tsx +5 -0
  298. package/src/library/components/ClientTrustMatchViewer.tsx +32 -2
  299. package/src/library/components/ContextGalleryDisplay.tsx +2 -0
  300. package/src/library/components/DemoWrapper.tsx +147 -52
  301. package/src/library/components/FullScreenGalleryDisplay.tsx +3 -0
  302. package/src/library/components/Gallery/BuiltItem.ts +34 -9
  303. package/src/library/components/Gallery/GalleryController.ts +75 -2
  304. package/src/library/components/Gallery/GalleryViewer.tsx +54 -10
  305. package/src/library/components/Gallery/LayoutManager.ts +30 -6
  306. package/src/library/components/Gallery/constants.ts +2 -0
  307. package/src/library/components/Gallery/registry.ts +44 -0
  308. package/src/library/components/GameDesigner.tsx +121 -12
  309. package/src/library/components/InlineGalleryDisplay.tsx +5 -0
  310. package/src/library/components/LiveButton.tsx +8 -5
  311. package/src/library/components/MatchViewer.tsx +14 -3
  312. package/src/library/components/Panel/MultiPanel.tsx +21 -0
  313. package/src/library/components/Panel/PanelContents.tsx +70 -1
  314. package/src/library/components/Panel/PanelTabStack.tsx +1 -0
  315. package/src/library/components/PanelSpark.tsx +9 -4
  316. package/src/library/components/Playground.tsx +125 -33
  317. package/src/library/components/PromptControls.tsx +7 -3
  318. package/src/library/components/SparkLineChart.tsx +23 -27
  319. package/src/library/components/TimeControlBar.tsx +5 -3
  320. package/src/library/components/TokenizedMarkdown.tsx +224 -0
  321. package/src/library/components/TokenizedMessage.tsx +30 -95
  322. package/src/library/components/TopBarPlayers.tsx +18 -10
  323. package/src/library/components/Tutorial/BrowserNarration.ts +233 -0
  324. package/src/library/components/Tutorial/TutorialBox.tsx +506 -0
  325. package/src/library/components/Tutorial/TutorialDevPanel.tsx +297 -0
  326. package/src/library/components/Tutorial/TutorialOverlay.tsx +1301 -0
  327. package/src/library/components/Tutorial/targetRects.ts +273 -0
  328. package/src/library/game/Chit.ts +23 -7
  329. package/src/library/game/ClientTimeState.ts +18 -0
  330. package/src/library/game/ConnectionTransport.ts +12 -3
  331. package/src/library/game/Game.ts +16 -1
  332. package/src/library/game/GameTheme.ts +4 -0
  333. package/src/library/game/Match.ts +174 -5
  334. package/src/library/game/MatchStorage.ts +14 -4
  335. package/src/library/game/Pick.ts +36 -1
  336. package/src/library/game/PlayerChit.ts +4 -1
  337. package/src/library/game/PlayerInfo.ts +13 -3
  338. package/src/library/game/PlayerPromptStatusChit.ts +8 -2
  339. package/src/library/game/Prompt.ts +20 -0
  340. package/src/library/game/Turn.ts +198 -68
  341. package/src/library/game/TurnState.ts +34 -3
  342. package/src/library/game/ai/AI_GUIDE.md +444 -0
  343. package/src/library/game/ai/AiClientPrompts.ts +730 -0
  344. package/src/library/game/ai/AiLiveView.ts +63 -0
  345. package/src/library/game/ai/AiPlayerView.ts +114 -0
  346. package/src/library/game/ai/ai.test.ts +475 -0
  347. package/src/library/game/ai/connectAiPlayer.ts +88 -0
  348. package/src/library/game/ai/defineAi.ts +230 -0
  349. package/src/library/game/ai/simulateMatches.ts +172 -0
  350. package/src/library/game/badAiTransport/BadAIClientPrompts.ts +3 -0
  351. package/src/library/game/clientTransport/ClientPrompts.ts +31 -1
  352. package/src/library/game/clientTransport/ClientTime.ts +54 -13
  353. package/src/library/game/serialize.test.ts +275 -0
  354. package/src/library/game/tutorial/TUTORIAL_GUIDE.md +411 -0
  355. package/src/library/game/tutorial/TutorialController.test.ts +731 -0
  356. package/src/library/game/tutorial/TutorialController.ts +1286 -0
  357. package/src/library/game/tutorial/TutorialRuntime.ts +311 -0
  358. package/src/library/game/tutorial/TutorialTheme.ts +67 -0
  359. package/src/library/game/tutorial/allowed.ts +145 -0
  360. package/src/library/game/tutorial/checks.ts +186 -0
  361. package/src/library/game/tutorial/createDemoMatch.ts +115 -0
  362. package/src/library/game/tutorial/defineTutorial.ts +414 -0
  363. package/src/library/game/tutorial/runTutorial.ts +331 -0
  364. package/src/library/game/undo.test.ts +282 -0
  365. package/src/library/hooks/usePanelNavigation.tsx +65 -0
  366. package/src/library/hooks/useTimeController.tsx +6 -2
  367. package/src/library/hooks/useTokenMap.ts +2 -6
  368. package/src/library/hooks/useTutorial.tsx +76 -0
  369. package/src/library/index.ts +91 -4
  370. package/src/library/rendering/CameraWrapperPerspective.ts +17 -0
  371. package/src/library/rendering/ChitGalleryItemInstance.ts +12 -0
  372. package/src/library/rendering/ChitRenderInstance.ts +34 -0
  373. package/src/library/rendering/RootChitRenderInstance.ts +30 -1
  374. package/src/library/utilities/Annotations.ts +35 -7
  375. package/src/library/utilities/CanvasStack/CanvasStack.ts +74 -29
  376. package/src/library/utilities/TokenizedText.test.ts +32 -0
  377. package/src/library/utilities/TokenizedText.ts +103 -0
  378. package/src/library/utilities/zIndex.ts +1 -0
@@ -0,0 +1,731 @@
1
+ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
2
+ import { TutorialController, TutorialView } from "./TutorialController";
3
+ import { defineTutorial } from "./defineTutorial";
4
+ import { TutorialRuntime } from "./TutorialRuntime";
5
+ import { PlayerChit } from "../PlayerChit";
6
+ import { RootChit } from "../RootChit";
7
+ import { ButtonPick } from "../Pick";
8
+
9
+ // Three narration steps of 6 words each: 2 s each on the reading clock (3 words/second)
10
+ const spec = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
11
+ id: "flow",
12
+ locale: "en",
13
+ title: "Flow",
14
+ steps: [
15
+ { id: "a", text: "one two three four five six" },
16
+ { id: "b", text: "one two three four five six" },
17
+ { id: "c", text: "one two three four five six" },
18
+ { id: "d", text: "the end", end: "continue" },
19
+ ],
20
+ });
21
+
22
+ function makeView(): TutorialView<PlayerChit, RootChit<PlayerChit>> {
23
+ const root = new RootChit<PlayerChit>();
24
+ const me = new PlayerChit();
25
+ return {
26
+ root: () => root,
27
+ me: () => me,
28
+ prompt: () => undefined,
29
+ clock: () => 1,
30
+ find: () => undefined,
31
+ latestLog: () => undefined,
32
+ live: () => true,
33
+ onChange: () => () => {},
34
+ };
35
+ }
36
+
37
+ describe("TutorialController flow", () => {
38
+ beforeEach(() => {
39
+ vi.useFakeTimers();
40
+ });
41
+ afterEach(() => {
42
+ vi.useRealTimers();
43
+ });
44
+
45
+ const make = () =>
46
+ new TutorialController({ spec, view: makeView(), autoAdvanceDelayMs: 100, now: () => Date.now() });
47
+
48
+ test("narration steps advance by themselves when their narration ends", () => {
49
+ const c = make();
50
+ c.start();
51
+ expect(c.index.value).toBe(0);
52
+ vi.advanceTimersByTime(2500);
53
+ expect(c.index.value).toBe(1);
54
+ vi.advanceTimersByTime(2500);
55
+ expect(c.index.value).toBe(2);
56
+ c.dispose();
57
+ });
58
+
59
+ test("the next step's recording loads while a step talks (and the first while the start card is up)", () => {
60
+ const audioSpec = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
61
+ id: "audio",
62
+ locale: "en",
63
+ title: "Audio",
64
+ steps: [
65
+ { id: "a", text: "first", audio: "a.mp3" },
66
+ { id: "b", text: "second", audio: "b.mp3" },
67
+ { id: "c", text: "the end", end: "continue" },
68
+ ],
69
+ });
70
+ const preloaded: string[] = [];
71
+ const ends: (() => void)[] = [];
72
+ const narration = {
73
+ play: () => Promise.resolve(),
74
+ stop: () => {},
75
+ pause: () => {},
76
+ resume: () => {},
77
+ playing: true,
78
+ paused: false,
79
+ time: 0,
80
+ duration: 1,
81
+ preload: (audio: string) => preloaded.push(audio),
82
+ onTime: () => () => {},
83
+ onSentence: () => () => {},
84
+ onEnd: (cb: () => void) => {
85
+ ends.push(cb);
86
+ return () => {};
87
+ },
88
+ };
89
+ const c = new TutorialController({ spec: audioSpec, view: makeView(), narration, now: () => Date.now() });
90
+ expect(preloaded).toEqual(["a.mp3"]);
91
+ c.start();
92
+ expect(preloaded).toEqual(["a.mp3", "b.mp3"]);
93
+ c.dispose();
94
+ });
95
+
96
+ test("Back pauses: nothing plays or advances until Play", () => {
97
+ const c = make();
98
+ c.start();
99
+ vi.advanceTimersByTime(2500);
100
+ vi.advanceTimersByTime(2500);
101
+ expect(c.index.value).toBe(2);
102
+
103
+ c.back();
104
+ expect(c.index.value).toBe(1);
105
+ expect(c.paused.value).toBe(true);
106
+ expect(c.narrating.value).toBe(false);
107
+
108
+ // Plenty of time passes: still held on step 2, so a second Back goes further back
109
+ vi.advanceTimersByTime(10000);
110
+ expect(c.index.value).toBe(1);
111
+ c.back();
112
+ expect(c.index.value).toBe(0);
113
+
114
+ // Next while held moves one step and stays held
115
+ c.next();
116
+ expect(c.index.value).toBe(1);
117
+ vi.advanceTimersByTime(10000);
118
+ expect(c.index.value).toBe(1);
119
+ expect(c.paused.value).toBe(true);
120
+
121
+ // Play resumes: the step narrates from the top, then the flow carries on
122
+ c.play();
123
+ expect(c.paused.value).toBe(false);
124
+ expect(c.narrating.value).toBe(true);
125
+ vi.advanceTimersByTime(2500);
126
+ expect(c.index.value).toBe(2);
127
+ c.dispose();
128
+ });
129
+
130
+ test("Pause holds mid-narration and Play continues from there", () => {
131
+ const c = make();
132
+ c.start();
133
+ vi.advanceTimersByTime(1000);
134
+ c.pause();
135
+ vi.advanceTimersByTime(10000);
136
+ expect(c.index.value).toBe(0);
137
+ c.play();
138
+ // one second of narration was left
139
+ vi.advanceTimersByTime(1500);
140
+ expect(c.index.value).toBe(1);
141
+ c.dispose();
142
+ });
143
+
144
+ test("Back with a game history rewinds, queues repeated presses, and lands paused on the live step", async () => {
145
+ const restored: string[] = [];
146
+ const saved: string[] = [];
147
+ const c = new TutorialController({
148
+ spec,
149
+ view: makeView(),
150
+ autoAdvanceDelayMs: 100,
151
+ now: () => Date.now(),
152
+ history: {
153
+ save: (id) => saved.push(id),
154
+ restore: (id) =>
155
+ new Promise<boolean>((resolve) => {
156
+ restored.push(id);
157
+ setTimeout(() => resolve(true), 300);
158
+ }),
159
+ },
160
+ });
161
+ c.start();
162
+ vi.advanceTimersByTime(2500);
163
+ vi.advanceTimersByTime(2500);
164
+ expect(c.index.value).toBe(2);
165
+ expect(saved).toEqual(["a", "b", "c"]);
166
+
167
+ c.back();
168
+ expect(c.rewinding.value).toBe(true);
169
+ expect(c.index.value).toBe(1);
170
+ expect(c.canAdvance).toBe(false);
171
+ c.back(); // pressed again before the first rewind landed
172
+ expect(c.index.value).toBe(0);
173
+
174
+ await vi.advanceTimersByTimeAsync(1000);
175
+ expect(restored).toEqual(["b", "a"]);
176
+ expect(c.rewinding.value).toBe(false);
177
+ expect(c.index.value).toBe(0);
178
+ expect(c.reviewing.value).toBe(false); // the game is back there: it is the live step
179
+ expect(c.frontier.value).toBe(0);
180
+ expect(c.paused.value).toBe(true);
181
+
182
+ // Playing on takes fresh snapshots for the steps it re-enters
183
+ c.play();
184
+ await vi.advanceTimersByTimeAsync(2500);
185
+ expect(c.index.value).toBe(1);
186
+ expect(saved).toEqual(["a", "b", "c", "a", "b"]);
187
+ c.dispose();
188
+ });
189
+
190
+ test("nothing on the board can be played before Start", () => {
191
+ let guard: ((a: any) => boolean | "handled") | undefined;
192
+ const view = { ...makeView(), setGuard: (g: any) => (guard = g) };
193
+ const c = new TutorialController({ spec, view, autoAdvanceDelayMs: 100, now: () => Date.now() });
194
+ expect(guard).toBeDefined();
195
+ expect(guard?.({ type: "pick", pick: {}, value: "x" })).toBe(false);
196
+ expect(c.index.value).toBe(-1);
197
+ c.dispose();
198
+ expect(guard).toBeUndefined();
199
+ });
200
+
201
+ test("the game's Undo is the tutorial's Back while it runs", () => {
202
+ let guard: ((a: any) => boolean | "handled") | undefined;
203
+ let undo: { undo: () => void } | undefined;
204
+ const view = { ...makeView(), setGuard: (g: any) => (guard = g), setUndo: (u: any) => (undo = u) };
205
+ const c = new TutorialController({ spec, view, autoAdvanceDelayMs: 100, now: () => Date.now() });
206
+ c.start();
207
+ expect(undo).toBeDefined();
208
+ vi.advanceTimersByTime(2500);
209
+ expect(c.index.value).toBe(1);
210
+
211
+ // The engine's Undo, as a prompt would report it, is redirected rather than refused
212
+ expect(guard?.({ type: "undo", fullReset: false })).toBe("handled");
213
+ expect(c.index.value).toBe(0);
214
+ expect(c.paused.value).toBe(true);
215
+
216
+ // The Undo button itself
217
+ c.next();
218
+ expect(c.index.value).toBe(1);
219
+ undo?.undo();
220
+ expect(c.index.value).toBe(0);
221
+
222
+ // After the tutorial the game owns Undo again
223
+ c.skip();
224
+ expect(undo).toBeUndefined();
225
+ expect(guard).toBeUndefined();
226
+ c.dispose();
227
+ });
228
+
229
+ test("playback speed: 2x halves a step's narration time, including a change mid-step", () => {
230
+ const c = make();
231
+ c.setRate(2);
232
+ c.start();
233
+ vi.advanceTimersByTime(1200); // 2 s of reading at 2x, plus the 100 ms auto-advance beat
234
+ expect(c.index.value).toBe(1);
235
+
236
+ // Halfway through step 2 at 2x (0.5 s real = 1 s of reading), drop back to 1x: 1 s left
237
+ vi.advanceTimersByTime(500);
238
+ c.setRate(1);
239
+ vi.advanceTimersByTime(800);
240
+ expect(c.index.value).toBe(1);
241
+ vi.advanceTimersByTime(400);
242
+ expect(c.index.value).toBe(2);
243
+ c.dispose();
244
+ });
245
+
246
+ test("a do-it step that passes mid-narration finishes its narration before moving on", () => {
247
+ let done = false;
248
+ const listeners: (() => void)[] = [];
249
+ const view = {
250
+ ...makeView(),
251
+ onChange: (cb: () => void) => {
252
+ listeners.push(cb);
253
+ return () => {};
254
+ },
255
+ };
256
+ const doIt = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
257
+ id: "doit",
258
+ locale: "en",
259
+ title: "Do it",
260
+ steps: [
261
+ // 9 words: 3 s on the reading clock
262
+ { id: "act", text: "one two three four five six seven eight nine", waitFor: () => done, allow: "any" },
263
+ { id: "next", text: "the end", end: "continue" },
264
+ ],
265
+ });
266
+ const c = new TutorialController({ spec: doIt, view, satisfiedDelayMs: 200, now: () => Date.now() });
267
+ c.start();
268
+ vi.advanceTimersByTime(500);
269
+ done = true;
270
+ listeners.forEach((l) => l()); // the player did it half a second in
271
+ expect(c.status.value).toBe("satisfied");
272
+ vi.advanceTimersByTime(1500); // well past the old 900 ms cut-off, narration still going
273
+ expect(c.index.value).toBe(0);
274
+ vi.advanceTimersByTime(1300); // narration ends at 3 s, then the 200 ms beat
275
+ expect(c.index.value).toBe(1);
276
+ c.dispose();
277
+ });
278
+
279
+ describe("acting ahead", () => {
280
+ // talk, talk, do it (press Go), talk, do it (press Again), the end
281
+ let done = 0;
282
+ const listeners: (() => void)[] = [];
283
+ const saved: string[] = [];
284
+ const events: string[] = [];
285
+ let guard: ((a: any) => boolean | "handled") | undefined;
286
+ const ahead = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
287
+ id: "ahead",
288
+ locale: "en",
289
+ title: "Ahead",
290
+ steps: [
291
+ { id: "talk1", text: "one two three four five six" },
292
+ { id: "talk2", text: "one two three four five six", pause: true },
293
+ { id: "go", text: "press go now", allow: [{ button: "Go" }, { ui: "gallery:modeButton" }], waitFor: () => done >= 1 },
294
+ { id: "talk3", text: "one two three four five six" },
295
+ { id: "again", text: "press again", allow: { button: "Again" }, waitFor: () => done >= 2 },
296
+ { id: "end", text: "the end", end: "continue" },
297
+ ],
298
+ });
299
+ const press = (label: string) => {
300
+ const pick = new ButtonPick();
301
+ pick.button = { label } as any;
302
+ return guard?.({ type: "pick", pick, value: undefined });
303
+ };
304
+ const land = () => {
305
+ done++;
306
+ listeners.forEach((l) => l());
307
+ };
308
+ const make = () => {
309
+ done = 0;
310
+ listeners.length = 0;
311
+ saved.length = 0;
312
+ events.length = 0;
313
+ const view = {
314
+ ...makeView(),
315
+ setGuard: (g: any) => (guard = g),
316
+ onChange: (cb: () => void) => {
317
+ listeners.push(cb);
318
+ return () => {};
319
+ },
320
+ };
321
+ return new TutorialController({
322
+ spec: ahead,
323
+ view,
324
+ autoAdvanceDelayMs: 100,
325
+ satisfiedDelayMs: 200,
326
+ now: () => Date.now(),
327
+ history: { save: (id: string) => saved.push(id), restore: async () => true },
328
+ onEvent: (e) => e.type === "step" && events.push(e.stepId),
329
+ });
330
+ };
331
+
332
+ test("the next do-it step's move, made while an earlier step talks, moves on to that step", () => {
333
+ const c = make();
334
+ c.start();
335
+ vi.advanceTimersByTime(500);
336
+ expect(press("Go")).toBe(true);
337
+ // The steps in between count as seen, so Back has somewhere to go
338
+ expect(c.index.value).toBe(2);
339
+ expect(saved).toEqual(["talk1", "talk2", "go"]);
340
+ expect(events).toEqual(["talk1", "talk2", "go"]);
341
+ // The step is not narrated: it would only ask for what was just done
342
+ expect(c.narrating.value).toBe(false);
343
+ land();
344
+ expect(c.status.value).toBe("satisfied");
345
+ vi.advanceTimersByTime(250);
346
+ expect(c.index.value).toBe(3);
347
+ expect(c.narrating.value).toBe(true);
348
+ c.dispose();
349
+ });
350
+
351
+ test("a move for a later do-it step, or one nothing asks for, is still refused", () => {
352
+ const c = make();
353
+ c.start();
354
+ expect(press("Again")).toBe(false);
355
+ expect(press("Other")).toBe(false);
356
+ expect(c.index.value).toBe(0);
357
+ c.dispose();
358
+ });
359
+
360
+ test("tapping the control the next do-it step allows moves on too, aliases included", () => {
361
+ const c = make();
362
+ c.start();
363
+ c.usedUi("log"); // not asked for
364
+ expect(c.index.value).toBe(0);
365
+ c.usedUi("gallery:toInline"); // "gallery:modeButton" stands for it
366
+ expect(c.index.value).toBe(2);
367
+ // the control's effect did not satisfy the check: narrate after all
368
+ vi.advanceTimersByTime(250);
369
+ expect(c.status.value).toBe("waiting");
370
+ expect(c.narrating.value).toBe(true);
371
+ c.dispose();
372
+ });
373
+ });
374
+
375
+ test("poses change chits in the view for their step, keep when asked, and are put back", () => {
376
+ const card = new PlayerChit() as PlayerChit & { faceDown?: boolean; tilt?: number };
377
+ const token = new PlayerChit() as PlayerChit & { faceDown?: boolean; tilt?: number };
378
+ const log: string[] = [];
379
+ const view = {
380
+ ...makeView(),
381
+ pose: (chit: any, change: (c: any) => void) => {
382
+ change(chit);
383
+ log.push(`pose ${chit === card ? "card" : "token"}`);
384
+ },
385
+ unpose: (chit: any) => {
386
+ chit.faceDown = undefined;
387
+ chit.tilt = undefined;
388
+ log.push(`unpose ${chit === card ? "card" : "token"}`);
389
+ },
390
+ };
391
+ const posing = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
392
+ id: "pose",
393
+ locale: "en",
394
+ title: "Pose",
395
+ steps: [
396
+ {
397
+ id: "a",
398
+ text: "one two three. four five six.",
399
+ pose: [
400
+ { chit: () => card, set: { faceDown: true } },
401
+ { chit: () => token, set: (c: any) => (c.tilt = 1), keep: true },
402
+ ],
403
+ // the second sentence turns the card back over
404
+ cues: [{ at: { sentence: 1 }, pose: [{ chit: () => card }] }],
405
+ },
406
+ { id: "b", text: "one two three four five six", pose: [{ chit: () => card, set: { faceDown: true } }] },
407
+ { id: "c", text: "one two three four five six" },
408
+ { id: "d", text: "the end", end: "continue" },
409
+ ],
410
+ });
411
+ const c = new TutorialController({ spec: posing, view, autoAdvanceDelayMs: 100, now: () => Date.now() });
412
+ c.start();
413
+ expect(card.faceDown).toBe(true);
414
+ expect(token.tilt).toBe(1);
415
+ vi.advanceTimersByTime(1100); // into the second sentence
416
+ expect(card.faceDown).toBeUndefined();
417
+
418
+ vi.advanceTimersByTime(1100); // step b poses the card again
419
+ expect(c.index.value).toBe(1);
420
+ expect(card.faceDown).toBe(true);
421
+ vi.advanceTimersByTime(2200); // step c: b's pose ends, the kept one stays
422
+ expect(c.index.value).toBe(2);
423
+ expect(card.faceDown).toBeUndefined();
424
+ expect(token.tilt).toBe(1);
425
+ expect(log).toEqual(["pose card", "pose token", "unpose card", "pose card", "unpose card"]);
426
+
427
+ // The end of the tutorial puts everything back
428
+ c.skip();
429
+ expect(token.tilt).toBeUndefined();
430
+ c.dispose();
431
+ });
432
+
433
+ test("timeline commands hold the board N moments on, until a moment, and let it play again", () => {
434
+ let clock = 10;
435
+ let log: string | undefined;
436
+ const holds: (number | undefined)[] = [];
437
+ const listeners: (() => void)[] = [];
438
+ const show = (c: number, line?: string) => {
439
+ clock = c;
440
+ log = line;
441
+ listeners.forEach((l) => l());
442
+ };
443
+ const view = {
444
+ ...makeView(),
445
+ clock: () => clock,
446
+ latestLog: () => log,
447
+ onChange: (cb: () => void) => {
448
+ listeners.push(cb);
449
+ return () => {};
450
+ },
451
+ timeline: { at: () => clock, hold: (c: number | undefined) => holds.push(c) },
452
+ };
453
+ const timed = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
454
+ id: "timeline",
455
+ locale: "en",
456
+ title: "Timeline",
457
+ steps: [
458
+ // two moments on from the one on screen, then freeze where the second sentence starts
459
+ {
460
+ id: "a",
461
+ text: "one two three. four five six.",
462
+ timeline: { advance: 2 },
463
+ cues: [{ at: { sentence: 1 }, timeline: "hold" }],
464
+ },
465
+ // play until Robin's buy is on the board
466
+ { id: "b", text: "one two three four five six", timeline: { until: (ctx) => ctx.recentLog.some((l) => /Robin buys/.test(l)) } },
467
+ { id: "c", text: "one two three four five six", timeline: "play" },
468
+ { id: "d", text: "the end", end: "continue" },
469
+ ],
470
+ });
471
+ const c = new TutorialController({ spec: timed, view, autoAdvanceDelayMs: 100, now: () => Date.now() });
472
+ c.start();
473
+ expect(holds).toEqual([12]);
474
+ show(11);
475
+ vi.advanceTimersByTime(1100); // the second sentence: hold where the board is now
476
+ expect(holds).toEqual([12, 11]);
477
+
478
+ vi.advanceTimersByTime(1100); // step b plays on until the log says so
479
+ expect(c.index.value).toBe(1);
480
+ expect(holds).toEqual([12, 11, undefined]);
481
+ show(12, "Sam passes");
482
+ expect(holds.length).toBe(3);
483
+ show(13, "Robin buys a card");
484
+ expect(holds).toEqual([12, 11, undefined, 13]);
485
+ expect(c.timelineHold.value).toBe(13);
486
+
487
+ vi.advanceTimersByTime(2200); // step c lets it play
488
+ expect(c.index.value).toBe(2);
489
+ expect(holds[holds.length - 1]).toBeUndefined();
490
+ c.dispose();
491
+ });
492
+
493
+ test("Back and the end of the tutorial let a held board play", async () => {
494
+ const holds: (number | undefined)[] = [];
495
+ const view = { ...makeView(), timeline: { at: () => 5, hold: (c: number | undefined) => holds.push(c) } };
496
+ const held = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
497
+ id: "held",
498
+ locale: "en",
499
+ title: "Held",
500
+ steps: [
501
+ { id: "a", text: "one two three four five six" },
502
+ { id: "b", text: "one two three four five six", timeline: "hold" },
503
+ { id: "c", text: "the end", end: "continue" },
504
+ ],
505
+ });
506
+ const c = new TutorialController({
507
+ spec: held,
508
+ view,
509
+ autoAdvanceDelayMs: 100,
510
+ now: () => Date.now(),
511
+ history: { save: () => {}, restore: async () => true },
512
+ });
513
+ c.start();
514
+ vi.advanceTimersByTime(2200);
515
+ expect(holds).toEqual([5]);
516
+ c.back(); // the rewind needs the board to catch up
517
+ expect(holds).toEqual([5, undefined]);
518
+ await vi.runOnlyPendingTimersAsync();
519
+ c.next();
520
+ expect(holds).toEqual([5, undefined, 5]);
521
+ c.skip();
522
+ expect(holds).toEqual([5, undefined, 5, undefined]);
523
+ c.dispose();
524
+ });
525
+
526
+ describe("doing it for the player", () => {
527
+ const build = () => {
528
+ let pressed = 0;
529
+ const listeners: (() => void)[] = [];
530
+ const go = new ButtonPick();
531
+ go.button = { label: "Go" } as any;
532
+ const other = new ButtonPick();
533
+ other.button = { label: "Other" } as any;
534
+ let guard: ((a: any) => boolean | "handled") | undefined;
535
+ const resolved: string[] = [];
536
+ const prompt = {
537
+ picks: [other, go],
538
+ resolvePick: (pick: ButtonPick, value: unknown) => {
539
+ if (guard && !guard({ type: "pick", pick, value })) return;
540
+ resolved.push(pick.button!.label);
541
+ if (pick === go) pressed++;
542
+ listeners.forEach((l) => l());
543
+ },
544
+ };
545
+ const ui: string[] = [];
546
+ const fast: boolean[] = [];
547
+ const view = {
548
+ ...makeView(),
549
+ prompt: () => prompt as any,
550
+ setGuard: (g: any) => (guard = g),
551
+ onChange: (cb: () => void) => {
552
+ listeners.push(cb);
553
+ return () => {};
554
+ },
555
+ pressUi: (name: string) => {
556
+ ui.push(name);
557
+ pressed++;
558
+ listeners.forEach((l) => l());
559
+ return true;
560
+ },
561
+ setFastForward: (on: boolean) => fast.push(on),
562
+ };
563
+ const spec = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
564
+ id: "doit-for-me",
565
+ locale: "en",
566
+ title: "Do it for me",
567
+ steps: [
568
+ { id: "talk", text: "one two three four five six" },
569
+ { id: "go", text: "press go", allow: { button: "Go" }, waitFor: () => pressed >= 1 },
570
+ { id: "open", text: "open the market", allow: { ui: "button:Market" }, waitFor: () => pressed >= 2 },
571
+ { id: "talk2", text: "one two three four five six" },
572
+ { id: "end", text: "the end", end: "continue" },
573
+ ],
574
+ });
575
+ const c = new TutorialController({ spec, view, autoAdvanceDelayMs: 100, satisfiedDelayMs: 200, now: () => Date.now() });
576
+ return { c, resolved, ui, fast, narrating: () => c.narrating.value };
577
+ };
578
+
579
+ test("→ makes the waiting step's move: the allowed one, through the guard, then moves on", () => {
580
+ const { c, resolved, ui } = build();
581
+ c.start();
582
+ c.forward(); // Next on a talking step
583
+ expect(c.index.value).toBe(1);
584
+ vi.advanceTimersByTime(1000); // its narration ("press go") is done
585
+ expect(c.status.value).toBe("waiting");
586
+ c.forward(); // the step's move, not the first button on offer
587
+ expect(resolved).toEqual(["Go"]);
588
+ vi.advanceTimersByTime(250);
589
+ expect(c.index.value).toBe(2);
590
+ vi.advanceTimersByTime(1500);
591
+ c.forward(); // a UI step presses its control
592
+ expect(ui).toEqual(["button:Market"]);
593
+ c.dispose();
594
+ });
595
+
596
+ test("fast-forward plays through talking and do-it steps and lands on its step, which plays as usual", () => {
597
+ const { c, resolved, ui, fast } = build();
598
+ c.start();
599
+ c.fastForwardTo(3);
600
+ expect(fast).toEqual([true]);
601
+ expect(c.narrating.value).toBe(false);
602
+ vi.advanceTimersByTime(3000); // each step waits for the board to settle (here: always settled)
603
+ expect(resolved).toEqual(["Go"]);
604
+ expect(ui).toEqual(["button:Market"]);
605
+ expect(c.index.value).toBe(3);
606
+ expect(fast).toEqual([true, false]);
607
+ expect(c.fastForwardTarget.value).toBeUndefined();
608
+ expect(c.narrating.value).toBe(true);
609
+ c.dispose();
610
+ });
611
+
612
+ test("pausing stops a fast-forward where it is", () => {
613
+ const { c, fast } = build();
614
+ c.start();
615
+ c.fastForwardTo(4);
616
+ c.pause();
617
+ expect(fast).toEqual([true, false]);
618
+ vi.advanceTimersByTime(5000);
619
+ expect(c.index.value).toBe(0);
620
+ c.dispose();
621
+ });
622
+ });
623
+
624
+ test("the last sentence stays emphasised through the beat before moving on; a waiting step shows it all", () => {
625
+ const flow = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
626
+ id: "emphasis",
627
+ locale: "en",
628
+ title: "Emphasis",
629
+ steps: [
630
+ { id: "a", text: "One two three. Four five six." },
631
+ { id: "b", text: "Seven eight nine.", pause: true },
632
+ { id: "c", text: "The end.", end: "continue" },
633
+ ],
634
+ });
635
+ const c = new TutorialController({ spec: flow, view: makeView(), autoAdvanceDelayMs: 500, now: () => Date.now() });
636
+ c.start();
637
+ expect(c.sentence.value).toBe(0); // emphasised from the first moment
638
+ vi.advanceTimersByTime(2100); // 6 words at 3/s: narration over, inside the 500 ms beat
639
+ expect(c.index.value).toBe(0);
640
+ expect(c.narrating.value).toBe(false);
641
+ expect(c.sentence.value).toBe(1); // still the last sentence, not the whole paragraph
642
+ vi.advanceTimersByTime(600);
643
+ expect(c.index.value).toBe(1);
644
+ vi.advanceTimersByTime(1200); // step b waits for Next: the whole paragraph comes back
645
+ expect(c.sentence.value).toBe(-1);
646
+ c.dispose();
647
+ });
648
+
649
+ test("a start held from a rewind stays silent until Play", () => {
650
+ const c = make();
651
+ c.start(2, { paused: true });
652
+ expect(c.index.value).toBe(2);
653
+ expect(c.narrating.value).toBe(false);
654
+ vi.advanceTimersByTime(10000);
655
+ expect(c.index.value).toBe(2);
656
+ c.toggleNarration();
657
+ vi.advanceTimersByTime(2500);
658
+ expect(c.index.value).toBe(3);
659
+ c.dispose();
660
+ });
661
+ });
662
+
663
+ describe("TutorialRuntime forced moves", () => {
664
+ test("a bot waits for the step that scripts its next move, and is woken when it arrives", () => {
665
+ const scripted = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
666
+ id: "bots",
667
+ locale: "en",
668
+ title: "Bots",
669
+ steps: [
670
+ { id: "talk", text: "Watch." },
671
+ { id: "robin", text: "Robin moves.", ai: { p1: [{ key: "market.buy" }] } },
672
+ { id: "after", text: "Done.", end: "continue" },
673
+ ],
674
+ });
675
+ const runtime = new TutorialRuntime(scripted);
676
+ const robin = runtime.aiOptionsFor("p1");
677
+ const sam = runtime.aiOptionsFor("p2");
678
+ const rechecks: string[] = [];
679
+ runtime.attachBots([
680
+ { playerId: "p1", prompts: { recheck: () => rechecks.push("p1") } } as any,
681
+ { playerId: "p2", prompts: { recheck: () => rechecks.push("p2") } } as any,
682
+ ]);
683
+
684
+ const prompt: any = { id: "x", type: "PickPrompt", details: { picks: [{ type: "ChitPick", details: {} }] } };
685
+ expect(robin.hold?.(prompt)).toBe(true); // setup: Robin's move belongs to the "robin" step
686
+ expect(sam.hold?.(prompt)).toBe(false); // nothing scripted for Sam: plays normally
687
+ runtime.activeStep.value = "talk";
688
+ expect(robin.hold?.(prompt)).toBe(true);
689
+ runtime.activeStep.value = "robin";
690
+ expect(robin.hold?.(prompt)).toBe(false);
691
+ runtime.activeStep.value = "done";
692
+ expect(robin.hold?.(prompt)).toBe(false);
693
+ });
694
+
695
+ test("a waiting bot still answers the engine's Confirm, unless that Confirm is its scripted move", () => {
696
+ const confirmOnly: any = {
697
+ id: "c1",
698
+ type: "PickPrompt",
699
+ canReset: false,
700
+ canStageInEarly: 0,
701
+ details: { picks: [{ type: "ButtonPick", details: { __buttonType: "Confirm", __f: [] } }] },
702
+ };
703
+ const buyPrompt: any = {
704
+ id: "b1",
705
+ type: "PickPrompt",
706
+ canReset: false,
707
+ canStageInEarly: 0,
708
+ details: { picks: [{ type: "ChitPick", details: { c: ["card1"], f: [] } }] },
709
+ };
710
+ const scripted = defineTutorial<PlayerChit, RootChit<PlayerChit>>({
711
+ id: "confirms",
712
+ locale: "en",
713
+ title: "Confirms",
714
+ steps: [
715
+ { id: "talk", text: "Watch." },
716
+ {
717
+ id: "later",
718
+ text: "Moves.",
719
+ ai: { p1: [{ key: "market.buy" }], p2: [{ button: "Confirm" }] },
720
+ },
721
+ ],
722
+ });
723
+ const runtime = new TutorialRuntime(scripted);
724
+ runtime.activeStep.value = "talk";
725
+ const robin = runtime.aiOptionsFor("p1");
726
+ const sam = runtime.aiOptionsFor("p2");
727
+ expect(robin.hold?.(buyPrompt)).toBe(true); // its buy waits for "later"
728
+ expect(robin.hold?.(confirmOnly)).toBe(false); // but it can still end the turn it is in
729
+ expect(sam.hold?.(confirmOnly)).toBe(true); // Sam's scripted move is that Confirm: it waits
730
+ });
731
+ });