@pretty-chitty/core 1.2.10 → 1.2.16
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 +17 -3
- package/dist/components/DemoWrapper.js +1 -1
- package/dist/components/DemoWrapper.js.map +1 -1
- package/dist/components/FullScreenGalleryDisplay.d.ts.map +1 -1
- package/dist/components/FullScreenGalleryDisplay.js +5 -1
- package/dist/components/FullScreenGalleryDisplay.js.map +1 -1
- package/dist/components/Gallery/AnimationController.d.ts +1 -0
- package/dist/components/Gallery/AnimationController.d.ts.map +1 -1
- package/dist/components/Gallery/AnimationController.js +9 -0
- package/dist/components/Gallery/AnimationController.js.map +1 -1
- package/dist/components/Gallery/BuiltItem.d.ts +2 -1
- package/dist/components/Gallery/BuiltItem.d.ts.map +1 -1
- package/dist/components/Gallery/BuiltItem.js +15 -3
- package/dist/components/Gallery/BuiltItem.js.map +1 -1
- package/dist/components/Gallery/GalleryController.d.ts +1 -0
- package/dist/components/Gallery/GalleryController.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryController.js +15 -4
- package/dist/components/Gallery/GalleryController.js.map +1 -1
- package/dist/components/Gallery/GalleryViewer.d.ts +2 -1
- package/dist/components/Gallery/GalleryViewer.d.ts.map +1 -1
- package/dist/components/Gallery/GalleryViewer.js +13 -4
- package/dist/components/Gallery/GalleryViewer.js.map +1 -1
- package/dist/components/InlineGalleryDisplay.d.ts.map +1 -1
- package/dist/components/InlineGalleryDisplay.js +5 -1
- package/dist/components/InlineGalleryDisplay.js.map +1 -1
- package/dist/components/Playground.d.ts.map +1 -1
- package/dist/components/Playground.js +59 -21
- package/dist/components/Playground.js.map +1 -1
- package/dist/components/ServerTrustMatchViewer.d.ts.map +1 -1
- package/dist/components/ServerTrustMatchViewer.js +10 -2
- package/dist/components/ServerTrustMatchViewer.js.map +1 -1
- package/dist/components/SparkLineChart.d.ts.map +1 -1
- package/dist/components/SparkLineChart.js +62 -22
- package/dist/components/SparkLineChart.js.map +1 -1
- package/dist/components/Viewer.d.ts.map +1 -1
- package/dist/components/Viewer.js +15 -6
- package/dist/components/Viewer.js.map +1 -1
- package/dist/game/Chit.d.ts +10 -1
- package/dist/game/Chit.d.ts.map +1 -1
- package/dist/game/Chit.js +125 -4
- package/dist/game/Chit.js.map +1 -1
- package/dist/game/Connection.d.ts +1 -0
- package/dist/game/Connection.d.ts.map +1 -1
- package/dist/game/Connection.js +27 -8
- package/dist/game/Connection.js.map +1 -1
- package/dist/game/ConnectionTransport.d.ts +5 -0
- package/dist/game/ConnectionTransport.d.ts.map +1 -1
- package/dist/game/ConnectionTransport.js +32 -0
- package/dist/game/ConnectionTransport.js.map +1 -1
- package/dist/game/GalleryItemChitChildrenSource.d.ts.map +1 -1
- package/dist/game/GalleryItemChitChildrenSource.js +9 -1
- package/dist/game/GalleryItemChitChildrenSource.js.map +1 -1
- package/dist/game/Game.d.ts +6 -0
- package/dist/game/Game.d.ts.map +1 -1
- package/dist/game/OrderedOutlet.d.ts +4 -1
- package/dist/game/OrderedOutlet.d.ts.map +1 -1
- package/dist/game/OrderedOutlet.js +25 -4
- package/dist/game/OrderedOutlet.js.map +1 -1
- package/dist/game/Pick.d.ts +1 -0
- package/dist/game/Pick.d.ts.map +1 -1
- package/dist/game/Pick.js +40 -1
- package/dist/game/Pick.js.map +1 -1
- package/dist/game/Prompt.d.ts +11 -1
- package/dist/game/Prompt.d.ts.map +1 -1
- package/dist/game/Prompt.js +34 -1
- package/dist/game/Prompt.js.map +1 -1
- package/dist/game/Turn.d.ts +17 -0
- package/dist/game/Turn.d.ts.map +1 -1
- package/dist/game/Turn.js +114 -63
- package/dist/game/Turn.js.map +1 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts +3 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.d.ts.map +1 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.js +31 -5
- package/dist/game/badAiTransport/BadAIClientPrompts.js.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.d.ts +2 -0
- package/dist/game/clientTransport/ClientPrompts.d.ts.map +1 -1
- package/dist/game/clientTransport/ClientPrompts.js +48 -16
- package/dist/game/clientTransport/ClientPrompts.js.map +1 -1
- package/dist/game/clientTransport/ClientTime.d.ts.map +1 -1
- package/dist/game/clientTransport/ClientTime.js +58 -52
- package/dist/game/clientTransport/ClientTime.js.map +1 -1
- package/dist/game/serverTransport/ServerPrompts.d.ts +1 -1
- package/dist/game/serverTransport/ServerPrompts.d.ts.map +1 -1
- package/dist/game/serverTransport/ServerPrompts.js +14 -3
- package/dist/game/serverTransport/ServerPrompts.js.map +1 -1
- package/dist/game/serverTransport/ServerStatus.d.ts.map +1 -1
- package/dist/game/serverTransport/ServerStatus.js +6 -2
- package/dist/game/serverTransport/ServerStatus.js.map +1 -1
- package/dist/game/serverTransport/ServerTime.d.ts.map +1 -1
- package/dist/game/serverTransport/ServerTime.js +6 -2
- package/dist/game/serverTransport/ServerTime.js.map +1 -1
- package/dist/hooks/useTimeController.d.ts.map +1 -1
- package/dist/hooks/useTimeController.js +3 -0
- package/dist/hooks/useTimeController.js.map +1 -1
- package/dist/hooks/useWebGlRenderer.d.ts +27 -1
- package/dist/hooks/useWebGlRenderer.d.ts.map +1 -1
- package/dist/hooks/useWebGlRenderer.js +191 -7
- package/dist/hooks/useWebGlRenderer.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/rendering/ChitGalleryItemInstance.js +1 -1
- package/dist/rendering/ChitGalleryItemInstance.js.map +1 -1
- package/dist/rendering/ChitRenderInstance.d.ts.map +1 -1
- package/dist/rendering/ChitRenderInstance.js +30 -9
- package/dist/rendering/ChitRenderInstance.js.map +1 -1
- package/dist/rendering/ChitRenderSpec.js +1 -1
- package/dist/rendering/ChitRenderSpec.js.map +1 -1
- package/dist/rendering/outline/IDBasedOutlinePass.d.ts.map +1 -1
- package/dist/rendering/outline/IDBasedOutlinePass.js +6 -2
- package/dist/rendering/outline/IDBasedOutlinePass.js.map +1 -1
- package/dist/rendering/outline/passes/InterMeshEdgeDetectionPass.d.ts.map +1 -1
- package/dist/rendering/outline/passes/InterMeshEdgeDetectionPass.js +7 -3
- package/dist/rendering/outline/passes/InterMeshEdgeDetectionPass.js.map +1 -1
- package/dist/utilities/CanvasStack/CanvasOperations.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/CanvasOperations.js +34 -13
- package/dist/utilities/CanvasStack/CanvasOperations.js.map +1 -1
- package/dist/utilities/CanvasStack/CanvasStack.d.ts +9 -0
- package/dist/utilities/CanvasStack/CanvasStack.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/CanvasStack.js +37 -2
- package/dist/utilities/CanvasStack/CanvasStack.js.map +1 -1
- package/dist/utilities/CanvasStack/RichTextRenderer.d.ts +2 -0
- package/dist/utilities/CanvasStack/RichTextRenderer.d.ts.map +1 -1
- package/dist/utilities/CanvasStack/RichTextRenderer.js +47 -4
- package/dist/utilities/CanvasStack/RichTextRenderer.js.map +1 -1
- package/package.json +1 -1
- package/src/library/components/DemoWrapper.tsx +1 -1
- package/src/library/components/FullScreenGalleryDisplay.tsx +5 -0
- package/src/library/components/Gallery/AnimationController.ts +10 -0
- package/src/library/components/Gallery/BuiltItem.ts +16 -3
- package/src/library/components/Gallery/GalleryController.ts +15 -4
- package/src/library/components/Gallery/GalleryViewer.tsx +17 -3
- package/src/library/components/InlineGalleryDisplay.tsx +5 -0
- package/src/library/components/Playground.tsx +76 -20
- package/src/library/components/ServerTrustMatchViewer.tsx +10 -2
- package/src/library/components/SparkLineChart.tsx +85 -24
- package/src/library/components/Viewer.tsx +15 -6
- package/src/library/game/Chit.test.ts +91 -0
- package/src/library/game/Chit.ts +122 -9
- package/src/library/game/Connection.ts +27 -8
- package/src/library/game/ConnectionTransport.ts +38 -0
- package/src/library/game/GalleryItemChitChildrenSource.ts +9 -1
- package/src/library/game/Game.ts +7 -0
- package/src/library/game/OrderedOutlet.ts +27 -4
- package/src/library/game/Pick.ts +46 -4
- package/src/library/game/Prompt.ts +43 -3
- package/src/library/game/Turn.ts +127 -78
- package/src/library/game/badAiTransport/BadAIClientPrompts.ts +33 -4
- package/src/library/game/clientTransport/ClientPrompts.ts +50 -16
- package/src/library/game/clientTransport/ClientTime.ts +61 -56
- package/src/library/game/serverTransport/ServerPrompts.ts +25 -7
- package/src/library/game/serverTransport/ServerStatus.ts +6 -2
- package/src/library/game/serverTransport/ServerTime.ts +6 -2
- package/src/library/hooks/useTimeController.tsx +3 -0
- package/src/library/hooks/useWebGlRenderer.tsx +225 -7
- package/src/library/index.ts +1 -1
- package/src/library/rendering/ChitGalleryItemInstance.ts +1 -1
- package/src/library/rendering/ChitRenderInstance.ts +32 -9
- package/src/library/rendering/ChitRenderSpec.ts +1 -1
- package/src/library/rendering/outline/IDBasedOutlinePass.ts +6 -2
- package/src/library/rendering/outline/passes/InterMeshEdgeDetectionPass.ts +7 -3
- package/src/library/utilities/CanvasStack/CanvasOperations.tsx +44 -13
- package/src/library/utilities/CanvasStack/CanvasStack.ts +38 -1
- package/src/library/utilities/CanvasStack/RichTextRenderer.ts +66 -5
|
@@ -36,6 +36,7 @@ export interface GalleryViewerProps {
|
|
|
36
36
|
galleryItemWidth?: number;
|
|
37
37
|
galleryItemHeight?: number;
|
|
38
38
|
onClose?: () => void;
|
|
39
|
+
onLongPress?: () => void;
|
|
39
40
|
showSummary?: SummaryMode;
|
|
40
41
|
zFactor?: number;
|
|
41
42
|
}
|
|
@@ -47,6 +48,7 @@ export function GalleryViewer({
|
|
|
47
48
|
fov = DEFAULT_FOV,
|
|
48
49
|
angle = DEFAULT_ANGLE,
|
|
49
50
|
onClose,
|
|
51
|
+
onLongPress,
|
|
50
52
|
itemSpacing = DEFAULT_ITEM_SPACING,
|
|
51
53
|
tweenDuration = DEFAULT_TWEEN_DURATION,
|
|
52
54
|
w = 0,
|
|
@@ -127,14 +129,20 @@ export function GalleryViewer({
|
|
|
127
129
|
|
|
128
130
|
const hammer = new Hammer.Manager(el);
|
|
129
131
|
hammer.add(new Hammer.Pan({ direction: Hammer.DIRECTION_HORIZONTAL }));
|
|
130
|
-
|
|
132
|
+
|
|
133
|
+
const singleTap = new Hammer.Tap({ event: "singletap" });
|
|
134
|
+
const press = new Hammer.Press({ event: "longtap", time: 600 });
|
|
135
|
+
|
|
136
|
+
hammer.add([singleTap, press]);
|
|
137
|
+
press.recognizeWith(singleTap);
|
|
138
|
+
singleTap.requireFailure(press);
|
|
131
139
|
|
|
132
140
|
const fixPosition = (ev: any) => {
|
|
133
141
|
const rect = el.getBoundingClientRect();
|
|
134
142
|
return { x: ev.center.x - rect.left, y: ev.center.y - rect.top };
|
|
135
143
|
};
|
|
136
144
|
|
|
137
|
-
hammer.on("
|
|
145
|
+
hammer.on("singletap", (ev) => {
|
|
138
146
|
const pos = fixPosition(ev);
|
|
139
147
|
// TODO: fix this
|
|
140
148
|
if (galleryController.isAnimating()) {
|
|
@@ -149,6 +157,10 @@ export function GalleryViewer({
|
|
|
149
157
|
}
|
|
150
158
|
});
|
|
151
159
|
|
|
160
|
+
hammer.on("longtap", () => {
|
|
161
|
+
onLongPress?.();
|
|
162
|
+
});
|
|
163
|
+
|
|
152
164
|
let lastX: number | undefined = undefined;
|
|
153
165
|
let lastVelocityX = 0;
|
|
154
166
|
|
|
@@ -181,14 +193,16 @@ export function GalleryViewer({
|
|
|
181
193
|
addWheelListener(el, wheelListener);
|
|
182
194
|
|
|
183
195
|
return () => {
|
|
196
|
+
clearTimeout(wheelTimeout);
|
|
184
197
|
hammer.destroy();
|
|
185
198
|
removeWheelListener(el, wheelListener);
|
|
186
199
|
};
|
|
187
|
-
}, [galleryController, onClose]);
|
|
200
|
+
}, [galleryController, onClose, onLongPress]);
|
|
188
201
|
|
|
189
202
|
useEffect(() => {
|
|
190
203
|
TextureReferenceCounter.registerInstance(galleryController);
|
|
191
204
|
return () => {
|
|
205
|
+
galleryController.destroy();
|
|
192
206
|
TextureReferenceCounter.unregisterInstance(galleryController);
|
|
193
207
|
galleryController.sceneWrapper.dispose();
|
|
194
208
|
};
|
|
@@ -84,6 +84,11 @@ export function InlineGalleryDisplay() {
|
|
|
84
84
|
<GalleryViewer
|
|
85
85
|
zFactor={0}
|
|
86
86
|
onClose={() => {}}
|
|
87
|
+
onLongPress={() => {
|
|
88
|
+
setSource(inlineSource);
|
|
89
|
+
setInlineSource(undefined);
|
|
90
|
+
setGalleryDisplayMode("modal");
|
|
91
|
+
}}
|
|
87
92
|
fov={5}
|
|
88
93
|
items={items ?? []}
|
|
89
94
|
tweenDuration={DELAY * animationSpeedMultiplier * 0.8}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState, useCallback } from "react";
|
|
1
|
+
import React, { useEffect, useState, useCallback, useRef } from "react";
|
|
2
2
|
|
|
3
3
|
import { Chit } from "../game/Chit";
|
|
4
4
|
import {
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
IconButton,
|
|
23
23
|
Tooltip,
|
|
24
24
|
} from "@mui/material";
|
|
25
|
-
import { Add, Delete, Refresh, GridOn, PhoneIphone, Tab as TabIcon, Upload, Download } from "@mui/icons-material";
|
|
25
|
+
import { Add, Delete, Refresh, GridOn, PhoneIphone, Tab as TabIcon, Upload, Download, LinkOff } from "@mui/icons-material";
|
|
26
26
|
import useLocalStorageState from "use-local-storage-state";
|
|
27
27
|
import { MatchViewer } from "./MatchViewer";
|
|
28
28
|
import { Game } from "../game/Game";
|
|
@@ -407,26 +407,62 @@ function PlayerEditor({
|
|
|
407
407
|
playerId,
|
|
408
408
|
match,
|
|
409
409
|
showBack,
|
|
410
|
+
disconnectSignal,
|
|
410
411
|
}: {
|
|
411
412
|
showBack?: boolean;
|
|
412
413
|
playerId: string;
|
|
413
414
|
match: Match<any, any>;
|
|
415
|
+
disconnectSignal?: number;
|
|
414
416
|
}) {
|
|
415
417
|
const [localConnection, setLocalConnection] = useState<Connection | undefined>();
|
|
416
|
-
const [,
|
|
418
|
+
const [clientTransport, setClientTransport] = useState<LocalConnectionTransport | null>(null);
|
|
419
|
+
const [serverTransport, setServerTransport] = useState<LocalConnectionTransport | null>(null);
|
|
420
|
+
const clientTransportRef = useRef<LocalConnectionTransport | null>(null);
|
|
417
421
|
|
|
422
|
+
// Create initial transport pair and connect to match
|
|
418
423
|
useEffect(() => {
|
|
419
|
-
const
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
match.connect(
|
|
424
|
+
const server = new LocalConnectionTransport();
|
|
425
|
+
const client = new LocalConnectionTransport();
|
|
426
|
+
client.connect(server);
|
|
427
|
+
match.connect(server, playerId);
|
|
428
|
+
setClientTransport(client);
|
|
429
|
+
setServerTransport(server);
|
|
430
|
+
}, [match, playerId]);
|
|
431
|
+
|
|
432
|
+
// Manage Connection from active client transport (re-runs on reconnect)
|
|
433
|
+
useEffect(() => {
|
|
434
|
+
if (!clientTransport) return;
|
|
435
|
+
const connection = new Connection(clientTransport);
|
|
436
|
+
clientTransportRef.current = clientTransport;
|
|
437
|
+
|
|
438
|
+
const unsub = clientTransport.onReconnect((newTransport) => {
|
|
439
|
+
setClientTransport(newTransport as LocalConnectionTransport);
|
|
440
|
+
});
|
|
423
441
|
|
|
424
|
-
setLocalConnection(
|
|
425
|
-
setRemoteConnection(newRemoteConnection);
|
|
442
|
+
setLocalConnection(connection);
|
|
426
443
|
return () => {
|
|
427
|
-
|
|
444
|
+
unsub();
|
|
445
|
+
clientTransportRef.current = null;
|
|
446
|
+
connection.dispose();
|
|
428
447
|
};
|
|
429
|
-
}, [
|
|
448
|
+
}, [clientTransport]);
|
|
449
|
+
|
|
450
|
+
// Reconnect server-side transport to match when it changes
|
|
451
|
+
useEffect(() => {
|
|
452
|
+
if (!serverTransport) return;
|
|
453
|
+
const unsub = serverTransport.onReconnect((newTransport) => {
|
|
454
|
+
match.connect(newTransport as LocalConnectionTransport, playerId);
|
|
455
|
+
setServerTransport(newTransport as LocalConnectionTransport);
|
|
456
|
+
});
|
|
457
|
+
return () => unsub();
|
|
458
|
+
}, [serverTransport, match, playerId]);
|
|
459
|
+
|
|
460
|
+
// Respond to disconnect signal from toolbar
|
|
461
|
+
useEffect(() => {
|
|
462
|
+
if (disconnectSignal && disconnectSignal > 0) {
|
|
463
|
+
clientTransportRef.current?.simulateDisconnect(2000);
|
|
464
|
+
}
|
|
465
|
+
}, [disconnectSignal]);
|
|
430
466
|
|
|
431
467
|
if (!localConnection) {
|
|
432
468
|
return null;
|
|
@@ -441,7 +477,7 @@ function PlayerEditor({
|
|
|
441
477
|
);
|
|
442
478
|
}
|
|
443
479
|
|
|
444
|
-
function MatchGrid({ match }: { match: Match<any, any
|
|
480
|
+
function MatchGrid({ match, disconnectSignal }: { match: Match<any, any>; disconnectSignal: number }) {
|
|
445
481
|
let rows = Math.ceil(Math.sqrt(match.players.length));
|
|
446
482
|
let columns = Math.ceil(match.players.length / rows);
|
|
447
483
|
|
|
@@ -463,7 +499,7 @@ function MatchGrid({ match }: { match: Match<any, any> }) {
|
|
|
463
499
|
<Stack key={i} direction="row" sx={{ height: `${100 / playerRows.length}%`, width: "100%" }}>
|
|
464
500
|
{ps.map((p) => (
|
|
465
501
|
<Box key={p.id} sx={{ width: `${100 / ps.length}%`, height: "100%" }}>
|
|
466
|
-
<PlayerEditor playerId={p.id} match={match} />
|
|
502
|
+
<PlayerEditor playerId={p.id} match={match} disconnectSignal={disconnectSignal} />
|
|
467
503
|
</Box>
|
|
468
504
|
))}
|
|
469
505
|
</Stack>
|
|
@@ -472,7 +508,7 @@ function MatchGrid({ match }: { match: Match<any, any> }) {
|
|
|
472
508
|
);
|
|
473
509
|
}
|
|
474
510
|
|
|
475
|
-
function MatchTabs({ match }: { match: Match<any, any
|
|
511
|
+
function MatchTabs({ match, disconnectSignal }: { match: Match<any, any>; disconnectSignal: number }) {
|
|
476
512
|
const [tabIndex, setTabIndex] = useLocalStorageState("selectedPlayerIndex", {
|
|
477
513
|
defaultValue: 0,
|
|
478
514
|
});
|
|
@@ -496,20 +532,20 @@ function MatchTabs({ match }: { match: Match<any, any> }) {
|
|
|
496
532
|
</Tabs>
|
|
497
533
|
<Box flex={1} sx={{ height: "100%" }}>
|
|
498
534
|
{[match.players[tabIndex].id].map((id) => (
|
|
499
|
-
<PlayerEditor key={id} playerId={id} match={match} />
|
|
535
|
+
<PlayerEditor key={id} playerId={id} match={match} disconnectSignal={disconnectSignal} />
|
|
500
536
|
))}
|
|
501
537
|
</Box>
|
|
502
538
|
</Stack>
|
|
503
539
|
);
|
|
504
540
|
}
|
|
505
541
|
|
|
506
|
-
function MatchPhone({ match }: { match: Match<any, any
|
|
542
|
+
function MatchPhone({ match, disconnectSignal }: { match: Match<any, any>; disconnectSignal: number }) {
|
|
507
543
|
return (
|
|
508
544
|
<Box sx={{ height: "100%", width: "100%", overflow: "scroll" }}>
|
|
509
545
|
<Stack direction={"row"} sx={{ width: `${390 * match.players.length}px` }}>
|
|
510
546
|
{match.players.map((p) => (
|
|
511
547
|
<Box key={p.id} sx={{ width: `390px`, height: "684px" }}>
|
|
512
|
-
<PlayerEditor showBack playerId={p.id} match={match} />
|
|
548
|
+
<PlayerEditor showBack playerId={p.id} match={match} disconnectSignal={disconnectSignal} />
|
|
513
549
|
</Box>
|
|
514
550
|
))}
|
|
515
551
|
</Stack>
|
|
@@ -521,10 +557,12 @@ function Editor({
|
|
|
521
557
|
layout,
|
|
522
558
|
game,
|
|
523
559
|
matchInfo,
|
|
560
|
+
disconnectSignal,
|
|
524
561
|
}: {
|
|
525
562
|
layout: Layout;
|
|
526
563
|
game: Game<any, any>;
|
|
527
564
|
matchInfo: SavedMatchInfo;
|
|
565
|
+
disconnectSignal: number;
|
|
528
566
|
}) {
|
|
529
567
|
const [match, setMatch] = useState<Match<any, any> | null>(null);
|
|
530
568
|
const [storage, setStorage] = useState<LocalMatchStorage | null>(null);
|
|
@@ -563,9 +601,9 @@ function Editor({
|
|
|
563
601
|
|
|
564
602
|
return (
|
|
565
603
|
<GameProvider game={game}>
|
|
566
|
-
{layout === "tile" && <MatchGrid match={match} />}
|
|
567
|
-
{layout === "tab" && <MatchTabs match={match} />}
|
|
568
|
-
{layout === "phone" && <MatchPhone match={match} />}
|
|
604
|
+
{layout === "tile" && <MatchGrid match={match} disconnectSignal={disconnectSignal} />}
|
|
605
|
+
{layout === "tab" && <MatchTabs match={match} disconnectSignal={disconnectSignal} />}
|
|
606
|
+
{layout === "phone" && <MatchPhone match={match} disconnectSignal={disconnectSignal} />}
|
|
569
607
|
</GameProvider>
|
|
570
608
|
);
|
|
571
609
|
}
|
|
@@ -585,6 +623,8 @@ export default function Playground({ game }: { game: Game<any, any> }) {
|
|
|
585
623
|
const [matchKey, setMatchKey] = useState(0); // For forcing re-render on reset
|
|
586
624
|
const [loadStateDialogOpen, setLoadStateDialogOpen] = useState(false);
|
|
587
625
|
const [exportStateDialogOpen, setExportStateDialogOpen] = useState(false);
|
|
626
|
+
const [disconnectSignal, setDisconnectSignal] = useState(0);
|
|
627
|
+
const [isDisconnected, setIsDisconnected] = useState(false);
|
|
588
628
|
|
|
589
629
|
const gameName = game.metadata.name;
|
|
590
630
|
|
|
@@ -796,6 +836,21 @@ export default function Playground({ game }: { game: Game<any, any> }) {
|
|
|
796
836
|
</IconButton>
|
|
797
837
|
</Tooltip>
|
|
798
838
|
|
|
839
|
+
<Tooltip title={isDisconnected ? "Reconnecting..." : "Simulate Disconnect"}>
|
|
840
|
+
<IconButton
|
|
841
|
+
onClick={() => {
|
|
842
|
+
setIsDisconnected(true);
|
|
843
|
+
setDisconnectSignal((prev) => prev + 1);
|
|
844
|
+
setTimeout(() => setIsDisconnected(false), 2000);
|
|
845
|
+
}}
|
|
846
|
+
size="small"
|
|
847
|
+
disabled={isDisconnected || !selectedMatchId}
|
|
848
|
+
color={isDisconnected ? "error" : "default"}
|
|
849
|
+
>
|
|
850
|
+
<LinkOff />
|
|
851
|
+
</IconButton>
|
|
852
|
+
</Tooltip>
|
|
853
|
+
|
|
799
854
|
<Box sx={{ flexGrow: 1 }} />
|
|
800
855
|
|
|
801
856
|
{loadingProgress && <Box sx={{ mr: 2 }}>{loadingProgress}</Box>}
|
|
@@ -825,6 +880,7 @@ export default function Playground({ game }: { game: Game<any, any> }) {
|
|
|
825
880
|
layout={layout}
|
|
826
881
|
game={game}
|
|
827
882
|
matchInfo={selectedMatch}
|
|
883
|
+
disconnectSignal={disconnectSignal}
|
|
828
884
|
/>
|
|
829
885
|
)}
|
|
830
886
|
</Box>
|
|
@@ -21,13 +21,21 @@ export function ServerTrustMatchViewer({
|
|
|
21
21
|
onBack?: () => void;
|
|
22
22
|
onLoadProgress?: LoadingStatesCallback;
|
|
23
23
|
}) {
|
|
24
|
+
const [activeTransport, setActiveTransport] = useState<ConnectionTransport>(transport);
|
|
24
25
|
const [loadingStates] = useState<LoadingStates>(new LoadingStates());
|
|
25
26
|
const [localConnection, setLocalConnection] = useState<Connection | undefined>();
|
|
26
27
|
|
|
27
28
|
useEffect(() => {
|
|
28
|
-
const newConnection = new Connection(
|
|
29
|
+
const newConnection = new Connection(activeTransport);
|
|
30
|
+
const unsubscribe = activeTransport.onReconnect((transport) => {
|
|
31
|
+
setActiveTransport(transport);
|
|
32
|
+
});
|
|
29
33
|
setLocalConnection(newConnection);
|
|
30
|
-
|
|
34
|
+
return () => {
|
|
35
|
+
unsubscribe();
|
|
36
|
+
newConnection.dispose();
|
|
37
|
+
};
|
|
38
|
+
}, [activeTransport]);
|
|
31
39
|
|
|
32
40
|
useEffect(() => {
|
|
33
41
|
if (onLoadProgress) {
|
|
@@ -27,34 +27,67 @@ interface SparkLineChartProps {
|
|
|
27
27
|
width?: number;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
function getColorLuminance(color: string): number {
|
|
32
|
-
// Convert hex to RGB
|
|
33
|
-
const hex = color.replace("#", "");
|
|
34
|
-
const r = parseInt(hex.substr(0, 2), 16) / 255;
|
|
35
|
-
const g = parseInt(hex.substr(2, 2), 16) / 255;
|
|
36
|
-
const b = parseInt(hex.substr(4, 2), 16) / 255;
|
|
30
|
+
const HALO_OPACITY = 0.35;
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
const
|
|
32
|
+
function hexToLinearRgb(color: string): { r: number; g: number; b: number } {
|
|
33
|
+
const hex = color.replace("#", "");
|
|
34
|
+
const toLin = (n: number) => {
|
|
35
|
+
const c = n / 255;
|
|
40
36
|
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
41
|
-
}
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
r: toLin(parseInt(hex.slice(0, 2), 16)),
|
|
40
|
+
g: toLin(parseInt(hex.slice(2, 4), 16)),
|
|
41
|
+
b: toLin(parseInt(hex.slice(4, 6), 16)),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getColorLuminance(color: string): number {
|
|
46
|
+
const { r, g, b } = hexToLinearRgb(color);
|
|
47
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
48
|
+
}
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
// Convert sRGB hex → CIE Lab (D65), so we can measure perceptual distance.
|
|
51
|
+
function hexToLab(color: string): { L: number; a: number; b: number } {
|
|
52
|
+
const { r, g, b } = hexToLinearRgb(color);
|
|
53
|
+
const X = (r * 0.4124564 + g * 0.3575761 + b * 0.1804375) / 0.95047;
|
|
54
|
+
const Y = r * 0.2126729 + g * 0.7151522 + b * 0.072175;
|
|
55
|
+
const Z = (r * 0.0193339 + g * 0.119192 + b * 0.9503041) / 1.08883;
|
|
56
|
+
const f = (t: number) => (t > 0.008856 ? Math.cbrt(t) : 7.787 * t + 16 / 116);
|
|
57
|
+
const fx = f(X);
|
|
58
|
+
const fy = f(Y);
|
|
59
|
+
const fz = f(Z);
|
|
60
|
+
return { L: 116 * fy - 16, a: 500 * (fx - fy), b: 200 * (fy - fz) };
|
|
44
61
|
}
|
|
45
62
|
|
|
46
|
-
//
|
|
63
|
+
// Perceptual contrast: a stroke is only needed if both luminance AND hue/chroma
|
|
64
|
+
// are too close to distinguish. Pure red vs pure green have similar luminance
|
|
65
|
+
// but enormous Lab distance, so they should pass without an outline.
|
|
47
66
|
function hasGoodContrast(color1: string, color2: string): boolean {
|
|
48
67
|
const lum1 = getColorLuminance(color1);
|
|
49
68
|
const lum2 = getColorLuminance(color2);
|
|
50
|
-
const
|
|
51
|
-
|
|
69
|
+
const lumRatio = (Math.max(lum1, lum2) + 0.05) / (Math.min(lum1, lum2) + 0.05);
|
|
70
|
+
if (lumRatio >= 3) return true;
|
|
71
|
+
|
|
72
|
+
const lab1 = hexToLab(color1);
|
|
73
|
+
const lab2 = hexToLab(color2);
|
|
74
|
+
const dL = lab1.L - lab2.L;
|
|
75
|
+
const da = lab1.a - lab2.a;
|
|
76
|
+
const db = lab1.b - lab2.b;
|
|
77
|
+
const deltaE = Math.sqrt(dL * dL + da * da + db * db);
|
|
78
|
+
return deltaE >= 35;
|
|
52
79
|
}
|
|
53
80
|
|
|
54
|
-
//
|
|
81
|
+
// The halo has to separate the line from BOTH the background and the line color
|
|
82
|
+
// itself — a white halo around a light-teal line on a dark-teal bg merges into
|
|
83
|
+
// the line and reads as fuzz. Pick black or white by whichever gives the higher
|
|
84
|
+
// minimum WCAG contrast against line and bg simultaneously.
|
|
55
85
|
function getStrokeColor(lineColor: string, backgroundColor: string): string {
|
|
56
86
|
const lineLum = getColorLuminance(lineColor);
|
|
57
|
-
|
|
87
|
+
const bgLum = getColorLuminance(backgroundColor);
|
|
88
|
+
const blackMin = Math.min((lineLum + 0.05) / 0.05, (bgLum + 0.05) / 0.05);
|
|
89
|
+
const whiteMin = Math.min(1.05 / (lineLum + 0.05), 1.05 / (bgLum + 0.05));
|
|
90
|
+
return blackMin >= whiteMin ? "#000000" : "#ffffff";
|
|
58
91
|
}
|
|
59
92
|
|
|
60
93
|
export function SparkLineChart({
|
|
@@ -169,6 +202,10 @@ export function SparkLineChart({
|
|
|
169
202
|
const getY = (value: number) => chartHeight - ((value - chartMinValue) / chartValueRange) * chartHeight;
|
|
170
203
|
const chartEndX = chartWidth;
|
|
171
204
|
|
|
205
|
+
// If any line needs a halo, give one to all of them so the chart reads
|
|
206
|
+
// consistently — singling out one line with an outline looks arbitrary.
|
|
207
|
+
const anyNeedsStroke = lines.some((line) => !hasGoodContrast(line.color, backgroundColor));
|
|
208
|
+
|
|
172
209
|
return (
|
|
173
210
|
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center", my: 4 }}>
|
|
174
211
|
<Typography variant="h6" sx={{ mb: 2 }}>
|
|
@@ -181,6 +218,14 @@ export function SparkLineChart({
|
|
|
181
218
|
preserveAspectRatio="preserve"
|
|
182
219
|
style={{ overflow: "visible", maxWidth: "100%" }}
|
|
183
220
|
>
|
|
221
|
+
<defs>
|
|
222
|
+
{/* Soften halo edges so the contrast outline reads as a smooth glow,
|
|
223
|
+
not a stairstepped stroke. */}
|
|
224
|
+
<filter id="sparkline-soften" x="-10%" y="-10%" width="120%" height="120%">
|
|
225
|
+
<feGaussianBlur stdDeviation="0.6" />
|
|
226
|
+
</filter>
|
|
227
|
+
</defs>
|
|
228
|
+
|
|
184
229
|
{/* Grid lines */}
|
|
185
230
|
<g opacity={0.1}>
|
|
186
231
|
{[0, 0.25, 0.5, 0.75, 1].map((ratio) => {
|
|
@@ -193,12 +238,15 @@ export function SparkLineChart({
|
|
|
193
238
|
|
|
194
239
|
{/* Draw each line */}
|
|
195
240
|
{lines.map((line) => {
|
|
196
|
-
//
|
|
241
|
+
// Step interpolation: values change instantaneously in the game (e.g. $0 → $50
|
|
242
|
+
// at t=100), so hold the previous value until the new clock, then jump vertically.
|
|
197
243
|
const pathData = line.points
|
|
198
244
|
.map((point, index) => {
|
|
199
245
|
const x = getX(point.clock);
|
|
200
246
|
const y = getY(point.value);
|
|
201
|
-
|
|
247
|
+
if (index === 0) return `M ${x} ${y}`;
|
|
248
|
+
const prevY = getY(line.points[index - 1].value);
|
|
249
|
+
return `L ${x} ${prevY} L ${x} ${y}`;
|
|
202
250
|
})
|
|
203
251
|
.join(" ");
|
|
204
252
|
|
|
@@ -207,8 +255,9 @@ export function SparkLineChart({
|
|
|
207
255
|
const lastY = getY(lastPoint.value);
|
|
208
256
|
const extendedPathData = `${pathData} L ${chartEndX} ${lastY}`;
|
|
209
257
|
|
|
210
|
-
//
|
|
211
|
-
|
|
258
|
+
// All lines get the same halo treatment if any line needs one — picked
|
|
259
|
+
// per line so each gets the right black/white for its own color.
|
|
260
|
+
const needsStroke = anyNeedsStroke;
|
|
212
261
|
const strokeColor = needsStroke ? getStrokeColor(line.color, backgroundColor) : undefined;
|
|
213
262
|
|
|
214
263
|
const adjustedLabelY = labelPositions[line.id];
|
|
@@ -221,10 +270,11 @@ export function SparkLineChart({
|
|
|
221
270
|
d={extendedPathData}
|
|
222
271
|
fill="none"
|
|
223
272
|
stroke={strokeColor}
|
|
224
|
-
strokeWidth={
|
|
273
|
+
strokeWidth={6}
|
|
225
274
|
strokeLinecap="round"
|
|
226
275
|
strokeLinejoin="round"
|
|
227
|
-
|
|
276
|
+
filter="url(#sparkline-soften)"
|
|
277
|
+
opacity={HALO_OPACITY}
|
|
228
278
|
/>
|
|
229
279
|
)}
|
|
230
280
|
<path
|
|
@@ -277,7 +327,9 @@ export function SparkLineChart({
|
|
|
277
327
|
dominantBaseline="middle"
|
|
278
328
|
fill={strokeColor}
|
|
279
329
|
stroke={strokeColor}
|
|
280
|
-
strokeWidth={
|
|
330
|
+
strokeWidth={5}
|
|
331
|
+
filter="url(#sparkline-soften)"
|
|
332
|
+
opacity={HALO_OPACITY}
|
|
281
333
|
>
|
|
282
334
|
{line.finalValue}
|
|
283
335
|
</text>
|
|
@@ -288,7 +340,16 @@ export function SparkLineChart({
|
|
|
288
340
|
</g>
|
|
289
341
|
|
|
290
342
|
{/* End point marker */}
|
|
291
|
-
{needsStroke &&
|
|
343
|
+
{needsStroke && (
|
|
344
|
+
<circle
|
|
345
|
+
cx={chartEndX}
|
|
346
|
+
cy={lastY}
|
|
347
|
+
r={6}
|
|
348
|
+
fill={strokeColor}
|
|
349
|
+
filter="url(#sparkline-soften)"
|
|
350
|
+
opacity={HALO_OPACITY}
|
|
351
|
+
/>
|
|
352
|
+
)}
|
|
292
353
|
<circle cx={chartEndX} cy={lastY} r={3} fill={line.color} />
|
|
293
354
|
</g>
|
|
294
355
|
);
|
|
@@ -148,7 +148,10 @@ export default function Viewer({
|
|
|
148
148
|
return;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
//
|
|
151
|
+
// Re-render when WebGL context is restored after a loss
|
|
152
|
+
const unsubDirty = rendererWrapper.onDirty(() => {
|
|
153
|
+
chitRenderInstance.markDirty();
|
|
154
|
+
});
|
|
152
155
|
|
|
153
156
|
let renderNextFrame: boolean | undefined;
|
|
154
157
|
let cancelled = false;
|
|
@@ -169,14 +172,18 @@ export default function Viewer({
|
|
|
169
172
|
) {
|
|
170
173
|
if (!hardPaused) {
|
|
171
174
|
// Clear canvas and render
|
|
172
|
-
rendererWrapper.render(chitRenderInstance.sceneWrapper, chitRenderInstance.camera, context, theme);
|
|
175
|
+
const drew = rendererWrapper.render(chitRenderInstance.sceneWrapper, chitRenderInstance.camera, context, theme, id);
|
|
173
176
|
|
|
174
177
|
loadingState.setLoading(id, false);
|
|
175
178
|
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
179
|
+
// Only clear the snapshot overlay once we've actually painted a fresh frame.
|
|
180
|
+
// If render bailed (e.g. WebGL context lost), keeping the snapshot visible
|
|
181
|
+
// avoids a blank canvas until the context is restored.
|
|
182
|
+
if (drew) {
|
|
183
|
+
const canvasEl = canvas as any;
|
|
184
|
+
if (canvasEl.clearSnapshot) {
|
|
185
|
+
canvasEl.clearSnapshot();
|
|
186
|
+
}
|
|
180
187
|
}
|
|
181
188
|
} else {
|
|
182
189
|
loadingState.setLoading(id, false);
|
|
@@ -200,6 +207,8 @@ export default function Viewer({
|
|
|
200
207
|
return () => {
|
|
201
208
|
timeState.setAnimationState(id, false);
|
|
202
209
|
cancelled = true;
|
|
210
|
+
unsubDirty();
|
|
211
|
+
rendererWrapper.unregisterViewerSize(id);
|
|
203
212
|
};
|
|
204
213
|
}, [
|
|
205
214
|
id,
|
|
@@ -64,3 +64,94 @@ test("chit references", () => {
|
|
|
64
64
|
// TODO: maybe assigning parentoutlet should be two way street? but probably doesn't matter and serialization and deserialization will always go
|
|
65
65
|
// at the same time.
|
|
66
66
|
});
|
|
67
|
+
|
|
68
|
+
test("dirty tracking: unchanged chit returns cached serialization", () => {
|
|
69
|
+
const c = new ChitSubClass();
|
|
70
|
+
const first = c.serialize();
|
|
71
|
+
const second = c.serialize();
|
|
72
|
+
// Same reference — no re-serialization happened
|
|
73
|
+
expect(second).toBe(first);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("dirty tracking: property assignment marks dirty", () => {
|
|
77
|
+
const c = new ChitSubClass();
|
|
78
|
+
const first = c.serialize();
|
|
79
|
+
c.s1 = "changed";
|
|
80
|
+
expect(c._dirty).toBe(true);
|
|
81
|
+
const second = c.serialize();
|
|
82
|
+
expect(second).not.toBe(first);
|
|
83
|
+
expect(JSON.parse(second).s1).toBe("changed");
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("dirty tracking: same-value assignment does not mark dirty", () => {
|
|
87
|
+
const c = new ChitSubClass();
|
|
88
|
+
c.serialize(); // instrument + cache
|
|
89
|
+
expect(c._dirty).toBe(false);
|
|
90
|
+
c.s1 = "s1"; // same value
|
|
91
|
+
expect(c._dirty).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("dirty tracking: nested object mutation marks dirty via proxy", () => {
|
|
95
|
+
const c = new ChitSubClass();
|
|
96
|
+
c.serialize(); // instrument + cache
|
|
97
|
+
expect(c._dirty).toBe(false);
|
|
98
|
+
c.o1.a = 99;
|
|
99
|
+
expect(c._dirty).toBe(true);
|
|
100
|
+
const serialized = c.serialize();
|
|
101
|
+
expect(JSON.parse(serialized).o1.a).toBe(99);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("dirty tracking: setParent marks child and parents dirty", () => {
|
|
105
|
+
const parent1 = new ChitSubClass();
|
|
106
|
+
const parent2 = new ChitSubClass();
|
|
107
|
+
const child = new ChitSubClass();
|
|
108
|
+
parent1.id = "p1";
|
|
109
|
+
parent2.id = "p2";
|
|
110
|
+
child.id = "child";
|
|
111
|
+
|
|
112
|
+
// Serialize all to clear dirty flags
|
|
113
|
+
parent1.serialize();
|
|
114
|
+
parent2.serialize();
|
|
115
|
+
child.serialize();
|
|
116
|
+
|
|
117
|
+
child.setParent(parent1, "orderedChildren", 0);
|
|
118
|
+
expect(child._dirty).toBe(true);
|
|
119
|
+
expect(parent1._dirty).toBe(true);
|
|
120
|
+
|
|
121
|
+
// Clear dirty
|
|
122
|
+
child.serialize();
|
|
123
|
+
parent1.serialize();
|
|
124
|
+
parent2.serialize();
|
|
125
|
+
|
|
126
|
+
// Reparent
|
|
127
|
+
child.setParent(parent2, "orderedChildren", 0);
|
|
128
|
+
expect(child._dirty).toBe(true);
|
|
129
|
+
expect(parent1._dirty).toBe(true); // old parent
|
|
130
|
+
expect(parent2._dirty).toBe(true); // new parent
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("dirty tracking: deserialize marks dirty and clears cache", () => {
|
|
134
|
+
const c = new ChitSubClass();
|
|
135
|
+
const serialized = c.serialize();
|
|
136
|
+
expect(c._dirty).toBe(false);
|
|
137
|
+
|
|
138
|
+
c.deserialize(serialized, () => c, true);
|
|
139
|
+
expect(c._dirty).toBe(true);
|
|
140
|
+
expect((c as any)._lastSerialized).toBeUndefined();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test("dirty tracking: array mutation via proxy marks dirty", () => {
|
|
144
|
+
class ChitWithArray extends Chit {
|
|
145
|
+
public items: number[] = [1, 2, 3];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const c = new ChitWithArray();
|
|
149
|
+
c.serialize();
|
|
150
|
+
expect(c._dirty).toBe(false);
|
|
151
|
+
|
|
152
|
+
c.items.push(4);
|
|
153
|
+
expect(c._dirty).toBe(true);
|
|
154
|
+
|
|
155
|
+
const serialized = c.serialize();
|
|
156
|
+
expect(JSON.parse(serialized).items).toEqual([1, 2, 3, 4]);
|
|
157
|
+
});
|