@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
|
@@ -4,36 +4,115 @@ import { ConnectionTransport } from "./ConnectionTransport";
|
|
|
4
4
|
import { Game, GameResult } from "./Game";
|
|
5
5
|
import { ServerTime } from "./serverTransport/ServerTime";
|
|
6
6
|
import { PlayerInfo } from "./PlayerInfo";
|
|
7
|
-
import { MismatchError, RerunError, Turn } from "./Turn";
|
|
8
|
-
import { TurnState } from "./TurnState";
|
|
7
|
+
import { DestroyError, MismatchError, RerunError, Turn } from "./Turn";
|
|
8
|
+
import { RngSource, TurnState } from "./TurnState";
|
|
9
9
|
import { IMatchStorage } from "./MatchStorage";
|
|
10
10
|
import { ServerPrompts } from "./serverTransport/ServerPrompts";
|
|
11
11
|
import { EventChannel } from "../utilities/EventChannel";
|
|
12
12
|
import { RootChit } from "./RootChit";
|
|
13
13
|
import { ServerStatus } from "./serverTransport/ServerStatus";
|
|
14
14
|
import { PlayerChit } from "./PlayerChit";
|
|
15
|
+
import { AiPlayerHandle, ConnectAiPlayerOptions, connectAiPlayer } from "./ai/connectAiPlayer";
|
|
16
|
+
import type { AiMemoryStore } from "./ai/AiClientPrompts";
|
|
17
|
+
|
|
18
|
+
/** Engine-level knobs for a match (as opposed to the game's own `matchOptions`). */
|
|
19
|
+
export type MatchConfig = {
|
|
20
|
+
/** Where fresh random draws come from. Default: `Math.random`. See `RngSource`. */
|
|
21
|
+
rngSource?: RngSource;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Options for {@link Match.seatAiPlayers}: applied to every bot it seats. */
|
|
25
|
+
export type SeatAiPlayersOptions = Omit<ConnectAiPlayerOptions, "difficulty" | "params" | "choose" | "memoryStore">;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The bots attached to a match, however they were seated ({@link Match.seatAiPlayers} or
|
|
29
|
+
* `connectAiPlayer`), and the one switch a host needs over them.
|
|
30
|
+
*
|
|
31
|
+
* @group AI
|
|
32
|
+
*/
|
|
33
|
+
export class MatchAiControls {
|
|
34
|
+
private _enabled = true;
|
|
35
|
+
private _handles: AiPlayerHandle[] = [];
|
|
36
|
+
|
|
37
|
+
/** Every bot currently attached, in seating order */
|
|
38
|
+
get handles(): readonly AiPlayerHandle[] {
|
|
39
|
+
return this._handles;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Ids of the seats that have a bot */
|
|
43
|
+
get seatedPlayerIds(): string[] {
|
|
44
|
+
return this._handles.map((h) => h.playerId);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** True when no bot is in the middle of answering a prompt (safe to tear the match down) */
|
|
48
|
+
get idle(): boolean {
|
|
49
|
+
return this._handles.every((h) => h.prompts.idle);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Whether the bots answer prompts. Default true. Set it false on every copy of a match but one
|
|
54
|
+
* when several copies run at once (each browser tab in client-trust mode, or two bundle versions
|
|
55
|
+
* of a match on a server), otherwise each copy answers the same prompt. Bots keep their memory
|
|
56
|
+
* while paused and answer the pending prompt when resumed. Applies to bots seated later too.
|
|
57
|
+
*/
|
|
58
|
+
get enabled(): boolean {
|
|
59
|
+
return this._enabled;
|
|
60
|
+
}
|
|
61
|
+
set enabled(enabled: boolean) {
|
|
62
|
+
this._enabled = enabled;
|
|
63
|
+
this._handles.forEach((h) => h.prompts.setEnabled(enabled));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @internal */
|
|
67
|
+
register(handle: AiPlayerHandle) {
|
|
68
|
+
this._handles.push(handle);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** @internal */
|
|
72
|
+
unregister(handle: AiPlayerHandle) {
|
|
73
|
+
this._handles = this._handles.filter((h) => h !== handle);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** @internal */
|
|
77
|
+
disposeAll() {
|
|
78
|
+
[...this._handles].forEach((h) => h.dispose());
|
|
79
|
+
this._handles = [];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
15
82
|
|
|
16
83
|
export class Match<P extends PlayerChit, R extends RootChit<P>> {
|
|
17
84
|
public state: TurnState = new TurnState();
|
|
18
85
|
public result = new EventChannel<undefined | GameResult<P>>(undefined);
|
|
19
86
|
public turn = new EventChannel<undefined | Turn<GameResult<P>, P, R>>(undefined);
|
|
20
87
|
public errorState = new EventChannel<undefined | string>(undefined);
|
|
88
|
+
/** The AI players attached to this match and the switch that pauses them. See {@link seatAiPlayers}. */
|
|
89
|
+
public readonly ai = new MatchAiControls();
|
|
21
90
|
private onChangeCallbacks: (() => void)[] = [];
|
|
91
|
+
private connections: Connection[] = [];
|
|
92
|
+
private unsubscribeStorage?: () => void;
|
|
93
|
+
private disposed = false;
|
|
22
94
|
|
|
23
95
|
constructor(
|
|
24
96
|
public game: Game<P, R>,
|
|
25
97
|
public players: PlayerInfo[],
|
|
26
98
|
private matchStorage: IMatchStorage,
|
|
27
99
|
private matchOptions?: any,
|
|
28
|
-
|
|
100
|
+
private config: MatchConfig = {},
|
|
101
|
+
) {
|
|
102
|
+
this.state.rngSource = config.rngSource;
|
|
103
|
+
}
|
|
29
104
|
|
|
30
105
|
async load() {
|
|
31
106
|
const savedState = await this.matchStorage.readState();
|
|
32
107
|
if (savedState !== null) {
|
|
33
108
|
this.state.deserialize(savedState);
|
|
34
109
|
}
|
|
35
|
-
this.matchStorage.registerNewStateCallback((savedState) => {
|
|
110
|
+
this.unsubscribeStorage = this.matchStorage.registerNewStateCallback((savedState) => {
|
|
111
|
+
if (this.disposed) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
36
114
|
this.state = new TurnState();
|
|
115
|
+
this.state.rngSource = this.config.rngSource;
|
|
37
116
|
this.state.deserialize(savedState);
|
|
38
117
|
if (this.errorState.value) {
|
|
39
118
|
this.turn.value?.destroy();
|
|
@@ -121,6 +200,11 @@ export class Match<P extends PlayerChit, R extends RootChit<P>> {
|
|
|
121
200
|
return;
|
|
122
201
|
}
|
|
123
202
|
|
|
203
|
+
if (e instanceof DestroyError || this.disposed) {
|
|
204
|
+
// The turn was torn down on purpose (dispose, or a reload replacing it): not an error
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
124
208
|
throw e;
|
|
125
209
|
}
|
|
126
210
|
}
|
|
@@ -133,11 +217,77 @@ export class Match<P extends PlayerChit, R extends RootChit<P>> {
|
|
|
133
217
|
connection.register(new ServerTime(this, playerId, connection));
|
|
134
218
|
connection.register(new ServerPrompts(playerId, this, connection));
|
|
135
219
|
connection.register(new ServerStatus(this, connection));
|
|
220
|
+
this.connections.push(connection);
|
|
136
221
|
return connection;
|
|
137
222
|
}
|
|
138
223
|
|
|
224
|
+
/**
|
|
225
|
+
* Seats an engine AI in every seat whose `PlayerInfo.ai` is set and that has no bot yet, and
|
|
226
|
+
* returns the handles of the bots it created. Call it after `load()` and before (or after)
|
|
227
|
+
* `start()`. Hosts opt in by calling it; the `ai` flag on its own does nothing, so a harness that
|
|
228
|
+
* seats its own bots with `connectAiPlayer` is never doubled up. Seats already taken by a
|
|
229
|
+
* `connectAiPlayer` bot are skipped, so the two can be mixed: hand-seat the bot under test, then
|
|
230
|
+
* call this for the rest.
|
|
231
|
+
*
|
|
232
|
+
* Each bot's `difficulty` comes from its seat's `ai` info; everything else from `options`.
|
|
233
|
+
* Bots follow {@link MatchAiControls.enabled} and are disposed with the match.
|
|
234
|
+
*
|
|
235
|
+
* ```ts
|
|
236
|
+
* const match = new Match(game, players, storage, options);
|
|
237
|
+
* await match.load();
|
|
238
|
+
* match.seatAiPlayers({ thinkMs: [400, 900] });
|
|
239
|
+
* match.start();
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* @group AI
|
|
243
|
+
*/
|
|
244
|
+
seatAiPlayers(options: SeatAiPlayersOptions = {}): AiPlayerHandle[] {
|
|
245
|
+
const seated = new Set(this.ai.seatedPlayerIds);
|
|
246
|
+
return this.players
|
|
247
|
+
.filter((p) => p.ai && !seated.has(p.id))
|
|
248
|
+
.map((p) => connectAiPlayer(this, p.id, { ...options, difficulty: p.ai?.difficulty }));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Where a bot in `playerId`'s seat keeps its plan memory: a slot in this match's saved state, so
|
|
253
|
+
* it is persisted by whatever `IMatchStorage` the host supplied and comes back after a reload.
|
|
254
|
+
* `connectAiPlayer` uses this by default.
|
|
255
|
+
* @internal
|
|
256
|
+
*/
|
|
257
|
+
aiMemoryStore(playerId: string): AiMemoryStore {
|
|
258
|
+
return {
|
|
259
|
+
read: () => this.state.ai?.[playerId],
|
|
260
|
+
write: (memory) => {
|
|
261
|
+
const ai = (this.state.ai ??= {});
|
|
262
|
+
ai[playerId] = memory;
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Headless runs only (simulations, testbeds): notify once per event-loop pass on setImmediate
|
|
269
|
+
* instead of the 0 ms debounce timer, which waits ≥1 ms per change in Node. Every prompt
|
|
270
|
+
* response waits for the next notification (ServerPrompts.resolvePrompt), so that timer was most
|
|
271
|
+
* of a simulated game's run time. Off by default: servers and browsers keep the debounce.
|
|
272
|
+
*/
|
|
273
|
+
public immediateNotify = false;
|
|
139
274
|
private _timeout?: NodeJS.Timeout | number = undefined;
|
|
275
|
+
private _notifyQueued = false;
|
|
140
276
|
private notify() {
|
|
277
|
+
if (this.disposed) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (this.immediateNotify && typeof setImmediate === "function") {
|
|
281
|
+
// Not a re-deferring debounce: with several bots answering every pass it would never fire,
|
|
282
|
+
// and the prompt responses waiting on it would stall.
|
|
283
|
+
if (this._notifyQueued) return;
|
|
284
|
+
this._notifyQueued = true;
|
|
285
|
+
setImmediate(() => {
|
|
286
|
+
this._notifyQueued = false;
|
|
287
|
+
this.processNotify();
|
|
288
|
+
});
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
141
291
|
clearTimeout(this._timeout);
|
|
142
292
|
this._timeout = setTimeout(() => this.processNotify(), 0);
|
|
143
293
|
}
|
|
@@ -145,6 +295,9 @@ export class Match<P extends PlayerChit, R extends RootChit<P>> {
|
|
|
145
295
|
private _isSaving = false;
|
|
146
296
|
private _saveStateNeeded = false;
|
|
147
297
|
private processNotify() {
|
|
298
|
+
if (this.disposed) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
148
301
|
this.onChangeCallbacks.forEach((cb) => cb());
|
|
149
302
|
|
|
150
303
|
// TODO: this is a promise going nowhere... do we block on saving?
|
|
@@ -174,8 +327,24 @@ export class Match<P extends PlayerChit, R extends RootChit<P>> {
|
|
|
174
327
|
});
|
|
175
328
|
}
|
|
176
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Tears the match down: disposes its bots and every connection made through `connect`, stops
|
|
332
|
+
* listening to storage, and destroys the running turn so no prompt stays pending. Nothing is
|
|
333
|
+
* saved after this. A disposed match cannot be restarted; make a new one.
|
|
334
|
+
*/
|
|
177
335
|
public dispose() {
|
|
178
|
-
|
|
336
|
+
if (this.disposed) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
this.disposed = true;
|
|
340
|
+
clearTimeout(this._timeout);
|
|
341
|
+
this.ai.disposeAll();
|
|
342
|
+
this.connections.forEach((c) => c.dispose());
|
|
343
|
+
this.connections = [];
|
|
344
|
+
this.unsubscribeStorage?.();
|
|
345
|
+
this.unsubscribeStorage = undefined;
|
|
346
|
+
this.onChangeCallbacks = [];
|
|
347
|
+
this.turn.value?.destroy();
|
|
179
348
|
}
|
|
180
349
|
|
|
181
350
|
public onChange(cb: () => void, callNow = true) {
|
|
@@ -51,15 +51,25 @@ export class LocalMatchStorage implements IMatchStorage {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export class EphemeralMatchStorage implements IMatchStorage {
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* @param lazy Headless runs only (simulations, testbeds): keep a reference to the saved state and
|
|
56
|
+
* turn it into JSON only when read. Saves get much cheaper (stringifying the whole match on every
|
|
57
|
+
* change cost ~10% of a headless game), but a read returns the match as it is *now*, not as of the
|
|
58
|
+
* last save. Off by default: every save is a snapshot.
|
|
59
|
+
*/
|
|
60
|
+
constructor(
|
|
61
|
+
private matchId: string,
|
|
62
|
+
private lazy = false,
|
|
63
|
+
) {}
|
|
55
64
|
private onChangeCallbacks: ((state: any) => void)[] = [];
|
|
56
65
|
|
|
57
|
-
private state:
|
|
66
|
+
private state: any = "{}";
|
|
58
67
|
|
|
59
68
|
async readState(): Promise<any> {
|
|
60
69
|
const result = this.state;
|
|
61
70
|
if (result) {
|
|
62
|
-
|
|
71
|
+
// A string is a snapshot (or the initial empty state); an object is a lazy reference.
|
|
72
|
+
return JSON.parse(typeof result === "string" ? result : JSON.stringify(result));
|
|
63
73
|
}
|
|
64
74
|
return null;
|
|
65
75
|
}
|
|
@@ -70,7 +80,7 @@ export class EphemeralMatchStorage implements IMatchStorage {
|
|
|
70
80
|
winners?: PlayerChit[],
|
|
71
81
|
notify = false,
|
|
72
82
|
): Promise<void> {
|
|
73
|
-
this.state = JSON.stringify(newState);
|
|
83
|
+
this.state = this.lazy ? newState : JSON.stringify(newState);
|
|
74
84
|
if (notify) {
|
|
75
85
|
this.notify(newState);
|
|
76
86
|
}
|
package/src/library/game/Pick.ts
CHANGED
|
@@ -8,12 +8,15 @@ import { MismatchError, Turn } from "./Turn";
|
|
|
8
8
|
|
|
9
9
|
export type FindChit = (id: string) => Chit;
|
|
10
10
|
export type PickType = "ChitPick" | "ButtonPick" | "DragPick";
|
|
11
|
+
/** Links a pick to a rule in the game's AI (see {@link Pick.ai}). `d` must be JSON and public. */
|
|
12
|
+
export type PickAiTag = { k: string; d?: unknown };
|
|
11
13
|
export type PickSerialization = {
|
|
12
14
|
type: PickType;
|
|
13
15
|
message?: string;
|
|
14
16
|
help?: string;
|
|
15
17
|
details: any;
|
|
16
18
|
context?: string;
|
|
19
|
+
ai?: PickAiTag;
|
|
17
20
|
};
|
|
18
21
|
|
|
19
22
|
export abstract class Pick {
|
|
@@ -30,6 +33,9 @@ export abstract class Pick {
|
|
|
30
33
|
/** @internal */
|
|
31
34
|
public contextChit?: Chit;
|
|
32
35
|
|
|
36
|
+
/** @internal */
|
|
37
|
+
public aiTag?: PickAiTag;
|
|
38
|
+
|
|
33
39
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
40
|
/** @internal */
|
|
35
41
|
confirmLock(_turn: Turn<any, any, any>) {
|
|
@@ -75,6 +81,18 @@ export abstract class Pick {
|
|
|
75
81
|
return this;
|
|
76
82
|
}
|
|
77
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Tags this pick so AI players score its options with the rule named `key` in the game's
|
|
86
|
+
* `ai` (see `defineAi`). Untagged picks fall back to the AI's `default` rule, or random.
|
|
87
|
+
* @param key Rule name, e.g. "market.buy"
|
|
88
|
+
* @param data Optional JSON hint passed to the rule. It is sent to every client, so it must
|
|
89
|
+
* only contain information the prompted player is allowed to see.
|
|
90
|
+
*/
|
|
91
|
+
ai(key: string, data?: unknown): this {
|
|
92
|
+
this.aiTag = data === undefined ? { k: key } : { k: key, d: data };
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
|
|
78
96
|
/** @internal */
|
|
79
97
|
serialize(): PickSerialization {
|
|
80
98
|
return {
|
|
@@ -83,6 +101,7 @@ export abstract class Pick {
|
|
|
83
101
|
message: this.messageContents,
|
|
84
102
|
details: this.serializeDetails(),
|
|
85
103
|
context: this.contextChit ? this.contextChit.id : undefined,
|
|
104
|
+
ai: this.aiTag,
|
|
86
105
|
};
|
|
87
106
|
}
|
|
88
107
|
|
|
@@ -108,6 +127,7 @@ export abstract class Pick {
|
|
|
108
127
|
p.contextChit = pick.context ? findChit(pick.context) : undefined;
|
|
109
128
|
p.messageContents = pick.message;
|
|
110
129
|
p.helpContents = pick.help;
|
|
130
|
+
p.aiTag = pick.ai;
|
|
111
131
|
p.deserializeDetails(pick.details, findChit, buttonLibrary);
|
|
112
132
|
return p;
|
|
113
133
|
}
|
|
@@ -306,18 +326,32 @@ export class DragPick<C extends Chit> extends Pick {
|
|
|
306
326
|
|
|
307
327
|
public dropTargets: DragTarget<any, C>[] = [];
|
|
308
328
|
|
|
329
|
+
/** Focus the draggable chits themselves (no argument), or the given chits, when the prompt stages in */
|
|
330
|
+
focus(chit?: Chit | Chit[]): this {
|
|
331
|
+
if (!chit) {
|
|
332
|
+
this.focusChits.push(...this.chits);
|
|
333
|
+
} else if (Array.isArray(chit)) {
|
|
334
|
+
this.focusChits.push(...chit);
|
|
335
|
+
} else {
|
|
336
|
+
this.focusChits.push(chit);
|
|
337
|
+
}
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
|
|
309
341
|
/** @internal */
|
|
310
342
|
serializeDetails() {
|
|
311
343
|
const result: any = {
|
|
312
344
|
c: this.chits.map((chit) => chit.id),
|
|
313
345
|
d: this.dropTargets.map((dropTarget) => dropTarget.chits.map((chit) => chit.id)),
|
|
346
|
+
f: this.focusChits.map((chit) => chit.id),
|
|
314
347
|
};
|
|
315
348
|
return result;
|
|
316
349
|
}
|
|
317
350
|
|
|
318
351
|
/** @internal */
|
|
319
|
-
deserializeDetails({ c, d }: { c: string[]; d: string[][] }, findChit: FindChit): void {
|
|
352
|
+
deserializeDetails({ c, d, f }: { c: string[]; d: string[][]; f?: string[] }, findChit: FindChit): void {
|
|
320
353
|
this.chits = c.map((chitId) => findChit(chitId) as C).filter((d) => d);
|
|
354
|
+
this.focusChits = (f ?? []).map((chitId) => findChit(chitId)).filter((d) => d);
|
|
321
355
|
this.dropTargets = d.map((dropIds: string[]) => {
|
|
322
356
|
const result = new DragTarget<any, C>();
|
|
323
357
|
result.chits = dropIds.map((chitId: string) => findChit(chitId)).filter((d) => d);
|
|
@@ -355,6 +389,7 @@ export class DragPick<C extends Chit> extends Pick {
|
|
|
355
389
|
prompt.resolvePick(this, { chitId: c.id!, targetChitId: droppedChit.id! });
|
|
356
390
|
};
|
|
357
391
|
});
|
|
392
|
+
this.processFocus();
|
|
358
393
|
}
|
|
359
394
|
|
|
360
395
|
/** @internal */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChildOutlet, NonEditable } from "../utilities/Annotations";
|
|
2
2
|
import { PlayerCanvas } from "../utilities/CanvasStack/PlayerCanvas";
|
|
3
3
|
import { Chit } from "./Chit";
|
|
4
|
-
import { PlayerInfo } from "./PlayerInfo";
|
|
4
|
+
import { AiSeatInfo, PlayerInfo } from "./PlayerInfo";
|
|
5
5
|
import { PlayerPromptStatusChit } from "./PlayerPromptStatusChit";
|
|
6
6
|
|
|
7
7
|
export class PlayerChit extends Chit {
|
|
@@ -11,6 +11,8 @@ export class PlayerChit extends Chit {
|
|
|
11
11
|
public playerId: string = "no id";
|
|
12
12
|
public name: string = "no name";
|
|
13
13
|
public color: string = "#000000";
|
|
14
|
+
/** Set when this seat is played by the engine's AI (copied from `PlayerInfo.ai`; public, so UIs can mark the seat) */
|
|
15
|
+
public ai?: AiSeatInfo = undefined;
|
|
14
16
|
|
|
15
17
|
/** @internal */
|
|
16
18
|
private myImageUrl?: string = undefined;
|
|
@@ -55,5 +57,6 @@ export class PlayerChit extends Chit {
|
|
|
55
57
|
this.name = playerInfo.name;
|
|
56
58
|
this.id = playerInfo.id;
|
|
57
59
|
this.imageUrl = playerInfo.imageUrl;
|
|
60
|
+
this.ai = playerInfo.ai;
|
|
58
61
|
}
|
|
59
62
|
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import multiavatar from "@multiavatar/multiavatar";
|
|
2
2
|
import base64 from "base-64";
|
|
3
3
|
|
|
4
|
+
/** Marks a seat as played by the engine's AI (see `connectAiPlayer`). */
|
|
5
|
+
export type AiSeatInfo = {
|
|
6
|
+
/** 0–1; lower plays less predictably. Default 0.85 */
|
|
7
|
+
difficulty?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
4
10
|
export interface IPlayerInfo {
|
|
5
11
|
id: string;
|
|
6
12
|
name: string;
|
|
7
13
|
imageUrl?: string;
|
|
14
|
+
ai?: AiSeatInfo;
|
|
8
15
|
}
|
|
9
16
|
|
|
10
17
|
export class PlayerInfo {
|
|
11
18
|
public id: string;
|
|
12
19
|
public name: string;
|
|
20
|
+
/** Set when this seat is an AI player */
|
|
21
|
+
public ai?: AiSeatInfo;
|
|
13
22
|
|
|
14
23
|
/** @internal */
|
|
15
24
|
public generateAvatar() {
|
|
16
|
-
if (!this.myImageUrl && window
|
|
25
|
+
if (!this.myImageUrl && typeof window !== "undefined" && window.URL) {
|
|
17
26
|
const data = multiavatar(`${this.name} ${this.id}`, true).replace("<svg", '<svg width="231" height="231"');
|
|
18
27
|
return `data:image/svg+xml;base64,${base64.encode(data)}`;
|
|
19
28
|
}
|
|
@@ -23,7 +32,7 @@ export class PlayerInfo {
|
|
|
23
32
|
/** @internal */
|
|
24
33
|
private myImageUrl?: string;
|
|
25
34
|
get imageUrl() {
|
|
26
|
-
if (!this.myImageUrl && window
|
|
35
|
+
if (!this.myImageUrl && typeof window !== "undefined" && window.URL) {
|
|
27
36
|
return this.generateAvatar();
|
|
28
37
|
}
|
|
29
38
|
return this.myImageUrl;
|
|
@@ -40,9 +49,10 @@ export class PlayerInfo {
|
|
|
40
49
|
this.id = idOrPlayerInfo.id;
|
|
41
50
|
this.name = idOrPlayerInfo.name;
|
|
42
51
|
this.imageUrl = idOrPlayerInfo.imageUrl;
|
|
52
|
+
this.ai = idOrPlayerInfo.ai;
|
|
43
53
|
}
|
|
44
54
|
|
|
45
|
-
if (!this.imageUrl && window
|
|
55
|
+
if (!this.imageUrl && typeof window !== "undefined" && window.URL) {
|
|
46
56
|
this.imageUrl = this.generateAvatar();
|
|
47
57
|
}
|
|
48
58
|
}
|
|
@@ -5,9 +5,15 @@ import { Prompt } from "./Prompt";
|
|
|
5
5
|
import StaticChitTypeRegistry from "./StaticChitTypeRegistry";
|
|
6
6
|
|
|
7
7
|
export class PlayerPromptStatusChit extends Chit {
|
|
8
|
-
/** @internal */
|
|
8
|
+
/** The prompt the player is currently being asked to answer, with `:token:` markup intact. @internal */
|
|
9
9
|
public latestPromptMessage?: string;
|
|
10
|
-
/** @internal */
|
|
10
|
+
/** Plain-text form of {@link latestPromptMessage} for storage, match lists and notifications. @internal */
|
|
11
|
+
public latestPromptMessageText?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The prompt this player is being asked right now, on the side that runs the match (undefined when
|
|
14
|
+
* it is not their turn). Read it, do not resolve it: answers go through the player's own client.
|
|
15
|
+
* Headless tutorial runs and harnesses use it to see whose turn it is.
|
|
16
|
+
*/
|
|
11
17
|
@NonEditable public latestPrompt = new EventChannel<Prompt | undefined>(undefined, 50);
|
|
12
18
|
/** @internal */
|
|
13
19
|
@NonEditable public latestPromptResponseTime = 0;
|
|
@@ -20,8 +20,17 @@ const defaultFindChit: FindChit = () => {
|
|
|
20
20
|
|
|
21
21
|
type FindChit = (id: string) => Chit;
|
|
22
22
|
|
|
23
|
+
/** What a player is trying to do with a prompt; a `PromptGuard` says whether it goes through. */
|
|
24
|
+
export type PromptAction = { type: "pick"; pick: Pick; value: any } | { type: "undo"; fullReset: boolean };
|
|
25
|
+
export type PromptGuard = (action: PromptAction) => boolean;
|
|
26
|
+
|
|
23
27
|
export abstract class Prompt {
|
|
24
28
|
public id = "";
|
|
29
|
+
/**
|
|
30
|
+
* Set on the client (see `ClientPrompts.guard`) to vet a player's answers before they are sent: a
|
|
31
|
+
* tutorial lets through only the moves its current step asks for. Not serialized.
|
|
32
|
+
*/
|
|
33
|
+
public guard?: PromptGuard;
|
|
25
34
|
public resolved = false;
|
|
26
35
|
public clock = 0;
|
|
27
36
|
public response: any;
|
|
@@ -73,6 +82,11 @@ export abstract class Prompt {
|
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
stepBack(fullReset: boolean = false) {
|
|
85
|
+
// The guard goes first: a tutorial turns Undo into its own Back, which works even where the
|
|
86
|
+
// engine could not undo (after a draw)
|
|
87
|
+
if (this.guard && !this.guard({ type: "undo", fullReset })) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
76
90
|
if (!this.canReset) {
|
|
77
91
|
throw new Error("Cannot be stepped back");
|
|
78
92
|
}
|
|
@@ -254,6 +268,12 @@ export class PickPrompt extends Prompt {
|
|
|
254
268
|
}
|
|
255
269
|
|
|
256
270
|
resolvePick(pick: Pick, value: any) {
|
|
271
|
+
if (this.resolved) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (this.guard && !this.guard({ type: "pick", pick, value })) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
257
277
|
const idx = this.picks.indexOf(pick);
|
|
258
278
|
this.resolve({ idx, value, pickType: pick.type });
|
|
259
279
|
}
|