@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.
- package/README.md +8 -0
- package/dist/components/ActionLogDisplay.d.ts.map +1 -1
- package/dist/components/ActionLogDisplay.js +1 -1
- package/dist/components/ActionLogDisplay.js.map +1 -1
- package/dist/components/BottomBarButton.d.ts +3 -1
- package/dist/components/BottomBarButton.d.ts.map +1 -1
- package/dist/components/BottomBarButton.js +3 -2
- package/dist/components/BottomBarButton.js.map +1 -1
- package/dist/components/ContextGalleryDisplay.d.ts.map +1 -1
- package/dist/components/ContextGalleryDisplay.js +1 -1
- package/dist/components/ContextGalleryDisplay.js.map +1 -1
- package/dist/components/DemoWrapper.d.ts +33 -2
- package/dist/components/DemoWrapper.d.ts.map +1 -1
- package/dist/components/DemoWrapper.js +77 -36
- package/dist/components/DemoWrapper.js.map +1 -1
- package/dist/components/FullScreenGalleryDisplay.d.ts.map +1 -1
- package/dist/components/FullScreenGalleryDisplay.js +2 -2
- package/dist/components/FullScreenGalleryDisplay.js.map +1 -1
- package/dist/components/Gallery/BuiltItem.d.ts +16 -2
- package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
- package/dist/components/Gallery/BuiltItem.js +92 -16
- package/dist/components/Gallery/BuiltItem.js.map +1 -1
- package/dist/components/Gallery/GalleryController.d.ts +26 -0
- package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryController.js +106 -6
- package/dist/components/Gallery/GalleryController.js.map +1 -1
- package/dist/components/Gallery/GalleryViewer.d.ts +6 -1
- package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryViewer.js +139 -12
- package/dist/components/Gallery/GalleryViewer.js.map +1 -1
- package/dist/components/Gallery/LayoutManager.d.ts +10 -0
- package/dist/components/Gallery/LayoutManager.d.ts.map +1 -1
- package/dist/components/Gallery/LayoutManager.js +49 -3
- package/dist/components/Gallery/LayoutManager.js.map +1 -1
- package/dist/components/Gallery/constants.d.ts +6 -0
- package/dist/components/Gallery/constants.d.ts.map +1 -1
- package/dist/components/Gallery/constants.js +6 -0
- package/dist/components/Gallery/constants.js.map +1 -1
- package/dist/components/Gallery/registry.d.ts +34 -0
- package/dist/components/Gallery/registry.d.ts.map +1 -0
- package/dist/components/Gallery/registry.js +17 -0
- package/dist/components/Gallery/registry.js.map +1 -0
- package/dist/components/Gallery/types.d.ts +5 -0
- package/dist/components/Gallery/types.d.ts.map +1 -1
- package/dist/components/GameDesigner.d.ts.map +1 -1
- package/dist/components/GameDesigner.js +84 -10
- package/dist/components/GameDesigner.js.map +1 -1
- package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
- package/dist/components/InlineGalleryDisplay.js +35 -8
- package/dist/components/InlineGalleryDisplay.js.map +1 -1
- package/dist/components/LiveButton.d.ts.map +1 -1
- package/dist/components/LiveButton.js +5 -2
- package/dist/components/LiveButton.js.map +1 -1
- package/dist/components/MatchViewer.d.ts +6 -1
- package/dist/components/MatchViewer.d.ts.map +1 -1
- package/dist/components/MatchViewer.js +9 -3
- package/dist/components/MatchViewer.js.map +1 -1
- package/dist/components/Panel/ExternalDrag.d.ts +30 -0
- package/dist/components/Panel/ExternalDrag.d.ts.map +1 -0
- package/dist/components/Panel/ExternalDrag.js +87 -0
- package/dist/components/Panel/ExternalDrag.js.map +1 -0
- package/dist/components/Panel/MultiPanel.d.ts.map +1 -1
- package/dist/components/Panel/MultiPanel.js +18 -0
- package/dist/components/Panel/MultiPanel.js.map +1 -1
- package/dist/components/Panel/PanelContents.d.ts +3 -0
- package/dist/components/Panel/PanelContents.d.ts.map +1 -1
- package/dist/components/Panel/PanelContents.js +116 -23
- package/dist/components/Panel/PanelContents.js.map +1 -1
- package/dist/components/Panel/PanelTabStack.d.ts.map +1 -1
- package/dist/components/Panel/PanelTabStack.js +1 -1
- package/dist/components/Panel/PanelTabStack.js.map +1 -1
- package/dist/components/PanelSpark.d.ts.map +1 -1
- package/dist/components/PanelSpark.js +6 -3
- package/dist/components/PanelSpark.js.map +1 -1
- package/dist/components/Playground.d.ts.map +1 -1
- package/dist/components/Playground.js +10 -4
- package/dist/components/Playground.js.map +1 -1
- package/dist/components/PromptControls.d.ts.map +1 -1
- package/dist/components/PromptControls.js +4 -2
- package/dist/components/PromptControls.js.map +1 -1
- package/dist/components/SparkLineChart.d.ts.map +1 -1
- package/dist/components/SparkLineChart.js +22 -26
- package/dist/components/SparkLineChart.js.map +1 -1
- package/dist/components/TimeControlBar.d.ts.map +1 -1
- package/dist/components/TimeControlBar.js +5 -3
- package/dist/components/TimeControlBar.js.map +1 -1
- package/dist/components/TokenizedMarkdown.d.ts +23 -0
- package/dist/components/TokenizedMarkdown.d.ts.map +1 -0
- package/dist/components/TokenizedMarkdown.js +144 -0
- package/dist/components/TokenizedMarkdown.js.map +1 -0
- package/dist/components/TokenizedMessage.d.ts +6 -0
- package/dist/components/TokenizedMessage.d.ts.map +1 -1
- package/dist/components/TokenizedMessage.js +20 -19
- package/dist/components/TokenizedMessage.js.map +1 -1
- package/dist/components/TopBar.d.ts.map +1 -1
- package/dist/components/TopBar.js +3 -1
- package/dist/components/TopBar.js.map +1 -1
- package/dist/components/TopBarPlayers.d.ts.map +1 -1
- package/dist/components/TopBarPlayers.js +2 -2
- package/dist/components/TopBarPlayers.js.map +1 -1
- package/dist/components/Tutorial/BrowserNarration.d.ts +55 -0
- package/dist/components/Tutorial/BrowserNarration.d.ts.map +1 -0
- package/dist/components/Tutorial/BrowserNarration.js +240 -0
- package/dist/components/Tutorial/BrowserNarration.js.map +1 -0
- package/dist/components/Tutorial/TutorialBox.d.ts +26 -0
- package/dist/components/Tutorial/TutorialBox.d.ts.map +1 -0
- package/dist/components/Tutorial/TutorialBox.js +239 -0
- package/dist/components/Tutorial/TutorialBox.js.map +1 -0
- package/dist/components/Tutorial/TutorialDevPanel.d.ts +9 -0
- package/dist/components/Tutorial/TutorialDevPanel.d.ts.map +1 -0
- package/dist/components/Tutorial/TutorialDevPanel.js +92 -0
- package/dist/components/Tutorial/TutorialDevPanel.js.map +1 -0
- package/dist/components/Tutorial/TutorialOverlay.d.ts +7 -0
- package/dist/components/Tutorial/TutorialOverlay.d.ts.map +1 -0
- package/dist/components/Tutorial/TutorialOverlay.js +1147 -0
- package/dist/components/Tutorial/TutorialOverlay.js.map +1 -0
- package/dist/components/Tutorial/targetRects.d.ts +67 -0
- package/dist/components/Tutorial/targetRects.d.ts.map +1 -0
- package/dist/components/Tutorial/targetRects.js +241 -0
- package/dist/components/Tutorial/targetRects.js.map +1 -0
- package/dist/components/Viewer.d.ts.map +1 -1
- package/dist/components/Viewer.js +1 -0
- package/dist/components/Viewer.js.map +1 -1
- package/dist/game/Chit.d.ts +10 -1
- package/dist/game/Chit.d.ts.map +1 -1
- package/dist/game/Chit.js +24 -6
- package/dist/game/Chit.js.map +1 -1
- package/dist/game/ClientTimeState.d.ts +14 -0
- package/dist/game/ClientTimeState.d.ts.map +1 -1
- package/dist/game/ClientTimeState.js +17 -0
- package/dist/game/ClientTimeState.js.map +1 -1
- package/dist/game/GalleryItemChitChildrenSource.d.ts +1 -0
- package/dist/game/GalleryItemChitChildrenSource.d.ts.map +1 -1
- package/dist/game/GalleryItemChitChildrenSource.js +1 -0
- package/dist/game/GalleryItemChitChildrenSource.js.map +1 -1
- package/dist/game/GalleryItemRawSource.d.ts +1 -0
- package/dist/game/GalleryItemRawSource.d.ts.map +1 -1
- package/dist/game/GalleryItemRawSource.js +1 -0
- package/dist/game/GalleryItemRawSource.js.map +1 -1
- package/dist/game/Game.d.ts +6 -0
- package/dist/game/Game.d.ts.map +1 -1
- package/dist/game/GameButton.d.ts +8 -0
- package/dist/game/GameButton.d.ts.map +1 -1
- package/dist/game/GameButton.js +13 -1
- package/dist/game/GameButton.js.map +1 -1
- package/dist/game/GameTheme.d.ts +3 -0
- package/dist/game/GameTheme.d.ts.map +1 -1
- package/dist/game/GameTheme.js +2 -0
- package/dist/game/GameTheme.js.map +1 -1
- package/dist/game/Match.d.ts +8 -2
- package/dist/game/Match.d.ts.map +1 -1
- package/dist/game/Match.js +4 -1
- package/dist/game/Match.js.map +1 -1
- package/dist/game/ModalState.d.ts +3 -0
- package/dist/game/ModalState.d.ts.map +1 -1
- package/dist/game/ModalState.js +2 -0
- package/dist/game/ModalState.js.map +1 -1
- package/dist/game/Pick.d.ts +2 -0
- package/dist/game/Pick.d.ts.map +1 -1
- package/dist/game/Pick.js +18 -4
- package/dist/game/Pick.js.map +1 -1
- package/dist/game/PlayerPromptStatusChit.d.ts +8 -0
- package/dist/game/PlayerPromptStatusChit.d.ts.map +1 -1
- package/dist/game/PlayerPromptStatusChit.js +6 -4
- package/dist/game/PlayerPromptStatusChit.js.map +1 -1
- package/dist/game/Prompt.d.ts +18 -1
- package/dist/game/Prompt.d.ts.map +1 -1
- package/dist/game/Prompt.js +29 -1
- package/dist/game/Prompt.js.map +1 -1
- package/dist/game/SparkChit.d.ts +6 -0
- package/dist/game/SparkChit.d.ts.map +1 -1
- package/dist/game/SparkChit.js +8 -0
- package/dist/game/SparkChit.js.map +1 -1
- package/dist/game/Turn.d.ts +17 -6
- package/dist/game/Turn.d.ts.map +1 -1
- package/dist/game/Turn.js +179 -69
- package/dist/game/Turn.js.map +1 -1
- package/dist/game/TurnState.d.ts +12 -1
- package/dist/game/TurnState.d.ts.map +1 -1
- package/dist/game/TurnState.js +15 -3
- package/dist/game/TurnState.js.map +1 -1
- package/dist/game/ai/AiClientPrompts.d.ts +20 -3
- package/dist/game/ai/AiClientPrompts.d.ts.map +1 -1
- package/dist/game/ai/AiClientPrompts.js +42 -6
- package/dist/game/ai/AiClientPrompts.js.map +1 -1
- package/dist/game/ai/AiPlayerView.js +2 -0
- package/dist/game/ai/AiPlayerView.js.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.d.ts +22 -1
- package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.js +72 -5
- package/dist/game/clientTransport/ClientPrompts.js.map +1 -1
- package/dist/game/clientTransport/ClientTime.d.ts +13 -0
- package/dist/game/clientTransport/ClientTime.d.ts.map +1 -1
- package/dist/game/clientTransport/ClientTime.js +71 -12
- package/dist/game/clientTransport/ClientTime.js.map +1 -1
- package/dist/game/tutorial/TutorialController.d.ts +308 -0
- package/dist/game/tutorial/TutorialController.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialController.js +1195 -0
- package/dist/game/tutorial/TutorialController.js.map +1 -0
- package/dist/game/tutorial/TutorialRuntime.d.ts +89 -0
- package/dist/game/tutorial/TutorialRuntime.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialRuntime.js +261 -0
- package/dist/game/tutorial/TutorialRuntime.js.map +1 -0
- package/dist/game/tutorial/TutorialTheme.d.ts +28 -0
- package/dist/game/tutorial/TutorialTheme.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialTheme.js +39 -0
- package/dist/game/tutorial/TutorialTheme.js.map +1 -0
- package/dist/game/tutorial/allowed.d.ts +2 -0
- package/dist/game/tutorial/allowed.d.ts.map +1 -0
- package/dist/game/tutorial/allowed.js +119 -0
- package/dist/game/tutorial/allowed.js.map +1 -0
- package/dist/game/tutorial/checks.d.ts +58 -0
- package/dist/game/tutorial/checks.d.ts.map +1 -0
- package/dist/game/tutorial/checks.js +144 -0
- package/dist/game/tutorial/checks.js.map +1 -0
- package/dist/game/tutorial/createDemoMatch.d.ts +47 -0
- package/dist/game/tutorial/createDemoMatch.d.ts.map +1 -0
- package/dist/game/tutorial/createDemoMatch.js +67 -0
- package/dist/game/tutorial/createDemoMatch.js.map +1 -0
- package/dist/game/tutorial/defineTutorial.d.ts +353 -0
- package/dist/game/tutorial/defineTutorial.d.ts.map +1 -0
- package/dist/game/tutorial/defineTutorial.js +86 -0
- package/dist/game/tutorial/defineTutorial.js.map +1 -0
- package/dist/game/tutorial/runTutorial.d.ts +64 -0
- package/dist/game/tutorial/runTutorial.d.ts.map +1 -0
- package/dist/game/tutorial/runTutorial.js +293 -0
- package/dist/game/tutorial/runTutorial.js.map +1 -0
- package/dist/hooks/usePanelNavigation.d.ts +28 -0
- package/dist/hooks/usePanelNavigation.d.ts.map +1 -0
- package/dist/hooks/usePanelNavigation.js +36 -0
- package/dist/hooks/usePanelNavigation.js.map +1 -0
- package/dist/hooks/useTimeController.d.ts +4 -1
- package/dist/hooks/useTimeController.d.ts.map +1 -1
- package/dist/hooks/useTimeController.js +10 -2
- package/dist/hooks/useTimeController.js.map +1 -1
- package/dist/hooks/useTutorial.d.ts +51 -0
- package/dist/hooks/useTutorial.d.ts.map +1 -0
- package/dist/hooks/useTutorial.js +16 -0
- package/dist/hooks/useTutorial.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/rendering/CameraWrapperPerspective.d.ts +5 -0
- package/dist/rendering/CameraWrapperPerspective.d.ts.map +1 -1
- package/dist/rendering/CameraWrapperPerspective.js +16 -0
- package/dist/rendering/CameraWrapperPerspective.js.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.d.ts +14 -3
- package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.js +29 -1
- package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
- package/dist/rendering/ChitRenderInstance.d.ts +15 -1
- package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/ChitRenderInstance.js +49 -4
- package/dist/rendering/ChitRenderInstance.js.map +1 -1
- package/dist/rendering/LightWrapper.d.ts.map +1 -1
- package/dist/rendering/LightWrapper.js +10 -1
- package/dist/rendering/LightWrapper.js.map +1 -1
- package/dist/rendering/RootChitRenderInstance.d.ts +2 -0
- package/dist/rendering/RootChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/RootChitRenderInstance.js +29 -0
- package/dist/rendering/RootChitRenderInstance.js.map +1 -1
- package/dist/rendering/Splay.d.ts +11 -0
- package/dist/rendering/Splay.d.ts.map +1 -1
- package/dist/rendering/Splay.js +20 -10
- package/dist/rendering/Splay.js.map +1 -1
- package/dist/utilities/Annotations.d.ts +15 -0
- package/dist/utilities/Annotations.d.ts.map +1 -1
- package/dist/utilities/Annotations.js +31 -7
- package/dist/utilities/Annotations.js.map +1 -1
- package/dist/utilities/CanvasStack/CanvasStack.d.ts +2 -0
- package/dist/utilities/CanvasStack/CanvasStack.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/CanvasStack.js +4 -0
- package/dist/utilities/CanvasStack/CanvasStack.js.map +1 -1
- package/dist/utilities/CanvasStack/RichTextRenderer.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/RichTextRenderer.js +12 -0
- package/dist/utilities/CanvasStack/RichTextRenderer.js.map +1 -1
- package/dist/utilities/Dice.d.ts +2 -0
- package/dist/utilities/Dice.d.ts.map +1 -1
- package/dist/utilities/Dice.js +5 -1
- package/dist/utilities/Dice.js.map +1 -1
- package/dist/utilities/GalleryItemConversion.d.ts.map +1 -1
- package/dist/utilities/GalleryItemConversion.js +5 -7
- package/dist/utilities/GalleryItemConversion.js.map +1 -1
- package/dist/utilities/TokenizedText.d.ts +6 -0
- package/dist/utilities/TokenizedText.d.ts.map +1 -1
- package/dist/utilities/TokenizedText.js.map +1 -1
- package/dist/utilities/zIndex.d.ts +1 -0
- package/dist/utilities/zIndex.d.ts.map +1 -1
- package/dist/utilities/zIndex.js +1 -0
- package/dist/utilities/zIndex.js.map +1 -1
- package/package.json +3 -2
- package/src/library/components/ActionLogDisplay.tsx +1 -0
- package/src/library/components/BottomBarButton.tsx +5 -0
- package/src/library/components/ContextGalleryDisplay.tsx +2 -0
- package/src/library/components/DemoWrapper.tsx +150 -44
- package/src/library/components/FullScreenGalleryDisplay.tsx +3 -0
- package/src/library/components/Gallery/BuiltItem.ts +92 -16
- package/src/library/components/Gallery/GalleryController.ts +111 -10
- package/src/library/components/Gallery/GalleryViewer.tsx +144 -12
- package/src/library/components/Gallery/LayoutManager.ts +55 -6
- package/src/library/components/Gallery/constants.ts +6 -0
- package/src/library/components/Gallery/registry.ts +44 -0
- package/src/library/components/Gallery/types.ts +6 -0
- package/src/library/components/GameDesigner.tsx +165 -12
- package/src/library/components/InlineGalleryDisplay.tsx +41 -6
- package/src/library/components/LiveButton.tsx +8 -5
- package/src/library/components/MatchViewer.tsx +14 -3
- package/src/library/components/Panel/ExternalDrag.ts +122 -0
- package/src/library/components/Panel/MultiPanel.tsx +21 -0
- package/src/library/components/Panel/PanelContents.tsx +96 -1
- package/src/library/components/Panel/PanelTabStack.tsx +1 -0
- package/src/library/components/PanelSpark.tsx +12 -5
- package/src/library/components/Playground.tsx +48 -21
- package/src/library/components/PromptControls.tsx +7 -3
- package/src/library/components/SparkLineChart.tsx +23 -27
- package/src/library/components/TimeControlBar.tsx +5 -3
- package/src/library/components/TokenizedMarkdown.tsx +224 -0
- package/src/library/components/TokenizedMessage.tsx +28 -32
- package/src/library/components/TopBar.tsx +2 -1
- package/src/library/components/TopBarPlayers.tsx +13 -15
- package/src/library/components/Tutorial/BrowserNarration.ts +233 -0
- package/src/library/components/Tutorial/TutorialBox.tsx +506 -0
- package/src/library/components/Tutorial/TutorialDevPanel.tsx +297 -0
- package/src/library/components/Tutorial/TutorialOverlay.tsx +1316 -0
- package/src/library/components/Tutorial/targetRects.ts +273 -0
- package/src/library/components/Viewer.tsx +1 -0
- package/src/library/game/Chit.ts +28 -7
- package/src/library/game/ClientTimeState.ts +18 -0
- package/src/library/game/GalleryItemChitChildrenSource.ts +1 -0
- package/src/library/game/GalleryItemRawSource.ts +1 -0
- package/src/library/game/Game.ts +7 -0
- package/src/library/game/GameButton.ts +13 -1
- package/src/library/game/GameTheme.ts +4 -0
- package/src/library/game/Match.ts +12 -2
- package/src/library/game/ModalState.ts +3 -0
- package/src/library/game/Pick.ts +17 -4
- package/src/library/game/PlayerPromptStatusChit.ts +6 -4
- package/src/library/game/Prompt.ts +33 -2
- package/src/library/game/SparkChit.ts +9 -0
- package/src/library/game/Turn.ts +185 -70
- package/src/library/game/TurnState.ts +26 -3
- package/src/library/game/ai/AI_GUIDE.md +10 -0
- package/src/library/game/ai/AiClientPrompts.ts +60 -11
- package/src/library/game/ai/AiPlayerView.ts +2 -0
- package/src/library/game/clientTransport/ClientPrompts.ts +76 -5
- package/src/library/game/clientTransport/ClientTime.ts +75 -14
- package/src/library/game/serialize.test.ts +275 -0
- package/src/library/game/tutorial/TUTORIAL_GUIDE.md +416 -0
- package/src/library/game/tutorial/TutorialController.test.ts +731 -0
- package/src/library/game/tutorial/TutorialController.ts +1299 -0
- package/src/library/game/tutorial/TutorialRuntime.ts +311 -0
- package/src/library/game/tutorial/TutorialTheme.ts +67 -0
- package/src/library/game/tutorial/allowed.ts +145 -0
- package/src/library/game/tutorial/checks.ts +186 -0
- package/src/library/game/tutorial/createDemoMatch.ts +115 -0
- package/src/library/game/tutorial/defineTutorial.ts +414 -0
- package/src/library/game/tutorial/runTutorial.ts +350 -0
- package/src/library/game/undo.test.ts +282 -0
- package/src/library/hooks/usePanelNavigation.tsx +65 -0
- package/src/library/hooks/useTimeController.tsx +10 -2
- package/src/library/hooks/useTutorial.tsx +80 -0
- package/src/library/index.ts +58 -2
- package/src/library/rendering/CameraWrapperPerspective.ts +17 -0
- package/src/library/rendering/ChitGalleryItemInstance.ts +30 -1
- package/src/library/rendering/ChitRenderInstance.ts +57 -4
- package/src/library/rendering/LightWrapper.ts +10 -1
- package/src/library/rendering/RootChitRenderInstance.ts +30 -1
- package/src/library/rendering/Splay.test.ts +60 -0
- package/src/library/rendering/Splay.ts +30 -9
- package/src/library/utilities/Annotations.ts +35 -7
- package/src/library/utilities/CanvasStack/CanvasStack.ts +6 -1
- package/src/library/utilities/CanvasStack/RichTextRenderer.ts +13 -0
- package/src/library/utilities/Dice.tsx +5 -1
- package/src/library/utilities/GalleryItemConversion.ts +5 -6
- package/src/library/utilities/TokenizedText.ts +6 -0
- 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, one moment at a time
|
|
479
|
+
expect(c.index.value).toBe(1);
|
|
480
|
+
expect(holds).toEqual([12, 11, 12]);
|
|
481
|
+
show(12, "Sam passes");
|
|
482
|
+
expect(holds).toEqual([12, 11, 12, 13]);
|
|
483
|
+
show(13, "Robin buys a card");
|
|
484
|
+
expect(holds).toEqual([12, 11, 12, 13]); // already held at the moment it was waiting for
|
|
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
|
+
});
|