@m2c2kit/core 0.3.5 → 0.3.7

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,4 +1,4 @@
1
- import { Image, CanvasKit, FontMgr, Typeface, Canvas, Surface, EmbindObject, Font, Paint, ParagraphBuilder, Paragraph, Path, PaintStyle } from 'canvaskit-wasm';
1
+ import { Image, CanvasKit, Canvas, Surface, FontMgr, Typeface, EmbindObject, Font, Paint, ParagraphBuilder, Paragraph, Path, PaintStyle } from 'canvaskit-wasm';
2
2
 
3
3
  declare class GlobalVariables {
4
4
  now: number;
@@ -78,6 +78,7 @@ interface JsonSchema {
78
78
  default?: any;
79
79
  }
80
80
  type JsonSchemaDataType = "string" | "number" | "integer" | "object" | "array" | "boolean" | "null";
81
+ type JsonSchemaDataTypeScriptTypes = string | number | object | boolean | null | undefined | Array<string> | Array<number> | Array<object> | Array<boolean> | Array<null>;
81
82
 
82
83
  /**
83
84
  * All the data created by an activity.
@@ -100,7 +101,7 @@ interface ActivityResults {
100
101
  *
101
102
  * @remarks Event contains all the data created by an activity, with
102
103
  * separate properties for the newly created data. ActivityResultsEvent
103
- * inherts "data" from ActivityResults, which contains the complete data
104
+ * inherits "data" from ActivityResults, which contains the complete data
104
105
  * up to this point (both new and existing data).
105
106
  */
106
107
  interface ActivityResultsEvent extends ActivityEvent, ActivityResults {
@@ -108,7 +109,7 @@ interface ActivityResultsEvent extends ActivityEvent, ActivityResults {
108
109
  newData: ActivityKeyValueData;
109
110
  /** JSON schema describing the new data */
110
111
  newDataSchema: JsonSchema;
111
- /** ISO 8601 timestamp of the event. Specifically, value of "new Date().toISOString()" executed on the device when the ActivityResultsEvent occured. */
112
+ /** ISO 8601 timestamp of the event. Specifically, value of "new Date().toISOString()" executed on the device when the ActivityResultsEvent occurred. */
112
113
  iso8601Timestamp: string;
113
114
  }
114
115
 
@@ -194,6 +195,8 @@ declare class ImageManager {
194
195
  private _scratchCanvas?;
195
196
  private ctx?;
196
197
  private scale?;
198
+ private session;
199
+ constructor(session: Session);
197
200
  /**
198
201
  * Returns a CanvasKit Image that was previously rendered by the ImageManager.
199
202
  *
@@ -254,6 +257,7 @@ declare class ImageManager {
254
257
  * @returns A promise of type void
255
258
  */
256
259
  private renderBrowserImage;
260
+ private arrayBufferToBase64String;
257
261
  private inferImageSubtypeFromUrl;
258
262
  private convertRenderedDataUrlImageToCanvasKitImage;
259
263
  /**
@@ -266,367 +270,91 @@ declare class ImageManager {
266
270
  removeScratchCanvas(): void;
267
271
  }
268
272
 
269
- interface GameFontUrls {
270
- uuid: string;
271
- fontUrls: Array<string>;
272
- }
273
-
274
- /**
275
- * This class contains all the fonts for all the games in the activity.
276
- * Fonts have been converted to canvaskit Typeface
277
- */
278
- declare class GameTypefaces {
279
- [gameUuid: string]: {
280
- [fontFamily: string]: Typeface;
281
- };
282
- }
283
- /**
284
- * Class for loading, preparing, and providing fonts to games.
285
- *
286
- * @remarks FOR INTERNAL USE ONLY
287
- */
288
- declare class FontManager {
289
- canvasKit?: CanvasKit;
290
- fontMgr?: FontMgr;
291
- gameTypefaces: GameTypefaces;
292
- private allGamesFontData?;
293
- /**
294
- * Gets a typeface that was previously loaded for the specified game.
295
- *
296
- * @param gameUuid
297
- * @param fontFamily
298
- * @returns the requested Typeface
299
- */
300
- getTypeface(gameUuid: string, fontFamily: string): Typeface;
301
- /**
302
- * Gets names of fonts loaded for the specified game.
303
- *
304
- * @param gameUuid
305
- * @returns array of font family names
306
- */
307
- getFontNames(gameUuid: string): Array<string>;
308
- /**
309
- * Fetches all fonts for all games.
310
- *
311
- * @param allGamesFontUrls
312
- * @returns
313
- */
314
- fetchFonts(allGamesFontUrls: Array<GameFontUrls>): Promise<void>;
315
- /**
316
- * Takes the fonts, which have been previously fetched and converted into
317
- * Array Buffers using FontManager.fetchFonts(), and makes them available
318
- * to our engine
319
- */
320
- loadAllGamesFontData(): void;
321
- /**
322
- * For the specified game, fetches all fonts in the array of urls and
323
- * stores fonts as array buffers.
324
- *
325
- * @param gameUuid
326
- * @param fontUrls - array of font urls
327
- * @returns
328
- */
329
- private fetchGameFontsAsArrayBuffers;
330
- /**
331
- * For the specified game, loads all fonts from array buffers and makes
332
- * fonts available within canvaskit as a Typeface
333
- *
334
- * @param gameUuid
335
- * @param fonts - array of fonts in array buffer form
336
- */
337
- private loadGameFonts;
273
+ interface FontData {
274
+ gameUuid: string;
275
+ fontUrl: string;
276
+ fontName: string;
277
+ fontFamilyName: string;
278
+ fontArrayBuffer: ArrayBuffer;
279
+ isDefault: boolean;
338
280
  }
339
281
 
282
+ type EasingFunction = (
283
+ /** elapsed time since start of action */
284
+ t: number,
285
+ /** start value of value to be eased */
286
+ b: number,
287
+ /** total change of value to be eased */
288
+ c: number,
289
+ /** total duration of action */
290
+ d: number) => number;
340
291
  /**
341
- * Notifies when an activity starts, ends, cancels, or
342
- * creates data.
292
+ * The Easings class has static methods for creating easings to be used in actions.
343
293
  */
344
- interface ActivityLifecycleEvent extends ActivityEvent {
345
- results?: ActivityResults;
346
- }
347
-
348
- interface ActivityCallbacks {
349
- /** Callback executed when the activity lifecycle changes, such as when it ends. */
350
- onActivityLifecycle?: (event: ActivityLifecycleEvent) => void;
351
- /** Callback executed when an activity creates some data. */
352
- onActivityResults?: (event: ActivityResultsEvent) => void;
353
- }
354
-
355
- /** Base interface for all Session events. */
356
- interface SessionEvent extends EventBase {
357
- target: Session;
294
+ declare class Easings {
295
+ static none: EasingFunction;
296
+ static linear: EasingFunction;
297
+ static quadraticIn: EasingFunction;
298
+ static quadraticOut: EasingFunction;
299
+ static quadraticInOut: EasingFunction;
300
+ static cubicIn: EasingFunction;
301
+ static cubicOut: EasingFunction;
302
+ static cubicInOut: EasingFunction;
303
+ static quarticIn: EasingFunction;
304
+ static quarticOut: EasingFunction;
305
+ static quarticInOut: EasingFunction;
306
+ static quinticIn: EasingFunction;
307
+ static quinticOut: EasingFunction;
308
+ static quinticInOut: EasingFunction;
309
+ static sinusoidalIn: EasingFunction;
310
+ static sinusoidalOut: EasingFunction;
311
+ static sinusoidalInOut: EasingFunction;
312
+ static exponentialIn: EasingFunction;
313
+ static exponentialOut: EasingFunction;
314
+ static exponentialInOut: EasingFunction;
315
+ static circularIn: EasingFunction;
316
+ static circularOut: EasingFunction;
317
+ static circularInOut: EasingFunction;
358
318
  }
359
319
 
360
320
  /**
361
- * Notifies when a session starts, ends, or initializes.
321
+ * Position in two-dimensional space.
362
322
  */
363
- interface SessionLifecycleEvent extends SessionEvent {
364
- }
365
-
366
- interface SessionCallbacks {
367
- /** Callback executed when the session lifecycle changes, such as when it is initialized. */
368
- onSessionLifecycle?: (event: SessionLifecycleEvent) => void;
369
- }
370
-
371
- interface SessionOptions {
372
- /** The activities that compose this session */
373
- activities: Array<Activity>;
374
- /** Callbacks executed when activity events occurs, such as when activity creates data or ends */
375
- activityCallbacks?: ActivityCallbacks;
376
- /** Callbacks executed when session events occur */
377
- sessionCallbacks?: SessionCallbacks;
378
- /** Url of the canvaskit.wasm binary. Always set to the default value of "assets/canvaskit.wasm" */
379
- canvasKitWasmUrl: "assets/canvaskit.wasm";
380
- /** Use a specified session UUID, rather than create a new one */
381
- sessionUuid?: string;
382
- /** NOT IMPLEMENTED YET: Orientation the screen should be locked to for this session. Value will be passed into the ScreenOrientation.lock() Web API. */
383
- orientation?: "natural" | "landscape" | "portrait" | "portrait-primary" | "portrait-secondary" | "landscape-primary" | "landscape-secondary";
323
+ interface Point {
324
+ /** Horizontal coordinate */
325
+ x: number;
326
+ /** Vertical coordinate */
327
+ y: number;
384
328
  }
385
329
 
386
- declare class Session {
387
- options: SessionOptions;
388
- fontManager: FontManager;
389
- imageManager: ImageManager;
390
- currentActivity?: Activity;
391
- uuid: string;
392
- dataStore?: IDataStore;
393
- private sessionDictionary;
394
- private canvasKit?;
395
- private version;
396
- /**
397
- * A Session contains one or more activities. The session manages the start
398
- * and stop of activities, and advancement to next activity
399
- *
400
- * @param options
401
- */
402
- constructor(options: SessionOptions);
403
- /**
404
- * Asynchronously initializes the m2c2kit engine and loads assets
405
- */
406
- init(): Promise<void>;
407
- /**
408
- * Starts the session and starts the first activity.
409
- */
410
- start(): Promise<void>;
411
- /**
412
- * Declares the session ended and sends callback.
413
- */
414
- end(): void;
415
- private stop;
330
+ interface IDrawable {
331
+ draw(canvas: Canvas): void;
332
+ warmup(canvas: Canvas): void;
416
333
  /**
417
- * Frees up resources that were allocated to run the session.
334
+ * Frees up resources that were allocated for this drawable entity.
418
335
  *
419
336
  * @remarks This will be done automatically by the m2c2kit library;
420
337
  * the end-user must not call this.
421
338
  */
422
- private dispose;
423
- /**
424
- * Stops the current activity and goes to the activity with the provided id.
425
- *
426
- * @param options
427
- */
428
- goToActivity(options: GoToActivityOptions): Promise<void>;
429
- /**
430
- * Stops the current activity and advances to next activity in the session.
431
- * If there is no activity after the current activity, throws error.
432
- */
433
- goToNextActivity(): Promise<void>;
434
- /**
435
- * Stops the current activity and advances to next activity in the session.
436
- * If there is no activity after the current activity, throws error.
437
- *
438
- * @deprecated Use goToNextActivity() instead.
439
- */
440
- advanceToNextActivity(): Promise<void>;
441
- /**
442
- * Gets the next activity after the current one, or undefined if
443
- * this is the last activity.
444
- */
445
- get nextActivity(): Activity | undefined;
446
- /**
447
- * Saves an item to the session's key-value dictionary.
448
- *
449
- * @remarks The session dictionary is not persisted. It is available only
450
- * during the actively running session. It is useful for storing temporary
451
- * data to coordinate between activities.
452
- *
453
- * @param key - item key
454
- * @param value - item value
455
- */
456
- dictionarySetItem(key: string, value: SessionDictionaryValues): void;
457
- /**
458
- * Gets an item value from the session's key-value dictionary.
459
- *
460
- * @remarks The session dictionary is not persisted. It is available only
461
- * during the actively running session. It is useful for storing temporary
462
- * data to coordinate between activities.
463
- *
464
- * @param key - item key
465
- * @returns value of the item
466
- */
467
- dictionaryGetItem<T extends SessionDictionaryValues>(key: string): T;
468
- /**
469
- * Deletes an item value from the session's key-value dictionary.
470
- *
471
- * @remarks The session dictionary is not persisted. It is available only
472
- * during the actively running session. It is useful for storing temporary
473
- * data to coordinate between activities.
474
- *
475
- * @param key - item key
476
- * @returns true if the item was deleted, false if it did not exist
477
- */
478
- dictionaryDeleteItem(key: string): boolean;
479
- /**
480
- * Determines if a key exists in the activity's key-value dictionary.
481
- *
482
- * @remarks The session dictionary is not persisted. It is available only
483
- * during the actively running session. It is useful for storing temporary
484
- * data to coordinate between activities.
485
- *
486
- * @param key - item key
487
- * @returns true if the key exists, false otherwise
488
- */
489
- dictionaryItemExists(key: string): boolean;
490
- /**
491
- * Gets asynchronous assets, including initialization of canvaskit wasm,
492
- * fetching of fonts from specified urls, and rendering and fetching
493
- * of images
494
- * @returns
495
- */
496
- private getAsynchronousAssets;
497
- private loadCanvasKit;
498
- private loadAssets;
499
- private assignCanvasKit;
500
- private getFontsConfigurationFromGames;
501
- private getImagesConfigurationFromGames;
502
- }
503
- interface GoToActivityOptions {
504
- /** ActivityId of the activity to go to. */
505
- id: string;
506
- }
507
- /**
508
- * Types of values that can be stored in the session dictonary.
509
- */
510
- type SessionDictionaryValues = string | number | boolean | object | null | undefined;
511
-
512
- interface Activity {
513
- /** The type of activity: Game or Survey */
514
- type: ActivityType;
515
- /** Initializes the activity. All code to create the activity's appearance and behavior must be placed in this method. This method is asynchronous, and must be awaited. When writing a new game by extending the `Game` class, this method will be overridden, but the base method must still be called with `await super.init()`. */
516
- init(): Promise<void>;
517
- /** Starts the activity */
518
- start(): Promise<void>;
519
- /** Stops the activity */
520
- stop(): void;
521
- /** The activity's parent session */
522
- session: Session;
523
- /** The activity's unique identifier. NOTE: This is newly generated each session. The uuid for an activity will vary across sessions. */
524
- uuid: string;
525
- /** Human-friendly name of this activity */
526
- name: string;
527
- /** Short identifier of this activity */
528
- id: string;
529
- /** The value of performance.now() immediately before the activity begins */
530
- beginTimestamp: number;
531
- /** The value of new Date().toISOString() immediately before the activity begins */
532
- beginIso8601Timestamp: string;
533
- /** Sets additional activity parameters if defaults are not sufficient. */
534
- setParameters(additionalParameters: unknown): void;
535
- /** Additional activity parameters that were set. */
536
- readonly additionalParameters?: unknown;
537
- /** Optional store to use for saving data. The implementation of the store is not provided by the \@m2c2kit/core library. */
538
- dataStore?: IDataStore;
539
- }
540
-
541
- /**
542
- * Base interface for all m2c2kit events.
543
- *
544
- * @remarks I would have named it Event, but that would collide with
545
- * the existing DOM Event
546
- */
547
- interface EventBase {
548
- /** Type of event. */
549
- type: EventType;
550
- /** The object on which the event occurred. */
551
- target: Entity | Session | Activity;
552
- /** Has the event been taken care of by the listener and not be dispatched to other targets? */
553
- handled?: boolean;
554
- }
555
- /**
556
- * The different events that are dispatched by m2c2kit.
557
- */
558
- declare enum EventType {
559
- SessionInitialize = "SessionInitialize",
560
- SessionStart = "SessionStart",
561
- SessionEnd = "SessionEnd",
562
- ActivityStart = "ActivityStart",
563
- ActivityEnd = "ActivityEnd",
564
- ActivityCancel = "ActivityCancel",
565
- ActivityData = "ActivityData",
566
- TapDown = "TapDown",
567
- TapUp = "TapUp",
568
- TapUpAny = "TapUpAny",
569
- TapLeave = "TapLeave",
570
- PointerDown = "PointerDown",
571
- PointerUp = "PointerUp",
572
- PointerMove = "PointerMove",
573
- Drag = "Drag",
574
- DragStart = "DragStart",
575
- DragEnd = "DragEnd",
576
- CompositeCustom = "CompositeCustom"
577
- }
578
-
579
- /** Base interface for all Entity events. */
580
- interface EntityEvent extends EventBase {
581
- /** The Entity on which the event occurred. */
582
- target: Entity;
583
- /** For composites that raise events, type of the composite custom event. */
584
- compositeType?: string;
585
- }
586
-
587
- interface EntityEventListener {
588
- type: EventType;
589
- /** For composites that raise events, type of the composite custom event. */
590
- compositeType?: string;
591
- entityUuid: string;
592
- callback: (event: EntityEvent) => void;
593
- }
594
-
595
- /**
596
- * Position in two-dimensional space.
597
- */
598
- interface Point {
599
- /** Horizonal coordinate */
600
- x: number;
601
- /** Vertical coordinate */
602
- y: number;
339
+ dispose(): void;
340
+ anchorPoint: Point;
341
+ zPosition: number;
603
342
  }
604
343
 
605
- /**
606
- * Describes an interaction between the pointer (mouse, touches) and an entity.
607
- *
608
- * @remarks I would have named it PointerEvent, but that would collide with
609
- * the existing DOM PointerEvent.
610
- */
611
- interface M2PointerEvent extends EntityEvent {
612
- /** Point that was tapped on entity, relative to the entity coordinate system */
613
- point: Point;
614
- /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
615
- buttons: number;
344
+ declare enum EntityType {
345
+ Entity = "Entity",
346
+ Scene = "Scene",
347
+ Sprite = "Sprite",
348
+ Label = "Label",
349
+ TextLine = "TextLine",
350
+ Shape = "Shape",
351
+ Composite = "Composite"
616
352
  }
617
353
 
618
354
  /**
619
- * Desrcibes an interaction of a pointer (mouse, touches) pressing an entity.
620
- *
621
- * @remarks Unlike M2PointerEvent, TapEvent considers how the pointer, while
622
- * in the down state, moves in relation to the bounds of the entity.
355
+ * Color in red (0-255), green (0-255), blue (0-255), alpha (0-1) format. Must be numeric array of length 4.
623
356
  */
624
- interface TapEvent extends EntityEvent {
625
- /** Point that was tapped on entity, relative to the entity coordinate system */
626
- point: Point;
627
- /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
628
- buttons: number;
629
- }
357
+ type RgbaColor = [number, number, number, number];
630
358
 
631
359
  interface DrawableOptions {
632
360
  /** Point within the entity that determines its position. Default is \{ x: 0.5, y: 0.5 \}, which centers the entity on its position */
@@ -665,123 +393,35 @@ interface Constraints {
665
393
  }
666
394
 
667
395
  /**
668
- * The Layout allows relative positioning via constraints.
669
- * This is not fully implemented yet: DO NOT USE!
670
- * We use it internally for instructions.
671
- */
672
- interface Layout {
673
- height?: number;
674
- width?: number;
675
- marginStart?: number;
676
- marginEnd?: number;
677
- marginTop?: number;
678
- marginBottom?: number;
679
- constraints?: Constraints;
680
- }
681
-
682
- /**
683
- * Color in red (0-255), green (0-255), blue (0-255), alpha (0-1) format. Must be numeric array of length 4.
684
- */
685
- type RgbaColor = [number, number, number, number];
686
-
687
- interface TextOptions {
688
- /** Text to be displayed */
689
- text?: string;
690
- /** Name of font to use for text. Must have been previously loaded */
691
- fontName?: string;
692
- /** Color of text. Default is Constants.DEFAULT_FONT_COLOR (WebColors.Black) */
693
- fontColor?: RgbaColor;
694
- /** Size of text. Default is Constants.DEFAULT_FONT_SIZE (16) */
695
- fontSize?: number;
696
- }
697
-
698
- /**
699
- * Width and height on two-dimensional space
700
- */
701
- interface Size {
702
- /** Horizonal width, x-axis */
703
- width: number;
704
- /** Vertical height, y-axis */
705
- height: number;
706
- }
707
-
708
- interface EntityOptions {
709
- /** Name of the entity. Only needed if the entity will be referred to by name in a later function */
710
- name?: string;
711
- /** Position of the entity within its parent coordinate system. Default is (0, 0) */
712
- position?: Point;
713
- /** Scale of the entity. Default is 1.0 */
714
- scale?: number;
715
- /** Does the entity respond to user events, such as taps? Default is false */
716
- isUserInteractionEnabled?: boolean;
717
- /** Can the entity be dragged? */
718
- draggable?: boolean;
719
- /** Is the entity, and its children, hidden? (not displayed). Default is false */
720
- hidden?: boolean;
721
- /** FOR INTERNAL USE ONLY */
722
- layout?: Layout;
723
- }
724
-
725
- declare enum EntityType {
726
- Entity = "Entity",
727
- Scene = "Scene",
728
- Sprite = "Sprite",
729
- Label = "Label",
730
- TextLine = "TextLine",
731
- Shape = "Shape",
732
- Composite = "Composite"
733
- }
734
-
735
- type EasingFunction = (
736
- /** elapsed time since start of action */
737
- t: number,
738
- /** start value of value to be eased */
739
- b: number,
740
- /** total change of value to be eased */
741
- c: number,
742
- /** total duration of action */
743
- d: number) => number;
744
- /**
745
- * The Easings class has static methods for creating easings to be used in actions.
746
- */
747
- declare class Easings {
748
- static none: EasingFunction;
749
- static linear: EasingFunction;
750
- static quadraticIn: EasingFunction;
751
- static quadraticOut: EasingFunction;
752
- static quadraticInOut: EasingFunction;
753
- static cubicIn: EasingFunction;
754
- static cubicOut: EasingFunction;
755
- static cubicInOut: EasingFunction;
756
- static quarticIn: EasingFunction;
757
- static quarticOut: EasingFunction;
758
- static quarticInOut: EasingFunction;
759
- static quinticIn: EasingFunction;
760
- static quinticOut: EasingFunction;
761
- static quinticInOut: EasingFunction;
762
- static sinusoidalIn: EasingFunction;
763
- static sinusoidalOut: EasingFunction;
764
- static sinusoidalInOut: EasingFunction;
765
- static exponentialIn: EasingFunction;
766
- static exponentialOut: EasingFunction;
767
- static exponentialInOut: EasingFunction;
768
- static circularIn: EasingFunction;
769
- static circularOut: EasingFunction;
770
- static circularInOut: EasingFunction;
396
+ * The Layout allows relative positioning via constraints.
397
+ * This is not fully implemented yet: DO NOT USE!
398
+ * We use it internally for instructions.
399
+ */
400
+ interface Layout {
401
+ height?: number;
402
+ width?: number;
403
+ marginStart?: number;
404
+ marginEnd?: number;
405
+ marginTop?: number;
406
+ marginBottom?: number;
407
+ constraints?: Constraints;
771
408
  }
772
409
 
773
- interface IDrawable {
774
- draw(canvas: Canvas): void;
775
- warmup(canvas: Canvas): void;
776
- /**
777
- * Frees up resources that were allocated for this drawable entity.
778
- *
779
- * @remarks This will be done automatically by the m2c2kit library;
780
- * the end-user must not call this.
781
- */
782
- dispose(): void;
783
- anchorPoint: Point;
784
- zPosition: number;
410
+ interface EntityOptions {
411
+ /** Name of the entity. Only needed if the entity will be referred to by name in a later function */
412
+ name?: string;
413
+ /** Position of the entity within its parent coordinate system. Default is (0, 0) */
414
+ position?: Point;
415
+ /** Scale of the entity. Default is 1.0 */
416
+ scale?: number;
417
+ /** Does the entity respond to user events, such as taps? Default is false */
418
+ isUserInteractionEnabled?: boolean;
419
+ /** Can the entity be dragged? */
420
+ draggable?: boolean;
421
+ /** Is the entity, and its children, hidden? (not displayed). Default is false */
422
+ hidden?: boolean;
423
+ /** FOR INTERNAL USE ONLY */
424
+ layout?: Layout;
785
425
  }
786
426
 
787
427
  interface SceneOptions extends EntityOptions, DrawableOptions {
@@ -861,7 +501,7 @@ declare class Scene extends Entity implements IDrawable, SceneOptions {
861
501
  interface SlideTransitionOptions {
862
502
  /** Direction in which the slide action goes */
863
503
  direction: TransitionDirection;
864
- /** Duration, in millis, of the transition */
504
+ /** Duration, in milliseconds, of the transition */
865
505
  duration: number;
866
506
  /** Easing function for movement; default is linear */
867
507
  easing?: EasingFunction;
@@ -914,6 +554,14 @@ declare class SceneTransition {
914
554
  constructor(scene: Scene, transition: Transition);
915
555
  }
916
556
 
557
+ /** Base interface for all Entity events. */
558
+ interface EntityEvent extends EventBase {
559
+ /** The Entity on which the event occurred. */
560
+ target: Entity;
561
+ /** For composites that raise events, type of the composite custom event. */
562
+ compositeType?: string;
563
+ }
564
+
917
565
  /**
918
566
  * TrialSchema defines the data that are generated for each trial. They are
919
567
  * key-value pairs in which the key is the variable name, and the value is
@@ -960,6 +608,16 @@ interface Translations {
960
608
  };
961
609
  }
962
610
 
611
+ /**
612
+ * Font asset to use in the game.
613
+ */
614
+ interface FontAsset {
615
+ /** Name of the font to use when referring to it within m2c2kit */
616
+ fontName: string;
617
+ /** URL of font (TrueType font) to load */
618
+ url: string;
619
+ }
620
+
963
621
  /**
964
622
  * Options to specify HTML canvas, set game canvas size, and load game assets.
965
623
  */
@@ -988,8 +646,8 @@ interface GameOptions {
988
646
  trialSchema?: TrialSchema;
989
647
  /** Default game parameters; JSON object where key is the game parameter, value is default value */
990
648
  parameters?: GameParameters;
991
- /** String array of urls from which to load fonts. The first element will be the default font */
992
- fontUrls?: Array<string>;
649
+ /** Font assets to use. The first element will be the default font */
650
+ fonts?: Array<FontAsset>;
993
651
  /** Array of BrowserImage objects to render and load */
994
652
  images?: Array<BrowserImage>;
995
653
  /** Show FPS in upper left corner? Default is false */
@@ -1008,6 +666,8 @@ interface GameOptions {
1008
666
  translations?: Translations;
1009
667
  /** Show logs for WebGl activity? */
1010
668
  logWebGl?: boolean;
669
+ /** URL of game assets folder, if not the default location of "assets/id of game from GameOptions" */
670
+ assetsUrl?: string;
1011
671
  }
1012
672
 
1013
673
  interface GameData extends ActivityKeyValueData {
@@ -1020,7 +680,7 @@ interface GameData extends ActivityKeyValueData {
1020
680
  interface LocalizationOptions {
1021
681
  /** Locale to use for localization, or "auto" to request from the environment. */
1022
682
  locale: string;
1023
- /** Locale to use if requested locale translation is not availble, or if "auto" locale was requested and environment cannot provide a locale. */
683
+ /** Locale to use if requested locale translation is not available, or if "auto" locale was requested and environment cannot provide a locale. */
1024
684
  fallbackLocale?: string;
1025
685
  /** Font color for strings that are missing translation and use the fallback locale or untranslated string. */
1026
686
  missingTranslationFontColor?: RgbaColor;
@@ -1068,6 +728,9 @@ declare class Game implements Activity {
1068
728
  private loaderElementsRemoved;
1069
729
  private _dataStore?;
1070
730
  additionalParameters?: unknown;
731
+ staticTrialSchema: {
732
+ [key: string]: JsonSchemaDataTypeScriptTypes;
733
+ };
1071
734
  /**
1072
735
  * The base class for all games. New games should extend this class.
1073
736
  *
@@ -1215,7 +878,7 @@ declare class Game implements Activity {
1215
878
  *
1216
879
  * @remarks Once added to the game, a free entity will always be drawn,
1217
880
  * and it will not be part of any scene transitions. This is useful if
1218
- * an entity must persisently be drawn and not move with scene
881
+ * an entity must persistently be drawn and not move with scene
1219
882
  * transitions. The appearance of the free entity must be managed
1220
883
  * by the programmer. Note: internally, the free entities are part of a
1221
884
  * special scene (named "__freeEntitiesScene"), but this scene is handled
@@ -1367,7 +1030,44 @@ declare class Game implements Activity {
1367
1030
  * @param variableName - variable to be set
1368
1031
  * @param value - value of the variable to set
1369
1032
  */
1370
- addTrialData(variableName: string, value: any): void;
1033
+ addTrialData(variableName: string, value: JsonSchemaDataTypeScriptTypes): void;
1034
+ /**
1035
+ * Adds custom trial schema to the game's trialSchema object.
1036
+ *
1037
+ * @param schema - Trial schema to add
1038
+ *
1039
+ * @remarks This is useful if you want to add custom trial variables.
1040
+ * This must be done before Session.start() is called, because
1041
+ * Session.start() will call Game.start(), which will initialize
1042
+ * the trial schema.
1043
+ */
1044
+ addTrialSchema(schema: TrialSchema): void;
1045
+ /**
1046
+ * Sets the value of a variable that will be the same for all trials.
1047
+ *
1048
+ * @remarks This sets the value of a variable that is the same across
1049
+ * all trials ("static"). This is useful for variables that are not
1050
+ * part of the trial schema, but that you want to save for each trial in
1051
+ * your use case. For example, you might want to save the subject's
1052
+ * participant ID for each trial, but this is not part of the trial schema.
1053
+ * Rather than modify the source code for the game, you can do the following
1054
+ * to ensure that the participant ID is saved for each trial:
1055
+ *
1056
+ * game.addTrialSchema({
1057
+ * participant_id: {
1058
+ * type: "string",
1059
+ * description: "ID of the participant",
1060
+ * }
1061
+ * });
1062
+ * game.addStaticTrialData("participant_id", "12345");
1063
+ *
1064
+ * When Game.trialComplete() is called, the participant_id variable will
1065
+ * be saved for the trial with the value "12345".
1066
+ *
1067
+ * @param variableName - variable to be set
1068
+ * @param value - value of the variable to set
1069
+ */
1070
+ addStaticTrialData(variableName: string, value: JsonSchemaDataTypeScriptTypes): void;
1371
1071
  /**
1372
1072
  * Should be called when the current trial has completed. It will
1373
1073
  * also increment the trial index.
@@ -1445,85 +1145,443 @@ declare class Game implements Activity {
1445
1145
  * must be queued and completed once a draw cycle has completed. See
1446
1146
  * the loop() method.
1447
1147
  *
1448
- * @param sx - Upper left coordinate of screenshot
1449
- * @param sy - Upper right coordinate of screenshot
1450
- * @param sw - width of area to screenshot
1451
- * @param sh - hegith of area to screenshot
1452
- * @returns Promise of Uint8Array of image data
1148
+ * @param sx - Upper left coordinate of screenshot
1149
+ * @param sy - Upper right coordinate of screenshot
1150
+ * @param sw - width of area to screenshot
1151
+ * @param sh - height of area to screenshot
1152
+ * @returns Promise of Uint8Array of image data
1153
+ */
1154
+ takeScreenshot(sx?: number, sy?: number, sw?: number, sh?: number): Promise<Uint8Array | null>;
1155
+ private animateSceneTransition;
1156
+ private drawFps;
1157
+ /**
1158
+ * Creates an event listener for an entity based on the entity name
1159
+ *
1160
+ * @remarks Typically, event listeners will be created using a method specific to the event, such as onTapDown(). This alternative allows creation with entity name.
1161
+ *
1162
+ * @param type - the type of event to listen for, e.g., "tapDown"
1163
+ * @param entityName - the entity name for which an event will be listened
1164
+ * @param callback
1165
+ * @param replaceExistingCallback
1166
+ */
1167
+ createEventListener(type: EventType, entityName: string, callback: (event: EntityEvent) => void, replaceExistingCallback?: boolean): void;
1168
+ /**
1169
+ * Returns array of all entities that have been added to the game object.
1170
+ */
1171
+ get entities(): Array<Entity>;
1172
+ /**
1173
+ * Receives callback from DOM PointerDown event
1174
+ *
1175
+ * @param domPointerEvent - PointerEvent from the DOM
1176
+ * @returns
1177
+ */
1178
+ private htmlCanvasPointerDownHandler;
1179
+ private htmlCanvasPointerUpHandler;
1180
+ private htmlCanvasPointerMoveHandler;
1181
+ /**
1182
+ * Adjusts dragging behavior when the pointer leaves the canvas
1183
+ *
1184
+ * @remarks This is necessary because the pointerup event is not fired when
1185
+ * the pointer leaves the canvas. On desktop, this means that the user might
1186
+ * lift the pointer outside the canvas, but the entity will still be dragged
1187
+ * when the pointer is moved back into the canvas.
1188
+ *
1189
+ * @param domPointerEvent
1190
+ * @returns
1191
+ */
1192
+ private htmlCanvasPointerLeaveHandler;
1193
+ /**
1194
+ * Determines if/how m2c2kit entities respond to the DOM PointerDown event
1195
+ *
1196
+ * @param entity - entity that might be affected by the DOM PointerDown event
1197
+ * @param m2Event
1198
+ * @param domPointerEvent
1199
+ */
1200
+ private processDomPointerDown;
1201
+ private processDomPointerUp;
1202
+ private processDomPointerMove;
1203
+ private raiseM2PointerDownEvent;
1204
+ private raiseTapDownEvent;
1205
+ private raiseTapLeaveEvent;
1206
+ private raiseM2PointerUpEvent;
1207
+ private raiseTapUpEvent;
1208
+ private raiseTapUpAny;
1209
+ private raiseM2PointerMoveEvent;
1210
+ private raiseM2DragStartEvent;
1211
+ private raiseM2DragEvent;
1212
+ private raiseM2DragEndEvent;
1213
+ private calculatePointWithinEntityFromDomPointerEvent;
1214
+ private raiseEventOnListeningEntities;
1215
+ private sceneCanReceiveUserInteraction;
1216
+ /**
1217
+ *
1218
+ * Checks if the given canvas point is within the entity's bounds.
1219
+ *
1220
+ * @param entity - entity to check bounds for
1221
+ * @param x - x coordinate of the canvas point
1222
+ * @param y - y coordinate of the canvas point
1223
+ * @returns true if x, y point is within the entity's bounds
1224
+ */
1225
+ private IsCanvasPointWithinEntityBounds;
1226
+ private calculateEntityAbsoluteBoundingBox;
1227
+ prependAssetsGameIdUrl(url: string): string;
1228
+ }
1229
+
1230
+ /**
1231
+ * This class contains all the fonts for all the games in the activity.
1232
+ * Fonts have been converted to canvaskit Typeface.
1233
+ *
1234
+ * @remarks fontName is how the user will refer to the font in the game.
1235
+ * fontFamily is the name of the font as it was specified within the TTF file.
1236
+ * We must retain the fontFamily name because we must provide fontFamily (not
1237
+ * fontName!) to canvaskit when rendering paragraphs.
1238
+ */
1239
+ declare class GameTypefaces {
1240
+ [gameUuid: string]: {
1241
+ [fontName: string]: {
1242
+ fontFamily: string;
1243
+ typeface: Typeface;
1244
+ isDefault: boolean;
1245
+ };
1246
+ };
1247
+ }
1248
+ /**
1249
+ * Class for loading, preparing, and providing fonts to games.
1250
+ *
1251
+ * @remarks FOR INTERNAL USE ONLY
1252
+ */
1253
+ declare class FontManager {
1254
+ canvasKit?: CanvasKit;
1255
+ fontMgr?: FontMgr;
1256
+ gameTypefaces: GameTypefaces;
1257
+ fontData: Array<FontData>;
1258
+ session: Session;
1259
+ games?: Array<Game>;
1260
+ constructor(session: Session);
1261
+ /**
1262
+ * Gets a typeface that was previously loaded for the specified game.
1263
+ *
1264
+ * @param gameUuid
1265
+ * @param fontName
1266
+ * @returns the requested Typeface
1267
+ */
1268
+ getTypeface(gameUuid: string, fontName: string): Typeface;
1269
+ /**
1270
+ * Gets names of fonts loaded for the specified game.
1271
+ *
1272
+ * @param gameUuid
1273
+ * @returns array of font names
1274
+ */
1275
+ getFontNames(gameUuid: string): Array<string>;
1276
+ /**
1277
+ * Fetches all fonts games.
1278
+ *
1279
+ * @param games - array of games
1280
+ * @returns
1281
+ */
1282
+ fetchFonts(games: Array<Game>): Promise<void[]>;
1283
+ /**
1284
+ * Takes the fonts, which have been previously fetched and converted into
1285
+ * Array Buffers using FontManager.fetchFonts(), and makes them available
1286
+ * to our engine by creating canvaskit Typefaces.
1287
+ */
1288
+ loadAllGamesFontData(): void;
1289
+ }
1290
+
1291
+ /**
1292
+ * Notifies when an activity starts, ends, cancels, or
1293
+ * creates data.
1294
+ */
1295
+ interface ActivityLifecycleEvent extends ActivityEvent {
1296
+ results?: ActivityResults;
1297
+ }
1298
+
1299
+ interface ActivityCallbacks {
1300
+ /** Callback executed when the activity lifecycle changes, such as when it ends. */
1301
+ onActivityLifecycle?: (event: ActivityLifecycleEvent) => void;
1302
+ /** Callback executed when an activity creates some data. */
1303
+ onActivityResults?: (event: ActivityResultsEvent) => void;
1304
+ }
1305
+
1306
+ /** Base interface for all Session events. */
1307
+ interface SessionEvent extends EventBase {
1308
+ target: Session;
1309
+ }
1310
+
1311
+ /**
1312
+ * Notifies when a session starts, ends, or initializes.
1313
+ */
1314
+ interface SessionLifecycleEvent extends SessionEvent {
1315
+ }
1316
+
1317
+ interface SessionCallbacks {
1318
+ /** Callback executed when the session lifecycle changes, such as when it is initialized. */
1319
+ onSessionLifecycle?: (event: SessionLifecycleEvent) => void;
1320
+ }
1321
+
1322
+ interface SessionOptions {
1323
+ /** The activities that compose this session */
1324
+ activities: Array<Activity>;
1325
+ /** Callbacks executed when activity events occurs, such as when activity creates data or ends */
1326
+ activityCallbacks?: ActivityCallbacks;
1327
+ /** Callbacks executed when session events occur */
1328
+ sessionCallbacks?: SessionCallbacks;
1329
+ /** Url of the canvaskit.wasm binary. Always set to the default value of "canvaskit.wasm" */
1330
+ canvasKitWasmUrl: "canvaskit.wasm";
1331
+ /** Use a specified session UUID, rather than create a new one */
1332
+ sessionUuid?: string;
1333
+ /** URL of session assets folder (which contains wasm binary), if not the default location of "assets" */
1334
+ assetsUrl?: string;
1335
+ /** NOT IMPLEMENTED YET: Orientation the screen should be locked to for this session. Value will be passed into the ScreenOrientation.lock() Web API. */
1336
+ orientation?: "natural" | "landscape" | "portrait" | "portrait-primary" | "portrait-secondary" | "landscape-primary" | "landscape-secondary";
1337
+ }
1338
+
1339
+ declare class Session {
1340
+ options: SessionOptions;
1341
+ fontManager: FontManager;
1342
+ imageManager: ImageManager;
1343
+ currentActivity?: Activity;
1344
+ uuid: string;
1345
+ dataStore?: IDataStore;
1346
+ private sessionDictionary;
1347
+ private canvasKit?;
1348
+ private version;
1349
+ /**
1350
+ * A Session contains one or more activities. The session manages the start
1351
+ * and stop of activities, and advancement to next activity
1352
+ *
1353
+ * @param options
1354
+ */
1355
+ constructor(options: SessionOptions);
1356
+ /**
1357
+ * Asynchronously initializes the m2c2kit engine and loads assets
1358
+ */
1359
+ init(): Promise<void>;
1360
+ /**
1361
+ * Starts the session and starts the first activity.
1362
+ */
1363
+ start(): Promise<void>;
1364
+ /**
1365
+ * Declares the session ended and sends callback.
1366
+ */
1367
+ end(): void;
1368
+ private stop;
1369
+ /**
1370
+ * Frees up resources that were allocated to run the session.
1371
+ *
1372
+ * @remarks This will be done automatically by the m2c2kit library;
1373
+ * the end-user must not call this.
1453
1374
  */
1454
- takeScreenshot(sx?: number, sy?: number, sw?: number, sh?: number): Promise<Uint8Array | null>;
1455
- private animateSceneTransition;
1456
- private drawFps;
1375
+ private dispose;
1457
1376
  /**
1458
- * Creates an event listener for an entity based on the entity name
1377
+ * Stops the current activity and goes to the activity with the provided id.
1459
1378
  *
1460
- * @remarks Typically, event listeners will be created using a method specific to the event, such as onTapDown(). This alternative allows creation with entity name.
1379
+ * @param options
1380
+ */
1381
+ goToActivity(options: GoToActivityOptions): Promise<void>;
1382
+ /**
1383
+ * Stops the current activity and advances to next activity in the session.
1384
+ * If there is no activity after the current activity, throws error.
1385
+ */
1386
+ goToNextActivity(): Promise<void>;
1387
+ /**
1388
+ * Stops the current activity and advances to next activity in the session.
1389
+ * If there is no activity after the current activity, throws error.
1461
1390
  *
1462
- * @param type - the type of event to listen for, e.g., "tapdown"
1463
- * @param entityName - the entity name for which an event will be listened
1464
- * @param callback
1465
- * @param replaceExistingCallback
1391
+ * @deprecated Use goToNextActivity() instead.
1466
1392
  */
1467
- createEventListener(type: EventType, entityName: string, callback: (event: EntityEvent) => void, replaceExistingCallback?: boolean): void;
1393
+ advanceToNextActivity(): Promise<void>;
1468
1394
  /**
1469
- * Returns array of all entities that have been added to the game object.
1395
+ * Gets the next activity after the current one, or undefined if
1396
+ * this is the last activity.
1470
1397
  */
1471
- get entities(): Array<Entity>;
1398
+ get nextActivity(): Activity | undefined;
1472
1399
  /**
1473
- * Receives callback from DOM PointerDown event
1400
+ * Saves an item to the session's key-value dictionary.
1474
1401
  *
1475
- * @param domPointerEvent - PointerEvent from the DOM
1476
- * @returns
1402
+ * @remarks The session dictionary is not persisted. It is available only
1403
+ * during the actively running session. It is useful for storing temporary
1404
+ * data to coordinate between activities.
1405
+ *
1406
+ * @param key - item key
1407
+ * @param value - item value
1477
1408
  */
1478
- private htmlCanvasPointerDownHandler;
1479
- private htmlCanvasPointerUpHandler;
1480
- private htmlCanvasPointerMoveHandler;
1409
+ dictionarySetItem(key: string, value: SessionDictionaryValues): void;
1481
1410
  /**
1482
- * Adjusts dragging behavior when the pointer leaves the canvas
1411
+ * Gets an item value from the session's key-value dictionary.
1483
1412
  *
1484
- * @remarks This is necessary because the pointerup event is not fired when
1485
- * the pointer leaves the canvas. On desktop, this means that the user might
1486
- * lift the pointer outside the canvas, but the entity will still be dragged
1487
- * when the pointer is moved back into the canvas.
1413
+ * @remarks The session dictionary is not persisted. It is available only
1414
+ * during the actively running session. It is useful for storing temporary
1415
+ * data to coordinate between activities.
1488
1416
  *
1489
- * @param domPointerEvent
1490
- * @returns
1417
+ * @param key - item key
1418
+ * @returns value of the item
1491
1419
  */
1492
- private htmlCanvasPointerLeaveHandler;
1420
+ dictionaryGetItem<T extends SessionDictionaryValues>(key: string): T;
1493
1421
  /**
1494
- * Determines if/how m2c2kit entities respond to the DOM PointerDown event
1422
+ * Deletes an item value from the session's key-value dictionary.
1495
1423
  *
1496
- * @param entity - entity that might be affected by the DOM PointerDown event
1497
- * @param m2Event
1498
- * @param domPointerEvent
1424
+ * @remarks The session dictionary is not persisted. It is available only
1425
+ * during the actively running session. It is useful for storing temporary
1426
+ * data to coordinate between activities.
1427
+ *
1428
+ * @param key - item key
1429
+ * @returns true if the item was deleted, false if it did not exist
1499
1430
  */
1500
- private processDomPointerDown;
1501
- private processDomPointerUp;
1502
- private processDomPointerMove;
1503
- private raiseM2PointerDownEvent;
1504
- private raiseTapDownEvent;
1505
- private raiseTapLeaveEvent;
1506
- private raiseM2PointerUpEvent;
1507
- private raiseTapUpEvent;
1508
- private raiseTapUpAny;
1509
- private raiseM2PointerMoveEvent;
1510
- private raiseM2DragStartEvent;
1511
- private raiseM2DragEvent;
1512
- private raiseM2DragEndEvent;
1513
- private calculatePointWithinEntityFromDomPointerEvent;
1514
- private raiseEventOnListeningEntities;
1515
- private sceneCanReceiveUserInteraction;
1431
+ dictionaryDeleteItem(key: string): boolean;
1516
1432
  /**
1433
+ * Determines if a key exists in the activity's key-value dictionary.
1517
1434
  *
1518
- * Checks if the given canvas point is within the entity's bounds.
1435
+ * @remarks The session dictionary is not persisted. It is available only
1436
+ * during the actively running session. It is useful for storing temporary
1437
+ * data to coordinate between activities.
1519
1438
  *
1520
- * @param entity - entity to check bounds for
1521
- * @param x - x coordinate of the canvas point
1522
- * @param y - y coordinate of the canvas point
1523
- * @returns true if x, y point is within the entity's bounds
1439
+ * @param key - item key
1440
+ * @returns true if the key exists, false otherwise
1524
1441
  */
1525
- private IsCanvasPointWithinEntityBounds;
1526
- private calculateEntityAbsoluteBoundingBox;
1442
+ dictionaryItemExists(key: string): boolean;
1443
+ /**
1444
+ * Gets asynchronous assets, including initialization of canvaskit wasm,
1445
+ * fetching of fonts from specified urls, and rendering and fetching
1446
+ * of images
1447
+ * @returns
1448
+ */
1449
+ private getAsynchronousAssets;
1450
+ private loadCanvasKit;
1451
+ private loadAssets;
1452
+ private assignCanvasKit;
1453
+ private getImagesConfigurationFromGames;
1454
+ prependAssetsUrl(url: string): string;
1455
+ }
1456
+ interface GoToActivityOptions {
1457
+ /** ActivityId of the activity to go to. */
1458
+ id: string;
1459
+ }
1460
+ /**
1461
+ * Types of values that can be stored in the session dictionary.
1462
+ */
1463
+ type SessionDictionaryValues = string | number | boolean | object | null | undefined;
1464
+
1465
+ interface Activity {
1466
+ /** The type of activity: Game or Survey */
1467
+ type: ActivityType;
1468
+ /** Initializes the activity. All code to create the activity's appearance and behavior must be placed in this method. This method is asynchronous, and must be awaited. When writing a new game by extending the `Game` class, this method will be overridden, but the base method must still be called with `await super.init()`. */
1469
+ init(): Promise<void>;
1470
+ /** Starts the activity */
1471
+ start(): Promise<void>;
1472
+ /** Stops the activity */
1473
+ stop(): void;
1474
+ /** The activity's parent session */
1475
+ session: Session;
1476
+ /** The activity's unique identifier. NOTE: This is newly generated each session. The uuid for an activity will vary across sessions. */
1477
+ uuid: string;
1478
+ /** Human-friendly name of this activity */
1479
+ name: string;
1480
+ /** Short identifier of this activity */
1481
+ id: string;
1482
+ /** The value of performance.now() immediately before the activity begins */
1483
+ beginTimestamp: number;
1484
+ /** The value of new Date().toISOString() immediately before the activity begins */
1485
+ beginIso8601Timestamp: string;
1486
+ /** Sets additional activity parameters if defaults are not sufficient. */
1487
+ setParameters(additionalParameters: unknown): void;
1488
+ /** Additional activity parameters that were set. */
1489
+ readonly additionalParameters?: unknown;
1490
+ /** Optional store to use for saving data. The implementation of the store is not provided by the \@m2c2kit/core library. */
1491
+ dataStore?: IDataStore;
1492
+ }
1493
+
1494
+ /**
1495
+ * Base interface for all m2c2kit events.
1496
+ *
1497
+ * @remarks I would have named it Event, but that would collide with
1498
+ * the existing DOM Event
1499
+ */
1500
+ interface EventBase {
1501
+ /** Type of event. */
1502
+ type: EventType;
1503
+ /** The object on which the event occurred. */
1504
+ target: Entity | Session | Activity;
1505
+ /** Has the event been taken care of by the listener and not be dispatched to other targets? */
1506
+ handled?: boolean;
1507
+ }
1508
+ /**
1509
+ * The different events that are dispatched by m2c2kit.
1510
+ */
1511
+ declare enum EventType {
1512
+ SessionInitialize = "SessionInitialize",
1513
+ SessionStart = "SessionStart",
1514
+ SessionEnd = "SessionEnd",
1515
+ ActivityStart = "ActivityStart",
1516
+ ActivityEnd = "ActivityEnd",
1517
+ ActivityCancel = "ActivityCancel",
1518
+ ActivityData = "ActivityData",
1519
+ TapDown = "TapDown",
1520
+ TapUp = "TapUp",
1521
+ TapUpAny = "TapUpAny",
1522
+ TapLeave = "TapLeave",
1523
+ PointerDown = "PointerDown",
1524
+ PointerUp = "PointerUp",
1525
+ PointerMove = "PointerMove",
1526
+ Drag = "Drag",
1527
+ DragStart = "DragStart",
1528
+ DragEnd = "DragEnd",
1529
+ CompositeCustom = "CompositeCustom"
1530
+ }
1531
+
1532
+ interface EntityEventListener {
1533
+ type: EventType;
1534
+ /** For composites that raise events, type of the composite custom event. */
1535
+ compositeType?: string;
1536
+ entityUuid: string;
1537
+ callback: (event: EntityEvent) => void;
1538
+ }
1539
+
1540
+ /**
1541
+ * Describes an interaction between the pointer (mouse, touches) and an entity.
1542
+ *
1543
+ * @remarks I would have named it PointerEvent, but that would collide with
1544
+ * the existing DOM PointerEvent.
1545
+ */
1546
+ interface M2PointerEvent extends EntityEvent {
1547
+ /** Point that was tapped on entity, relative to the entity coordinate system */
1548
+ point: Point;
1549
+ /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
1550
+ buttons: number;
1551
+ }
1552
+
1553
+ /**
1554
+ * Describes an interaction of a pointer (mouse, touches) pressing an entity.
1555
+ *
1556
+ * @remarks Unlike M2PointerEvent, TapEvent considers how the pointer, while
1557
+ * in the down state, moves in relation to the bounds of the entity.
1558
+ */
1559
+ interface TapEvent extends EntityEvent {
1560
+ /** Point that was tapped on entity, relative to the entity coordinate system */
1561
+ point: Point;
1562
+ /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
1563
+ buttons: number;
1564
+ }
1565
+
1566
+ interface TextOptions {
1567
+ /** Text to be displayed */
1568
+ text?: string;
1569
+ /** Name of font to use for text. Must have been previously loaded */
1570
+ fontName?: string;
1571
+ /** Color of text. Default is Constants.DEFAULT_FONT_COLOR (WebColors.Black) */
1572
+ fontColor?: RgbaColor;
1573
+ /** Size of text. Default is Constants.DEFAULT_FONT_SIZE (16) */
1574
+ fontSize?: number;
1575
+ }
1576
+
1577
+ /**
1578
+ * Width and height on two-dimensional space
1579
+ */
1580
+ interface Size {
1581
+ /** Horizontal width, x-axis */
1582
+ width: number;
1583
+ /** Vertical height, y-axis */
1584
+ height: number;
1527
1585
  }
1528
1586
 
1529
1587
  /**
@@ -1598,7 +1656,7 @@ declare abstract class Entity implements EntityOptions {
1598
1656
  */
1599
1657
  toString: () => string;
1600
1658
  /**
1601
- * Adds a child to this parent entity. Thows exception if the child's name
1659
+ * Adds a child to this parent entity. Throws exception if the child's name
1602
1660
  * is not unique with respect to other children of this parent.
1603
1661
  *
1604
1662
  * @param child - The child entity to add
@@ -1870,7 +1928,7 @@ interface MoveActionOptions {
1870
1928
  duration: number;
1871
1929
  /** Easing function for movement; default is linear */
1872
1930
  easing?: EasingFunction;
1873
- /** Should the action run during screen trnsitions? Default is no */
1931
+ /** Should the action run during screen transitions? Default is no */
1874
1932
  runDuringTransition?: boolean;
1875
1933
  }
1876
1934
 
@@ -2129,7 +2187,7 @@ declare class Constants {
2129
2187
  }
2130
2188
 
2131
2189
  /**
2132
- * This enum is used interally for processing the layout constraints. We use
2190
+ * This enum is used internally for processing the layout constraints. We use
2133
2191
  * an enum to avoid magic strings. NOTE: the casing in ConstraintType must
2134
2192
  * match the casing in Constraints.ts. Thus, this enum's members are in
2135
2193
  * lowercase, which is not typical Typescript style.
@@ -2168,12 +2226,6 @@ declare class Equals {
2168
2226
  static rgbaColor(color1?: RgbaColor, color2?: RgbaColor): boolean;
2169
2227
  }
2170
2228
 
2171
- interface FontData {
2172
- gameUuid: string;
2173
- fontUrl: string;
2174
- fontArrayBuffer: ArrayBuffer;
2175
- }
2176
-
2177
2229
  interface IText {
2178
2230
  text?: string;
2179
2231
  fontName?: string;
@@ -2194,6 +2246,8 @@ interface LabelOptions extends EntityOptions, DrawableOptions, TextOptions {
2194
2246
  preferredMaxLayoutWidth?: number;
2195
2247
  /** Background color of label text. Default is no background color */
2196
2248
  backgroundColor?: RgbaColor;
2249
+ /** Names of multiple fonts to use for text. For example, if a text font and an emoji font are to be used together. Must have been previously loaded */
2250
+ fontNames?: Array<string>;
2197
2251
  }
2198
2252
 
2199
2253
  declare class Label extends Entity implements IDrawable, IText, LabelOptions {
@@ -2207,6 +2261,7 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2207
2261
  zPosition: number;
2208
2262
  private _text;
2209
2263
  private _fontName;
2264
+ private _fontNames;
2210
2265
  private _fontColor;
2211
2266
  private _fontSize;
2212
2267
  private _horizontalAlignmentMode;
@@ -2231,6 +2286,8 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2231
2286
  get translatedText(): string;
2232
2287
  get fontName(): string | undefined;
2233
2288
  set fontName(fontName: string | undefined);
2289
+ get fontNames(): Array<string> | undefined;
2290
+ set fontNames(fontNames: Array<string> | undefined);
2234
2291
  get fontColor(): RgbaColor;
2235
2292
  set fontColor(fontColor: RgbaColor);
2236
2293
  get fontSize(): number;
@@ -2259,7 +2316,7 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2259
2316
 
2260
2317
  /**
2261
2318
  * This class is used internally for processing layout constraints that
2262
- * have been defined according to the Contraints interface.
2319
+ * have been defined according to the Constraints interface.
2263
2320
  *
2264
2321
  * Imagine we have two entities, A and B. B's position is set
2265
2322
  * using its position property. A's position is set using the layout
@@ -2286,7 +2343,7 @@ declare class LayoutConstraint {
2286
2343
  interface M2Path {
2287
2344
  /** The subpath that compose up the path */
2288
2345
  subpaths: Array<Array<Point>>;
2289
- /** The size of the path. This is neeeded to properly position the shape that is drawn by the path */
2346
+ /** The size of the path. This is needed to properly position the shape that is drawn by the path */
2290
2347
  size: Size;
2291
2348
  }
2292
2349
 
@@ -2405,13 +2462,13 @@ interface ShapeOptions extends EntityOptions, DrawableOptions {
2405
2462
  fillColor?: RgbaColor;
2406
2463
  /** Color with which to outline shape. Default is no color for rectangle and circle, red for path. */
2407
2464
  strokeColor?: RgbaColor;
2408
- /** Width of outline. Default is undefined for rectangle and cricle, 2 for path. */
2465
+ /** Width of outline. Default is undefined for rectangle and circle, 2 for path. */
2409
2466
  lineWidth?: number;
2410
2467
  /** A path from which to create the shape */
2411
2468
  path?: M2Path | SvgStringPath;
2412
- /** Size of container "viewbox" for path shapes. Leave undefined for circle and rectangle shapes. */
2469
+ /** Size of container "view box" for path shapes. Leave undefined for circle and rectangle shapes. */
2413
2470
  size?: Size;
2414
- /** Should the shape be drawn with antialiasing. Default is yes. */
2471
+ /** Should the shape be drawn with anti-aliasing. Default is yes. */
2415
2472
  isAntialiased?: boolean;
2416
2473
  }
2417
2474
 
@@ -2620,7 +2677,7 @@ declare class Timer {
2620
2677
  private stopped;
2621
2678
  /**
2622
2679
  * cumulativeElapsed is a cumulative total of elapsed time while the timer
2623
- * was in previous started (running) states, NOT INCLUDING the possibily
2680
+ * was in previous started (running) states, NOT INCLUDING the possibly
2624
2681
  * active run's duration
2625
2682
  */
2626
2683
  private cumulativeElapsed;