@pretty-chitty/core 1.2.18 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/ClientTrustMatchViewer.d.ts +14 -1
- package/dist/components/ClientTrustMatchViewer.d.ts.map +1 -1
- package/dist/components/ClientTrustMatchViewer.js +25 -2
- package/dist/components/ClientTrustMatchViewer.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 +30 -2
- package/dist/components/DemoWrapper.d.ts.map +1 -1
- package/dist/components/DemoWrapper.js +79 -43
- 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 +6 -2
- package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
- package/dist/components/Gallery/BuiltItem.js +31 -9
- package/dist/components/Gallery/BuiltItem.js.map +1 -1
- package/dist/components/Gallery/GalleryController.d.ts +18 -0
- package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryController.js +70 -1
- 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 +48 -10
- package/dist/components/Gallery/GalleryViewer.js.map +1 -1
- package/dist/components/Gallery/LayoutManager.d.ts +6 -0
- package/dist/components/Gallery/LayoutManager.d.ts.map +1 -1
- package/dist/components/Gallery/LayoutManager.js +23 -3
- package/dist/components/Gallery/LayoutManager.js.map +1 -1
- package/dist/components/Gallery/constants.d.ts +2 -0
- package/dist/components/Gallery/constants.d.ts.map +1 -1
- package/dist/components/Gallery/constants.js +2 -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/GameDesigner.d.ts.map +1 -1
- package/dist/components/GameDesigner.js +42 -10
- package/dist/components/GameDesigner.js.map +1 -1
- package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
- package/dist/components/InlineGalleryDisplay.js +2 -2
- 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/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.map +1 -1
- package/dist/components/Panel/PanelContents.js +92 -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 +3 -2
- package/dist/components/PanelSpark.js.map +1 -1
- package/dist/components/Playground.d.ts.map +1 -1
- package/dist/components/Playground.js +46 -14
- 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 +8 -6
- package/dist/components/TokenizedMessage.d.ts.map +1 -1
- package/dist/components/TokenizedMessage.js +21 -54
- package/dist/components/TokenizedMessage.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 +1132 -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/game/Chit.d.ts +7 -0
- package/dist/game/Chit.d.ts.map +1 -1
- package/dist/game/Chit.js +22 -7
- 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/ConnectionTransport.d.ts +3 -0
- package/dist/game/ConnectionTransport.d.ts.map +1 -1
- package/dist/game/ConnectionTransport.js +13 -4
- package/dist/game/ConnectionTransport.js.map +1 -1
- package/dist/game/Game.d.ts +14 -1
- package/dist/game/Game.d.ts.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 +74 -2
- package/dist/game/Match.d.ts.map +1 -1
- package/dist/game/Match.js +155 -4
- package/dist/game/Match.js.map +1 -1
- package/dist/game/MatchStorage.d.ts +8 -1
- package/dist/game/MatchStorage.d.ts.map +1 -1
- package/dist/game/MatchStorage.js +11 -3
- package/dist/game/MatchStorage.js.map +1 -1
- package/dist/game/Pick.d.ts +16 -0
- package/dist/game/Pick.d.ts.map +1 -1
- package/dist/game/Pick.js +32 -1
- package/dist/game/Pick.js.map +1 -1
- package/dist/game/PlayerChit.d.ts +3 -0
- package/dist/game/PlayerChit.d.ts.map +1 -1
- package/dist/game/PlayerChit.js +3 -0
- package/dist/game/PlayerChit.js.map +1 -1
- package/dist/game/PlayerInfo.d.ts +8 -0
- package/dist/game/PlayerInfo.d.ts.map +1 -1
- package/dist/game/PlayerInfo.js +6 -3
- package/dist/game/PlayerInfo.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 +8 -2
- package/dist/game/PlayerPromptStatusChit.js.map +1 -1
- package/dist/game/Prompt.d.ts +15 -0
- package/dist/game/Prompt.d.ts.map +1 -1
- package/dist/game/Prompt.js +16 -0
- package/dist/game/Prompt.js.map +1 -1
- package/dist/game/Turn.d.ts +20 -4
- package/dist/game/Turn.d.ts.map +1 -1
- package/dist/game/Turn.js +191 -67
- package/dist/game/Turn.js.map +1 -1
- package/dist/game/TurnState.d.ts +20 -1
- package/dist/game/TurnState.d.ts.map +1 -1
- package/dist/game/TurnState.js +22 -3
- package/dist/game/TurnState.js.map +1 -1
- package/dist/game/ai/AiClientPrompts.d.ts +177 -0
- package/dist/game/ai/AiClientPrompts.d.ts.map +1 -0
- package/dist/game/ai/AiClientPrompts.js +561 -0
- package/dist/game/ai/AiClientPrompts.js.map +1 -0
- package/dist/game/ai/AiLiveView.d.ts +2 -0
- package/dist/game/ai/AiLiveView.d.ts.map +1 -0
- package/dist/game/ai/AiLiveView.js +48 -0
- package/dist/game/ai/AiLiveView.js.map +1 -0
- package/dist/game/ai/AiPlayerView.d.ts +2 -0
- package/dist/game/ai/AiPlayerView.d.ts.map +1 -0
- package/dist/game/ai/AiPlayerView.js +91 -0
- package/dist/game/ai/AiPlayerView.js.map +1 -0
- package/dist/game/ai/connectAiPlayer.d.ts +43 -0
- package/dist/game/ai/connectAiPlayer.d.ts.map +1 -0
- package/dist/game/ai/connectAiPlayer.js +58 -0
- package/dist/game/ai/connectAiPlayer.js.map +1 -0
- package/dist/game/ai/defineAi.d.ts +119 -0
- package/dist/game/ai/defineAi.d.ts.map +1 -0
- package/dist/game/ai/defineAi.js +122 -0
- package/dist/game/ai/defineAi.js.map +1 -0
- package/dist/game/ai/simulateMatches.d.ts +62 -0
- package/dist/game/ai/simulateMatches.d.ts.map +1 -0
- package/dist/game/ai/simulateMatches.js +108 -0
- package/dist/game/ai/simulateMatches.js.map +1 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts +3 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts.map +1 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.js +3 -0
- package/dist/game/badAiTransport/BadAIClientPrompts.js.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.d.ts +20 -1
- package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.js +30 -1
- 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 +51 -11
- package/dist/game/clientTransport/ClientTime.js.map +1 -1
- package/dist/game/tutorial/TutorialController.d.ts +300 -0
- package/dist/game/tutorial/TutorialController.d.ts.map +1 -0
- package/dist/game/tutorial/TutorialController.js +1182 -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 +63 -0
- package/dist/game/tutorial/runTutorial.d.ts.map +1 -0
- package/dist/game/tutorial/runTutorial.js +273 -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 +2 -1
- package/dist/hooks/useTimeController.d.ts.map +1 -1
- package/dist/hooks/useTimeController.js +6 -2
- package/dist/hooks/useTimeController.js.map +1 -1
- package/dist/hooks/useTokenMap.d.ts +2 -4
- package/dist/hooks/useTokenMap.d.ts.map +1 -1
- package/dist/hooks/useTokenMap.js +2 -5
- package/dist/hooks/useTokenMap.js.map +1 -1
- package/dist/hooks/useTutorial.d.ts +48 -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 +57 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.html +12 -0
- package/dist/index.js +27 -3
- package/dist/index.js.map +1 -1
- package/dist/main.0792d734cde2c688d5f7.hot-update.js +16991 -0
- package/dist/main.0792d734cde2c688d5f7.hot-update.js.map +1 -0
- package/dist/main.0792d734cde2c688d5f7.hot-update.json +1 -0
- package/dist/pretty-chitty.js +204513 -0
- package/dist/pretty-chitty.js.map +1 -0
- 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 +1 -0
- package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.js +12 -0
- package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
- package/dist/rendering/ChitRenderInstance.d.ts +9 -1
- package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/ChitRenderInstance.js +28 -0
- package/dist/rendering/ChitRenderInstance.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/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 +13 -0
- package/dist/utilities/CanvasStack/CanvasStack.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/CanvasStack.js +66 -15
- package/dist/utilities/CanvasStack/CanvasStack.js.map +1 -1
- package/dist/utilities/TokenizedText.d.ts +55 -0
- package/dist/utilities/TokenizedText.d.ts.map +1 -0
- package/dist/utilities/TokenizedText.js +47 -0
- package/dist/utilities/TokenizedText.js.map +1 -0
- 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/ClientTrustMatchViewer.tsx +32 -2
- package/src/library/components/ContextGalleryDisplay.tsx +2 -0
- package/src/library/components/DemoWrapper.tsx +147 -52
- package/src/library/components/FullScreenGalleryDisplay.tsx +3 -0
- package/src/library/components/Gallery/BuiltItem.ts +34 -9
- package/src/library/components/Gallery/GalleryController.ts +75 -2
- package/src/library/components/Gallery/GalleryViewer.tsx +54 -10
- package/src/library/components/Gallery/LayoutManager.ts +30 -6
- package/src/library/components/Gallery/constants.ts +2 -0
- package/src/library/components/Gallery/registry.ts +44 -0
- package/src/library/components/GameDesigner.tsx +121 -12
- package/src/library/components/InlineGalleryDisplay.tsx +5 -0
- package/src/library/components/LiveButton.tsx +8 -5
- package/src/library/components/MatchViewer.tsx +14 -3
- package/src/library/components/Panel/MultiPanel.tsx +21 -0
- package/src/library/components/Panel/PanelContents.tsx +70 -1
- package/src/library/components/Panel/PanelTabStack.tsx +1 -0
- package/src/library/components/PanelSpark.tsx +9 -4
- package/src/library/components/Playground.tsx +125 -33
- 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 +30 -95
- package/src/library/components/TopBarPlayers.tsx +18 -10
- 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 +1301 -0
- package/src/library/components/Tutorial/targetRects.ts +273 -0
- package/src/library/game/Chit.ts +23 -7
- package/src/library/game/ClientTimeState.ts +18 -0
- package/src/library/game/ConnectionTransport.ts +12 -3
- package/src/library/game/Game.ts +16 -1
- package/src/library/game/GameTheme.ts +4 -0
- package/src/library/game/Match.ts +174 -5
- package/src/library/game/MatchStorage.ts +14 -4
- package/src/library/game/Pick.ts +36 -1
- package/src/library/game/PlayerChit.ts +4 -1
- package/src/library/game/PlayerInfo.ts +13 -3
- package/src/library/game/PlayerPromptStatusChit.ts +8 -2
- package/src/library/game/Prompt.ts +20 -0
- package/src/library/game/Turn.ts +198 -68
- package/src/library/game/TurnState.ts +34 -3
- package/src/library/game/ai/AI_GUIDE.md +444 -0
- package/src/library/game/ai/AiClientPrompts.ts +730 -0
- package/src/library/game/ai/AiLiveView.ts +63 -0
- package/src/library/game/ai/AiPlayerView.ts +114 -0
- package/src/library/game/ai/ai.test.ts +475 -0
- package/src/library/game/ai/connectAiPlayer.ts +88 -0
- package/src/library/game/ai/defineAi.ts +230 -0
- package/src/library/game/ai/simulateMatches.ts +172 -0
- package/src/library/game/badAiTransport/BadAIClientPrompts.ts +3 -0
- package/src/library/game/clientTransport/ClientPrompts.ts +31 -1
- package/src/library/game/clientTransport/ClientTime.ts +54 -13
- package/src/library/game/serialize.test.ts +275 -0
- package/src/library/game/tutorial/TUTORIAL_GUIDE.md +411 -0
- package/src/library/game/tutorial/TutorialController.test.ts +731 -0
- package/src/library/game/tutorial/TutorialController.ts +1286 -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 +331 -0
- package/src/library/game/undo.test.ts +282 -0
- package/src/library/hooks/usePanelNavigation.tsx +65 -0
- package/src/library/hooks/useTimeController.tsx +6 -2
- package/src/library/hooks/useTokenMap.ts +2 -6
- package/src/library/hooks/useTutorial.tsx +76 -0
- package/src/library/index.ts +91 -4
- package/src/library/rendering/CameraWrapperPerspective.ts +17 -0
- package/src/library/rendering/ChitGalleryItemInstance.ts +12 -0
- package/src/library/rendering/ChitRenderInstance.ts +34 -0
- package/src/library/rendering/RootChitRenderInstance.ts +30 -1
- package/src/library/utilities/Annotations.ts +35 -7
- package/src/library/utilities/CanvasStack/CanvasStack.ts +74 -29
- package/src/library/utilities/TokenizedText.test.ts +32 -0
- package/src/library/utilities/TokenizedText.ts +103 -0
- package/src/library/utilities/zIndex.ts +1 -0
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { Box, IconButton, Stack, Tooltip, Typography } from "@mui/material";
|
|
3
|
+
import {
|
|
4
|
+
ArrowBack,
|
|
5
|
+
ArrowForward,
|
|
6
|
+
Close,
|
|
7
|
+
DragIndicator,
|
|
8
|
+
Pause,
|
|
9
|
+
PlayArrow,
|
|
10
|
+
SkipNext,
|
|
11
|
+
VolumeOff,
|
|
12
|
+
VolumeUp,
|
|
13
|
+
} from "@mui/icons-material";
|
|
14
|
+
import { TutorialTheme } from "../../game/tutorial/TutorialTheme";
|
|
15
|
+
import { TutorialController, TutorialStatus } from "../../game/tutorial/TutorialController";
|
|
16
|
+
import { useEventChannelState } from "../../hooks/useEventChannelState";
|
|
17
|
+
import { TokenizedMarkdown } from "../TokenizedMarkdown";
|
|
18
|
+
import { TokenMap } from "../../utilities/TokenizedText";
|
|
19
|
+
|
|
20
|
+
export type BoxPosition = { x: number; y: number };
|
|
21
|
+
|
|
22
|
+
export function TutorialBox({
|
|
23
|
+
controller,
|
|
24
|
+
theme,
|
|
25
|
+
tokenMap,
|
|
26
|
+
position,
|
|
27
|
+
width,
|
|
28
|
+
narrow = false,
|
|
29
|
+
onDrag,
|
|
30
|
+
onMeasure,
|
|
31
|
+
started,
|
|
32
|
+
onStart,
|
|
33
|
+
hasNarration,
|
|
34
|
+
resolveImage,
|
|
35
|
+
}: {
|
|
36
|
+
controller: TutorialController<any, any>;
|
|
37
|
+
theme: TutorialTheme;
|
|
38
|
+
tokenMap: TokenMap;
|
|
39
|
+
position: BoxPosition;
|
|
40
|
+
width: number;
|
|
41
|
+
/** Narrow screen: tighter padding and type so the box covers less */
|
|
42
|
+
narrow?: boolean;
|
|
43
|
+
onDrag: (pos: BoxPosition) => void;
|
|
44
|
+
onMeasure: (size: { width: number; height: number }) => void;
|
|
45
|
+
started: boolean;
|
|
46
|
+
onStart: () => void;
|
|
47
|
+
hasNarration: boolean;
|
|
48
|
+
resolveImage?: (src: string) => string;
|
|
49
|
+
}) {
|
|
50
|
+
const [index] = useEventChannelState(controller.index);
|
|
51
|
+
const [status] = useEventChannelState(controller.status);
|
|
52
|
+
const [hint] = useEventChannelState(controller.hint);
|
|
53
|
+
const [sentence] = useEventChannelState(controller.sentence);
|
|
54
|
+
const [narrating] = useEventChannelState(controller.narrating);
|
|
55
|
+
const [paused] = useEventChannelState(controller.paused);
|
|
56
|
+
const [rate] = useEventChannelState(controller.rate);
|
|
57
|
+
const [rewinding] = useEventChannelState(controller.rewinding);
|
|
58
|
+
const [muted] = useEventChannelState(controller.muted);
|
|
59
|
+
const [check] = useEventChannelState(controller.check);
|
|
60
|
+
const [reviewing] = useEventChannelState(controller.reviewing);
|
|
61
|
+
const [frontier] = useEventChannelState(controller.frontier);
|
|
62
|
+
const [blockedCount] = useEventChannelState(controller.blocked);
|
|
63
|
+
const [blockedFlash, setBlockedFlash] = useState(false);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (blockedCount === 0) return;
|
|
66
|
+
setBlockedFlash(true);
|
|
67
|
+
const to = setTimeout(() => setBlockedFlash(false), 1800);
|
|
68
|
+
return () => clearTimeout(to);
|
|
69
|
+
}, [blockedCount]);
|
|
70
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
71
|
+
const bodyRef = useRef<HTMLDivElement>(null);
|
|
72
|
+
const dragRef = useRef<{ startX: number; startY: number; originX: number; originY: number } | null>(null);
|
|
73
|
+
const [dragging, setDragging] = useState(false);
|
|
74
|
+
const [confirmSkip, setConfirmSkip] = useState(false);
|
|
75
|
+
|
|
76
|
+
const step = controller.step;
|
|
77
|
+
const total = controller.steps.length;
|
|
78
|
+
const fontSize = (narrow ? 13.5 : 15) * theme.fontScalar;
|
|
79
|
+
// On a phone the text gets about four lines, and follows the voice (below)
|
|
80
|
+
const bodyMaxHeight = narrow ? Math.round(fontSize * 1.35 * 4.2) : undefined;
|
|
81
|
+
|
|
82
|
+
// Keep the sentence being read in view, like a teleprompter: a long text scrolls under it. A step
|
|
83
|
+
// starts at the top; once the narration ends the whole text can be scrolled freely.
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const body = bodyRef.current;
|
|
86
|
+
if (!body) return;
|
|
87
|
+
if (sentence < 0) return;
|
|
88
|
+
const el = body.querySelector(`[data-sentence="${sentence}"]`) as HTMLElement | null;
|
|
89
|
+
if (!el) return;
|
|
90
|
+
const top = el.getBoundingClientRect().top - body.getBoundingClientRect().top + body.scrollTop;
|
|
91
|
+
// a sliver of the line before, so the reader keeps their place
|
|
92
|
+
body.scrollTo({ top: Math.max(0, top - fontSize * 0.5), behavior: "smooth" });
|
|
93
|
+
}, [sentence, fontSize]);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
bodyRef.current?.scrollTo({ top: 0 });
|
|
96
|
+
}, [index]);
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
const el = ref.current;
|
|
100
|
+
if (!el) return;
|
|
101
|
+
const report = () => onMeasure({ width: el.offsetWidth, height: el.offsetHeight });
|
|
102
|
+
report();
|
|
103
|
+
const ro = new ResizeObserver(report);
|
|
104
|
+
ro.observe(el);
|
|
105
|
+
return () => ro.disconnect();
|
|
106
|
+
}, [onMeasure, index, hint, started]);
|
|
107
|
+
|
|
108
|
+
const onPointerDown = useCallback(
|
|
109
|
+
(e: React.PointerEvent) => {
|
|
110
|
+
dragRef.current = { startX: e.clientX, startY: e.clientY, originX: position.x, originY: position.y };
|
|
111
|
+
(e.target as HTMLElement).setPointerCapture?.(e.pointerId);
|
|
112
|
+
setDragging(true);
|
|
113
|
+
e.stopPropagation();
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
},
|
|
116
|
+
[position.x, position.y],
|
|
117
|
+
);
|
|
118
|
+
const onPointerMove = useCallback(
|
|
119
|
+
(e: React.PointerEvent) => {
|
|
120
|
+
const d = dragRef.current;
|
|
121
|
+
if (!d) return;
|
|
122
|
+
onDrag({ x: d.originX + (e.clientX - d.startX), y: d.originY + (e.clientY - d.startY) });
|
|
123
|
+
e.stopPropagation();
|
|
124
|
+
},
|
|
125
|
+
[onDrag],
|
|
126
|
+
);
|
|
127
|
+
const onPointerUp = useCallback((e: React.PointerEvent) => {
|
|
128
|
+
dragRef.current = null;
|
|
129
|
+
setDragging(false);
|
|
130
|
+
e.stopPropagation();
|
|
131
|
+
}, []);
|
|
132
|
+
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
setConfirmSkip(false);
|
|
135
|
+
}, [index]);
|
|
136
|
+
|
|
137
|
+
const stop = (e: React.SyntheticEvent) => e.stopPropagation();
|
|
138
|
+
|
|
139
|
+
const waiting = status === "waiting" && !reviewing;
|
|
140
|
+
const satisfied = status === "satisfied" && !reviewing;
|
|
141
|
+
const done = status === "done";
|
|
142
|
+
const canAdvance = controller.canAdvance;
|
|
143
|
+
// Does this step want something from the player, or is it waiting on the bots/the world?
|
|
144
|
+
const allow = step?.allow;
|
|
145
|
+
const playerActs = !!step?.waitFor && !!allow && (!Array.isArray(allow) || allow.length > 0);
|
|
146
|
+
const statusLabel = rewinding
|
|
147
|
+
? index > frontier
|
|
148
|
+
? "Skipping ahead…"
|
|
149
|
+
: "Going back…"
|
|
150
|
+
: reviewing
|
|
151
|
+
? "Reviewing"
|
|
152
|
+
: paused && !(waiting && playerActs)
|
|
153
|
+
? "Paused"
|
|
154
|
+
: statusText(status, check, playerActs);
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<Box
|
|
158
|
+
ref={ref}
|
|
159
|
+
onPointerDown={stop}
|
|
160
|
+
onPointerUp={stop}
|
|
161
|
+
onClick={stop}
|
|
162
|
+
onTouchStart={stop}
|
|
163
|
+
onMouseDown={stop}
|
|
164
|
+
sx={{
|
|
165
|
+
position: "absolute",
|
|
166
|
+
left: position.x,
|
|
167
|
+
top: position.y,
|
|
168
|
+
width,
|
|
169
|
+
maxWidth: "calc(100% - 16px)",
|
|
170
|
+
maxHeight: narrow ? "45%" : "60%",
|
|
171
|
+
display: "flex",
|
|
172
|
+
flexDirection: "column",
|
|
173
|
+
pointerEvents: "auto",
|
|
174
|
+
background: theme.boxBackground,
|
|
175
|
+
color: theme.boxTextColor,
|
|
176
|
+
borderRadius: `${theme.borderRadius}px`,
|
|
177
|
+
boxShadow: theme.boxShadow,
|
|
178
|
+
fontFamily: theme.fontFamily,
|
|
179
|
+
transition: dragging
|
|
180
|
+
? "none"
|
|
181
|
+
: "left 0.35s cubic-bezier(.2,.8,.2,1), top 0.35s cubic-bezier(.2,.8,.2,1), bottom 0.35s cubic-bezier(.2,.8,.2,1)",
|
|
182
|
+
overflow: "hidden",
|
|
183
|
+
userSelect: "none",
|
|
184
|
+
touchAction: "none",
|
|
185
|
+
border: `1px solid ${blockedFlash ? theme.accent : theme.highlightGlow}`,
|
|
186
|
+
animation: blockedFlash ? "tutorialShake 0.4s ease-in-out" : undefined,
|
|
187
|
+
"@keyframes tutorialShake": {
|
|
188
|
+
"0%, 100%": { transform: "translateX(0)" },
|
|
189
|
+
"25%": { transform: "translateX(-6px)" },
|
|
190
|
+
"75%": { transform: "translateX(6px)" },
|
|
191
|
+
},
|
|
192
|
+
}}
|
|
193
|
+
>
|
|
194
|
+
{/* Title row / drag handle */}
|
|
195
|
+
<Stack
|
|
196
|
+
direction="row"
|
|
197
|
+
alignItems="center"
|
|
198
|
+
onPointerDown={onPointerDown}
|
|
199
|
+
onPointerMove={onPointerMove}
|
|
200
|
+
onPointerUp={onPointerUp}
|
|
201
|
+
onPointerCancel={onPointerUp}
|
|
202
|
+
sx={{ px: 1.5, pt: narrow ? 0.5 : 1, pb: 0.5, cursor: dragging ? "grabbing" : "grab" }}
|
|
203
|
+
>
|
|
204
|
+
<DragIndicator sx={{ opacity: 0.4, fontSize: 18, mr: 0.5 }} />
|
|
205
|
+
<Typography sx={{ fontSize: 12 * theme.fontScalar, opacity: 0.7, flex: 1, fontFamily: "inherit" }}>
|
|
206
|
+
{done ? controller.spec.title : `${controller.spec.title} · ${index + 1} / ${total}`}
|
|
207
|
+
</Typography>
|
|
208
|
+
{!done && (
|
|
209
|
+
<Tooltip title={confirmSkip ? "Tap again to leave the tutorial" : "Skip tutorial"}>
|
|
210
|
+
<IconButton
|
|
211
|
+
size="small"
|
|
212
|
+
onClick={() => (confirmSkip ? controller.skip() : setConfirmSkip(true))}
|
|
213
|
+
sx={{ color: confirmSkip ? theme.accent : theme.boxTextColor, opacity: confirmSkip ? 1 : 0.6, p: 0.25 }}
|
|
214
|
+
>
|
|
215
|
+
<Close fontSize="small" />
|
|
216
|
+
</IconButton>
|
|
217
|
+
</Tooltip>
|
|
218
|
+
)}
|
|
219
|
+
</Stack>
|
|
220
|
+
|
|
221
|
+
{/* Progress */}
|
|
222
|
+
{!done && (
|
|
223
|
+
<Box sx={{ height: 3, mx: 1.5, borderRadius: 2, background: "rgba(255,255,255,0.12)" }}>
|
|
224
|
+
<Box
|
|
225
|
+
sx={{
|
|
226
|
+
height: "100%",
|
|
227
|
+
borderRadius: 2,
|
|
228
|
+
background: theme.accent,
|
|
229
|
+
width: `${((index + 1) / total) * 100}%`,
|
|
230
|
+
transition: "width 0.3s ease-out",
|
|
231
|
+
}}
|
|
232
|
+
/>
|
|
233
|
+
</Box>
|
|
234
|
+
)}
|
|
235
|
+
|
|
236
|
+
{/* Body */}
|
|
237
|
+
<Box
|
|
238
|
+
ref={bodyRef}
|
|
239
|
+
sx={{ px: 1.5, pt: narrow ? 0.75 : 1.25, pb: narrow ? 0.5 : 1, overflowY: "auto", flex: 1, minHeight: 0, maxHeight: bodyMaxHeight }}
|
|
240
|
+
>
|
|
241
|
+
{!started ? (
|
|
242
|
+
<TokenizedMarkdown
|
|
243
|
+
text={controller.spec.intro ?? controller.spec.steps[0]?.text ?? ""}
|
|
244
|
+
fontSize={fontSize}
|
|
245
|
+
tokenMap={tokenMap}
|
|
246
|
+
color={theme.boxTextColor}
|
|
247
|
+
resolveImage={resolveImage}
|
|
248
|
+
/>
|
|
249
|
+
) : step ? (
|
|
250
|
+
<TokenizedMarkdown
|
|
251
|
+
text={step.text}
|
|
252
|
+
fontSize={fontSize}
|
|
253
|
+
tokenMap={tokenMap}
|
|
254
|
+
color={theme.boxTextColor}
|
|
255
|
+
activeSentence={sentence}
|
|
256
|
+
accent={theme.accent}
|
|
257
|
+
resolveImage={resolveImage}
|
|
258
|
+
/>
|
|
259
|
+
) : null}
|
|
260
|
+
{blockedFlash && (
|
|
261
|
+
<Box
|
|
262
|
+
sx={{
|
|
263
|
+
mt: 1,
|
|
264
|
+
px: 1,
|
|
265
|
+
py: 0.75,
|
|
266
|
+
borderRadius: 1.5,
|
|
267
|
+
fontSize: 13 * theme.fontScalar,
|
|
268
|
+
background: "rgba(255,255,255,0.08)",
|
|
269
|
+
borderLeft: `3px solid ${theme.accent}`,
|
|
270
|
+
}}
|
|
271
|
+
>
|
|
272
|
+
{waiting
|
|
273
|
+
? (typeof step?.hint === "object" ? step.hint.text : step?.hint) ?? "Not that: follow the instructions above."
|
|
274
|
+
: "Not yet: the tutorial will tell you when it's your move."}
|
|
275
|
+
</Box>
|
|
276
|
+
)}
|
|
277
|
+
{hint && waiting && !blockedFlash && (
|
|
278
|
+
<Box
|
|
279
|
+
sx={{
|
|
280
|
+
mt: 1,
|
|
281
|
+
px: 1,
|
|
282
|
+
py: 0.75,
|
|
283
|
+
borderRadius: 1.5,
|
|
284
|
+
fontSize: 13 * theme.fontScalar,
|
|
285
|
+
background: "rgba(255,255,255,0.08)",
|
|
286
|
+
borderLeft: `3px solid ${theme.accent}`,
|
|
287
|
+
}}
|
|
288
|
+
>
|
|
289
|
+
{hint}
|
|
290
|
+
</Box>
|
|
291
|
+
)}
|
|
292
|
+
</Box>
|
|
293
|
+
|
|
294
|
+
{/* Footer */}
|
|
295
|
+
<Stack direction="row" alignItems="center" sx={{ px: 1, pb: 0.75, pt: 0.25 }}>
|
|
296
|
+
{!started ? (
|
|
297
|
+
<>
|
|
298
|
+
<Box flex={1} />
|
|
299
|
+
<PrimaryButton theme={theme} onClick={onStart} label="Start" icon={<PlayArrow fontSize="small" />} />
|
|
300
|
+
</>
|
|
301
|
+
) : (
|
|
302
|
+
<>
|
|
303
|
+
<Tooltip title={controller.rewinds ? "Previous step (←, puts the game back as it was)" : "Previous step (←)"}>
|
|
304
|
+
<span>
|
|
305
|
+
<IconButton
|
|
306
|
+
size="small"
|
|
307
|
+
disabled={index <= 0}
|
|
308
|
+
onClick={() => controller.back()}
|
|
309
|
+
sx={{ color: theme.boxTextColor, opacity: index <= 0 ? 0.3 : 0.8 }}
|
|
310
|
+
>
|
|
311
|
+
<ArrowBack fontSize="small" />
|
|
312
|
+
</IconButton>
|
|
313
|
+
</span>
|
|
314
|
+
</Tooltip>
|
|
315
|
+
<Tooltip title={narrating && !paused ? "Pause (Space)" : "Play (Space)"}>
|
|
316
|
+
<IconButton
|
|
317
|
+
size="small"
|
|
318
|
+
onClick={() => controller.toggleNarration()}
|
|
319
|
+
sx={{
|
|
320
|
+
color: paused ? theme.accent : theme.boxTextColor,
|
|
321
|
+
opacity: paused ? 1 : 0.8,
|
|
322
|
+
}}
|
|
323
|
+
>
|
|
324
|
+
{narrating && !paused ? <Pause fontSize="small" /> : <PlayArrow fontSize="small" />}
|
|
325
|
+
</IconButton>
|
|
326
|
+
</Tooltip>
|
|
327
|
+
<Tooltip title="Narration speed">
|
|
328
|
+
<Box
|
|
329
|
+
component="button"
|
|
330
|
+
onClick={() => controller.setRate(nextRate(rate))}
|
|
331
|
+
sx={{
|
|
332
|
+
border: "none",
|
|
333
|
+
background: rate === 1 ? "transparent" : "rgba(255,255,255,0.12)",
|
|
334
|
+
color: rate === 1 ? theme.boxTextColor : theme.accent,
|
|
335
|
+
opacity: rate === 1 ? 0.8 : 1,
|
|
336
|
+
fontFamily: "inherit",
|
|
337
|
+
fontWeight: 700,
|
|
338
|
+
fontSize: 12 * theme.fontScalar,
|
|
339
|
+
minWidth: 38,
|
|
340
|
+
height: 26,
|
|
341
|
+
px: 0.75,
|
|
342
|
+
borderRadius: 999,
|
|
343
|
+
cursor: "pointer",
|
|
344
|
+
fontVariantNumeric: "tabular-nums",
|
|
345
|
+
}}
|
|
346
|
+
>
|
|
347
|
+
{formatRate(rate)}
|
|
348
|
+
</Box>
|
|
349
|
+
</Tooltip>
|
|
350
|
+
{hasNarration && (
|
|
351
|
+
<>
|
|
352
|
+
<Tooltip title={muted ? "Unmute" : "Mute"}>
|
|
353
|
+
<IconButton
|
|
354
|
+
size="small"
|
|
355
|
+
onClick={() => controller.setMuted(!muted)}
|
|
356
|
+
sx={{ color: theme.boxTextColor, opacity: 0.8 }}
|
|
357
|
+
>
|
|
358
|
+
{muted ? <VolumeOff fontSize="small" /> : <VolumeUp fontSize="small" />}
|
|
359
|
+
</IconButton>
|
|
360
|
+
</Tooltip>
|
|
361
|
+
</>
|
|
362
|
+
)}
|
|
363
|
+
{reviewing && (
|
|
364
|
+
<Tooltip title={`Back to step ${frontier + 1}`}>
|
|
365
|
+
<IconButton size="small" onClick={() => controller.resume()} sx={{ color: theme.accent, opacity: 0.9 }}>
|
|
366
|
+
<SkipNext fontSize="small" />
|
|
367
|
+
</IconButton>
|
|
368
|
+
</Tooltip>
|
|
369
|
+
)}
|
|
370
|
+
<Box flex={1} />
|
|
371
|
+
{statusLabel && (
|
|
372
|
+
<Stack direction="row" alignItems="center" spacing={0.75} sx={{ mr: 1 }}>
|
|
373
|
+
<Box
|
|
374
|
+
sx={{
|
|
375
|
+
width: 8,
|
|
376
|
+
height: 8,
|
|
377
|
+
borderRadius: "50%",
|
|
378
|
+
background: theme.accent,
|
|
379
|
+
animation: waiting && !paused ? "tutorialPulse 1.2s ease-in-out infinite" : undefined,
|
|
380
|
+
opacity: reviewing ? 0.5 : 1,
|
|
381
|
+
"@keyframes tutorialPulse": {
|
|
382
|
+
"0%": { transform: "scale(0.8)", opacity: 0.5 },
|
|
383
|
+
"50%": { transform: "scale(1.3)", opacity: 1 },
|
|
384
|
+
"100%": { transform: "scale(0.8)", opacity: 0.5 },
|
|
385
|
+
},
|
|
386
|
+
}}
|
|
387
|
+
/>
|
|
388
|
+
<Typography sx={{ fontSize: 12 * theme.fontScalar, opacity: 0.8, fontFamily: "inherit" }}>
|
|
389
|
+
{statusLabel}
|
|
390
|
+
</Typography>
|
|
391
|
+
</Stack>
|
|
392
|
+
)}
|
|
393
|
+
{/* Paused: Resume is the way on (Next stays as a small arrow to step through silently).
|
|
394
|
+
Otherwise Next shows only when there is something to move on to: while the step waits
|
|
395
|
+
for the player's move the status says "Your move" and Next appears once it is done */}
|
|
396
|
+
{paused && !rewinding ? (
|
|
397
|
+
<>
|
|
398
|
+
{canAdvance && (
|
|
399
|
+
<Tooltip title={controller.isLast ? "Finish (→)" : "Next step (→, stays paused)"}>
|
|
400
|
+
<IconButton
|
|
401
|
+
size="small"
|
|
402
|
+
onClick={() => controller.next()}
|
|
403
|
+
sx={{ color: theme.boxTextColor, opacity: 0.8, mr: 0.5 }}
|
|
404
|
+
>
|
|
405
|
+
<ArrowForward fontSize="small" />
|
|
406
|
+
</IconButton>
|
|
407
|
+
</Tooltip>
|
|
408
|
+
)}
|
|
409
|
+
<PrimaryButton
|
|
410
|
+
theme={theme}
|
|
411
|
+
onClick={() => controller.play()}
|
|
412
|
+
label="Resume"
|
|
413
|
+
icon={<PlayArrow fontSize="small" />}
|
|
414
|
+
/>
|
|
415
|
+
</>
|
|
416
|
+
) : (
|
|
417
|
+
(canAdvance || satisfied) && (
|
|
418
|
+
<PrimaryButton
|
|
419
|
+
theme={theme}
|
|
420
|
+
onClick={() => controller.next()}
|
|
421
|
+
label={controller.isLast ? "Finish" : "Next"}
|
|
422
|
+
icon={<ArrowForward fontSize="small" />}
|
|
423
|
+
/>
|
|
424
|
+
)
|
|
425
|
+
)}
|
|
426
|
+
</>
|
|
427
|
+
)}
|
|
428
|
+
</Stack>
|
|
429
|
+
</Box>
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const RATES = [1, 1.25, 1.5, 2];
|
|
434
|
+
|
|
435
|
+
function nextRate(rate: number) {
|
|
436
|
+
const i = RATES.findIndex((r) => Math.abs(r - rate) < 0.001);
|
|
437
|
+
return RATES[(i + 1) % RATES.length];
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function formatRate(rate: number) {
|
|
441
|
+
return `${Number.isInteger(rate) ? rate : rate.toFixed(rate * 100 % 10 === 0 ? 1 : 2)}×`;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function statusText(status: TutorialStatus, check: boolean | string | undefined, playerActs: boolean) {
|
|
445
|
+
if (status === "waiting") return check === true ? "Nice!" : playerActs ? "Your move" : "Watch the table";
|
|
446
|
+
if (status === "satisfied") return "Nice!";
|
|
447
|
+
return undefined;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function PrimaryButton({
|
|
451
|
+
theme,
|
|
452
|
+
onClick,
|
|
453
|
+
label,
|
|
454
|
+
icon,
|
|
455
|
+
disabled,
|
|
456
|
+
}: {
|
|
457
|
+
theme: TutorialTheme;
|
|
458
|
+
onClick: () => void;
|
|
459
|
+
label: string;
|
|
460
|
+
icon: React.ReactNode;
|
|
461
|
+
disabled?: boolean;
|
|
462
|
+
}) {
|
|
463
|
+
return (
|
|
464
|
+
<Box
|
|
465
|
+
component="button"
|
|
466
|
+
onClick={disabled ? undefined : onClick}
|
|
467
|
+
disabled={disabled}
|
|
468
|
+
sx={{
|
|
469
|
+
display: "inline-flex",
|
|
470
|
+
alignItems: "center",
|
|
471
|
+
gap: 0.5,
|
|
472
|
+
border: "none",
|
|
473
|
+
cursor: disabled ? "default" : "pointer",
|
|
474
|
+
borderRadius: 999,
|
|
475
|
+
px: 1.5,
|
|
476
|
+
py: 0.5,
|
|
477
|
+
fontFamily: "inherit",
|
|
478
|
+
fontSize: 13 * theme.fontScalar,
|
|
479
|
+
fontWeight: 700,
|
|
480
|
+
letterSpacing: 0.3,
|
|
481
|
+
color: disabled ? theme.boxTextColor : contrastText(theme.accent),
|
|
482
|
+
background: disabled ? "rgba(255,255,255,0.12)" : theme.accent,
|
|
483
|
+
opacity: disabled ? 0.6 : 1,
|
|
484
|
+
transition: "background 0.2s, opacity 0.2s, transform 0.1s",
|
|
485
|
+
"&:active": { transform: disabled ? "none" : "scale(0.97)" },
|
|
486
|
+
}}
|
|
487
|
+
>
|
|
488
|
+
{label}
|
|
489
|
+
{icon}
|
|
490
|
+
</Box>
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function contrastText(background: string) {
|
|
495
|
+
try {
|
|
496
|
+
// tiny luminance check without pulling in color for every render
|
|
497
|
+
const m = background.replace("#", "");
|
|
498
|
+
const hex = m.length >= 6 ? m : m.replace(/(.)/g, "$1$1");
|
|
499
|
+
const r = parseInt(hex.substring(0, 2), 16);
|
|
500
|
+
const g = parseInt(hex.substring(2, 4), 16);
|
|
501
|
+
const b = parseInt(hex.substring(4, 6), 16);
|
|
502
|
+
return (r * 299 + g * 587 + b * 114) / 1000 > 150 ? "#111" : "#fff";
|
|
503
|
+
} catch {
|
|
504
|
+
return "#fff";
|
|
505
|
+
}
|
|
506
|
+
}
|