@pretty-chitty/core 1.2.9 → 1.2.15
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 +23 -0
- package/dist/components/ActionLogDisplay.js +1 -1
- package/dist/components/ActionLogDisplay.js.map +1 -1
- package/dist/components/ActionLogHistory.js +1 -1
- package/dist/components/ActionLogHistory.js.map +1 -1
- package/dist/components/BottomBarButton.d.ts.map +1 -1
- package/dist/components/BottomBarButton.js +12 -1
- package/dist/components/BottomBarButton.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/GameDialog.js +1 -1
- package/dist/components/GameDialog.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/TopBarDropdown.js +4 -4
- package/dist/components/TopBarDropdown.js.map +1 -1
- package/dist/components/TopBarPlayers.d.ts.map +1 -1
- package/dist/components/TopBarPlayers.js +9 -3
- package/dist/components/TopBarPlayers.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/GameTheme.d.ts +3 -0
- package/dist/game/GameTheme.d.ts.map +1 -1
- package/dist/game/GameTheme.js +3 -0
- package/dist/game/GameTheme.js.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.map +1 -1
- package/dist/game/badAiTransport/BadAIClientPrompts.js +24 -4
- 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 +179 -6
- 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/ActionLogDisplay.tsx +1 -1
- package/src/library/components/ActionLogHistory.tsx +2 -2
- package/src/library/components/BottomBarButton.tsx +19 -2
- 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/GameDialog.tsx +1 -1
- 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/TopBarDropdown.tsx +4 -4
- package/src/library/components/TopBarPlayers.tsx +9 -3
- 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/GameTheme.ts +4 -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 +21 -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 +212 -6
- 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
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
UVMapping,
|
|
4
4
|
ClampToEdgeWrapping,
|
|
5
5
|
LinearFilter,
|
|
6
|
+
LinearMipmapLinearFilter,
|
|
6
7
|
MeshPhongMaterial,
|
|
7
8
|
Material,
|
|
8
9
|
SRGBColorSpace,
|
|
@@ -12,6 +13,7 @@ import { IUpdatingCanvas } from "../IUpdatingCanvas";
|
|
|
12
13
|
import { CanvasOperation } from "./CanvasOperations";
|
|
13
14
|
import { ImageResult, ImageCache } from "./ImageCache";
|
|
14
15
|
import { ThreeDisposer } from "../ThreeDisposer";
|
|
16
|
+
import { getWebGlRendererInstance } from "../../hooks/useWebGlRenderer";
|
|
15
17
|
|
|
16
18
|
export type RenderBounds = {
|
|
17
19
|
x: number;
|
|
@@ -96,6 +98,7 @@ export class CanvasStack implements IUpdatingCanvas {
|
|
|
96
98
|
this.canvas!.title = `Disposed, mat ${this._material?.uuid} texture ${this._texture?.uuid}`;
|
|
97
99
|
this.canvas = undefined;
|
|
98
100
|
this.context = undefined;
|
|
101
|
+
CanvasStack._liveStacks.delete(this);
|
|
99
102
|
|
|
100
103
|
if (this._material) {
|
|
101
104
|
this._material.dispose();
|
|
@@ -122,9 +125,35 @@ export class CanvasStack implements IUpdatingCanvas {
|
|
|
122
125
|
}
|
|
123
126
|
this.context = context;
|
|
124
127
|
|
|
128
|
+
CanvasStack._liveStacks.add(this);
|
|
129
|
+
CanvasStack.ensureContextRestoreSubscription();
|
|
130
|
+
|
|
125
131
|
this.render();
|
|
126
132
|
}
|
|
127
133
|
|
|
134
|
+
private static _liveStacks: Set<CanvasStack> = new Set();
|
|
135
|
+
private static _restoreSubscribed = false;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* After a WebGL context restore, GPU-side textures are gone. The 2D canvas
|
|
139
|
+
* backing data is still valid, but three.js needs to be told to re-upload it.
|
|
140
|
+
* Subscribe once to the renderer's restore notification and re-flag every
|
|
141
|
+
* live instance's texture.
|
|
142
|
+
*/
|
|
143
|
+
private static ensureContextRestoreSubscription() {
|
|
144
|
+
if (CanvasStack._restoreSubscribed) return;
|
|
145
|
+
const wrapper = getWebGlRendererInstance();
|
|
146
|
+
if (!wrapper) return;
|
|
147
|
+
CanvasStack._restoreSubscribed = true;
|
|
148
|
+
wrapper.onDirty(() => {
|
|
149
|
+
for (const stack of CanvasStack._liveStacks) {
|
|
150
|
+
if (stack._texture) {
|
|
151
|
+
stack._texture.needsUpdate = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
128
157
|
get outlets() {
|
|
129
158
|
return this._outlets;
|
|
130
159
|
}
|
|
@@ -146,14 +175,18 @@ export class CanvasStack implements IUpdatingCanvas {
|
|
|
146
175
|
}
|
|
147
176
|
|
|
148
177
|
if (!this._texture) {
|
|
178
|
+
// WebGL1 only supports mipmaps on power-of-two textures, and these
|
|
179
|
+
// canvases are arbitrarily sized. Skip mipmap generation outside WebGL2.
|
|
180
|
+
const useMipmaps = getWebGlRendererInstance()?.isWebGL2 ?? false;
|
|
149
181
|
this._texture = new Texture(
|
|
150
182
|
this.canvas,
|
|
151
183
|
UVMapping,
|
|
152
184
|
ClampToEdgeWrapping,
|
|
153
185
|
ClampToEdgeWrapping,
|
|
154
186
|
LinearFilter,
|
|
155
|
-
LinearFilter,
|
|
187
|
+
useMipmaps ? LinearMipmapLinearFilter : LinearFilter,
|
|
156
188
|
);
|
|
189
|
+
this._texture.generateMipmaps = useMipmaps;
|
|
157
190
|
this._texture.needsUpdate = true;
|
|
158
191
|
this._texture.colorSpace = SRGBColorSpace;
|
|
159
192
|
|
|
@@ -179,6 +212,10 @@ export class CanvasStack implements IUpdatingCanvas {
|
|
|
179
212
|
canvasStack._texture.source.data = _NOTHING_CANVAS; // prevent memory leaks! somehow it holding this reference stops the GC from cleaning anything up
|
|
180
213
|
canvasStack._texture = undefined;
|
|
181
214
|
}
|
|
215
|
+
// Drop the strong reference so the instance can be GC'd. Both this
|
|
216
|
+
// path and the explicit dispose() can run for the same stack — Set.delete
|
|
217
|
+
// is idempotent, so the duplicate is harmless.
|
|
218
|
+
CanvasStack._liveStacks.delete(canvasStack);
|
|
182
219
|
});
|
|
183
220
|
|
|
184
221
|
public static materialDisposer = new ThreeDisposer<Material>((material) => {
|
|
@@ -17,6 +17,8 @@ export interface IconMap {
|
|
|
17
17
|
[name: string]: SpriteRef | undefined;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export type WordBreak = "break-all" | "keep-all" | "keep-words";
|
|
21
|
+
|
|
20
22
|
export type RichTextRenderOptionsParameters = {
|
|
21
23
|
fontFamily?: string;
|
|
22
24
|
fontSize?: number;
|
|
@@ -27,6 +29,7 @@ export type RichTextRenderOptionsParameters = {
|
|
|
27
29
|
iconMap?: IconMap;
|
|
28
30
|
iconBaseline?: IconBaseline;
|
|
29
31
|
iconScale?: number; // 1.0 = same height as text
|
|
32
|
+
wordBreak?: WordBreak; // "keep-all" prevents word breaking/hyphenation
|
|
30
33
|
};
|
|
31
34
|
|
|
32
35
|
export interface RenderOptions extends RichTextRenderOptionsParameters {
|
|
@@ -89,6 +92,7 @@ export class RichTextRenderer {
|
|
|
89
92
|
iconBaseline = "text",
|
|
90
93
|
iconScale = 1.0,
|
|
91
94
|
debug = false,
|
|
95
|
+
wordBreak,
|
|
92
96
|
} = opts;
|
|
93
97
|
|
|
94
98
|
if (!maxWidth || maxWidth <= 0) {
|
|
@@ -105,7 +109,7 @@ export class RichTextRenderer {
|
|
|
105
109
|
|
|
106
110
|
const tokens = this.tokenize(text);
|
|
107
111
|
const runs = this.expandRuns(tokens);
|
|
108
|
-
const lines = this.layoutRunsToLines(ctx, runs, metrics, maxWidth, iconMap);
|
|
112
|
+
const lines = this.layoutRunsToLines(ctx, runs, metrics, maxWidth, iconMap, wordBreak);
|
|
109
113
|
|
|
110
114
|
// Draw
|
|
111
115
|
ctx.save();
|
|
@@ -162,17 +166,23 @@ export class RichTextRenderer {
|
|
|
162
166
|
sprite.width > 0 &&
|
|
163
167
|
sprite.height > 0
|
|
164
168
|
) {
|
|
169
|
+
// Inset source rect by half a texel so bilinear filtering
|
|
170
|
+
// never samples neighboring sprites in the spritesheet.
|
|
171
|
+
const inset = 0.5;
|
|
172
|
+
const prevSmoothing = ctx.imageSmoothingEnabled;
|
|
173
|
+
ctx.imageSmoothingEnabled = false;
|
|
165
174
|
ctx.drawImage(
|
|
166
175
|
sprite.image,
|
|
167
|
-
sprite.x,
|
|
168
|
-
sprite.y,
|
|
169
|
-
sprite.width,
|
|
170
|
-
sprite.height, // source rect
|
|
176
|
+
sprite.x + inset,
|
|
177
|
+
sprite.y + inset,
|
|
178
|
+
sprite.width - inset * 2,
|
|
179
|
+
sprite.height - inset * 2, // source rect
|
|
171
180
|
Math.round(cursorX),
|
|
172
181
|
Math.round(drawY),
|
|
173
182
|
Math.round(seg.width),
|
|
174
183
|
Math.round(seg.height), // destination rect (aspect preserved)
|
|
175
184
|
);
|
|
185
|
+
ctx.imageSmoothingEnabled = prevSmoothing;
|
|
176
186
|
} else {
|
|
177
187
|
// Placeholder box with preserved layout size
|
|
178
188
|
ctx.save();
|
|
@@ -325,6 +335,7 @@ export class RichTextRenderer {
|
|
|
325
335
|
metrics: Metrics,
|
|
326
336
|
maxWidth: number,
|
|
327
337
|
iconMap: IconMap,
|
|
338
|
+
wordBreak?: WordBreak,
|
|
328
339
|
): Line[] {
|
|
329
340
|
const lines: Line[] = [];
|
|
330
341
|
let line: Line = this.newLine();
|
|
@@ -417,6 +428,56 @@ export class RichTextRenderer {
|
|
|
417
428
|
continue;
|
|
418
429
|
}
|
|
419
430
|
|
|
431
|
+
// In keep-all mode, never break words — move to next line and let long words overflow.
|
|
432
|
+
if (wordBreak === "keep-all") {
|
|
433
|
+
if (cursorW > 0) {
|
|
434
|
+
flushLine(true);
|
|
435
|
+
}
|
|
436
|
+
line.segments.push({
|
|
437
|
+
kind: "text",
|
|
438
|
+
text: r.text,
|
|
439
|
+
width: wordWidth,
|
|
440
|
+
style: { bold: r.bold, italic: r.italic },
|
|
441
|
+
});
|
|
442
|
+
cursorW = wordWidth;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// In keep-words mode, don't break words mid-line, but hyphenate if a word
|
|
447
|
+
// is too wide to fit on a line by itself.
|
|
448
|
+
if (wordBreak === "keep-words") {
|
|
449
|
+
if (cursorW > 0) {
|
|
450
|
+
flushLine(true);
|
|
451
|
+
}
|
|
452
|
+
if (wordWidth > maxWidth) {
|
|
453
|
+
// Word doesn't fit on a line by itself — hyphenate it.
|
|
454
|
+
const res = this.hyphenateIntoLines(
|
|
455
|
+
ctx,
|
|
456
|
+
r.text,
|
|
457
|
+
r,
|
|
458
|
+
styleKey,
|
|
459
|
+
metrics,
|
|
460
|
+
maxWidth,
|
|
461
|
+
lines,
|
|
462
|
+
line,
|
|
463
|
+
0,
|
|
464
|
+
maxWidth,
|
|
465
|
+
hyphenWidth(styleKey),
|
|
466
|
+
);
|
|
467
|
+
line = res.line;
|
|
468
|
+
cursorW = res.cursorW;
|
|
469
|
+
} else {
|
|
470
|
+
line.segments.push({
|
|
471
|
+
kind: "text",
|
|
472
|
+
text: r.text,
|
|
473
|
+
width: wordWidth,
|
|
474
|
+
style: { bold: r.bold, italic: r.italic },
|
|
475
|
+
});
|
|
476
|
+
cursorW = wordWidth;
|
|
477
|
+
}
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
|
|
420
481
|
// If it doesn't fit the tail…
|
|
421
482
|
if (cursorW > 0) {
|
|
422
483
|
// …and the word is "long" (over threshold), try hyphenating into the remaining space.
|