@pretty-chitty/core 2.0.0 → 2.3.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 (377) 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 +33 -2
  13. package/dist/components/DemoWrapper.d.ts.map +1 -1
  14. package/dist/components/DemoWrapper.js +77 -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 +16 -2
  20. package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
  21. package/dist/components/Gallery/BuiltItem.js +92 -16
  22. package/dist/components/Gallery/BuiltItem.js.map +1 -1
  23. package/dist/components/Gallery/GalleryController.d.ts +26 -0
  24. package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
  25. package/dist/components/Gallery/GalleryController.js +106 -6
  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 +139 -12
  30. package/dist/components/Gallery/GalleryViewer.js.map +1 -1
  31. package/dist/components/Gallery/LayoutManager.d.ts +10 -0
  32. package/dist/components/Gallery/LayoutManager.d.ts.map +1 -1
  33. package/dist/components/Gallery/LayoutManager.js +49 -3
  34. package/dist/components/Gallery/LayoutManager.js.map +1 -1
  35. package/dist/components/Gallery/constants.d.ts +6 -0
  36. package/dist/components/Gallery/constants.d.ts.map +1 -1
  37. package/dist/components/Gallery/constants.js +6 -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/Gallery/types.d.ts +5 -0
  44. package/dist/components/Gallery/types.d.ts.map +1 -1
  45. package/dist/components/GameDesigner.d.ts.map +1 -1
  46. package/dist/components/GameDesigner.js +84 -10
  47. package/dist/components/GameDesigner.js.map +1 -1
  48. package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
  49. package/dist/components/InlineGalleryDisplay.js +35 -8
  50. package/dist/components/InlineGalleryDisplay.js.map +1 -1
  51. package/dist/components/LiveButton.d.ts.map +1 -1
  52. package/dist/components/LiveButton.js +5 -2
  53. package/dist/components/LiveButton.js.map +1 -1
  54. package/dist/components/MatchViewer.d.ts +6 -1
  55. package/dist/components/MatchViewer.d.ts.map +1 -1
  56. package/dist/components/MatchViewer.js +9 -3
  57. package/dist/components/MatchViewer.js.map +1 -1
  58. package/dist/components/Panel/ExternalDrag.d.ts +30 -0
  59. package/dist/components/Panel/ExternalDrag.d.ts.map +1 -0
  60. package/dist/components/Panel/ExternalDrag.js +87 -0
  61. package/dist/components/Panel/ExternalDrag.js.map +1 -0
  62. package/dist/components/Panel/MultiPanel.d.ts.map +1 -1
  63. package/dist/components/Panel/MultiPanel.js +18 -0
  64. package/dist/components/Panel/MultiPanel.js.map +1 -1
  65. package/dist/components/Panel/PanelContents.d.ts +3 -0
  66. package/dist/components/Panel/PanelContents.d.ts.map +1 -1
  67. package/dist/components/Panel/PanelContents.js +116 -23
  68. package/dist/components/Panel/PanelContents.js.map +1 -1
  69. package/dist/components/Panel/PanelTabStack.d.ts.map +1 -1
  70. package/dist/components/Panel/PanelTabStack.js +1 -1
  71. package/dist/components/Panel/PanelTabStack.js.map +1 -1
  72. package/dist/components/PanelSpark.d.ts.map +1 -1
  73. package/dist/components/PanelSpark.js +6 -3
  74. package/dist/components/PanelSpark.js.map +1 -1
  75. package/dist/components/Playground.d.ts.map +1 -1
  76. package/dist/components/Playground.js +10 -4
  77. package/dist/components/Playground.js.map +1 -1
  78. package/dist/components/PromptControls.d.ts.map +1 -1
  79. package/dist/components/PromptControls.js +4 -2
  80. package/dist/components/PromptControls.js.map +1 -1
  81. package/dist/components/SparkLineChart.d.ts.map +1 -1
  82. package/dist/components/SparkLineChart.js +22 -26
  83. package/dist/components/SparkLineChart.js.map +1 -1
  84. package/dist/components/TimeControlBar.d.ts.map +1 -1
  85. package/dist/components/TimeControlBar.js +5 -3
  86. package/dist/components/TimeControlBar.js.map +1 -1
  87. package/dist/components/TokenizedMarkdown.d.ts +23 -0
  88. package/dist/components/TokenizedMarkdown.d.ts.map +1 -0
  89. package/dist/components/TokenizedMarkdown.js +144 -0
  90. package/dist/components/TokenizedMarkdown.js.map +1 -0
  91. package/dist/components/TokenizedMessage.d.ts +6 -0
  92. package/dist/components/TokenizedMessage.d.ts.map +1 -1
  93. package/dist/components/TokenizedMessage.js +20 -19
  94. package/dist/components/TokenizedMessage.js.map +1 -1
  95. package/dist/components/TopBar.d.ts.map +1 -1
  96. package/dist/components/TopBar.js +3 -1
  97. package/dist/components/TopBar.js.map +1 -1
  98. package/dist/components/TopBarPlayers.d.ts.map +1 -1
  99. package/dist/components/TopBarPlayers.js +2 -2
  100. package/dist/components/TopBarPlayers.js.map +1 -1
  101. package/dist/components/Tutorial/BrowserNarration.d.ts +55 -0
  102. package/dist/components/Tutorial/BrowserNarration.d.ts.map +1 -0
  103. package/dist/components/Tutorial/BrowserNarration.js +240 -0
  104. package/dist/components/Tutorial/BrowserNarration.js.map +1 -0
  105. package/dist/components/Tutorial/TutorialBox.d.ts +26 -0
  106. package/dist/components/Tutorial/TutorialBox.d.ts.map +1 -0
  107. package/dist/components/Tutorial/TutorialBox.js +239 -0
  108. package/dist/components/Tutorial/TutorialBox.js.map +1 -0
  109. package/dist/components/Tutorial/TutorialDevPanel.d.ts +9 -0
  110. package/dist/components/Tutorial/TutorialDevPanel.d.ts.map +1 -0
  111. package/dist/components/Tutorial/TutorialDevPanel.js +92 -0
  112. package/dist/components/Tutorial/TutorialDevPanel.js.map +1 -0
  113. package/dist/components/Tutorial/TutorialOverlay.d.ts +7 -0
  114. package/dist/components/Tutorial/TutorialOverlay.d.ts.map +1 -0
  115. package/dist/components/Tutorial/TutorialOverlay.js +1147 -0
  116. package/dist/components/Tutorial/TutorialOverlay.js.map +1 -0
  117. package/dist/components/Tutorial/targetRects.d.ts +67 -0
  118. package/dist/components/Tutorial/targetRects.d.ts.map +1 -0
  119. package/dist/components/Tutorial/targetRects.js +241 -0
  120. package/dist/components/Tutorial/targetRects.js.map +1 -0
  121. package/dist/components/Viewer.d.ts.map +1 -1
  122. package/dist/components/Viewer.js +1 -0
  123. package/dist/components/Viewer.js.map +1 -1
  124. package/dist/game/Chit.d.ts +10 -1
  125. package/dist/game/Chit.d.ts.map +1 -1
  126. package/dist/game/Chit.js +24 -6
  127. package/dist/game/Chit.js.map +1 -1
  128. package/dist/game/ClientTimeState.d.ts +14 -0
  129. package/dist/game/ClientTimeState.d.ts.map +1 -1
  130. package/dist/game/ClientTimeState.js +17 -0
  131. package/dist/game/ClientTimeState.js.map +1 -1
  132. package/dist/game/GalleryItemChitChildrenSource.d.ts +1 -0
  133. package/dist/game/GalleryItemChitChildrenSource.d.ts.map +1 -1
  134. package/dist/game/GalleryItemChitChildrenSource.js +1 -0
  135. package/dist/game/GalleryItemChitChildrenSource.js.map +1 -1
  136. package/dist/game/GalleryItemRawSource.d.ts +1 -0
  137. package/dist/game/GalleryItemRawSource.d.ts.map +1 -1
  138. package/dist/game/GalleryItemRawSource.js +1 -0
  139. package/dist/game/GalleryItemRawSource.js.map +1 -1
  140. package/dist/game/Game.d.ts +6 -0
  141. package/dist/game/Game.d.ts.map +1 -1
  142. package/dist/game/GameButton.d.ts +8 -0
  143. package/dist/game/GameButton.d.ts.map +1 -1
  144. package/dist/game/GameButton.js +13 -1
  145. package/dist/game/GameButton.js.map +1 -1
  146. package/dist/game/GameTheme.d.ts +3 -0
  147. package/dist/game/GameTheme.d.ts.map +1 -1
  148. package/dist/game/GameTheme.js +2 -0
  149. package/dist/game/GameTheme.js.map +1 -1
  150. package/dist/game/Match.d.ts +8 -2
  151. package/dist/game/Match.d.ts.map +1 -1
  152. package/dist/game/Match.js +4 -1
  153. package/dist/game/Match.js.map +1 -1
  154. package/dist/game/ModalState.d.ts +3 -0
  155. package/dist/game/ModalState.d.ts.map +1 -1
  156. package/dist/game/ModalState.js +2 -0
  157. package/dist/game/ModalState.js.map +1 -1
  158. package/dist/game/Pick.d.ts +2 -0
  159. package/dist/game/Pick.d.ts.map +1 -1
  160. package/dist/game/Pick.js +18 -4
  161. package/dist/game/Pick.js.map +1 -1
  162. package/dist/game/PlayerPromptStatusChit.d.ts +8 -0
  163. package/dist/game/PlayerPromptStatusChit.d.ts.map +1 -1
  164. package/dist/game/PlayerPromptStatusChit.js +6 -4
  165. package/dist/game/PlayerPromptStatusChit.js.map +1 -1
  166. package/dist/game/Prompt.d.ts +18 -1
  167. package/dist/game/Prompt.d.ts.map +1 -1
  168. package/dist/game/Prompt.js +29 -1
  169. package/dist/game/Prompt.js.map +1 -1
  170. package/dist/game/SparkChit.d.ts +6 -0
  171. package/dist/game/SparkChit.d.ts.map +1 -1
  172. package/dist/game/SparkChit.js +8 -0
  173. package/dist/game/SparkChit.js.map +1 -1
  174. package/dist/game/Turn.d.ts +17 -6
  175. package/dist/game/Turn.d.ts.map +1 -1
  176. package/dist/game/Turn.js +179 -69
  177. package/dist/game/Turn.js.map +1 -1
  178. package/dist/game/TurnState.d.ts +12 -1
  179. package/dist/game/TurnState.d.ts.map +1 -1
  180. package/dist/game/TurnState.js +15 -3
  181. package/dist/game/TurnState.js.map +1 -1
  182. package/dist/game/ai/AiClientPrompts.d.ts +20 -3
  183. package/dist/game/ai/AiClientPrompts.d.ts.map +1 -1
  184. package/dist/game/ai/AiClientPrompts.js +42 -6
  185. package/dist/game/ai/AiClientPrompts.js.map +1 -1
  186. package/dist/game/ai/AiPlayerView.js +2 -0
  187. package/dist/game/ai/AiPlayerView.js.map +1 -1
  188. package/dist/game/clientTransport/ClientPrompts.d.ts +22 -1
  189. package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
  190. package/dist/game/clientTransport/ClientPrompts.js +72 -5
  191. package/dist/game/clientTransport/ClientPrompts.js.map +1 -1
  192. package/dist/game/clientTransport/ClientTime.d.ts +13 -0
  193. package/dist/game/clientTransport/ClientTime.d.ts.map +1 -1
  194. package/dist/game/clientTransport/ClientTime.js +71 -12
  195. package/dist/game/clientTransport/ClientTime.js.map +1 -1
  196. package/dist/game/tutorial/TutorialController.d.ts +308 -0
  197. package/dist/game/tutorial/TutorialController.d.ts.map +1 -0
  198. package/dist/game/tutorial/TutorialController.js +1195 -0
  199. package/dist/game/tutorial/TutorialController.js.map +1 -0
  200. package/dist/game/tutorial/TutorialRuntime.d.ts +89 -0
  201. package/dist/game/tutorial/TutorialRuntime.d.ts.map +1 -0
  202. package/dist/game/tutorial/TutorialRuntime.js +261 -0
  203. package/dist/game/tutorial/TutorialRuntime.js.map +1 -0
  204. package/dist/game/tutorial/TutorialTheme.d.ts +28 -0
  205. package/dist/game/tutorial/TutorialTheme.d.ts.map +1 -0
  206. package/dist/game/tutorial/TutorialTheme.js +39 -0
  207. package/dist/game/tutorial/TutorialTheme.js.map +1 -0
  208. package/dist/game/tutorial/allowed.d.ts +2 -0
  209. package/dist/game/tutorial/allowed.d.ts.map +1 -0
  210. package/dist/game/tutorial/allowed.js +119 -0
  211. package/dist/game/tutorial/allowed.js.map +1 -0
  212. package/dist/game/tutorial/checks.d.ts +58 -0
  213. package/dist/game/tutorial/checks.d.ts.map +1 -0
  214. package/dist/game/tutorial/checks.js +144 -0
  215. package/dist/game/tutorial/checks.js.map +1 -0
  216. package/dist/game/tutorial/createDemoMatch.d.ts +47 -0
  217. package/dist/game/tutorial/createDemoMatch.d.ts.map +1 -0
  218. package/dist/game/tutorial/createDemoMatch.js +67 -0
  219. package/dist/game/tutorial/createDemoMatch.js.map +1 -0
  220. package/dist/game/tutorial/defineTutorial.d.ts +353 -0
  221. package/dist/game/tutorial/defineTutorial.d.ts.map +1 -0
  222. package/dist/game/tutorial/defineTutorial.js +86 -0
  223. package/dist/game/tutorial/defineTutorial.js.map +1 -0
  224. package/dist/game/tutorial/runTutorial.d.ts +64 -0
  225. package/dist/game/tutorial/runTutorial.d.ts.map +1 -0
  226. package/dist/game/tutorial/runTutorial.js +293 -0
  227. package/dist/game/tutorial/runTutorial.js.map +1 -0
  228. package/dist/hooks/usePanelNavigation.d.ts +28 -0
  229. package/dist/hooks/usePanelNavigation.d.ts.map +1 -0
  230. package/dist/hooks/usePanelNavigation.js +36 -0
  231. package/dist/hooks/usePanelNavigation.js.map +1 -0
  232. package/dist/hooks/useTimeController.d.ts +4 -1
  233. package/dist/hooks/useTimeController.d.ts.map +1 -1
  234. package/dist/hooks/useTimeController.js +10 -2
  235. package/dist/hooks/useTimeController.js.map +1 -1
  236. package/dist/hooks/useTutorial.d.ts +51 -0
  237. package/dist/hooks/useTutorial.d.ts.map +1 -0
  238. package/dist/hooks/useTutorial.js +16 -0
  239. package/dist/hooks/useTutorial.js.map +1 -0
  240. package/dist/index.d.ts +37 -0
  241. package/dist/index.d.ts.map +1 -1
  242. package/dist/index.js +19 -2
  243. package/dist/index.js.map +1 -1
  244. package/dist/rendering/CameraWrapperPerspective.d.ts +5 -0
  245. package/dist/rendering/CameraWrapperPerspective.d.ts.map +1 -1
  246. package/dist/rendering/CameraWrapperPerspective.js +16 -0
  247. package/dist/rendering/CameraWrapperPerspective.js.map +1 -1
  248. package/dist/rendering/ChitGalleryItemInstance.d.ts +14 -3
  249. package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
  250. package/dist/rendering/ChitGalleryItemInstance.js +29 -1
  251. package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
  252. package/dist/rendering/ChitRenderInstance.d.ts +15 -1
  253. package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
  254. package/dist/rendering/ChitRenderInstance.js +49 -4
  255. package/dist/rendering/ChitRenderInstance.js.map +1 -1
  256. package/dist/rendering/LightWrapper.d.ts.map +1 -1
  257. package/dist/rendering/LightWrapper.js +10 -1
  258. package/dist/rendering/LightWrapper.js.map +1 -1
  259. package/dist/rendering/RootChitRenderInstance.d.ts +2 -0
  260. package/dist/rendering/RootChitRenderInstance.d.ts.map +1 -1
  261. package/dist/rendering/RootChitRenderInstance.js +29 -0
  262. package/dist/rendering/RootChitRenderInstance.js.map +1 -1
  263. package/dist/rendering/Splay.d.ts +11 -0
  264. package/dist/rendering/Splay.d.ts.map +1 -1
  265. package/dist/rendering/Splay.js +20 -10
  266. package/dist/rendering/Splay.js.map +1 -1
  267. package/dist/utilities/Annotations.d.ts +15 -0
  268. package/dist/utilities/Annotations.d.ts.map +1 -1
  269. package/dist/utilities/Annotations.js +31 -7
  270. package/dist/utilities/Annotations.js.map +1 -1
  271. package/dist/utilities/CanvasStack/CanvasStack.d.ts +2 -0
  272. package/dist/utilities/CanvasStack/CanvasStack.d.ts.map +1 -1
  273. package/dist/utilities/CanvasStack/CanvasStack.js +4 -0
  274. package/dist/utilities/CanvasStack/CanvasStack.js.map +1 -1
  275. package/dist/utilities/CanvasStack/RichTextRenderer.d.ts.map +1 -1
  276. package/dist/utilities/CanvasStack/RichTextRenderer.js +12 -0
  277. package/dist/utilities/CanvasStack/RichTextRenderer.js.map +1 -1
  278. package/dist/utilities/Dice.d.ts +2 -0
  279. package/dist/utilities/Dice.d.ts.map +1 -1
  280. package/dist/utilities/Dice.js +5 -1
  281. package/dist/utilities/Dice.js.map +1 -1
  282. package/dist/utilities/GalleryItemConversion.d.ts.map +1 -1
  283. package/dist/utilities/GalleryItemConversion.js +5 -7
  284. package/dist/utilities/GalleryItemConversion.js.map +1 -1
  285. package/dist/utilities/TokenizedText.d.ts +6 -0
  286. package/dist/utilities/TokenizedText.d.ts.map +1 -1
  287. package/dist/utilities/TokenizedText.js.map +1 -1
  288. package/dist/utilities/zIndex.d.ts +1 -0
  289. package/dist/utilities/zIndex.d.ts.map +1 -1
  290. package/dist/utilities/zIndex.js +1 -0
  291. package/dist/utilities/zIndex.js.map +1 -1
  292. package/package.json +3 -2
  293. package/src/library/components/ActionLogDisplay.tsx +1 -0
  294. package/src/library/components/BottomBarButton.tsx +5 -0
  295. package/src/library/components/ContextGalleryDisplay.tsx +2 -0
  296. package/src/library/components/DemoWrapper.tsx +150 -44
  297. package/src/library/components/FullScreenGalleryDisplay.tsx +3 -0
  298. package/src/library/components/Gallery/BuiltItem.ts +92 -16
  299. package/src/library/components/Gallery/GalleryController.ts +111 -10
  300. package/src/library/components/Gallery/GalleryViewer.tsx +144 -12
  301. package/src/library/components/Gallery/LayoutManager.ts +55 -6
  302. package/src/library/components/Gallery/constants.ts +6 -0
  303. package/src/library/components/Gallery/registry.ts +44 -0
  304. package/src/library/components/Gallery/types.ts +6 -0
  305. package/src/library/components/GameDesigner.tsx +165 -12
  306. package/src/library/components/InlineGalleryDisplay.tsx +41 -6
  307. package/src/library/components/LiveButton.tsx +8 -5
  308. package/src/library/components/MatchViewer.tsx +14 -3
  309. package/src/library/components/Panel/ExternalDrag.ts +122 -0
  310. package/src/library/components/Panel/MultiPanel.tsx +21 -0
  311. package/src/library/components/Panel/PanelContents.tsx +96 -1
  312. package/src/library/components/Panel/PanelTabStack.tsx +1 -0
  313. package/src/library/components/PanelSpark.tsx +12 -5
  314. package/src/library/components/Playground.tsx +48 -21
  315. package/src/library/components/PromptControls.tsx +7 -3
  316. package/src/library/components/SparkLineChart.tsx +23 -27
  317. package/src/library/components/TimeControlBar.tsx +5 -3
  318. package/src/library/components/TokenizedMarkdown.tsx +224 -0
  319. package/src/library/components/TokenizedMessage.tsx +28 -32
  320. package/src/library/components/TopBar.tsx +2 -1
  321. package/src/library/components/TopBarPlayers.tsx +13 -15
  322. package/src/library/components/Tutorial/BrowserNarration.ts +233 -0
  323. package/src/library/components/Tutorial/TutorialBox.tsx +506 -0
  324. package/src/library/components/Tutorial/TutorialDevPanel.tsx +297 -0
  325. package/src/library/components/Tutorial/TutorialOverlay.tsx +1316 -0
  326. package/src/library/components/Tutorial/targetRects.ts +273 -0
  327. package/src/library/components/Viewer.tsx +1 -0
  328. package/src/library/game/Chit.ts +28 -7
  329. package/src/library/game/ClientTimeState.ts +18 -0
  330. package/src/library/game/GalleryItemChitChildrenSource.ts +1 -0
  331. package/src/library/game/GalleryItemRawSource.ts +1 -0
  332. package/src/library/game/Game.ts +7 -0
  333. package/src/library/game/GameButton.ts +13 -1
  334. package/src/library/game/GameTheme.ts +4 -0
  335. package/src/library/game/Match.ts +12 -2
  336. package/src/library/game/ModalState.ts +3 -0
  337. package/src/library/game/Pick.ts +17 -4
  338. package/src/library/game/PlayerPromptStatusChit.ts +6 -4
  339. package/src/library/game/Prompt.ts +33 -2
  340. package/src/library/game/SparkChit.ts +9 -0
  341. package/src/library/game/Turn.ts +185 -70
  342. package/src/library/game/TurnState.ts +26 -3
  343. package/src/library/game/ai/AI_GUIDE.md +10 -0
  344. package/src/library/game/ai/AiClientPrompts.ts +60 -11
  345. package/src/library/game/ai/AiPlayerView.ts +2 -0
  346. package/src/library/game/clientTransport/ClientPrompts.ts +76 -5
  347. package/src/library/game/clientTransport/ClientTime.ts +75 -14
  348. package/src/library/game/serialize.test.ts +275 -0
  349. package/src/library/game/tutorial/TUTORIAL_GUIDE.md +416 -0
  350. package/src/library/game/tutorial/TutorialController.test.ts +731 -0
  351. package/src/library/game/tutorial/TutorialController.ts +1299 -0
  352. package/src/library/game/tutorial/TutorialRuntime.ts +311 -0
  353. package/src/library/game/tutorial/TutorialTheme.ts +67 -0
  354. package/src/library/game/tutorial/allowed.ts +145 -0
  355. package/src/library/game/tutorial/checks.ts +186 -0
  356. package/src/library/game/tutorial/createDemoMatch.ts +115 -0
  357. package/src/library/game/tutorial/defineTutorial.ts +414 -0
  358. package/src/library/game/tutorial/runTutorial.ts +350 -0
  359. package/src/library/game/undo.test.ts +282 -0
  360. package/src/library/hooks/usePanelNavigation.tsx +65 -0
  361. package/src/library/hooks/useTimeController.tsx +10 -2
  362. package/src/library/hooks/useTutorial.tsx +80 -0
  363. package/src/library/index.ts +58 -2
  364. package/src/library/rendering/CameraWrapperPerspective.ts +17 -0
  365. package/src/library/rendering/ChitGalleryItemInstance.ts +30 -1
  366. package/src/library/rendering/ChitRenderInstance.ts +57 -4
  367. package/src/library/rendering/LightWrapper.ts +10 -1
  368. package/src/library/rendering/RootChitRenderInstance.ts +30 -1
  369. package/src/library/rendering/Splay.test.ts +60 -0
  370. package/src/library/rendering/Splay.ts +30 -9
  371. package/src/library/utilities/Annotations.ts +35 -7
  372. package/src/library/utilities/CanvasStack/CanvasStack.ts +6 -1
  373. package/src/library/utilities/CanvasStack/RichTextRenderer.ts +13 -0
  374. package/src/library/utilities/Dice.tsx +5 -1
  375. package/src/library/utilities/GalleryItemConversion.ts +5 -6
  376. package/src/library/utilities/TokenizedText.ts +6 -0
  377. package/src/library/utilities/zIndex.ts +1 -0
@@ -10,6 +10,11 @@ import { requestSharedAnimationFrame } from "../../utilities/RequestSharedAnimat
10
10
  import { TextureReferenceCounter } from "../../rendering/TextureReferenceCounter";
11
11
  import { GalleryController } from "./GalleryController";
12
12
  import { GalleryItem, SummaryMode } from "./types";
13
+ import { GalleryKind, galleryRegistry } from "./registry";
14
+ import { Chit } from "../../game/Chit";
15
+ import { ChitGalleryItemInstance } from "../../rendering/ChitGalleryItemInstance";
16
+ import { useModalState } from "../../hooks/useModalState";
17
+ import type { ExternalDrag } from "../Panel/ExternalDrag";
13
18
  import {
14
19
  DEFAULT_TWEEN_DURATION,
15
20
  DEFAULT_FOV,
@@ -39,6 +44,20 @@ export interface GalleryViewerProps {
39
44
  onLongPress?: () => void;
40
45
  showSummary?: SummaryMode;
41
46
  zFactor?: number;
47
+ /** Lets tutorials find and point at this gallery's items (see `galleryRegistry`) */
48
+ kind?: GalleryKind;
49
+ /** `data-tutorial-target` for the gallery area */
50
+ tutorialTarget?: string;
51
+ }
52
+
53
+ /**
54
+ * Whether a gallery item shows `chit`: the item is that chit, or (galleries merge identical chits into
55
+ * one "2x" item) an identical one.
56
+ */
57
+ function itemShows(item: GalleryItem, chit: Chit) {
58
+ if (item.id === chit.id) return true;
59
+ const shown = (item as ChitGalleryItemInstance).chit;
60
+ return shown instanceof Chit && shown !== chit && shown.functionallyIdentical(chit);
42
61
  }
43
62
 
44
63
  export function GalleryViewer({
@@ -56,6 +75,8 @@ export function GalleryViewer({
56
75
  galleryItemHeight = h * 0.7,
57
76
  showSummary = "full",
58
77
  zFactor = DEFAULT_Z_FACTOR,
78
+ kind,
79
+ tutorialTarget,
59
80
  }: GalleryViewerProps) {
60
81
  const calcedItemWidth =
61
82
  items.length > 0 ? Math.min(...items.map((item) => item.preferredWidth ?? galleryItemWidth)) : galleryItemWidth;
@@ -66,11 +87,23 @@ export function GalleryViewer({
66
87
  const refContainer = useRef<HTMLCanvasElement>(null);
67
88
  const rendererWrapper = useWebGlRenderer();
68
89
  const theme = useGameTheme();
90
+ const modalState = useModalState();
69
91
  const [galleryController] = useState(() => new GalleryController(new SceneWrapper(new Scene()), theme, angle, fov));
70
92
 
71
93
  galleryController.setTweenDuration(tweenDuration);
72
94
  galleryController.showSummary = showSummary;
73
95
 
96
+ // Must run before the effects below build items: each build sweeps unused textures, and the gallery's clones
97
+ // only count as used once it's registered.
98
+ useEffect(() => {
99
+ TextureReferenceCounter.registerInstance(galleryController);
100
+ return () => {
101
+ galleryController.destroy();
102
+ TextureReferenceCounter.unregisterInstance(galleryController);
103
+ galleryController.sceneWrapper.dispose();
104
+ };
105
+ }, [galleryController]);
106
+
74
107
  // Single effect to handle both size and items changes
75
108
  useEffect(() => {
76
109
  if (!w || !h || !Number.isFinite(calcedItemHeight) || !Number.isFinite(calcedItemWidth)) {
@@ -89,6 +122,29 @@ export function GalleryViewer({
89
122
  });
90
123
  }, [calcedItemWidth, itemSpacing, calcedItemHeight, w, h, galleryController, zFactor]);
91
124
 
125
+ // Tell tutorials where this gallery's items are
126
+ useEffect(() => {
127
+ const canvas = refContainer.current;
128
+ if (!kind || !canvas) return;
129
+ return galleryRegistry.register({
130
+ kind,
131
+ element: canvas,
132
+ chitIds: () => galleryController.itemIds(),
133
+ locate: (chit) => {
134
+ const exact = galleryController.locateItem((item) => item.id === chit.id);
135
+ const found = exact ?? galleryController.locateItem((item) => itemShows(item, chit));
136
+ if (!found || found === "offscreen") return found;
137
+ const r = canvas.getBoundingClientRect();
138
+ return { left: r.left + found.left, top: r.top + found.top, right: r.left + found.right, bottom: r.top + found.bottom };
139
+ },
140
+ scrollTo: (chit) => {
141
+ const hasExact = galleryController.itemIds().includes(chit.id ?? "");
142
+ galleryController.scrollToItem((item) => (hasExact ? item.id === chit.id : itemShows(item, chit)));
143
+ },
144
+ });
145
+ // the canvas exists only once w and h are known
146
+ }, [kind, galleryController, w, h]);
147
+
92
148
  useEffect(() => {
93
149
  galleryController.setItems(items);
94
150
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -133,7 +189,10 @@ export function GalleryViewer({
133
189
  if (!el) return;
134
190
 
135
191
  const hammer = new Hammer.Manager(el);
136
- hammer.add(new Hammer.Pan({ direction: Hammer.DIRECTION_HORIZONTAL }));
192
+ // The inline strip also takes upward drags: a draggable item pulled up goes onto the board.
193
+ const dragsOut = kind === "inline";
194
+ // The full gallery takes vertical drags too: they scroll the summaries when those are longer than their space.
195
+ hammer.add(new Hammer.Pan({ direction: Hammer.DIRECTION_ALL }));
137
196
 
138
197
  const singleTap = new Hammer.Tap({ event: "singletap" });
139
198
  const press = new Hammer.Press({ event: "longtap", time: 600 });
@@ -168,8 +227,62 @@ export function GalleryViewer({
168
227
 
169
228
  let lastX: number | undefined = undefined;
170
229
  let lastVelocityX = 0;
230
+ // Decided on a gesture's first movement: a pull upward (more than ~30° above horizontal) on
231
+ // an item with a live DragPick drags it out onto the board; anything else scrolls the strip.
232
+ // A scroll that leaves the strip through its top edge turns into a drag of the item it started
233
+ // on, so a long diagonal pull toward the board still lands the piece.
234
+ let mode: "undecided" | "scroll" | "drag" | "summaries" = "undecided";
235
+ let lastY: number | undefined = undefined;
236
+ let summaryX = 0;
237
+ let drag: ExternalDrag | undefined;
238
+ let startItem: GalleryItem | null = null;
239
+
240
+ const draggableChit = (item: GalleryItem | null) => {
241
+ const chit = item instanceof ChitGalleryItemInstance ? item.chit : undefined;
242
+ return chit?.onDrag ? chit : undefined;
243
+ };
244
+ const beginDragOut = (ev: HammerInput): boolean => {
245
+ const chit = draggableChit(startItem);
246
+ if (!chit || !startItem || !modalState.externalDragHost) return false;
247
+ drag = modalState.externalDragHost.begin(chit, startItem, ev.center.x, ev.center.y);
248
+ return !!drag;
249
+ };
171
250
 
172
251
  hammer.on("pan", (ev) => {
252
+ if (mode === "undecided") {
253
+ const rect = el.getBoundingClientRect();
254
+ startItem = dragsOut ? galleryController.getItemAtPosition(ev.center.x - ev.deltaX - rect.left, ev.center.y - ev.deltaY - rect.top) : null;
255
+ const upward = -ev.deltaY > Math.abs(ev.deltaX) * 0.58;
256
+ const vertical = Math.abs(ev.deltaY) > Math.abs(ev.deltaX);
257
+ mode = upward && beginDragOut(ev) ? "drag" : !dragsOut && vertical && galleryController.canScrollSummaries() ? "summaries" : "scroll";
258
+ // a summary drag scrolls the one it started on
259
+ summaryX = ev.center.x - ev.deltaX - rect.left;
260
+ } else if (mode === "scroll" && dragsOut && ev.center.y < el.getBoundingClientRect().top && beginDragOut(ev)) {
261
+ // Put the strip back where the gesture found it, and carry on as a drag.
262
+ if (lastX !== undefined) {
263
+ galleryController.pan(-lastX);
264
+ galleryController.pan(0, true);
265
+ }
266
+ lastX = undefined;
267
+ mode = "drag";
268
+ }
269
+ if (mode === "drag") {
270
+ drag?.move(ev.center.x, ev.center.y);
271
+ ev.preventDefault();
272
+ return;
273
+ }
274
+ if (mode === "summaries") {
275
+ // the text follows the finger: dragging up reads further down
276
+ if (lastY !== undefined) galleryController.scrollSummaries(lastY - ev.deltaY, summaryX);
277
+ lastY = ev.deltaY;
278
+ ev.preventDefault();
279
+ return;
280
+ }
281
+ if (!dragsOut && Math.abs(ev.deltaX) < 1 && lastX === undefined && Math.abs(ev.deltaY) > 0) {
282
+ // a vertical drag with nothing to scroll: leave the strip where it is
283
+ ev.preventDefault();
284
+ return;
285
+ }
173
286
  if (lastX === undefined) {
174
287
  lastX = 0;
175
288
  } else {
@@ -180,7 +293,26 @@ export function GalleryViewer({
180
293
  ev.preventDefault();
181
294
  });
182
295
 
296
+ hammer.on("pancancel", () => {
297
+ drag?.cancel();
298
+ drag = undefined;
299
+ mode = "undecided";
300
+ lastY = undefined;
301
+ });
302
+
183
303
  hammer.on("panend", () => {
304
+ if (mode === "drag") {
305
+ drag?.end();
306
+ drag = undefined;
307
+ mode = "undecided";
308
+ return;
309
+ }
310
+ if (mode === "summaries") {
311
+ mode = "undecided";
312
+ lastY = undefined;
313
+ return;
314
+ }
315
+ mode = "undecided";
184
316
  lastX = undefined;
185
317
  galleryController.pan(lastVelocityX * VELOCITY_MULTIPLIER, true);
186
318
  lastVelocityX = 0;
@@ -188,6 +320,15 @@ export function GalleryViewer({
188
320
 
189
321
  let wheelTimeout: NodeJS.Timeout;
190
322
  const wheelListener = (ev: WheelEvent) => {
323
+ // over the summaries (when they are longer than their space) the wheel reads through them
324
+ if (galleryController.canScrollSummaries()) {
325
+ const rect = el.getBoundingClientRect();
326
+ if (ev.clientY - rect.top > galleryController.summariesTop()) {
327
+ galleryController.scrollSummaries(ev.deltaY, ev.clientX - rect.left);
328
+ ev.preventDefault();
329
+ return;
330
+ }
331
+ }
191
332
  const dy = (ev as any).wheelDeltaY as number;
192
333
  galleryController.pan(dy / WHEEL_SENSITIVITY, false);
193
334
  ev.preventDefault();
@@ -202,23 +343,14 @@ export function GalleryViewer({
202
343
  hammer.destroy();
203
344
  removeWheelListener(el, wheelListener);
204
345
  };
205
- }, [galleryController, onClose, onLongPress]);
206
-
207
- useEffect(() => {
208
- TextureReferenceCounter.registerInstance(galleryController);
209
- return () => {
210
- galleryController.destroy();
211
- TextureReferenceCounter.unregisterInstance(galleryController);
212
- galleryController.sceneWrapper.dispose();
213
- };
214
- }, [galleryController]);
346
+ }, [galleryController, onClose, onLongPress, kind, modalState]);
215
347
 
216
348
  if (!w || !h) {
217
349
  return null;
218
350
  }
219
351
 
220
352
  return (
221
- <Box sx={{ position: "absolute", top: 0, right: 0, left: 0, bottom: 0 }}>
353
+ <Box data-tutorial-target={tutorialTarget} sx={{ position: "absolute", top: 0, right: 0, left: 0, bottom: 0 }}>
222
354
  <canvas
223
355
  width={w * rendererWrapper.pixelRatio}
224
356
  height={h * rendererWrapper.pixelRatio}
@@ -1,5 +1,6 @@
1
1
  import { GameTheme } from "../../game/GameTheme";
2
2
  import { SummaryMode } from "./types";
3
+ import { ITEM_HEIGHT_FRACTION_WITH_SUMMARY, MIN_ITEM_HEIGHT_FRACTION, SUMMARY_MAX_WIDTH } from "./constants";
3
4
 
4
5
  export class LayoutManager {
5
6
  // Dimensions (all scaled)
@@ -24,6 +25,8 @@ export class LayoutManager {
24
25
  // summary info
25
26
  private summaryMode: SummaryMode = "full";
26
27
  private summaryMaxHeight = 0;
28
+ private summaryWidth = 100;
29
+ private summaryHeightLimit = 0;
27
30
 
28
31
  public dirty = false;
29
32
 
@@ -69,6 +72,20 @@ export class LayoutManager {
69
72
  return { w: this.itemWidth, h: this.itemHeight, summaryMaxHeight: this.summaryMaxHeight };
70
73
  }
71
74
 
75
+ getSummaryDimensions() {
76
+ return { w: this.summaryWidth, maxHeight: this.summaryHeightLimit };
77
+ }
78
+
79
+ /** The height the summaries take on screen: in the full gallery the window they scroll in, otherwise their height */
80
+ getSummaryViewportHeight() {
81
+ return this.summaryMode === "full" ? Math.min(this.summaryMaxHeight, this.summaryHeightLimit) : this.summaryMaxHeight;
82
+ }
83
+ /** Whether some summary is longer than its window (the full gallery scrolls them) */
84
+ canScrollSummaries() {
85
+ return this.summaryMode === "full" && this.summaryMaxHeight > this.summaryHeightLimit + 1;
86
+ }
87
+
88
+
72
89
  getStageDimensions() {
73
90
  return { frontStageWidth: this.frontStageWidth, itemsPerPage: this.itemsPerPage, itemSpacing: this.itemSpacing };
74
91
  }
@@ -117,16 +134,14 @@ export class LayoutManager {
117
134
  }
118
135
 
119
136
  recalculateEffectiveItemDimensions() {
120
- // recalcs itemWidth,itemHeight,itemsPerPage and frontStageWidth
137
+ // recalcs itemWidth,itemHeight,itemsPerPage,frontStageWidth and the summary bounds
121
138
 
122
139
  let itemWidth = this.itemPreferredWidth ?? this.baseItemWidth;
123
140
  let itemHeight = this.itemPreferredHeight ?? this.baseItemHeight;
124
141
  const aspectRatio = itemWidth / itemHeight;
125
142
 
126
- const maxItemHeight = Math.max(
127
- this.theme.galleryItemMinimumHeight,
128
- this.h - this.itemSpacing * 2 - this.summaryMaxHeight,
129
- );
143
+ const availableHeight = this.h - this.itemSpacing * 2;
144
+ const maxItemHeight = Math.max(this.theme.galleryItemMinimumHeight, availableHeight);
130
145
  const maxItemWidth = Math.max(this.theme.galleryItemMinimumWidth, this.w - this.itemSpacing * 2);
131
146
 
132
147
  if (itemHeight > maxItemHeight) {
@@ -140,6 +155,36 @@ export class LayoutManager {
140
155
 
141
156
  itemWidth = Math.max(this.theme.galleryItemMinimumWidth, itemWidth);
142
157
 
158
+ let summaryHeightLimit: number;
159
+ let summaryWidth: number;
160
+ if (this.summaryMode === "full" && this.summaryMaxHeight > 0) {
161
+ // The full gallery: the item keeps a fixed, readable share of the height whatever its summary says (it is what
162
+ // the player is looking at), and the summaries sit under it at their natural size, scrolling in what is left.
163
+ itemHeight = Math.min(itemHeight, availableHeight * ITEM_HEIGHT_FRACTION_WITH_SUMMARY);
164
+ itemWidth = Math.max(this.theme.galleryItemMinimumWidth, Math.min(maxItemWidth, itemHeight * aspectRatio));
165
+ itemHeight = itemWidth / aspectRatio;
166
+ summaryHeightLimit = Math.max(0, availableHeight - itemHeight - this.theme.spacing);
167
+ // never wider than a readable measure; side by side, no wider than the item's own slot
168
+ summaryWidth =
169
+ this.itemCount === 1
170
+ ? Math.min(SUMMARY_MAX_WIDTH, maxItemWidth)
171
+ : Math.min(SUMMARY_MAX_WIDTH, itemWidth + this.itemSpacing * 0.8);
172
+ } else {
173
+ // The summary takes its height from the item, and the item keeps its shape, so the slot (and the summary laid
174
+ // out at its width) stays as wide as the item actually draws. A narrower summary can wrap taller and shrink the
175
+ // item again, but only down to the height floor, so the layout settles instead of collapsing.
176
+ const itemHeightFloor = Math.max(
177
+ this.theme.galleryItemMinimumHeight,
178
+ Math.min(itemHeight, availableHeight * MIN_ITEM_HEIGHT_FRACTION),
179
+ );
180
+ summaryHeightLimit = Math.max(0, availableHeight - itemHeightFloor);
181
+ itemHeight = Math.max(itemHeightFloor, Math.min(itemHeight, availableHeight - this.summaryMaxHeight));
182
+ itemWidth = Math.max(this.theme.galleryItemMinimumWidth, itemHeight * aspectRatio);
183
+ // Each caption is as wide as its item, however many items there are: a lone item's caption looks just as it
184
+ // would beside a second one (a stage-wide caption read as a bar under a short label).
185
+ summaryWidth = itemWidth;
186
+ }
187
+
143
188
  const itemsPerPage = Math.max(
144
189
  1,
145
190
  Math.min(this.itemCount, Math.floor((this.w - this.itemSpacing * 2) / (itemWidth + this.itemSpacing))),
@@ -150,12 +195,16 @@ export class LayoutManager {
150
195
  this.itemHeight !== itemHeight ||
151
196
  this.itemWidth !== itemWidth ||
152
197
  this.itemsPerPage !== itemsPerPage ||
153
- this.frontStageWidth !== frontStageWidth
198
+ this.frontStageWidth !== frontStageWidth ||
199
+ this.summaryWidth !== summaryWidth ||
200
+ this.summaryHeightLimit !== summaryHeightLimit
154
201
  ) {
155
202
  this.itemHeight = itemHeight;
156
203
  this.itemWidth = itemWidth;
157
204
  this.itemsPerPage = itemsPerPage;
158
205
  this.frontStageWidth = frontStageWidth;
206
+ this.summaryWidth = summaryWidth;
207
+ this.summaryHeightLimit = summaryHeightLimit;
159
208
  this.dirty = true;
160
209
  }
161
210
  }
@@ -10,3 +10,9 @@ export const DEFAULT_ANGLE = Math.PI * 0.0;
10
10
  export const DEFAULT_ITEM_WIDTH = 200;
11
11
  export const DEFAULT_ITEM_SPACING = 50;
12
12
  export const DEFAULT_Z_FACTOR = 3;
13
+ export const MIN_ITEM_HEIGHT_FRACTION = 0.4;
14
+ /** Full gallery: the items keep this share of the height (never shrunk for their summaries); the summaries scroll in
15
+ * the rest */
16
+ export const ITEM_HEIGHT_FRACTION_WITH_SUMMARY = 0.6;
17
+ /** Full gallery: a summary is never wider than a readable measure, however wide its item (scaled px) */
18
+ export const SUMMARY_MAX_WIDTH = 380;
@@ -0,0 +1,44 @@
1
+ import { Chit } from "../../game/Chit";
2
+
3
+ /** Which gallery: the strip above the log, the full-screen one, or the small one in the prompt bar */
4
+ export type GalleryKind = "inline" | "fullscreen" | "context";
5
+
6
+ /** A page-space rectangle (CSS px, like getBoundingClientRect) */
7
+ export type GalleryRect = { left: number; top: number; right: number; bottom: number };
8
+
9
+ /**
10
+ * An open gallery, as the tutorial overlay sees it: where a chit's item is on screen, and how to bring
11
+ * an item into view. Registered by `GalleryViewer` when given a `kind`.
12
+ */
13
+ export interface RegisteredGallery {
14
+ kind: GalleryKind;
15
+ /** The gallery's canvas, used to tell which viewer (and so which player) the gallery belongs to */
16
+ element: HTMLElement;
17
+ /**
18
+ * Where the item showing this chit is: a rect when it is on screen, "offscreen" when the gallery has
19
+ * the item but it is scrolled out of view, undefined when the gallery does not show it.
20
+ */
21
+ locate(chit: Chit): GalleryRect | "offscreen" | undefined;
22
+ /** Scrolls the gallery so the item showing this chit is in view */
23
+ scrollTo(chit: Chit): void;
24
+ /** Ids of the chits whose items the gallery shows */
25
+ chitIds(): string[];
26
+ }
27
+
28
+ const galleries = new Set<RegisteredGallery>();
29
+
30
+ export const galleryRegistry = {
31
+ register(gallery: RegisteredGallery) {
32
+ galleries.add(gallery);
33
+ return () => {
34
+ galleries.delete(gallery);
35
+ };
36
+ },
37
+ /** Open galleries inside `scope` (a viewer's root element), full-screen first, then inline, then context */
38
+ list(scope?: ParentNode | null): RegisteredGallery[] {
39
+ const order: GalleryKind[] = ["fullscreen", "inline", "context"];
40
+ return [...galleries]
41
+ .filter((g) => !scope || (scope as Node).contains(g.element))
42
+ .sort((a, b) => order.indexOf(a.kind) - order.indexOf(b.kind));
43
+ },
44
+ };
@@ -41,6 +41,12 @@ export interface GalleryItemSource {
41
41
  close(): void;
42
42
 
43
43
  inlineGallerySize?: number;
44
+
45
+ /**
46
+ * Opt-in (see `ToggleGalleryButton.holdOnCloseMs`): how long the inline strip keeps this
47
+ * source's items and height after the source is closed, waiting for the next one.
48
+ */
49
+ inlineHoldOnCloseMs?: number;
44
50
  }
45
51
 
46
52
  export interface GallerySizeConfig {
@@ -1,11 +1,149 @@
1
- import React from "react";
1
+ import React, { useState } from "react";
2
2
  import useLocalStorageState from "use-local-storage-state";
3
- import { AppBar, Tabs, Tab, CssBaseline, Stack } from "@mui/material";
3
+ import {
4
+ AppBar,
5
+ Tabs,
6
+ Tab,
7
+ CssBaseline,
8
+ Stack,
9
+ Box,
10
+ Paper,
11
+ Select,
12
+ MenuItem,
13
+ FormControl,
14
+ IconButton,
15
+ Tooltip,
16
+ ToggleButton,
17
+ } from "@mui/material";
18
+ import { OpenInNew, Refresh, Tune } from "@mui/icons-material";
4
19
  import CanvasLibraryViewer from "./CanvasLibraryViewer";
5
20
  import { Game } from "../game/Game";
6
21
  import ChitLibraryViewer from "./ChitLibraryViewer";
7
22
  import Playground from "./Playground";
8
23
  import { DemoWrapper } from "./DemoWrapper";
24
+ import { TutorialDevPanel } from "./Tutorial/TutorialDevPanel";
25
+ import type { TutorialEvent } from "../game/tutorial/TutorialController";
26
+
27
+ const NONE = "__none__";
28
+
29
+ /** The Demo tab: a demo game or any of the game's tutorials, with the tutorial workbench beside it. */
30
+ function DemoWorkbench({ game }: { game: Game<any, any> }) {
31
+ const tutorials = game.tutorials ?? [];
32
+ const [selected, setSelected] = useLocalStorageState<string>(`demo_${game.metadata.name}_tutorial`, {
33
+ defaultValue: tutorials[0] ? `${tutorials[0].id}|${tutorials[0].locale}` : NONE,
34
+ });
35
+ const [showDev, setShowDev] = useLocalStorageState<boolean>(`demo_${game.metadata.name}_devPanel`, {
36
+ defaultValue: true,
37
+ });
38
+ const [restartKey, setRestartKey] = useState(0);
39
+ const [startAt, setStartAt] = useState(0);
40
+
41
+ const [id, locale] = selected === NONE ? [undefined, undefined] : selected.split("|");
42
+ const spec = id ? tutorials.find((t) => t.id === id && t.locale === locale) : undefined;
43
+ // The step the tutorial is on, kept across reloads: a code change reloads the game while the developer
44
+ // reviews it, and the workbench comes back to that step (played up to headlessly) instead of the start.
45
+ // Restart, or picking another tutorial, forgets it.
46
+ const stepKey = `demo_${game.metadata.name}_step_${selected}`;
47
+ const storedStep = () => {
48
+ try {
49
+ return localStorage.getItem(stepKey) ?? undefined;
50
+ } catch {
51
+ return undefined;
52
+ }
53
+ };
54
+ const keepStep = (e: TutorialEvent) => {
55
+ try {
56
+ if (e.type === "step") localStorage.setItem(stepKey, e.stepId);
57
+ else if (e.type === "completed" || e.type === "skipped") localStorage.removeItem(stepKey);
58
+ } catch {
59
+ // storage blocked: reloads start over
60
+ }
61
+ };
62
+ const restart = (at = 0) => {
63
+ try {
64
+ localStorage.removeItem(stepKey);
65
+ } catch {
66
+ // storage blocked
67
+ }
68
+ setStartAt(at);
69
+ setRestartKey((k) => k + 1);
70
+ };
71
+
72
+ const fullScreenUrl = spec ? `/demo?tutorial=${encodeURIComponent(spec.id)}&locale=${encodeURIComponent(spec.locale)}` : "/demo";
73
+
74
+ return (
75
+ <Stack sx={{ height: "100%", minHeight: 0 }}>
76
+ <Paper elevation={3} sx={{ position: "relative", zIndex: 1 }}>
77
+ <Stack direction="row" alignItems="center" spacing={1} sx={{ p: 1 }}>
78
+ <FormControl sx={{ minWidth: 240 }}>
79
+ <Select
80
+ variant="standard"
81
+ value={spec ? selected : NONE}
82
+ onChange={(e) => {
83
+ restart(0);
84
+ setSelected(e.target.value);
85
+ }}
86
+ >
87
+ <MenuItem value={NONE}>Demo (no tutorial)</MenuItem>
88
+ {tutorials.map((t) => (
89
+ <MenuItem key={`${t.id}|${t.locale}`} value={`${t.id}|${t.locale}`}>
90
+ {t.title} ({t.locale}) · {t.steps.length} steps
91
+ </MenuItem>
92
+ ))}
93
+ </Select>
94
+ </FormControl>
95
+ <Tooltip title="Restart">
96
+ <IconButton size="small" onClick={() => restart(0)}>
97
+ <Refresh />
98
+ </IconButton>
99
+ </Tooltip>
100
+ <Tooltip title="Open full screen">
101
+ <IconButton size="small" component="a" href={fullScreenUrl} target="_blank">
102
+ <OpenInNew />
103
+ </IconButton>
104
+ </Tooltip>
105
+ <Box flex={1} />
106
+ {spec && (
107
+ <Tooltip title="Tutorial workbench">
108
+ <ToggleButton size="small" value="dev" selected={showDev} onChange={() => setShowDev(!showDev)}>
109
+ <Tune fontSize="small" />
110
+ </ToggleButton>
111
+ </Tooltip>
112
+ )}
113
+ </Stack>
114
+ </Paper>
115
+ <Stack direction="row" sx={{ flex: 1, minHeight: 0 }}>
116
+ {/* The workbench sits beside the game, not over it: the tutorial's own layer (the dark start
117
+ screen, the box) stays inside the game and never covers the step list */}
118
+ <Box sx={{ flex: 1, minWidth: 0, position: "relative", display: "flex" }}>
119
+ <DemoWrapper
120
+ key={`${selected}-${restartKey}`}
121
+ game={game}
122
+ tutorial={spec}
123
+ startAt={startAt}
124
+ resumeAt={spec && startAt === 0 ? storedStep() : undefined}
125
+ onTutorialEvent={spec ? keepStep : undefined}
126
+ >
127
+ {spec && showDev && (
128
+ <Box
129
+ sx={{
130
+ width: 360,
131
+ flexShrink: 0,
132
+ height: "100%",
133
+ bgcolor: "background.paper",
134
+ borderLeft: "1px solid rgba(0,0,0,0.12)",
135
+ overflow: "hidden",
136
+ }}
137
+ >
138
+ <TutorialDevPanel onRestart={restart} />
139
+ </Box>
140
+ )}
141
+ </DemoWrapper>
142
+ </Box>
143
+ </Stack>
144
+ </Stack>
145
+ );
146
+ }
9
147
 
10
148
  export function GameDesigner({ game }: { game: Game<any, any> }) {
11
149
  const [tabIndex, setTabIndex] = useLocalStorageState("selectedMainTab", {
@@ -15,9 +153,31 @@ export function GameDesigner({ game }: { game: Game<any, any> }) {
15
153
  const isDemo = window.location.pathname.endsWith("/demo");
16
154
 
17
155
  if (isDemo) {
156
+ const params = new URLSearchParams(window.location.search);
157
+ const tutorial = params.get("tutorial") ?? undefined;
158
+ const locale = params.get("locale") ?? undefined;
159
+ // The step in the URL: kept current as the tutorial plays, so a reload (a code change while the
160
+ // developer reviews it) comes back to the same step instead of the start
161
+ const resumeAt = params.get("step") ?? undefined;
162
+ const keepStep = (e: TutorialEvent) => {
163
+ if (e.type !== "step" && e.type !== "completed" && e.type !== "skipped") return;
164
+ const url = new URL(window.location.href);
165
+ if (e.type === "step") url.searchParams.set("step", e.stepId);
166
+ else url.searchParams.delete("step");
167
+ window.history.replaceState(window.history.state, "", url);
168
+ };
18
169
  return (
19
170
  <Stack sx={{ height: "100vh", maxHeight: "-webkit-fill-available", width: "100vw" }}>
20
- <DemoWrapper game={game} />
171
+ <DemoWrapper
172
+ game={game}
173
+ tutorial={tutorial}
174
+ locale={locale}
175
+ resumeAt={tutorial ? resumeAt : undefined}
176
+ onTutorialEvent={tutorial ? keepStep : undefined}
177
+ onBack={() => {
178
+ window.history.back();
179
+ }}
180
+ />
21
181
  </Stack>
22
182
  );
23
183
  }
@@ -29,13 +189,7 @@ export function GameDesigner({ game }: { game: Game<any, any> }) {
29
189
  <AppBar position="static">
30
190
  <Tabs
31
191
  value={tabIndex}
32
- onChange={(e, newValue) => {
33
- if (newValue === 3) {
34
- document.location.pathname = "/demo";
35
- } else {
36
- setTabIndex(newValue);
37
- }
38
- }}
192
+ onChange={(e, newValue) => setTabIndex(newValue)}
39
193
  indicatorColor="secondary"
40
194
  textColor="inherit"
41
195
  variant="fullWidth"
@@ -44,13 +198,12 @@ export function GameDesigner({ game }: { game: Game<any, any> }) {
44
198
  <Tab label="Chits" />
45
199
  <Tab label="Playground" />
46
200
  <Tab label="Demo" />
47
- {/* <Tab label="Gallery" /> */}
48
201
  </Tabs>
49
202
  </AppBar>
50
203
  {tabIndex === 0 && <CanvasLibraryViewer library={game.canvasLibrary} />}
51
204
  {tabIndex === 1 && <ChitLibraryViewer library={game.chitLibrary} />}
52
205
  {tabIndex === 2 && <Playground game={game} />}
53
- {/* {tabIndex === 3 && <GalleryPlayground game={game} />} */}
206
+ {tabIndex === 3 && <DemoWorkbench game={game} />}
54
207
  </Stack>
55
208
  );
56
209
  }