@m2c2kit/core 0.3.18 → 0.3.19

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.d.ts CHANGED
@@ -1,88 +1,5 @@
1
1
  import { Canvas, Typeface, TypefaceFontProvider, Image, Paint, CanvasKit, Surface, Font, ParagraphBuilder, Paragraph, FontMgr, Path, PaintStyle } from 'canvaskit-wasm';
2
2
 
3
- declare class GlobalVariables {
4
- now: number;
5
- deltaTime: number;
6
- canvasScale: number;
7
- rootScale: number;
8
- canvasCssWidth: number;
9
- canvasCssHeight: number;
10
- }
11
-
12
- declare global {
13
- var Globals: GlobalVariables;
14
- }
15
- //# sourceMappingURL=Globals.d.ts.map
16
-
17
- /**
18
- * Base interface for all m2c2kit events.
19
- *
20
- * @remarks I would have named it Event, but that would collide with
21
- * the existing DOM Event
22
- */
23
- interface M2Event<T> {
24
- /** Type of event. */
25
- type: M2EventType | string;
26
- /** The object on which the event occurred. */
27
- target: T;
28
- /** Has the event been taken care of by the listener and not be dispatched to other targets? */
29
- handled?: boolean;
30
- }
31
- /**
32
- * The different events that are dispatched by m2c2kit core.
33
- */
34
- declare const M2EventType: {
35
- readonly ActivityStart: "ActivityStart";
36
- readonly ActivityEnd: "ActivityEnd";
37
- readonly ActivityCancel: "ActivityCancel";
38
- readonly ActivityData: "ActivityData";
39
- readonly GameWarmupStart: "GameWarmupStart";
40
- readonly GameWarmupEnd: "GameWarmupEnd";
41
- readonly TapDown: "TapDown";
42
- readonly TapUp: "TapUp";
43
- readonly TapUpAny: "TapUpAny";
44
- readonly TapLeave: "TapLeave";
45
- readonly PointerDown: "PointerDown";
46
- readonly PointerUp: "PointerUp";
47
- readonly PointerMove: "PointerMove";
48
- readonly PointerLeave: "PointerLeave";
49
- readonly Drag: "Drag";
50
- readonly DragStart: "DragStart";
51
- readonly DragEnd: "DragEnd";
52
- readonly CompositeCustom: "CompositeCustom";
53
- readonly FrameDidSimulatePhysics: "FrameDidSimulatePhysics";
54
- readonly SceneSetup: "SceneSetup";
55
- readonly SceneAppear: "SceneAppear";
56
- };
57
- type M2EventType = (typeof M2EventType)[keyof typeof M2EventType];
58
-
59
- /**
60
- * Base interface for all m2c2kit event listeners.
61
- */
62
- interface M2EventListener<T> {
63
- /** Type of event to listen for. */
64
- type: M2EventType | string;
65
- /** Callback function to be called when the event is dispatched. */
66
- callback: (event: T) => void;
67
- /** Optional key (string identifier) used to identify the event listener. */
68
- key?: string;
69
- }
70
-
71
- interface M2NodeEventListener<M2NodeEvent> extends M2EventListener<M2NodeEvent> {
72
- /** For composites that raise events, type of the composite custom event. */
73
- compositeType?: string;
74
- /** UUID of the node that the event listener is listening for. */
75
- nodeUuid: string;
76
- }
77
-
78
- /** Base interface for all M2Node events. */
79
- interface M2NodeEvent extends M2Event<M2Node> {
80
- /** The M2Node on which the event occurred. */
81
- target: M2Node;
82
- /** For composites that raise events, type of the composite custom event. */
83
- compositeType?: string;
84
- }
85
-
86
3
  /**
87
4
  * Position in two-dimensional space.
88
5
  */
@@ -93,30 +10,32 @@ interface Point {
93
10
  y: number;
94
11
  }
95
12
 
96
- /**
97
- * Describes an interaction between the pointer (mouse, touches) and a node.
98
- *
99
- * @remarks I would have named it PointerEvent, but that would collide with
100
- * the existing DOM PointerEvent.
101
- */
102
- interface M2PointerEvent extends M2NodeEvent {
103
- /** Point that was tapped on node, relative to the node coordinate system */
104
- point: Point;
105
- /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
106
- buttons: number;
13
+ interface IDrawable {
14
+ draw(canvas: Canvas): void;
15
+ warmup(canvas: Canvas): void;
16
+ /**
17
+ * Frees up resources allocated by the Drawable M2Node.
18
+ *
19
+ * @internal For m2c2kit library use only
20
+ *
21
+ * @remarks This will be done automatically by the m2c2kit library; the
22
+ * end-user must not call this.
23
+ */
24
+ dispose(): void;
25
+ anchorPoint: Point;
26
+ zPosition: number;
107
27
  }
108
28
 
109
- /**
110
- * Describes an interaction of a pointer (mouse, touches) pressing a node.
111
- *
112
- * @remarks Unlike M2PointerEvent, TapEvent considers how the pointer, while
113
- * in the down state, moves in relation to the bounds of the node.
114
- */
115
- interface TapEvent extends M2NodeEvent {
116
- /** Point that was tapped on node, relative to the node coordinate system */
117
- point: Point;
118
- /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
119
- buttons: number;
29
+ declare enum M2NodeType {
30
+ Node = "Node",
31
+ Scene = "Scene",
32
+ Sprite = "Sprite",
33
+ Label = "Label",
34
+ TextLine = "TextLine",
35
+ Shape = "Shape",
36
+ Composite = "Composite",
37
+ SoundPlayer = "SoundPlayer",
38
+ SoundRecorder = "SoundRecorder"
120
39
  }
121
40
 
122
41
  interface DrawableOptions {
@@ -170,43 +89,6 @@ interface Layout {
170
89
  constraints?: Constraints;
171
90
  }
172
91
 
173
- /**
174
- * Color in red (0-255), green (0-255), blue (0-255), alpha (0-1) format. Must be numeric array of length 4.
175
- */
176
- type RgbaColor = [number, number, number, number];
177
-
178
- /**
179
- * Map of placeholders to values for use in string interpolation.
180
- */
181
- interface StringInterpolationMap {
182
- [placeholder: string]: string;
183
- }
184
-
185
- interface TextOptions {
186
- /** Text to be displayed */
187
- text?: string;
188
- /** Name of font to use for text. Must have been previously loaded */
189
- fontName?: string;
190
- /** Color of text. Default is Constants.DEFAULT_FONT_COLOR (WebColors.Black) */
191
- fontColor?: RgbaColor;
192
- /** Size of text. Default is Constants.DEFAULT_FONT_SIZE (16) */
193
- fontSize?: number;
194
- /** Map of placeholders to values for use in string interpolation during localization. */
195
- interpolation?: StringInterpolationMap;
196
- /** If true, try to use a localized version of the text. Default is true. */
197
- localize?: boolean;
198
- }
199
-
200
- /**
201
- * Width and height on two-dimensional space
202
- */
203
- interface Size {
204
- /** Horizontal width, x-axis */
205
- width: number;
206
- /** Vertical height, y-axis */
207
- height: number;
208
- }
209
-
210
92
  interface M2NodeOptions {
211
93
  /** Name of the node. Only needed if the node will be referred to by name in a later function */
212
94
  name?: string;
@@ -226,210 +108,46 @@ interface M2NodeOptions {
226
108
  hidden?: boolean;
227
109
  /** FOR INTERNAL USE ONLY */
228
110
  layout?: Layout;
111
+ /** Unique identifier (UUID). Will be generated automatically. @internal For m2c2kit library use only */
112
+ uuid?: string;
113
+ /** Should the node not emit events to the EventStore? Default is false.
114
+ * @remarks This property is for use by authors of `Composite` nodes. It is not intended for general use. */
115
+ suppressEvents?: boolean;
229
116
  }
230
117
 
231
- declare enum M2NodeType {
232
- Node = "Node",
233
- Scene = "Scene",
234
- Sprite = "Sprite",
235
- Label = "Label",
236
- TextLine = "TextLine",
237
- Shape = "Shape",
238
- Composite = "Composite",
239
- SoundPlayer = "SoundPlayer",
240
- SoundRecorder = "SoundRecorder"
241
- }
242
-
243
- type EasingFunction = (
244
- /** elapsed time since start of action */
245
- t: number,
246
- /** start value of value to be eased */
247
- b: number,
248
- /** total change of value to be eased */
249
- c: number,
250
- /** total duration of action */
251
- d: number) => number;
252
- /**
253
- * The Easings class has static methods for creating easings to be used in actions.
254
- */
255
- declare class Easings {
256
- static none: EasingFunction;
257
- static linear: EasingFunction;
258
- static quadraticIn: EasingFunction;
259
- static quadraticOut: EasingFunction;
260
- static quadraticInOut: EasingFunction;
261
- static cubicIn: EasingFunction;
262
- static cubicOut: EasingFunction;
263
- static cubicInOut: EasingFunction;
264
- static quarticIn: EasingFunction;
265
- static quarticOut: EasingFunction;
266
- static quarticInOut: EasingFunction;
267
- static quinticIn: EasingFunction;
268
- static quinticOut: EasingFunction;
269
- static quinticInOut: EasingFunction;
270
- static sinusoidalIn: EasingFunction;
271
- static sinusoidalOut: EasingFunction;
272
- static sinusoidalInOut: EasingFunction;
273
- static exponentialIn: EasingFunction;
274
- static exponentialOut: EasingFunction;
275
- static exponentialInOut: EasingFunction;
276
- static circularIn: EasingFunction;
277
- static circularOut: EasingFunction;
278
- static circularInOut: EasingFunction;
279
- }
280
-
281
- interface IDrawable {
282
- draw(canvas: Canvas): void;
283
- warmup(canvas: Canvas): void;
284
- /**
285
- * Frees up resources allocated by the Drawable M2Node.
286
- *
287
- * @internal For m2c2kit library use only
288
- *
289
- * @remarks This will be done automatically by the m2c2kit library; the
290
- * end-user must not call this.
291
- */
292
- dispose(): void;
293
- anchorPoint: Point;
294
- zPosition: number;
295
- }
296
-
297
- interface SceneOptions extends M2NodeOptions, DrawableOptions {
298
- /** Background color of the scene. Default is Constants.DEFAULT_SCENE_BACKGROUND_COLOR (WebColors.White) */
299
- backgroundColor?: RgbaColor;
300
- }
301
-
302
- interface CallbackOptions {
303
- /** Should the provided callback replace any existing callbacks of the same event type for this target? Default is false */
304
- replaceExisting?: boolean;
305
- /** String identifier used to identify the callback. Only needed if the callback will be removed later */
306
- key?: string;
118
+ interface CompositeOptions extends M2NodeOptions, DrawableOptions {
307
119
  }
308
120
 
309
- declare class Scene extends M2Node implements IDrawable, SceneOptions {
310
- readonly type = M2NodeType.Scene;
121
+ declare abstract class Composite extends M2Node implements IDrawable {
122
+ readonly type = M2NodeType.Composite;
123
+ compositeType: string;
311
124
  isDrawable: boolean;
312
- anchorPoint: {
313
- x: number;
314
- y: number;
315
- };
316
- zPosition: number;
317
- private _backgroundColor;
318
- _active: boolean;
319
- _transitioning: boolean;
320
- private backgroundPaint?;
125
+ private _anchorPoint;
126
+ private _zPosition;
321
127
  /**
322
- * Top-level node that holds all other nodes, such as sprites, rectangles, or labels, that will be displayed on the screen
323
- *
324
- * @remarks The scene is the game screen or stage, and fills the entire available screen. There are usually multiple screens to contain multiple stages of the game, such as various instruction pages or phases of a game.
128
+ * Base Drawable object for creating custom nodes ("composites") composed of primitive nodes.
325
129
  *
326
- * @param options - {@link SceneOptions}
130
+ * @param options
327
131
  */
328
- constructor(options?: SceneOptions);
132
+ constructor(options?: CompositeOptions);
329
133
  initialize(): void;
134
+ get anchorPoint(): Point;
135
+ set anchorPoint(anchorPoint: Point);
136
+ get zPosition(): number;
137
+ set zPosition(zPosition: number);
330
138
  dispose(): void;
331
- set game(game: Game);
332
- /**
333
- * The game which this scene is a part of.
334
- *
335
- * @remarks Throws error if scene is not part of the game object.
336
- */
337
- get game(): Game;
338
- get backgroundColor(): RgbaColor;
339
- set backgroundColor(backgroundColor: RgbaColor);
340
- /**
341
- * Duplicates a node using deep copy.
342
- *
343
- * @remarks This is a deep recursive clone (node and children).
344
- * The uuid property of all duplicated nodes will be newly created,
345
- * because uuid must be unique.
346
- *
347
- * @param newName - optional name of the new, duplicated node. If not
348
- * provided, name will be the new uuid
349
- */
350
- duplicate(newName?: string): Scene;
351
- /**
352
- * Code that will be called every time the scene is presented.
353
- *
354
- * @remarks Use this callback to set nodes to their initial state, if
355
- * that state might be changed later. For example, if a scene allows
356
- * players to place dots on a grid, the setup() method should ensure the
357
- * grid is clear of any prior dots from previous times this scene may
358
- * have been displayed. In addition, if nodes should vary in each
359
- * iteration, that should be done here.
360
- *
361
- * @param callback - function to execute
362
- * @param options - {@link CallbackOptions}
363
- */
364
- onSetup(callback: (nodeEvent: M2NodeEvent) => void, options?: CallbackOptions): void;
365
- /**
366
- *
367
- * Code that will be called after the scene has finished any transitions
368
- * and has fully appeared on the screen.
369
- *
370
- * @param callback - function to execute
371
- * @param options - {@link CallbackOptions}
372
- */
373
- onAppear(callback: (nodeEvent: M2NodeEvent) => void, options?: CallbackOptions): void;
374
139
  update(): void;
375
140
  draw(canvas: Canvas): void;
376
- warmup(canvas: Canvas): void;
377
- }
378
-
379
- interface SlideTransitionOptions {
380
- /** Direction in which the slide action goes */
381
- direction: TransitionDirection;
382
- /** Duration, in milliseconds, of the transition */
383
- duration: number;
384
- /** Easing function for movement; default is linear */
385
- easing?: EasingFunction;
386
- }
387
- /**
388
- * The Transition class has static methods for creating animations that run as one scene transitions to another.
389
- */
390
- declare abstract class Transition {
391
- abstract type: TransitionType;
392
- abstract easing: EasingFunction;
393
- abstract duration: number;
141
+ abstract warmup(canvas: Canvas): void;
394
142
  /**
395
- * Creates a scene transition in which the outgoing scene slides out and the incoming scene slides in, as if the incoming scene pushes it.
143
+ * Event handler for custom events a `Composite` may generate.
396
144
  *
397
- * @param options - {@link SlideTransitionOptions}
398
- * @returns
399
- */
400
- static slide(options: SlideTransitionOptions): SlideTransition;
401
- /**
402
- * Creates a scene transition with no animation or duration. The next scene is immediately drawn.
145
+ * @remarks If the `Composite` generates custom events, this method is
146
+ * necessary for the `Composite` to work in replay mode.
147
+ *
148
+ * @param event - event to handle
403
149
  */
404
- static none(): NoneTransition;
405
- }
406
- declare class NoneTransition extends Transition {
407
- type: TransitionType;
408
- easing: EasingFunction;
409
- duration: number;
410
- constructor();
411
- }
412
- declare class SlideTransition extends Transition {
413
- type: TransitionType;
414
- easing: EasingFunction;
415
- duration: number;
416
- direction: TransitionDirection;
417
- constructor(direction: TransitionDirection, duration: number, easing: EasingFunction);
418
- }
419
- declare enum TransitionType {
420
- Slide = "Slide",
421
- None = "None"
422
- }
423
- declare enum TransitionDirection {
424
- Up = "Up",
425
- Down = "Down",
426
- Right = "Right",
427
- Left = "Left"
428
- }
429
- declare class SceneTransition {
430
- scene: Scene;
431
- transition: Transition;
432
- constructor(scene: Scene, transition: Transition);
150
+ handleCompositeEvent(event: CompositeEvent): void;
433
151
  }
434
152
 
435
153
  /** Base interface for all Activity events. */
@@ -577,6 +295,13 @@ interface IDataStore {
577
295
  itemExists(key: string): Promise<boolean>;
578
296
  }
579
297
 
298
+ interface CallbackOptions {
299
+ /** Should the provided callback replace any existing callbacks of the same event type for this target? Default is false */
300
+ replaceExisting?: boolean;
301
+ /** String identifier used to identify the callback. Only needed if the callback will be removed later */
302
+ key?: string;
303
+ }
304
+
580
305
  interface Activity {
581
306
  /** The type of activity: Game or Survey */
582
307
  type: ActivityType;
@@ -621,43 +346,244 @@ interface Activity {
621
346
  */
622
347
  onCancel(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
623
348
  /**
624
- * Executes a callback when the activity ends.
349
+ * Executes a callback when the activity ends.
350
+ *
351
+ * @param callback - function to execute.
352
+ * @param options - options for the callback.
353
+ */
354
+ onEnd(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
355
+ /**
356
+ * Executes a callback when the activity generates data.
357
+ *
358
+ * @param callback - function to execute.
359
+ * @param options - options for the callback.
360
+ */
361
+ onData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
362
+ /** The activity's parent session unique identifier. This is newly generated each session. */
363
+ sessionUuid: string;
364
+ /** The activity's unique identifier. This is newly generated each session. The UUID for an activity will vary across sessions. */
365
+ uuid: string;
366
+ /** Human-friendly name of this activity */
367
+ name: string;
368
+ /** Short identifier of this activity */
369
+ id: string;
370
+ /** Persistent unique identifier (UUID) of the activity. Required for games. Optional or empty string if a survey. */
371
+ publishUuid: string;
372
+ /** The ID of the study (protocol, experiment, or other aggregate) that contains the repeated administrations of this activity. The ID should be short, url-friendly, human-readable text (no spaces, special characters, or slashes), e.g., `nyc-aging-cohort`. */
373
+ studyId?: string;
374
+ /** Unique identifier (UUID) of the study (protocol, experiment, or other aggregate) that contains the administration of this activity. */
375
+ studyUuid?: string;
376
+ /** The value of performance.now() immediately before the activity begins */
377
+ beginTimestamp: number;
378
+ /** The value of new Date().toISOString() immediately before the activity begins */
379
+ beginIso8601Timestamp: string;
380
+ /** Sets additional activity parameters if defaults are not sufficient. */
381
+ setParameters(additionalParameters: unknown): void;
382
+ /** Additional activity parameters that were set. */
383
+ readonly additionalParameters?: unknown;
384
+ /** Optional stores to use for saving data. The implementation of the store is not provided by the \@m2c2kit/core library. */
385
+ dataStores?: IDataStore[];
386
+ }
387
+
388
+ /** Base interface for all M2Node events. */
389
+ interface M2NodeEvent extends M2Event<M2Node> {
390
+ /** The M2Node on which the event occurred. If the event has gone through serialization, the string will be the node's UUID. */
391
+ target: M2Node | string;
392
+ }
393
+
394
+ /**
395
+ * Color in red (0-255), green (0-255), blue (0-255), alpha (0-1) format. Must be numeric array of length 4.
396
+ */
397
+ type RgbaColor = [number, number, number, number];
398
+
399
+ interface SceneOptions extends M2NodeOptions, DrawableOptions {
400
+ /** Background color of the scene. Default is Constants.DEFAULT_SCENE_BACKGROUND_COLOR (WebColors.White) */
401
+ backgroundColor?: RgbaColor;
402
+ }
403
+
404
+ declare class Scene extends M2Node implements IDrawable, SceneOptions {
405
+ readonly type = M2NodeType.Scene;
406
+ isDrawable: boolean;
407
+ private _anchorPoint;
408
+ private _zPosition;
409
+ private _backgroundColor;
410
+ _active: boolean;
411
+ _transitioning: boolean;
412
+ private backgroundPaint?;
413
+ /**
414
+ * Top-level node that holds all other nodes, such as sprites, rectangles, or labels, that will be displayed on the screen
415
+ *
416
+ * @remarks The scene is the game screen or stage, and fills the entire available screen. There are usually multiple screens to contain multiple stages of the game, such as various instruction pages or phases of a game.
417
+ *
418
+ * @param options - {@link SceneOptions}
419
+ */
420
+ constructor(options?: SceneOptions);
421
+ get completeNodeOptions(): {
422
+ backgroundColor: RgbaColor;
423
+ anchorPoint?: Point;
424
+ zPosition?: number;
425
+ name?: string;
426
+ position?: Point;
427
+ scale?: number;
428
+ alpha?: number;
429
+ zRotation?: number;
430
+ isUserInteractionEnabled?: boolean;
431
+ draggable?: boolean;
432
+ hidden?: boolean;
433
+ layout?: Layout;
434
+ uuid?: string;
435
+ suppressEvents?: boolean;
436
+ };
437
+ initialize(): void;
438
+ dispose(): void;
439
+ set game(game: Game);
440
+ /**
441
+ * The game which this scene is a part of.
442
+ *
443
+ * @remarks Throws error if scene is not part of the game object.
444
+ */
445
+ get game(): Game;
446
+ get backgroundColor(): RgbaColor;
447
+ set backgroundColor(backgroundColor: RgbaColor);
448
+ get anchorPoint(): Point;
449
+ set anchorPoint(anchorPoint: Point);
450
+ get zPosition(): number;
451
+ set zPosition(zPosition: number);
452
+ /**
453
+ * Duplicates a node using deep copy.
454
+ *
455
+ * @remarks This is a deep recursive clone (node and children).
456
+ * The uuid property of all duplicated nodes will be newly created,
457
+ * because uuid must be unique.
458
+ *
459
+ * @param newName - optional name of the new, duplicated node. If not
460
+ * provided, name will be the new uuid
461
+ */
462
+ duplicate(newName?: string): Scene;
463
+ /**
464
+ * Code that will be called every time the scene is presented.
465
+ *
466
+ * @remarks Use this callback to set nodes to their initial state, if
467
+ * that state might be changed later. For example, if a scene allows
468
+ * players to place dots on a grid, the setup() method should ensure the
469
+ * grid is clear of any prior dots from previous times this scene may
470
+ * have been displayed. In addition, if nodes should vary in each
471
+ * iteration, that should be done here.
472
+ *
473
+ * @param callback - function to execute
474
+ * @param options - {@link CallbackOptions}
475
+ */
476
+ onSetup(callback: (nodeEvent: M2NodeEvent) => void, options?: CallbackOptions): void;
477
+ /**
478
+ *
479
+ * Code that will be called after the scene has finished any transitions
480
+ * and has fully appeared on the screen.
481
+ *
482
+ * @param callback - function to execute
483
+ * @param options - {@link CallbackOptions}
484
+ */
485
+ onAppear(callback: (nodeEvent: M2NodeEvent) => void, options?: CallbackOptions): void;
486
+ update(): void;
487
+ draw(canvas: Canvas): void;
488
+ warmup(canvas: Canvas): void;
489
+ }
490
+
491
+ type EasingFunction = (
492
+ /** elapsed time since start of action */
493
+ t: number,
494
+ /** start value of value to be eased */
495
+ b: number,
496
+ /** total change of value to be eased */
497
+ c: number,
498
+ /** total duration of action */
499
+ d: number) => number;
500
+ /**
501
+ * The Easings class has static methods for creating easings to be used in actions.
502
+ */
503
+ declare class Easings {
504
+ static none: EasingFunction;
505
+ static linear: EasingFunction;
506
+ static quadraticIn: EasingFunction;
507
+ static quadraticOut: EasingFunction;
508
+ static quadraticInOut: EasingFunction;
509
+ static cubicIn: EasingFunction;
510
+ static cubicOut: EasingFunction;
511
+ static cubicInOut: EasingFunction;
512
+ static quarticIn: EasingFunction;
513
+ static quarticOut: EasingFunction;
514
+ static quarticInOut: EasingFunction;
515
+ static quinticIn: EasingFunction;
516
+ static quinticOut: EasingFunction;
517
+ static quinticInOut: EasingFunction;
518
+ static sinusoidalIn: EasingFunction;
519
+ static sinusoidalOut: EasingFunction;
520
+ static sinusoidalInOut: EasingFunction;
521
+ static exponentialIn: EasingFunction;
522
+ static exponentialOut: EasingFunction;
523
+ static exponentialInOut: EasingFunction;
524
+ static circularIn: EasingFunction;
525
+ static circularOut: EasingFunction;
526
+ static circularInOut: EasingFunction;
527
+ static toTypeAsString(easingFunction: EasingFunction): string;
528
+ static fromTypeAsString(easingType: string): EasingFunction;
529
+ }
530
+
531
+ interface SlideTransitionOptions {
532
+ /** Direction in which the slide action goes */
533
+ direction: TransitionDirection;
534
+ /** Duration, in milliseconds, of the transition */
535
+ duration: number;
536
+ /** Easing function for movement or a string identifier of the easing function, e.g., `SinusoidalInOut`. Default is a linear easing function. */
537
+ easing?: EasingFunction | string;
538
+ }
539
+ /**
540
+ * The Transition class has static methods for creating animations that run as one scene transitions to another.
541
+ */
542
+ declare abstract class Transition {
543
+ abstract type: TransitionType;
544
+ abstract easing: EasingFunction;
545
+ abstract duration: number;
546
+ /**
547
+ * Creates a scene transition in which the outgoing scene slides out and the incoming scene slides in, as if the incoming scene pushes it.
625
548
  *
626
- * @param callback - function to execute.
627
- * @param options - options for the callback.
549
+ * @param options - {@link SlideTransitionOptions}
550
+ * @returns
628
551
  */
629
- onEnd(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
552
+ static slide(options: SlideTransitionOptions): SlideTransition;
630
553
  /**
631
- * Executes a callback when the activity generates data.
632
- *
633
- * @param callback - function to execute.
634
- * @param options - options for the callback.
554
+ * Creates a scene transition with no animation or duration. The next scene is immediately drawn.
635
555
  */
636
- onData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
637
- /** The activity's parent session unique identifier. This is newly generated each session. */
638
- sessionUuid: string;
639
- /** The activity's unique identifier. This is newly generated each session. The UUID for an activity will vary across sessions. */
640
- uuid: string;
641
- /** Human-friendly name of this activity */
642
- name: string;
643
- /** Short identifier of this activity */
644
- id: string;
645
- /** Persistent unique identifier (UUID) of the activity. Required for games. Optional or empty string if a survey. */
646
- publishUuid: string;
647
- /** The ID of the study (protocol, experiment, or other aggregate) that contains the repeated administrations of this activity. The ID should be short, url-friendly, human-readable text (no spaces, special characters, or slashes), e.g., `nyc-aging-cohort`. */
648
- studyId?: string;
649
- /** Unique identifier (UUID) of the study (protocol, experiment, or other aggregate) that contains the administration of this activity. */
650
- studyUuid?: string;
651
- /** The value of performance.now() immediately before the activity begins */
652
- beginTimestamp: number;
653
- /** The value of new Date().toISOString() immediately before the activity begins */
654
- beginIso8601Timestamp: string;
655
- /** Sets additional activity parameters if defaults are not sufficient. */
656
- setParameters(additionalParameters: unknown): void;
657
- /** Additional activity parameters that were set. */
658
- readonly additionalParameters?: unknown;
659
- /** Optional stores to use for saving data. The implementation of the store is not provided by the \@m2c2kit/core library. */
660
- dataStores?: IDataStore[];
556
+ static none(): NoneTransition;
557
+ }
558
+ declare class NoneTransition extends Transition {
559
+ type: "None";
560
+ easing: EasingFunction;
561
+ duration: number;
562
+ constructor();
563
+ }
564
+ declare class SlideTransition extends Transition {
565
+ type: "Slide";
566
+ easing: EasingFunction;
567
+ duration: number;
568
+ direction: TransitionDirection;
569
+ constructor(direction: TransitionDirection, duration: number, easing: EasingFunction);
570
+ }
571
+ declare const TransitionType: {
572
+ readonly Slide: "Slide";
573
+ readonly None: "None";
574
+ };
575
+ type TransitionType = (typeof TransitionType)[keyof typeof TransitionType];
576
+ declare const TransitionDirection: {
577
+ readonly Up: "Up";
578
+ readonly Down: "Down";
579
+ readonly Right: "Right";
580
+ readonly Left: "Left";
581
+ };
582
+ type TransitionDirection = (typeof TransitionDirection)[keyof typeof TransitionDirection];
583
+ declare class SceneTransition {
584
+ scene: Scene;
585
+ transition: Transition;
586
+ constructor(scene: Scene, transition: Transition);
661
587
  }
662
588
 
663
589
  /**
@@ -677,6 +603,8 @@ interface BrowserImage {
677
603
  svgString?: string;
678
604
  /** URL of image asset (svg, png, jpg) to render and load */
679
605
  url?: string;
606
+ /** Image asset as a Data URL. @internal For m2c2kit library use only */
607
+ dataUrl?: string;
680
608
  /** If true, the image will not be fully loaded until it is needed. Default
681
609
  * is false. Lazy loading is useful for large "banks" of images. These should
682
610
  * be lazy loaded because they may not be needed. */
@@ -950,158 +878,63 @@ interface LocalizationOptions {
950
878
  /**
951
879
  * Options to specify HTML canvas, set game canvas size, and load game assets.
952
880
  */
953
- interface GameOptions extends LocalizationOptions {
954
- /** Human-friendly name of this game */
955
- name: string;
956
- /** Short identifier of this game; unique among published games and url-friendly (no spaces, special characters, or slashes). */
957
- id: string;
958
- /** Persistent unique identifier (UUID) of this game; unique among published games. The m2c2kit CLI will generate this property automatically, and you should not change it. If not using the CLI, use a website like https://www.uuidgenerator.net/version4 to generate this value. */
959
- publishUuid: string;
960
- /** Version of this game */
961
- version: string;
962
- /** Uri (repository, webpage, or other location where full information about the game can be found) */
963
- uri?: string;
964
- /** Brief description of game */
965
- shortDescription?: string;
966
- /** Full description of game */
967
- longDescription?: string;
968
- /** Id of the HTML canvas that game will be drawn on. If not provided, the first canvas found will be used */
969
- canvasId?: string;
970
- /** Width of game canvas */
971
- width: number;
972
- /** Height of game canvas */
973
- height: number;
974
- /** Stretch to fill screen? Default is false */
975
- stretch?: boolean;
976
- /** Schema of trial data; JSON object where key is variable name, value is data type */
977
- trialSchema?: TrialSchema;
978
- /** Default game parameters; JSON object where key is the game parameter, value is default value */
979
- parameters?: GameParameters;
980
- /** Font assets to use. The first element will be the default font */
981
- fonts?: Array<FontAsset>;
982
- /** Array of BrowserImage objects to render and load */
983
- images?: Array<BrowserImage>;
984
- /** Array of SoundAsset objects to fetch and decode */
985
- sounds?: Array<SoundAsset>;
986
- /** Show FPS in upper left corner? Default is false */
987
- showFps?: boolean;
988
- /** Color of the html body, if the game does not fill the screen. Useful for showing scene boundaries. Default is the scene background color */
989
- bodyBackgroundColor?: RgbaColor;
990
- /** Maximum number of activity metrics to log. */
991
- maximumRecordedActivityMetrics?: number;
992
- /** The FPS will be logged in game metrics if the FPS is lower than this value. Default is 59, as defined in Constants.FPS_METRIC_REPORT_THRESHOLD */
993
- fpsMetricReportThreshold?: number;
994
- /** Advance through time step-by-step, for development and debugging */
995
- timeStepping?: boolean;
996
- /** Show logs for WebGl activity? */
997
- logWebGl?: boolean;
998
- /** Should games within a session share wasm and font assets that have identical filenames, in order to reduce bandwidth? Default is true. */
999
- shareAssets?: boolean;
1000
- /** Game's module name, version, and dependencies. @internal For m2c2kit library use only */
1001
- moduleMetadata?: ModuleMetadata;
1002
- }
1003
-
1004
- interface GameData extends ActivityKeyValueData {
1005
- trials: Array<TrialData>;
1006
- }
1007
-
1008
- interface TranslationOptions {
1009
- [key: string]: unknown;
1010
- }
1011
- interface TextLocalizationResult {
1012
- text: string;
1013
- fontName?: string;
1014
- fontNames?: string[];
1015
- isFallbackOrMissingTranslation: boolean;
1016
- }
1017
- declare class I18n {
1018
- private _translation;
1019
- locale: string;
1020
- fallbackLocale: string;
1021
- baseLocale: string;
1022
- missingLocalizationColor: RgbaColor | undefined;
1023
- game: Game;
1024
- /**
1025
- * The I18n class localizes text and images.
1026
- *
1027
- * @param game - game instance
1028
- * @param options - {@link LocalizationOptions}
1029
- */
1030
- constructor(game: Game, options: LocalizationOptions);
1031
- /**
1032
- * Initializes the I18n instance and sets the initial locale.
1033
- *
1034
- * @remarks If the game instance has been configured to use a data store,
1035
- * the previously used locale and fallback locale will be retrieved from the
1036
- * data store if they have been previously set.
1037
- */
1038
- initialize(): Promise<void>;
1039
- private configureInitialLocale;
1040
- private localeTranslationAvailable;
1041
- switchToLocale(locale: string): void;
1042
- /**
1043
- *
1044
- * @param key - Translation key
1045
- * @param interpolation - Interpolation keys and values to replace
1046
- * placeholders in the translated text
1047
- * @returns a `TextLocalizationResult` object with the localized text, font
1048
- * information, and whether the translation is a fallback.
1049
- */
1050
- getTextLocalization(key: string, interpolation?: StringInterpolationMap): TextLocalizationResult;
1051
- /**
1052
- * Returns the translation text for the given key in the current locale.
1053
- *
1054
- * @remarks Optional interpolation keys and values can be provided to replace
1055
- * placeholders in the translated text. Placeholders are denoted by double
1056
- * curly braces.
1057
- *
1058
- * @param key - key to look up in the translation
1059
- * @param options - `TranslationOptions`, such as interpolation keys/values
1060
- * and whether to translate using the fallback locale
1061
- * @returns the translation text for the key in the current locale, or
1062
- * undefined if the key is not found
1063
- *
1064
- * @example
1065
- *
1066
- * ```
1067
- * const translation: Translation = {
1068
- * "en-US": {
1069
- * "GREETING": "Hello, {{name}}."
1070
- * }
1071
- * }
1072
- * ...
1073
- * i18n.t("GREETING", { name: "World" }); // returns "Hello, World."
1074
- *
1075
- * ```
1076
- */
1077
- t(key: string, options?: TranslationOptions): string | undefined;
1078
- /**
1079
- * Returns the translation text and font information for the given key in the
1080
- * current locale.
1081
- *
1082
- * @remarks Optional interpolation keys and values can be provided to replace
1083
- * placeholders in the translated text. Placeholders are denoted by double
1084
- * curly braces. See method {@link I18n.t()} for interpolation example.
1085
- *
1086
- * @param key - key to look up in the translation
1087
- * @param options - `TranslationOptions`, such as interpolation keys/values
1088
- * and whether to translate using the fallback locale
1089
- * @returns the translation text and font information for the key in the
1090
- * current locale, or undefined if the key is not found
1091
- */
1092
- tf(key: string, options?: TranslationOptions): TextAndFont | undefined;
1093
- private getKeyText;
1094
- private getKeyTextAndFont;
1095
- private insertInterpolations;
1096
- get translation(): Translation;
1097
- set translation(value: Translation);
1098
- private getEnvironmentLocale;
1099
- private mergeAdditionalTranslation;
1100
- static makeLocalizationParameters(): GameParameters;
1101
- private isTextWithFontCustomization;
1102
- private isStringOrTextWithFontCustomization;
1103
- private isStringArray;
1104
- private isString;
881
+ interface GameOptions extends LocalizationOptions {
882
+ /** Human-friendly name of this game */
883
+ name: string;
884
+ /** Short identifier of this game; unique among published games and url-friendly (no spaces, special characters, or slashes). */
885
+ id: string;
886
+ /** Persistent unique identifier (UUID) of this game; unique among published games. The m2c2kit CLI will generate this property automatically, and you should not change it. If not using the CLI, use a website like https://www.uuidgenerator.net/version4 to generate this value. */
887
+ publishUuid: string;
888
+ /** Version of this game */
889
+ version: string;
890
+ /** Uri (repository, webpage, or other location where full information about the game can be found) */
891
+ uri?: string;
892
+ /** Brief description of game */
893
+ shortDescription?: string;
894
+ /** Full description of game */
895
+ longDescription?: string;
896
+ /** Id of the HTML canvas that game will be drawn on. If not provided, the first canvas found will be used */
897
+ canvasId?: string;
898
+ /** Width of game canvas */
899
+ width: number;
900
+ /** Height of game canvas */
901
+ height: number;
902
+ /** Stretch to fill screen? Default is false */
903
+ stretch?: boolean;
904
+ /** Schema of trial data; JSON object where key is variable name, value is data type */
905
+ trialSchema?: TrialSchema;
906
+ /** Default game parameters; JSON object where key is the game parameter, value is default value */
907
+ parameters?: GameParameters;
908
+ /** Font assets to use. The first element will be the default font */
909
+ fonts?: Array<FontAsset>;
910
+ /** Array of BrowserImage objects to render and load */
911
+ images?: Array<BrowserImage>;
912
+ /** Array of SoundAsset objects to fetch and decode */
913
+ sounds?: Array<SoundAsset>;
914
+ /** Show FPS in upper left corner? Default is false */
915
+ showFps?: boolean;
916
+ /** Color of the html body, if the game does not fill the screen. Useful for showing scene boundaries. Default is the scene background color */
917
+ bodyBackgroundColor?: RgbaColor;
918
+ /** Maximum number of activity metrics to log. */
919
+ maximumRecordedActivityMetrics?: number;
920
+ /** The FPS will be logged in game metrics if the FPS is lower than this value. Default is 59, as defined in Constants.FPS_METRIC_REPORT_THRESHOLD */
921
+ fpsMetricReportThreshold?: number;
922
+ /** Advance through time step-by-step, for development and debugging */
923
+ timeStepping?: boolean;
924
+ /** Show controls for replaying and viewing the event store? Default is false */
925
+ showEventStoreControls?: boolean;
926
+ /** Should the game events be saved to the event store? Default is false */
927
+ recordEvents?: boolean;
928
+ /** Show logs for WebGl activity? */
929
+ logWebGl?: boolean;
930
+ /** Should games within a session share wasm and font assets that have identical filenames, in order to reduce bandwidth? Default is true. */
931
+ shareAssets?: boolean;
932
+ /** Game's module name, version, and dependencies. @internal For m2c2kit library use only */
933
+ moduleMetadata?: ModuleMetadata;
934
+ }
935
+
936
+ interface GameData extends ActivityKeyValueData {
937
+ trials: Array<TrialData>;
1105
938
  }
1106
939
 
1107
940
  /**
@@ -1555,6 +1388,99 @@ interface GameEvent extends M2Event<Activity> {
1555
1388
  target: Game;
1556
1389
  }
1557
1390
 
1391
+ type M2EventTarget = M2Node | Element | ImageManager | I18n;
1392
+
1393
+ /**
1394
+ * Event store mode.
1395
+ */
1396
+ declare const EventStoreMode: {
1397
+ readonly Disabled: "Disabled";
1398
+ readonly Record: "Record";
1399
+ readonly Replay: "Replay";
1400
+ };
1401
+ type EventStoreMode = (typeof EventStoreMode)[keyof typeof EventStoreMode];
1402
+ declare class EventStore {
1403
+ private events;
1404
+ private replayBeginTimestamp;
1405
+ private firstTimestamp;
1406
+ replayThoughSequence: number;
1407
+ serializedEventsBeforeReplay: string;
1408
+ mode: EventStoreMode;
1409
+ private serializeEvent;
1410
+ addEvent(event: M2Event<M2EventTarget>): void;
1411
+ addEvents(events: Array<M2Event<M2EventTarget>>): void;
1412
+ clearEvents(): void;
1413
+ record(): void;
1414
+ replay(events?: M2Event<M2EventTarget>[]): void;
1415
+ getEvents(): M2Event<M2EventTarget>[];
1416
+ dequeueEvents(timestamp: number): M2Event<M2EventTarget>[];
1417
+ get eventQueueLength(): number;
1418
+ /**
1419
+ * Sorts the events in the event store.
1420
+ *
1421
+ * @remarks The events are sorted by sequence number in ascending order.
1422
+ */
1423
+ private sortEventStore;
1424
+ }
1425
+
1426
+ declare class M2NodeFactory {
1427
+ /**
1428
+ * The `M2NodeFactory` creates nodes of the specified type with the specified
1429
+ * options for event replay.
1430
+ */
1431
+ constructor();
1432
+ /**
1433
+ * Creates a new node of the specified type with the specified options.
1434
+ *
1435
+ * @param type - The type of node to create
1436
+ * @param compositeType - The composite type of the node to create
1437
+ * @param options - The options to use when creating the node
1438
+ * @returns created node
1439
+ */
1440
+ createNode(type: string, compositeType: string | undefined, options: M2NodeOptions): M2Node;
1441
+ private hasClassRegistration;
1442
+ }
1443
+
1444
+ interface EventMaterializerOptions {
1445
+ game: Game;
1446
+ nodeFactory: M2NodeFactory;
1447
+ freeNodesScene: Scene;
1448
+ configureI18n(localizationOptions: LocalizationOptions): Promise<void>;
1449
+ }
1450
+ declare class EventMaterializer {
1451
+ private game;
1452
+ private nodeFactory;
1453
+ private freeNodesScene;
1454
+ private eventMaterializers;
1455
+ private configureI18n;
1456
+ /**
1457
+ * The `EventMaterializer` class is responsible for taking serialized events
1458
+ * from an event store and replaying them in the game.
1459
+ */
1460
+ constructor(options: EventMaterializerOptions);
1461
+ /**
1462
+ * Deserialize the events by materializing them into the game.
1463
+ *
1464
+ * @remarks This method is called when the game is replaying events from the
1465
+ * event store. Materializing an event means to take the event and apply its
1466
+ * changes to the game. For example, a `NodeNew` event will create a new node
1467
+ * in the game. A `NodePropertyChange` event will change a property of a node
1468
+ * in the game.
1469
+ *
1470
+ * @param events - The events to materialize
1471
+ */
1472
+ materialize(events: ReadonlyArray<M2Event<M2EventTarget>>): void;
1473
+ private materializeCompositeEvent;
1474
+ private materializeNodeNewEvent;
1475
+ private materializeNodePropertyChangeEvent;
1476
+ private materializeNodeAddChildEvent;
1477
+ private materializeNodeRemoveChildEvent;
1478
+ private materializeDomPointerDownEvent;
1479
+ private materializeBrowserImageDataReadyEvent;
1480
+ private materializeI18nDataReadyEvent;
1481
+ private materializeScenePresentEvent;
1482
+ }
1483
+
1558
1484
  interface TrialData {
1559
1485
  [key: string]: string | number | boolean | object | undefined | null;
1560
1486
  }
@@ -1592,12 +1518,18 @@ declare class Game implements Activity {
1592
1518
  private _imageManager?;
1593
1519
  private _soundManager?;
1594
1520
  manifest?: Manifest;
1521
+ eventStore: EventStore;
1522
+ private nodeFactory;
1523
+ private _eventMaterializer?;
1524
+ /** Nodes created during event replay */
1525
+ materializedNodes: M2Node[];
1595
1526
  /**
1596
1527
  * The base class for all games. New games should extend this class.
1597
1528
  *
1598
1529
  * @param options - {@link GameOptions}
1599
1530
  */
1600
1531
  constructor(options: GameOptions);
1532
+ private createFreeNodesScene;
1601
1533
  private getImportedModuleBaseUrl;
1602
1534
  private addLocalizationParametersToGameParameters;
1603
1535
  init(): Promise<void>;
@@ -1623,6 +1555,7 @@ declare class Game implements Activity {
1623
1555
  * @returns base URLs for game assets and CanvasKit wasm binary
1624
1556
  */
1625
1557
  resolveGameBaseUrls(game: Game): Promise<GameBaseUrls>;
1558
+ private configureI18n;
1626
1559
  initialize(): Promise<void>;
1627
1560
  /**
1628
1561
  * Returns the manifest, if manifest.json was created during the build.
@@ -1643,6 +1576,8 @@ declare class Game implements Activity {
1643
1576
  set imageManager(imageManager: ImageManager);
1644
1577
  get soundManager(): SoundManager;
1645
1578
  set soundManager(soundManager: SoundManager);
1579
+ get eventMaterializer(): EventMaterializer;
1580
+ set eventMaterializer(eventMaterializer: EventMaterializer);
1646
1581
  /**
1647
1582
  * Adds prefixes to a key to ensure that keys are unique across activities
1648
1583
  * and studies.
@@ -1775,7 +1710,7 @@ declare class Game implements Activity {
1775
1710
  surface?: Surface;
1776
1711
  private showFps?;
1777
1712
  private bodyBackgroundColor?;
1778
- private currentScene?;
1713
+ currentScene?: Scene;
1779
1714
  private priorUpdateTime?;
1780
1715
  private fpsTextFont?;
1781
1716
  private fpsTextPaint?;
@@ -1790,7 +1725,7 @@ declare class Game implements Activity {
1790
1725
  canvasCssWidth: number;
1791
1726
  canvasCssHeight: number;
1792
1727
  scenes: Scene[];
1793
- private freeNodesScene;
1728
+ freeNodesScene: Scene;
1794
1729
  private incomingSceneTransitions;
1795
1730
  private currentSceneSnapshot?;
1796
1731
  private pendingScreenshot?;
@@ -1852,6 +1787,19 @@ declare class Game implements Activity {
1852
1787
  * @param scene
1853
1788
  */
1854
1789
  addScene(scene: Scene): void;
1790
+ /**
1791
+ * Adds events from a node and its children to the game's event store.
1792
+ *
1793
+ * @remarks This method is first called when a scene is added to the game.
1794
+ * If the scene or any of its descendants was constructed or had its
1795
+ * properties changed before it was added to the game, these events were
1796
+ * stored within the node (because the game event store was not yet
1797
+ * available). This method retrieves these events from the node and adds
1798
+ * them to the game's event store.
1799
+ *
1800
+ * @param node - node that contains events to add
1801
+ */
1802
+ private addNodeEvents;
1855
1803
  /**
1856
1804
  * Adds multiple scenes to the game.
1857
1805
  *
@@ -1867,10 +1815,10 @@ declare class Game implements Activity {
1867
1815
  /**
1868
1816
  * Specifies the scene that will be presented upon the next frame draw.
1869
1817
  *
1870
- * @param scene
1818
+ * @param scene - the scene, its string name, or UUID
1871
1819
  * @param transition
1872
1820
  */
1873
- presentScene(scene: string | Scene, transition?: NoneTransition): void;
1821
+ presentScene(scene: string | Scene, transition?: Transition): void;
1874
1822
  /**
1875
1823
  * Gets the value of the game parameter. If parameterName
1876
1824
  * is not found, then throw exception.
@@ -1909,6 +1857,11 @@ declare class Game implements Activity {
1909
1857
  * @param entryScene - The scene (Scene object or its string name) to display when the game starts
1910
1858
  */
1911
1859
  start(entryScene?: Scene | string): Promise<void>;
1860
+ playEventsHandler(mouseEvent: MouseEvent): void;
1861
+ private replayEventsButtonEnabled;
1862
+ private setReplayEventsButtonEnabled;
1863
+ private setStopReplayButtonEnabled;
1864
+ private addEventControlsToDom;
1912
1865
  private addTimeSteppingControlsToDom;
1913
1866
  private updateTimeSteppingOutput;
1914
1867
  private advanceStepsHandler;
@@ -2234,6 +2187,326 @@ declare class Game implements Activity {
2234
2187
  private IsCanvasPointWithinNodeBounds;
2235
2188
  }
2236
2189
 
2190
+ /**
2191
+ * Map of placeholders to values for use in string interpolation.
2192
+ */
2193
+ interface StringInterpolationMap {
2194
+ [placeholder: string]: string;
2195
+ }
2196
+
2197
+ interface TranslationOptions {
2198
+ [key: string]: unknown;
2199
+ }
2200
+ interface TextLocalizationResult {
2201
+ text: string;
2202
+ fontName?: string;
2203
+ fontNames?: string[];
2204
+ isFallbackOrMissingTranslation: boolean;
2205
+ }
2206
+ declare class I18n {
2207
+ private _translation;
2208
+ locale: string;
2209
+ fallbackLocale: string;
2210
+ baseLocale: string;
2211
+ missingLocalizationColor: RgbaColor | undefined;
2212
+ game: Game;
2213
+ /**
2214
+ * The I18n class localizes text and images.
2215
+ *
2216
+ * @param game - game instance
2217
+ * @param options - {@link LocalizationOptions}
2218
+ */
2219
+ constructor(game: Game, options: LocalizationOptions);
2220
+ /**
2221
+ * Initializes the I18n instance and sets the initial locale.
2222
+ *
2223
+ * @remarks If the game instance has been configured to use a data store,
2224
+ * the previously used locale and fallback locale will be retrieved from the
2225
+ * data store if they have been previously set.
2226
+ */
2227
+ initialize(): Promise<void>;
2228
+ private configureInitialLocale;
2229
+ private localeTranslationAvailable;
2230
+ switchToLocale(locale: string): void;
2231
+ /**
2232
+ *
2233
+ * @param key - Translation key
2234
+ * @param interpolation - Interpolation keys and values to replace
2235
+ * placeholders in the translated text
2236
+ * @returns a `TextLocalizationResult` object with the localized text, font
2237
+ * information, and whether the translation is a fallback.
2238
+ */
2239
+ getTextLocalization(key: string, interpolation?: StringInterpolationMap): TextLocalizationResult;
2240
+ /**
2241
+ * Returns the translation text for the given key in the current locale.
2242
+ *
2243
+ * @remarks Optional interpolation keys and values can be provided to replace
2244
+ * placeholders in the translated text. Placeholders are denoted by double
2245
+ * curly braces.
2246
+ *
2247
+ * @param key - key to look up in the translation
2248
+ * @param options - `TranslationOptions`, such as interpolation keys/values
2249
+ * and whether to translate using the fallback locale
2250
+ * @returns the translation text for the key in the current locale, or
2251
+ * undefined if the key is not found
2252
+ *
2253
+ * @example
2254
+ *
2255
+ * ```
2256
+ * const translation: Translation = {
2257
+ * "en-US": {
2258
+ * "GREETING": "Hello, {{name}}."
2259
+ * }
2260
+ * }
2261
+ * ...
2262
+ * i18n.t("GREETING", { name: "World" }); // returns "Hello, World."
2263
+ *
2264
+ * ```
2265
+ */
2266
+ t(key: string, options?: TranslationOptions): string | undefined;
2267
+ /**
2268
+ * Returns the translation text and font information for the given key in the
2269
+ * current locale.
2270
+ *
2271
+ * @remarks Optional interpolation keys and values can be provided to replace
2272
+ * placeholders in the translated text. Placeholders are denoted by double
2273
+ * curly braces. See method {@link I18n.t()} for interpolation example.
2274
+ *
2275
+ * @param key - key to look up in the translation
2276
+ * @param options - `TranslationOptions`, such as interpolation keys/values
2277
+ * and whether to translate using the fallback locale
2278
+ * @returns the translation text and font information for the key in the
2279
+ * current locale, or undefined if the key is not found
2280
+ */
2281
+ tf(key: string, options?: TranslationOptions): TextAndFont | undefined;
2282
+ private getKeyText;
2283
+ private getKeyTextAndFont;
2284
+ private insertInterpolations;
2285
+ get translation(): Translation;
2286
+ set translation(value: Translation);
2287
+ private getEnvironmentLocale;
2288
+ private mergeAdditionalTranslation;
2289
+ static makeLocalizationParameters(): GameParameters;
2290
+ private isTextWithFontCustomization;
2291
+ private isStringOrTextWithFontCustomization;
2292
+ private isStringArray;
2293
+ private isString;
2294
+ }
2295
+
2296
+ /**
2297
+ * Base interface for all m2c2kit events.
2298
+ *
2299
+ * @remarks I would have named it Event, but that would collide with
2300
+ * the existing DOM Event
2301
+ */
2302
+ interface M2Event<T> {
2303
+ /** Type of event. */
2304
+ type: M2EventType | string;
2305
+ /** The object on which the event occurred. If the event has gone through serialization, the string will be the object's UUID (if an `M2Node`) or class name. */
2306
+ target: T | string;
2307
+ /** Has the event been taken care of by the listener and not be dispatched to other targets? */
2308
+ handled?: boolean;
2309
+ /** Timestamp of the event, `from performance.now()` */
2310
+ timestamp: number;
2311
+ /** Timestamp of th event, from `new Date().toISOString()` */
2312
+ iso8601Timestamp: string;
2313
+ /** Sequence number of event.
2314
+ * @remarks Sequence number is guaranteed to reflect order of events, but
2315
+ * not necessarily contiguous, e.g., could be 1, 2, 5, 10, 11, 24.
2316
+ * */
2317
+ sequence?: number;
2318
+ }
2319
+ interface DomPointerDownEvent extends M2Event<Element> {
2320
+ type: "DomPointerDown";
2321
+ target: Element;
2322
+ x: number;
2323
+ y: number;
2324
+ }
2325
+ interface CompositeEvent extends M2NodeEvent {
2326
+ /** The Composite on which the event occurred. If the event has gone through serialization, the string will be the composite's UUID. */
2327
+ target: Composite | string;
2328
+ type: "Composite";
2329
+ /** The type of the composite node. */
2330
+ compositeType: string;
2331
+ /** The type of the composite event. */
2332
+ compositeEventType: string;
2333
+ /** The composite event properties */
2334
+ [key: string]: number | string | boolean | object | null | undefined;
2335
+ }
2336
+ interface M2NodeNewEvent extends M2Event<M2Node> {
2337
+ type: "NodeNew";
2338
+ target: M2Node;
2339
+ /** The type of the new node. */
2340
+ nodeType: M2NodeType | string;
2341
+ /** If a composite node, the type of the composite. */
2342
+ compositeType?: string;
2343
+ /** The options of the at the time of instantiation. This includes options for any base types and interfaces. */
2344
+ nodeOptions: M2NodeOptions;
2345
+ }
2346
+ interface M2NodeAddChildEvent extends M2Event<M2Node> {
2347
+ type: "NodeAddChild";
2348
+ target: M2Node;
2349
+ /** The node's unique identifier (UUID). */
2350
+ uuid: string;
2351
+ /** The child node's unique identifier (UUID). */
2352
+ childUuid: string;
2353
+ }
2354
+ interface M2NodeRemoveChildEvent extends M2Event<M2Node> {
2355
+ type: "NodeRemoveChild";
2356
+ target: M2Node;
2357
+ /** The node's unique identifier (UUID). */
2358
+ uuid: string;
2359
+ /** The child node's unique identifier (UUID). */
2360
+ childUuid: string;
2361
+ }
2362
+ interface ScenePresentEvent extends M2Event<M2Node> {
2363
+ type: "ScenePresent";
2364
+ target: Scene;
2365
+ /** The node's unique identifier (UUID). */
2366
+ uuid: string;
2367
+ /** Transition type of the presented scene. */
2368
+ transitionType: TransitionType;
2369
+ direction?: TransitionDirection;
2370
+ duration?: number;
2371
+ easingType?: string;
2372
+ }
2373
+ interface M2NodePropertyChangeEvent extends M2Event<M2Node> {
2374
+ type: "NodePropertyChange";
2375
+ target: M2Node;
2376
+ /** The node's unique identifier (UUID). */
2377
+ uuid: string;
2378
+ /** The property that changed. */
2379
+ property: string;
2380
+ /** The new value of the property. */
2381
+ value: string | number | boolean | object | null | undefined;
2382
+ }
2383
+ interface BrowserImageDataReadyEvent extends M2Event<ImageManager> {
2384
+ type: "BrowserImageDataReady";
2385
+ target: ImageManager;
2386
+ /** The image name. */
2387
+ imageName: string;
2388
+ /** Width to scale image to */
2389
+ width: number;
2390
+ /** Height to scale image to */
2391
+ height: number;
2392
+ /** The image data URL. */
2393
+ dataUrl?: string;
2394
+ /** SVG string */
2395
+ svgString?: string;
2396
+ }
2397
+ interface I18nDataReadyEvent extends M2Event<I18n> {
2398
+ type: "I18nDataReadyEvent";
2399
+ target: I18n;
2400
+ localizationOptions: LocalizationOptions;
2401
+ }
2402
+ /**
2403
+ * The different events that are dispatched by m2c2kit core.
2404
+ */
2405
+ declare const M2EventType: {
2406
+ readonly ActivityStart: "ActivityStart";
2407
+ readonly ActivityEnd: "ActivityEnd";
2408
+ readonly ActivityCancel: "ActivityCancel";
2409
+ readonly ActivityData: "ActivityData";
2410
+ readonly GameWarmupStart: "GameWarmupStart";
2411
+ readonly GameWarmupEnd: "GameWarmupEnd";
2412
+ readonly TapDown: "TapDown";
2413
+ readonly TapUp: "TapUp";
2414
+ readonly TapUpAny: "TapUpAny";
2415
+ readonly TapLeave: "TapLeave";
2416
+ readonly PointerDown: "PointerDown";
2417
+ readonly PointerUp: "PointerUp";
2418
+ readonly PointerMove: "PointerMove";
2419
+ readonly PointerLeave: "PointerLeave";
2420
+ readonly Drag: "Drag";
2421
+ readonly DragStart: "DragStart";
2422
+ readonly DragEnd: "DragEnd";
2423
+ readonly Composite: "Composite";
2424
+ readonly FrameDidSimulatePhysics: "FrameDidSimulatePhysics";
2425
+ readonly SceneSetup: "SceneSetup";
2426
+ readonly SceneAppear: "SceneAppear";
2427
+ readonly ScenePresent: "ScenePresent";
2428
+ readonly NodeNew: "NodeNew";
2429
+ readonly NodeAddChild: "NodeAddChild";
2430
+ readonly NodeRemoveChild: "NodeRemoveChild";
2431
+ readonly NodePropertyChange: "NodePropertyChange";
2432
+ readonly DomPointerDown: "DomPointerDown";
2433
+ readonly BrowserImageDataReady: "BrowserImageDataReady";
2434
+ readonly I18nDataReadyEvent: "I18nDataReadyEvent";
2435
+ };
2436
+ type M2EventType = (typeof M2EventType)[keyof typeof M2EventType];
2437
+
2438
+ /**
2439
+ * Base interface for all m2c2kit event listeners.
2440
+ */
2441
+ interface M2EventListener<T> {
2442
+ /** Type of event to listen for. */
2443
+ type: M2EventType | string;
2444
+ /** Callback function to be called when the event is dispatched. */
2445
+ callback: (event: T) => void;
2446
+ /** Optional key (string identifier) used to identify the event listener. */
2447
+ key?: string;
2448
+ }
2449
+
2450
+ interface M2NodeEventListener<M2NodeEvent> extends M2EventListener<M2NodeEvent> {
2451
+ /** For composites that raise events, type of the composite node. */
2452
+ compositeType?: string;
2453
+ /** For composites that raise events, type of the composite event. */
2454
+ compositeEventType?: string;
2455
+ /** UUID of the node that the event listener is listening for. */
2456
+ nodeUuid: string;
2457
+ }
2458
+
2459
+ /**
2460
+ * Describes an interaction between the pointer (mouse, touches) and a node.
2461
+ *
2462
+ * @remarks I would have named it PointerEvent, but that would collide with
2463
+ * the existing DOM PointerEvent.
2464
+ */
2465
+ interface M2PointerEvent extends M2NodeEvent {
2466
+ /** Point that was tapped on node, relative to the node coordinate system */
2467
+ point: Point;
2468
+ /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
2469
+ buttons: number;
2470
+ }
2471
+
2472
+ /**
2473
+ * Describes an interaction of a pointer (mouse, touches) pressing a node.
2474
+ *
2475
+ * @remarks Unlike M2PointerEvent, TapEvent considers how the pointer, while
2476
+ * in the down state, moves in relation to the bounds of the node.
2477
+ */
2478
+ interface TapEvent extends M2NodeEvent {
2479
+ /** Point that was tapped on node, relative to the node coordinate system */
2480
+ point: Point;
2481
+ /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
2482
+ buttons: number;
2483
+ }
2484
+
2485
+ interface TextOptions {
2486
+ /** Text to be displayed */
2487
+ text?: string;
2488
+ /** Name of font to use for text. Must have been previously loaded */
2489
+ fontName?: string;
2490
+ /** Color of text. Default is Constants.DEFAULT_FONT_COLOR (WebColors.Black) */
2491
+ fontColor?: RgbaColor;
2492
+ /** Size of text. Default is Constants.DEFAULT_FONT_SIZE (16) */
2493
+ fontSize?: number;
2494
+ /** Map of placeholders to values for use in string interpolation during localization. */
2495
+ interpolation?: StringInterpolationMap;
2496
+ /** If true, try to use a localized version of the text. Default is true. */
2497
+ localize?: boolean;
2498
+ }
2499
+
2500
+ /**
2501
+ * Width and height on two-dimensional space
2502
+ */
2503
+ interface Size {
2504
+ /** Horizontal width, x-axis */
2505
+ width: number;
2506
+ /** Vertical height, y-axis */
2507
+ height: number;
2508
+ }
2509
+
2237
2510
  /**
2238
2511
  * Describes a drag and drop operation.
2239
2512
  *
@@ -2253,20 +2526,25 @@ declare abstract class M2Node implements M2NodeOptions {
2253
2526
  isDrawable: boolean;
2254
2527
  isShape: boolean;
2255
2528
  isText: boolean;
2529
+ private _suppressEvents;
2530
+ options: M2NodeOptions;
2531
+ constructionTimeStamp: number;
2532
+ constructionIso8601TimeStamp: string;
2533
+ constructionSequence: number;
2256
2534
  name: string;
2257
2535
  _position: Point;
2258
2536
  _scale: number;
2259
- alpha: number;
2537
+ _alpha: number;
2260
2538
  _zRotation: number;
2261
2539
  protected _isUserInteractionEnabled: boolean;
2262
- draggable: boolean;
2263
- hidden: boolean;
2540
+ protected _draggable: boolean;
2541
+ protected _hidden: boolean;
2264
2542
  layout: Layout;
2265
2543
  _game?: Game;
2266
2544
  parent?: M2Node;
2267
2545
  children: M2Node[];
2268
2546
  absolutePosition: Point;
2269
- size: Size;
2547
+ protected _size: Size;
2270
2548
  absoluteScale: number;
2271
2549
  absoluteAlpha: number;
2272
2550
  absoluteAlphaChange: number;
@@ -2277,6 +2555,7 @@ declare abstract class M2Node implements M2NodeOptions {
2277
2555
  needsInitialization: boolean;
2278
2556
  userData: any;
2279
2557
  loopMessages: Set<string>;
2558
+ nodeEvents: M2Event<M2Node>[];
2280
2559
  /** Is the node in a pressed state? E.g., did the user put the pointer
2281
2560
  * down on the node and not yet release it? */
2282
2561
  pressed: boolean;
@@ -2297,6 +2576,28 @@ declare abstract class M2Node implements M2NodeOptions {
2297
2576
  dragging: boolean;
2298
2577
  constructor(options?: M2NodeOptions);
2299
2578
  initialize(): void;
2579
+ protected get completeNodeOptions(): M2NodeOptions;
2580
+ /**
2581
+ * Save the node's construction event in the event store.
2582
+ */
2583
+ protected saveNodeNewEvent(): void;
2584
+ /**
2585
+ * Saves the node's property change event in the event store.
2586
+ *
2587
+ * @param property - property name
2588
+ * @param value - property value
2589
+ */
2590
+ protected savePropertyChangeEvent(property: string, value: string | number | boolean | object | null | undefined): void;
2591
+ /**
2592
+ * Saves the node's event.
2593
+ *
2594
+ * @remarks If the game event store is not available, the event is saved
2595
+ * within the node's `nodeEvents` event array. It will be added to the game
2596
+ * event store when the node is added to the game.
2597
+ *
2598
+ * @param event - event to save
2599
+ */
2600
+ protected saveEvent(event: M2Event<M2Node>): void;
2300
2601
  /**
2301
2602
  * The game which this node is a part of.
2302
2603
  *
@@ -2323,6 +2624,15 @@ declare abstract class M2Node implements M2NodeOptions {
2323
2624
  * @param child - The child node to add
2324
2625
  */
2325
2626
  addChild(child: M2Node): void;
2627
+ /**
2628
+ * Saves the child's events to the parent node.
2629
+ *
2630
+ * @remarks When a child is added to a parent, the parent receives all the
2631
+ * child's events and saves them.
2632
+ *
2633
+ * @param child - child node to save events to parent node
2634
+ */
2635
+ private saveChildEvents;
2326
2636
  /**
2327
2637
  * Removes all children from the node.
2328
2638
  */
@@ -2554,14 +2864,24 @@ declare abstract class M2Node implements M2NodeOptions {
2554
2864
  */
2555
2865
  get canvasKit(): CanvasKit;
2556
2866
  get parentSceneAsNode(): M2Node;
2867
+ get size(): Size;
2868
+ set size(size: Size);
2557
2869
  get position(): Point;
2558
2870
  set position(position: Point);
2559
2871
  get zRotation(): number;
2560
2872
  set zRotation(zRotation: number);
2561
2873
  get scale(): number;
2562
2874
  set scale(scale: number);
2875
+ get alpha(): number;
2876
+ set alpha(alpha: number);
2563
2877
  get isUserInteractionEnabled(): boolean;
2564
2878
  set isUserInteractionEnabled(isUserInteractionEnabled: boolean);
2879
+ get hidden(): boolean;
2880
+ set hidden(hidden: boolean);
2881
+ get draggable(): boolean;
2882
+ set draggable(draggable: boolean);
2883
+ get suppressEvents(): boolean;
2884
+ set suppressEvents(value: boolean);
2565
2885
  /**
2566
2886
  * For a given directed acyclic graph, topological ordering of the vertices will be identified using BFS
2567
2887
  * @param adjList Adjacency List that represent a graph with vertices and edges
@@ -3310,28 +3630,6 @@ declare class ColorfulMutablePath extends MutablePath {
3310
3630
  duplicate(): ColorfulMutablePath;
3311
3631
  }
3312
3632
 
3313
- interface CompositeOptions extends M2NodeOptions, DrawableOptions {
3314
- }
3315
-
3316
- declare abstract class Composite extends M2Node implements IDrawable {
3317
- readonly type = M2NodeType.Composite;
3318
- compositeType: string;
3319
- isDrawable: boolean;
3320
- anchorPoint: Point;
3321
- zPosition: number;
3322
- /**
3323
- * Base Drawable object for creating custom nodes ("composites") composed of primitive nodes.
3324
- *
3325
- * @param options
3326
- */
3327
- constructor(options?: CompositeOptions);
3328
- initialize(): void;
3329
- dispose(): void;
3330
- update(): void;
3331
- draw(canvas: Canvas): void;
3332
- abstract warmup(canvas: Canvas): void;
3333
- }
3334
-
3335
3633
  /**
3336
3634
  * Reasonable defaults to use if values are not specified.
3337
3635
  */
@@ -3390,10 +3688,79 @@ declare enum Dimensions {
3390
3688
  MatchConstraint = 0
3391
3689
  }
3392
3690
 
3691
+ type M2NodeConstructor = new (options?: M2NodeOptions) => M2Node;
3692
+
3393
3693
  /**
3394
3694
  * Utility class for comparing equality of m2c2kit objects.
3695
+ *
3696
+ * @deprecated Use the class `Equal` instead.
3395
3697
  */
3396
3698
  declare class Equals {
3699
+ /**
3700
+ * Compares two RgbaColor objects and returns true if they are equal.
3701
+ *
3702
+ * @remarks If either of the colors is undefined, the comparison will
3703
+ * return false. RgbaColor is an array of 4 numbers, and thus is a
3704
+ * reference type. We need this method to compare two RgbaColor objects
3705
+ * for value equality.
3706
+ *
3707
+ * @deprecated Use the methods in `Equal` instead.
3708
+ *
3709
+ * @param color1
3710
+ * @param color2
3711
+ * @returns
3712
+ */
3713
+ static rgbaColor(color1?: RgbaColor, color2?: RgbaColor): boolean;
3714
+ }
3715
+
3716
+ interface RectOptions {
3717
+ /** Position of rectangle */
3718
+ origin?: Point;
3719
+ /** Size of rectangle */
3720
+ size?: Size;
3721
+ /** X coordinate of rectangle position; this can be used instead of setting the origin property */
3722
+ x?: number;
3723
+ /** Y coordinate of rectangle position; this can be used instead of setting the origin property */
3724
+ y?: number;
3725
+ /** Width of rectangle; this can be used instead of setting the size property */
3726
+ width?: number;
3727
+ /** Height of rectangle; this can be used instead of setting the size property */
3728
+ height?: number;
3729
+ }
3730
+
3731
+ /**
3732
+ * A collection of multi-color lines to draw.
3733
+ *
3734
+ * @remarks Unlike `M2Path`, this interface allows for lines of different
3735
+ * colors and widths to be drawn in the same path.
3736
+ */
3737
+ interface M2ColorfulPath extends M2Path {
3738
+ /** Colors and widths of lines in the path. */
3739
+ linePresentations: Array<LinePresentation>;
3740
+ }
3741
+
3742
+ /**
3743
+ * A path created from an SVG string path.
3744
+ */
3745
+ interface SvgStringPath {
3746
+ /** SVG string from which to create the path */
3747
+ pathString?: string;
3748
+ /** SVG string from which to create the path @deprecated Use `pathString` */
3749
+ svgPathString?: string;
3750
+ /** If provided, scale the SVG path to this height, and scale the width to keep the original SVG proportions */
3751
+ height?: number;
3752
+ /** If provided, scale the SVG path to this width, and scale the height to keep the original SVG proportions */
3753
+ width?: number;
3754
+ }
3755
+
3756
+ type ValueType = string | number | boolean | null | undefined | Array<ValueType> | {
3757
+ [key: string]: ValueType;
3758
+ } | Point | RectOptions | M2Path | M2ColorfulPath | SvgStringPath | Size;
3759
+ /**
3760
+ * Utility class for comparing equality of m2c2kit objects.
3761
+ *
3762
+ */
3763
+ declare class Equal {
3397
3764
  /**
3398
3765
  * Compares two RgbaColor objects and returns true if they are equal.
3399
3766
  *
@@ -3407,6 +3774,28 @@ declare class Equals {
3407
3774
  * @returns
3408
3775
  */
3409
3776
  static rgbaColor(color1?: RgbaColor, color2?: RgbaColor): boolean;
3777
+ /**
3778
+ * Compares two values for deep equality.
3779
+ *
3780
+ * @remarks Supported values are string, number, boolean, null, undefined,
3781
+ * and object (note that arrays are objects in JavaScript).
3782
+ *
3783
+ * @param value1 - value to compare
3784
+ * @param value2 - value to compare
3785
+ * @returns true if values have deep equality
3786
+ */
3787
+ static value(value1: ValueType, value2: ValueType): boolean;
3788
+ /**
3789
+ * Compares two objects for deep equality.
3790
+ *
3791
+ * @remarks In JavaScript, arrays are objects, so this method will also
3792
+ * compare arrays for deep equality.
3793
+ *
3794
+ * @param obj1 - object to compare
3795
+ * @param obj2 - object to compare
3796
+ * @returns true if objects have deep equality
3797
+ */
3798
+ private static objectsDeepEqual;
3410
3799
  }
3411
3800
 
3412
3801
  /**
@@ -3451,6 +3840,57 @@ declare class M2c2KitHelpers {
3451
3840
  * "https://", "file://", etc.)
3452
3841
  */
3453
3842
  static urlHasScheme(url: string): boolean;
3843
+ /**
3844
+ * Registers a `M2Node` class with the global class registry.
3845
+ *
3846
+ * @remarks This is used to register a class so that it can be
3847
+ * instantiated by the `M2NodeFactory`.
3848
+ *
3849
+ * @param nodeClass - class or classes to register.
3850
+ */
3851
+ static registerM2NodeClass(...nodeClass: Array<M2NodeConstructor>): void;
3852
+ /**
3853
+ * Creates timestamps based on when the current frame's update began.
3854
+ *
3855
+ * @remarks When recording events related to node creation, node
3856
+ * parent-child relationships, and node properties, the timestamps should be
3857
+ * based on when current frame's update began -- not the current time. While
3858
+ * current time is most accurate for recording user interactions (use
3859
+ * `M2c2KitHelpers.createTimestamps()` for user interactions), the frame's
3860
+ * update is the best way to ensure that node events that occurred in the same
3861
+ * frame are recorded with the same timestamp and thus are replayed in the
3862
+ * correct order. For example, a node may be created, added to a scene, and
3863
+ * have its hidden property set to true, all in the same frame. If the
3864
+ * current timestamps were used for all these events, it could happen that
3865
+ * the hidden property is set slightly after the node is added to the scene.
3866
+ * When replayed, this could cause the node to be visible for a single frame
3867
+ * if the queue of replay events pulls only the creation and addition events.
3868
+ * By using the frame's update time, we ensure that all events related to a
3869
+ * node are recorded with the same timestamp and are replayed in the same
3870
+ * frame.
3871
+ * If game has not yet begun to run (i.e., frame updates have not yet started),
3872
+ * the timestamps will be based on the current time.
3873
+ *
3874
+ * @returns object with timestamps
3875
+ */
3876
+ static createFrameUpdateTimestamps(): {
3877
+ timestamp: number;
3878
+ iso8601Timestamp: string;
3879
+ };
3880
+ /**
3881
+ * Creates timestamps based on the current time.
3882
+ *
3883
+ * @remarks Use `M2c2KitHelpers.createFrameUpdateTimestamps()` when requesting
3884
+ * timestamps for events related to node creation, parent-child
3885
+ * relationships, and properties.
3886
+ * See {@link createFrameUpdateTimestamps()} for explanation.
3887
+ *
3888
+ * @returns object with `timestamp` and `iso8601Timestamp` properties
3889
+ */
3890
+ static createTimestamps(): {
3891
+ timestamp: number;
3892
+ iso8601Timestamp: string;
3893
+ };
3454
3894
  /**
3455
3895
  * Calculates the four points of the bounding box of the node, taking
3456
3896
  * into account the node's rotation (as well as the rotation of its
@@ -3592,6 +4032,37 @@ interface FontData {
3592
4032
  isDefault: boolean;
3593
4033
  }
3594
4034
 
4035
+ declare global {
4036
+ var m2c2Globals: GlobalVariables;
4037
+ }
4038
+ interface GlobalVariables {
4039
+ now: number;
4040
+ iso8601Now: string;
4041
+ deltaTime: number;
4042
+ canvasScale: number;
4043
+ /**
4044
+ * rootScale is the scaling factor to be applied to scenes to scale up or
4045
+ * down to fit the device's window while preserving the aspect ratio the
4046
+ * game was designed for
4047
+ */
4048
+ rootScale: number;
4049
+ canvasCssWidth: number;
4050
+ canvasCssHeight: number;
4051
+ /**
4052
+ * A dictionary of all `M2Node` classes that have been registered.
4053
+ * This is used to instantiate `M2Node` objects from their class name.
4054
+ *
4055
+ * @remarks The type should be `{ [key: string]: M2NodeConstructor }` or
4056
+ * `M2NodeClassRegistry`. But, this creates problems in Jest: I could not
4057
+ * get ts-jest to compile when the type of a global variable is not a
4058
+ * simple type. Instead, the type of `m2NodeClassRegistry` is `object`,
4059
+ * and I will assert it to `M2NodeClassRegistry` when needed.
4060
+ */
4061
+ m2NodeClassRegistry: object;
4062
+ get eventSequence(): number;
4063
+ __sequence: number;
4064
+ }
4065
+
3595
4066
  interface IText {
3596
4067
  text?: string;
3597
4068
  fontName?: string;
@@ -3622,11 +4093,8 @@ declare class Label extends M2Node implements IDrawable, IText, LabelOptions {
3622
4093
  readonly type = M2NodeType.Label;
3623
4094
  isDrawable: boolean;
3624
4095
  isText: boolean;
3625
- anchorPoint: {
3626
- x: number;
3627
- y: number;
3628
- };
3629
- zPosition: number;
4096
+ private _anchorPoint;
4097
+ private _zPosition;
3630
4098
  private _text;
3631
4099
  private _fontName;
3632
4100
  private _fontNames;
@@ -3652,6 +4120,31 @@ declare class Label extends M2Node implements IDrawable, IText, LabelOptions {
3652
4120
  * @param options - {@link LabelOptions}
3653
4121
  */
3654
4122
  constructor(options?: LabelOptions);
4123
+ get completeNodeOptions(): {
4124
+ horizontalAlignmentMode: LabelHorizontalAlignmentMode;
4125
+ preferredMaxLayoutWidth: number | undefined;
4126
+ backgroundColor: RgbaColor | undefined;
4127
+ fontNames: string[] | undefined;
4128
+ text?: string;
4129
+ fontName?: string;
4130
+ fontColor?: RgbaColor;
4131
+ fontSize?: number;
4132
+ interpolation?: StringInterpolationMap;
4133
+ localize?: boolean;
4134
+ anchorPoint?: Point;
4135
+ zPosition?: number;
4136
+ name?: string;
4137
+ position?: Point;
4138
+ scale?: number;
4139
+ alpha?: number;
4140
+ zRotation?: number;
4141
+ isUserInteractionEnabled?: boolean;
4142
+ draggable?: boolean;
4143
+ hidden?: boolean;
4144
+ layout?: Layout;
4145
+ uuid?: string;
4146
+ suppressEvents?: boolean;
4147
+ };
3655
4148
  initialize(): void;
3656
4149
  /**
3657
4150
  * Determines the M2Font objects that need to be ready in order to draw
@@ -3685,6 +4178,10 @@ declare class Label extends M2Node implements IDrawable, IText, LabelOptions {
3685
4178
  set backgroundColor(backgroundColor: RgbaColor | undefined);
3686
4179
  get localize(): boolean;
3687
4180
  set localize(localize: boolean);
4181
+ get anchorPoint(): Point;
4182
+ set anchorPoint(anchorPoint: Point);
4183
+ get zPosition(): number;
4184
+ set zPosition(zPosition: number);
3688
4185
  private get backgroundPaint();
3689
4186
  private set backgroundPaint(value);
3690
4187
  private get fontPaint();
@@ -3848,17 +4345,6 @@ declare class LegacyTimer {
3848
4345
  static exists(name: string): boolean;
3849
4346
  }
3850
4347
 
3851
- /**
3852
- * A collection of multi-color lines to draw.
3853
- *
3854
- * @remarks Unlike `M2Path`, this interface allows for lines of different
3855
- * colors and widths to be drawn in the same path.
3856
- */
3857
- interface M2ColorfulPath extends M2Path {
3858
- /** Colors and widths of lines in the path. */
3859
- linePresentations: Array<LinePresentation>;
3860
- }
3861
-
3862
4348
  /** Base interface for all Plugin events. */
3863
4349
  interface PluginEvent extends M2Event<Plugin> {
3864
4350
  target: Plugin;
@@ -3906,21 +4392,6 @@ declare class RandomDraws {
3906
4392
  }>;
3907
4393
  }
3908
4394
 
3909
- interface RectOptions {
3910
- /** Position of rectangle */
3911
- origin?: Point;
3912
- /** Size of rectangle */
3913
- size?: Size;
3914
- /** X coordinate of rectangle position; this can be used instead of setting the origin property */
3915
- x?: number;
3916
- /** Y coordinate of rectangle position; this can be used instead of setting the origin property */
3917
- y?: number;
3918
- /** Width of rectangle; this can be used instead of setting the size property */
3919
- width?: number;
3920
- /** Height of rectangle; this can be used instead of setting the size property */
3921
- height?: number;
3922
- }
3923
-
3924
4395
  declare enum ShapeType {
3925
4396
  Undefined = "Undefined",
3926
4397
  Rectangle = "Rectangle",
@@ -3928,20 +4399,6 @@ declare enum ShapeType {
3928
4399
  Path = "Path"
3929
4400
  }
3930
4401
 
3931
- /**
3932
- * A path created from an SVG string path.
3933
- */
3934
- interface SvgStringPath {
3935
- /** SVG string from which to create the path */
3936
- pathString?: string;
3937
- /** SVG string from which to create the path @deprecated Use `pathString` */
3938
- svgPathString?: string;
3939
- /** If provided, scale the SVG path to this height, and scale the width to keep the original SVG proportions */
3940
- height?: number;
3941
- /** If provided, scale the SVG path to this width, and scale the height to keep the original SVG proportions */
3942
- width?: number;
3943
- }
3944
-
3945
4402
  interface ShapeOptions extends M2NodeOptions, DrawableOptions {
3946
4403
  shapeType?: ShapeType;
3947
4404
  /** If provided, shape will be a circle with given radius */
@@ -3968,22 +4425,19 @@ declare class Shape extends M2Node implements IDrawable, ShapeOptions {
3968
4425
  readonly type = M2NodeType.Shape;
3969
4426
  isDrawable: boolean;
3970
4427
  isShape: boolean;
3971
- anchorPoint: {
3972
- x: number;
3973
- y: number;
3974
- };
3975
- zPosition: number;
4428
+ private _anchorPoint;
4429
+ private _zPosition;
3976
4430
  shapeType: ShapeType;
3977
- circleOfRadius?: number;
3978
- rect?: RectOptions;
3979
- path?: M2Path | M2ColorfulPath | SvgStringPath;
4431
+ private _circleOfRadius?;
4432
+ private _rect?;
4433
+ private _path?;
3980
4434
  ckPath: Path | null;
3981
4435
  ckPathWidth?: number;
3982
4436
  ckPathHeight?: number;
3983
- cornerRadius: number;
4437
+ private _cornerRadius;
3984
4438
  private _fillColor;
3985
4439
  private _strokeColor?;
3986
- lineWidth?: number;
4440
+ private _lineWidth?;
3987
4441
  private _isAntialiased;
3988
4442
  private _fillColorPaintAntialiased?;
3989
4443
  private _strokeColorPaintAntialiased?;
@@ -4004,7 +4458,35 @@ declare class Shape extends M2Node implements IDrawable, ShapeOptions {
4004
4458
  * @param options - {@link ShapeOptions}
4005
4459
  */
4006
4460
  constructor(options?: ShapeOptions);
4461
+ get completeNodeOptions(): {
4462
+ circleOfRadius: number | undefined;
4463
+ rect: RectOptions | undefined;
4464
+ cornerRadius: number;
4465
+ fillColor: RgbaColor;
4466
+ strokeColor: RgbaColor | undefined;
4467
+ lineWidth: number | undefined;
4468
+ path: M2Path | M2ColorfulPath | SvgStringPath | undefined;
4469
+ size: Size | undefined;
4470
+ isAntialiased: boolean;
4471
+ anchorPoint?: Point;
4472
+ zPosition?: number;
4473
+ name?: string;
4474
+ position?: Point;
4475
+ scale?: number;
4476
+ alpha?: number;
4477
+ zRotation?: number;
4478
+ isUserInteractionEnabled?: boolean;
4479
+ draggable?: boolean;
4480
+ hidden?: boolean;
4481
+ layout?: Layout;
4482
+ uuid?: string;
4483
+ suppressEvents?: boolean;
4484
+ };
4007
4485
  initialize(): void;
4486
+ get anchorPoint(): Point;
4487
+ set anchorPoint(anchorPoint: Point);
4488
+ get zPosition(): number;
4489
+ set zPosition(zPosition: number);
4008
4490
  dispose(): void;
4009
4491
  /**
4010
4492
  * Duplicates a node using deep copy.
@@ -4042,6 +4524,16 @@ declare class Shape extends M2Node implements IDrawable, ShapeOptions {
4042
4524
  private warmupStrokedCircle;
4043
4525
  private warmupFilledRectangle;
4044
4526
  private warmupStrokedRectangle;
4527
+ get circleOfRadius(): number | undefined;
4528
+ set circleOfRadius(circleOfRadius: number | undefined);
4529
+ get rect(): RectOptions | undefined;
4530
+ set rect(rect: RectOptions | undefined);
4531
+ get cornerRadius(): number;
4532
+ set cornerRadius(cornerRadius: number | undefined);
4533
+ get lineWidth(): number | undefined;
4534
+ set lineWidth(lineWidth: number | undefined);
4535
+ get path(): M2Path | M2ColorfulPath | SvgStringPath | undefined;
4536
+ set path(path: M2Path | M2ColorfulPath | SvgStringPath | undefined);
4045
4537
  get fillColor(): RgbaColor;
4046
4538
  set fillColor(fillColor: RgbaColor);
4047
4539
  get strokeColor(): RgbaColor | undefined;
@@ -4191,11 +4683,8 @@ interface SpriteOptions extends M2NodeOptions, DrawableOptions {
4191
4683
  declare class Sprite extends M2Node implements IDrawable, SpriteOptions {
4192
4684
  readonly type = M2NodeType.Sprite;
4193
4685
  isDrawable: boolean;
4194
- anchorPoint: {
4195
- x: number;
4196
- y: number;
4197
- };
4198
- zPosition: number;
4686
+ private _anchorPoint;
4687
+ private _zPosition;
4199
4688
  private _imageName;
4200
4689
  private m2Image?;
4201
4690
  private _paint?;
@@ -4207,10 +4696,30 @@ declare class Sprite extends M2Node implements IDrawable, SpriteOptions {
4207
4696
  * @param options - {@link SpriteOptions}
4208
4697
  */
4209
4698
  constructor(options?: SpriteOptions);
4699
+ get completeNodeOptions(): {
4700
+ imageName: string;
4701
+ anchorPoint?: Point;
4702
+ zPosition?: number;
4703
+ name?: string;
4704
+ position?: Point;
4705
+ scale?: number;
4706
+ alpha?: number;
4707
+ zRotation?: number;
4708
+ isUserInteractionEnabled?: boolean;
4709
+ draggable?: boolean;
4710
+ hidden?: boolean;
4711
+ layout?: Layout;
4712
+ uuid?: string;
4713
+ suppressEvents?: boolean;
4714
+ };
4210
4715
  initialize(): void;
4211
4716
  dispose(): void;
4212
- set imageName(imageName: string);
4213
4717
  get imageName(): string;
4718
+ set imageName(imageName: string);
4719
+ get anchorPoint(): Point;
4720
+ set anchorPoint(anchorPoint: Point);
4721
+ get zPosition(): number;
4722
+ set zPosition(zPosition: number);
4214
4723
  private set paint(value);
4215
4724
  private get paint();
4216
4725
  /**
@@ -4257,11 +4766,8 @@ declare class TextLine extends M2Node implements IDrawable, IText, TextLineOptio
4257
4766
  readonly type = M2NodeType.TextLine;
4258
4767
  isDrawable: boolean;
4259
4768
  isText: boolean;
4260
- zPosition: number;
4261
- anchorPoint: {
4262
- x: number;
4263
- y: number;
4264
- };
4769
+ private _zPosition;
4770
+ private _anchorPoint;
4265
4771
  private _text;
4266
4772
  private _fontName;
4267
4773
  private _fontColor;
@@ -4284,6 +4790,28 @@ declare class TextLine extends M2Node implements IDrawable, IText, TextLineOptio
4284
4790
  * @param options - {@link TextLineOptions}
4285
4791
  */
4286
4792
  constructor(options?: TextLineOptions);
4793
+ get completeNodeOptions(): {
4794
+ width: number;
4795
+ text?: string;
4796
+ fontName?: string;
4797
+ fontColor?: RgbaColor;
4798
+ fontSize?: number;
4799
+ interpolation?: StringInterpolationMap;
4800
+ localize?: boolean;
4801
+ anchorPoint?: Point;
4802
+ zPosition?: number;
4803
+ name?: string;
4804
+ position?: Point;
4805
+ scale?: number;
4806
+ alpha?: number;
4807
+ zRotation?: number;
4808
+ isUserInteractionEnabled?: boolean;
4809
+ draggable?: boolean;
4810
+ hidden?: boolean;
4811
+ layout?: Layout;
4812
+ uuid?: string;
4813
+ suppressEvents?: boolean;
4814
+ };
4287
4815
  initialize(): void;
4288
4816
  /**
4289
4817
  * Determines the M2Font object that needs to be ready in order to draw
@@ -4310,6 +4838,10 @@ declare class TextLine extends M2Node implements IDrawable, IText, TextLineOptio
4310
4838
  set interpolation(interpolation: StringInterpolationMap);
4311
4839
  get localize(): boolean;
4312
4840
  set localize(localize: boolean);
4841
+ get anchorPoint(): Point;
4842
+ set anchorPoint(anchorPoint: Point);
4843
+ get zPosition(): number;
4844
+ set zPosition(zPosition: number);
4313
4845
  dispose(): void;
4314
4846
  /**
4315
4847
  * Duplicates a node using deep copy.
@@ -4612,4 +5144,4 @@ declare class WebGlInfo {
4612
5144
  static dispose(): void;
4613
5145
  }
4614
5146
 
4615
- export { Action, type Activity, type ActivityCallbacks, type ActivityEvent, type ActivityEventListener, type ActivityKeyValueData, type ActivityLifecycleEvent, type ActivityResultsEvent, ActivityType, type BrowserImage, type CallbackOptions, CanvasKitHelpers, ColorfulMutablePath, Composite, type CompositeOptions, Constants, ConstraintType, type Constraints, CustomAction, type CustomActionOptions, type DefaultParameter, Dimensions, type DrawableOptions, type EasingFunction, Easings, Equals, FadeAlphaAction, type FadeAlphaActionOptions, type FontAsset, type FontData, FontManager, Game, type GameData, type GameEvent, type GameOptions, type GameParameters, GlobalVariables, GroupAction, I18n, type IDataStore, type IDrawable, type IText, ImageManager, Label, LabelHorizontalAlignmentMode, type LabelOptions, type Layout, LayoutConstraint, LegacyTimer, type LocaleSvg, type M2ColorfulPath, type M2DragEvent, type M2Event, type M2EventListener, M2EventType, type M2Image, M2ImageStatus, M2Node, type M2NodeEvent, type M2NodeEventListener, type M2NodeOptions, M2NodeType, type M2Path, type M2PointerEvent, type M2Sound, M2SoundStatus, M2c2KitHelpers, MoveAction, type MoveActionOptions, MutablePath, NoneTransition, PlayAction, type PlayActionOptions, type Plugin, type PluginEvent, type Point, RandomDraws, type RectOptions, RepeatAction, RepeatForeverAction, type RgbaColor, RotateAction, ScaleAction, type ScaleActionOptions, Scene, type SceneOptions, SceneTransition, SequenceAction, Shape, type ShapeOptions, ShapeType, type Size, SlideTransition, type SlideTransitionOptions, type SoundAsset, SoundManager, SoundPlayer, type SoundPlayerOptions, SoundRecorder, type SoundRecorderOptions, type SoundRecorderResults, Sprite, type SpriteOptions, Story, type StoryOptions, type StringInterpolationMap, type TapEvent, type TextAndFont, TextLine, type TextLineOptions, type TextLocalizationResult, type TextOptions, type TextWithFontCustomization, Timer, Transition, TransitionDirection, TransitionType, type Translation, type TranslationConfiguration, type TranslationOptions, type TrialData, type TrialSchema, Uuid, WaitAction, type WaitActionOptions, WebColors, WebGlInfo, handleInterfaceOptions };
5147
+ export { Action, type Activity, type ActivityCallbacks, type ActivityEvent, type ActivityEventListener, type ActivityKeyValueData, type ActivityLifecycleEvent, type ActivityResultsEvent, ActivityType, type BrowserImage, type BrowserImageDataReadyEvent, type CallbackOptions, CanvasKitHelpers, ColorfulMutablePath, Composite, type CompositeEvent, type CompositeOptions, Constants, ConstraintType, type Constraints, CustomAction, type CustomActionOptions, type DefaultParameter, Dimensions, type DomPointerDownEvent, type DrawableOptions, type EasingFunction, Easings, Equal, Equals, EventStore, EventStoreMode, FadeAlphaAction, type FadeAlphaActionOptions, type FontAsset, type FontData, FontManager, Game, type GameData, type GameEvent, type GameOptions, type GameParameters, type GlobalVariables, GroupAction, I18n, type I18nDataReadyEvent, type IDataStore, type IDrawable, type IText, ImageManager, Label, LabelHorizontalAlignmentMode, type LabelOptions, type Layout, LayoutConstraint, LegacyTimer, type LocaleSvg, type M2ColorfulPath, type M2DragEvent, type M2Event, type M2EventListener, M2EventType, type M2Image, M2ImageStatus, M2Node, type M2NodeAddChildEvent, type M2NodeConstructor, type M2NodeEvent, type M2NodeEventListener, M2NodeFactory, type M2NodeNewEvent, type M2NodeOptions, type M2NodePropertyChangeEvent, type M2NodeRemoveChildEvent, M2NodeType, type M2Path, type M2PointerEvent, type M2Sound, M2SoundStatus, M2c2KitHelpers, MoveAction, type MoveActionOptions, MutablePath, NoneTransition, PlayAction, type PlayActionOptions, type Plugin, type PluginEvent, type Point, RandomDraws, type RectOptions, RepeatAction, RepeatForeverAction, type RgbaColor, RotateAction, ScaleAction, type ScaleActionOptions, Scene, type SceneOptions, type ScenePresentEvent, SceneTransition, SequenceAction, Shape, type ShapeOptions, ShapeType, type Size, SlideTransition, type SlideTransitionOptions, type SoundAsset, SoundManager, SoundPlayer, type SoundPlayerOptions, SoundRecorder, type SoundRecorderOptions, type SoundRecorderResults, Sprite, type SpriteOptions, Story, type StoryOptions, type StringInterpolationMap, type TapEvent, type TextAndFont, TextLine, type TextLineOptions, type TextLocalizationResult, type TextOptions, type TextWithFontCustomization, Timer, Transition, TransitionDirection, TransitionType, type Translation, type TranslationConfiguration, type TranslationOptions, type TrialData, type TrialSchema, Uuid, WaitAction, type WaitActionOptions, WebColors, WebGlInfo, handleInterfaceOptions };