@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
1
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
|
|
3
3
|
import { Chit } from "../game/Chit";
|
|
4
4
|
import { MatchViewer } from "./MatchViewer";
|
|
@@ -8,19 +8,31 @@ import { ConnectionProvider } from "../hooks/useConnection";
|
|
|
8
8
|
import { Connection } from "../game/Connection";
|
|
9
9
|
import { LocalConnectionTransport } from "../game/ConnectionTransport";
|
|
10
10
|
import { Match } from "../game/Match";
|
|
11
|
-
import { PlayerInfo } from "../game/PlayerInfo";
|
|
12
|
-
import { EphemeralMatchStorage } from "../game/MatchStorage";
|
|
13
11
|
import { PlayerProvider } from "../hooks/usePlayer";
|
|
14
|
-
import { LoadingStateProvider, LoadingStates } from "../hooks/useLoadingStates";
|
|
15
|
-
import {
|
|
12
|
+
import { LoadingStateProvider, LoadingStates, LoadingStatesCallback } from "../hooks/useLoadingStates";
|
|
13
|
+
import { TutorialSpec, findTutorial } from "../game/tutorial/defineTutorial";
|
|
14
|
+
import { createDemoMatch, DemoMatch } from "../game/tutorial/createDemoMatch";
|
|
15
|
+
import { runTutorial } from "../game/tutorial/runTutorial";
|
|
16
|
+
import { TutorialProvider } from "../hooks/useTutorial";
|
|
17
|
+
import { TutorialTheme } from "../game/tutorial/TutorialTheme";
|
|
18
|
+
import { TutorialEvent } from "../game/tutorial/TutorialController";
|
|
16
19
|
|
|
17
20
|
export interface IChitLibrary {
|
|
18
21
|
[key: string]: new () => Chit;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
function PlayerEditor({
|
|
24
|
+
function PlayerEditor({
|
|
25
|
+
playerId,
|
|
26
|
+
match,
|
|
27
|
+
onBack,
|
|
28
|
+
skipReplay,
|
|
29
|
+
}: {
|
|
30
|
+
onBack?: () => void;
|
|
31
|
+
playerId: string;
|
|
32
|
+
match: Match<any, any>;
|
|
33
|
+
skipReplay?: boolean;
|
|
34
|
+
}) {
|
|
22
35
|
const [localConnection, setLocalConnection] = useState<Connection | undefined>();
|
|
23
|
-
const [, setRemoteConnection] = useState<LocalConnectionTransport>(new LocalConnectionTransport());
|
|
24
36
|
|
|
25
37
|
useEffect(() => {
|
|
26
38
|
const newRemoteConnection = new LocalConnectionTransport();
|
|
@@ -29,7 +41,6 @@ function PlayerEditor({ playerId, match, showBack }: { showBack?: boolean; playe
|
|
|
29
41
|
match.connect(newRemoteConnection, playerId);
|
|
30
42
|
|
|
31
43
|
setLocalConnection(newConnection);
|
|
32
|
-
setRemoteConnection(newRemoteConnection);
|
|
33
44
|
return () => {
|
|
34
45
|
newConnection.dispose();
|
|
35
46
|
};
|
|
@@ -42,68 +53,160 @@ function PlayerEditor({ playerId, match, showBack }: { showBack?: boolean; playe
|
|
|
42
53
|
return (
|
|
43
54
|
<ConnectionProvider connection={localConnection}>
|
|
44
55
|
<PlayerProvider playerId={playerId}>
|
|
45
|
-
<MatchViewer
|
|
46
|
-
onBack={
|
|
47
|
-
showBack
|
|
48
|
-
? () => {
|
|
49
|
-
window.history.back();
|
|
50
|
-
}
|
|
51
|
-
: undefined
|
|
52
|
-
}
|
|
53
|
-
/>
|
|
56
|
+
<MatchViewer onBack={onBack} skipReplay={skipReplay} />
|
|
54
57
|
</PlayerProvider>
|
|
55
58
|
</ConnectionProvider>
|
|
56
59
|
);
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
export type DemoWrapperProps = {
|
|
63
|
+
game: Game<any, any>;
|
|
64
|
+
/**
|
|
65
|
+
* Run a tutorial: its id (looked up on `game.tutorials`, with `locale` when given) or the spec
|
|
66
|
+
* itself. Without one this is a plain demo game: the same match, no overlay.
|
|
67
|
+
*/
|
|
68
|
+
tutorial?: string | TutorialSpec<any, any>;
|
|
69
|
+
locale?: string;
|
|
70
|
+
/** Colour overrides for the overlay, on top of the game's and the spec's */
|
|
71
|
+
tutorialTheme?: Partial<TutorialTheme>;
|
|
72
|
+
onTutorialEvent?: (e: TutorialEvent) => void;
|
|
73
|
+
/** Shown as the back button; with a tutorial whose last step ends with "back", called when it finishes */
|
|
74
|
+
onBack?: () => void;
|
|
75
|
+
/** Panel load progress, as on `ClientTrustMatchViewer`: a host hides its loading screen when loaded equals created */
|
|
76
|
+
onLoadProgress?: LoadingStatesCallback;
|
|
77
|
+
/** Start the tutorial at this step (the Playground's "restart at step") */
|
|
78
|
+
startAt?: number;
|
|
79
|
+
/** Rendered alongside the match once it exists (the Playground's dev panel) */
|
|
80
|
+
children?: React.ReactNode;
|
|
81
|
+
};
|
|
61
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Runs a demo game in this tab: an ephemeral match with one human seat and a bot in every other
|
|
85
|
+
* seat. With `tutorial`, the same match runs the given script on top. A demo is a tutorial with no
|
|
86
|
+
* steps, so both go through `createDemoMatch`.
|
|
87
|
+
*/
|
|
88
|
+
export function DemoWrapper({
|
|
89
|
+
game,
|
|
90
|
+
tutorial,
|
|
91
|
+
locale,
|
|
92
|
+
tutorialTheme,
|
|
93
|
+
onTutorialEvent,
|
|
94
|
+
onBack,
|
|
95
|
+
onLoadProgress,
|
|
96
|
+
startAt = 0,
|
|
97
|
+
children,
|
|
98
|
+
}: DemoWrapperProps) {
|
|
99
|
+
const [loadingStates] = useState<LoadingStates>(new LoadingStates());
|
|
62
100
|
useEffect(() => {
|
|
63
|
-
|
|
101
|
+
if (onLoadProgress) {
|
|
102
|
+
return loadingStates.onChange(onLoadProgress);
|
|
103
|
+
}
|
|
104
|
+
}, [loadingStates, onLoadProgress]);
|
|
105
|
+
const [demo, setDemo] = useState<DemoMatch<any, any> | null>(null);
|
|
106
|
+
const demoRef = useRef<DemoMatch<any, any> | null>(null);
|
|
107
|
+
// Where the script (re)starts and whether it needs the Start tap: a rewind restarts at the step it
|
|
108
|
+
// went back to, without the tap
|
|
109
|
+
const [start] = useState<{ at: number; auto: boolean; paused: boolean }>({
|
|
110
|
+
at: startAt,
|
|
111
|
+
auto: false,
|
|
112
|
+
paused: false,
|
|
113
|
+
});
|
|
64
114
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
115
|
+
const spec = typeof tutorial === "string" ? findTutorial(game, tutorial, locale) : tutorial;
|
|
116
|
+
if (typeof tutorial === "string" && !spec) {
|
|
117
|
+
console.warn(`Tutorial "${tutorial}" not found on ${game.metadata.name}; running a plain demo`);
|
|
118
|
+
}
|
|
68
119
|
|
|
69
|
-
|
|
70
|
-
for (let i = 0; i < playerCount; i++) {
|
|
71
|
-
const player = new PlayerInfo(`p${i}`, i === 0 ? "Human" : `Robot ${i}`);
|
|
72
|
-
player.ai = i === 0 ? undefined : {};
|
|
73
|
-
players.push(player);
|
|
74
|
-
}
|
|
75
|
-
const match = new Match(game, players, storage, configOptions);
|
|
120
|
+
useEffect(() => {
|
|
76
121
|
let cancelled = false;
|
|
77
|
-
|
|
122
|
+
createDemoMatch(game, spec).then((d) => {
|
|
78
123
|
if (cancelled) {
|
|
124
|
+
d.match.dispose();
|
|
79
125
|
return;
|
|
80
126
|
}
|
|
81
|
-
match.
|
|
82
|
-
|
|
83
|
-
|
|
127
|
+
demoRef.current?.match.dispose();
|
|
128
|
+
demoRef.current = d;
|
|
129
|
+
d.match.start();
|
|
130
|
+
setDemo(d);
|
|
84
131
|
});
|
|
85
132
|
return () => {
|
|
86
|
-
match.dispose();
|
|
87
133
|
cancelled = true;
|
|
134
|
+
demoRef.current?.match.dispose();
|
|
135
|
+
demoRef.current = null;
|
|
88
136
|
};
|
|
137
|
+
}, [game, spec]);
|
|
138
|
+
|
|
139
|
+
// Back in a tutorial: put the match back to the snapshot taken when that step went live. The
|
|
140
|
+
// match reruns from it in place (saved decisions replay deterministically; the pinned draws and
|
|
141
|
+
// forced moves rewind with it) and the viewer animates to the old board without remounting.
|
|
142
|
+
const snapshot = useCallback(() => JSON.parse(JSON.stringify(demoRef.current?.match.state ?? {})), []);
|
|
143
|
+
// Skipping ahead (the dev panel) goes the same way: a step not played yet is played headlessly
|
|
144
|
+
// first, and this match takes that run's snapshots, so Back works from wherever it lands.
|
|
145
|
+
const specRef = useRef(spec);
|
|
146
|
+
specRef.current = spec;
|
|
147
|
+
const rewind = useCallback(async (stepId: string) => {
|
|
148
|
+
const current = demoRef.current;
|
|
149
|
+
if (!current) return false;
|
|
150
|
+
if (!current.runtime.hasSnapshot(stepId) && specRef.current) {
|
|
151
|
+
const T0 = performance.now();
|
|
152
|
+
const run = await runTutorial(game, specRef.current, { until: stepId, stepTimeoutMs: 5000 });
|
|
153
|
+
console.info("ZZTIME headless", Math.round(performance.now() - T0));
|
|
154
|
+
if (demoRef.current !== current) return false;
|
|
155
|
+
if (!run.runtime.hasSnapshot(stepId)) {
|
|
156
|
+
console.warn(
|
|
157
|
+
`[tutorial ${specRef.current.id}] could not play ahead to "${stepId}": ${run.error ?? `stuck on "${run.stuckOn}"`}`,
|
|
158
|
+
);
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
current.runtime.adoptSnapshots(run.runtime);
|
|
162
|
+
}
|
|
163
|
+
const state = current.runtime.restoreSnapshot(stepId);
|
|
164
|
+
if (state === undefined) return false;
|
|
165
|
+
await current.replaceState(state);
|
|
166
|
+
return true;
|
|
89
167
|
}, [game]);
|
|
90
168
|
|
|
91
|
-
if (!
|
|
169
|
+
if (!demo) {
|
|
92
170
|
return null;
|
|
93
171
|
}
|
|
94
172
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
173
|
+
const onFinished = (e: TutorialEvent) => {
|
|
174
|
+
onTutorialEvent?.(e);
|
|
175
|
+
if (e.type === "completed" && e.end === "back") {
|
|
176
|
+
onBack?.();
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const viewer = (
|
|
181
|
+
<PlayerEditor key={demo.key} playerId={demo.playerId} match={demo.match} onBack={onBack} skipReplay={start.auto} />
|
|
99
182
|
);
|
|
100
|
-
}
|
|
101
183
|
|
|
102
|
-
export function DemoWrapper({ game }: { game: Game<any, any> }) {
|
|
103
|
-
const [loadingStates] = useState<LoadingStates>(new LoadingStates());
|
|
104
184
|
return (
|
|
105
185
|
<LoadingStateProvider loadingStates={loadingStates}>
|
|
106
|
-
<
|
|
186
|
+
<GameProvider game={game}>
|
|
187
|
+
{spec && spec.steps.length > 0 ? (
|
|
188
|
+
<TutorialProvider
|
|
189
|
+
spec={spec}
|
|
190
|
+
runtime={demo.runtime}
|
|
191
|
+
themeOverrides={tutorialTheme}
|
|
192
|
+
ai={demo.match.ai}
|
|
193
|
+
onEvent={onFinished}
|
|
194
|
+
startAt={start.at}
|
|
195
|
+
autoStart={start.auto}
|
|
196
|
+
startPaused={start.paused}
|
|
197
|
+
snapshot={snapshot}
|
|
198
|
+
rewind={rewind}
|
|
199
|
+
>
|
|
200
|
+
{viewer}
|
|
201
|
+
{children}
|
|
202
|
+
</TutorialProvider>
|
|
203
|
+
) : (
|
|
204
|
+
<>
|
|
205
|
+
{viewer}
|
|
206
|
+
{children}
|
|
207
|
+
</>
|
|
208
|
+
)}
|
|
209
|
+
</GameProvider>
|
|
107
210
|
</LoadingStateProvider>
|
|
108
211
|
);
|
|
109
212
|
}
|
|
@@ -46,6 +46,7 @@ export function FullScreenGalleryDisplay() {
|
|
|
46
46
|
<GameModalBackdrop visible={!!hasItems}>
|
|
47
47
|
{source?.inlineGallerySize && (
|
|
48
48
|
<IconButton
|
|
49
|
+
data-tutorial-target="gallery:toInline"
|
|
49
50
|
sx={{
|
|
50
51
|
backgroundColor: theme.inlineGalleryButtonBackgroundColor,
|
|
51
52
|
position: "absolute",
|
|
@@ -64,6 +65,8 @@ export function FullScreenGalleryDisplay() {
|
|
|
64
65
|
</IconButton>
|
|
65
66
|
)}
|
|
66
67
|
<GalleryViewer
|
|
68
|
+
kind="fullscreen"
|
|
69
|
+
tutorialTarget="gallery:fullscreen"
|
|
67
70
|
onClose={() => {
|
|
68
71
|
setSource(undefined);
|
|
69
72
|
}}
|
|
@@ -76,6 +76,17 @@ export class BuiltItem {
|
|
|
76
76
|
return this.summaryHeight;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/** The item's mesh in world space (its summary text excluded), for pointing at it */
|
|
80
|
+
worldBox(): Box3 {
|
|
81
|
+
this.group.updateWorldMatrix(true, true);
|
|
82
|
+
return new Box3().setFromObject(this.mesh);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** False while the item is sliding in or out */
|
|
86
|
+
get settled() {
|
|
87
|
+
return !this.removing && this.enteredAmount >= 1;
|
|
88
|
+
}
|
|
89
|
+
|
|
79
90
|
public raycastHitsItem(camera: Camera, x: number, y: number): boolean {
|
|
80
91
|
const { w, h } = this.layoutManager.getDimensions();
|
|
81
92
|
const ndc = new Vector3((x / w) * 2 - 1, -(y / h) * 2 + 1, 0.5);
|
|
@@ -327,12 +338,13 @@ export class BuiltItem {
|
|
|
327
338
|
};
|
|
328
339
|
}
|
|
329
340
|
|
|
330
|
-
private
|
|
341
|
+
private _lastSummaryMeshKey = "";
|
|
331
342
|
private checkRecreateSummaryMesh() {
|
|
332
|
-
const { w
|
|
333
|
-
|
|
343
|
+
const { w, maxHeight } = this.layoutManager.getSummaryDimensions();
|
|
344
|
+
const key = `${w}x${maxHeight}`;
|
|
345
|
+
if (this._lastSummaryMeshKey !== key) {
|
|
334
346
|
this.createHelpText();
|
|
335
|
-
this.
|
|
347
|
+
this._lastSummaryMeshKey = key;
|
|
336
348
|
}
|
|
337
349
|
}
|
|
338
350
|
|
|
@@ -364,7 +376,8 @@ export class BuiltItem {
|
|
|
364
376
|
}
|
|
365
377
|
|
|
366
378
|
private createSummaryMesh(summary: string, specs: RichTextRenderOptionsParameters): Mesh {
|
|
367
|
-
const {
|
|
379
|
+
const { h: itemHeight } = this.layoutManager.getItemDimensions();
|
|
380
|
+
const { w: summaryWidth, maxHeight: summaryMaxHeight } = this.layoutManager.getSummaryDimensions();
|
|
368
381
|
const pad =
|
|
369
382
|
this.layoutManager.getSummaryMode() === "full"
|
|
370
383
|
? this.theme.spacing * window.devicePixelRatio
|
|
@@ -380,12 +393,12 @@ export class BuiltItem {
|
|
|
380
393
|
const height = itemHeight * 2; // arbitrary large height to allow text to flow
|
|
381
394
|
|
|
382
395
|
// First pass: render with full height to let text flow and calculate actual size
|
|
383
|
-
const stack1 = new CanvasStack(
|
|
396
|
+
const stack1 = new CanvasStack(summaryWidth * window.devicePixelRatio, height * window.devicePixelRatio, ops);
|
|
384
397
|
stack1.render();
|
|
385
398
|
stack1.dispose();
|
|
386
399
|
|
|
387
400
|
// Second pass: render with actual measured height for final material
|
|
388
|
-
const stack2 = new CanvasStack(
|
|
401
|
+
const stack2 = new CanvasStack(summaryWidth * window.devicePixelRatio, markdown.height + pad * 2, ops);
|
|
389
402
|
stack2.render();
|
|
390
403
|
|
|
391
404
|
const material = stack2.material;
|
|
@@ -393,10 +406,18 @@ export class BuiltItem {
|
|
|
393
406
|
material.depthWrite = true;
|
|
394
407
|
|
|
395
408
|
const finalHeight = stack2.height / window.devicePixelRatio;
|
|
396
|
-
this.summaryHeight = finalHeight;
|
|
397
409
|
|
|
398
|
-
const geometry = new PlaneGeometry(
|
|
410
|
+
const geometry = new PlaneGeometry(summaryWidth, finalHeight);
|
|
399
411
|
const mesh = new Mesh(geometry, material);
|
|
412
|
+
|
|
413
|
+
// Too long to fit even at full width: shrink it rather than crowd out the item
|
|
414
|
+
if (summaryMaxHeight > 0 && finalHeight > summaryMaxHeight) {
|
|
415
|
+
const scale = summaryMaxHeight / finalHeight;
|
|
416
|
+
mesh.scale.set(scale, scale, 1);
|
|
417
|
+
this.summaryHeight = summaryMaxHeight;
|
|
418
|
+
} else {
|
|
419
|
+
this.summaryHeight = finalHeight;
|
|
420
|
+
}
|
|
400
421
|
return mesh;
|
|
401
422
|
}
|
|
402
423
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Object3D } from "three";
|
|
1
|
+
import { Object3D, Vector3 } from "three";
|
|
2
2
|
import { GameTheme } from "../../game/GameTheme";
|
|
3
3
|
import { SceneWrapper } from "../../rendering/outline";
|
|
4
4
|
import { TextureReferenceCounterRootGroup } from "../../rendering/TextureReferenceCounter";
|
|
@@ -97,6 +97,77 @@ export class GalleryController implements TextureReferenceCounterRootGroup {
|
|
|
97
97
|
return item.getGalleryItem();
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/** The built item showing `matches` (by its gallery item) */
|
|
101
|
+
private findItem(matches: (item: GalleryItem) => boolean): BuiltItem | undefined {
|
|
102
|
+
return this.items.find((b) => matches(b.getGalleryItem()));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Ids of the gallery items currently shown (chit ids for items built from chits) */
|
|
106
|
+
itemIds(): string[] {
|
|
107
|
+
return this.items.map((b) => b.id);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The gallery items currently shown */
|
|
111
|
+
galleryItems(): GalleryItem[] {
|
|
112
|
+
return this.items.map((b) => b.getGalleryItem());
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Where an item is drawn, in the canvas's CSS pixels: a rect when it is on screen, "offscreen"
|
|
117
|
+
* when it is scrolled out of view, undefined when no item matches.
|
|
118
|
+
*/
|
|
119
|
+
locateItem(
|
|
120
|
+
matches: (item: GalleryItem) => boolean,
|
|
121
|
+
): { left: number; top: number; right: number; bottom: number } | "offscreen" | undefined {
|
|
122
|
+
const built = this.findItem(matches);
|
|
123
|
+
if (!built || !built.settled) return undefined;
|
|
124
|
+
const box = built.worldBox();
|
|
125
|
+
if (box.isEmpty()) return undefined;
|
|
126
|
+
const { w, h } = this.layoutManager.getDimensions();
|
|
127
|
+
const camera = this.cameraManager.camera;
|
|
128
|
+
camera.updateMatrixWorld();
|
|
129
|
+
let left = Infinity,
|
|
130
|
+
top = Infinity,
|
|
131
|
+
right = -Infinity,
|
|
132
|
+
bottom = -Infinity;
|
|
133
|
+
for (const x of [box.min.x, box.max.x]) {
|
|
134
|
+
for (const y of [box.min.y, box.max.y]) {
|
|
135
|
+
for (const z of [box.min.z, box.max.z]) {
|
|
136
|
+
const p = new Vector3(x, y, z).project(camera);
|
|
137
|
+
const px = ((p.x + 1) / 2) * w;
|
|
138
|
+
const py = ((1 - p.y) / 2) * h;
|
|
139
|
+
left = Math.min(left, px);
|
|
140
|
+
right = Math.max(right, px);
|
|
141
|
+
top = Math.min(top, py);
|
|
142
|
+
bottom = Math.max(bottom, py);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Mostly out of the visible strip: it needs scrolling into view first
|
|
147
|
+
const visible = Math.max(0, Math.min(right, w) - Math.max(left, 0));
|
|
148
|
+
if (visible < (right - left) * 0.6) return "offscreen";
|
|
149
|
+
return {
|
|
150
|
+
left: Math.max(0, left),
|
|
151
|
+
top: Math.max(0, top),
|
|
152
|
+
right: Math.min(w, right),
|
|
153
|
+
bottom: Math.min(h, bottom),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Pans (animated) so the matching item is on screen, roughly centred */
|
|
158
|
+
scrollToItem(matches: (item: GalleryItem) => boolean) {
|
|
159
|
+
const built = this.findItem(matches);
|
|
160
|
+
if (!built) return;
|
|
161
|
+
const { itemsPerPage, itemSpacing } = this.layoutManager.getStageDimensions();
|
|
162
|
+
const { w: itemWidth } = this.layoutManager.getItemDimensions();
|
|
163
|
+
const step = itemWidth + itemSpacing;
|
|
164
|
+
const firstVisible = -this.animationController.getOffsetX() / step;
|
|
165
|
+
const index = Math.round(built.getIndex());
|
|
166
|
+
if (index >= firstVisible && index <= firstVisible + itemsPerPage - 1) return;
|
|
167
|
+
const target = -(index - Math.floor((itemsPerPage - 1) / 2)) * step;
|
|
168
|
+
this.pan(target - this.animationController.getOffsetX(), true);
|
|
169
|
+
}
|
|
170
|
+
|
|
100
171
|
render(): boolean {
|
|
101
172
|
// Item rebuilds (and other paths) only mark the scene wrapper dirty; honor
|
|
102
173
|
// that here the same way RootChitRenderInstance does so the canvas repaints.
|
|
@@ -10,6 +10,9 @@ import { requestSharedAnimationFrame } from "../../utilities/RequestSharedAnimat
|
|
|
10
10
|
import { TextureReferenceCounter } from "../../rendering/TextureReferenceCounter";
|
|
11
11
|
import { GalleryController } from "./GalleryController";
|
|
12
12
|
import { GalleryItem, SummaryMode } from "./types";
|
|
13
|
+
import { GalleryKind, galleryRegistry } from "./registry";
|
|
14
|
+
import { Chit } from "../../game/Chit";
|
|
15
|
+
import { ChitGalleryItemInstance } from "../../rendering/ChitGalleryItemInstance";
|
|
13
16
|
import {
|
|
14
17
|
DEFAULT_TWEEN_DURATION,
|
|
15
18
|
DEFAULT_FOV,
|
|
@@ -39,6 +42,20 @@ export interface GalleryViewerProps {
|
|
|
39
42
|
onLongPress?: () => void;
|
|
40
43
|
showSummary?: SummaryMode;
|
|
41
44
|
zFactor?: number;
|
|
45
|
+
/** Lets tutorials find and point at this gallery's items (see `galleryRegistry`) */
|
|
46
|
+
kind?: GalleryKind;
|
|
47
|
+
/** `data-tutorial-target` for the gallery area */
|
|
48
|
+
tutorialTarget?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Whether a gallery item shows `chit`: the item is that chit, or (galleries merge identical chits into
|
|
53
|
+
* one "2x" item) an identical one.
|
|
54
|
+
*/
|
|
55
|
+
function itemShows(item: GalleryItem, chit: Chit) {
|
|
56
|
+
if (item.id === chit.id) return true;
|
|
57
|
+
const shown = (item as ChitGalleryItemInstance).chit;
|
|
58
|
+
return shown instanceof Chit && shown !== chit && shown.functionallyIdentical(chit);
|
|
42
59
|
}
|
|
43
60
|
|
|
44
61
|
export function GalleryViewer({
|
|
@@ -56,6 +73,8 @@ export function GalleryViewer({
|
|
|
56
73
|
galleryItemHeight = h * 0.7,
|
|
57
74
|
showSummary = "full",
|
|
58
75
|
zFactor = DEFAULT_Z_FACTOR,
|
|
76
|
+
kind,
|
|
77
|
+
tutorialTarget,
|
|
59
78
|
}: GalleryViewerProps) {
|
|
60
79
|
const calcedItemWidth =
|
|
61
80
|
items.length > 0 ? Math.min(...items.map((item) => item.preferredWidth ?? galleryItemWidth)) : galleryItemWidth;
|
|
@@ -71,6 +90,17 @@ export function GalleryViewer({
|
|
|
71
90
|
galleryController.setTweenDuration(tweenDuration);
|
|
72
91
|
galleryController.showSummary = showSummary;
|
|
73
92
|
|
|
93
|
+
// Must run before the effects below build items: each build sweeps unused textures, and the gallery's clones
|
|
94
|
+
// only count as used once it's registered.
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
TextureReferenceCounter.registerInstance(galleryController);
|
|
97
|
+
return () => {
|
|
98
|
+
galleryController.destroy();
|
|
99
|
+
TextureReferenceCounter.unregisterInstance(galleryController);
|
|
100
|
+
galleryController.sceneWrapper.dispose();
|
|
101
|
+
};
|
|
102
|
+
}, [galleryController]);
|
|
103
|
+
|
|
74
104
|
// Single effect to handle both size and items changes
|
|
75
105
|
useEffect(() => {
|
|
76
106
|
if (!w || !h || !Number.isFinite(calcedItemHeight) || !Number.isFinite(calcedItemWidth)) {
|
|
@@ -89,6 +119,29 @@ export function GalleryViewer({
|
|
|
89
119
|
});
|
|
90
120
|
}, [calcedItemWidth, itemSpacing, calcedItemHeight, w, h, galleryController, zFactor]);
|
|
91
121
|
|
|
122
|
+
// Tell tutorials where this gallery's items are
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
const canvas = refContainer.current;
|
|
125
|
+
if (!kind || !canvas) return;
|
|
126
|
+
return galleryRegistry.register({
|
|
127
|
+
kind,
|
|
128
|
+
element: canvas,
|
|
129
|
+
chitIds: () => galleryController.itemIds(),
|
|
130
|
+
locate: (chit) => {
|
|
131
|
+
const exact = galleryController.locateItem((item) => item.id === chit.id);
|
|
132
|
+
const found = exact ?? galleryController.locateItem((item) => itemShows(item, chit));
|
|
133
|
+
if (!found || found === "offscreen") return found;
|
|
134
|
+
const r = canvas.getBoundingClientRect();
|
|
135
|
+
return { left: r.left + found.left, top: r.top + found.top, right: r.left + found.right, bottom: r.top + found.bottom };
|
|
136
|
+
},
|
|
137
|
+
scrollTo: (chit) => {
|
|
138
|
+
const hasExact = galleryController.itemIds().includes(chit.id ?? "");
|
|
139
|
+
galleryController.scrollToItem((item) => (hasExact ? item.id === chit.id : itemShows(item, chit)));
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
// the canvas exists only once w and h are known
|
|
143
|
+
}, [kind, galleryController, w, h]);
|
|
144
|
+
|
|
92
145
|
useEffect(() => {
|
|
93
146
|
galleryController.setItems(items);
|
|
94
147
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -204,21 +257,12 @@ export function GalleryViewer({
|
|
|
204
257
|
};
|
|
205
258
|
}, [galleryController, onClose, onLongPress]);
|
|
206
259
|
|
|
207
|
-
useEffect(() => {
|
|
208
|
-
TextureReferenceCounter.registerInstance(galleryController);
|
|
209
|
-
return () => {
|
|
210
|
-
galleryController.destroy();
|
|
211
|
-
TextureReferenceCounter.unregisterInstance(galleryController);
|
|
212
|
-
galleryController.sceneWrapper.dispose();
|
|
213
|
-
};
|
|
214
|
-
}, [galleryController]);
|
|
215
|
-
|
|
216
260
|
if (!w || !h) {
|
|
217
261
|
return null;
|
|
218
262
|
}
|
|
219
263
|
|
|
220
264
|
return (
|
|
221
|
-
<Box sx={{ position: "absolute", top: 0, right: 0, left: 0, bottom: 0 }}>
|
|
265
|
+
<Box data-tutorial-target={tutorialTarget} sx={{ position: "absolute", top: 0, right: 0, left: 0, bottom: 0 }}>
|
|
222
266
|
<canvas
|
|
223
267
|
width={w * rendererWrapper.pixelRatio}
|
|
224
268
|
height={h * rendererWrapper.pixelRatio}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GameTheme } from "../../game/GameTheme";
|
|
2
2
|
import { SummaryMode } from "./types";
|
|
3
|
+
import { MIN_ITEM_HEIGHT_FRACTION, SINGLE_ITEM_SUMMARY_MAX_WIDTH } from "./constants";
|
|
3
4
|
|
|
4
5
|
export class LayoutManager {
|
|
5
6
|
// Dimensions (all scaled)
|
|
@@ -24,6 +25,8 @@ export class LayoutManager {
|
|
|
24
25
|
// summary info
|
|
25
26
|
private summaryMode: SummaryMode = "full";
|
|
26
27
|
private summaryMaxHeight = 0;
|
|
28
|
+
private summaryWidth = 100;
|
|
29
|
+
private summaryHeightLimit = 0;
|
|
27
30
|
|
|
28
31
|
public dirty = false;
|
|
29
32
|
|
|
@@ -69,6 +72,10 @@ export class LayoutManager {
|
|
|
69
72
|
return { w: this.itemWidth, h: this.itemHeight, summaryMaxHeight: this.summaryMaxHeight };
|
|
70
73
|
}
|
|
71
74
|
|
|
75
|
+
getSummaryDimensions() {
|
|
76
|
+
return { w: this.summaryWidth, maxHeight: this.summaryHeightLimit };
|
|
77
|
+
}
|
|
78
|
+
|
|
72
79
|
getStageDimensions() {
|
|
73
80
|
return { frontStageWidth: this.frontStageWidth, itemsPerPage: this.itemsPerPage, itemSpacing: this.itemSpacing };
|
|
74
81
|
}
|
|
@@ -117,16 +124,14 @@ export class LayoutManager {
|
|
|
117
124
|
}
|
|
118
125
|
|
|
119
126
|
recalculateEffectiveItemDimensions() {
|
|
120
|
-
// recalcs itemWidth,itemHeight,itemsPerPage and
|
|
127
|
+
// recalcs itemWidth,itemHeight,itemsPerPage,frontStageWidth and the summary bounds
|
|
121
128
|
|
|
122
129
|
let itemWidth = this.itemPreferredWidth ?? this.baseItemWidth;
|
|
123
130
|
let itemHeight = this.itemPreferredHeight ?? this.baseItemHeight;
|
|
124
131
|
const aspectRatio = itemWidth / itemHeight;
|
|
125
132
|
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
this.h - this.itemSpacing * 2 - this.summaryMaxHeight,
|
|
129
|
-
);
|
|
133
|
+
const availableHeight = this.h - this.itemSpacing * 2;
|
|
134
|
+
const maxItemHeight = Math.max(this.theme.galleryItemMinimumHeight, availableHeight);
|
|
130
135
|
const maxItemWidth = Math.max(this.theme.galleryItemMinimumWidth, this.w - this.itemSpacing * 2);
|
|
131
136
|
|
|
132
137
|
if (itemHeight > maxItemHeight) {
|
|
@@ -140,6 +145,21 @@ export class LayoutManager {
|
|
|
140
145
|
|
|
141
146
|
itemWidth = Math.max(this.theme.galleryItemMinimumWidth, itemWidth);
|
|
142
147
|
|
|
148
|
+
// The summary takes its height from the item, and the item keeps its shape, so the slot (and the summary laid out
|
|
149
|
+
// at its width) stays as wide as the item actually draws. A narrower summary can wrap taller and shrink the item
|
|
150
|
+
// again, but only down to the height floor, so the layout settles instead of collapsing.
|
|
151
|
+
const itemHeightFloor = Math.max(
|
|
152
|
+
this.theme.galleryItemMinimumHeight,
|
|
153
|
+
Math.min(itemHeight, availableHeight * MIN_ITEM_HEIGHT_FRACTION),
|
|
154
|
+
);
|
|
155
|
+
const summaryHeightLimit = Math.max(0, availableHeight - itemHeightFloor);
|
|
156
|
+
itemHeight = Math.max(itemHeightFloor, Math.min(itemHeight, availableHeight - this.summaryMaxHeight));
|
|
157
|
+
itemWidth = Math.max(this.theme.galleryItemMinimumWidth, itemHeight * aspectRatio);
|
|
158
|
+
|
|
159
|
+
// A lone item has the stage to itself, so its summary can spread out instead of stacking into a tall column.
|
|
160
|
+
const summaryWidth =
|
|
161
|
+
this.itemCount === 1 ? Math.max(itemWidth, Math.min(maxItemWidth, SINGLE_ITEM_SUMMARY_MAX_WIDTH)) : itemWidth;
|
|
162
|
+
|
|
143
163
|
const itemsPerPage = Math.max(
|
|
144
164
|
1,
|
|
145
165
|
Math.min(this.itemCount, Math.floor((this.w - this.itemSpacing * 2) / (itemWidth + this.itemSpacing))),
|
|
@@ -150,12 +170,16 @@ export class LayoutManager {
|
|
|
150
170
|
this.itemHeight !== itemHeight ||
|
|
151
171
|
this.itemWidth !== itemWidth ||
|
|
152
172
|
this.itemsPerPage !== itemsPerPage ||
|
|
153
|
-
this.frontStageWidth !== frontStageWidth
|
|
173
|
+
this.frontStageWidth !== frontStageWidth ||
|
|
174
|
+
this.summaryWidth !== summaryWidth ||
|
|
175
|
+
this.summaryHeightLimit !== summaryHeightLimit
|
|
154
176
|
) {
|
|
155
177
|
this.itemHeight = itemHeight;
|
|
156
178
|
this.itemWidth = itemWidth;
|
|
157
179
|
this.itemsPerPage = itemsPerPage;
|
|
158
180
|
this.frontStageWidth = frontStageWidth;
|
|
181
|
+
this.summaryWidth = summaryWidth;
|
|
182
|
+
this.summaryHeightLimit = summaryHeightLimit;
|
|
159
183
|
this.dirty = true;
|
|
160
184
|
}
|
|
161
185
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Chit } from "../../game/Chit";
|
|
2
|
+
|
|
3
|
+
/** Which gallery: the strip above the log, the full-screen one, or the small one in the prompt bar */
|
|
4
|
+
export type GalleryKind = "inline" | "fullscreen" | "context";
|
|
5
|
+
|
|
6
|
+
/** A page-space rectangle (CSS px, like getBoundingClientRect) */
|
|
7
|
+
export type GalleryRect = { left: number; top: number; right: number; bottom: number };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* An open gallery, as the tutorial overlay sees it: where a chit's item is on screen, and how to bring
|
|
11
|
+
* an item into view. Registered by `GalleryViewer` when given a `kind`.
|
|
12
|
+
*/
|
|
13
|
+
export interface RegisteredGallery {
|
|
14
|
+
kind: GalleryKind;
|
|
15
|
+
/** The gallery's canvas, used to tell which viewer (and so which player) the gallery belongs to */
|
|
16
|
+
element: HTMLElement;
|
|
17
|
+
/**
|
|
18
|
+
* Where the item showing this chit is: a rect when it is on screen, "offscreen" when the gallery has
|
|
19
|
+
* the item but it is scrolled out of view, undefined when the gallery does not show it.
|
|
20
|
+
*/
|
|
21
|
+
locate(chit: Chit): GalleryRect | "offscreen" | undefined;
|
|
22
|
+
/** Scrolls the gallery so the item showing this chit is in view */
|
|
23
|
+
scrollTo(chit: Chit): void;
|
|
24
|
+
/** Ids of the chits whose items the gallery shows */
|
|
25
|
+
chitIds(): string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const galleries = new Set<RegisteredGallery>();
|
|
29
|
+
|
|
30
|
+
export const galleryRegistry = {
|
|
31
|
+
register(gallery: RegisteredGallery) {
|
|
32
|
+
galleries.add(gallery);
|
|
33
|
+
return () => {
|
|
34
|
+
galleries.delete(gallery);
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
/** Open galleries inside `scope` (a viewer's root element), full-screen first, then inline, then context */
|
|
38
|
+
list(scope?: ParentNode | null): RegisteredGallery[] {
|
|
39
|
+
const order: GalleryKind[] = ["fullscreen", "inline", "context"];
|
|
40
|
+
return [...galleries]
|
|
41
|
+
.filter((g) => !scope || (scope as Node).contains(g.element))
|
|
42
|
+
.sort((a, b) => order.indexOf(a.kind) - order.indexOf(b.kind));
|
|
43
|
+
},
|
|
44
|
+
};
|