@blorkfield/overlay-core 0.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.
- package/README.md +417 -0
- package/dist/index.cjs +2519 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +700 -0
- package/dist/index.d.ts +700 -0
- package/dist/index.js +2474 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
import opentype from 'opentype.js';
|
|
2
|
+
|
|
3
|
+
interface OverlaySceneConfig {
|
|
4
|
+
bounds: Bounds;
|
|
5
|
+
gravity?: number;
|
|
6
|
+
wrapHorizontal?: boolean;
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
background?: string;
|
|
9
|
+
/** @deprecated Use floorConfig instead. Pressure threshold for the floor boundary. */
|
|
10
|
+
floorThreshold?: number;
|
|
11
|
+
/** Distance below floor (as fraction of container height) at which objects despawn. Default: 1.0 (100%) */
|
|
12
|
+
despawnBelowFloor?: number;
|
|
13
|
+
/** Configuration for floor segments and thresholds */
|
|
14
|
+
floorConfig?: FloorConfig;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for floor segments and pressure thresholds.
|
|
18
|
+
* When provided, floor can be divided into segments with individual collapse behavior.
|
|
19
|
+
*/
|
|
20
|
+
interface FloorConfig {
|
|
21
|
+
/**
|
|
22
|
+
* Number of segments to divide the floor into.
|
|
23
|
+
* If not provided or 1, floor is a single strip.
|
|
24
|
+
*/
|
|
25
|
+
segments?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Pressure threshold(s) for floor segments:
|
|
28
|
+
* - number: Same threshold for all segments
|
|
29
|
+
* - number[]: Per-segment thresholds (segment 0 uses value[0], etc.)
|
|
30
|
+
* If not provided, segments have infinite capacity.
|
|
31
|
+
*/
|
|
32
|
+
threshold?: number | number[];
|
|
33
|
+
}
|
|
34
|
+
interface Bounds {
|
|
35
|
+
top: number;
|
|
36
|
+
bottom: number;
|
|
37
|
+
left: number;
|
|
38
|
+
right: number;
|
|
39
|
+
}
|
|
40
|
+
type ShapePreset = 'circle' | 'rectangle' | 'polygon' | 'hexagon' | 'octagon' | 'triangle' | 'pentagon';
|
|
41
|
+
interface ShapeConfig {
|
|
42
|
+
/** Shape type - preset name or 'polygon' for n-gon. Image shape extraction is automatic when imageUrl provided */
|
|
43
|
+
type: ShapePreset;
|
|
44
|
+
/** For rectangle: aspect ratio (width/height). Default 1 */
|
|
45
|
+
aspectRatio?: number;
|
|
46
|
+
/** Number of sides for polygon shapes. Required for 'polygon', optional override for presets */
|
|
47
|
+
sides?: number;
|
|
48
|
+
/** Custom vertices (overrides type). Array of {x, y} relative to center */
|
|
49
|
+
vertices?: Array<{
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
}>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for despawn effects (placeholder for future custom effects)
|
|
56
|
+
*/
|
|
57
|
+
interface DespawnEffectConfig {
|
|
58
|
+
/** Effect type identifier for future use */
|
|
59
|
+
type?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Unified configuration for spawning scene objects.
|
|
63
|
+
* Objects are configured via tags that define their behavior:
|
|
64
|
+
* - 'falling': Object is dynamic and affected by gravity (without this tag, object is static)
|
|
65
|
+
* - 'follow': Object follows mouse position when grounded
|
|
66
|
+
* - 'grabable': Object can be dragged via mouse constraint
|
|
67
|
+
*/
|
|
68
|
+
interface ObjectConfig {
|
|
69
|
+
x: number;
|
|
70
|
+
y: number;
|
|
71
|
+
/** Radius for circle/polygon shapes */
|
|
72
|
+
radius?: number;
|
|
73
|
+
/** Width for rectangle objects (ignored if imageUrl is provided) */
|
|
74
|
+
width?: number;
|
|
75
|
+
/** Height for rectangle objects (ignored if imageUrl is provided) */
|
|
76
|
+
height?: number;
|
|
77
|
+
/** Image URL for image-based shapes */
|
|
78
|
+
imageUrl?: string;
|
|
79
|
+
/** Size of the object when using imageUrl (diameter) */
|
|
80
|
+
size?: number;
|
|
81
|
+
/** Fill style color */
|
|
82
|
+
fillStyle?: string;
|
|
83
|
+
/** Tags that define object behavior */
|
|
84
|
+
tags?: string[];
|
|
85
|
+
/** Shape configuration. Defaults to circle if radius provided, rectangle otherwise */
|
|
86
|
+
shape?: ShapeConfig;
|
|
87
|
+
/** Time-to-live in milliseconds. If not set, object lives forever */
|
|
88
|
+
ttl?: number;
|
|
89
|
+
/** Configuration for despawn effect (future use) */
|
|
90
|
+
despawnEffect?: DespawnEffectConfig;
|
|
91
|
+
/** Weight for pressure calculation (default: 1). Higher weight = more pressure contribution */
|
|
92
|
+
weight?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Dynamic object data passed to update callbacks.
|
|
96
|
+
* Only objects with the 'falling' tag (dynamic objects) are included.
|
|
97
|
+
*/
|
|
98
|
+
interface DynamicObject {
|
|
99
|
+
id: string;
|
|
100
|
+
x: number;
|
|
101
|
+
y: number;
|
|
102
|
+
angle: number;
|
|
103
|
+
tags: string[];
|
|
104
|
+
}
|
|
105
|
+
interface UpdateCallbackData {
|
|
106
|
+
/** All dynamic objects (objects with 'falling' tag) */
|
|
107
|
+
objects: DynamicObject[];
|
|
108
|
+
}
|
|
109
|
+
type UpdateCallback = (data: UpdateCallbackData) => void;
|
|
110
|
+
interface ContainerOptions {
|
|
111
|
+
width?: number;
|
|
112
|
+
height?: number;
|
|
113
|
+
fullscreen?: boolean;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Configuration for an object type that can be spawned by an effect.
|
|
117
|
+
* Effects can spawn multiple object types with different probabilities.
|
|
118
|
+
*/
|
|
119
|
+
interface EffectObjectConfig {
|
|
120
|
+
/** Partial object config - x, y will be set by the effect */
|
|
121
|
+
objectConfig: Omit<ObjectConfig, 'x' | 'y' | 'radius'> & {
|
|
122
|
+
radius?: number;
|
|
123
|
+
};
|
|
124
|
+
/** Probability weight for this object type (relative to others in the effect) */
|
|
125
|
+
probability: number;
|
|
126
|
+
/** Minimum scale multiplier for radius */
|
|
127
|
+
minScale: number;
|
|
128
|
+
/** Maximum scale multiplier for radius */
|
|
129
|
+
maxScale: number;
|
|
130
|
+
/** Base radius for the object (default: 20) */
|
|
131
|
+
baseRadius?: number;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Base configuration shared by all effect types
|
|
135
|
+
*/
|
|
136
|
+
interface BaseEffectConfig {
|
|
137
|
+
/** Unique identifier for this effect */
|
|
138
|
+
id: string;
|
|
139
|
+
/** Whether the effect is currently active */
|
|
140
|
+
enabled: boolean;
|
|
141
|
+
/** Object configurations with their spawn probabilities */
|
|
142
|
+
objectConfigs: EffectObjectConfig[];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Burst effect - spawns entities from a point that explode outward
|
|
146
|
+
*/
|
|
147
|
+
interface BurstEffectConfig extends BaseEffectConfig {
|
|
148
|
+
type: 'burst';
|
|
149
|
+
/** How often a burst occurs (in milliseconds) */
|
|
150
|
+
burstInterval: number;
|
|
151
|
+
/** Number of entities spawned per burst */
|
|
152
|
+
burstCount: number;
|
|
153
|
+
/** Velocity magnitude for burst entities */
|
|
154
|
+
burstForce: number;
|
|
155
|
+
/** Optional fixed origin point. If not specified, random position is used */
|
|
156
|
+
origin?: {
|
|
157
|
+
x: number;
|
|
158
|
+
y: number;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Rain effect - continuously spawns entities from the top that fall down
|
|
163
|
+
*/
|
|
164
|
+
interface RainEffectConfig extends BaseEffectConfig {
|
|
165
|
+
type: 'rain';
|
|
166
|
+
/** How many entities to spawn per second */
|
|
167
|
+
spawnRate: number;
|
|
168
|
+
/** Portion of screen width to spawn across (0-1, default: 1) */
|
|
169
|
+
spawnWidth?: number;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Stream effect - emits entities from a point in a configurable direction with cone spread
|
|
173
|
+
*/
|
|
174
|
+
interface StreamEffectConfig extends BaseEffectConfig {
|
|
175
|
+
type: 'stream';
|
|
176
|
+
/** Origin point where entities are emitted from (can be outside bounds) */
|
|
177
|
+
origin: {
|
|
178
|
+
x: number;
|
|
179
|
+
y: number;
|
|
180
|
+
};
|
|
181
|
+
/** Direction vector (will be normalized). e.g., { x: 0, y: 1 } for downward */
|
|
182
|
+
direction: {
|
|
183
|
+
x: number;
|
|
184
|
+
y: number;
|
|
185
|
+
};
|
|
186
|
+
/** How many entities to spawn per second */
|
|
187
|
+
spawnRate: number;
|
|
188
|
+
/** Initial velocity/force magnitude for spawned entities */
|
|
189
|
+
force: number;
|
|
190
|
+
/** Cone angle in radians - spread from center direction (0 = laser, Math.PI/4 = 45° cone) */
|
|
191
|
+
coneAngle: number;
|
|
192
|
+
}
|
|
193
|
+
type EffectConfig = BurstEffectConfig | RainEffectConfig | StreamEffectConfig;
|
|
194
|
+
type EffectType = EffectConfig['type'];
|
|
195
|
+
/**
|
|
196
|
+
* Configuration for pressure-based collapse of obstacles.
|
|
197
|
+
* When pressure (number of objects resting on an obstacle) reaches the threshold,
|
|
198
|
+
* the obstacle converts to dynamic (falling).
|
|
199
|
+
*/
|
|
200
|
+
interface PressureThresholdConfig {
|
|
201
|
+
/**
|
|
202
|
+
* Threshold value(s):
|
|
203
|
+
* - number: Single threshold applied per-letter (or word total if wordCollapse is true)
|
|
204
|
+
* - number[]: Per-letter thresholds by index (letter 0 uses value[0], etc.)
|
|
205
|
+
*/
|
|
206
|
+
value: number | number[];
|
|
207
|
+
/**
|
|
208
|
+
* When true and value is a single number:
|
|
209
|
+
* - Tracks total pressure across all letters in the word
|
|
210
|
+
* - When total reaches threshold, ALL letters in the word collapse together
|
|
211
|
+
* When false or undefined (default):
|
|
212
|
+
* - Each letter tracks its own pressure
|
|
213
|
+
* - Only the letter that reaches threshold collapses
|
|
214
|
+
*/
|
|
215
|
+
wordCollapse?: boolean;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Configuration for weight of obstacles (used when they collapse and become falling objects).
|
|
219
|
+
* Weight determines how much pressure an object contributes when resting on something.
|
|
220
|
+
*/
|
|
221
|
+
interface WeightConfig {
|
|
222
|
+
/**
|
|
223
|
+
* Weight value(s):
|
|
224
|
+
* - number: Single weight applied to all letters
|
|
225
|
+
* - number[]: Per-letter weights by index (letter 0 uses value[0], etc.)
|
|
226
|
+
*/
|
|
227
|
+
value: number | number[];
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Configuration for shadow left behind when an obstacle collapses.
|
|
231
|
+
* When enabled, a static washed-out version of the obstacle remains at its original position.
|
|
232
|
+
*/
|
|
233
|
+
interface ShadowConfig {
|
|
234
|
+
/**
|
|
235
|
+
* Opacity of the shadow (0-1). Default: 0.3
|
|
236
|
+
*/
|
|
237
|
+
opacity?: number;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Configuration for click to fall behavior.
|
|
241
|
+
* When enabled, obstacles collapse after being clicked a specified number of times.
|
|
242
|
+
*/
|
|
243
|
+
interface ClickToFallConfig {
|
|
244
|
+
/**
|
|
245
|
+
* Number of clicks required before the obstacle falls.
|
|
246
|
+
* Each click decrements the counter; when it reaches zero, the obstacle collapses.
|
|
247
|
+
*/
|
|
248
|
+
clicks: number;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Configuration for creating text objects from strings
|
|
252
|
+
*/
|
|
253
|
+
interface TextObstacleConfig {
|
|
254
|
+
/** The text to create objects from (A-Z, 0-9 supported, supports \n for multiline) */
|
|
255
|
+
text: string;
|
|
256
|
+
/** X position of the first letter's center */
|
|
257
|
+
x: number;
|
|
258
|
+
/** Y position of the letter centers */
|
|
259
|
+
y: number;
|
|
260
|
+
/** Size of each letter (width/height) */
|
|
261
|
+
letterSize: number;
|
|
262
|
+
/** Spacing between letter centers (default: letterSize) */
|
|
263
|
+
letterSpacing?: number;
|
|
264
|
+
/** Font name - corresponds to directory under /fonts/ (default: 'handwritten') */
|
|
265
|
+
fontName?: string;
|
|
266
|
+
/** Base URL path for fonts directory (default: '/fonts/') */
|
|
267
|
+
fontsBasePath?: string;
|
|
268
|
+
/** Tags to apply to all letters (use 'falling' for dynamic objects) */
|
|
269
|
+
tags?: string[];
|
|
270
|
+
/** Tag for the entire string (for releasing whole string). Auto-generated if not provided */
|
|
271
|
+
stringTag?: string;
|
|
272
|
+
/** Time-to-live in milliseconds */
|
|
273
|
+
ttl?: number;
|
|
274
|
+
/** Color to tint the letters (CSS color string). If not set, original image colors are used */
|
|
275
|
+
letterColor?: string;
|
|
276
|
+
/** Line height for multiline text (default: letterSize * 1.2) */
|
|
277
|
+
lineHeight?: number;
|
|
278
|
+
/** Pressure threshold config - when reached, letters collapse */
|
|
279
|
+
pressureThreshold?: PressureThresholdConfig;
|
|
280
|
+
/** Weight config - when letters collapse, this is their pressure contribution */
|
|
281
|
+
weight?: WeightConfig;
|
|
282
|
+
/** Shadow config - when enabled, a washed-out version remains after collapse */
|
|
283
|
+
shadow?: ShadowConfig;
|
|
284
|
+
/** Click to fall config - when set, letters collapse after being clicked N times */
|
|
285
|
+
clickToFall?: ClickToFallConfig;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Debug information for a single letter's positioning
|
|
289
|
+
*/
|
|
290
|
+
interface LetterDebugInfo {
|
|
291
|
+
/** Letter character */
|
|
292
|
+
char: string;
|
|
293
|
+
/** Obstacle ID */
|
|
294
|
+
id: string;
|
|
295
|
+
/** Original PNG dimensions (before scaling) */
|
|
296
|
+
originalWidth: number;
|
|
297
|
+
originalHeight: number;
|
|
298
|
+
/** Scaled dimensions at letterSize */
|
|
299
|
+
scaledWidth: number;
|
|
300
|
+
scaledHeight: number;
|
|
301
|
+
/** Position of the letter's original dimension box (top-left corner) */
|
|
302
|
+
boxX: number;
|
|
303
|
+
boxY: number;
|
|
304
|
+
/** Center position of the letter */
|
|
305
|
+
centerX: number;
|
|
306
|
+
centerY: number;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Result of creating text obstacles
|
|
310
|
+
*/
|
|
311
|
+
interface TextObstacleResult {
|
|
312
|
+
/** IDs of all created letter obstacles */
|
|
313
|
+
letterIds: string[];
|
|
314
|
+
/** Tag for the entire string (all letters) */
|
|
315
|
+
stringTag: string;
|
|
316
|
+
/** Tags for each individual word (space/newline separated) */
|
|
317
|
+
wordTags: string[];
|
|
318
|
+
/** Map of character to obstacle ID for individual control */
|
|
319
|
+
letterMap: Map<string, string>;
|
|
320
|
+
/** Debug info for each letter (for drawing original dimension boxes) */
|
|
321
|
+
letterDebugInfo: LetterDebugInfo[];
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Configuration for creating text objects from a TTF font
|
|
325
|
+
*/
|
|
326
|
+
interface TTFTextObstacleConfig {
|
|
327
|
+
/** Text to display (supports \n for multiline) */
|
|
328
|
+
text: string;
|
|
329
|
+
/** X position of the start of text */
|
|
330
|
+
x: number;
|
|
331
|
+
/** Y position of the text baseline */
|
|
332
|
+
y: number;
|
|
333
|
+
/** Font size in pixels */
|
|
334
|
+
fontSize: number;
|
|
335
|
+
/** URL path to the TTF/OTF font file */
|
|
336
|
+
fontUrl: string;
|
|
337
|
+
/** Tags to apply to all letters (use 'falling' for dynamic objects) */
|
|
338
|
+
tags?: string[];
|
|
339
|
+
/** Tag for the entire string (for releasing whole string). Auto-generated if not provided */
|
|
340
|
+
stringTag?: string;
|
|
341
|
+
/** Time-to-live in milliseconds */
|
|
342
|
+
ttl?: number;
|
|
343
|
+
/** Fill color for the letters (CSS color string, default: '#ffffff') */
|
|
344
|
+
fillColor?: string;
|
|
345
|
+
/** Line height for multiline text (default: fontSize * 1.2) */
|
|
346
|
+
lineHeight?: number;
|
|
347
|
+
/** Pressure threshold config - when reached, letters collapse */
|
|
348
|
+
pressureThreshold?: PressureThresholdConfig;
|
|
349
|
+
/** Weight config - when letters collapse, this is their pressure contribution */
|
|
350
|
+
weight?: WeightConfig;
|
|
351
|
+
/** Shadow config - when enabled, a washed-out version remains after collapse */
|
|
352
|
+
shadow?: ShadowConfig;
|
|
353
|
+
/** Click to fall config - when set, letters collapse after being clicked N times */
|
|
354
|
+
clickToFall?: ClickToFallConfig;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Information about an available font
|
|
358
|
+
*/
|
|
359
|
+
interface FontInfo {
|
|
360
|
+
/** Font name (directory name under /fonts/) */
|
|
361
|
+
name: string;
|
|
362
|
+
/** Available characters in this font (e.g., "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") */
|
|
363
|
+
characters: string;
|
|
364
|
+
/** Font type: 'png' for image-based, 'ttf' for TrueType fonts */
|
|
365
|
+
type: 'png' | 'ttf';
|
|
366
|
+
/** For TTF fonts: relative URL path to the font file */
|
|
367
|
+
fontUrl?: string;
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Font manifest structure loaded from fonts.json
|
|
371
|
+
*/
|
|
372
|
+
interface FontManifest {
|
|
373
|
+
fonts: FontInfo[];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
declare class OverlayScene {
|
|
377
|
+
private engine;
|
|
378
|
+
private render;
|
|
379
|
+
private runner;
|
|
380
|
+
private canvas;
|
|
381
|
+
/** All scene objects (unified - no more entity/obstacle distinction) */
|
|
382
|
+
private objects;
|
|
383
|
+
private boundaries;
|
|
384
|
+
private updateCallbacks;
|
|
385
|
+
private mouseX;
|
|
386
|
+
private config;
|
|
387
|
+
private animationFrameId;
|
|
388
|
+
private mouse;
|
|
389
|
+
private mouseConstraint;
|
|
390
|
+
private effectManager;
|
|
391
|
+
private fonts;
|
|
392
|
+
private fontsInitialized;
|
|
393
|
+
private letterDebugInfo;
|
|
394
|
+
private obstaclePressure;
|
|
395
|
+
private previousPressure;
|
|
396
|
+
private pressureLogTimer;
|
|
397
|
+
private floorSegments;
|
|
398
|
+
private floorSegmentPressure;
|
|
399
|
+
private collapsedSegments;
|
|
400
|
+
static createContainer(parent: HTMLElement, options?: ContainerOptions): {
|
|
401
|
+
canvas: HTMLCanvasElement;
|
|
402
|
+
bounds: Bounds;
|
|
403
|
+
};
|
|
404
|
+
constructor(canvas: HTMLCanvasElement, config: OverlaySceneConfig);
|
|
405
|
+
/** Filter drag events - only allow grabbing objects with 'grabable' tag */
|
|
406
|
+
private handleStartDrag;
|
|
407
|
+
/** Handle canvas clicks for click-to-fall behavior */
|
|
408
|
+
private handleCanvasClick;
|
|
409
|
+
/** Get a display name for an obstacle (letter char or short ID) */
|
|
410
|
+
private getObstacleDisplayName;
|
|
411
|
+
/** Update pressure tracking - check which dynamic objects rest on static obstacles */
|
|
412
|
+
private updatePressure;
|
|
413
|
+
/** Update pressure tracking for each floor segment */
|
|
414
|
+
private updateFloorSegmentPressure;
|
|
415
|
+
/** Check floor segment thresholds and collapse segments that exceed them */
|
|
416
|
+
private checkFloorSegmentThresholds;
|
|
417
|
+
/** Collapse a single floor segment */
|
|
418
|
+
private collapseFloorSegment;
|
|
419
|
+
/** Log a summary of pressure on all obstacles, grouped by word */
|
|
420
|
+
private logPressureSummary;
|
|
421
|
+
/** Calculate weighted pressure from a set of object IDs */
|
|
422
|
+
private calculateWeightedPressure;
|
|
423
|
+
/** Check pressure thresholds and collapse obstacles that exceed them */
|
|
424
|
+
private checkPressureThresholds;
|
|
425
|
+
/** Convert a static obstacle to dynamic (make it fall) */
|
|
426
|
+
private collapseObstacle;
|
|
427
|
+
/** Create a static shadow copy of an obstacle at its original position */
|
|
428
|
+
private createShadow;
|
|
429
|
+
/** Apply opacity to a CSS color string */
|
|
430
|
+
private applyOpacityToColor;
|
|
431
|
+
/** Find an object entry by its Matter.js body (handles compound body parts) */
|
|
432
|
+
private findObjectByBody;
|
|
433
|
+
/** Check if a body is grounded (low vertical velocity indicates resting on something) */
|
|
434
|
+
private isGrounded;
|
|
435
|
+
start(): void;
|
|
436
|
+
stop(): void;
|
|
437
|
+
destroy(): void;
|
|
438
|
+
setDebug(enabled: boolean): void;
|
|
439
|
+
resize(width: number, height: number): void;
|
|
440
|
+
/**
|
|
441
|
+
* Spawn an object synchronously.
|
|
442
|
+
* Object behavior is determined by tags:
|
|
443
|
+
* - 'falling': Object is dynamic (affected by gravity)
|
|
444
|
+
* - 'follow': Object follows mouse when grounded
|
|
445
|
+
* - 'grabable': Object can be dragged
|
|
446
|
+
* Without 'falling' tag, object is static.
|
|
447
|
+
*/
|
|
448
|
+
spawnObject(config: ObjectConfig): string;
|
|
449
|
+
/**
|
|
450
|
+
* Spawn an object asynchronously. Required for image-based shapes that need
|
|
451
|
+
* shape extraction from image alpha channel.
|
|
452
|
+
*/
|
|
453
|
+
spawnObjectAsync(config: ObjectConfig): Promise<string>;
|
|
454
|
+
/**
|
|
455
|
+
* Add 'falling' tag to an object, making it dynamic (affected by gravity).
|
|
456
|
+
* Also adds 'grabable' tag so released objects can be dragged.
|
|
457
|
+
* This is the tag-based replacement for releaseObstacle().
|
|
458
|
+
*/
|
|
459
|
+
addFallingTag(id: string): void;
|
|
460
|
+
/**
|
|
461
|
+
* Add a tag to an object.
|
|
462
|
+
*/
|
|
463
|
+
addTag(id: string, tag: string): void;
|
|
464
|
+
/**
|
|
465
|
+
* Remove a tag from an object.
|
|
466
|
+
*/
|
|
467
|
+
removeTag(id: string, tag: string): void;
|
|
468
|
+
/**
|
|
469
|
+
* Release an object (add 'falling' tag to make it dynamic).
|
|
470
|
+
* Convenience method - equivalent to addFallingTag().
|
|
471
|
+
*/
|
|
472
|
+
releaseObject(id: string): void;
|
|
473
|
+
/**
|
|
474
|
+
* Release multiple objects by their IDs.
|
|
475
|
+
*/
|
|
476
|
+
releaseObjects(ids: string[]): void;
|
|
477
|
+
/**
|
|
478
|
+
* Release all static objects (add 'falling' and 'grabable' tags).
|
|
479
|
+
*/
|
|
480
|
+
releaseAllObjects(): void;
|
|
481
|
+
/**
|
|
482
|
+
* Release objects by tag (add 'falling' and 'grabable' tags to matching objects).
|
|
483
|
+
*/
|
|
484
|
+
releaseObjectsByTag(tag: string): void;
|
|
485
|
+
removeObject(id: string): void;
|
|
486
|
+
removeObjects(ids: string[]): void;
|
|
487
|
+
removeAllObjects(): void;
|
|
488
|
+
removeObjectsByTag(tag: string): void;
|
|
489
|
+
getObjectIds(): string[];
|
|
490
|
+
getObjectIdsByTag(tag: string): string[];
|
|
491
|
+
/**
|
|
492
|
+
* Get all unique tags currently in use by objects in the scene.
|
|
493
|
+
*/
|
|
494
|
+
getAllTags(): string[];
|
|
495
|
+
setMousePosition(x: number, _y: number): void;
|
|
496
|
+
/**
|
|
497
|
+
* Get the current pressure (number of objects resting) on an obstacle.
|
|
498
|
+
* @param obstacleId - The ID of the obstacle
|
|
499
|
+
* @returns Number of objects currently resting on the obstacle
|
|
500
|
+
*/
|
|
501
|
+
getPressure(obstacleId: string): number;
|
|
502
|
+
/**
|
|
503
|
+
* Get the IDs of all objects currently resting on an obstacle.
|
|
504
|
+
* @param obstacleId - The ID of the obstacle
|
|
505
|
+
* @returns Array of object IDs resting on the obstacle
|
|
506
|
+
*/
|
|
507
|
+
getObjectsRestingOn(obstacleId: string): string[];
|
|
508
|
+
/**
|
|
509
|
+
* Get all obstacles that have pressure (at least one object resting on them).
|
|
510
|
+
* @returns Map of obstacle ID -> pressure count
|
|
511
|
+
*/
|
|
512
|
+
getAllPressure(): Map<string, number>;
|
|
513
|
+
/**
|
|
514
|
+
* Get pressure summary for all obstacles with their display names (letters).
|
|
515
|
+
* Useful for debugging and visualization.
|
|
516
|
+
* @returns Array of { id, name, pressure } objects
|
|
517
|
+
*/
|
|
518
|
+
getPressureSummary(): {
|
|
519
|
+
id: string;
|
|
520
|
+
name: string;
|
|
521
|
+
pressure: number;
|
|
522
|
+
}[];
|
|
523
|
+
/**
|
|
524
|
+
* Initialize fonts by loading the font manifest.
|
|
525
|
+
* Should be called before using text obstacles if you want automatic font detection.
|
|
526
|
+
* @param fontsBasePath Base URL path for fonts directory (default: '/fonts/')
|
|
527
|
+
*/
|
|
528
|
+
initializeFonts(fontsBasePath?: string): Promise<void>;
|
|
529
|
+
/**
|
|
530
|
+
* Get list of available fonts.
|
|
531
|
+
* Returns empty array if fonts have not been initialized.
|
|
532
|
+
*/
|
|
533
|
+
getAvailableFonts(): FontInfo[];
|
|
534
|
+
/**
|
|
535
|
+
* Get font by index. Returns undefined if index is out of bounds.
|
|
536
|
+
* @param index Font index (0-based)
|
|
537
|
+
*/
|
|
538
|
+
getFontByIndex(index: number): FontInfo | undefined;
|
|
539
|
+
/**
|
|
540
|
+
* Get font by name. Returns undefined if font not found.
|
|
541
|
+
* @param name Font name to find
|
|
542
|
+
*/
|
|
543
|
+
getFontByName(name: string): FontInfo | undefined;
|
|
544
|
+
/**
|
|
545
|
+
* Get the default font (first available font).
|
|
546
|
+
* Returns undefined if no fonts are available.
|
|
547
|
+
*/
|
|
548
|
+
getDefaultFont(): FontInfo | undefined;
|
|
549
|
+
/**
|
|
550
|
+
* Check if fonts have been initialized.
|
|
551
|
+
*/
|
|
552
|
+
areFontsInitialized(): boolean;
|
|
553
|
+
/**
|
|
554
|
+
* Create text obstacles from a string. Each character becomes an individual obstacle
|
|
555
|
+
* with shape extracted from the corresponding letter PNG image.
|
|
556
|
+
* Supported characters: A-Z, a-z, 0-9 (spaces handled, unsupported chars skipped)
|
|
557
|
+
* Case is preserved: uses lowercase PNG if available, falls back to uppercase (and vice versa).
|
|
558
|
+
* Supports multiline text with \n characters.
|
|
559
|
+
*
|
|
560
|
+
* Letter positioning is based on original PNG dimensions:
|
|
561
|
+
* - Each letter's PNG width controls its horizontal spacing
|
|
562
|
+
* - The clipped shape is positioned correctly within the original bounds
|
|
563
|
+
* - This allows fine control of letter spacing via PNG canvas size
|
|
564
|
+
*/
|
|
565
|
+
addTextObstacles(config: TextObstacleConfig): Promise<TextObstacleResult>;
|
|
566
|
+
/**
|
|
567
|
+
* Spawn falling text objects from a string.
|
|
568
|
+
* Same as addTextObstacles but with 'falling' tag (objects fall with gravity).
|
|
569
|
+
*/
|
|
570
|
+
spawnFallingTextObstacles(config: TextObstacleConfig): Promise<TextObstacleResult>;
|
|
571
|
+
/**
|
|
572
|
+
* Release all letters in a word (add 'falling' tag so they fall).
|
|
573
|
+
* @param wordTag - The word tag returned from addTextObstacles
|
|
574
|
+
*/
|
|
575
|
+
releaseTextObstacles(wordTag: string): void;
|
|
576
|
+
/**
|
|
577
|
+
* Release letters one by one with a delay between each.
|
|
578
|
+
* @param wordTag - The word tag returned from addTextObstacles
|
|
579
|
+
* @param delayMs - Delay between releasing each letter (default: 100ms)
|
|
580
|
+
* @param reverse - If true, release from end to start (default: false)
|
|
581
|
+
*/
|
|
582
|
+
releaseTextObstaclesSequentially(wordTag: string, delayMs?: number, reverse?: boolean): Promise<void>;
|
|
583
|
+
/**
|
|
584
|
+
* Get letter debug info for a word.
|
|
585
|
+
* Returns the debug info array for the given word tag, or undefined if not found.
|
|
586
|
+
* Debug info includes original dimension boxes for each letter.
|
|
587
|
+
*/
|
|
588
|
+
getLetterDebugInfo(wordTag: string): LetterDebugInfo[] | undefined;
|
|
589
|
+
/**
|
|
590
|
+
* Get all stored letter debug info (all words).
|
|
591
|
+
* Returns a map of wordTag -> debug info array.
|
|
592
|
+
*/
|
|
593
|
+
getAllLetterDebugInfo(): Map<string, LetterDebugInfo[]>;
|
|
594
|
+
/**
|
|
595
|
+
* Create text obstacles from a TTF/OTF font file.
|
|
596
|
+
* Uses proper font metrics for spacing, kerning, and glyph outlines for collision.
|
|
597
|
+
* Supports multiline text with \n characters.
|
|
598
|
+
*/
|
|
599
|
+
addTTFTextObstacles(config: TTFTextObstacleConfig): Promise<TextObstacleResult>;
|
|
600
|
+
/**
|
|
601
|
+
* Spawn falling TTF text objects.
|
|
602
|
+
* Same as addTTFTextObstacles but with 'falling' tag (objects fall with gravity).
|
|
603
|
+
*/
|
|
604
|
+
spawnFallingTTFTextObstacles(config: TTFTextObstacleConfig): Promise<TextObstacleResult>;
|
|
605
|
+
removeAllByTag(tag: string): void;
|
|
606
|
+
removeAll(): void;
|
|
607
|
+
onUpdate(callback: UpdateCallback): void;
|
|
608
|
+
/**
|
|
609
|
+
* Add or update an effect configuration.
|
|
610
|
+
* Effects are persistent spawning mechanisms that run until disabled.
|
|
611
|
+
*/
|
|
612
|
+
setEffect(config: EffectConfig): void;
|
|
613
|
+
/**
|
|
614
|
+
* Remove an effect by ID
|
|
615
|
+
*/
|
|
616
|
+
removeEffect(id: string): void;
|
|
617
|
+
/**
|
|
618
|
+
* Enable or disable an effect
|
|
619
|
+
*/
|
|
620
|
+
setEffectEnabled(id: string, enabled: boolean): void;
|
|
621
|
+
/**
|
|
622
|
+
* Get an effect configuration by ID
|
|
623
|
+
*/
|
|
624
|
+
getEffect(id: string): EffectConfig | undefined;
|
|
625
|
+
/**
|
|
626
|
+
* Get all effect IDs
|
|
627
|
+
*/
|
|
628
|
+
getEffectIds(): string[];
|
|
629
|
+
/**
|
|
630
|
+
* Check if an effect is currently enabled
|
|
631
|
+
*/
|
|
632
|
+
isEffectEnabled(id: string): boolean;
|
|
633
|
+
private loop;
|
|
634
|
+
/**
|
|
635
|
+
* Draw debug overlays for letter original dimension boxes
|
|
636
|
+
*/
|
|
637
|
+
private drawDebugOverlays;
|
|
638
|
+
/**
|
|
639
|
+
* Draw TTF glyphs using canvas fillText for clean text rendering
|
|
640
|
+
*/
|
|
641
|
+
private drawTTFGlyphs;
|
|
642
|
+
private checkTTLExpiration;
|
|
643
|
+
/** Despawn objects that have fallen below the floor by the configured distance */
|
|
644
|
+
private checkDespawnBelowFloor;
|
|
645
|
+
private fireUpdateCallbacks;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
649
|
+
declare function setLogLevel(level: LogLevel): void;
|
|
650
|
+
declare function getLogLevel(): LogLevel;
|
|
651
|
+
declare const logger: {
|
|
652
|
+
debug(prefix: string, message: string, data?: unknown): void;
|
|
653
|
+
info(prefix: string, message: string, data?: unknown): void;
|
|
654
|
+
warn(prefix: string, message: string, data?: unknown): void;
|
|
655
|
+
error(prefix: string, message: string, data?: unknown): void;
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
interface Vector2D {
|
|
659
|
+
x: number;
|
|
660
|
+
y: number;
|
|
661
|
+
}
|
|
662
|
+
interface GlyphData {
|
|
663
|
+
vertices: Vector2D[];
|
|
664
|
+
advanceWidth: number;
|
|
665
|
+
leftSideBearing: number;
|
|
666
|
+
boundingBox: {
|
|
667
|
+
x1: number;
|
|
668
|
+
y1: number;
|
|
669
|
+
x2: number;
|
|
670
|
+
y2: number;
|
|
671
|
+
} | null;
|
|
672
|
+
}
|
|
673
|
+
interface LoadedFont {
|
|
674
|
+
font: opentype.Font;
|
|
675
|
+
unitsPerEm: number;
|
|
676
|
+
ascender: number;
|
|
677
|
+
descender: number;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Load a TTF/OTF font from a URL
|
|
681
|
+
*/
|
|
682
|
+
declare function loadFont(fontUrl: string): Promise<LoadedFont>;
|
|
683
|
+
/**
|
|
684
|
+
* Get glyph data for a character including vertices and metrics
|
|
685
|
+
*/
|
|
686
|
+
declare function getGlyphData(loadedFont: LoadedFont, char: string, fontSize: number): GlyphData;
|
|
687
|
+
/**
|
|
688
|
+
* Get kerning adjustment between two characters
|
|
689
|
+
*/
|
|
690
|
+
declare function getKerning(loadedFont: LoadedFont, char1: string, char2: string, fontSize: number): number;
|
|
691
|
+
/**
|
|
692
|
+
* Calculate total width of a string with proper spacing and kerning
|
|
693
|
+
*/
|
|
694
|
+
declare function measureText(loadedFont: LoadedFont, text: string, fontSize: number): number;
|
|
695
|
+
/**
|
|
696
|
+
* Clear the font cache
|
|
697
|
+
*/
|
|
698
|
+
declare function clearFontCache(): void;
|
|
699
|
+
|
|
700
|
+
export { type BaseEffectConfig, type Bounds, type BurstEffectConfig, type ClickToFallConfig, type ContainerOptions, type DespawnEffectConfig, type DynamicObject, type EffectConfig, type EffectObjectConfig, type EffectType, type FloorConfig, type FontInfo, type FontManifest, type GlyphData, type LoadedFont, type ObjectConfig, OverlayScene, type OverlaySceneConfig, type PressureThresholdConfig, type RainEffectConfig, type ShadowConfig, type ShapeConfig, type ShapePreset, type StreamEffectConfig, type TTFTextObstacleConfig, type TextObstacleConfig, type TextObstacleResult, type UpdateCallback, type UpdateCallbackData, type WeightConfig, clearFontCache, getGlyphData, getKerning, getLogLevel, loadFont, logger, measureText, setLogLevel };
|