@pretty-chitty/core 2.0.0 → 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/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 -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 +6 -2
- package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
- package/dist/components/Gallery/BuiltItem.js +28 -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 +67 -0
- 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 +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/TopBarPlayers.d.ts.map +1 -1
- package/dist/components/TopBarPlayers.js +1 -1
- 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 +20 -5
- 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/Game.d.ts +6 -0
- 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 +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/Pick.d.ts +2 -0
- package/dist/game/Pick.d.ts.map +1 -1
- package/dist/game/Pick.js +17 -1
- 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 +5 -1
- 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 +15 -4
- package/dist/game/Turn.d.ts.map +1 -1
- package/dist/game/Turn.js +173 -60
- 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 +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/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 +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.html +12 -0
- package/dist/index.js +19 -2
- 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 +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/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 +147 -44
- package/src/library/components/FullScreenGalleryDisplay.tsx +3 -0
- package/src/library/components/Gallery/BuiltItem.ts +30 -9
- package/src/library/components/Gallery/GalleryController.ts +72 -1
- 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 +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/TopBarPlayers.tsx +12 -9
- 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 +21 -5
- package/src/library/game/ClientTimeState.ts +18 -0
- package/src/library/game/Game.ts +7 -0
- package/src/library/game/GameTheme.ts +4 -0
- package/src/library/game/Match.ts +12 -2
- package/src/library/game/Pick.ts +16 -1
- package/src/library/game/PlayerPromptStatusChit.ts +5 -1
- package/src/library/game/Prompt.ts +20 -0
- package/src/library/game/Turn.ts +179 -61
- 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 +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/useTutorial.tsx +76 -0
- package/src/library/index.ts +57 -2
- 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 +6 -1
- package/src/library/utilities/TokenizedText.ts +6 -0
- package/src/library/utilities/zIndex.ts +1 -0
|
@@ -60,11 +60,15 @@ export function useAnimationSpeedMultiplier() {
|
|
|
60
60
|
return speed;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export function TimeControllerProvider({ children }: { children: ReactNode }) {
|
|
63
|
+
export function TimeControllerProvider({ children, skipReplay = false }: { children: ReactNode; skipReplay?: boolean }) {
|
|
64
64
|
const connection = useConnection();
|
|
65
65
|
const playerId = usePlayerId();
|
|
66
66
|
const game = useGame();
|
|
67
|
-
const [clientTimeState] = useState<ClientTimeState>(
|
|
67
|
+
const [clientTimeState] = useState<ClientTimeState>(() => {
|
|
68
|
+
const state = new ClientTimeState();
|
|
69
|
+
state.skipInitialReplay = skipReplay;
|
|
70
|
+
return state;
|
|
71
|
+
});
|
|
68
72
|
const [clientTime, setClientTime] = useState<ClientTime | null>(null);
|
|
69
73
|
const [clientPrompts, setClientPrompts] = useState<ClientPrompts<any, any> | undefined>(undefined);
|
|
70
74
|
const [clientStatus, setClientStatus] = useState<ClientStatus<any, any> | undefined>(undefined);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { createContext, ReactNode, useContext, useMemo, useState } from "react";
|
|
2
|
+
import { EventChannel } from "../utilities/EventChannel";
|
|
3
|
+
import { TutorialSpec } from "../game/tutorial/defineTutorial";
|
|
4
|
+
import { TutorialController, TutorialEvent } from "../game/tutorial/TutorialController";
|
|
5
|
+
import { TutorialRuntime } from "../game/tutorial/TutorialRuntime";
|
|
6
|
+
import { TutorialTheme } from "../game/tutorial/TutorialTheme";
|
|
7
|
+
import { MatchAiControls } from "../game/Match";
|
|
8
|
+
|
|
9
|
+
export type TutorialDevSettings = {
|
|
10
|
+
showTargetRects: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type TutorialContextValue = {
|
|
14
|
+
spec: TutorialSpec<any, any>;
|
|
15
|
+
runtime: TutorialRuntime<any, any>;
|
|
16
|
+
themeOverrides?: Partial<TutorialTheme>;
|
|
17
|
+
ai?: MatchAiControls;
|
|
18
|
+
onEvent?: (e: TutorialEvent) => void;
|
|
19
|
+
/** Set by the overlay once it has built the controller (it needs the match view, which lives inside MatchViewer) */
|
|
20
|
+
controller: EventChannel<TutorialController<any, any> | undefined>;
|
|
21
|
+
dev: EventChannel<TutorialDevSettings>;
|
|
22
|
+
/** Start muted (dev panel toggle) */
|
|
23
|
+
muted: EventChannel<boolean>;
|
|
24
|
+
/** Step to start on (dev panel restarts, rewinds) */
|
|
25
|
+
startAt: number;
|
|
26
|
+
/** Start the script without the Start tap (after a rewind or a dev restart) */
|
|
27
|
+
autoStart: boolean;
|
|
28
|
+
/** Start held (after Back): silent until the player presses Play */
|
|
29
|
+
startPaused: boolean;
|
|
30
|
+
/** Serializes the match for a step snapshot; undefined when the host cannot rebuild the match */
|
|
31
|
+
snapshot?: () => unknown;
|
|
32
|
+
/** Puts the match back to the snapshot taken when `stepId` went live; false when there is none */
|
|
33
|
+
rewind?: (stepId: string) => Promise<boolean>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const TutorialContext = createContext<TutorialContextValue | undefined>(undefined);
|
|
37
|
+
|
|
38
|
+
/** The running tutorial, or undefined when the match has none. */
|
|
39
|
+
export function useTutorial(): TutorialContextValue | undefined {
|
|
40
|
+
return useContext(TutorialContext);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function TutorialProvider({
|
|
44
|
+
spec,
|
|
45
|
+
runtime,
|
|
46
|
+
themeOverrides,
|
|
47
|
+
ai,
|
|
48
|
+
onEvent,
|
|
49
|
+
startAt = 0,
|
|
50
|
+
autoStart = false,
|
|
51
|
+
startPaused = false,
|
|
52
|
+
snapshot,
|
|
53
|
+
rewind,
|
|
54
|
+
children,
|
|
55
|
+
}: {
|
|
56
|
+
spec: TutorialSpec<any, any>;
|
|
57
|
+
runtime: TutorialRuntime<any, any>;
|
|
58
|
+
themeOverrides?: Partial<TutorialTheme>;
|
|
59
|
+
ai?: MatchAiControls;
|
|
60
|
+
onEvent?: (e: TutorialEvent) => void;
|
|
61
|
+
startAt?: number;
|
|
62
|
+
autoStart?: boolean;
|
|
63
|
+
startPaused?: boolean;
|
|
64
|
+
snapshot?: () => unknown;
|
|
65
|
+
rewind?: (stepId: string) => Promise<boolean>;
|
|
66
|
+
children: ReactNode;
|
|
67
|
+
}) {
|
|
68
|
+
const [controller] = useState(() => new EventChannel<TutorialController<any, any> | undefined>(undefined));
|
|
69
|
+
const [dev] = useState(() => new EventChannel<TutorialDevSettings>({ showTargetRects: false }));
|
|
70
|
+
const [muted] = useState(() => new EventChannel<boolean>(false));
|
|
71
|
+
const value = useMemo<TutorialContextValue>(
|
|
72
|
+
() => ({ spec, runtime, themeOverrides, ai, onEvent, controller, dev, muted, startAt, autoStart, startPaused, snapshot, rewind }),
|
|
73
|
+
[spec, runtime, themeOverrides, ai, onEvent, controller, dev, muted, startAt, autoStart, startPaused, snapshot, rewind],
|
|
74
|
+
);
|
|
75
|
+
return <TutorialContext.Provider value={value}>{children}</TutorialContext.Provider>;
|
|
76
|
+
}
|
package/src/library/index.ts
CHANGED
|
@@ -62,6 +62,60 @@ export { simulateMatches } from "./game/ai/simulateMatches";
|
|
|
62
62
|
/** @group AI */
|
|
63
63
|
export type { SimulateMatchesOptions, SimulatedMatch, SimulationReport } from "./game/ai/simulateMatches";
|
|
64
64
|
|
|
65
|
+
/** @group Tutorials */
|
|
66
|
+
export { defineTutorial, listTutorials, findTutorial, splitSentences } from "./game/tutorial/defineTutorial";
|
|
67
|
+
/** @group Tutorials */
|
|
68
|
+
export type {
|
|
69
|
+
TutorialSpec,
|
|
70
|
+
TutorialStep,
|
|
71
|
+
TutorialMatchSetup,
|
|
72
|
+
TutorialContext,
|
|
73
|
+
TutorialSummary,
|
|
74
|
+
Checker,
|
|
75
|
+
CheckResult,
|
|
76
|
+
ChitSelector,
|
|
77
|
+
Target,
|
|
78
|
+
UiTarget,
|
|
79
|
+
Focus,
|
|
80
|
+
Cue,
|
|
81
|
+
BoxPlacement,
|
|
82
|
+
BoxAnchor,
|
|
83
|
+
ForcedDecision,
|
|
84
|
+
AllowedAction,
|
|
85
|
+
GalleryCommand,
|
|
86
|
+
Pose,
|
|
87
|
+
TimelineCommand,
|
|
88
|
+
TutorialGalleryState,
|
|
89
|
+
} from "./game/tutorial/defineTutorial";
|
|
90
|
+
/** @group Tutorials */
|
|
91
|
+
export { checks } from "./game/tutorial/checks";
|
|
92
|
+
/** @group Tutorials */
|
|
93
|
+
export { runTutorial } from "./game/tutorial/runTutorial";
|
|
94
|
+
/** @group Tutorials */
|
|
95
|
+
export type { RunTutorialOptions, RunTutorialResult } from "./game/tutorial/runTutorial";
|
|
96
|
+
/** @group Tutorials */
|
|
97
|
+
export { createDemoMatch } from "./game/tutorial/createDemoMatch";
|
|
98
|
+
/** @group Tutorials */
|
|
99
|
+
export type { DemoMatch, CreateDemoMatchOptions } from "./game/tutorial/createDemoMatch";
|
|
100
|
+
/** @group Tutorials */
|
|
101
|
+
export { TutorialController } from "./game/tutorial/TutorialController";
|
|
102
|
+
/** @group Tutorials */
|
|
103
|
+
export type { TutorialEvent, TutorialStatus, TutorialView, NarrationPlayer } from "./game/tutorial/TutorialController";
|
|
104
|
+
/** @group Tutorials */
|
|
105
|
+
export { TutorialRuntime } from "./game/tutorial/TutorialRuntime";
|
|
106
|
+
/** @group Tutorials */
|
|
107
|
+
export type { TutorialTheme } from "./game/tutorial/TutorialTheme";
|
|
108
|
+
/** @group Tutorials */
|
|
109
|
+
export { resolveTutorialTheme } from "./game/tutorial/TutorialTheme";
|
|
110
|
+
/** @group Tutorials */
|
|
111
|
+
export { TokenizedMarkdown } from "./components/TokenizedMarkdown";
|
|
112
|
+
/** @group Tutorials */
|
|
113
|
+
export { TutorialDevPanel } from "./components/Tutorial/TutorialDevPanel";
|
|
114
|
+
/** @group Supporting Types */
|
|
115
|
+
export type { RngSource } from "./game/TurnState";
|
|
116
|
+
/** @group Supporting Types */
|
|
117
|
+
export type { MatchConfig } from "./game/Match";
|
|
118
|
+
|
|
65
119
|
/** @group Buttons */
|
|
66
120
|
export { GameButton, DynamicGameButton, ToggleGalleryButton } from "./game/GameButton";
|
|
67
121
|
|
|
@@ -115,9 +169,10 @@ export type { IPlayerInfo, AiSeatInfo } from "./game/PlayerInfo";
|
|
|
115
169
|
/** @internal */
|
|
116
170
|
/** @group Supporting Types */
|
|
117
171
|
export { MatchViewer } from "./components/MatchViewer";
|
|
118
|
-
/** @
|
|
119
|
-
/** @group Supporting Types */
|
|
172
|
+
/** @group Tutorials */
|
|
120
173
|
export { DemoWrapper } from "./components/DemoWrapper";
|
|
174
|
+
/** @group Tutorials */
|
|
175
|
+
export type { DemoWrapperProps } from "./components/DemoWrapper";
|
|
121
176
|
/** @internal */
|
|
122
177
|
/** @group Supporting Types */
|
|
123
178
|
export { Match, MatchAiControls } from "./game/Match";
|
|
@@ -151,6 +151,23 @@ export class CameraWrapperPerspective {
|
|
|
151
151
|
this.adjust(this.bbox, !animate);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Zooms to `zoom` (clamped to the camera's range) and brings the point at panel pixel (x, y) to the
|
|
156
|
+
* middle of the panel, as far as panning allows. Animated. Zoom 1 is the whole table.
|
|
157
|
+
*/
|
|
158
|
+
public focusOn(x: number, y: number, zoom: number): void {
|
|
159
|
+
const z = Math.max(1, Math.min(zoom, this.cameraSpec.maxZoom));
|
|
160
|
+
// A point on screen sits at (content * zoom + offset) from the middle: keep the content under
|
|
161
|
+
// (x, y) and move it to the middle
|
|
162
|
+
const sx = x - this.width / 2;
|
|
163
|
+
const sy = y - this.height / 2;
|
|
164
|
+
this.current.x = -(sx - this.current.x) * (z / this.current.z);
|
|
165
|
+
this.current.y = -(sy - this.current.y) * (z / this.current.z);
|
|
166
|
+
this.current.z = z;
|
|
167
|
+
this.lockZoom();
|
|
168
|
+
this.adjust(this.bbox, false);
|
|
169
|
+
}
|
|
170
|
+
|
|
154
171
|
private lockZoom() {
|
|
155
172
|
const maxZoom = this.cameraSpec.maxZoom;
|
|
156
173
|
if (this.current.z <= 1) {
|
|
@@ -26,6 +26,7 @@ export class ChitGalleryItemInstance implements GalleryItem {
|
|
|
26
26
|
shortSummaryRenderingOptions?: RichTextRenderOptionsParameters;
|
|
27
27
|
|
|
28
28
|
private sceneWrapper: SceneWrapper | undefined;
|
|
29
|
+
private creatingMesh = false;
|
|
29
30
|
|
|
30
31
|
constructor(public chit: Chit) {
|
|
31
32
|
this.id = chit.id ?? "no id";
|
|
@@ -82,6 +83,14 @@ export class ChitGalleryItemInstance implements GalleryItem {
|
|
|
82
83
|
const renderInstance = this.chit.renderInstance;
|
|
83
84
|
const g = new Group();
|
|
84
85
|
if (renderInstance) {
|
|
86
|
+
// a refresh re-renders the chit, which would ask us to rebuild while we're mid-build
|
|
87
|
+
this.creatingMesh = true;
|
|
88
|
+
try {
|
|
89
|
+
renderInstance.refreshDisposedTextures();
|
|
90
|
+
} finally {
|
|
91
|
+
this.creatingMesh = false;
|
|
92
|
+
}
|
|
93
|
+
|
|
85
94
|
const mesh = this.cloneWithUserData(renderInstance.group) ?? new Group();
|
|
86
95
|
mesh.visible = true;
|
|
87
96
|
mesh.rotation.set(0, 0, 0);
|
|
@@ -101,6 +110,9 @@ export class ChitGalleryItemInstance implements GalleryItem {
|
|
|
101
110
|
}
|
|
102
111
|
|
|
103
112
|
update() {
|
|
113
|
+
if (this.creatingMesh) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
104
116
|
this.cbs.forEach((cb) => cb());
|
|
105
117
|
}
|
|
106
118
|
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
Group,
|
|
6
6
|
Mesh,
|
|
7
7
|
MeshBasicMaterial,
|
|
8
|
+
Object3D,
|
|
8
9
|
Plane,
|
|
9
10
|
Quaternion,
|
|
10
11
|
Raycaster,
|
|
@@ -18,6 +19,7 @@ import { Easing, Tween, Group as TweenGroup } from "@tweenjs/tween.js";
|
|
|
18
19
|
import { RootChitRenderInstance } from "./RootChitRenderInstance";
|
|
19
20
|
import { fixBbox } from "../utilities/BboxUtils";
|
|
20
21
|
import { ChitGalleryItemInstance } from "./ChitGalleryItemInstance";
|
|
22
|
+
import { CanvasStack } from "../utilities/CanvasStack/CanvasStack";
|
|
21
23
|
|
|
22
24
|
const LINE_COLOR = new MeshBasicMaterial({ color: 0xff0000, wireframe: true, wireframeLinewidth: 2 });
|
|
23
25
|
const CLICK_LINE_COLOR = new MeshBasicMaterial({ color: 0xffff00, wireframe: true, wireframeLinewidth: 2 });
|
|
@@ -50,6 +52,11 @@ export class ChitRenderInstance {
|
|
|
50
52
|
// rendering info
|
|
51
53
|
protected renderSpec: ChitRenderSpec | null = null;
|
|
52
54
|
|
|
55
|
+
/** The chit's own drawn object (not its children or ornaments), for exact hit tests on a tap. */
|
|
56
|
+
public get hitObject(): Object3D | undefined {
|
|
57
|
+
return this.renderSpec?.object ?? undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
53
60
|
// threejs info
|
|
54
61
|
public group = new Group(); // group storing the visible meshes. Will tween
|
|
55
62
|
protected targetAnchorPoints = new Map<OwnerOriginPosition | string, Vector3>();
|
|
@@ -453,6 +460,33 @@ export class ChitRenderInstance {
|
|
|
453
460
|
return this._galleryItem;
|
|
454
461
|
}
|
|
455
462
|
|
|
463
|
+
/**
|
|
464
|
+
* Hidden chits (e.g. inside a deck or bag) aren't counted by the TextureReferenceCounter, so their textures get
|
|
465
|
+
* reclaimed while the render spec still points at them. Galleries clone that spec, so re-render first if stale.
|
|
466
|
+
*/
|
|
467
|
+
public refreshDisposedTextures() {
|
|
468
|
+
if (this.usesDisposedTexture()) {
|
|
469
|
+
this.refresh();
|
|
470
|
+
}
|
|
471
|
+
[...this.childrenRenderInstances].forEach((child) => child.refreshDisposedTextures());
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
private usesDisposedTexture() {
|
|
475
|
+
let disposed = false;
|
|
476
|
+
[this.renderSpec?.object, ...(this.renderSpec?.ornaments ?? [])].forEach((root) =>
|
|
477
|
+
root?.traverse((obj) => {
|
|
478
|
+
if (!disposed && obj instanceof Mesh) {
|
|
479
|
+
const materials = Array.isArray(obj.material) ? obj.material : [obj.material];
|
|
480
|
+
disposed = materials.some((m) => {
|
|
481
|
+
const map = (m as MeshBasicMaterial | undefined)?.map;
|
|
482
|
+
return !!map && CanvasStack.isDisposedTexture(map);
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
}),
|
|
486
|
+
);
|
|
487
|
+
return disposed;
|
|
488
|
+
}
|
|
489
|
+
|
|
456
490
|
public destroyGalleryItem() {
|
|
457
491
|
if (this._galleryItem) {
|
|
458
492
|
this._galleryItem.destroy();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Tween, Group as TweenGroup } from "@tweenjs/tween.js";
|
|
2
2
|
import { ChitRenderInstance } from "./ChitRenderInstance";
|
|
3
3
|
import { Chit } from "../game/Chit";
|
|
4
|
-
import { Box3, Group, Object3D, Plane, Raycaster, Vector2, Vector3 } from "three";
|
|
4
|
+
import { Box3, Group, Mesh, Object3D, Plane, Raycaster, Vector2, Vector3 } from "three";
|
|
5
5
|
import { CameraWrapperPerspective } from "./CameraWrapperPerspective";
|
|
6
6
|
import { LightWrapper } from "./LightWrapper";
|
|
7
7
|
import { ModalState } from "../game/ModalState";
|
|
@@ -331,6 +331,11 @@ export class RootChitRenderInstance extends ChitRenderInstance implements Textur
|
|
|
331
331
|
precision: number,
|
|
332
332
|
): Chit[] {
|
|
333
333
|
const result = new Map<Chit, number>();
|
|
334
|
+
// Box hits that the ray also hits on the chit's real shape. A clickbox is the axis-aligned box around the whole
|
|
335
|
+
// object, so a large irregular piece (a sea area, a province) claims every tap inside its rectangle, and
|
|
336
|
+
// neighbours whose rectangles overlap would all be offered in a gallery. See the end of this function.
|
|
337
|
+
const exact = new Map<Chit, number>();
|
|
338
|
+
const hasShape = new Map<Chit, boolean>();
|
|
334
339
|
const chitRenderInstances: ChitRenderInstance[] = [];
|
|
335
340
|
const threeJsToChitLookup: { [threejsId: number]: Chit } = {};
|
|
336
341
|
|
|
@@ -371,10 +376,28 @@ export class RootChitRenderInstance extends ChitRenderInstance implements Textur
|
|
|
371
376
|
const c = threeJsToChitLookup[id];
|
|
372
377
|
if (filter(c)) {
|
|
373
378
|
result.set(c, Math.min(result.get(c) ?? r, r));
|
|
379
|
+
const shape = c.renderInstance?.hitObject;
|
|
380
|
+
if (!hasShape.has(c)) {
|
|
381
|
+
let meshes = false;
|
|
382
|
+
shape?.traverse((o) => {
|
|
383
|
+
if ((o as Mesh).isMesh) meshes = true;
|
|
384
|
+
});
|
|
385
|
+
hasShape.set(c, meshes);
|
|
386
|
+
}
|
|
387
|
+
if (shape && hasShape.get(c) && (exact.get(c) ?? Infinity) > r && raycaster.intersectObject(shape, true).length) {
|
|
388
|
+
exact.set(c, r);
|
|
389
|
+
}
|
|
374
390
|
}
|
|
375
391
|
}
|
|
376
392
|
}
|
|
377
393
|
}
|
|
394
|
+
// Keep the chits whose real shape was hit, plus those with no mesh of their own to test (an empty group that
|
|
395
|
+
// is clicked through its children). If no shape was hit at all (a tap in the gap between pieces, within the
|
|
396
|
+
// finger tolerance), fall back to the boxes so a near miss still lands. Nearest first.
|
|
397
|
+
const precise = [...result.keys()].filter((c) => exact.has(c) || !hasShape.get(c));
|
|
398
|
+
if (precise.length && precise.length < result.size) {
|
|
399
|
+
return precise.sort((a, b) => (exact.get(a) ?? result.get(a)!) - (exact.get(b) ?? result.get(b)!));
|
|
400
|
+
}
|
|
378
401
|
return [...result.keys()];
|
|
379
402
|
}
|
|
380
403
|
|
|
@@ -465,6 +488,12 @@ export class RootChitRenderInstance extends ChitRenderInstance implements Textur
|
|
|
465
488
|
this.markDirty();
|
|
466
489
|
}
|
|
467
490
|
|
|
491
|
+
/** Zooms the camera to `zoom` around panel pixel (x, y), bringing it to the middle (see `CameraWrapperPerspective.focusOn`) */
|
|
492
|
+
public focusCamera(x: number, y: number, zoom: number) {
|
|
493
|
+
this.cameraWrapper.focusOn(x, y, zoom);
|
|
494
|
+
this.markDirty();
|
|
495
|
+
}
|
|
496
|
+
|
|
468
497
|
public get cameraZoom() {
|
|
469
498
|
return this.cameraWrapper.zoom;
|
|
470
499
|
}
|
|
@@ -23,6 +23,11 @@ export interface SelectableConfig {
|
|
|
23
23
|
label: string;
|
|
24
24
|
/** List of possible choices for this property */
|
|
25
25
|
choices: SelectableChoice[];
|
|
26
|
+
/**
|
|
27
|
+
* When true the property holds any number of the choices' ids (a `string[]`, e.g. the expansion
|
|
28
|
+
* modules a match plays with) rather than exactly one. Defaults to false.
|
|
29
|
+
*/
|
|
30
|
+
multiple?: boolean;
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
/**
|
|
@@ -203,17 +208,30 @@ export function FixChildOutlets(instance: Chit) {
|
|
|
203
208
|
|
|
204
209
|
if (obj?.__orderedOutlets) {
|
|
205
210
|
Object.entries(obj.__orderedOutlets).forEach(([key, prop]: [key: any, prop: any]) => {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (v) {
|
|
209
|
-
v.outletName = key;
|
|
210
|
-
v.parent = instance;
|
|
211
|
+
if (seenKeys.has(`ordered:${key}`)) {
|
|
212
|
+
return;
|
|
211
213
|
}
|
|
214
|
+
seenKeys.add(`ordered:${key}`);
|
|
215
|
+
const existingValue = (instance as any)[key];
|
|
216
|
+
let v = existingValue || prop?.initializer?.apply(instance, []);
|
|
217
|
+
const adopt = (outlet: any) => {
|
|
218
|
+
if (outlet instanceof OrderedOutlet) {
|
|
219
|
+
outlet.outletName = key;
|
|
220
|
+
outlet.parent = instance;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
adopt(v);
|
|
224
|
+
// An accessor rather than a data property: with TypeScript/esbuild class fields (no babel
|
|
225
|
+
// initializer capture) the subclass constructor assigns `new OrderedOutlet()` *after* this
|
|
226
|
+
// runs, and the setter adopts that outlet instead of leaving it parentless.
|
|
212
227
|
Object.defineProperty(instance, key, {
|
|
213
228
|
enumerable: true,
|
|
214
|
-
writable: true,
|
|
215
229
|
configurable: true,
|
|
216
|
-
|
|
230
|
+
get: () => v,
|
|
231
|
+
set: (newValue: any) => {
|
|
232
|
+
v = newValue;
|
|
233
|
+
adopt(v);
|
|
234
|
+
},
|
|
217
235
|
});
|
|
218
236
|
});
|
|
219
237
|
}
|
|
@@ -237,6 +255,16 @@ export function FixChildOutlets(instance: Chit) {
|
|
|
237
255
|
* ]
|
|
238
256
|
* })
|
|
239
257
|
* public difficulty: string = "medium";
|
|
258
|
+
*
|
|
259
|
+
* @Selectable({
|
|
260
|
+
* label: "Expansions",
|
|
261
|
+
* multiple: true,
|
|
262
|
+
* choices: [
|
|
263
|
+
* { id: "rivers", label: "Rivers" },
|
|
264
|
+
* { id: "traders", label: "Traders & Builders" },
|
|
265
|
+
* ],
|
|
266
|
+
* })
|
|
267
|
+
* public expansions: string[] = [];
|
|
240
268
|
* }
|
|
241
269
|
* ```
|
|
242
270
|
*
|
|
@@ -332,7 +332,12 @@ export class CanvasStack implements IUpdatingCanvas {
|
|
|
332
332
|
CanvasStack._liveStacks.delete(canvasStack);
|
|
333
333
|
});
|
|
334
334
|
|
|
335
|
-
|
|
335
|
+
/** True once the disposer has reclaimed this texture; anything still drawing with it renders blank. */
|
|
336
|
+
public static isDisposedTexture(texture: Texture) {
|
|
337
|
+
return !!_NOTHING_CANVAS && texture.source.data === _NOTHING_CANVAS;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
public static materialDisposer =new ThreeDisposer<Material>((material) => {
|
|
336
341
|
material.dispose();
|
|
337
342
|
});
|
|
338
343
|
|
|
@@ -11,6 +11,12 @@ export interface TokenDefinition {
|
|
|
11
11
|
image?: string | ImageSpec;
|
|
12
12
|
label?: string;
|
|
13
13
|
color?: string;
|
|
14
|
+
/**
|
|
15
|
+
* How far the image extends above and below its line of text, as a fraction of the font size. The image grows by
|
|
16
|
+
* twice this amount without pushing lines apart, so a large value can overlap neighbouring lines. Defaults to 0.2,
|
|
17
|
+
* or 0 when the token has a `color` (so the image stays inside the colored background).
|
|
18
|
+
*/
|
|
19
|
+
imageBleed?: number;
|
|
14
20
|
/** Plain-text representation of this token, for places that cannot render images or styling. */
|
|
15
21
|
text?: string;
|
|
16
22
|
}
|