@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,1316 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { Box } from "@mui/material";
|
|
3
|
+
import useSize from "@react-hook/size";
|
|
4
|
+
import { useTutorial } from "../../hooks/useTutorial";
|
|
5
|
+
import { useClientPrompts, useTimeController, useTimeState } from "../../hooks/useTimeController";
|
|
6
|
+
import { usePlayerId } from "../../hooks/usePlayer";
|
|
7
|
+
import { useGameTheme } from "../../hooks/useGameTheme";
|
|
8
|
+
import { useTokenMap } from "../../hooks/useTokenMap";
|
|
9
|
+
import { usePanelNavigation } from "../../hooks/usePanelNavigation";
|
|
10
|
+
import { useEventChannelState } from "../../hooks/useEventChannelState";
|
|
11
|
+
import { TutorialController, TutorialStatus, TutorialView } from "../../game/tutorial/TutorialController";
|
|
12
|
+
import { EventChannel } from "../../utilities/EventChannel";
|
|
13
|
+
import { samePasses } from "../../game/ClockDetails";
|
|
14
|
+
import { resolveTutorialTheme } from "../../game/tutorial/TutorialTheme";
|
|
15
|
+
import { BoxAnchor, BoxPlacement, Focus, Target } from "../../game/tutorial/defineTutorial";
|
|
16
|
+
import { PickPrompt } from "../../game/Prompt";
|
|
17
|
+
import { Chit } from "../../game/Chit";
|
|
18
|
+
import { PlayerChit } from "../../game/PlayerChit";
|
|
19
|
+
import { RootChit } from "../../game/RootChit";
|
|
20
|
+
import { ZINDEX_TUTORIAL } from "../../utilities/zIndex";
|
|
21
|
+
import { requestSharedAnimationFrame } from "../../utilities/RequestSharedAnimationFrame";
|
|
22
|
+
import { BrowserNarration } from "./BrowserNarration";
|
|
23
|
+
import { PanelShown, Rect, rectCenter, resolveTarget, tableRects, toLocal, unionRects } from "./targetRects";
|
|
24
|
+
import type { RootChitRenderInstance } from "../../rendering/RootChitRenderInstance";
|
|
25
|
+
import { UI_ALIASES } from "../../game/tutorial/allowed";
|
|
26
|
+
import { BoxPosition, TutorialBox } from "./TutorialBox";
|
|
27
|
+
import { useModalState } from "../../hooks/useModalState";
|
|
28
|
+
import { ModalState } from "../../game/ModalState";
|
|
29
|
+
import { GalleryCommand, TutorialGalleryState, selectChits } from "../../game/tutorial/defineTutorial";
|
|
30
|
+
import { GalleryItemSource } from "../Gallery/types";
|
|
31
|
+
import { GalleryItemChitChildrenSource } from "../../game/GalleryItemChitChildrenSource";
|
|
32
|
+
import { GalleryItemRawSource } from "../../game/GalleryItemRawSource";
|
|
33
|
+
import { chitsToGalleryItems } from "../../utilities/GalleryItemConversion";
|
|
34
|
+
import { RegisteredGallery } from "../Gallery/registry";
|
|
35
|
+
|
|
36
|
+
type DrawnFocus = {
|
|
37
|
+
/** One union box, or one per chit with `separate` */
|
|
38
|
+
rings: Rect[];
|
|
39
|
+
shape: "rect" | "ellipse";
|
|
40
|
+
arrows: Rect[];
|
|
41
|
+
dim: boolean;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** What the overlay draws, and for which step (placement must not mix two steps' targets) */
|
|
45
|
+
type Frame = { focus: DrawnFocus[]; debug: Rect[]; step: number };
|
|
46
|
+
|
|
47
|
+
const RING_PADDING = 8;
|
|
48
|
+
/** The box keeps this far from the screen's sides */
|
|
49
|
+
const BOX_MARGIN = 16;
|
|
50
|
+
/** A ringed thing smaller than this (its longer side, in pixels, with the whole table shown) gets zoomed in on */
|
|
51
|
+
const ZOOM_BELOW_PX = 28;
|
|
52
|
+
/** ...until its longer side is this share of its panel's shorter side, or this many pixels: enough to read it,
|
|
53
|
+
* with its surroundings still in view (a zoom that fills the panel loses where the thing is) */
|
|
54
|
+
const ZOOM_TO_SHARE = 0.3;
|
|
55
|
+
const ZOOM_TO_MAX_PX = 140;
|
|
56
|
+
/** Full screen hides every other panel, so it is used only when it buys something the camera cannot: a ringed thing
|
|
57
|
+
* smaller than FOCUS_TARGET_PX that zooming in its own panel cannot bring to READABLE_PX (the panel is too small, or the
|
|
58
|
+
* camera's max zoom too low), and whose panel full screen would grow at least FOCUS_GAIN times. A board overview, a
|
|
59
|
+
* badge, anything readable in place stays in the normal layout, beside the rest of the table (the developer: "it should
|
|
60
|
+
* only go full screen when it'd gain something meaningful. otherwise you're losing context") */
|
|
61
|
+
const FOCUS_TARGET_PX = 24;
|
|
62
|
+
const READABLE_PX = 40;
|
|
63
|
+
const FOCUS_GAIN = 1.5;
|
|
64
|
+
/** A zoom the step asks for outright (`zoom: 1.6`) applies on a screen smaller than this (its shorter side: a phone) */
|
|
65
|
+
const SMALL_SCREEN_PX = 500;
|
|
66
|
+
/** The dim stays this long after nothing asks for it (a ring hidden by a tab slide, a sentence with no ring), so the
|
|
67
|
+
* gaps between rings do not blink it off and on */
|
|
68
|
+
const DIM_HOLD_MS = 400;
|
|
69
|
+
/** How long a ring that leapt in one frame stays where it was (see the ring tick) */
|
|
70
|
+
const JUMP_HOLD_MS = 120;
|
|
71
|
+
|
|
72
|
+
function sameFrame(a: Frame, b: Frame) {
|
|
73
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function overlapArea(a: Rect, b: Rect) {
|
|
77
|
+
const w = Math.min(a.right, b.right) - Math.max(a.left, b.left);
|
|
78
|
+
const h = Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top);
|
|
79
|
+
return w > 0 && h > 0 ? w * h : 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const RING_BREATHING_ROOM = 20;
|
|
83
|
+
/** Arrows need room to be seen, so their targets push the box further away */
|
|
84
|
+
const ARROW_BREATHING_ROOM = 44;
|
|
85
|
+
|
|
86
|
+
/** A target the box keeps clear of; `weight` makes sitting next to an arrow's tip count as covering it */
|
|
87
|
+
type Avoid = { rect: Rect; room: number; weight: number };
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* How badly `box` hides the targets: the sum over targets of the fraction of each target (plus its
|
|
91
|
+
* breathing room) that the box covers. A small counter fully under the box counts as 1, the same as
|
|
92
|
+
* a whole card; the box's own size does not matter.
|
|
93
|
+
*/
|
|
94
|
+
function coverage(box: Rect, targets: Avoid[]) {
|
|
95
|
+
return targets.reduce((acc, { rect: t, room, weight }) => {
|
|
96
|
+
const padded: Rect = { left: t.left - room, top: t.top - room, right: t.right + room, bottom: t.bottom + room };
|
|
97
|
+
const area = Math.max(1, (padded.right - padded.left) * (padded.bottom - padded.top));
|
|
98
|
+
return acc + (overlapArea(box, padded) / area) * weight;
|
|
99
|
+
}, 0);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Every rect the overlay is drawing right now: the box must not sit on any of them */
|
|
103
|
+
function targetRects(frame: Frame): Avoid[] {
|
|
104
|
+
return frame.focus.flatMap((f) => [
|
|
105
|
+
...f.rings.map((rect) => ({ rect, room: RING_BREATHING_ROOM, weight: 1 })),
|
|
106
|
+
...f.arrows.map((rect) => ({ rect, room: ARROW_BREATHING_ROOM, weight: 3 })),
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function sameAvoid(a: Avoid, b: Avoid) {
|
|
111
|
+
return (
|
|
112
|
+
a.room === b.room &&
|
|
113
|
+
Math.abs(a.rect.left - b.rect.left) < 2 &&
|
|
114
|
+
Math.abs(a.rect.top - b.rect.top) < 2 &&
|
|
115
|
+
Math.abs(a.rect.right - b.rect.right) < 2 &&
|
|
116
|
+
Math.abs(a.rect.bottom - b.rect.bottom) < 2
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The 2D tutorial layer over the whole player: rings and arrows (SVG) that follow chits and UI, the
|
|
122
|
+
* draggable text box, and the controller that drives them. Renders nothing unless the match was
|
|
123
|
+
* started with a tutorial (see `TutorialProvider`).
|
|
124
|
+
*/
|
|
125
|
+
export function TutorialOverlay() {
|
|
126
|
+
const tutorial = useTutorial();
|
|
127
|
+
if (!tutorial) return null;
|
|
128
|
+
return <InnerOverlay />;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function InnerOverlay() {
|
|
132
|
+
const tutorial = useTutorial()!;
|
|
133
|
+
const clientTime = useTimeController();
|
|
134
|
+
const clientPrompts = useClientPrompts();
|
|
135
|
+
const timeState = useTimeState();
|
|
136
|
+
const playerId = usePlayerId();
|
|
137
|
+
const gameTheme = useGameTheme();
|
|
138
|
+
const tokenMap = useTokenMap();
|
|
139
|
+
const navigation = usePanelNavigation();
|
|
140
|
+
const modalState = useModalState();
|
|
141
|
+
const theme = useMemo(
|
|
142
|
+
() => resolveTutorialTheme(gameTheme, tutorial.spec.theme, tutorial.themeOverrides),
|
|
143
|
+
[gameTheme, tutorial.spec.theme, tutorial.themeOverrides],
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
147
|
+
const [width, height] = useSize(ref);
|
|
148
|
+
const [rootChit] = useEventChannelState(clientTime.rootChit);
|
|
149
|
+
const [isLoading] = useEventChannelState(timeState.isLoading);
|
|
150
|
+
const [live] = useEventChannelState(timeState.live);
|
|
151
|
+
const [controller, setController] = useState<TutorialController<any, any> | undefined>();
|
|
152
|
+
const [started, setStarted] = useState(tutorial.autoStart);
|
|
153
|
+
const [dev] = useEventChannelState(tutorial.dev);
|
|
154
|
+
const [muted] = useEventChannelState(tutorial.muted);
|
|
155
|
+
|
|
156
|
+
// ---- the controller, built once the board exists -------------------------------------------
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (!rootChit || controller) return;
|
|
159
|
+
const view: TutorialView<PlayerChit, RootChit<PlayerChit>> = {
|
|
160
|
+
root: () => clientTime.rootChit.value,
|
|
161
|
+
me: () => clientTime.rootChit.value?.players.find((p) => p.id === playerId),
|
|
162
|
+
prompt: () => {
|
|
163
|
+
const p = clientPrompts.currentPrompt.value;
|
|
164
|
+
return p instanceof PickPrompt ? p : undefined;
|
|
165
|
+
},
|
|
166
|
+
clock: () => clientTime.currentClock.value.clock,
|
|
167
|
+
find: (id) => clientTime.findChitUnsafe(id),
|
|
168
|
+
latestLog: () => clientTime.activeLog.value,
|
|
169
|
+
live: () => timeState.live.value,
|
|
170
|
+
onChange: (cb) => {
|
|
171
|
+
const unsubs = [
|
|
172
|
+
clientTime.currentClock.on(cb, false),
|
|
173
|
+
clientTime.rootChit.on(cb, false),
|
|
174
|
+
clientTime.activeLog.on(cb, false),
|
|
175
|
+
clientPrompts.currentPrompt.on(cb, false),
|
|
176
|
+
timeState.live.on(cb, false),
|
|
177
|
+
modalState.gallerySource.on(cb, false),
|
|
178
|
+
modalState.inlineGallerySource.on(cb, false),
|
|
179
|
+
];
|
|
180
|
+
return () => unsubs.forEach((u) => u());
|
|
181
|
+
},
|
|
182
|
+
setGuard: (guard) => {
|
|
183
|
+
clientPrompts.guard = guard ? (_prompt, action) => guard(action) : undefined;
|
|
184
|
+
},
|
|
185
|
+
setUndo: (undo) => {
|
|
186
|
+
clientPrompts.undoOverride.value = undo;
|
|
187
|
+
},
|
|
188
|
+
galleries: () => describeGalleries(modalState),
|
|
189
|
+
setGallery: (command) =>
|
|
190
|
+
applyGalleryCommand(
|
|
191
|
+
modalState,
|
|
192
|
+
command,
|
|
193
|
+
clientTime.rootChit.value,
|
|
194
|
+
clientTime.rootChit.value?.players.find((p) => p.id === playerId),
|
|
195
|
+
),
|
|
196
|
+
onBlocked: (cb) => clientPrompts.blocked.on((b) => b && cb(b.action), false),
|
|
197
|
+
// Poses change this client's copy of a chit only; the match never hears of them
|
|
198
|
+
pose: (chit, change) => clientTime.poseChit(chit, change),
|
|
199
|
+
unpose: (chit) => clientTime.restoreChit(chit),
|
|
200
|
+
// Holds only how far this board plays; the match runs on behind it
|
|
201
|
+
timeline: {
|
|
202
|
+
at: () => Math.max(clientTime.currentClock.value.clock, timeState.targetClock.value),
|
|
203
|
+
hold: (clock) => {
|
|
204
|
+
timeState.timelineHold.value = clock;
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
pressUi: (name) => {
|
|
208
|
+
const el = (UI_ALIASES[name] ?? [name])
|
|
209
|
+
.map((n) => document.querySelector(`[data-tutorial-target="${CSS.escape(n)}"]`) as HTMLElement | null)
|
|
210
|
+
.find((e) => e && e.getBoundingClientRect().width > 0);
|
|
211
|
+
if (!el) return false;
|
|
212
|
+
// a target is often a wrapper around the actual control
|
|
213
|
+
const control = (el.matches("button, [role=button]") ? el : el.querySelector("button, [role=button]")) ?? el;
|
|
214
|
+
(control as HTMLElement).click();
|
|
215
|
+
return true;
|
|
216
|
+
},
|
|
217
|
+
settled: () =>
|
|
218
|
+
!timeState.isWaitingOnAnimations.value &&
|
|
219
|
+
clientTime.currentClock.value.clock >= clientTime.maxClock.value.clock,
|
|
220
|
+
setFastForward: (on) => {
|
|
221
|
+
timeState.animationSpeedOverrideMultiplier.value = on ? 0.05 : undefined;
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
const { snapshot, rewind, runtime } = tutorial;
|
|
225
|
+
const c = new TutorialController({
|
|
226
|
+
spec: tutorial.spec,
|
|
227
|
+
view,
|
|
228
|
+
runtime,
|
|
229
|
+
narration: new BrowserNarration(),
|
|
230
|
+
ai: tutorial.ai,
|
|
231
|
+
onEvent: tutorial.onEvent,
|
|
232
|
+
muted: tutorial.muted.value,
|
|
233
|
+
rate: readRate(),
|
|
234
|
+
history:
|
|
235
|
+
snapshot && rewind
|
|
236
|
+
? {
|
|
237
|
+
save: (stepId) => runtime.saveSnapshot(stepId, snapshot()),
|
|
238
|
+
restore: async (stepId, index) => {
|
|
239
|
+
// Watch the history live, then wait for the rerun (a new clock pass) to reach this view
|
|
240
|
+
if (!timeState.live.value) timeState.live.value = true;
|
|
241
|
+
const before = clientTime.currentClock.value.pass;
|
|
242
|
+
// Skipping ahead shows the board as it is at that step, not each move on the way there:
|
|
243
|
+
// the view goes straight to the rerun's latest clock, with no time to animate
|
|
244
|
+
const ahead = index > (tutorial.controller.value?.frontier.value ?? -1);
|
|
245
|
+
const started = Date.now();
|
|
246
|
+
const unsubJump = ahead
|
|
247
|
+
? clientTime.maxClock.on((max) => {
|
|
248
|
+
if (max.pass !== before) timeState.targetClock.value = max.clock;
|
|
249
|
+
}, false)
|
|
250
|
+
: undefined;
|
|
251
|
+
if (ahead) timeState.animationSpeedOverrideMultiplier.value = 0.001;
|
|
252
|
+
const done = (ok: boolean) => {
|
|
253
|
+
unsubJump?.();
|
|
254
|
+
if (ahead) {
|
|
255
|
+
timeState.animationSpeedOverrideMultiplier.value = undefined;
|
|
256
|
+
console.info(`[tutorial] skipped to step ${index + 1} in ${Date.now() - started} ms`);
|
|
257
|
+
}
|
|
258
|
+
return ok;
|
|
259
|
+
};
|
|
260
|
+
if (!(await rewind(stepId))) return done(false);
|
|
261
|
+
const deadline = Date.now() + 8000;
|
|
262
|
+
while (Date.now() < deadline) {
|
|
263
|
+
const current = clientTime.currentClock.value;
|
|
264
|
+
const max = clientTime.maxClock.value;
|
|
265
|
+
if (
|
|
266
|
+
current.pass !== before &&
|
|
267
|
+
current.clock === max.clock &&
|
|
268
|
+
samePasses(current, max) &&
|
|
269
|
+
!timeState.isWaitingOnAnimations.value
|
|
270
|
+
) {
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
await new Promise((resolve) => setTimeout(resolve, ahead ? 5 : 50));
|
|
274
|
+
}
|
|
275
|
+
return done(true);
|
|
276
|
+
},
|
|
277
|
+
}
|
|
278
|
+
: undefined,
|
|
279
|
+
});
|
|
280
|
+
setController(c);
|
|
281
|
+
tutorial.controller.value = c;
|
|
282
|
+
c.rate.on((rate) => writeRate(rate), false);
|
|
283
|
+
if (tutorial.autoStart) {
|
|
284
|
+
// After a rewind or a dev restart: the board is already there and the player already tapped once
|
|
285
|
+
setStarted(true);
|
|
286
|
+
c.start(tutorial.startAt, { paused: tutorial.startPaused });
|
|
287
|
+
} else if (tutorial.resumeAt) {
|
|
288
|
+
// A reload comes back to the step the player was on, with the board as it was then
|
|
289
|
+
const index = c.steps.findIndex((s) => s.id === tutorial.resumeAt);
|
|
290
|
+
if (index > 0) {
|
|
291
|
+
setStarted(true);
|
|
292
|
+
c.skipTo(index);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}, [rootChit, controller, clientTime, clientPrompts, timeState, playerId, tutorial, modalState]);
|
|
296
|
+
|
|
297
|
+
useEffect(() => {
|
|
298
|
+
return () => {
|
|
299
|
+
controller?.dispose();
|
|
300
|
+
if (tutorial.controller.value === controller) tutorial.controller.value = undefined;
|
|
301
|
+
};
|
|
302
|
+
}, [controller, tutorial]);
|
|
303
|
+
|
|
304
|
+
useEffect(() => {
|
|
305
|
+
controller?.setMuted(muted);
|
|
306
|
+
}, [controller, muted]);
|
|
307
|
+
|
|
308
|
+
// A move inside an open prompt (a piece dragged within the build prompt) changes the board without any of the
|
|
309
|
+
// view's channels firing, so a check waiting on it never re-ran and the step hung ("it gets stuck on me dragging
|
|
310
|
+
// my dealer"). Re-run the check a few times a second as well; the headless runner polls the same way.
|
|
311
|
+
useEffect(() => {
|
|
312
|
+
if (!controller) return;
|
|
313
|
+
const poll = setInterval(() => controller.recheck(), 250);
|
|
314
|
+
return () => clearInterval(poll);
|
|
315
|
+
}, [controller]);
|
|
316
|
+
|
|
317
|
+
// Tapping a control the next "do it" step asks for counts as moving on to that step. Listen in the
|
|
318
|
+
// capture phase so the step is entered (and its check baselined) before the control acts.
|
|
319
|
+
useEffect(() => {
|
|
320
|
+
if (!controller) return;
|
|
321
|
+
const onClick = (e: MouseEvent) => {
|
|
322
|
+
const el = (e.target as Element | null)?.closest?.("[data-tutorial-target]");
|
|
323
|
+
const name = el?.getAttribute("data-tutorial-target");
|
|
324
|
+
if (name) controller.usedUi(name);
|
|
325
|
+
};
|
|
326
|
+
document.addEventListener("click", onClick, true);
|
|
327
|
+
return () => document.removeEventListener("click", onClick, true);
|
|
328
|
+
}, [controller]);
|
|
329
|
+
|
|
330
|
+
// Keyboard: → next step (or, while a step waits for the player, makes its move for them), ← previous
|
|
331
|
+
// step, Space play/pause. Otherwise the same as the box's buttons. Before the start, → or Enter starts.
|
|
332
|
+
const startRef = useRef<() => void>(() => undefined);
|
|
333
|
+
useEffect(() => {
|
|
334
|
+
if (!controller) return;
|
|
335
|
+
const onKey = (e: KeyboardEvent) => {
|
|
336
|
+
if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) return;
|
|
337
|
+
const el = e.target as HTMLElement | null;
|
|
338
|
+
if (el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName))) return;
|
|
339
|
+
const status = controller.status.value;
|
|
340
|
+
if (status === "idle") {
|
|
341
|
+
if (e.key !== "ArrowRight" && e.key !== "Enter") return;
|
|
342
|
+
startRef.current();
|
|
343
|
+
e.preventDefault();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (status === "done") return;
|
|
347
|
+
if (e.key === "ArrowRight") controller.forward();
|
|
348
|
+
else if (e.key === "ArrowLeft") controller.back();
|
|
349
|
+
else if (e.key === " ") {
|
|
350
|
+
// a focused button would also take the space as a click
|
|
351
|
+
if (el?.tagName === "BUTTON") el.blur();
|
|
352
|
+
controller.toggleNarration();
|
|
353
|
+
} else return;
|
|
354
|
+
e.preventDefault();
|
|
355
|
+
};
|
|
356
|
+
window.addEventListener("keydown", onKey);
|
|
357
|
+
return () => window.removeEventListener("keydown", onKey);
|
|
358
|
+
}, [controller]);
|
|
359
|
+
|
|
360
|
+
const onStart = useCallback(() => {
|
|
361
|
+
if (!controller || controller.status.value !== "idle") return;
|
|
362
|
+
setStarted(true);
|
|
363
|
+
controller.start(tutorial.startAt);
|
|
364
|
+
}, [controller, tutorial.startAt]);
|
|
365
|
+
startRef.current = onStart;
|
|
366
|
+
// Skipping to a step (the dev panel) starts the tutorial too
|
|
367
|
+
useEffect(() => {
|
|
368
|
+
if (!controller) return;
|
|
369
|
+
const update = () => {
|
|
370
|
+
if (controller.status.value !== "idle" || controller.rewinding.value) setStarted(true);
|
|
371
|
+
};
|
|
372
|
+
const unsubs = [controller.status.on(update, false), controller.rewinding.on(update, false)];
|
|
373
|
+
return () => unsubs.forEach((u) => u());
|
|
374
|
+
}, [controller]);
|
|
375
|
+
|
|
376
|
+
// ---- per-frame target resolution ------------------------------------------------------------
|
|
377
|
+
const [focus] = useEventChannelState(controller?.focus ?? EMPTY_FOCUS);
|
|
378
|
+
const [status] = useEventChannelState(controller?.status ?? IDLE);
|
|
379
|
+
// Everything this step has pointed at so far: an earlier sentence's target stays relevant while
|
|
380
|
+
// the step is on screen, so the box keeps clear of it too. Keyed by the step the frame was drawn for.
|
|
381
|
+
const stepTargetsRef = useRef<{ step: number; targets: Avoid[] }>({ step: -1, targets: [] });
|
|
382
|
+
const [placement] = useEventChannelState(controller?.box ?? NO_BOX);
|
|
383
|
+
const [frame, setFrame] = useState<Frame>({ focus: [], debug: [], step: -1 });
|
|
384
|
+
const frameRef = useRef(frame);
|
|
385
|
+
/** Rings that leapt in one frame, per focus entry: since when (see the ring tick) */
|
|
386
|
+
const jumpRef = useRef<{ focus: unknown; since: (number | undefined)[] }>({ focus: undefined, since: [] });
|
|
387
|
+
const [boxSize, setBoxSize] = useState({ width: theme.boxWidth, height: 160 });
|
|
388
|
+
// Dragging a narrower box is still allowed; the drag is clamped to the viewer
|
|
389
|
+
const [boxPos, setBoxPos] = useState<BoxPosition>({ x: 16, y: 16 });
|
|
390
|
+
// The latest box rect, for the framing (an effect that outlives renders)
|
|
391
|
+
const boxPosRef = useRef(boxPos);
|
|
392
|
+
boxPosRef.current = boxPos;
|
|
393
|
+
const boxSizeRef = useRef(boxSize);
|
|
394
|
+
boxSizeRef.current = boxSize;
|
|
395
|
+
const userDraggedRef = useRef(false);
|
|
396
|
+
const targetRectRef = useRef<Rect | undefined>(undefined);
|
|
397
|
+
|
|
398
|
+
const active = started && status !== "done" && live;
|
|
399
|
+
// Keep the box off the top and bottom bars: the player needs the prompt buttons the script points at
|
|
400
|
+
const safeTop = gameTheme.topBarHeight + 12;
|
|
401
|
+
const safeBottom = gameTheme.bottomBarHeight + 12;
|
|
402
|
+
/** Where the box may sit: inside the screen, clear of the top and bottom bars */
|
|
403
|
+
const clampBox = useCallback(
|
|
404
|
+
(p: BoxPosition): BoxPosition => ({
|
|
405
|
+
x: Math.max(BOX_MARGIN, Math.min(width - boxSize.width - BOX_MARGIN, p.x)),
|
|
406
|
+
y: Math.max(safeTop, Math.min(height - boxSize.height - safeBottom, p.y)),
|
|
407
|
+
}),
|
|
408
|
+
[width, height, boxSize.width, boxSize.height, safeTop, safeBottom],
|
|
409
|
+
);
|
|
410
|
+
// A chit is on screen only if its panel is in front of its tab group: one behind still paints during
|
|
411
|
+
// a tab slide, from where it would be, and a ring drawn there points at the wrong panel
|
|
412
|
+
const shown = useCallback<PanelShown>(
|
|
413
|
+
(chit) => {
|
|
414
|
+
if (!navigation) return true;
|
|
415
|
+
const roots = new Set(navigation.panelRoots().map((c) => c.id));
|
|
416
|
+
let panel: Chit | undefined = chit;
|
|
417
|
+
while (panel && !roots.has(panel.id)) panel = panel.parent;
|
|
418
|
+
return !panel?.id || navigation.isFront(panel.id);
|
|
419
|
+
},
|
|
420
|
+
[navigation],
|
|
421
|
+
);
|
|
422
|
+
// The box floats on every screen size; on a narrow one it just gets narrower
|
|
423
|
+
const boxWidth = Math.max(220, Math.min(theme.boxWidth, width - 32));
|
|
424
|
+
|
|
425
|
+
// Bring hidden targets on screen, and keep doing so for as long as the step has one: the panel
|
|
426
|
+
// stack flips to wherever the bots act, and a target that is off screen explains nothing
|
|
427
|
+
useEffect(() => {
|
|
428
|
+
if (!active || !navigation || !controller) return;
|
|
429
|
+
let cancelled = false;
|
|
430
|
+
let revealing = false;
|
|
431
|
+
let revealedOnce = false;
|
|
432
|
+
const attempt = () => {
|
|
433
|
+
if (cancelled || revealing) return;
|
|
434
|
+
const container = ref.current;
|
|
435
|
+
if (!container) return;
|
|
436
|
+
const ctx = controller.context();
|
|
437
|
+
const root = ctx?.root;
|
|
438
|
+
const me = ctx?.me;
|
|
439
|
+
const hidden = new Set<Chit>();
|
|
440
|
+
const visible = new Set<Chit>();
|
|
441
|
+
const scroll: { gallery: RegisteredGallery; chit: Chit }[] = [];
|
|
442
|
+
focus.forEach((f: Focus<any, any>) => {
|
|
443
|
+
if (f.reveal === false) return;
|
|
444
|
+
const targets: Target<any, any>[] = [];
|
|
445
|
+
if (f.ring) targets.push(f.ring);
|
|
446
|
+
if (f.arrow && f.arrow !== true) targets.push(f.arrow);
|
|
447
|
+
targets.forEach((t) => {
|
|
448
|
+
const resolved = resolveTarget(t, root, me, container, shown, ctx?.find);
|
|
449
|
+
resolved.hidden.forEach((c) => hidden.add(c));
|
|
450
|
+
resolved.chits.forEach((c) => !resolved.hidden.includes(c) && visible.add(c));
|
|
451
|
+
scroll.push(...resolved.offscreenInGallery);
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
// Items scrolled out of an open gallery: bring the first one into view
|
|
455
|
+
if (scroll.length > 0) scroll[0].gallery.scrollTo(scroll[0].chit);
|
|
456
|
+
// What shows stays in front: its tab group would otherwise slide off to wherever a bot just moved
|
|
457
|
+
visible.forEach((c) => navigation.keepFront(c));
|
|
458
|
+
if (hidden.size === 0) return;
|
|
459
|
+
// Targets in two panels of one tab group cannot both show: switch once, not back and forth
|
|
460
|
+
if (visible.size > 0 && revealedOnce) return;
|
|
461
|
+
revealedOnce = true;
|
|
462
|
+
revealing = true;
|
|
463
|
+
void navigation.revealChit([...hidden][0]).finally(() => {
|
|
464
|
+
revealing = false;
|
|
465
|
+
});
|
|
466
|
+
};
|
|
467
|
+
const first = setTimeout(attempt, 50);
|
|
468
|
+
const interval = setInterval(attempt, 400);
|
|
469
|
+
return () => {
|
|
470
|
+
cancelled = true;
|
|
471
|
+
clearTimeout(first);
|
|
472
|
+
clearInterval(interval);
|
|
473
|
+
};
|
|
474
|
+
}, [focus, active, navigation, controller, shown]);
|
|
475
|
+
|
|
476
|
+
// Frame what the step is about. When everything it rings on the table sits in one panel and is too small
|
|
477
|
+
// to read even with that panel's camera zoomed (see FOCUS_TARGET_PX), show that panel full screen (as
|
|
478
|
+
// zooming in does, with every panel as a tab); anything readable in place stays beside the rest of the
|
|
479
|
+
// table. Rings in another panel go back
|
|
480
|
+
// to the normal layout first, and full screen comes back only if that one needs it too: switching
|
|
481
|
+
// tabs inside full screen, sentence after sentence, flips panels with no context. Then, if the thing
|
|
482
|
+
// is still tiny, zoom the camera in on it, and keep that zoom while the step's later rings still show
|
|
483
|
+
// in it. Both are undone when no longer needed (not if the player zoomed or focused meanwhile: that is
|
|
484
|
+
// theirs). Only what is ringed counts, and only on the table (a gallery shows things at a readable
|
|
485
|
+
// size already).
|
|
486
|
+
const zoomRef = useRef<{ panel: RootChitRenderInstance; zoom: number } | undefined>(undefined);
|
|
487
|
+
const focusedByUsRef = useRef<Chit | undefined>(undefined);
|
|
488
|
+
/** The step whose rings set the current framing */
|
|
489
|
+
const framedStepRef = useRef(-1);
|
|
490
|
+
// The framing moved the targets: the box's memory of where they were this step is out of date
|
|
491
|
+
const forgetTargets = () => {
|
|
492
|
+
stepTargetsRef.current.targets = [];
|
|
493
|
+
};
|
|
494
|
+
const unzoom = useCallback(() => {
|
|
495
|
+
const z = zoomRef.current;
|
|
496
|
+
zoomRef.current = undefined;
|
|
497
|
+
if (z && Math.abs(z.panel.cameraZoom - z.zoom) < 0.01) {
|
|
498
|
+
z.panel.focusCamera(z.panel.width / 2, z.panel.height / 2, 1);
|
|
499
|
+
forgetTargets();
|
|
500
|
+
}
|
|
501
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
502
|
+
}, []);
|
|
503
|
+
const unfocus = useCallback(() => {
|
|
504
|
+
const ours = focusedByUsRef.current;
|
|
505
|
+
focusedByUsRef.current = undefined;
|
|
506
|
+
if (ours && navigation?.focusedPanel()) void navigation.focusPanelOf(undefined);
|
|
507
|
+
}, [navigation]);
|
|
508
|
+
useEffect(() => {
|
|
509
|
+
if (!active || !controller) {
|
|
510
|
+
unzoom();
|
|
511
|
+
unfocus();
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
let cancelled = false;
|
|
515
|
+
const ringed = () => {
|
|
516
|
+
const container = ref.current;
|
|
517
|
+
const ctx = controller.context();
|
|
518
|
+
const found: { rect: Rect; panel: RootChitRenderInstance }[] = [];
|
|
519
|
+
const panels = new Map<string, Chit>(); // panel root id → a ringed chit in it
|
|
520
|
+
let inGallery = false;
|
|
521
|
+
let asked: number | undefined; // a zoom the step asks for outright
|
|
522
|
+
if (!container || !navigation) return { found, panels, inGallery, asked };
|
|
523
|
+
const roots = new Set(navigation.panelRoots().map((c) => c.id));
|
|
524
|
+
focus.forEach((f: Focus<any, any>) => {
|
|
525
|
+
if (f.reveal === false || f.zoom === false || !f.ring) return;
|
|
526
|
+
const t = f.ring;
|
|
527
|
+
if (typeof t !== "function" && !("chit" in t)) return; // a UI or screen target
|
|
528
|
+
if (typeof f.zoom === "number") asked = Math.max(asked ?? 1, f.zoom);
|
|
529
|
+
const table = tableRects(t, ctx?.root, ctx?.me, container, shown);
|
|
530
|
+
inGallery ||= table.inGallery;
|
|
531
|
+
found.push(...table.rects);
|
|
532
|
+
for (const c of selectChits(typeof t === "function" ? t : t.chit, ctx?.root, ctx?.me)) {
|
|
533
|
+
let p: Chit | undefined = c;
|
|
534
|
+
while (p && !roots.has(p.id)) p = p.parent;
|
|
535
|
+
if (p?.id) panels.set(p.id, c);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
return { found, panels, inGallery, asked };
|
|
539
|
+
};
|
|
540
|
+
const zoomIn = () => {
|
|
541
|
+
const { found, inGallery, asked, panels } = ringed();
|
|
542
|
+
// Nothing to frame in this cue (only rings that flash by, or UI): keep the step's framing; a new
|
|
543
|
+
// step starts zoomed out
|
|
544
|
+
if (panels.size === 0 && !inGallery) {
|
|
545
|
+
if (controller.index.value !== framedStepRef.current) unzoom();
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
const sameStep = framedStepRef.current === controller.index.value;
|
|
549
|
+
framedStepRef.current = controller.index.value;
|
|
550
|
+
const panel = found[0]?.panel;
|
|
551
|
+
if (!panel || inGallery || found.some((f) => f.panel !== panel)) return unzoom();
|
|
552
|
+
// Only one panel is remembered as zoomed: moving the framing to another panel zooms the first back out, or
|
|
553
|
+
// it would stay zoomed in for good and its later rings land off-screen (Lisboa's Court card → Influence disc
|
|
554
|
+
// → Manuel's office)
|
|
555
|
+
if (zoomRef.current && zoomRef.current.panel !== panel) unzoom();
|
|
556
|
+
const union = unionRects(found.map((f) => f.rect))!;
|
|
557
|
+
const topLeft = panel.convertCameraSpaceToScreenSpace(-1, 1);
|
|
558
|
+
const bottomRight = panel.convertCameraSpaceToScreenSpace(1, -1);
|
|
559
|
+
if (!topLeft || !bottomRight) return;
|
|
560
|
+
// Later in the same step, a zoom whose view still shows every ring stays: re-framing each sentence is a
|
|
561
|
+
// camera that never stops moving
|
|
562
|
+
const inset = 8;
|
|
563
|
+
if (
|
|
564
|
+
sameStep &&
|
|
565
|
+
zoomRef.current?.panel === panel &&
|
|
566
|
+
union.left >= topLeft.x + inset &&
|
|
567
|
+
union.right <= bottomRight.x - inset &&
|
|
568
|
+
union.top >= topLeft.y + inset &&
|
|
569
|
+
union.bottom <= bottomRight.y - inset
|
|
570
|
+
)
|
|
571
|
+
return;
|
|
572
|
+
// its longer side with the whole table shown
|
|
573
|
+
const current = panel.cameraZoom;
|
|
574
|
+
const size = Math.max(union.right - union.left, union.bottom - union.top) / current;
|
|
575
|
+
// Where the thing should end up: the part of the panel the box leaves free (above or below it)
|
|
576
|
+
const bounds = ref.current!.getBoundingClientRect();
|
|
577
|
+
const box = {
|
|
578
|
+
left: bounds.left + boxPosRef.current.x,
|
|
579
|
+
top: bounds.top + boxPosRef.current.y,
|
|
580
|
+
right: bounds.left + boxPosRef.current.x + boxSizeRef.current.width,
|
|
581
|
+
bottom: bounds.top + boxPosRef.current.y + boxSizeRef.current.height,
|
|
582
|
+
};
|
|
583
|
+
let bandTop = topLeft.y;
|
|
584
|
+
let bandBottom = bottomRight.y;
|
|
585
|
+
if (box.right > topLeft.x && box.left < bottomRight.x && box.bottom > topLeft.y && box.top < bottomRight.y) {
|
|
586
|
+
if (box.top - topLeft.y >= bottomRight.y - box.bottom) bandBottom = Math.max(topLeft.y + 1, box.top);
|
|
587
|
+
else bandTop = Math.min(bottomRight.y - 1, box.bottom);
|
|
588
|
+
}
|
|
589
|
+
const panelShort = Math.min(bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
|
|
590
|
+
// a zoom the step asks for is for small screens, like the full-screen panel
|
|
591
|
+
const smallScreen = Math.min(width, height) < SMALL_SCREEN_PX;
|
|
592
|
+
const fits = Math.min(0.85 * (bandBottom - bandTop), 0.85 * (bottomRight.x - topLeft.x)) / size;
|
|
593
|
+
const wanted =
|
|
594
|
+
asked && smallScreen ? asked : size < ZOOM_BELOW_PX ? Math.min(Math.min(panelShort * ZOOM_TO_SHARE, ZOOM_TO_MAX_PX) / size, fits) : 1;
|
|
595
|
+
const zoom = Math.min(wanted, panel.cameraWrapper.cameraSpec.maxZoom);
|
|
596
|
+
if (zoom < 1.25) return unzoom();
|
|
597
|
+
// focusCamera brings a point to the middle: pick the point that puts the thing in the free band
|
|
598
|
+
const c = rectCenter(union);
|
|
599
|
+
const shift = ((bandTop + bandBottom) / 2 - (topLeft.y + bottomRight.y) / 2) * (current / zoom);
|
|
600
|
+
panel.focusCamera(c.x - topLeft.x, c.y - shift - topLeft.y, zoom);
|
|
601
|
+
zoomRef.current = { panel, zoom: panel.cameraZoom };
|
|
602
|
+
forgetTargets();
|
|
603
|
+
};
|
|
604
|
+
const frame = async () => {
|
|
605
|
+
if (cancelled || !navigation) return;
|
|
606
|
+
const { panels, inGallery } = ringed();
|
|
607
|
+
// A new step with nothing on the table (a button, the box alone): full screen we chose goes
|
|
608
|
+
if (
|
|
609
|
+
panels.size === 0 &&
|
|
610
|
+
!inGallery &&
|
|
611
|
+
focusedByUsRef.current &&
|
|
612
|
+
navigation.focusedPanel() &&
|
|
613
|
+
controller.index.value !== framedStepRef.current
|
|
614
|
+
) {
|
|
615
|
+
unzoom();
|
|
616
|
+
focusedByUsRef.current = undefined;
|
|
617
|
+
await navigation.focusPanelOf(undefined);
|
|
618
|
+
forgetTargets();
|
|
619
|
+
}
|
|
620
|
+
if (!inGallery && panels.size > 1 && navigation.focusedPanel()) {
|
|
621
|
+
// the step needs more than one panel: the normal layout shows them side by side
|
|
622
|
+
unzoom();
|
|
623
|
+
focusedByUsRef.current = undefined;
|
|
624
|
+
await navigation.focusPanelOf(undefined);
|
|
625
|
+
forgetTargets();
|
|
626
|
+
} else if (!inGallery && panels.size === 1) {
|
|
627
|
+
const [[, chit]] = [...panels];
|
|
628
|
+
// Full screen we chose for another panel: back to the normal layout, then decide afresh from there
|
|
629
|
+
const ours = focusedByUsRef.current;
|
|
630
|
+
if (ours && navigation.focusedPanel() && ours.renderInstance?.rootRenderInstance !== chit.renderInstance?.rootRenderInstance) {
|
|
631
|
+
unzoom();
|
|
632
|
+
focusedByUsRef.current = undefined;
|
|
633
|
+
await navigation.focusPanelOf(undefined);
|
|
634
|
+
forgetTargets();
|
|
635
|
+
if (cancelled) return;
|
|
636
|
+
}
|
|
637
|
+
if (navigation.focusedPanel()) {
|
|
638
|
+
// full screen already (the player's, or ours for this panel): switch to its tab
|
|
639
|
+
await navigation.focusPanelOf(chit);
|
|
640
|
+
forgetTargets();
|
|
641
|
+
} else {
|
|
642
|
+
const panel = chit.renderInstance?.rootRenderInstance;
|
|
643
|
+
const union = unionRects(ringed().found.map((f) => f.rect));
|
|
644
|
+
if (panel && union && width && height) {
|
|
645
|
+
const size = Math.max(union.right - union.left, union.bottom - union.top) / panel.cameraZoom;
|
|
646
|
+
const zoomable = Math.min(Math.min(panel.width, panel.height) * ZOOM_TO_SHARE, size * panel.cameraWrapper.cameraSpec.maxZoom);
|
|
647
|
+
const gain = Math.min(width / panel.width, height / panel.height);
|
|
648
|
+
if (size < FOCUS_TARGET_PX && zoomable < READABLE_PX && gain >= FOCUS_GAIN) {
|
|
649
|
+
await navigation.focusPanelOf(chit);
|
|
650
|
+
focusedByUsRef.current = chit;
|
|
651
|
+
forgetTargets();
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (!cancelled) zoomIn();
|
|
657
|
+
};
|
|
658
|
+
// After a tab switch has slid in (see the reveal above), and the zoom once more in case it was slow
|
|
659
|
+
const first = setTimeout(() => void frame(), 450);
|
|
660
|
+
const again = setTimeout(() => !cancelled && zoomIn(), 1500);
|
|
661
|
+
return () => {
|
|
662
|
+
cancelled = true;
|
|
663
|
+
clearTimeout(first);
|
|
664
|
+
clearTimeout(again);
|
|
665
|
+
};
|
|
666
|
+
}, [focus, active, controller, shown, unzoom, unfocus, navigation, width, height]);
|
|
667
|
+
|
|
668
|
+
// While the player only watches, the prompt's own strip (the gallery its toggle button opens by
|
|
669
|
+
// itself) is put away, so the board gets the room; it comes back when it is the player's move or
|
|
670
|
+
// the step points into it. A strip the player opens themselves stays open.
|
|
671
|
+
const putAwayRef = useRef<{ source: GalleryItemSource; channel: EventChannel<GalleryItemSource | undefined> } | undefined>(undefined);
|
|
672
|
+
useEffect(() => {
|
|
673
|
+
if (!controller || !active) return;
|
|
674
|
+
const promptStrips = (): GalleryItemSource[] => {
|
|
675
|
+
const p = clientPrompts.currentPrompt.value;
|
|
676
|
+
if (!(p instanceof PickPrompt)) return [];
|
|
677
|
+
return p.picks.flatMap((k) => {
|
|
678
|
+
// a chit pick's toggle button (Hand, Actions...), when it opens its gallery by itself
|
|
679
|
+
const button = (k as { button?: { autoShow?: boolean; galleryItemSource?: GalleryItemSource } }).button;
|
|
680
|
+
return button?.autoShow && button.galleryItemSource ? [button.galleryItemSource] : [];
|
|
681
|
+
});
|
|
682
|
+
};
|
|
683
|
+
const playersMove = () => {
|
|
684
|
+
const allow = controller.step?.allow;
|
|
685
|
+
const list = allow === undefined ? [] : Array.isArray(allow) ? allow : [allow];
|
|
686
|
+
return controller.status.value === "waiting" && !controller.reviewing.value && list.length > 0;
|
|
687
|
+
};
|
|
688
|
+
const pointsInto = (source: GalleryItemSource) => {
|
|
689
|
+
const ids = new Set(describeSource(source, "inline").chitIds);
|
|
690
|
+
const ctx = controller.context();
|
|
691
|
+
return controller.focus.value.some((f: Focus<any, any>) =>
|
|
692
|
+
[f.ring, f.arrow].some((t) => {
|
|
693
|
+
if (!t || t === true) return false;
|
|
694
|
+
if (typeof t !== "function" && "ui" in t) {
|
|
695
|
+
const name = typeof t.ui === "function" ? (ctx ? t.ui(ctx.root, ctx.me) : "") : t.ui;
|
|
696
|
+
return typeof name === "string" && (name.startsWith("gallery:") || name.startsWith("button:"));
|
|
697
|
+
}
|
|
698
|
+
if (typeof t !== "function" && !("chit" in t)) return false;
|
|
699
|
+
const selector = typeof t === "function" ? t : t.chit;
|
|
700
|
+
return selectChits(selector, ctx?.root, ctx?.me).some((c) => ids.has(c.id ?? ""));
|
|
701
|
+
}),
|
|
702
|
+
);
|
|
703
|
+
};
|
|
704
|
+
// Inline or full screen, as the player prefers
|
|
705
|
+
const channels = [modalState.inlineGallerySource, modalState.gallerySource];
|
|
706
|
+
const update = () => {
|
|
707
|
+
const strips = promptStrips();
|
|
708
|
+
const away = putAwayRef.current;
|
|
709
|
+
if (away && !strips.includes(away.source)) putAwayRef.current = undefined; // its prompt is gone
|
|
710
|
+
for (const channel of channels) {
|
|
711
|
+
const open = channel.value;
|
|
712
|
+
if (open && strips.includes(open) && !playersMove() && !pointsInto(open)) {
|
|
713
|
+
putAwayRef.current = { source: open, channel };
|
|
714
|
+
channel.value = undefined;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
const back = putAwayRef.current;
|
|
718
|
+
if (back && !channels.some((c) => c.value) && (playersMove() || pointsInto(back.source))) {
|
|
719
|
+
back.channel.value = back.source;
|
|
720
|
+
putAwayRef.current = undefined;
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
update();
|
|
724
|
+
const unsubs = [
|
|
725
|
+
controller.status.on(update, false),
|
|
726
|
+
controller.focus.on(update, false),
|
|
727
|
+
controller.index.on(update, false),
|
|
728
|
+
clientPrompts.currentPrompt.on(update, false),
|
|
729
|
+
];
|
|
730
|
+
return () => unsubs.forEach((u) => u());
|
|
731
|
+
}, [controller, active, clientPrompts, modalState]);
|
|
732
|
+
|
|
733
|
+
// Project every target each frame while something is drawn; publish a new frame only when it changed
|
|
734
|
+
useEffect(() => {
|
|
735
|
+
if (!controller || (!active && !dev.showTargetRects)) {
|
|
736
|
+
if (frameRef.current.focus.length || frameRef.current.debug.length) {
|
|
737
|
+
frameRef.current = { focus: [], debug: [], step: -1 };
|
|
738
|
+
setFrame(frameRef.current);
|
|
739
|
+
}
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
let cancelled = false;
|
|
743
|
+
const tick = () => {
|
|
744
|
+
if (cancelled) return;
|
|
745
|
+
requestSharedAnimationFrame(tick);
|
|
746
|
+
const container = ref.current;
|
|
747
|
+
if (!container) return;
|
|
748
|
+
const bounds = container.getBoundingClientRect();
|
|
749
|
+
const ctx = controller.context();
|
|
750
|
+
const root = ctx?.root;
|
|
751
|
+
const me = ctx?.me;
|
|
752
|
+
const drawn: DrawnFocus[] = [];
|
|
753
|
+
const debug: Rect[] = [];
|
|
754
|
+
let firstRing: Rect | undefined;
|
|
755
|
+
focus.forEach((f: Focus<any, any>) => {
|
|
756
|
+
let rings: Rect[] = [];
|
|
757
|
+
if (f.ring) {
|
|
758
|
+
const resolved = resolveTarget(f.ring, root, me, container, shown, ctx?.find);
|
|
759
|
+
const local = resolved.rects.map((r) => toLocal(r, bounds));
|
|
760
|
+
if (f.separate) {
|
|
761
|
+
rings = local;
|
|
762
|
+
} else {
|
|
763
|
+
const union = unionRects(local);
|
|
764
|
+
rings = union ? [union] : [];
|
|
765
|
+
}
|
|
766
|
+
debug.push(...local);
|
|
767
|
+
}
|
|
768
|
+
const ring = rings[0];
|
|
769
|
+
let arrows: Rect[] = [];
|
|
770
|
+
if (f.arrow === true) {
|
|
771
|
+
arrows = rings;
|
|
772
|
+
} else if (f.arrow) {
|
|
773
|
+
const resolved = resolveTarget(f.arrow, root, me, container, shown, ctx?.find);
|
|
774
|
+
arrows = resolved.rects.map((r) => toLocal(r, bounds));
|
|
775
|
+
debug.push(...arrows);
|
|
776
|
+
}
|
|
777
|
+
if (ring && !firstRing) firstRing = ring;
|
|
778
|
+
if (!firstRing && arrows[0]) firstRing = unionRects(arrows);
|
|
779
|
+
drawn.push({ rings, shape: f.shape ?? "rect", arrows, dim: !!f.dim });
|
|
780
|
+
});
|
|
781
|
+
// A ring that leaps across the screen in one frame, for the same focus, is the board mid-switch (a
|
|
782
|
+
// panel reporting where it is going a frame before it gets there): keep it where it was until
|
|
783
|
+
// the new place has lasted a moment. Zooms and slides move smoothly and are never held back.
|
|
784
|
+
const jumps = jumpRef.current;
|
|
785
|
+
if (jumps.focus !== focus) jumpRef.current = { focus, since: [] };
|
|
786
|
+
else {
|
|
787
|
+
const now = performance.now();
|
|
788
|
+
const far = 0.2 * Math.min(bounds.width, bounds.height);
|
|
789
|
+
drawn.forEach((d, i) => {
|
|
790
|
+
const before = frameRef.current.focus[i];
|
|
791
|
+
const moved =
|
|
792
|
+
before && before.rings.length === d.rings.length && d.rings.length > 0
|
|
793
|
+
? Math.max(...d.rings.map((r, k) => {
|
|
794
|
+
const a = rectCenter(r), b = rectCenter(before.rings[k]);
|
|
795
|
+
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
796
|
+
}))
|
|
797
|
+
: 0;
|
|
798
|
+
if (moved <= far) {
|
|
799
|
+
jumps.since[i] = undefined;
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
jumps.since[i] ??= now;
|
|
803
|
+
if (now - jumps.since[i]! < JUMP_HOLD_MS) drawn[i] = before;
|
|
804
|
+
else jumps.since[i] = undefined;
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
targetRectRef.current = firstRing;
|
|
808
|
+
const next: Frame = { focus: drawn, debug: dev.showTargetRects ? debug : [], step: controller.index.value };
|
|
809
|
+
if (!sameFrame(next, frameRef.current)) {
|
|
810
|
+
frameRef.current = next;
|
|
811
|
+
setFrame(next);
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
tick();
|
|
815
|
+
return () => {
|
|
816
|
+
cancelled = true;
|
|
817
|
+
};
|
|
818
|
+
}, [controller, focus, active, dev.showTargetRects, shown]);
|
|
819
|
+
|
|
820
|
+
// ---- box placement --------------------------------------------------------------------------
|
|
821
|
+
useEffect(() => {
|
|
822
|
+
userDraggedRef.current = false;
|
|
823
|
+
}, [placement]);
|
|
824
|
+
|
|
825
|
+
useEffect(() => {
|
|
826
|
+
const container = ref.current;
|
|
827
|
+
if (!container || width === 0) return;
|
|
828
|
+
if (stepTargetsRef.current.step !== frame.step) {
|
|
829
|
+
stepTargetsRef.current = { step: frame.step, targets: [] };
|
|
830
|
+
}
|
|
831
|
+
const seen = stepTargetsRef.current.targets;
|
|
832
|
+
targetRects(frame).forEach((t) => {
|
|
833
|
+
if (!seen.some((s) => sameAvoid(s, t))) seen.push(t);
|
|
834
|
+
});
|
|
835
|
+
const targetsNow = seen;
|
|
836
|
+
const rectNow: Rect = {
|
|
837
|
+
left: boxPos.x,
|
|
838
|
+
top: boxPos.y,
|
|
839
|
+
right: boxPos.x + boxSize.width,
|
|
840
|
+
bottom: boxPos.y + boxSize.height,
|
|
841
|
+
};
|
|
842
|
+
const margin = BOX_MARGIN;
|
|
843
|
+
const bw = boxSize.width;
|
|
844
|
+
const bh = boxSize.height;
|
|
845
|
+
const clamp = clampBox;
|
|
846
|
+
// A dragged box stays put unless a target shows up underneath it (but stays on screen when it
|
|
847
|
+
// grows or the screen turns)
|
|
848
|
+
if (userDraggedRef.current && coverage(rectNow, targetsNow) <= 0.1) {
|
|
849
|
+
const kept = clamp(boxPos);
|
|
850
|
+
if (Math.abs(kept.x - boxPos.x) > 1 || Math.abs(kept.y - boxPos.y) > 1) setBoxPos(kept);
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
const place = (p: BoxPlacement<any, any> | undefined): BoxPosition => {
|
|
854
|
+
const anchor = p?.anchor ?? "top-right";
|
|
855
|
+
switch (anchor) {
|
|
856
|
+
case "top-left":
|
|
857
|
+
return { x: margin, y: safeTop };
|
|
858
|
+
case "top":
|
|
859
|
+
return { x: (width - bw) / 2, y: safeTop };
|
|
860
|
+
case "top-right":
|
|
861
|
+
return { x: width - bw - margin, y: safeTop };
|
|
862
|
+
case "bottom-left":
|
|
863
|
+
return { x: margin, y: height - bh - safeBottom };
|
|
864
|
+
case "bottom":
|
|
865
|
+
return { x: (width - bw) / 2, y: height - bh - safeBottom };
|
|
866
|
+
case "bottom-right":
|
|
867
|
+
return { x: width - bw - margin, y: height - bh - safeBottom };
|
|
868
|
+
case "center":
|
|
869
|
+
return { x: (width - bw) / 2, y: (height - bh) / 2 };
|
|
870
|
+
case "keep":
|
|
871
|
+
return boxPos;
|
|
872
|
+
case "near": {
|
|
873
|
+
const bounds = container.getBoundingClientRect();
|
|
874
|
+
const ctx = controller?.context();
|
|
875
|
+
const resolved = resolveTarget((p as any).target, ctx?.root, ctx?.me, container, shown);
|
|
876
|
+
const target = unionRects(resolved.rects.map((r) => toLocal(r, bounds)));
|
|
877
|
+
if (!target) return boxPos;
|
|
878
|
+
const gap = 24;
|
|
879
|
+
const side =
|
|
880
|
+
(p as any).side ??
|
|
881
|
+
(target.bottom + gap + bh < height ? "below" : target.top - gap - bh > 0 ? "above" : "right");
|
|
882
|
+
const c = rectCenter(target);
|
|
883
|
+
switch (side) {
|
|
884
|
+
case "below":
|
|
885
|
+
return { x: c.x - bw / 2, y: target.bottom + gap };
|
|
886
|
+
case "above":
|
|
887
|
+
return { x: c.x - bw / 2, y: target.top - gap - bh };
|
|
888
|
+
case "left":
|
|
889
|
+
return { x: target.left - gap - bw, y: c.y - bh / 2 };
|
|
890
|
+
default:
|
|
891
|
+
return { x: target.right + gap, y: c.y - bh / 2 };
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
const targets = targetsNow;
|
|
897
|
+
const rectAt = (p: BoxPosition): Rect => ({ left: p.x, top: p.y, right: p.x + bw, bottom: p.y + bh });
|
|
898
|
+
// The start card sits in the middle of the darkened table
|
|
899
|
+
let next = clamp(place(started ? placement : { anchor: "center" }));
|
|
900
|
+
// Never sit on what the step is pointing at: if the requested spot covers a target, take the
|
|
901
|
+
// corner that covers the least (the current spot wins ties so the box does not wander)
|
|
902
|
+
if (coverage(rectAt(next), targets) > 0.1) {
|
|
903
|
+
const candidates: BoxAnchor[] = ["top-left", "top-right", "bottom-left", "bottom-right", "top", "bottom"];
|
|
904
|
+
let best = { pos: boxPos, cover: coverage(rectAt(boxPos), targets) };
|
|
905
|
+
for (const anchor of candidates) {
|
|
906
|
+
const pos = clamp(place({ anchor }));
|
|
907
|
+
const cover = coverage(rectAt(pos), targets);
|
|
908
|
+
if (cover < best.cover - 0.02) best = { pos, cover };
|
|
909
|
+
}
|
|
910
|
+
next = best.pos;
|
|
911
|
+
}
|
|
912
|
+
if (Math.abs(next.x - boxPos.x) > 1 || Math.abs(next.y - boxPos.y) > 1) {
|
|
913
|
+
setBoxPos(next);
|
|
914
|
+
}
|
|
915
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
916
|
+
}, [placement, width, height, boxSize.width, boxSize.height, frame, controller, safeTop, safeBottom, clampBox, shown, started]);
|
|
917
|
+
|
|
918
|
+
// Dragging keeps the box on screen too: a box dragged off it could not be dragged back
|
|
919
|
+
const clampRef = useRef(clampBox);
|
|
920
|
+
clampRef.current = clampBox;
|
|
921
|
+
const onDrag = useCallback((pos: BoxPosition) => {
|
|
922
|
+
userDraggedRef.current = true;
|
|
923
|
+
setBoxPos(clampRef.current(pos));
|
|
924
|
+
}, []);
|
|
925
|
+
const onMeasure = useCallback((size: { width: number; height: number }) => {
|
|
926
|
+
setBoxSize((prev) => (prev.width === size.width && prev.height === size.height ? prev : size));
|
|
927
|
+
}, []);
|
|
928
|
+
|
|
929
|
+
const wantDim = frame.focus.some((f) => f.dim) && frame.focus.some((f) => f.rings.length > 0 || f.arrows.length > 0);
|
|
930
|
+
const litNow = frame.focus.flatMap((f) => [
|
|
931
|
+
...f.rings.map((rect) => ({ rect, shape: f.shape })),
|
|
932
|
+
...f.arrows.map((rect) => ({ rect, shape: "rect" as const })),
|
|
933
|
+
]);
|
|
934
|
+
const litRef = useRef(litNow);
|
|
935
|
+
if (wantDim) litRef.current = litNow;
|
|
936
|
+
const [anyDim, setAnyDim] = useState(false);
|
|
937
|
+
useEffect(() => {
|
|
938
|
+
if (wantDim) {
|
|
939
|
+
setAnyDim(true);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
const t = setTimeout(() => setAnyDim(false), DIM_HOLD_MS);
|
|
943
|
+
return () => clearTimeout(t);
|
|
944
|
+
}, [wantDim]);
|
|
945
|
+
|
|
946
|
+
if (!controller) {
|
|
947
|
+
return <Box ref={ref} sx={{ position: "absolute", inset: 0, pointerEvents: "none", zIndex: ZINDEX_TUTORIAL }} />;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
const boxRect: Rect = {
|
|
951
|
+
left: boxPos.x,
|
|
952
|
+
top: boxPos.y,
|
|
953
|
+
right: boxPos.x + boxSize.width,
|
|
954
|
+
bottom: boxPos.y + boxSize.height,
|
|
955
|
+
};
|
|
956
|
+
const hasNarration = !!controller.step?.audio || controller.spec.steps.some((s) => !!s.audio);
|
|
957
|
+
// Once the tutorial is finished or skipped the box goes away and the match is just a game
|
|
958
|
+
const showBox = !isLoading && (live || !started) && status !== "done";
|
|
959
|
+
// A spotlight keeps everything the step highlights lit: every ring and every arrow target. Through a short
|
|
960
|
+
// gap (see DIM_HOLD_MS) the dim stays, with the holes it last had
|
|
961
|
+
const lit = anyDim && !wantDim ? litRef.current : litNow;
|
|
962
|
+
|
|
963
|
+
return (
|
|
964
|
+
<Box
|
|
965
|
+
ref={ref}
|
|
966
|
+
sx={{
|
|
967
|
+
position: "absolute",
|
|
968
|
+
inset: 0,
|
|
969
|
+
pointerEvents: "none",
|
|
970
|
+
zIndex: ZINDEX_TUTORIAL,
|
|
971
|
+
overflow: "hidden",
|
|
972
|
+
fontFamily: theme.fontFamily,
|
|
973
|
+
}}
|
|
974
|
+
>
|
|
975
|
+
{active && (
|
|
976
|
+
<svg width={width} height={height} style={{ position: "absolute", inset: 0, pointerEvents: "none" }}>
|
|
977
|
+
<defs>
|
|
978
|
+
<marker
|
|
979
|
+
id="tutorial-arrowhead"
|
|
980
|
+
viewBox="0 0 10 10"
|
|
981
|
+
refX="8"
|
|
982
|
+
refY="5"
|
|
983
|
+
markerWidth="7"
|
|
984
|
+
markerHeight="7"
|
|
985
|
+
orient="auto-start-reverse"
|
|
986
|
+
>
|
|
987
|
+
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.arrowColor} />
|
|
988
|
+
</marker>
|
|
989
|
+
{/* Sized to the overlay, not to each shape: a near-vertical arrow's own bounding box is a
|
|
990
|
+
few pixels wide and does not include its arrowhead, which then gets clipped */}
|
|
991
|
+
<filter id="tutorial-glow" filterUnits="userSpaceOnUse" x={0} y={0} width={width} height={height}>
|
|
992
|
+
<feGaussianBlur stdDeviation="4" result="blur" />
|
|
993
|
+
<feMerge>
|
|
994
|
+
<feMergeNode in="blur" />
|
|
995
|
+
<feMergeNode in="SourceGraphic" />
|
|
996
|
+
</feMerge>
|
|
997
|
+
</filter>
|
|
998
|
+
<mask id="tutorial-dim-mask">
|
|
999
|
+
<rect x={0} y={0} width={width} height={height} fill="white" />
|
|
1000
|
+
{lit.map((l, i) => (
|
|
1001
|
+
<RingShape key={i} rect={l.rect} shape={l.shape} pad={RING_PADDING + 4} fill="black" />
|
|
1002
|
+
))}
|
|
1003
|
+
<rect
|
|
1004
|
+
x={boxRect.left - 4}
|
|
1005
|
+
y={boxRect.top - 4}
|
|
1006
|
+
width={boxRect.right - boxRect.left + 8}
|
|
1007
|
+
height={boxRect.bottom - boxRect.top + 8}
|
|
1008
|
+
rx={theme.borderRadius}
|
|
1009
|
+
fill="black"
|
|
1010
|
+
/>
|
|
1011
|
+
</mask>
|
|
1012
|
+
</defs>
|
|
1013
|
+
{/* Always drawn, so it fades in and out rather than popping */}
|
|
1014
|
+
<rect
|
|
1015
|
+
x={0}
|
|
1016
|
+
y={0}
|
|
1017
|
+
width={width}
|
|
1018
|
+
height={height}
|
|
1019
|
+
fill={theme.dimColor}
|
|
1020
|
+
opacity={anyDim ? theme.dimOpacity : 0}
|
|
1021
|
+
mask="url(#tutorial-dim-mask)"
|
|
1022
|
+
style={{ transition: "opacity 0.3s" }}
|
|
1023
|
+
/>
|
|
1024
|
+
<style>{`
|
|
1025
|
+
@keyframes tutorialRingPulse { 0% { stroke-opacity: 0.55; } 50% { stroke-opacity: 1; } 100% { stroke-opacity: 0.55; } }
|
|
1026
|
+
@keyframes tutorialDash { to { stroke-dashoffset: -24; } }
|
|
1027
|
+
@keyframes tutorialArrowNudge { 0% { transform: translate(0,0); } 50% { transform: translate(var(--nx), var(--ny)); } 100% { transform: translate(0,0); } }
|
|
1028
|
+
`}</style>
|
|
1029
|
+
{frame.debug.map((r, i) => (
|
|
1030
|
+
<rect
|
|
1031
|
+
key={`d${i}`}
|
|
1032
|
+
x={r.left}
|
|
1033
|
+
y={r.top}
|
|
1034
|
+
width={r.right - r.left}
|
|
1035
|
+
height={r.bottom - r.top}
|
|
1036
|
+
fill="none"
|
|
1037
|
+
stroke="#ff00ff"
|
|
1038
|
+
strokeWidth={1}
|
|
1039
|
+
strokeDasharray="3 3"
|
|
1040
|
+
/>
|
|
1041
|
+
))}
|
|
1042
|
+
{frame.focus.map((f, i) => (
|
|
1043
|
+
<g key={i}>
|
|
1044
|
+
{f.rings.map((ring, j) => (
|
|
1045
|
+
<RingShape
|
|
1046
|
+
key={j}
|
|
1047
|
+
rect={ring}
|
|
1048
|
+
shape={f.shape}
|
|
1049
|
+
pad={ringPadding(ring, f.rings)}
|
|
1050
|
+
fill="none"
|
|
1051
|
+
stroke={theme.highlightColor}
|
|
1052
|
+
strokeWidth={3}
|
|
1053
|
+
filter="url(#tutorial-glow)"
|
|
1054
|
+
style={{ animation: "tutorialRingPulse 1.6s ease-in-out infinite" }}
|
|
1055
|
+
/>
|
|
1056
|
+
))}
|
|
1057
|
+
{f.arrows.map((target, j) => (
|
|
1058
|
+
<Arrow key={j} from={boxRect} to={target} color={theme.arrowColor} />
|
|
1059
|
+
))}
|
|
1060
|
+
</g>
|
|
1061
|
+
))}
|
|
1062
|
+
</svg>
|
|
1063
|
+
)}
|
|
1064
|
+
|
|
1065
|
+
{/* Until Start, the whole game sits dark behind the start card, and takes no taps */}
|
|
1066
|
+
{showBox && !started && (
|
|
1067
|
+
<Box
|
|
1068
|
+
sx={{ position: "absolute", inset: 0, pointerEvents: "auto", background: theme.dimColor, opacity: theme.dimOpacity }}
|
|
1069
|
+
/>
|
|
1070
|
+
)}
|
|
1071
|
+
{showBox && (
|
|
1072
|
+
<TutorialBox
|
|
1073
|
+
controller={controller}
|
|
1074
|
+
theme={theme}
|
|
1075
|
+
tokenMap={tokenMap}
|
|
1076
|
+
position={boxPos}
|
|
1077
|
+
width={boxWidth}
|
|
1078
|
+
narrow={width < 600}
|
|
1079
|
+
onDrag={onDrag}
|
|
1080
|
+
onMeasure={onMeasure}
|
|
1081
|
+
started={started}
|
|
1082
|
+
onStart={onStart}
|
|
1083
|
+
hasNarration={hasNarration}
|
|
1084
|
+
/>
|
|
1085
|
+
)}
|
|
1086
|
+
</Box>
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// ---- galleries ---------------------------------------------------------------------------------
|
|
1091
|
+
|
|
1092
|
+
const DEFAULT_INLINE_GALLERY_SIZE = 125;
|
|
1093
|
+
|
|
1094
|
+
function describeSource(source: GalleryItemSource, mode: "inline" | "fullscreen"): TutorialGalleryState {
|
|
1095
|
+
const backing = source.backingObject;
|
|
1096
|
+
return {
|
|
1097
|
+
mode,
|
|
1098
|
+
of: backing instanceof Chit ? backing.id : undefined,
|
|
1099
|
+
chitIds: source.items.map((item) => ((item as any).chit instanceof Chit ? (item as any).chit.id : item.id)),
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
function describeGalleries(modal: ModalState): TutorialGalleryState[] {
|
|
1104
|
+
const result: TutorialGalleryState[] = [];
|
|
1105
|
+
if (modal.gallerySource.value) result.push(describeSource(modal.gallerySource.value, "fullscreen"));
|
|
1106
|
+
if (modal.inlineGallerySource.value) result.push(describeSource(modal.inlineGallerySource.value, "inline"));
|
|
1107
|
+
return result;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
/** The inline/full-screen choice the gallery buttons remember */
|
|
1111
|
+
function preferredGalleryMode(): "inline" | "fullscreen" {
|
|
1112
|
+
try {
|
|
1113
|
+
return window.localStorage.getItem("galleryFullScreen") === '"modal"' ? "fullscreen" : "inline";
|
|
1114
|
+
} catch {
|
|
1115
|
+
return "inline";
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* Opens, switches or closes a gallery through the same modal state the gallery buttons use, so the
|
|
1121
|
+
* player can keep using those buttons. Returns true when it opened a new gallery.
|
|
1122
|
+
*/
|
|
1123
|
+
function applyGalleryCommand(
|
|
1124
|
+
modal: ModalState,
|
|
1125
|
+
command: GalleryCommand<any, any>,
|
|
1126
|
+
root: RootChit<any> | undefined,
|
|
1127
|
+
me: PlayerChit | undefined,
|
|
1128
|
+
): boolean {
|
|
1129
|
+
if (command === "close") {
|
|
1130
|
+
modal.gallerySource.value = undefined;
|
|
1131
|
+
modal.inlineGallerySource.value = undefined;
|
|
1132
|
+
return false;
|
|
1133
|
+
}
|
|
1134
|
+
const open = modal.gallerySource.value ?? modal.inlineGallerySource.value;
|
|
1135
|
+
let source: GalleryItemSource | undefined;
|
|
1136
|
+
let opened = false;
|
|
1137
|
+
if (command.of) {
|
|
1138
|
+
const container = selectChits(command.of, root, me)[0];
|
|
1139
|
+
if (container) {
|
|
1140
|
+
source = new GalleryItemChitChildrenSource(container);
|
|
1141
|
+
opened = true;
|
|
1142
|
+
}
|
|
1143
|
+
} else if (command.items) {
|
|
1144
|
+
const chits = selectChits(command.items, root, me);
|
|
1145
|
+
if (chits.length > 0) {
|
|
1146
|
+
source = new GalleryItemRawSource(chitsToGalleryItems(chits));
|
|
1147
|
+
opened = true;
|
|
1148
|
+
}
|
|
1149
|
+
} else if (open) {
|
|
1150
|
+
// Switching modes: a display closes the source it leaves, so hand the other one a fresh copy
|
|
1151
|
+
source = open.backingObject instanceof Chit ? new GalleryItemChitChildrenSource(open.backingObject) : open;
|
|
1152
|
+
source.inlineGallerySize = open.inlineGallerySize;
|
|
1153
|
+
}
|
|
1154
|
+
if (!source) return false;
|
|
1155
|
+
source.inlineGallerySize ??= DEFAULT_INLINE_GALLERY_SIZE;
|
|
1156
|
+
const mode =
|
|
1157
|
+
command.mode && command.mode !== "preferred"
|
|
1158
|
+
? command.mode
|
|
1159
|
+
: opened
|
|
1160
|
+
? preferredGalleryMode()
|
|
1161
|
+
: modal.gallerySource.value
|
|
1162
|
+
? "fullscreen"
|
|
1163
|
+
: "inline";
|
|
1164
|
+
if (mode === "fullscreen") {
|
|
1165
|
+
modal.inlineGallerySource.value = undefined;
|
|
1166
|
+
modal.gallerySource.value = source;
|
|
1167
|
+
} else {
|
|
1168
|
+
modal.gallerySource.value = undefined;
|
|
1169
|
+
modal.inlineGallerySource.value = source;
|
|
1170
|
+
}
|
|
1171
|
+
return opened;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
const RATE_KEY = "tutorialPlaybackRate";
|
|
1175
|
+
|
|
1176
|
+
/** The narration speed this viewer chose last time (a per-device convenience; 1 when unavailable) */
|
|
1177
|
+
function readRate(): number {
|
|
1178
|
+
try {
|
|
1179
|
+
const value = parseFloat(window.localStorage.getItem(RATE_KEY) ?? "1");
|
|
1180
|
+
return value > 0 ? value : 1;
|
|
1181
|
+
} catch {
|
|
1182
|
+
return 1;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
function writeRate(rate: number) {
|
|
1187
|
+
try {
|
|
1188
|
+
window.localStorage.setItem(RATE_KEY, String(rate));
|
|
1189
|
+
} catch {
|
|
1190
|
+
// private window or blocked storage: the speed just is not remembered
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
const EMPTY_FOCUS = new EventChannel<Focus<any, any>[]>([]);
|
|
1195
|
+
const IDLE = new EventChannel<TutorialStatus>("idle");
|
|
1196
|
+
const NO_BOX = new EventChannel<BoxPlacement<any, any> | undefined>(undefined);
|
|
1197
|
+
|
|
1198
|
+
/** A ring's padding: the usual breathing room, shrunk so neighbouring rings (with `separate`) never touch */
|
|
1199
|
+
function ringPadding(ring: Rect, all: Rect[]) {
|
|
1200
|
+
let pad = RING_PADDING;
|
|
1201
|
+
for (const other of all) {
|
|
1202
|
+
if (other === ring) continue;
|
|
1203
|
+
const gapX = Math.max(other.left - ring.right, ring.left - other.right);
|
|
1204
|
+
const gapY = Math.max(other.top - ring.bottom, ring.top - other.bottom);
|
|
1205
|
+
const gap = Math.max(gapX, gapY);
|
|
1206
|
+
pad = Math.min(pad, gap / 2 - 2);
|
|
1207
|
+
}
|
|
1208
|
+
return Math.max(1, pad);
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
function RingShape({
|
|
1212
|
+
rect,
|
|
1213
|
+
shape,
|
|
1214
|
+
pad,
|
|
1215
|
+
...rest
|
|
1216
|
+
}: { rect: Rect; shape: "rect" | "ellipse"; pad: number } & React.SVGProps<SVGRectElement> &
|
|
1217
|
+
React.SVGProps<SVGEllipseElement>) {
|
|
1218
|
+
const w = rect.right - rect.left + pad * 2;
|
|
1219
|
+
const h = rect.bottom - rect.top + pad * 2;
|
|
1220
|
+
if (shape === "ellipse") {
|
|
1221
|
+
return (
|
|
1222
|
+
<ellipse
|
|
1223
|
+
cx={rect.left - pad + w / 2}
|
|
1224
|
+
cy={rect.top - pad + h / 2}
|
|
1225
|
+
rx={w / 2}
|
|
1226
|
+
ry={h / 2}
|
|
1227
|
+
{...(rest as React.SVGProps<SVGEllipseElement>)}
|
|
1228
|
+
/>
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
return (
|
|
1232
|
+
<rect
|
|
1233
|
+
x={rect.left - pad}
|
|
1234
|
+
y={rect.top - pad}
|
|
1235
|
+
width={w}
|
|
1236
|
+
height={h}
|
|
1237
|
+
rx={Math.min(14, w / 4, h / 4)}
|
|
1238
|
+
{...(rest as React.SVGProps<SVGRectElement>)}
|
|
1239
|
+
/>
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
/** A curved arrow from the nearest edge of the box to the nearest edge of the target. */
|
|
1244
|
+
function Arrow({ from, to, color }: { from: Rect; to: Rect; color: string }) {
|
|
1245
|
+
const tc = rectCenter(to);
|
|
1246
|
+
const fc = rectCenter(from);
|
|
1247
|
+
// Start on the box edge facing the target
|
|
1248
|
+
const dx = tc.x - fc.x;
|
|
1249
|
+
const dy = tc.y - fc.y;
|
|
1250
|
+
let start: { x: number; y: number };
|
|
1251
|
+
// ...as close to straight across from the target as the edge allows, so several arrows fan out
|
|
1252
|
+
// from their own points instead of one shared one
|
|
1253
|
+
const edgeMargin = 18;
|
|
1254
|
+
if (Math.abs(dx) * (from.bottom - from.top) > Math.abs(dy) * (from.right - from.left)) {
|
|
1255
|
+
start = {
|
|
1256
|
+
x: dx > 0 ? from.right : from.left,
|
|
1257
|
+
y: Math.max(from.top + edgeMargin, Math.min(from.bottom - edgeMargin, tc.y)),
|
|
1258
|
+
};
|
|
1259
|
+
} else {
|
|
1260
|
+
start = {
|
|
1261
|
+
x: Math.max(from.left + edgeMargin, Math.min(from.right - edgeMargin, tc.x)),
|
|
1262
|
+
y: dy > 0 ? from.bottom : from.top,
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
// End on the target edge facing the box, a little outside it
|
|
1266
|
+
const pad = 10;
|
|
1267
|
+
const ex = tc.x - start.x;
|
|
1268
|
+
const ey = tc.y - start.y;
|
|
1269
|
+
let end: { x: number; y: number };
|
|
1270
|
+
if (Math.abs(ex) * (to.bottom - to.top) > Math.abs(ey) * (to.right - to.left)) {
|
|
1271
|
+
end = { x: ex > 0 ? to.left - pad : to.right + pad, y: tc.y };
|
|
1272
|
+
} else {
|
|
1273
|
+
end = { x: tc.x, y: ey > 0 ? to.top - pad : to.bottom + pad };
|
|
1274
|
+
}
|
|
1275
|
+
const len = Math.hypot(end.x - start.x, end.y - start.y);
|
|
1276
|
+
if (len < 24) return null;
|
|
1277
|
+
// Control point: perpendicular offset for a gentle curve
|
|
1278
|
+
const mx = (start.x + end.x) / 2;
|
|
1279
|
+
const my = (start.y + end.y) / 2;
|
|
1280
|
+
const nx = -(end.y - start.y) / len;
|
|
1281
|
+
const ny = (end.x - start.x) / len;
|
|
1282
|
+
const bend = Math.min(60, len * 0.2);
|
|
1283
|
+
const cx = mx + nx * bend;
|
|
1284
|
+
const cy = my + ny * bend;
|
|
1285
|
+
const ux = (end.x - start.x) / len;
|
|
1286
|
+
const uy = (end.y - start.y) / len;
|
|
1287
|
+
return (
|
|
1288
|
+
<g
|
|
1289
|
+
style={
|
|
1290
|
+
{
|
|
1291
|
+
"--nx": `${ux * 6}px`,
|
|
1292
|
+
"--ny": `${uy * 6}px`,
|
|
1293
|
+
animation: "tutorialArrowNudge 1.1s ease-in-out infinite",
|
|
1294
|
+
} as React.CSSProperties
|
|
1295
|
+
}
|
|
1296
|
+
>
|
|
1297
|
+
<path
|
|
1298
|
+
d={`M ${start.x} ${start.y} Q ${cx} ${cy} ${end.x} ${end.y}`}
|
|
1299
|
+
fill="none"
|
|
1300
|
+
stroke="rgba(0,0,0,0.35)"
|
|
1301
|
+
strokeWidth={6}
|
|
1302
|
+
strokeLinecap="round"
|
|
1303
|
+
/>
|
|
1304
|
+
<path
|
|
1305
|
+
d={`M ${start.x} ${start.y} Q ${cx} ${cy} ${end.x} ${end.y}`}
|
|
1306
|
+
fill="none"
|
|
1307
|
+
stroke={color}
|
|
1308
|
+
strokeWidth={3}
|
|
1309
|
+
strokeLinecap="round"
|
|
1310
|
+
markerEnd="url(#tutorial-arrowhead)"
|
|
1311
|
+
filter="url(#tutorial-glow)"
|
|
1312
|
+
/>
|
|
1313
|
+
<circle cx={start.x} cy={start.y} r={4} fill={color} />
|
|
1314
|
+
</g>
|
|
1315
|
+
);
|
|
1316
|
+
}
|