@pretty-chitty/core 2.0.0 → 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 (318) 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/ContextGalleryDisplay.d.ts.map +1 -1
  10. package/dist/components/ContextGalleryDisplay.js +1 -1
  11. package/dist/components/ContextGalleryDisplay.js.map +1 -1
  12. package/dist/components/DemoWrapper.d.ts +30 -2
  13. package/dist/components/DemoWrapper.d.ts.map +1 -1
  14. package/dist/components/DemoWrapper.js +79 -36
  15. package/dist/components/DemoWrapper.js.map +1 -1
  16. package/dist/components/FullScreenGalleryDisplay.d.ts.map +1 -1
  17. package/dist/components/FullScreenGalleryDisplay.js +2 -2
  18. package/dist/components/FullScreenGalleryDisplay.js.map +1 -1
  19. package/dist/components/Gallery/BuiltItem.d.ts +6 -2
  20. package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
  21. package/dist/components/Gallery/BuiltItem.js +28 -9
  22. package/dist/components/Gallery/BuiltItem.js.map +1 -1
  23. package/dist/components/Gallery/GalleryController.d.ts +18 -0
  24. package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
  25. package/dist/components/Gallery/GalleryController.js +67 -0
  26. package/dist/components/Gallery/GalleryController.js.map +1 -1
  27. package/dist/components/Gallery/GalleryViewer.d.ts +6 -1
  28. package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -1
  29. package/dist/components/Gallery/GalleryViewer.js +48 -10
  30. package/dist/components/Gallery/GalleryViewer.js.map +1 -1
  31. package/dist/components/Gallery/LayoutManager.d.ts +6 -0
  32. package/dist/components/Gallery/LayoutManager.d.ts.map +1 -1
  33. package/dist/components/Gallery/LayoutManager.js +23 -3
  34. package/dist/components/Gallery/LayoutManager.js.map +1 -1
  35. package/dist/components/Gallery/constants.d.ts +2 -0
  36. package/dist/components/Gallery/constants.d.ts.map +1 -1
  37. package/dist/components/Gallery/constants.js +2 -0
  38. package/dist/components/Gallery/constants.js.map +1 -1
  39. package/dist/components/Gallery/registry.d.ts +34 -0
  40. package/dist/components/Gallery/registry.d.ts.map +1 -0
  41. package/dist/components/Gallery/registry.js +17 -0
  42. package/dist/components/Gallery/registry.js.map +1 -0
  43. package/dist/components/GameDesigner.d.ts.map +1 -1
  44. package/dist/components/GameDesigner.js +42 -10
  45. package/dist/components/GameDesigner.js.map +1 -1
  46. package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
  47. package/dist/components/InlineGalleryDisplay.js +2 -2
  48. package/dist/components/InlineGalleryDisplay.js.map +1 -1
  49. package/dist/components/LiveButton.d.ts.map +1 -1
  50. package/dist/components/LiveButton.js +5 -2
  51. package/dist/components/LiveButton.js.map +1 -1
  52. package/dist/components/MatchViewer.d.ts +6 -1
  53. package/dist/components/MatchViewer.d.ts.map +1 -1
  54. package/dist/components/MatchViewer.js +9 -3
  55. package/dist/components/MatchViewer.js.map +1 -1
  56. package/dist/components/Panel/MultiPanel.d.ts.map +1 -1
  57. package/dist/components/Panel/MultiPanel.js +18 -0
  58. package/dist/components/Panel/MultiPanel.js.map +1 -1
  59. package/dist/components/Panel/PanelContents.d.ts.map +1 -1
  60. package/dist/components/Panel/PanelContents.js +92 -23
  61. package/dist/components/Panel/PanelContents.js.map +1 -1
  62. package/dist/components/Panel/PanelTabStack.d.ts.map +1 -1
  63. package/dist/components/Panel/PanelTabStack.js +1 -1
  64. package/dist/components/Panel/PanelTabStack.js.map +1 -1
  65. package/dist/components/PanelSpark.d.ts.map +1 -1
  66. package/dist/components/PanelSpark.js +3 -2
  67. package/dist/components/PanelSpark.js.map +1 -1
  68. package/dist/components/Playground.d.ts.map +1 -1
  69. package/dist/components/Playground.js +10 -4
  70. package/dist/components/Playground.js.map +1 -1
  71. package/dist/components/PromptControls.d.ts.map +1 -1
  72. package/dist/components/PromptControls.js +4 -2
  73. package/dist/components/PromptControls.js.map +1 -1
  74. package/dist/components/SparkLineChart.d.ts.map +1 -1
  75. package/dist/components/SparkLineChart.js +22 -26
  76. package/dist/components/SparkLineChart.js.map +1 -1
  77. package/dist/components/TimeControlBar.d.ts.map +1 -1
  78. package/dist/components/TimeControlBar.js +5 -3
  79. package/dist/components/TimeControlBar.js.map +1 -1
  80. package/dist/components/TokenizedMarkdown.d.ts +23 -0
  81. package/dist/components/TokenizedMarkdown.d.ts.map +1 -0
  82. package/dist/components/TokenizedMarkdown.js +144 -0
  83. package/dist/components/TokenizedMarkdown.js.map +1 -0
  84. package/dist/components/TokenizedMessage.d.ts +6 -0
  85. package/dist/components/TokenizedMessage.d.ts.map +1 -1
  86. package/dist/components/TokenizedMessage.js +20 -19
  87. package/dist/components/TokenizedMessage.js.map +1 -1
  88. package/dist/components/TopBarPlayers.d.ts.map +1 -1
  89. package/dist/components/TopBarPlayers.js +1 -1
  90. package/dist/components/TopBarPlayers.js.map +1 -1
  91. package/dist/components/Tutorial/BrowserNarration.d.ts +55 -0
  92. package/dist/components/Tutorial/BrowserNarration.d.ts.map +1 -0
  93. package/dist/components/Tutorial/BrowserNarration.js +240 -0
  94. package/dist/components/Tutorial/BrowserNarration.js.map +1 -0
  95. package/dist/components/Tutorial/TutorialBox.d.ts +26 -0
  96. package/dist/components/Tutorial/TutorialBox.d.ts.map +1 -0
  97. package/dist/components/Tutorial/TutorialBox.js +239 -0
  98. package/dist/components/Tutorial/TutorialBox.js.map +1 -0
  99. package/dist/components/Tutorial/TutorialDevPanel.d.ts +9 -0
  100. package/dist/components/Tutorial/TutorialDevPanel.d.ts.map +1 -0
  101. package/dist/components/Tutorial/TutorialDevPanel.js +92 -0
  102. package/dist/components/Tutorial/TutorialDevPanel.js.map +1 -0
  103. package/dist/components/Tutorial/TutorialOverlay.d.ts +7 -0
  104. package/dist/components/Tutorial/TutorialOverlay.d.ts.map +1 -0
  105. package/dist/components/Tutorial/TutorialOverlay.js +1132 -0
  106. package/dist/components/Tutorial/TutorialOverlay.js.map +1 -0
  107. package/dist/components/Tutorial/targetRects.d.ts +67 -0
  108. package/dist/components/Tutorial/targetRects.d.ts.map +1 -0
  109. package/dist/components/Tutorial/targetRects.js +241 -0
  110. package/dist/components/Tutorial/targetRects.js.map +1 -0
  111. package/dist/game/Chit.d.ts +7 -0
  112. package/dist/game/Chit.d.ts.map +1 -1
  113. package/dist/game/Chit.js +20 -5
  114. package/dist/game/Chit.js.map +1 -1
  115. package/dist/game/ClientTimeState.d.ts +14 -0
  116. package/dist/game/ClientTimeState.d.ts.map +1 -1
  117. package/dist/game/ClientTimeState.js +17 -0
  118. package/dist/game/ClientTimeState.js.map +1 -1
  119. package/dist/game/Game.d.ts +6 -0
  120. package/dist/game/Game.d.ts.map +1 -1
  121. package/dist/game/GameTheme.d.ts +3 -0
  122. package/dist/game/GameTheme.d.ts.map +1 -1
  123. package/dist/game/GameTheme.js +2 -0
  124. package/dist/game/GameTheme.js.map +1 -1
  125. package/dist/game/Match.d.ts +8 -2
  126. package/dist/game/Match.d.ts.map +1 -1
  127. package/dist/game/Match.js +4 -1
  128. package/dist/game/Match.js.map +1 -1
  129. package/dist/game/Pick.d.ts +2 -0
  130. package/dist/game/Pick.d.ts.map +1 -1
  131. package/dist/game/Pick.js +17 -1
  132. package/dist/game/Pick.js.map +1 -1
  133. package/dist/game/PlayerPromptStatusChit.d.ts +8 -0
  134. package/dist/game/PlayerPromptStatusChit.d.ts.map +1 -1
  135. package/dist/game/PlayerPromptStatusChit.js +5 -1
  136. package/dist/game/PlayerPromptStatusChit.js.map +1 -1
  137. package/dist/game/Prompt.d.ts +15 -0
  138. package/dist/game/Prompt.d.ts.map +1 -1
  139. package/dist/game/Prompt.js +16 -0
  140. package/dist/game/Prompt.js.map +1 -1
  141. package/dist/game/Turn.d.ts +15 -4
  142. package/dist/game/Turn.d.ts.map +1 -1
  143. package/dist/game/Turn.js +173 -60
  144. package/dist/game/Turn.js.map +1 -1
  145. package/dist/game/TurnState.d.ts +12 -1
  146. package/dist/game/TurnState.d.ts.map +1 -1
  147. package/dist/game/TurnState.js +15 -3
  148. package/dist/game/TurnState.js.map +1 -1
  149. package/dist/game/ai/AiClientPrompts.d.ts +20 -3
  150. package/dist/game/ai/AiClientPrompts.d.ts.map +1 -1
  151. package/dist/game/ai/AiClientPrompts.js +42 -6
  152. package/dist/game/ai/AiClientPrompts.js.map +1 -1
  153. package/dist/game/ai/AiPlayerView.js +2 -0
  154. package/dist/game/ai/AiPlayerView.js.map +1 -1
  155. package/dist/game/clientTransport/ClientPrompts.d.ts +20 -1
  156. package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
  157. package/dist/game/clientTransport/ClientPrompts.js +30 -1
  158. package/dist/game/clientTransport/ClientPrompts.js.map +1 -1
  159. package/dist/game/clientTransport/ClientTime.d.ts +13 -0
  160. package/dist/game/clientTransport/ClientTime.d.ts.map +1 -1
  161. package/dist/game/clientTransport/ClientTime.js +51 -11
  162. package/dist/game/clientTransport/ClientTime.js.map +1 -1
  163. package/dist/game/tutorial/TutorialController.d.ts +300 -0
  164. package/dist/game/tutorial/TutorialController.d.ts.map +1 -0
  165. package/dist/game/tutorial/TutorialController.js +1182 -0
  166. package/dist/game/tutorial/TutorialController.js.map +1 -0
  167. package/dist/game/tutorial/TutorialRuntime.d.ts +89 -0
  168. package/dist/game/tutorial/TutorialRuntime.d.ts.map +1 -0
  169. package/dist/game/tutorial/TutorialRuntime.js +261 -0
  170. package/dist/game/tutorial/TutorialRuntime.js.map +1 -0
  171. package/dist/game/tutorial/TutorialTheme.d.ts +28 -0
  172. package/dist/game/tutorial/TutorialTheme.d.ts.map +1 -0
  173. package/dist/game/tutorial/TutorialTheme.js +39 -0
  174. package/dist/game/tutorial/TutorialTheme.js.map +1 -0
  175. package/dist/game/tutorial/allowed.d.ts +2 -0
  176. package/dist/game/tutorial/allowed.d.ts.map +1 -0
  177. package/dist/game/tutorial/allowed.js +119 -0
  178. package/dist/game/tutorial/allowed.js.map +1 -0
  179. package/dist/game/tutorial/checks.d.ts +58 -0
  180. package/dist/game/tutorial/checks.d.ts.map +1 -0
  181. package/dist/game/tutorial/checks.js +144 -0
  182. package/dist/game/tutorial/checks.js.map +1 -0
  183. package/dist/game/tutorial/createDemoMatch.d.ts +47 -0
  184. package/dist/game/tutorial/createDemoMatch.d.ts.map +1 -0
  185. package/dist/game/tutorial/createDemoMatch.js +67 -0
  186. package/dist/game/tutorial/createDemoMatch.js.map +1 -0
  187. package/dist/game/tutorial/defineTutorial.d.ts +353 -0
  188. package/dist/game/tutorial/defineTutorial.d.ts.map +1 -0
  189. package/dist/game/tutorial/defineTutorial.js +86 -0
  190. package/dist/game/tutorial/defineTutorial.js.map +1 -0
  191. package/dist/game/tutorial/runTutorial.d.ts +63 -0
  192. package/dist/game/tutorial/runTutorial.d.ts.map +1 -0
  193. package/dist/game/tutorial/runTutorial.js +273 -0
  194. package/dist/game/tutorial/runTutorial.js.map +1 -0
  195. package/dist/hooks/usePanelNavigation.d.ts +28 -0
  196. package/dist/hooks/usePanelNavigation.d.ts.map +1 -0
  197. package/dist/hooks/usePanelNavigation.js +36 -0
  198. package/dist/hooks/usePanelNavigation.js.map +1 -0
  199. package/dist/hooks/useTimeController.d.ts +2 -1
  200. package/dist/hooks/useTimeController.d.ts.map +1 -1
  201. package/dist/hooks/useTimeController.js +6 -2
  202. package/dist/hooks/useTimeController.js.map +1 -1
  203. package/dist/hooks/useTutorial.d.ts +48 -0
  204. package/dist/hooks/useTutorial.d.ts.map +1 -0
  205. package/dist/hooks/useTutorial.js +16 -0
  206. package/dist/hooks/useTutorial.js.map +1 -0
  207. package/dist/index.d.ts +36 -0
  208. package/dist/index.d.ts.map +1 -1
  209. package/dist/index.html +12 -0
  210. package/dist/index.js +19 -2
  211. package/dist/index.js.map +1 -1
  212. package/dist/main.0792d734cde2c688d5f7.hot-update.js +16991 -0
  213. package/dist/main.0792d734cde2c688d5f7.hot-update.js.map +1 -0
  214. package/dist/main.0792d734cde2c688d5f7.hot-update.json +1 -0
  215. package/dist/pretty-chitty.js +204513 -0
  216. package/dist/pretty-chitty.js.map +1 -0
  217. package/dist/rendering/CameraWrapperPerspective.d.ts +5 -0
  218. package/dist/rendering/CameraWrapperPerspective.d.ts.map +1 -1
  219. package/dist/rendering/CameraWrapperPerspective.js +16 -0
  220. package/dist/rendering/CameraWrapperPerspective.js.map +1 -1
  221. package/dist/rendering/ChitGalleryItemInstance.d.ts +1 -0
  222. package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
  223. package/dist/rendering/ChitGalleryItemInstance.js +12 -0
  224. package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
  225. package/dist/rendering/ChitRenderInstance.d.ts +9 -1
  226. package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
  227. package/dist/rendering/ChitRenderInstance.js +28 -0
  228. package/dist/rendering/ChitRenderInstance.js.map +1 -1
  229. package/dist/rendering/RootChitRenderInstance.d.ts +2 -0
  230. package/dist/rendering/RootChitRenderInstance.d.ts.map +1 -1
  231. package/dist/rendering/RootChitRenderInstance.js +29 -0
  232. package/dist/rendering/RootChitRenderInstance.js.map +1 -1
  233. package/dist/utilities/Annotations.d.ts +15 -0
  234. package/dist/utilities/Annotations.d.ts.map +1 -1
  235. package/dist/utilities/Annotations.js +31 -7
  236. package/dist/utilities/Annotations.js.map +1 -1
  237. package/dist/utilities/CanvasStack/CanvasStack.d.ts +2 -0
  238. package/dist/utilities/CanvasStack/CanvasStack.d.ts.map +1 -1
  239. package/dist/utilities/CanvasStack/CanvasStack.js +4 -0
  240. package/dist/utilities/CanvasStack/CanvasStack.js.map +1 -1
  241. package/dist/utilities/TokenizedText.d.ts +6 -0
  242. package/dist/utilities/TokenizedText.d.ts.map +1 -1
  243. package/dist/utilities/TokenizedText.js.map +1 -1
  244. package/dist/utilities/zIndex.d.ts +1 -0
  245. package/dist/utilities/zIndex.d.ts.map +1 -1
  246. package/dist/utilities/zIndex.js +1 -0
  247. package/dist/utilities/zIndex.js.map +1 -1
  248. package/package.json +3 -2
  249. package/src/library/components/ActionLogDisplay.tsx +1 -0
  250. package/src/library/components/BottomBarButton.tsx +5 -0
  251. package/src/library/components/ContextGalleryDisplay.tsx +2 -0
  252. package/src/library/components/DemoWrapper.tsx +147 -44
  253. package/src/library/components/FullScreenGalleryDisplay.tsx +3 -0
  254. package/src/library/components/Gallery/BuiltItem.ts +30 -9
  255. package/src/library/components/Gallery/GalleryController.ts +72 -1
  256. package/src/library/components/Gallery/GalleryViewer.tsx +54 -10
  257. package/src/library/components/Gallery/LayoutManager.ts +30 -6
  258. package/src/library/components/Gallery/constants.ts +2 -0
  259. package/src/library/components/Gallery/registry.ts +44 -0
  260. package/src/library/components/GameDesigner.tsx +121 -12
  261. package/src/library/components/InlineGalleryDisplay.tsx +5 -0
  262. package/src/library/components/LiveButton.tsx +8 -5
  263. package/src/library/components/MatchViewer.tsx +14 -3
  264. package/src/library/components/Panel/MultiPanel.tsx +21 -0
  265. package/src/library/components/Panel/PanelContents.tsx +70 -1
  266. package/src/library/components/Panel/PanelTabStack.tsx +1 -0
  267. package/src/library/components/PanelSpark.tsx +9 -4
  268. package/src/library/components/Playground.tsx +48 -21
  269. package/src/library/components/PromptControls.tsx +7 -3
  270. package/src/library/components/SparkLineChart.tsx +23 -27
  271. package/src/library/components/TimeControlBar.tsx +5 -3
  272. package/src/library/components/TokenizedMarkdown.tsx +224 -0
  273. package/src/library/components/TokenizedMessage.tsx +28 -32
  274. package/src/library/components/TopBarPlayers.tsx +12 -9
  275. package/src/library/components/Tutorial/BrowserNarration.ts +233 -0
  276. package/src/library/components/Tutorial/TutorialBox.tsx +506 -0
  277. package/src/library/components/Tutorial/TutorialDevPanel.tsx +297 -0
  278. package/src/library/components/Tutorial/TutorialOverlay.tsx +1301 -0
  279. package/src/library/components/Tutorial/targetRects.ts +273 -0
  280. package/src/library/game/Chit.ts +21 -5
  281. package/src/library/game/ClientTimeState.ts +18 -0
  282. package/src/library/game/Game.ts +7 -0
  283. package/src/library/game/GameTheme.ts +4 -0
  284. package/src/library/game/Match.ts +12 -2
  285. package/src/library/game/Pick.ts +16 -1
  286. package/src/library/game/PlayerPromptStatusChit.ts +5 -1
  287. package/src/library/game/Prompt.ts +20 -0
  288. package/src/library/game/Turn.ts +179 -61
  289. package/src/library/game/TurnState.ts +26 -3
  290. package/src/library/game/ai/AI_GUIDE.md +10 -0
  291. package/src/library/game/ai/AiClientPrompts.ts +60 -11
  292. package/src/library/game/ai/AiPlayerView.ts +2 -0
  293. package/src/library/game/clientTransport/ClientPrompts.ts +31 -1
  294. package/src/library/game/clientTransport/ClientTime.ts +54 -13
  295. package/src/library/game/serialize.test.ts +275 -0
  296. package/src/library/game/tutorial/TUTORIAL_GUIDE.md +411 -0
  297. package/src/library/game/tutorial/TutorialController.test.ts +731 -0
  298. package/src/library/game/tutorial/TutorialController.ts +1286 -0
  299. package/src/library/game/tutorial/TutorialRuntime.ts +311 -0
  300. package/src/library/game/tutorial/TutorialTheme.ts +67 -0
  301. package/src/library/game/tutorial/allowed.ts +145 -0
  302. package/src/library/game/tutorial/checks.ts +186 -0
  303. package/src/library/game/tutorial/createDemoMatch.ts +115 -0
  304. package/src/library/game/tutorial/defineTutorial.ts +414 -0
  305. package/src/library/game/tutorial/runTutorial.ts +331 -0
  306. package/src/library/game/undo.test.ts +282 -0
  307. package/src/library/hooks/usePanelNavigation.tsx +65 -0
  308. package/src/library/hooks/useTimeController.tsx +6 -2
  309. package/src/library/hooks/useTutorial.tsx +76 -0
  310. package/src/library/index.ts +57 -2
  311. package/src/library/rendering/CameraWrapperPerspective.ts +17 -0
  312. package/src/library/rendering/ChitGalleryItemInstance.ts +12 -0
  313. package/src/library/rendering/ChitRenderInstance.ts +34 -0
  314. package/src/library/rendering/RootChitRenderInstance.ts +30 -1
  315. package/src/library/utilities/Annotations.ts +35 -7
  316. package/src/library/utilities/CanvasStack/CanvasStack.ts +6 -1
  317. package/src/library/utilities/TokenizedText.ts +6 -0
  318. package/src/library/utilities/zIndex.ts +1 -0
@@ -60,11 +60,15 @@ export function useAnimationSpeedMultiplier() {
60
60
  return speed;
61
61
  }
62
62
 
63
- export function TimeControllerProvider({ children }: { children: ReactNode }) {
63
+ export function TimeControllerProvider({ children, skipReplay = false }: { children: ReactNode; skipReplay?: boolean }) {
64
64
  const connection = useConnection();
65
65
  const playerId = usePlayerId();
66
66
  const game = useGame();
67
- const [clientTimeState] = useState<ClientTimeState>(new ClientTimeState());
67
+ const [clientTimeState] = useState<ClientTimeState>(() => {
68
+ const state = new ClientTimeState();
69
+ state.skipInitialReplay = skipReplay;
70
+ return state;
71
+ });
68
72
  const [clientTime, setClientTime] = useState<ClientTime | null>(null);
69
73
  const [clientPrompts, setClientPrompts] = useState<ClientPrompts<any, any> | undefined>(undefined);
70
74
  const [clientStatus, setClientStatus] = useState<ClientStatus<any, any> | undefined>(undefined);
@@ -0,0 +1,76 @@
1
+ import React, { createContext, ReactNode, useContext, useMemo, useState } from "react";
2
+ import { EventChannel } from "../utilities/EventChannel";
3
+ import { TutorialSpec } from "../game/tutorial/defineTutorial";
4
+ import { TutorialController, TutorialEvent } from "../game/tutorial/TutorialController";
5
+ import { TutorialRuntime } from "../game/tutorial/TutorialRuntime";
6
+ import { TutorialTheme } from "../game/tutorial/TutorialTheme";
7
+ import { MatchAiControls } from "../game/Match";
8
+
9
+ export type TutorialDevSettings = {
10
+ showTargetRects: boolean;
11
+ };
12
+
13
+ export type TutorialContextValue = {
14
+ spec: TutorialSpec<any, any>;
15
+ runtime: TutorialRuntime<any, any>;
16
+ themeOverrides?: Partial<TutorialTheme>;
17
+ ai?: MatchAiControls;
18
+ onEvent?: (e: TutorialEvent) => void;
19
+ /** Set by the overlay once it has built the controller (it needs the match view, which lives inside MatchViewer) */
20
+ controller: EventChannel<TutorialController<any, any> | undefined>;
21
+ dev: EventChannel<TutorialDevSettings>;
22
+ /** Start muted (dev panel toggle) */
23
+ muted: EventChannel<boolean>;
24
+ /** Step to start on (dev panel restarts, rewinds) */
25
+ startAt: number;
26
+ /** Start the script without the Start tap (after a rewind or a dev restart) */
27
+ autoStart: boolean;
28
+ /** Start held (after Back): silent until the player presses Play */
29
+ startPaused: boolean;
30
+ /** Serializes the match for a step snapshot; undefined when the host cannot rebuild the match */
31
+ snapshot?: () => unknown;
32
+ /** Puts the match back to the snapshot taken when `stepId` went live; false when there is none */
33
+ rewind?: (stepId: string) => Promise<boolean>;
34
+ };
35
+
36
+ const TutorialContext = createContext<TutorialContextValue | undefined>(undefined);
37
+
38
+ /** The running tutorial, or undefined when the match has none. */
39
+ export function useTutorial(): TutorialContextValue | undefined {
40
+ return useContext(TutorialContext);
41
+ }
42
+
43
+ export function TutorialProvider({
44
+ spec,
45
+ runtime,
46
+ themeOverrides,
47
+ ai,
48
+ onEvent,
49
+ startAt = 0,
50
+ autoStart = false,
51
+ startPaused = false,
52
+ snapshot,
53
+ rewind,
54
+ children,
55
+ }: {
56
+ spec: TutorialSpec<any, any>;
57
+ runtime: TutorialRuntime<any, any>;
58
+ themeOverrides?: Partial<TutorialTheme>;
59
+ ai?: MatchAiControls;
60
+ onEvent?: (e: TutorialEvent) => void;
61
+ startAt?: number;
62
+ autoStart?: boolean;
63
+ startPaused?: boolean;
64
+ snapshot?: () => unknown;
65
+ rewind?: (stepId: string) => Promise<boolean>;
66
+ children: ReactNode;
67
+ }) {
68
+ const [controller] = useState(() => new EventChannel<TutorialController<any, any> | undefined>(undefined));
69
+ const [dev] = useState(() => new EventChannel<TutorialDevSettings>({ showTargetRects: false }));
70
+ const [muted] = useState(() => new EventChannel<boolean>(false));
71
+ const value = useMemo<TutorialContextValue>(
72
+ () => ({ spec, runtime, themeOverrides, ai, onEvent, controller, dev, muted, startAt, autoStart, startPaused, snapshot, rewind }),
73
+ [spec, runtime, themeOverrides, ai, onEvent, controller, dev, muted, startAt, autoStart, startPaused, snapshot, rewind],
74
+ );
75
+ return <TutorialContext.Provider value={value}>{children}</TutorialContext.Provider>;
76
+ }
@@ -62,6 +62,60 @@ export { simulateMatches } from "./game/ai/simulateMatches";
62
62
  /** @group AI */
63
63
  export type { SimulateMatchesOptions, SimulatedMatch, SimulationReport } from "./game/ai/simulateMatches";
64
64
 
65
+ /** @group Tutorials */
66
+ export { defineTutorial, listTutorials, findTutorial, splitSentences } from "./game/tutorial/defineTutorial";
67
+ /** @group Tutorials */
68
+ export type {
69
+ TutorialSpec,
70
+ TutorialStep,
71
+ TutorialMatchSetup,
72
+ TutorialContext,
73
+ TutorialSummary,
74
+ Checker,
75
+ CheckResult,
76
+ ChitSelector,
77
+ Target,
78
+ UiTarget,
79
+ Focus,
80
+ Cue,
81
+ BoxPlacement,
82
+ BoxAnchor,
83
+ ForcedDecision,
84
+ AllowedAction,
85
+ GalleryCommand,
86
+ Pose,
87
+ TimelineCommand,
88
+ TutorialGalleryState,
89
+ } from "./game/tutorial/defineTutorial";
90
+ /** @group Tutorials */
91
+ export { checks } from "./game/tutorial/checks";
92
+ /** @group Tutorials */
93
+ export { runTutorial } from "./game/tutorial/runTutorial";
94
+ /** @group Tutorials */
95
+ export type { RunTutorialOptions, RunTutorialResult } from "./game/tutorial/runTutorial";
96
+ /** @group Tutorials */
97
+ export { createDemoMatch } from "./game/tutorial/createDemoMatch";
98
+ /** @group Tutorials */
99
+ export type { DemoMatch, CreateDemoMatchOptions } from "./game/tutorial/createDemoMatch";
100
+ /** @group Tutorials */
101
+ export { TutorialController } from "./game/tutorial/TutorialController";
102
+ /** @group Tutorials */
103
+ export type { TutorialEvent, TutorialStatus, TutorialView, NarrationPlayer } from "./game/tutorial/TutorialController";
104
+ /** @group Tutorials */
105
+ export { TutorialRuntime } from "./game/tutorial/TutorialRuntime";
106
+ /** @group Tutorials */
107
+ export type { TutorialTheme } from "./game/tutorial/TutorialTheme";
108
+ /** @group Tutorials */
109
+ export { resolveTutorialTheme } from "./game/tutorial/TutorialTheme";
110
+ /** @group Tutorials */
111
+ export { TokenizedMarkdown } from "./components/TokenizedMarkdown";
112
+ /** @group Tutorials */
113
+ export { TutorialDevPanel } from "./components/Tutorial/TutorialDevPanel";
114
+ /** @group Supporting Types */
115
+ export type { RngSource } from "./game/TurnState";
116
+ /** @group Supporting Types */
117
+ export type { MatchConfig } from "./game/Match";
118
+
65
119
  /** @group Buttons */
66
120
  export { GameButton, DynamicGameButton, ToggleGalleryButton } from "./game/GameButton";
67
121
 
@@ -115,9 +169,10 @@ export type { IPlayerInfo, AiSeatInfo } from "./game/PlayerInfo";
115
169
  /** @internal */
116
170
  /** @group Supporting Types */
117
171
  export { MatchViewer } from "./components/MatchViewer";
118
- /** @internal */
119
- /** @group Supporting Types */
172
+ /** @group Tutorials */
120
173
  export { DemoWrapper } from "./components/DemoWrapper";
174
+ /** @group Tutorials */
175
+ export type { DemoWrapperProps } from "./components/DemoWrapper";
121
176
  /** @internal */
122
177
  /** @group Supporting Types */
123
178
  export { Match, MatchAiControls } from "./game/Match";
@@ -151,6 +151,23 @@ export class CameraWrapperPerspective {
151
151
  this.adjust(this.bbox, !animate);
152
152
  }
153
153
 
154
+ /**
155
+ * Zooms to `zoom` (clamped to the camera's range) and brings the point at panel pixel (x, y) to the
156
+ * middle of the panel, as far as panning allows. Animated. Zoom 1 is the whole table.
157
+ */
158
+ public focusOn(x: number, y: number, zoom: number): void {
159
+ const z = Math.max(1, Math.min(zoom, this.cameraSpec.maxZoom));
160
+ // A point on screen sits at (content * zoom + offset) from the middle: keep the content under
161
+ // (x, y) and move it to the middle
162
+ const sx = x - this.width / 2;
163
+ const sy = y - this.height / 2;
164
+ this.current.x = -(sx - this.current.x) * (z / this.current.z);
165
+ this.current.y = -(sy - this.current.y) * (z / this.current.z);
166
+ this.current.z = z;
167
+ this.lockZoom();
168
+ this.adjust(this.bbox, false);
169
+ }
170
+
154
171
  private lockZoom() {
155
172
  const maxZoom = this.cameraSpec.maxZoom;
156
173
  if (this.current.z <= 1) {
@@ -26,6 +26,7 @@ export class ChitGalleryItemInstance implements GalleryItem {
26
26
  shortSummaryRenderingOptions?: RichTextRenderOptionsParameters;
27
27
 
28
28
  private sceneWrapper: SceneWrapper | undefined;
29
+ private creatingMesh = false;
29
30
 
30
31
  constructor(public chit: Chit) {
31
32
  this.id = chit.id ?? "no id";
@@ -82,6 +83,14 @@ export class ChitGalleryItemInstance implements GalleryItem {
82
83
  const renderInstance = this.chit.renderInstance;
83
84
  const g = new Group();
84
85
  if (renderInstance) {
86
+ // a refresh re-renders the chit, which would ask us to rebuild while we're mid-build
87
+ this.creatingMesh = true;
88
+ try {
89
+ renderInstance.refreshDisposedTextures();
90
+ } finally {
91
+ this.creatingMesh = false;
92
+ }
93
+
85
94
  const mesh = this.cloneWithUserData(renderInstance.group) ?? new Group();
86
95
  mesh.visible = true;
87
96
  mesh.rotation.set(0, 0, 0);
@@ -101,6 +110,9 @@ export class ChitGalleryItemInstance implements GalleryItem {
101
110
  }
102
111
 
103
112
  update() {
113
+ if (this.creatingMesh) {
114
+ return;
115
+ }
104
116
  this.cbs.forEach((cb) => cb());
105
117
  }
106
118
 
@@ -5,6 +5,7 @@ import {
5
5
  Group,
6
6
  Mesh,
7
7
  MeshBasicMaterial,
8
+ Object3D,
8
9
  Plane,
9
10
  Quaternion,
10
11
  Raycaster,
@@ -18,6 +19,7 @@ import { Easing, Tween, Group as TweenGroup } from "@tweenjs/tween.js";
18
19
  import { RootChitRenderInstance } from "./RootChitRenderInstance";
19
20
  import { fixBbox } from "../utilities/BboxUtils";
20
21
  import { ChitGalleryItemInstance } from "./ChitGalleryItemInstance";
22
+ import { CanvasStack } from "../utilities/CanvasStack/CanvasStack";
21
23
 
22
24
  const LINE_COLOR = new MeshBasicMaterial({ color: 0xff0000, wireframe: true, wireframeLinewidth: 2 });
23
25
  const CLICK_LINE_COLOR = new MeshBasicMaterial({ color: 0xffff00, wireframe: true, wireframeLinewidth: 2 });
@@ -50,6 +52,11 @@ export class ChitRenderInstance {
50
52
  // rendering info
51
53
  protected renderSpec: ChitRenderSpec | null = null;
52
54
 
55
+ /** The chit's own drawn object (not its children or ornaments), for exact hit tests on a tap. */
56
+ public get hitObject(): Object3D | undefined {
57
+ return this.renderSpec?.object ?? undefined;
58
+ }
59
+
53
60
  // threejs info
54
61
  public group = new Group(); // group storing the visible meshes. Will tween
55
62
  protected targetAnchorPoints = new Map<OwnerOriginPosition | string, Vector3>();
@@ -453,6 +460,33 @@ export class ChitRenderInstance {
453
460
  return this._galleryItem;
454
461
  }
455
462
 
463
+ /**
464
+ * Hidden chits (e.g. inside a deck or bag) aren't counted by the TextureReferenceCounter, so their textures get
465
+ * reclaimed while the render spec still points at them. Galleries clone that spec, so re-render first if stale.
466
+ */
467
+ public refreshDisposedTextures() {
468
+ if (this.usesDisposedTexture()) {
469
+ this.refresh();
470
+ }
471
+ [...this.childrenRenderInstances].forEach((child) => child.refreshDisposedTextures());
472
+ }
473
+
474
+ private usesDisposedTexture() {
475
+ let disposed = false;
476
+ [this.renderSpec?.object, ...(this.renderSpec?.ornaments ?? [])].forEach((root) =>
477
+ root?.traverse((obj) => {
478
+ if (!disposed && obj instanceof Mesh) {
479
+ const materials = Array.isArray(obj.material) ? obj.material : [obj.material];
480
+ disposed = materials.some((m) => {
481
+ const map = (m as MeshBasicMaterial | undefined)?.map;
482
+ return !!map && CanvasStack.isDisposedTexture(map);
483
+ });
484
+ }
485
+ }),
486
+ );
487
+ return disposed;
488
+ }
489
+
456
490
  public destroyGalleryItem() {
457
491
  if (this._galleryItem) {
458
492
  this._galleryItem.destroy();
@@ -1,7 +1,7 @@
1
1
  import { Tween, Group as TweenGroup } from "@tweenjs/tween.js";
2
2
  import { ChitRenderInstance } from "./ChitRenderInstance";
3
3
  import { Chit } from "../game/Chit";
4
- import { Box3, Group, Object3D, Plane, Raycaster, Vector2, Vector3 } from "three";
4
+ import { Box3, Group, Mesh, Object3D, Plane, Raycaster, Vector2, Vector3 } from "three";
5
5
  import { CameraWrapperPerspective } from "./CameraWrapperPerspective";
6
6
  import { LightWrapper } from "./LightWrapper";
7
7
  import { ModalState } from "../game/ModalState";
@@ -331,6 +331,11 @@ export class RootChitRenderInstance extends ChitRenderInstance implements Textur
331
331
  precision: number,
332
332
  ): Chit[] {
333
333
  const result = new Map<Chit, number>();
334
+ // Box hits that the ray also hits on the chit's real shape. A clickbox is the axis-aligned box around the whole
335
+ // object, so a large irregular piece (a sea area, a province) claims every tap inside its rectangle, and
336
+ // neighbours whose rectangles overlap would all be offered in a gallery. See the end of this function.
337
+ const exact = new Map<Chit, number>();
338
+ const hasShape = new Map<Chit, boolean>();
334
339
  const chitRenderInstances: ChitRenderInstance[] = [];
335
340
  const threeJsToChitLookup: { [threejsId: number]: Chit } = {};
336
341
 
@@ -371,10 +376,28 @@ export class RootChitRenderInstance extends ChitRenderInstance implements Textur
371
376
  const c = threeJsToChitLookup[id];
372
377
  if (filter(c)) {
373
378
  result.set(c, Math.min(result.get(c) ?? r, r));
379
+ const shape = c.renderInstance?.hitObject;
380
+ if (!hasShape.has(c)) {
381
+ let meshes = false;
382
+ shape?.traverse((o) => {
383
+ if ((o as Mesh).isMesh) meshes = true;
384
+ });
385
+ hasShape.set(c, meshes);
386
+ }
387
+ if (shape && hasShape.get(c) && (exact.get(c) ?? Infinity) > r && raycaster.intersectObject(shape, true).length) {
388
+ exact.set(c, r);
389
+ }
374
390
  }
375
391
  }
376
392
  }
377
393
  }
394
+ // Keep the chits whose real shape was hit, plus those with no mesh of their own to test (an empty group that
395
+ // is clicked through its children). If no shape was hit at all (a tap in the gap between pieces, within the
396
+ // finger tolerance), fall back to the boxes so a near miss still lands. Nearest first.
397
+ const precise = [...result.keys()].filter((c) => exact.has(c) || !hasShape.get(c));
398
+ if (precise.length && precise.length < result.size) {
399
+ return precise.sort((a, b) => (exact.get(a) ?? result.get(a)!) - (exact.get(b) ?? result.get(b)!));
400
+ }
378
401
  return [...result.keys()];
379
402
  }
380
403
 
@@ -465,6 +488,12 @@ export class RootChitRenderInstance extends ChitRenderInstance implements Textur
465
488
  this.markDirty();
466
489
  }
467
490
 
491
+ /** Zooms the camera to `zoom` around panel pixel (x, y), bringing it to the middle (see `CameraWrapperPerspective.focusOn`) */
492
+ public focusCamera(x: number, y: number, zoom: number) {
493
+ this.cameraWrapper.focusOn(x, y, zoom);
494
+ this.markDirty();
495
+ }
496
+
468
497
  public get cameraZoom() {
469
498
  return this.cameraWrapper.zoom;
470
499
  }
@@ -23,6 +23,11 @@ export interface SelectableConfig {
23
23
  label: string;
24
24
  /** List of possible choices for this property */
25
25
  choices: SelectableChoice[];
26
+ /**
27
+ * When true the property holds any number of the choices' ids (a `string[]`, e.g. the expansion
28
+ * modules a match plays with) rather than exactly one. Defaults to false.
29
+ */
30
+ multiple?: boolean;
26
31
  }
27
32
 
28
33
  /**
@@ -203,17 +208,30 @@ export function FixChildOutlets(instance: Chit) {
203
208
 
204
209
  if (obj?.__orderedOutlets) {
205
210
  Object.entries(obj.__orderedOutlets).forEach(([key, prop]: [key: any, prop: any]) => {
206
- const existingValue = (instance as any)[key];
207
- const v = existingValue || prop?.initializer?.apply(instance, []);
208
- if (v) {
209
- v.outletName = key;
210
- v.parent = instance;
211
+ if (seenKeys.has(`ordered:${key}`)) {
212
+ return;
211
213
  }
214
+ seenKeys.add(`ordered:${key}`);
215
+ const existingValue = (instance as any)[key];
216
+ let v = existingValue || prop?.initializer?.apply(instance, []);
217
+ const adopt = (outlet: any) => {
218
+ if (outlet instanceof OrderedOutlet) {
219
+ outlet.outletName = key;
220
+ outlet.parent = instance;
221
+ }
222
+ };
223
+ adopt(v);
224
+ // An accessor rather than a data property: with TypeScript/esbuild class fields (no babel
225
+ // initializer capture) the subclass constructor assigns `new OrderedOutlet()` *after* this
226
+ // runs, and the setter adopts that outlet instead of leaving it parentless.
212
227
  Object.defineProperty(instance, key, {
213
228
  enumerable: true,
214
- writable: true,
215
229
  configurable: true,
216
- value: v,
230
+ get: () => v,
231
+ set: (newValue: any) => {
232
+ v = newValue;
233
+ adopt(v);
234
+ },
217
235
  });
218
236
  });
219
237
  }
@@ -237,6 +255,16 @@ export function FixChildOutlets(instance: Chit) {
237
255
  * ]
238
256
  * })
239
257
  * public difficulty: string = "medium";
258
+ *
259
+ * @Selectable({
260
+ * label: "Expansions",
261
+ * multiple: true,
262
+ * choices: [
263
+ * { id: "rivers", label: "Rivers" },
264
+ * { id: "traders", label: "Traders & Builders" },
265
+ * ],
266
+ * })
267
+ * public expansions: string[] = [];
240
268
  * }
241
269
  * ```
242
270
  *
@@ -332,7 +332,12 @@ export class CanvasStack implements IUpdatingCanvas {
332
332
  CanvasStack._liveStacks.delete(canvasStack);
333
333
  });
334
334
 
335
- public static materialDisposer = new ThreeDisposer<Material>((material) => {
335
+ /** True once the disposer has reclaimed this texture; anything still drawing with it renders blank. */
336
+ public static isDisposedTexture(texture: Texture) {
337
+ return !!_NOTHING_CANVAS && texture.source.data === _NOTHING_CANVAS;
338
+ }
339
+
340
+ public static materialDisposer =new ThreeDisposer<Material>((material) => {
336
341
  material.dispose();
337
342
  });
338
343
 
@@ -11,6 +11,12 @@ export interface TokenDefinition {
11
11
  image?: string | ImageSpec;
12
12
  label?: string;
13
13
  color?: string;
14
+ /**
15
+ * How far the image extends above and below its line of text, as a fraction of the font size. The image grows by
16
+ * twice this amount without pushing lines apart, so a large value can overlap neighbouring lines. Defaults to 0.2,
17
+ * or 0 when the token has a `color` (so the image stays inside the colored background).
18
+ */
19
+ imageBleed?: number;
14
20
  /** Plain-text representation of this token, for places that cannot render images or styling. */
15
21
  text?: string;
16
22
  }
@@ -13,3 +13,4 @@ export const ZINDEX_MATCH_END_DISPLAY = 150;
13
13
  export const ZINDEX_GALLERY_VISIBLE = 160;
14
14
  export const ZINDEX_TOP_BAR_HEADER = 210;
15
15
  export const ZINDEX_TOP_BAR_BODY = 200;
16
+ export const ZINDEX_TUTORIAL = 250;