@pretty-chitty/core 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/dist/components/DemoWrapper.d.ts +4 -1
  2. package/dist/components/DemoWrapper.d.ts.map +1 -1
  3. package/dist/components/DemoWrapper.js +2 -4
  4. package/dist/components/DemoWrapper.js.map +1 -1
  5. package/dist/components/Gallery/BuiltItem.d.ts +10 -0
  6. package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
  7. package/dist/components/Gallery/BuiltItem.js +65 -8
  8. package/dist/components/Gallery/BuiltItem.js.map +1 -1
  9. package/dist/components/Gallery/GalleryController.d.ts +8 -0
  10. package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
  11. package/dist/components/Gallery/GalleryController.js +39 -6
  12. package/dist/components/Gallery/GalleryController.js.map +1 -1
  13. package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -1
  14. package/dist/components/Gallery/GalleryViewer.js +91 -2
  15. package/dist/components/Gallery/GalleryViewer.js.map +1 -1
  16. package/dist/components/Gallery/LayoutManager.d.ts +4 -0
  17. package/dist/components/Gallery/LayoutManager.d.ts.map +1 -1
  18. package/dist/components/Gallery/LayoutManager.js +36 -10
  19. package/dist/components/Gallery/LayoutManager.js.map +1 -1
  20. package/dist/components/Gallery/constants.d.ts +5 -1
  21. package/dist/components/Gallery/constants.d.ts.map +1 -1
  22. package/dist/components/Gallery/constants.js +5 -1
  23. package/dist/components/Gallery/constants.js.map +1 -1
  24. package/dist/components/Gallery/types.d.ts +5 -0
  25. package/dist/components/Gallery/types.d.ts.map +1 -1
  26. package/dist/components/GameDesigner.d.ts.map +1 -1
  27. package/dist/components/GameDesigner.js +45 -3
  28. package/dist/components/GameDesigner.js.map +1 -1
  29. package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
  30. package/dist/components/InlineGalleryDisplay.js +33 -6
  31. package/dist/components/InlineGalleryDisplay.js.map +1 -1
  32. package/dist/components/Panel/ExternalDrag.d.ts +30 -0
  33. package/dist/components/Panel/ExternalDrag.d.ts.map +1 -0
  34. package/dist/components/Panel/ExternalDrag.js +87 -0
  35. package/dist/components/Panel/ExternalDrag.js.map +1 -0
  36. package/dist/components/Panel/PanelContents.d.ts +3 -0
  37. package/dist/components/Panel/PanelContents.d.ts.map +1 -1
  38. package/dist/components/Panel/PanelContents.js +24 -0
  39. package/dist/components/Panel/PanelContents.js.map +1 -1
  40. package/dist/components/PanelSpark.d.ts.map +1 -1
  41. package/dist/components/PanelSpark.js +3 -1
  42. package/dist/components/PanelSpark.js.map +1 -1
  43. package/dist/components/TopBar.d.ts.map +1 -1
  44. package/dist/components/TopBar.js +3 -1
  45. package/dist/components/TopBar.js.map +1 -1
  46. package/dist/components/TopBarPlayers.d.ts.map +1 -1
  47. package/dist/components/TopBarPlayers.js +1 -1
  48. package/dist/components/TopBarPlayers.js.map +1 -1
  49. package/dist/components/Tutorial/TutorialOverlay.js +17 -2
  50. package/dist/components/Tutorial/TutorialOverlay.js.map +1 -1
  51. package/dist/components/Viewer.d.ts.map +1 -1
  52. package/dist/components/Viewer.js +1 -0
  53. package/dist/components/Viewer.js.map +1 -1
  54. package/dist/game/Chit.d.ts +3 -1
  55. package/dist/game/Chit.d.ts.map +1 -1
  56. package/dist/game/Chit.js +4 -1
  57. package/dist/game/Chit.js.map +1 -1
  58. package/dist/game/GalleryItemChitChildrenSource.d.ts +1 -0
  59. package/dist/game/GalleryItemChitChildrenSource.d.ts.map +1 -1
  60. package/dist/game/GalleryItemChitChildrenSource.js +1 -0
  61. package/dist/game/GalleryItemChitChildrenSource.js.map +1 -1
  62. package/dist/game/GalleryItemRawSource.d.ts +1 -0
  63. package/dist/game/GalleryItemRawSource.d.ts.map +1 -1
  64. package/dist/game/GalleryItemRawSource.js +1 -0
  65. package/dist/game/GalleryItemRawSource.js.map +1 -1
  66. package/dist/game/GameButton.d.ts +8 -0
  67. package/dist/game/GameButton.d.ts.map +1 -1
  68. package/dist/game/GameButton.js +13 -1
  69. package/dist/game/GameButton.js.map +1 -1
  70. package/dist/game/ModalState.d.ts +3 -0
  71. package/dist/game/ModalState.d.ts.map +1 -1
  72. package/dist/game/ModalState.js +2 -0
  73. package/dist/game/ModalState.js.map +1 -1
  74. package/dist/game/Pick.d.ts.map +1 -1
  75. package/dist/game/Pick.js +1 -3
  76. package/dist/game/Pick.js.map +1 -1
  77. package/dist/game/PlayerPromptStatusChit.d.ts.map +1 -1
  78. package/dist/game/PlayerPromptStatusChit.js +1 -3
  79. package/dist/game/PlayerPromptStatusChit.js.map +1 -1
  80. package/dist/game/Prompt.d.ts +3 -1
  81. package/dist/game/Prompt.d.ts.map +1 -1
  82. package/dist/game/Prompt.js +15 -3
  83. package/dist/game/Prompt.js.map +1 -1
  84. package/dist/game/SparkChit.d.ts +6 -0
  85. package/dist/game/SparkChit.d.ts.map +1 -1
  86. package/dist/game/SparkChit.js +8 -0
  87. package/dist/game/SparkChit.js.map +1 -1
  88. package/dist/game/Turn.d.ts +2 -2
  89. package/dist/game/Turn.d.ts.map +1 -1
  90. package/dist/game/Turn.js +6 -9
  91. package/dist/game/Turn.js.map +1 -1
  92. package/dist/game/clientTransport/ClientPrompts.d.ts +2 -0
  93. package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
  94. package/dist/game/clientTransport/ClientPrompts.js +42 -4
  95. package/dist/game/clientTransport/ClientPrompts.js.map +1 -1
  96. package/dist/game/clientTransport/ClientTime.d.ts.map +1 -1
  97. package/dist/game/clientTransport/ClientTime.js +20 -1
  98. package/dist/game/clientTransport/ClientTime.js.map +1 -1
  99. package/dist/game/tutorial/TutorialController.d.ts +9 -1
  100. package/dist/game/tutorial/TutorialController.d.ts.map +1 -1
  101. package/dist/game/tutorial/TutorialController.js +21 -8
  102. package/dist/game/tutorial/TutorialController.js.map +1 -1
  103. package/dist/game/tutorial/runTutorial.d.ts +3 -2
  104. package/dist/game/tutorial/runTutorial.d.ts.map +1 -1
  105. package/dist/game/tutorial/runTutorial.js +28 -8
  106. package/dist/game/tutorial/runTutorial.js.map +1 -1
  107. package/dist/hooks/useTimeController.d.ts +2 -0
  108. package/dist/hooks/useTimeController.d.ts.map +1 -1
  109. package/dist/hooks/useTimeController.js +4 -0
  110. package/dist/hooks/useTimeController.js.map +1 -1
  111. package/dist/hooks/useTutorial.d.ts +4 -1
  112. package/dist/hooks/useTutorial.d.ts.map +1 -1
  113. package/dist/hooks/useTutorial.js +2 -2
  114. package/dist/hooks/useTutorial.js.map +1 -1
  115. package/dist/index.d.ts +1 -0
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js.map +1 -1
  118. package/dist/rendering/ChitGalleryItemInstance.d.ts +13 -3
  119. package/dist/rendering/ChitGalleryItemInstance.d.ts.map +1 -1
  120. package/dist/rendering/ChitGalleryItemInstance.js +17 -1
  121. package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
  122. package/dist/rendering/ChitRenderInstance.d.ts +6 -0
  123. package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
  124. package/dist/rendering/ChitRenderInstance.js +21 -4
  125. package/dist/rendering/ChitRenderInstance.js.map +1 -1
  126. package/dist/rendering/LightWrapper.d.ts.map +1 -1
  127. package/dist/rendering/LightWrapper.js +10 -1
  128. package/dist/rendering/LightWrapper.js.map +1 -1
  129. package/dist/rendering/Splay.d.ts +11 -0
  130. package/dist/rendering/Splay.d.ts.map +1 -1
  131. package/dist/rendering/Splay.js +20 -10
  132. package/dist/rendering/Splay.js.map +1 -1
  133. package/dist/utilities/CanvasStack/RichTextRenderer.d.ts.map +1 -1
  134. package/dist/utilities/CanvasStack/RichTextRenderer.js +12 -0
  135. package/dist/utilities/CanvasStack/RichTextRenderer.js.map +1 -1
  136. package/dist/utilities/Dice.d.ts +2 -0
  137. package/dist/utilities/Dice.d.ts.map +1 -1
  138. package/dist/utilities/Dice.js +5 -1
  139. package/dist/utilities/Dice.js.map +1 -1
  140. package/dist/utilities/GalleryItemConversion.d.ts.map +1 -1
  141. package/dist/utilities/GalleryItemConversion.js +5 -7
  142. package/dist/utilities/GalleryItemConversion.js.map +1 -1
  143. package/package.json +1 -1
  144. package/src/library/components/DemoWrapper.tsx +5 -2
  145. package/src/library/components/Gallery/BuiltItem.ts +63 -8
  146. package/src/library/components/Gallery/GalleryController.ts +39 -9
  147. package/src/library/components/Gallery/GalleryViewer.tsx +90 -2
  148. package/src/library/components/Gallery/LayoutManager.ts +40 -15
  149. package/src/library/components/Gallery/constants.ts +5 -1
  150. package/src/library/components/Gallery/types.ts +6 -0
  151. package/src/library/components/GameDesigner.tsx +46 -2
  152. package/src/library/components/InlineGalleryDisplay.tsx +36 -6
  153. package/src/library/components/Panel/ExternalDrag.ts +122 -0
  154. package/src/library/components/Panel/PanelContents.tsx +26 -0
  155. package/src/library/components/PanelSpark.tsx +3 -1
  156. package/src/library/components/TopBar.tsx +2 -1
  157. package/src/library/components/TopBarPlayers.tsx +1 -6
  158. package/src/library/components/Tutorial/TutorialOverlay.tsx +16 -1
  159. package/src/library/components/Viewer.tsx +1 -0
  160. package/src/library/game/Chit.ts +7 -2
  161. package/src/library/game/GalleryItemChitChildrenSource.ts +1 -0
  162. package/src/library/game/GalleryItemRawSource.ts +1 -0
  163. package/src/library/game/GameButton.ts +13 -1
  164. package/src/library/game/ModalState.ts +3 -0
  165. package/src/library/game/Pick.ts +1 -3
  166. package/src/library/game/PlayerPromptStatusChit.ts +1 -3
  167. package/src/library/game/Prompt.ts +15 -4
  168. package/src/library/game/SparkChit.ts +9 -0
  169. package/src/library/game/Turn.ts +6 -9
  170. package/src/library/game/clientTransport/ClientPrompts.ts +45 -4
  171. package/src/library/game/clientTransport/ClientTime.ts +21 -1
  172. package/src/library/game/tutorial/TUTORIAL_GUIDE.md +11 -6
  173. package/src/library/game/tutorial/TutorialController.test.ts +4 -4
  174. package/src/library/game/tutorial/TutorialController.ts +20 -7
  175. package/src/library/game/tutorial/runTutorial.ts +29 -10
  176. package/src/library/hooks/useTimeController.tsx +4 -0
  177. package/src/library/hooks/useTutorial.tsx +6 -2
  178. package/src/library/index.ts +1 -0
  179. package/src/library/rendering/ChitGalleryItemInstance.ts +18 -1
  180. package/src/library/rendering/ChitRenderInstance.ts +23 -4
  181. package/src/library/rendering/LightWrapper.ts +10 -1
  182. package/src/library/rendering/Splay.test.ts +60 -0
  183. package/src/library/rendering/Splay.ts +30 -9
  184. package/src/library/utilities/CanvasStack/RichTextRenderer.ts +13 -0
  185. package/src/library/utilities/Dice.tsx +5 -1
  186. package/src/library/utilities/GalleryItemConversion.ts +5 -6
  187. package/dist/index.html +0 -12
  188. package/dist/main.0792d734cde2c688d5f7.hot-update.js +0 -16991
  189. package/dist/main.0792d734cde2c688d5f7.hot-update.js.map +0 -1
  190. package/dist/main.0792d734cde2c688d5f7.hot-update.json +0 -1
  191. package/dist/pretty-chitty.js +0 -204513
  192. package/dist/pretty-chitty.js.map +0 -1
@@ -22,6 +22,7 @@ import ChitLibraryViewer from "./ChitLibraryViewer";
22
22
  import Playground from "./Playground";
23
23
  import { DemoWrapper } from "./DemoWrapper";
24
24
  import { TutorialDevPanel } from "./Tutorial/TutorialDevPanel";
25
+ import type { TutorialEvent } from "../game/tutorial/TutorialController";
25
26
 
26
27
  const NONE = "__none__";
27
28
 
@@ -39,7 +40,31 @@ function DemoWorkbench({ game }: { game: Game<any, any> }) {
39
40
 
40
41
  const [id, locale] = selected === NONE ? [undefined, undefined] : selected.split("|");
41
42
  const spec = id ? tutorials.find((t) => t.id === id && t.locale === locale) : undefined;
43
+ // The step the tutorial is on, kept across reloads: a code change reloads the game while the developer
44
+ // reviews it, and the workbench comes back to that step (played up to headlessly) instead of the start.
45
+ // Restart, or picking another tutorial, forgets it.
46
+ const stepKey = `demo_${game.metadata.name}_step_${selected}`;
47
+ const storedStep = () => {
48
+ try {
49
+ return localStorage.getItem(stepKey) ?? undefined;
50
+ } catch {
51
+ return undefined;
52
+ }
53
+ };
54
+ const keepStep = (e: TutorialEvent) => {
55
+ try {
56
+ if (e.type === "step") localStorage.setItem(stepKey, e.stepId);
57
+ else if (e.type === "completed" || e.type === "skipped") localStorage.removeItem(stepKey);
58
+ } catch {
59
+ // storage blocked: reloads start over
60
+ }
61
+ };
42
62
  const restart = (at = 0) => {
63
+ try {
64
+ localStorage.removeItem(stepKey);
65
+ } catch {
66
+ // storage blocked
67
+ }
43
68
  setStartAt(at);
44
69
  setRestartKey((k) => k + 1);
45
70
  };
@@ -55,8 +80,8 @@ function DemoWorkbench({ game }: { game: Game<any, any> }) {
55
80
  variant="standard"
56
81
  value={spec ? selected : NONE}
57
82
  onChange={(e) => {
58
- setSelected(e.target.value);
59
83
  restart(0);
84
+ setSelected(e.target.value);
60
85
  }}
61
86
  >
62
87
  <MenuItem value={NONE}>Demo (no tutorial)</MenuItem>
@@ -91,7 +116,14 @@ function DemoWorkbench({ game }: { game: Game<any, any> }) {
91
116
  {/* The workbench sits beside the game, not over it: the tutorial's own layer (the dark start
92
117
  screen, the box) stays inside the game and never covers the step list */}
93
118
  <Box sx={{ flex: 1, minWidth: 0, position: "relative", display: "flex" }}>
94
- <DemoWrapper key={`${selected}-${restartKey}`} game={game} tutorial={spec} startAt={startAt}>
119
+ <DemoWrapper
120
+ key={`${selected}-${restartKey}`}
121
+ game={game}
122
+ tutorial={spec}
123
+ startAt={startAt}
124
+ resumeAt={spec && startAt === 0 ? storedStep() : undefined}
125
+ onTutorialEvent={spec ? keepStep : undefined}
126
+ >
95
127
  {spec && showDev && (
96
128
  <Box
97
129
  sx={{
@@ -124,12 +156,24 @@ export function GameDesigner({ game }: { game: Game<any, any> }) {
124
156
  const params = new URLSearchParams(window.location.search);
125
157
  const tutorial = params.get("tutorial") ?? undefined;
126
158
  const locale = params.get("locale") ?? undefined;
159
+ // The step in the URL: kept current as the tutorial plays, so a reload (a code change while the
160
+ // developer reviews it) comes back to the same step instead of the start
161
+ const resumeAt = params.get("step") ?? undefined;
162
+ const keepStep = (e: TutorialEvent) => {
163
+ if (e.type !== "step" && e.type !== "completed" && e.type !== "skipped") return;
164
+ const url = new URL(window.location.href);
165
+ if (e.type === "step") url.searchParams.set("step", e.stepId);
166
+ else url.searchParams.delete("step");
167
+ window.history.replaceState(window.history.state, "", url);
168
+ };
127
169
  return (
128
170
  <Stack sx={{ height: "100vh", maxHeight: "-webkit-fill-available", width: "100vw" }}>
129
171
  <DemoWrapper
130
172
  game={game}
131
173
  tutorial={tutorial}
132
174
  locale={locale}
175
+ resumeAt={tutorial ? resumeAt : undefined}
176
+ onTutorialEvent={tutorial ? keepStep : undefined}
133
177
  onBack={() => {
134
178
  window.history.back();
135
179
  }}
@@ -4,7 +4,9 @@ import { useEventChannelState } from "../hooks/useEventChannelState";
4
4
  import { useModalState } from "../hooks/useModalState";
5
5
  import { GalleryItem, GalleryViewer } from "./GalleryViewer";
6
6
  import useSize from "@react-hook/size";
7
- import { useAnimationSpeedMultiplier } from "../hooks/useTimeController";
7
+ import { useAnimationSpeedMultiplier, useOptionalClientPrompts } from "../hooks/useTimeController";
8
+ import { EventChannel } from "../utilities/EventChannel";
9
+ import { Prompt } from "../game/Prompt";
8
10
  import { useGameTheme } from "../hooks/useGameTheme";
9
11
  import { ScreenshotMonitor } from "@mui/icons-material";
10
12
  import { useButtonGalleriesOptions } from "../hooks/useButtonGalleriesOptions";
@@ -24,9 +26,19 @@ export function InlineGalleryDisplay() {
24
26
  const inlineGallerySize = inlineSource ? (inlineSource.inlineGallerySize ?? DEFAULT_INLINE_GALLERY_SIZE) : 0;
25
27
  const [displaySize, setDisplaySize] = useState(0);
26
28
  const [_galleryDisplayMode, setGalleryDisplayMode] = useButtonGalleriesOptions();
29
+ // A closed source that opted in to holdOnCloseMs leaves its items and height up for a while,
30
+ // so a gallery that opens right after swaps in place instead of animating out and back.
31
+ const lastSource = useRef<{ size: number; holdMs: number } | undefined>(undefined);
32
+ const [heldSize, setHeldSize] = useState<number | undefined>(undefined);
33
+ const shownSize = inlineGallerySize || heldSize || 0;
34
+ const clientPrompts = useOptionalClientPrompts();
35
+ const [noPrompts] = useState(() => new EventChannel<Prompt | undefined>(undefined));
36
+ const [prompt] = useEventChannelState(clientPrompts?.currentPrompt ?? noPrompts);
27
37
 
28
38
  useEffect(() => {
29
39
  if (inlineSource) {
40
+ lastSource.current = { size: inlineGallerySize, holdMs: inlineSource.inlineHoldOnCloseMs ?? 0 };
41
+ setHeldSize(undefined);
30
42
  setItems(inlineSource.items);
31
43
  const unSub = inlineSource.registerUpdateHandler(() => {
32
44
  setItems(inlineSource.items);
@@ -35,21 +47,39 @@ export function InlineGalleryDisplay() {
35
47
  inlineSource.close();
36
48
  unSub();
37
49
  };
38
- } else {
39
- setItems(undefined);
40
50
  }
51
+ const last = lastSource.current;
52
+ lastSource.current = undefined;
53
+ if (last && last.holdMs > 0) {
54
+ setHeldSize(last.size);
55
+ const to = setTimeout(() => {
56
+ setHeldSize(undefined);
57
+ setItems(undefined);
58
+ }, last.holdMs);
59
+ return () => clearTimeout(to);
60
+ }
61
+ setItems(undefined);
41
62
  }, [inlineSource, setItems, inlineGallerySize]);
42
63
 
64
+ // The hold only bridges a wait for the next prompt: a prompt showing with no inline gallery
65
+ // (or the gallery toggled shut on the same prompt) ends it at once.
66
+ useEffect(() => {
67
+ if (prompt && !inlineSource) {
68
+ setHeldSize(undefined);
69
+ setItems(undefined);
70
+ }
71
+ }, [prompt, inlineSource, setItems]);
72
+
43
73
  useEffect(() => {
44
- if (items && items.length > 0 && inlineGallerySize > 0) {
45
- setDisplaySize(inlineGallerySize);
74
+ if (items && items.length > 0 && shownSize > 0) {
75
+ setDisplaySize(shownSize);
46
76
  } else {
47
77
  const to = setTimeout(() => {
48
78
  setDisplaySize(0);
49
79
  }, 250);
50
80
  return () => clearTimeout(to);
51
81
  }
52
- }, [inlineGallerySize, items, setDisplaySize]);
82
+ }, [shownSize, items, setDisplaySize]);
53
83
 
54
84
  return (
55
85
  <Box
@@ -0,0 +1,122 @@
1
+ import { Box3, Object3D, Vector3 } from "three";
2
+ import { Chit } from "../../game/Chit";
3
+ import { GalleryItem } from "../Gallery/types";
4
+ import { RootChitRenderInstance } from "../../rendering/RootChitRenderInstance";
5
+ import { ChitGalleryItemInstance } from "../../rendering/ChitGalleryItemInstance";
6
+
7
+ /**
8
+ * A drag that starts outside the board, for now only in the inline gallery strip: a chit
9
+ * shown there with a live DragPick is pulled up onto the panel that holds its drop targets.
10
+ * Coordinates are client (page) pixels.
11
+ */
12
+ export interface ExternalDrag {
13
+ move(clientX: number, clientY: number): void;
14
+ /** Drops on the target under the pointer, if any; off the board it does nothing. */
15
+ end(): void;
16
+ cancel(): void;
17
+ }
18
+
19
+ export interface ExternalDragHost {
20
+ /** Undefined when the chit can't be dragged now, or its targets aren't on a visible panel. */
21
+ begin(chit: Chit, item: GalleryItem, clientX: number, clientY: number): ExternalDrag | undefined;
22
+ }
23
+
24
+ // How long the set-down copy stays after a drop, covering the round trip to the game.
25
+ const SETTLE_MS = 600;
26
+
27
+ export interface ExternalDragViewer {
28
+ getBounds: () => DOMRect | null;
29
+ renderInstance: RootChitRenderInstance;
30
+ }
31
+
32
+ /**
33
+ * Draws a copy of the chit under the pointer on the target panel, lifted like a normal drag,
34
+ * and outlines the nearest drop target, exactly as `ChitRenderInstance.executeDrag` does on
35
+ * the table. Dropping calls the chit's `onDrag`, so the DragPick resolves as if the chit had
36
+ * been dragged there; the chit itself is not moved on the client (it lives in the gallery).
37
+ */
38
+ export function startExternalDrag(
39
+ chit: Chit,
40
+ item: GalleryItem,
41
+ viewer: ExternalDragViewer,
42
+ clientX: number,
43
+ clientY: number,
44
+ ): ExternalDrag {
45
+ const root = viewer.renderInstance;
46
+ // cloneMesh, not createMesh: createMesh would bind the gallery's item to the board's scene, so
47
+ // after a cancelled drag its updates would redraw the board instead of the strip
48
+ const ghost: Object3D = item instanceof ChitGalleryItemInstance ? item.cloneMesh() : item.createMesh(root.sceneWrapper);
49
+ ghost.visible = false;
50
+ root.sceneWrapper.scene.add(ghost);
51
+ const lift = chit.renderInstance?.dragLift ?? 1;
52
+ const targets = (chit.dropTargets ?? [])
53
+ .filter((t) => t.renderInstance && t.renderInstance.rootRenderInstance === root)
54
+ .map((t) => ({ chit: t, at: t.renderInstance!.worldCenter() }));
55
+
56
+ let dropTarget: Chit | undefined;
57
+ const setTarget = (t: Chit | undefined) => {
58
+ if (dropTarget === t) return;
59
+ dropTarget?.renderInstance?.markAsDropTarget(false);
60
+ dropTarget = t;
61
+ t?.renderInstance?.markAsDropTarget(true);
62
+ };
63
+
64
+ const move = (x: number, y: number) => {
65
+ const b = viewer.getBounds();
66
+ const inside = !!b && x >= b.left && x <= b.right && y >= b.top && y <= b.bottom;
67
+ const p = inside ? root.attemptToFindPlaneZ0OfCanvasPoints(x - b!.left, y - b!.top) : undefined;
68
+ if (!p || targets.length === 0) {
69
+ ghost.visible = false;
70
+ setTarget(undefined);
71
+ root.markDirty();
72
+ return;
73
+ }
74
+ let nearest = targets[0];
75
+ let best = Number.MAX_VALUE;
76
+ for (const t of targets) {
77
+ const d = (t.at.x - p.x) * (t.at.x - p.x) + (t.at.y - p.y) * (t.at.y - p.y);
78
+ if (d < best) {
79
+ best = d;
80
+ nearest = t;
81
+ }
82
+ }
83
+ ghost.position.set(p.x, p.y, nearest.at.z + lift);
84
+ ghost.visible = true;
85
+ setTarget(nearest.chit);
86
+ root.markDirty();
87
+ };
88
+
89
+ const removeGhost = () => {
90
+ ghost.removeFromParent();
91
+ root.markDirty();
92
+ };
93
+
94
+ move(clientX, clientY);
95
+ return {
96
+ move,
97
+ end: () => {
98
+ const t = dropTarget;
99
+ const at = targets.find((x) => x.chit === t)?.at;
100
+ setTarget(undefined);
101
+ if (!t || !at || !chit.onDrag) {
102
+ removeGhost();
103
+ return;
104
+ }
105
+ // Set the copy down on the spot and keep it there while the move goes to the game: the
106
+ // chit the game creates appears under it, so the piece doesn't blink out and fly back in.
107
+ // Resting on the target, not centred on it (half of it would sink into whatever is there).
108
+ ghost.position.set(at.x, at.y, at.z + new Box3().setFromObject(ghost).getSize(new Vector3()).z / 2);
109
+ root.markDirty();
110
+ // A refused drop (a tutorial's guard) creates nothing: take the copy away at once
111
+ if (chit.onDrag(t) === false) {
112
+ removeGhost();
113
+ return;
114
+ }
115
+ setTimeout(removeGhost, SETTLE_MS);
116
+ },
117
+ cancel: () => {
118
+ setTarget(undefined);
119
+ removeGhost();
120
+ },
121
+ };
122
+ }
@@ -12,6 +12,9 @@ import Hammer from "@egjs/hammerjs";
12
12
  import { PanelPositioningContext, ViewerPosition } from "../../hooks/usePanelPositioning";
13
13
  import { ViewerWrapper } from "./ViewerWrapper";
14
14
  import { PanelNavigation, PanelNavigationContext, usePublishPanelNavigation } from "../../hooks/usePanelNavigation";
15
+ import { RootChitRenderInstance } from "../../rendering/RootChitRenderInstance";
16
+ import { useModalState } from "../../hooks/useModalState";
17
+ import { startExternalDrag } from "./ExternalDrag";
15
18
 
16
19
  // Types for gesture handling
17
20
  export interface ViewerGestureHandlers {
@@ -30,6 +33,8 @@ export interface ViewerRegistration {
30
33
  id: string;
31
34
  getBounds: () => DOMRect | null;
32
35
  handlers: ViewerGestureHandlers;
36
+ /** The viewer's renderer, so a drag from outside (the inline gallery) can draw on it. */
37
+ renderInstance?: RootChitRenderInstance;
33
38
  }
34
39
 
35
40
  interface GestureContextValue {
@@ -76,6 +81,27 @@ export function PanelContents({
76
81
  };
77
82
  }, []);
78
83
 
84
+ // A drag from the inline gallery lands on the viewer that renders the chit's drop targets.
85
+ const modalState = useModalState();
86
+ useEffect(() => {
87
+ modalState.externalDragHost = {
88
+ begin: (chit, item, clientX, clientY) => {
89
+ if (!chit.onDrag || !chit.dropTargets?.length) return undefined;
90
+ const root = chit.dropTargets.find((t) => t.renderInstance)?.renderInstance?.rootRenderInstance;
91
+ if (!root) return undefined;
92
+ for (const registration of viewerRegistrationsRef.current.values()) {
93
+ if (registration.renderInstance === root && registration.getBounds()) {
94
+ return startExternalDrag(chit, item, { getBounds: registration.getBounds, renderInstance: root }, clientX, clientY);
95
+ }
96
+ }
97
+ return undefined;
98
+ },
99
+ };
100
+ return () => {
101
+ modalState.externalDragHost = undefined;
102
+ };
103
+ }, [modalState]);
104
+
79
105
  // Panel positioning system
80
106
  const positionsRef = useRef<Map<string, ViewerPosition>>(
81
107
  new Map([["root", { chitId: "root", x: -40, y: 0, w: 30, h: 30, front: true, visible: true, paused: true }]]),
@@ -33,7 +33,9 @@ export default function PanelSpark({ chit, paused, zIndex }: { zIndex: number; c
33
33
  useEffect(() => {
34
34
  if (targetValue !== value) {
35
35
  if (paused && value !== Number.MIN_SAFE_INTEGER) {
36
- chit.parent?.renderInstance?.rootRenderInstance.markHasPendingChange();
36
+ if (chit.worthSlidingToPanelToShowChange) {
37
+ chit.parent?.renderInstance?.rootRenderInstance.markHasPendingChange();
38
+ }
37
39
  return;
38
40
  }
39
41
 
@@ -79,7 +79,8 @@ export default function TopBar({ onBack }: { onBack?: () => void }) {
79
79
  <TopBarPlayers />
80
80
  </Box>
81
81
  {dropdowns.map((dropdown) => (
82
- <Box key={dropdown.id} sx={{ width: barWidth, borderLeft: `1px solid ${theme.barBreak}` }}>
82
+ // a tutorial points at a dropdown (a player aid) as `{ ui: "dropdown:<chit id>" }`
83
+ <Box key={dropdown.id} data-tutorial-target={`dropdown:${dropdown.id}`} sx={{ width: barWidth, borderLeft: `1px solid ${theme.barBreak}` }}>
83
84
  <DropdownChitWrapper chitId={dropdown.id} />
84
85
  </Box>
85
86
  ))}
@@ -117,12 +117,7 @@ function PlayerInfoRow({ headers, player }: { player: PlayerChit; headers?: bool
117
117
  <PlayerInfoCell size={size} key={spark.id} spark={spark} />
118
118
  ))}
119
119
  <TextPlayerInfoCell size={size} width={NAME_WIDTH} text={player.name} />
120
- {/* This cell is single-line, ellipsized text, so use the plain-text prompt (player tokens become names). */}
121
- <TextPlayerInfoCell
122
- size={size}
123
- width={PROMPT_WIDTH}
124
- text={player.promptStatus.latestPromptMessageText ?? player.promptStatus.latestPromptMessage ?? ""}
125
- />
120
+ <TextPlayerInfoCell size={size} width={PROMPT_WIDTH} text={player.promptStatus.latestPromptMessage ?? ""} />
126
121
  </Stack>
127
122
  );
128
123
  }
@@ -262,7 +262,6 @@ function InnerOverlay() {
262
262
  while (Date.now() < deadline) {
263
263
  const current = clientTime.currentClock.value;
264
264
  const max = clientTime.maxClock.value;
265
- if (ahead) console.info("ZZTIME wait", Date.now() - started, current.clock, max.clock, current.pass === max.pass, [...((timeState as any).currentlyAnimating ?? [])].map((k: string) => k.replace(/\d{6,}/, "")).join(","));
266
265
  if (
267
266
  current.pass !== before &&
268
267
  current.clock === max.clock &&
@@ -285,6 +284,13 @@ function InnerOverlay() {
285
284
  // After a rewind or a dev restart: the board is already there and the player already tapped once
286
285
  setStarted(true);
287
286
  c.start(tutorial.startAt, { paused: tutorial.startPaused });
287
+ } else if (tutorial.resumeAt) {
288
+ // A reload comes back to the step the player was on, with the board as it was then
289
+ const index = c.steps.findIndex((s) => s.id === tutorial.resumeAt);
290
+ if (index > 0) {
291
+ setStarted(true);
292
+ c.skipTo(index);
293
+ }
288
294
  }
289
295
  }, [rootChit, controller, clientTime, clientPrompts, timeState, playerId, tutorial, modalState]);
290
296
 
@@ -299,6 +305,15 @@ function InnerOverlay() {
299
305
  controller?.setMuted(muted);
300
306
  }, [controller, muted]);
301
307
 
308
+ // A move inside an open prompt (a piece dragged within the build prompt) changes the board without any of the
309
+ // view's channels firing, so a check waiting on it never re-ran and the step hung ("it gets stuck on me dragging
310
+ // my dealer"). Re-run the check a few times a second as well; the headless runner polls the same way.
311
+ useEffect(() => {
312
+ if (!controller) return;
313
+ const poll = setInterval(() => controller.recheck(), 250);
314
+ return () => clearInterval(poll);
315
+ }, [controller]);
316
+
302
317
  // Tapping a control the next "do it" step asks for counts as moving on to that step. Listen in the
303
318
  // capture phase so the step is entered (and its check baselined) before the control acts.
304
319
  useEffect(() => {
@@ -382,6 +382,7 @@ export default function Viewer({
382
382
  id,
383
383
  getBounds: () => el.getBoundingClientRect(),
384
384
  handlers,
385
+ renderInstance: chitRenderInstance,
385
386
  });
386
387
 
387
388
  return () => {
@@ -58,7 +58,9 @@ function wrapWithDirtyProxy(value: any, chit: Chit): any {
58
58
  }
59
59
 
60
60
  export type ChitClick = () => void;
61
- export type ChitDrag = (dropOn: Chit) => void;
61
+ /** Called when a dragged chit is dropped on a target; returning `false` says the drop was refused (a
62
+ * tutorial's guard), so the dragged chit goes back where it came from instead of onto the target. */
63
+ export type ChitDrag = (dropOn: Chit) => void | boolean;
62
64
 
63
65
  export type HiddenPropertySerializationRule = {
64
66
  fields: "all" | string[];
@@ -555,7 +557,10 @@ export class Chit extends ObjectWithProps {
555
557
 
556
558
  this._parentFallback = inflateValue(j._parentFallback);
557
559
 
558
- if (this._version === 1 && this._parentFallback) {
560
+ // a chit appearing for the first time starts in its fallback (its bag), so it is seen coming out of it. A chit
561
+ // that already has a parent is not new: hopping it through the bag would clear its parent's outlet, which an
562
+ // undo's reset has already restored and will not restore again
563
+ if (this._version === 1 && this._parentFallback && !this._parent) {
559
564
  this.setParent(this._parentFallback, j._parentOutlet ?? "graveyard");
560
565
  }
561
566
 
@@ -6,6 +6,7 @@ export class GalleryItemChitChildrenSource implements GalleryItemSource {
6
6
  private unSub: () => void;
7
7
 
8
8
  public inlineGallerySize?: number | undefined = undefined;
9
+ public inlineHoldOnCloseMs?: number | undefined = undefined;
9
10
 
10
11
  constructor(public backingObject: Chit) {
11
12
  this.unSub = backingObject.onChange("deserialized", () => {
@@ -4,6 +4,7 @@ export class GalleryItemRawSource implements GalleryItemSource {
4
4
  constructor(private galleryItems: GalleryItem[]) {}
5
5
 
6
6
  public inlineGallerySize?: number | undefined = undefined;
7
+ public inlineHoldOnCloseMs?: number | undefined = undefined;
7
8
 
8
9
  get items() {
9
10
  return this.galleryItems;
@@ -54,6 +54,15 @@ export class ToggleGalleryButton extends GameButton {
54
54
 
55
55
  toggleSmallSize?: number = 125;
56
56
 
57
+ /**
58
+ * Opt-in, off by default. When this gallery's prompt goes away (say, while the answer's
59
+ * animations play), the inline strip keeps its items and height for up to this many ms. If the
60
+ * next prompt opens an inline gallery in that time, it swaps in place: items shared by both
61
+ * stay where they are instead of animating out and back in. Meant for a gallery that reopens
62
+ * after every pick, like a build menu.
63
+ */
64
+ holdOnCloseMs?: number;
65
+
57
66
  /** @internal */
58
67
  parentChit?: Chit;
59
68
 
@@ -70,15 +79,17 @@ export class ToggleGalleryButton extends GameButton {
70
79
  return {
71
80
  parentChitId: this.parentChit?.id,
72
81
  autoShow: this.autoShow,
82
+ holdOnCloseMs: this.holdOnCloseMs,
73
83
  };
74
84
  }
75
85
 
76
86
  /** @internal */
77
- deserialize({ parentChitId, autoShow }: { parentChitId?: string; autoShow: boolean }, findChit: FindChit) {
87
+ deserialize({ parentChitId, autoShow, holdOnCloseMs }: { parentChitId?: string; autoShow: boolean; holdOnCloseMs?: number }, findChit: FindChit) {
78
88
  if (parentChitId) {
79
89
  this.parentChit = findChit(parentChitId);
80
90
  }
81
91
  this.autoShow = autoShow;
92
+ if (holdOnCloseMs !== undefined) this.holdOnCloseMs = holdOnCloseMs;
82
93
  }
83
94
 
84
95
  /** @internal */
@@ -89,6 +100,7 @@ export class ToggleGalleryButton extends GameButton {
89
100
  this.galleryItemSource = new GalleryItemRawSource(chitsToGalleryItems(chitPick.chits));
90
101
  }
91
102
  this.galleryItemSource.inlineGallerySize = this.toggleSmallSize;
103
+ this.galleryItemSource.inlineHoldOnCloseMs = this.holdOnCloseMs;
92
104
  }
93
105
  }
94
106
 
@@ -1,11 +1,14 @@
1
1
  import { GalleryItemSource } from "../components/GalleryViewer";
2
2
  import { EventChannel } from "../utilities/EventChannel";
3
+ import type { ExternalDragHost } from "../components/Panel/ExternalDrag";
3
4
 
4
5
  export class ModalState {
5
6
  public gallerySource = new EventChannel<undefined | GalleryItemSource>(undefined);
6
7
  public inlineGallerySource = new EventChannel<undefined | GalleryItemSource>(undefined);
7
8
  public actionLogVisible = new EventChannel<boolean>(false);
8
9
  public settingsVisible = new EventChannel<boolean>(false);
10
+ /** Set by the panels: lets the inline gallery drag a chit onto the board (see ExternalDrag). */
11
+ public externalDragHost?: ExternalDragHost;
9
12
 
10
13
  constructor() {
11
14
  this.gallerySource.on((source) => {
@@ -385,9 +385,7 @@ export class DragPick<C extends Chit> extends Pick {
385
385
  stageIn(prompt: PickPrompt) {
386
386
  this.chits.forEach((c) => {
387
387
  c.dropTargets = this.dropTargets.flatMap((dt) => dt.chits);
388
- c.onDrag = (droppedChit: Chit) => {
389
- prompt.resolvePick(this, { chitId: c.id!, targetChitId: droppedChit.id! });
390
- };
388
+ c.onDrag = (droppedChit: Chit) => prompt.resolvePick(this, { chitId: c.id!, targetChitId: droppedChit.id! });
391
389
  });
392
390
  this.processFocus();
393
391
  }
@@ -5,10 +5,8 @@ import { Prompt } from "./Prompt";
5
5
  import StaticChitTypeRegistry from "./StaticChitTypeRegistry";
6
6
 
7
7
  export class PlayerPromptStatusChit extends Chit {
8
- /** The prompt the player is currently being asked to answer, with `:token:` markup intact. @internal */
8
+ /** Plain text of the prompt the player is currently being asked to answer (`:token:` markup resolved). @internal */
9
9
  public latestPromptMessage?: string;
10
- /** Plain-text form of {@link latestPromptMessage} for storage, match lists and notifications. @internal */
11
- public latestPromptMessageText?: string;
12
10
  /**
13
11
  * The prompt this player is being asked right now, on the side that runs the match (undefined when
14
12
  * it is not their turn). Read it, do not resolve it: answers go through the player's own client.
@@ -267,15 +267,18 @@ export class PickPrompt extends Prompt {
267
267
  this._help = details.help;
268
268
  }
269
269
 
270
- resolvePick(pick: Pick, value: any) {
270
+ /** Answers with this pick. Returns false when the answer was not taken (already answered, or refused
271
+ * by the guard), so a drag can put its chit back instead of leaving it on the target. */
272
+ resolvePick(pick: Pick, value: any): boolean {
271
273
  if (this.resolved) {
272
- return;
274
+ return false;
273
275
  }
274
276
  if (this.guard && !this.guard({ type: "pick", pick, value })) {
275
- return;
277
+ return false;
276
278
  }
277
279
  const idx = this.picks.indexOf(pick);
278
280
  this.resolve({ idx, value, pickType: pick.type });
281
+ return true;
279
282
  }
280
283
 
281
284
  resolveDetails(resolution: PickResolution) {
@@ -285,7 +288,15 @@ export class PickPrompt extends Prompt {
285
288
 
286
289
  this.resolved = true;
287
290
  const pick = this.picks[resolution.idx];
288
- this.finished = () => pick.resolveDetails(resolution?.value);
291
+ this.finished = () => {
292
+ // A recorded answer replayed against a prompt that has changed (picks added or reordered by
293
+ // a code change) can land on a different pick: the same check a live answer gets
294
+ // (canResolveResponse), so it is a mismatch rather than a crash inside the pick.
295
+ if (!pick || (resolution.pickType && resolution.pickType !== pick.type) || !pick.canResolveResponse(resolution.value)) {
296
+ throw new MismatchError();
297
+ }
298
+ return pick.resolveDetails(resolution.value);
299
+ };
289
300
  }
290
301
 
291
302
  stageIn() {
@@ -39,6 +39,15 @@ export class SparkChit extends Chit {
39
39
  return this.icon;
40
40
  }
41
41
 
42
+ /**
43
+ * Whether a change to this spark, while its panel is out of view, marks the panel as changed (so the layout may
44
+ * slide to it), as `ChitRenderSpec.worthSlidingToPanelToShowChange` does for a chit on the table. Override to
45
+ * return false for a number that changes often during other panels' actions (money earned on every sale).
46
+ */
47
+ public get worthSlidingToPanelToShowChange(): boolean {
48
+ return true;
49
+ }
50
+
42
51
  /** @internal */
43
52
  @NonEditable public element: RefObject<HTMLElement> | undefined;
44
53
 
@@ -284,17 +284,14 @@ export class Turn<T, P extends PlayerChit, R extends RootChit<P>> {
284
284
  }
285
285
 
286
286
  /**
287
- * Records what a player is being asked for: the tokenized message for the in-game UI, and a plain-text version
288
- * (player tokens become names, etc.) for anything that can only show text.
287
+ * Records what a player is being asked for, as plain text (player tokens become names, etc.) for match storage,
288
+ * match lists and notifications. The in-game prompt renders its own tokenized message.
289
289
  */
290
290
  private setPromptMessage(player: P, message: string | undefined) {
291
- player.promptStatus.latestPromptMessage = message;
292
- if (message === undefined) {
293
- player.promptStatus.latestPromptMessageText = undefined;
294
- return;
295
- }
296
- const tokenMap = buildTokenMap(this.match.game.tokenMap, this.rootChit.players.map((p) => p));
297
- player.promptStatus.latestPromptMessageText = tokenizedMessageToText(message, tokenMap);
291
+ player.promptStatus.latestPromptMessage =
292
+ message === undefined
293
+ ? undefined
294
+ : tokenizedMessageToText(message, buildTokenMap(this.match.game.tokenMap, this.rootChit.players.map((p) => p)));
298
295
  }
299
296
 
300
297
  /**