@react-shimeji/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1408 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +511 -0
- package/dist/index.d.ts +511 -0
- package/dist/index.js +1362 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
/** A two-dimensional point in work-area coordinates. */
|
|
2
|
+
interface Point {
|
|
3
|
+
/** Horizontal coordinate in CSS pixels. */
|
|
4
|
+
x: number;
|
|
5
|
+
/** Vertical coordinate in CSS pixels. */
|
|
6
|
+
y: number;
|
|
7
|
+
}
|
|
8
|
+
/** A rectangular region in a spritesheet or work area. */
|
|
9
|
+
interface Rectangle extends Point {
|
|
10
|
+
/** Rectangle width in CSS pixels. */
|
|
11
|
+
width: number;
|
|
12
|
+
/** Rectangle height in CSS pixels. */
|
|
13
|
+
height: number;
|
|
14
|
+
}
|
|
15
|
+
/** A sprite cropped from the character's atlas. */
|
|
16
|
+
interface SpriteRectangle extends Rectangle {
|
|
17
|
+
/** Optional URL overriding the character-level spritesheet for this sprite. */
|
|
18
|
+
url?: string;
|
|
19
|
+
}
|
|
20
|
+
/** A standalone sprite image rather than an atlas crop. */
|
|
21
|
+
interface IndividualSprite {
|
|
22
|
+
/** Image URL or data URI. */
|
|
23
|
+
url: string;
|
|
24
|
+
/** Optional known image width. */
|
|
25
|
+
width?: number;
|
|
26
|
+
/** Optional known image height. */
|
|
27
|
+
height?: number;
|
|
28
|
+
}
|
|
29
|
+
/** Sprite definitions keyed by the legacy image path, such as `/shime1.png`. */
|
|
30
|
+
type SpriteMap = Record<string, SpriteRectangle | IndividualSprite | string>;
|
|
31
|
+
/** One legacy animation pose. Durations use the traditional 40 ms unit. */
|
|
32
|
+
interface Pose {
|
|
33
|
+
/** Sprite key from the character's sprite map, or an image URL. */
|
|
34
|
+
sprite: string;
|
|
35
|
+
/** Point within the sprite that occupies the mascot's world position. */
|
|
36
|
+
anchor: Point;
|
|
37
|
+
/** Per-legacy-frame movement encoded by the character pack. */
|
|
38
|
+
velocity: Point;
|
|
39
|
+
/** Number of 40 ms units for which the pose remains active. */
|
|
40
|
+
duration: number;
|
|
41
|
+
}
|
|
42
|
+
/** A conditional collection of poses used by an action. */
|
|
43
|
+
interface AnimationDefinition {
|
|
44
|
+
/** Optional Shimeji expression controlling whether this animation applies. */
|
|
45
|
+
condition?: string;
|
|
46
|
+
/** Ordered pose frames. */
|
|
47
|
+
poses: Pose[];
|
|
48
|
+
}
|
|
49
|
+
/** Kind of action understood by the action executor. */
|
|
50
|
+
type ActionType = "Sequence" | "Select" | "Reference" | "Stay" | "Animate" | "Move" | "Embedded";
|
|
51
|
+
/** Boundary on which an action is allowed to begin. */
|
|
52
|
+
type BorderType = "Floor" | "Wall" | "Ceiling";
|
|
53
|
+
/** A normalized action from a compiled or XML character definition. */
|
|
54
|
+
interface ActionDefinition {
|
|
55
|
+
/** Action implementation kind. */
|
|
56
|
+
type: ActionType;
|
|
57
|
+
/** Stable action name used by behaviors and references. */
|
|
58
|
+
name?: string;
|
|
59
|
+
/** Embedded action class name such as `Fall`, `Dragged`, or `Look`. */
|
|
60
|
+
embedType?: string;
|
|
61
|
+
/** Optional expression that must evaluate truthfully. */
|
|
62
|
+
condition?: string;
|
|
63
|
+
/** Optional boundary prerequisite. */
|
|
64
|
+
borderType?: BorderType;
|
|
65
|
+
/** Nested actions for sequence and selection nodes. */
|
|
66
|
+
actions?: ActionDefinition[];
|
|
67
|
+
/** Conditional pose alternatives for leaf actions. */
|
|
68
|
+
animations?: AnimationDefinition[];
|
|
69
|
+
/** Whether a sequence should repeat. */
|
|
70
|
+
loop?: boolean;
|
|
71
|
+
/** Duration expression measured in legacy frames. */
|
|
72
|
+
duration?: string | number;
|
|
73
|
+
/** Legacy expression gap made available while evaluating other properties. */
|
|
74
|
+
gap?: string | number;
|
|
75
|
+
/** Horizontal target expression. */
|
|
76
|
+
targetX?: string | number;
|
|
77
|
+
/** Vertical target expression. */
|
|
78
|
+
targetY?: string | number;
|
|
79
|
+
/** Movement speed expression. */
|
|
80
|
+
velocity?: string | number;
|
|
81
|
+
/** Horizontal offset expression. */
|
|
82
|
+
x?: string | number;
|
|
83
|
+
/** Vertical offset expression. */
|
|
84
|
+
y?: string | number;
|
|
85
|
+
/** Initial horizontal velocity expression. */
|
|
86
|
+
initialVx?: string | number;
|
|
87
|
+
/** Initial vertical velocity expression. */
|
|
88
|
+
initialVy?: string | number;
|
|
89
|
+
/** Horizontal air-resistance expression. */
|
|
90
|
+
resistanceX?: string | number;
|
|
91
|
+
/** Vertical air-resistance expression. */
|
|
92
|
+
resistanceY?: string | number;
|
|
93
|
+
/** Gravity expression. */
|
|
94
|
+
gravity?: string | number;
|
|
95
|
+
/** Child spawn horizontal offset expression. */
|
|
96
|
+
bornX?: string | number;
|
|
97
|
+
/** Child spawn vertical offset expression. */
|
|
98
|
+
bornY?: string | number;
|
|
99
|
+
/** Behavior assigned to a spawned child. */
|
|
100
|
+
bornBehavior?: string;
|
|
101
|
+
/** Carried-element horizontal offset expression. */
|
|
102
|
+
ieOffsetX?: string | number;
|
|
103
|
+
/** Carried-element vertical offset expression. */
|
|
104
|
+
ieOffsetY?: string | number;
|
|
105
|
+
/** Facing expression used by Look actions. */
|
|
106
|
+
lookRight?: string | boolean;
|
|
107
|
+
}
|
|
108
|
+
/** Kind of behavior node stored in a character specification. */
|
|
109
|
+
type BehaviorType = "Behavior" | "Reference";
|
|
110
|
+
/** One weighted behavior and its possible transitions. */
|
|
111
|
+
interface BehaviorDefinition {
|
|
112
|
+
/** Whether this is a complete behavior or a reference to one. */
|
|
113
|
+
type: BehaviorType;
|
|
114
|
+
/** Name of the behavior and its same-named action. */
|
|
115
|
+
name: string;
|
|
116
|
+
/** Relative random-selection weight. */
|
|
117
|
+
frequency: number;
|
|
118
|
+
/** Conditions that must all be true. */
|
|
119
|
+
conditions: string[];
|
|
120
|
+
/** Candidates considered after this behavior completes. */
|
|
121
|
+
nextBehaviors: BehaviorDefinition[];
|
|
122
|
+
/** Menu grouping value retained from legacy packs. */
|
|
123
|
+
groupIndex: number;
|
|
124
|
+
/** Whether user interfaces should hide the behavior. */
|
|
125
|
+
hidden: boolean;
|
|
126
|
+
}
|
|
127
|
+
/** Free-form character attribution and directory metadata. */
|
|
128
|
+
interface CharacterMetadata {
|
|
129
|
+
/** Character display name. */
|
|
130
|
+
shimejiName?: string;
|
|
131
|
+
/** Character group identifier. */
|
|
132
|
+
group?: string;
|
|
133
|
+
/** Character group display name. */
|
|
134
|
+
groupName?: string;
|
|
135
|
+
/** Original artist name. */
|
|
136
|
+
artistName?: string | null;
|
|
137
|
+
/** Upstream source URL. */
|
|
138
|
+
sourceUrl?: string;
|
|
139
|
+
/** Any additional pack-specific metadata. */
|
|
140
|
+
[key: string]: unknown;
|
|
141
|
+
}
|
|
142
|
+
/** Fully parsed character data consumed by the engine. */
|
|
143
|
+
interface CharacterSpec {
|
|
144
|
+
/** Stable identifier used when spawning the character. */
|
|
145
|
+
id: string;
|
|
146
|
+
/** Optional human-readable name. */
|
|
147
|
+
name?: string;
|
|
148
|
+
/** Character attribution metadata. */
|
|
149
|
+
metadata?: CharacterMetadata;
|
|
150
|
+
/** Spritesheet URL, data URI, or Blob owned by spawned mascots. */
|
|
151
|
+
spritesheet: string | Blob;
|
|
152
|
+
/** Atlas rectangles or individual sprite URLs. */
|
|
153
|
+
sprites: SpriteMap;
|
|
154
|
+
/** Parsed action tree definitions. */
|
|
155
|
+
actions: ActionDefinition[];
|
|
156
|
+
/** Parsed behavior state-machine definitions. */
|
|
157
|
+
behaviors: BehaviorDefinition[];
|
|
158
|
+
}
|
|
159
|
+
/** Legacy bundle whose XML and JSON fields have not necessarily been parsed. */
|
|
160
|
+
interface LegacyCharacterPack {
|
|
161
|
+
/** Stable character identifier; inferred from metadata when omitted. */
|
|
162
|
+
id?: string;
|
|
163
|
+
/** Optional human-readable name. */
|
|
164
|
+
name?: string;
|
|
165
|
+
/** Optional wrapper object used by some pack exporters. */
|
|
166
|
+
configuration?: unknown;
|
|
167
|
+
/** Parsed actions or raw `actions.xml` text. */
|
|
168
|
+
actions: ActionDefinition[] | string;
|
|
169
|
+
/** Parsed behaviors or raw `behaviors.xml` text. */
|
|
170
|
+
behaviors: BehaviorDefinition[] | string;
|
|
171
|
+
/** Parsed sprite map or raw `sprites.json` text. */
|
|
172
|
+
sprites: SpriteMap | string;
|
|
173
|
+
/** Spritesheet URL, data URI, or Blob. */
|
|
174
|
+
spritesheet: string | Blob;
|
|
175
|
+
/** Optional character metadata. */
|
|
176
|
+
metadata?: CharacterMetadata;
|
|
177
|
+
}
|
|
178
|
+
/** Supported input accepted by the character loader. */
|
|
179
|
+
type CharacterSource = CharacterSpec | LegacyCharacterPack | string | URL;
|
|
180
|
+
/** Initial placement and state for a newly spawned mascot. */
|
|
181
|
+
interface SpawnOptions extends Partial<Point> {
|
|
182
|
+
/** Initial horizontal velocity. */
|
|
183
|
+
vx?: number;
|
|
184
|
+
/** Initial vertical velocity. */
|
|
185
|
+
vy?: number;
|
|
186
|
+
/** Initial facing direction. */
|
|
187
|
+
lookRight?: boolean;
|
|
188
|
+
/** Behavior to run first. */
|
|
189
|
+
behaviorName?: string;
|
|
190
|
+
}
|
|
191
|
+
/** Public immutable snapshot of a mascot. */
|
|
192
|
+
interface MascotState extends Point {
|
|
193
|
+
/** Unique mascot instance identifier. */
|
|
194
|
+
id: string;
|
|
195
|
+
/** Registered character identifier. */
|
|
196
|
+
characterId: string;
|
|
197
|
+
/** Current horizontal velocity. */
|
|
198
|
+
vx: number;
|
|
199
|
+
/** Current vertical velocity. */
|
|
200
|
+
vy: number;
|
|
201
|
+
/** Current sprite key. */
|
|
202
|
+
sprite: string;
|
|
203
|
+
/** Current horizontal sprite anchor. */
|
|
204
|
+
anchorX: number;
|
|
205
|
+
/** Current vertical sprite anchor. */
|
|
206
|
+
anchorY: number;
|
|
207
|
+
/** Whether the sprite faces right. */
|
|
208
|
+
lookRight: boolean;
|
|
209
|
+
/** Name of the current behavior. */
|
|
210
|
+
behaviorName: string;
|
|
211
|
+
/** Whether the mascot is currently being dragged. */
|
|
212
|
+
dragging: boolean;
|
|
213
|
+
}
|
|
214
|
+
/** Runtime options for a Shimeji engine. */
|
|
215
|
+
interface ShimejiEngineOptions {
|
|
216
|
+
/** Legacy frame duration in milliseconds. Defaults to 40. */
|
|
217
|
+
frameDuration?: number;
|
|
218
|
+
/** Default gravity in legacy pixels per frame squared. Defaults to 2. */
|
|
219
|
+
gravity?: number;
|
|
220
|
+
/** Maximum elapsed time applied to one animation update. Defaults to 100 ms. */
|
|
221
|
+
maxDeltaTime?: number;
|
|
222
|
+
/** CSS class added to the generated work area. */
|
|
223
|
+
workAreaClassName?: string;
|
|
224
|
+
/** CSS class added to each generated mascot element. */
|
|
225
|
+
mascotClassName?: string;
|
|
226
|
+
/** Optional deterministic random-number source. */
|
|
227
|
+
random?: () => number;
|
|
228
|
+
}
|
|
229
|
+
/** Events emitted by {@link ShimejiEngine}. */
|
|
230
|
+
interface ShimejiEngineEventMap {
|
|
231
|
+
/** Emitted after a mascot is created. */
|
|
232
|
+
spawn: MascotState;
|
|
233
|
+
/** Emitted immediately before a mascot is discarded. */
|
|
234
|
+
remove: MascotState;
|
|
235
|
+
/** Emitted when the state collection changes during a frame. */
|
|
236
|
+
statechange: MascotState[];
|
|
237
|
+
/** Emitted when a mascot is clicked without being dragged. */
|
|
238
|
+
click: MascotState;
|
|
239
|
+
/** Emitted when a recoverable pack or runtime error occurs. */
|
|
240
|
+
error: Error;
|
|
241
|
+
}
|
|
242
|
+
/** Typed callback for one engine event. */
|
|
243
|
+
type ShimejiEventListener<K extends keyof ShimejiEngineEventMap> = (payload: ShimejiEngineEventMap[K]) => void;
|
|
244
|
+
/** Read-only environment supplied to expression and action evaluation. */
|
|
245
|
+
interface MascotEnvironment {
|
|
246
|
+
/** Current mascot snapshot. */
|
|
247
|
+
mascot: {
|
|
248
|
+
/** Current number of live mascots. */
|
|
249
|
+
totalCount: number;
|
|
250
|
+
/** Current anchor position. */
|
|
251
|
+
anchor: Point;
|
|
252
|
+
/** Current facing direction. */
|
|
253
|
+
lookRight: boolean;
|
|
254
|
+
/** Browser and work-area values exposed to legacy expressions. */
|
|
255
|
+
environment: {
|
|
256
|
+
/** Latest pointer position and velocity. */
|
|
257
|
+
cursor: Point & {
|
|
258
|
+
dx: number;
|
|
259
|
+
dy: number;
|
|
260
|
+
};
|
|
261
|
+
/** Current viewport dimensions. */
|
|
262
|
+
screen: {
|
|
263
|
+
width: number;
|
|
264
|
+
height: number;
|
|
265
|
+
};
|
|
266
|
+
/** Current work-area bounds and edge predicates. */
|
|
267
|
+
workArea: EnvironmentRectangle;
|
|
268
|
+
/** Alias for the work-area bottom edge. */
|
|
269
|
+
floor: EnvironmentEdge;
|
|
270
|
+
/** Alias for the work-area top edge. */
|
|
271
|
+
ceiling: EnvironmentEdge;
|
|
272
|
+
/** Inactive compatibility rectangle for page-element actions. */
|
|
273
|
+
activeIE: EnvironmentRectangle & {
|
|
274
|
+
visible: boolean;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
/** Legacy expression gap variable. */
|
|
279
|
+
gap: number;
|
|
280
|
+
/** Configured upper mascot count. */
|
|
281
|
+
maxCount: number;
|
|
282
|
+
/** Current action target x-coordinate. */
|
|
283
|
+
targetX?: number;
|
|
284
|
+
/** Current action target y-coordinate. */
|
|
285
|
+
targetY?: number;
|
|
286
|
+
/** Dragging animation foot x-coordinate. */
|
|
287
|
+
footX?: number;
|
|
288
|
+
/** Dragging animation foot y-coordinate. */
|
|
289
|
+
footY?: number;
|
|
290
|
+
}
|
|
291
|
+
/** Edge predicate exposed to legacy expressions. */
|
|
292
|
+
interface EnvironmentEdge {
|
|
293
|
+
/** Returns whether a point is on this edge. */
|
|
294
|
+
isOn(point: Point): boolean;
|
|
295
|
+
}
|
|
296
|
+
/** Rectangle and edge predicates exposed to legacy expressions. */
|
|
297
|
+
interface EnvironmentRectangle extends Rectangle {
|
|
298
|
+
/** Left edge coordinate. */
|
|
299
|
+
left: number;
|
|
300
|
+
/** Right edge coordinate. */
|
|
301
|
+
right: number;
|
|
302
|
+
/** Top edge coordinate. */
|
|
303
|
+
top: number;
|
|
304
|
+
/** Bottom edge coordinate. */
|
|
305
|
+
bottom: number;
|
|
306
|
+
/** Top edge predicate. */
|
|
307
|
+
topBorder: EnvironmentEdge;
|
|
308
|
+
/** Left edge predicate. */
|
|
309
|
+
leftBorder: EnvironmentEdge;
|
|
310
|
+
/** Right edge predicate. */
|
|
311
|
+
rightBorder: EnvironmentEdge;
|
|
312
|
+
/** Bottom edge predicate. */
|
|
313
|
+
bottomBorder: EnvironmentEdge;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Framework-agnostic manager for character registration and live Shimeji mascots. */
|
|
317
|
+
declare class ShimejiEngine {
|
|
318
|
+
private readonly container;
|
|
319
|
+
private readonly specs;
|
|
320
|
+
private readonly mascots;
|
|
321
|
+
private readonly sprites;
|
|
322
|
+
private readonly dom;
|
|
323
|
+
private readonly events;
|
|
324
|
+
private readonly disposers;
|
|
325
|
+
private readonly intervals;
|
|
326
|
+
private readonly options;
|
|
327
|
+
private readonly originalContainerPosition;
|
|
328
|
+
private readonly adjustedContainerPosition;
|
|
329
|
+
private pointer;
|
|
330
|
+
private animationFrame;
|
|
331
|
+
private lastFrameTime;
|
|
332
|
+
private nextMascotId;
|
|
333
|
+
private destroyed;
|
|
334
|
+
private initialized;
|
|
335
|
+
/** Creates and initializes an engine inside a host DOM element. */
|
|
336
|
+
constructor(container: HTMLElement, options?: ShimejiEngineOptions);
|
|
337
|
+
/** Starts the clock and global listeners. Calling this method more than once is harmless. */
|
|
338
|
+
initialize(): void;
|
|
339
|
+
/** Registers or replaces a parsed or legacy character specification. */
|
|
340
|
+
registerCharacter(spec: CharacterSpec | unknown): string;
|
|
341
|
+
/** Unregisters a character and optionally removes all of its live mascots. */
|
|
342
|
+
unregisterCharacter(characterId: string, removeMascots?: boolean): boolean;
|
|
343
|
+
/** Returns identifiers for all currently registered characters. */
|
|
344
|
+
getCharacterIds(): string[];
|
|
345
|
+
/** Creates a mascot from a registered character and returns its instance id. */
|
|
346
|
+
spawn(characterId: string, position?: SpawnOptions): string;
|
|
347
|
+
/** Removes one mascot and all resources associated with it. */
|
|
348
|
+
remove(mascotId: string): boolean;
|
|
349
|
+
/** Removes every live mascot while leaving registered character specs available. */
|
|
350
|
+
removeAll(): void;
|
|
351
|
+
/** Returns detached snapshots of every live mascot. */
|
|
352
|
+
getState(): MascotState[];
|
|
353
|
+
/** Subscribes to a typed engine event and returns an unsubscribe function. */
|
|
354
|
+
on<K extends keyof ShimejiEngineEventMap>(event: K, listener: ShimejiEventListener<K>): () => void;
|
|
355
|
+
/** Stops animation and timers, removes listeners and DOM, and revokes all object URLs. */
|
|
356
|
+
destroy(): void;
|
|
357
|
+
/** Returns whether this engine has completed permanent teardown. */
|
|
358
|
+
isDestroyed(): boolean;
|
|
359
|
+
private readonly onAnimationFrame;
|
|
360
|
+
private renderAll;
|
|
361
|
+
private emitState;
|
|
362
|
+
private listen;
|
|
363
|
+
private assertAlive;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Parses a legacy `actions.xml` document into normalized action definitions. */
|
|
367
|
+
declare function parseActionsXml(xml: string): ActionDefinition[];
|
|
368
|
+
/** Parses a legacy `behaviors.xml` document into normalized behavior definitions. */
|
|
369
|
+
declare function parseBehaviorsXml(xml: string): BehaviorDefinition[];
|
|
370
|
+
/** Converts a pre-parsed definition or raw XML/JSON legacy bundle to a character specification. */
|
|
371
|
+
declare function normalizeCharacterSpec(input: CharacterSpec | LegacyCharacterPack | unknown): CharacterSpec;
|
|
372
|
+
/** Loads character JSON from a URL or normalizes an already available character bundle. */
|
|
373
|
+
declare function loadCharacter(source: CharacterSource): Promise<CharacterSpec>;
|
|
374
|
+
|
|
375
|
+
/** Safely evaluates a legacy Shimeji expression without using `eval` or `Function`. */
|
|
376
|
+
declare function evaluateExpression(expression: string | number | boolean | undefined, environment: MascotEnvironment, fallback: number): number;
|
|
377
|
+
/** Safely evaluates a legacy Shimeji expression without using `eval` or `Function`. */
|
|
378
|
+
declare function evaluateExpression(expression: string | number | boolean | undefined, environment: MascotEnvironment, fallback: boolean): boolean;
|
|
379
|
+
/** Returns true when every condition in a behavior or action is satisfied. */
|
|
380
|
+
declare function conditionsMatch(conditions: readonly string[], environment: MascotEnvironment): boolean;
|
|
381
|
+
/** Chooses one item with probability proportional to its non-negative weight. */
|
|
382
|
+
declare function selectWeighted<T>(items: readonly T[], weight: (item: T) => number, random?: () => number): T | undefined;
|
|
383
|
+
/** Selects applicable behaviors and resolves legacy behavior references. */
|
|
384
|
+
declare class BehaviorController {
|
|
385
|
+
private readonly spec;
|
|
386
|
+
private readonly random;
|
|
387
|
+
private previous;
|
|
388
|
+
/** Creates a behavior selector for a normalized character specification. */
|
|
389
|
+
constructor(spec: CharacterSpec, random?: () => number);
|
|
390
|
+
/** Selects an initial behavior, honoring an explicit requested name when possible. */
|
|
391
|
+
selectInitial(environment: MascotEnvironment, requestedName?: string): BehaviorDefinition | undefined;
|
|
392
|
+
/** Selects the weighted transition following the current behavior. */
|
|
393
|
+
selectNext(environment: MascotEnvironment): BehaviorDefinition | undefined;
|
|
394
|
+
/** Replaces selection history so an external interaction can force a behavior. */
|
|
395
|
+
force(name: string): BehaviorDefinition | undefined;
|
|
396
|
+
private choose;
|
|
397
|
+
private resolve;
|
|
398
|
+
private findFallBehavior;
|
|
399
|
+
private isOnAnyBoundary;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Callbacks through which embedded actions request engine-level operations. */
|
|
403
|
+
interface ActionExecutorCallbacks {
|
|
404
|
+
/** Spawns another mascot from the same character. */
|
|
405
|
+
spawn(position: {
|
|
406
|
+
x: number;
|
|
407
|
+
y: number;
|
|
408
|
+
behaviorName?: string;
|
|
409
|
+
}): void;
|
|
410
|
+
/** Removes the mascot owning this executor. */
|
|
411
|
+
remove(): void;
|
|
412
|
+
}
|
|
413
|
+
/** Settings used while interpreting actions. */
|
|
414
|
+
interface ActionExecutorOptions {
|
|
415
|
+
/** Duration of one legacy animation unit in milliseconds. */
|
|
416
|
+
frameDuration: number;
|
|
417
|
+
/** Gravity used when a Fall action does not define one. */
|
|
418
|
+
gravity: number;
|
|
419
|
+
}
|
|
420
|
+
/** Executes normalized action trees independently from DOM rendering. */
|
|
421
|
+
declare class ActionExecutor {
|
|
422
|
+
private readonly spec;
|
|
423
|
+
private readonly state;
|
|
424
|
+
private readonly options;
|
|
425
|
+
private readonly callbacks;
|
|
426
|
+
private runtime;
|
|
427
|
+
/** Creates an executor bound to one mascot's mutable internal state. */
|
|
428
|
+
constructor(spec: CharacterSpec, state: MascotState, options: ActionExecutorOptions, callbacks: ActionExecutorCallbacks);
|
|
429
|
+
/** Starts the action whose name matches a selected behavior. */
|
|
430
|
+
start(actionName: string, environment: MascotEnvironment): boolean;
|
|
431
|
+
/** Advances the current action and returns true when it has completed. */
|
|
432
|
+
tick(deltaMs: number, environment: MascotEnvironment, bounds: Rectangle): boolean;
|
|
433
|
+
/** Cancels the current action tree. */
|
|
434
|
+
cancel(): void;
|
|
435
|
+
private createRuntime;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/** Clamps a number to an inclusive range. */
|
|
439
|
+
declare function clamp(value: number, minimum: number, maximum: number): number;
|
|
440
|
+
/** Returns whether a point lies on the top edge of a rectangle. */
|
|
441
|
+
declare function isOnTop(point: Point, rectangle: Rectangle, tolerance?: number): boolean;
|
|
442
|
+
/** Returns whether a point lies on the bottom edge of a rectangle. */
|
|
443
|
+
declare function isOnBottom(point: Point, rectangle: Rectangle, tolerance?: number): boolean;
|
|
444
|
+
/** Returns whether a point lies on the left edge of a rectangle. */
|
|
445
|
+
declare function isOnLeft(point: Point, rectangle: Rectangle, tolerance?: number): boolean;
|
|
446
|
+
/** Returns whether a point lies on the right edge of a rectangle. */
|
|
447
|
+
declare function isOnRight(point: Point, rectangle: Rectangle, tolerance?: number): boolean;
|
|
448
|
+
/** Returns whether an anchor satisfies an action's boundary requirement. */
|
|
449
|
+
declare function isOnBorder(state: MascotState, bounds: Rectangle, border: "Floor" | "Wall" | "Ceiling" | undefined): boolean;
|
|
450
|
+
/** Advances ballistic motion and clamps the mascot to the work-area boundaries. */
|
|
451
|
+
declare function applyGravity(state: MascotState, bounds: Rectangle, frameScale: number, gravity: number, resistanceX?: number, resistanceY?: number): boolean;
|
|
452
|
+
/** Moves a mascot toward a target without overshooting it. */
|
|
453
|
+
declare function moveToward(state: MascotState, target: Point, speed: number, frameScale: number): boolean;
|
|
454
|
+
|
|
455
|
+
/** A resolved image and optional atlas crop for one sprite frame. */
|
|
456
|
+
interface ResolvedSprite {
|
|
457
|
+
/** Browser-loadable image URL. */
|
|
458
|
+
url: string;
|
|
459
|
+
/** Optional atlas crop. */
|
|
460
|
+
rectangle?: SpriteRectangle;
|
|
461
|
+
}
|
|
462
|
+
/** A per-mascot spritesheet resource whose temporary URL can be released. */
|
|
463
|
+
interface SpriteLease {
|
|
464
|
+
/** URL used to render atlas-backed frames. */
|
|
465
|
+
url: string;
|
|
466
|
+
/** Releases any object URL owned by this lease. */
|
|
467
|
+
release(): void;
|
|
468
|
+
}
|
|
469
|
+
/** Owns temporary sprite URLs and resolves atlas or individual image frames. */
|
|
470
|
+
declare class SpriteManager {
|
|
471
|
+
private readonly leases;
|
|
472
|
+
/** Creates a separately releasable spritesheet lease for a mascot. */
|
|
473
|
+
acquire(source: string | Blob): SpriteLease;
|
|
474
|
+
/** Resolves a sprite key using a lease and the character's sprite map. */
|
|
475
|
+
resolve(spec: CharacterSpec, lease: SpriteLease, spriteName: string): ResolvedSprite | undefined;
|
|
476
|
+
/** Revokes every object URL that has not already been released. */
|
|
477
|
+
destroy(): void;
|
|
478
|
+
}
|
|
479
|
+
/** Returns whether a sprite definition is a standalone image object. */
|
|
480
|
+
declare function isIndividualSprite(sprite: SpriteRectangle | IndividualSprite | string): sprite is IndividualSprite;
|
|
481
|
+
|
|
482
|
+
/** DOM nodes and resources owned by one mascot. */
|
|
483
|
+
interface MascotDomHandle {
|
|
484
|
+
/** Pointer-interactive mascot wrapper. */
|
|
485
|
+
element: HTMLDivElement;
|
|
486
|
+
/** Child element on which sprite images are painted. */
|
|
487
|
+
spriteElement: HTMLDivElement;
|
|
488
|
+
/** Per-mascot spritesheet URL lease. */
|
|
489
|
+
spriteLease: SpriteLease;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/** Callbacks through which a mascot communicates with its owning engine. */
|
|
493
|
+
interface MascotCallbacks {
|
|
494
|
+
/** Returns the latest pointer position and velocity in work-area coordinates. */
|
|
495
|
+
pointer(): Point & {
|
|
496
|
+
dx: number;
|
|
497
|
+
dy: number;
|
|
498
|
+
};
|
|
499
|
+
/** Returns the current number of live mascots. */
|
|
500
|
+
count(): number;
|
|
501
|
+
/** Requests a sibling mascot. */
|
|
502
|
+
spawn(characterId: string, options: SpawnOptions): void;
|
|
503
|
+
/** Requests removal of this mascot. */
|
|
504
|
+
remove(id: string): void;
|
|
505
|
+
/** Reports a click without a drag gesture. */
|
|
506
|
+
click(state: MascotState): void;
|
|
507
|
+
/** Reports a recoverable runtime failure. */
|
|
508
|
+
error(error: Error): void;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export { type ActionDefinition, ActionExecutor, type ActionExecutorCallbacks, type ActionExecutorOptions, type ActionType, type AnimationDefinition, BehaviorController, type BehaviorDefinition, type BehaviorType, type BorderType, type CharacterMetadata, type CharacterSource, type CharacterSpec, type EnvironmentEdge, type EnvironmentRectangle, type IndividualSprite, type LegacyCharacterPack, type MascotCallbacks, type MascotDomHandle, type MascotEnvironment, type MascotState, type Point, type Pose, type Rectangle, type ResolvedSprite, ShimejiEngine, type ShimejiEngineEventMap, type ShimejiEngineOptions, type ShimejiEventListener, type SpawnOptions, type SpriteLease, SpriteManager, type SpriteMap, type SpriteRectangle, applyGravity, clamp, conditionsMatch, evaluateExpression, isIndividualSprite, isOnBorder, isOnBottom, isOnLeft, isOnRight, isOnTop, loadCharacter, moveToward, normalizeCharacterSpec, parseActionsXml, parseBehaviorsXml, selectWeighted };
|