@m2c2kit/core 0.3.15 → 0.3.17

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, Canvas, Surface, FontMgr, Typeface, EmbindObject, Font, Paint, ParagraphBuilder, Paragraph, Path, PaintStyle } from 'canvaskit-wasm';
1
+ import { Canvas, Typeface, TypefaceFontProvider, Image, CanvasKit, Surface, Font, Paint, ParagraphBuilder, Paragraph, FontMgr, Path, PaintStyle } from 'canvaskit-wasm';
2
2
 
3
3
  declare class GlobalVariables {
4
4
  now: number;
@@ -14,8 +14,413 @@ declare global {
14
14
  }
15
15
  //# sourceMappingURL=Globals.d.ts.map
16
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
+ /**
87
+ * Position in two-dimensional space.
88
+ */
89
+ interface Point {
90
+ /** Horizontal coordinate */
91
+ x: number;
92
+ /** Vertical coordinate */
93
+ y: number;
94
+ }
95
+
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;
107
+ }
108
+
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;
120
+ }
121
+
122
+ interface DrawableOptions {
123
+ /** Point within the node that determines its position. Default is &#123; x: 0.5, y: 0.5 &#125;, which centers the node on its position */
124
+ anchorPoint?: Point;
125
+ /** Value along the z-axis to determine drawing and tap order. Larger values are on top. */
126
+ zPosition?: number;
127
+ }
128
+
129
+ /**
130
+ * Constraints for defining relative layouts.
131
+ *
132
+ * @remarks FOR INTERNAL USE ONLY
133
+ */
134
+ interface Constraints {
135
+ /** Constrain the top (vertical axis) of this node to the top of the specified node. The tops of both will appear at the same vertical location */
136
+ topToTopOf?: M2Node | string;
137
+ /** Constrain the top (vertical axis) of this node to the bottom of the specified node. This node will appear immediately below the specified node */
138
+ topToBottomOf?: M2Node | string;
139
+ /** Constrain the bottom (vertical axis) of this node to the top of the specified node. This node will appear immediately above of the specified node */
140
+ bottomToTopOf?: M2Node | string;
141
+ /** Constrain the bottom (vertical axis) of this node to the bottom of the specified node. The bottoms of both will appear at the same vertical location */
142
+ bottomToBottomOf?: M2Node | string;
143
+ /** Constrain the start (horizontal axis) of this node to the start of the specified node. The start of both will appear at the same horizontal location */
144
+ startToStartOf?: M2Node | string;
145
+ /** Constrain the start (horizontal axis) of this node to the end of the specified node. This node will appear immediately to the right of the specified node */
146
+ startToEndOf?: M2Node | string;
147
+ /** Constrain the end (horizontal axis) of this node to the end of the specified node. The end of both will appear at the same horizontal location */
148
+ endToEndOf?: M2Node | string;
149
+ /** Constrain the end (horizontal axis) of this node to the start of the specified node. This node will appear immediately to the left of the specified node */
150
+ endToStartOf?: M2Node | string;
151
+ /** When opposing horizontal constraints are applied, the default is to center the node within the constraints (horizontalBias = .5). Setting horizontalBias less than .5 will pull the node towards the start (to the left). Setting horizontalBias greater than .5 will pull the node towards the end (to the right) */
152
+ horizontalBias?: number;
153
+ /** When opposing vertical constraints are applied, the default is to center the node within the constraints (verticalBias = .5). Setting verticalBias less than .5 will pull the node towards the top. Setting verticalBias greater than .5 will pull the node towards the bottom */
154
+ verticalBias?: number;
155
+ [key: string]: M2Node | string | number | undefined;
156
+ }
157
+
158
+ /**
159
+ * The Layout allows relative positioning via constraints.
160
+ * This is not fully implemented yet: DO NOT USE!
161
+ * We use it internally for instructions.
162
+ */
163
+ interface Layout {
164
+ height?: number;
165
+ width?: number;
166
+ marginStart?: number;
167
+ marginEnd?: number;
168
+ marginTop?: number;
169
+ marginBottom?: number;
170
+ constraints?: Constraints;
171
+ }
172
+
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
+ interface TextOptions {
179
+ /** Text to be displayed */
180
+ text?: string;
181
+ /** Name of font to use for text. Must have been previously loaded */
182
+ fontName?: string;
183
+ /** Color of text. Default is Constants.DEFAULT_FONT_COLOR (WebColors.Black) */
184
+ fontColor?: RgbaColor;
185
+ /** Size of text. Default is Constants.DEFAULT_FONT_SIZE (16) */
186
+ fontSize?: number;
187
+ }
188
+
189
+ /**
190
+ * Width and height on two-dimensional space
191
+ */
192
+ interface Size {
193
+ /** Horizontal width, x-axis */
194
+ width: number;
195
+ /** Vertical height, y-axis */
196
+ height: number;
197
+ }
198
+
199
+ interface M2NodeOptions {
200
+ /** Name of the node. Only needed if the node will be referred to by name in a later function */
201
+ name?: string;
202
+ /** Position of the node within its parent coordinate system. Default is (0, 0) */
203
+ position?: Point;
204
+ /** Scale of the node. Default is 1.0 */
205
+ scale?: number;
206
+ /** Opacity of the node. 0 is fully transparent, 1 is fully opaque. Default is 1.0. Alpha has multiplicative inheritance. For example, if the node's parent is alpha .5 and this node's is alpha .4, then the node will appear with alpha .2. */
207
+ alpha?: number;
208
+ /** Rotation of the node around the Z axis. Unit is radians. Default is 0 (no rotation). zRotation has inheritance. In addition to this node's zRotation, all ancestors' zRotations will be applied. */
209
+ zRotation?: number;
210
+ /** Does the node respond to user events, such as taps? Default is false */
211
+ isUserInteractionEnabled?: boolean;
212
+ /** Can the node be dragged? */
213
+ draggable?: boolean;
214
+ /** Is the node, and its children, hidden? (not displayed). Default is false */
215
+ hidden?: boolean;
216
+ /** FOR INTERNAL USE ONLY */
217
+ layout?: Layout;
218
+ }
219
+
220
+ declare enum M2NodeType {
221
+ Node = "Node",
222
+ Scene = "Scene",
223
+ Sprite = "Sprite",
224
+ Label = "Label",
225
+ TextLine = "TextLine",
226
+ Shape = "Shape",
227
+ Composite = "Composite"
228
+ }
229
+
230
+ type EasingFunction = (
231
+ /** elapsed time since start of action */
232
+ t: number,
233
+ /** start value of value to be eased */
234
+ b: number,
235
+ /** total change of value to be eased */
236
+ c: number,
237
+ /** total duration of action */
238
+ d: number) => number;
239
+ /**
240
+ * The Easings class has static methods for creating easings to be used in actions.
241
+ */
242
+ declare class Easings {
243
+ static none: EasingFunction;
244
+ static linear: EasingFunction;
245
+ static quadraticIn: EasingFunction;
246
+ static quadraticOut: EasingFunction;
247
+ static quadraticInOut: EasingFunction;
248
+ static cubicIn: EasingFunction;
249
+ static cubicOut: EasingFunction;
250
+ static cubicInOut: EasingFunction;
251
+ static quarticIn: EasingFunction;
252
+ static quarticOut: EasingFunction;
253
+ static quarticInOut: EasingFunction;
254
+ static quinticIn: EasingFunction;
255
+ static quinticOut: EasingFunction;
256
+ static quinticInOut: EasingFunction;
257
+ static sinusoidalIn: EasingFunction;
258
+ static sinusoidalOut: EasingFunction;
259
+ static sinusoidalInOut: EasingFunction;
260
+ static exponentialIn: EasingFunction;
261
+ static exponentialOut: EasingFunction;
262
+ static exponentialInOut: EasingFunction;
263
+ static circularIn: EasingFunction;
264
+ static circularOut: EasingFunction;
265
+ static circularInOut: EasingFunction;
266
+ }
267
+
268
+ interface IDrawable {
269
+ draw(canvas: Canvas): void;
270
+ warmup(canvas: Canvas): void;
271
+ /**
272
+ * Frees up resources allocated by the Drawable M2Node.
273
+ *
274
+ * @internal For m2c2kit library use only
275
+ *
276
+ * @remarks This will be done automatically by the m2c2kit library; the
277
+ * end-user must not call this.
278
+ */
279
+ dispose(): void;
280
+ anchorPoint: Point;
281
+ zPosition: number;
282
+ }
283
+
284
+ interface SceneOptions extends M2NodeOptions, DrawableOptions {
285
+ /** Background color of the scene. Default is Constants.DEFAULT_SCENE_BACKGROUND_COLOR (WebColors.White) */
286
+ backgroundColor?: RgbaColor;
287
+ }
288
+
289
+ interface CallbackOptions {
290
+ /** Should the provided callback replace any existing callbacks of the same event type for this target? Default is false */
291
+ replaceExisting?: boolean;
292
+ /** String identifier used to identify the callback. Only needed if the callback will be removed later */
293
+ key?: string;
294
+ }
295
+
296
+ declare class Scene extends M2Node implements IDrawable, SceneOptions {
297
+ readonly type = M2NodeType.Scene;
298
+ isDrawable: boolean;
299
+ anchorPoint: {
300
+ x: number;
301
+ y: number;
302
+ };
303
+ zPosition: number;
304
+ private _backgroundColor;
305
+ _active: boolean;
306
+ _transitioning: boolean;
307
+ private backgroundPaint?;
308
+ /**
309
+ * Top-level node that holds all other nodes, such as sprites, rectangles, or labels, that will be displayed on the screen
310
+ *
311
+ * @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.
312
+ *
313
+ * @param options - {@link SceneOptions}
314
+ */
315
+ constructor(options?: SceneOptions);
316
+ initialize(): void;
317
+ dispose(): void;
318
+ set game(game: Game);
319
+ /**
320
+ * The game which this scene is a part of.
321
+ *
322
+ * @remarks Throws error if scene is not part of the game object.
323
+ */
324
+ get game(): Game;
325
+ get backgroundColor(): RgbaColor;
326
+ set backgroundColor(backgroundColor: RgbaColor);
327
+ /**
328
+ * Duplicates a node using deep copy.
329
+ *
330
+ * @remarks This is a deep recursive clone (node and children).
331
+ * The uuid property of all duplicated nodes will be newly created,
332
+ * because uuid must be unique.
333
+ *
334
+ * @param newName - optional name of the new, duplicated node. If not
335
+ * provided, name will be the new uuid
336
+ */
337
+ duplicate(newName?: string): Scene;
338
+ /**
339
+ * Code that will be called every time the scene is presented.
340
+ *
341
+ * @remarks Use this callback to set nodes to their initial state, if
342
+ * that state might be changed later. For example, if a scene allows
343
+ * players to place dots on a grid, the setup() method should ensure the
344
+ * grid is clear of any prior dots from previous times this scene may
345
+ * have been displayed. In addition, if nodes should vary in each
346
+ * iteration, that should be done here.
347
+ *
348
+ * @param callback - function to execute
349
+ * @param options - {@link CallbackOptions}
350
+ */
351
+ onSetup(callback: (nodeEvent: M2NodeEvent) => void, options?: CallbackOptions): void;
352
+ /**
353
+ *
354
+ * Code that will be called after the scene has finished any transitions
355
+ * and has fully appeared on the screen.
356
+ *
357
+ * @param callback - function to execute
358
+ * @param options - {@link CallbackOptions}
359
+ */
360
+ onAppear(callback: (nodeEvent: M2NodeEvent) => void, options?: CallbackOptions): void;
361
+ update(): void;
362
+ draw(canvas: Canvas): void;
363
+ warmup(canvas: Canvas): void;
364
+ }
365
+
366
+ interface SlideTransitionOptions {
367
+ /** Direction in which the slide action goes */
368
+ direction: TransitionDirection;
369
+ /** Duration, in milliseconds, of the transition */
370
+ duration: number;
371
+ /** Easing function for movement; default is linear */
372
+ easing?: EasingFunction;
373
+ }
374
+ /**
375
+ * The Transition class has static methods for creating animations that run as one scene transitions to another.
376
+ */
377
+ declare abstract class Transition {
378
+ abstract type: TransitionType;
379
+ abstract easing: EasingFunction;
380
+ abstract duration: number;
381
+ /**
382
+ * Creates a scene transition in which the outgoing scene slides out and the incoming scene slides in, as if the incoming scene pushes it.
383
+ *
384
+ * @param options - {@link SlideTransitionOptions}
385
+ * @returns
386
+ */
387
+ static slide(options: SlideTransitionOptions): SlideTransition;
388
+ /**
389
+ * Creates a scene transition with no animation or duration. The next scene is immediately drawn.
390
+ */
391
+ static none(): NoneTransition;
392
+ }
393
+ declare class NoneTransition extends Transition {
394
+ type: TransitionType;
395
+ easing: EasingFunction;
396
+ duration: number;
397
+ constructor();
398
+ }
399
+ declare class SlideTransition extends Transition {
400
+ type: TransitionType;
401
+ easing: EasingFunction;
402
+ duration: number;
403
+ direction: TransitionDirection;
404
+ constructor(direction: TransitionDirection, duration: number, easing: EasingFunction);
405
+ }
406
+ declare enum TransitionType {
407
+ Slide = "Slide",
408
+ None = "None"
409
+ }
410
+ declare enum TransitionDirection {
411
+ Up = "Up",
412
+ Down = "Down",
413
+ Right = "Right",
414
+ Left = "Left"
415
+ }
416
+ declare class SceneTransition {
417
+ scene: Scene;
418
+ transition: Transition;
419
+ constructor(scene: Scene, transition: Transition);
420
+ }
421
+
17
422
  /** Base interface for all Activity events. */
18
- interface ActivityEvent extends EventBase {
423
+ interface ActivityEvent extends M2Event<Activity> {
19
424
  target: Activity;
20
425
  }
21
426
 
@@ -159,420 +564,104 @@ interface IDataStore {
159
564
  itemExists(key: string): Promise<boolean>;
160
565
  }
161
566
 
162
- declare class LoadedImage {
163
- name: string;
164
- image: Image;
165
- width: number;
166
- height: number;
167
- constructor(name: string, image: Image, width: number, height: number);
168
- }
169
-
170
- /**
171
- * Image that can be rendered by a browser from a URL or from a
172
- * HTML svg tag in string form. Provide either url or svgString, not both.
173
- */
174
- interface BrowserImage {
175
- /** Name that will be used to refer to the image. Must be unique among all
176
- * images within a game */
177
- imageName: string;
178
- /** Width to scale image to */
179
- width: number;
180
- /** Height to scale image to */
181
- height: number;
182
- /** The HTML SVG tag, in string form, that will be rendered and loaded.
183
- * Must begin with &#60;svg> and end with &#60;/svg> */
184
- svgString?: string;
185
- /** URL of image asset (svg, png, jpg) to render and load */
186
- url?: string;
187
- }
188
-
189
- interface GameImages {
190
- uuid: string;
191
- images: Array<BrowserImage>;
192
- }
193
-
194
- declare class LoadedImages {
195
- [gameUuid: string]: {
196
- [name: string]: LoadedImage;
197
- };
198
- }
199
- declare class ImageManager {
200
- canvasKit?: CanvasKit;
201
- private renderedImages;
202
- loadedImages: LoadedImages;
203
- private _scratchCanvas?;
204
- private ctx?;
205
- private scale?;
206
- private session;
207
- constructor(session: Session);
208
- /**
209
- * Returns a CanvasKit Image that was previously rendered by the ImageManager.
210
- *
211
- * @remarks Typically, this won't be called directly because a programmer
212
- * will use a higher-level abstraction (m2c2kit Sprite).
213
- *
214
- * @param gameUuid - The game that the image resource is part of
215
- * @param imageName - The name given to the rendered image
216
- * @returns A CanvasKit Image
217
- */
218
- getLoadedImage(gameUuid: string, imageName: string): LoadedImage;
219
- /**
220
- * Adds a CanvasKit Image to the images available to a given game.
221
- *
222
- * @remarks Typically, a programmer won't call this because images will be
223
- * automatically rendered and loaded in the Activity async init.
224
- * The only time this function is called in-game is when our internal
225
- * methods add screenshot images needed for transitions.
226
- *
227
- * @param loadedImage - An image that has been converted to a CanvasKit Image
228
- * @param gameUuid - The game that the Image is part of
229
- */
230
- addLoadedImage(loadedImage: LoadedImage, gameUuid: string): void;
231
- /**
232
- * Renders game images from their original format (png, jpg, svg) to
233
- * CanvasKit Image.
234
- *
235
- * @remarks Typically, a programmer won't call this because the Session
236
- * object will manage this. Rendering is an async activity, and thus
237
- * this method returns a promise. Rendering of all images is done in
238
- * parallel.
239
- *
240
- * @param allGamesImages - An array of GameImages data structures that
241
- * specify the image's desired size, it's name, and where the image to be
242
- * rendered is located (e.g., embedded svgString or url)
243
- * @returns A promise that completes when all game images have rendered
244
- */
245
- renderImages(allGamesImages: Array<GameImages>): Promise<void[]>;
246
- /**
247
- * Adds all rendered CanvasKit Images to the images available to m2c2kit.
248
- *
249
- * @remarks Typically, a programmer won't call this because the Session
250
- * object will manage this.
251
- */
252
- loadAllGamesRenderedImages(): void;
253
- /**
254
- * Our private method rendering an image to a CanvasKit Image
255
- *
256
- * @remarks This is complex because there is a separate flow to render
257
- * svg images versus other (e.g., jpg, png). Svg images may be provided
258
- * in a url or inline. In addition, there is a Firefox svg rendering issue,
259
- * see below, that must be handled.
260
- * Additional complexity comes from the potentially multiple async steps and
261
- * the multiple errors that can happen throughout.
262
- *
263
- * @param gameUuid
264
- * @param browserImage
265
- * @returns A promise of type void
266
- */
267
- private renderBrowserImage;
268
- private arrayBufferToBase64String;
269
- private inferImageSubtypeFromUrl;
270
- private convertRenderedDataUrlImageToCanvasKitImage;
271
- /**
272
- * Returns the scratchCanvas, which is an extra, non-visible canvas in the
273
- * DOM we use so the native browser can render images like svg, png, jpg,
274
- * that we later will convert to CanvasKit Image.
275
- */
276
- private get scratchCanvas();
277
- private dataURLtoArrayBuffer;
278
- removeScratchCanvas(): void;
279
- }
280
-
281
- interface FontData {
282
- gameUuid: string;
283
- fontUrl: string;
284
- fontName: string;
285
- fontFamilyName: string;
286
- fontArrayBuffer: ArrayBuffer;
287
- isDefault: boolean;
288
- }
289
-
290
- type EasingFunction = (
291
- /** elapsed time since start of action */
292
- t: number,
293
- /** start value of value to be eased */
294
- b: number,
295
- /** total change of value to be eased */
296
- c: number,
297
- /** total duration of action */
298
- d: number) => number;
299
- /**
300
- * The Easings class has static methods for creating easings to be used in actions.
301
- */
302
- declare class Easings {
303
- static none: EasingFunction;
304
- static linear: EasingFunction;
305
- static quadraticIn: EasingFunction;
306
- static quadraticOut: EasingFunction;
307
- static quadraticInOut: EasingFunction;
308
- static cubicIn: EasingFunction;
309
- static cubicOut: EasingFunction;
310
- static cubicInOut: EasingFunction;
311
- static quarticIn: EasingFunction;
312
- static quarticOut: EasingFunction;
313
- static quarticInOut: EasingFunction;
314
- static quinticIn: EasingFunction;
315
- static quinticOut: EasingFunction;
316
- static quinticInOut: EasingFunction;
317
- static sinusoidalIn: EasingFunction;
318
- static sinusoidalOut: EasingFunction;
319
- static sinusoidalInOut: EasingFunction;
320
- static exponentialIn: EasingFunction;
321
- static exponentialOut: EasingFunction;
322
- static exponentialInOut: EasingFunction;
323
- static circularIn: EasingFunction;
324
- static circularOut: EasingFunction;
325
- static circularInOut: EasingFunction;
326
- }
327
-
328
- /**
329
- * Position in two-dimensional space.
330
- */
331
- interface Point {
332
- /** Horizontal coordinate */
333
- x: number;
334
- /** Vertical coordinate */
335
- y: number;
336
- }
337
-
338
- interface IDrawable {
339
- draw(canvas: Canvas): void;
340
- warmup(canvas: Canvas): void;
341
- /**
342
- * Frees up resources that were allocated for this drawable entity.
343
- *
344
- * @remarks This will be done automatically by the m2c2kit library;
345
- * the end-user must not call this.
346
- */
347
- dispose(): void;
348
- anchorPoint: Point;
349
- zPosition: number;
350
- }
351
-
352
- declare enum EntityType {
353
- Entity = "Entity",
354
- Scene = "Scene",
355
- Sprite = "Sprite",
356
- Label = "Label",
357
- TextLine = "TextLine",
358
- Shape = "Shape",
359
- Composite = "Composite"
360
- }
361
-
362
- /**
363
- * Color in red (0-255), green (0-255), blue (0-255), alpha (0-1) format. Must be numeric array of length 4.
364
- */
365
- type RgbaColor = [number, number, number, number];
366
-
367
- interface DrawableOptions {
368
- /** Point within the entity that determines its position. Default is &#123; x: 0.5, y: 0.5 &#125;, which centers the entity on its position */
369
- anchorPoint?: Point;
370
- /** Value along the z-axis to determine drawing and tap order. Larger values are on top. */
371
- zPosition?: number;
372
- }
373
-
374
- /**
375
- * Constraints for defining relative layouts.
376
- *
377
- * @remarks FOR INTERNAL USE ONLY
378
- */
379
- interface Constraints {
380
- /** Constrain the top (vertical axis) of this entity to the top of the specified entity. The tops of both will appear at the same vertical location */
381
- topToTopOf?: Entity | string;
382
- /** Constrain the top (vertical axis) of this entity to the bottom of the specified entity. This entity will appear immediately below the specified entity */
383
- topToBottomOf?: Entity | string;
384
- /** Constrain the bottom (vertical axis) of this entity to the top of the specified entity. This entity will appear immediately above of the specified entity */
385
- bottomToTopOf?: Entity | string;
386
- /** Constrain the bottom (vertical axis) of this entity to the bottom of the specified entity. The bottoms of both will appear at the same vertical location */
387
- bottomToBottomOf?: Entity | string;
388
- /** Constrain the start (horizontal axis) of this entity to the start of the specified entity. The start of both will appear at the same horizontal location */
389
- startToStartOf?: Entity | string;
390
- /** Constrain the start (horizontal axis) of this entity to the end of the specified entity. This entity will appear immediately to the right of the specified entity */
391
- startToEndOf?: Entity | string;
392
- /** Constrain the end (horizontal axis) of this entity to the end of the specified entity. The end of both will appear at the same horizontal location */
393
- endToEndOf?: Entity | string;
394
- /** Constrain the end (horizontal axis) of this entity to the start of the specified entity. This entity will appear immediately to the left of the specified entity */
395
- endToStartOf?: Entity | string;
396
- /** When opposing horizontal constraints are applied, the default is to center the entity within the constraints (horizontalBias = .5). Setting horizontalBias less than .5 will pull the entity towards the start (to the left). Setting horizontalBias greater than .5 will pull the entity towards the end (to the right) */
397
- horizontalBias?: number;
398
- /** When opposing vertical constraints are applied, the default is to center the entity within the constraints (verticalBias = .5). Setting verticalBias less than .5 will pull the entity towards the top. Setting verticalBias greater than .5 will pull the entity towards the bottom */
399
- verticalBias?: number;
400
- [key: string]: Entity | string | number | undefined;
401
- }
402
-
403
- /**
404
- * The Layout allows relative positioning via constraints.
405
- * This is not fully implemented yet: DO NOT USE!
406
- * We use it internally for instructions.
407
- */
408
- interface Layout {
409
- height?: number;
410
- width?: number;
411
- marginStart?: number;
412
- marginEnd?: number;
413
- marginTop?: number;
414
- marginBottom?: number;
415
- constraints?: Constraints;
416
- }
417
-
418
- interface EntityOptions {
419
- /** Name of the entity. Only needed if the entity will be referred to by name in a later function */
420
- name?: string;
421
- /** Position of the entity within its parent coordinate system. Default is (0, 0) */
422
- position?: Point;
423
- /** Scale of the entity. Default is 1.0 */
424
- scale?: number;
425
- /** Opacity of the entity. 0 is fully transparent, 1 is fully opaque. Default is 1.0. Alpha has multiplicative inheritance. For example, if the entity's parent is alpha .5 and this entity's is alpha .4, then the entity will appear with alpha .2. */
426
- alpha?: number;
427
- /** Rotation of the entity around the Z axis. Unit is radians. Default is 0 (no rotation). zRotation has inheritance. In addition to this entity's zRotation, all ancestors' zRotations will be applied. */
428
- zRotation?: number;
429
- /** Does the entity respond to user events, such as taps? Default is false */
430
- isUserInteractionEnabled?: boolean;
431
- /** Can the entity be dragged? */
432
- draggable?: boolean;
433
- /** Is the entity, and its children, hidden? (not displayed). Default is false */
434
- hidden?: boolean;
435
- /** FOR INTERNAL USE ONLY */
436
- layout?: Layout;
437
- }
438
-
439
- interface SceneOptions extends EntityOptions, DrawableOptions {
440
- /** Background color of the scene. Default is Constants.DEFAULT_SCENE_BACKGROUND_COLOR (WebColors.White) */
441
- backgroundColor?: RgbaColor;
442
- }
443
-
444
- declare class Scene extends Entity implements IDrawable, SceneOptions {
445
- readonly type = EntityType.Scene;
446
- isDrawable: boolean;
447
- anchorPoint: {
448
- x: number;
449
- y: number;
450
- };
451
- zPosition: number;
452
- private _backgroundColor;
453
- _active: boolean;
454
- _transitioning: boolean;
455
- _setupCallback?: (scene: Scene) => void;
456
- _appearCallback?: (scene: Scene) => void;
457
- private backgroundPaint?;
458
- /**
459
- * Top-level entity that holds all other entities, such as sprites, rectangles, or labels, that will be displayed on the screen
460
- *
461
- * @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.
462
- *
463
- * @param options - {@link SceneOptions}
464
- */
465
- constructor(options?: SceneOptions);
466
- initialize(): void;
467
- dispose(): void;
468
- set game(game: Game);
567
+ interface Activity {
568
+ /** The type of activity: Game or Survey */
569
+ type: ActivityType;
469
570
  /**
470
- * The game which this scene is a part of.
571
+ * Initializes the activity.
471
572
  *
472
- * @remarks Throws error if scene is not part of the game object.
573
+ * @remarks All code to create the activity's appearance and behavior must
574
+ * be placed in this method. This method is asynchronous, and must be
575
+ * awaited. When writing a new game by extending the `Game` class, this
576
+ * method will be overridden, but the base method must still be called with
577
+ * `await super.initialize()`.
473
578
  */
474
- get game(): Game;
475
- get backgroundColor(): RgbaColor;
476
- set backgroundColor(backgroundColor: RgbaColor);
579
+ initialize(): Promise<void>;
477
580
  /**
478
- * Duplicates an entity using deep copy.
581
+ * Initializes the activity.
479
582
  *
480
- * @remarks This is a deep recursive clone (entity and children).
481
- * The uuid property of all duplicated entities will be newly created,
482
- * because uuid must be unique.
583
+ * @remarks All code to create the activity's appearance and behavior must
584
+ * be placed in this method. This method is asynchronous, and must be
585
+ * awaited. When writing a new game by extending the `Game` class, this
586
+ * method will be overridden, but the base method must still be called with
587
+ * `await super.init()`.
483
588
  *
484
- * @param newName - optional name of the new, duplicated entity. If not
485
- * provided, name will be the new uuid
589
+ * @deprecated use Game.initialize() instead.
486
590
  */
487
- duplicate(newName?: string): Scene;
488
- /**
489
- * Code that will be called every time the scene is presented.
490
- *
491
- * @remarks Use this callback to set entities to their initial state, if
492
- * that state might be changed later. For example, if a scene allows
493
- * players to place dots on a grid, the setup() method should ensure the
494
- * grid is clear of any prior dots from previous times this scene may
495
- * have been displayed. In addition, if entities should vary in each
496
- * iteration, that should be done here.
591
+ init(): Promise<void>;
592
+ /** Starts the activity */
593
+ start(): Promise<void>;
594
+ /** Stops the activity */
595
+ stop(): void;
596
+ /**
597
+ * Executes a callback when the activity starts.
497
598
  *
498
- * @param callback
599
+ * @param callback - function to execute.
600
+ * @param options - options for the callback.
499
601
  */
500
- onSetup(callback: (scene: Scene) => void): void;
602
+ onStart(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
501
603
  /**
604
+ * Executes a callback when the activity is canceled.
502
605
  *
503
- * Code that will be called after the scene has finished any transitions
504
- * and has fully appeared on the screen.
505
- *
506
- * @param callback
606
+ * @param callback - function to execute.
607
+ * @param options - options for the callback.
507
608
  */
508
- onAppear(callback: (scene: Scene) => void): void;
509
- update(): void;
510
- draw(canvas: Canvas): void;
511
- warmup(canvas: Canvas): void;
512
- }
513
-
514
- interface SlideTransitionOptions {
515
- /** Direction in which the slide action goes */
516
- direction: TransitionDirection;
517
- /** Duration, in milliseconds, of the transition */
518
- duration: number;
519
- /** Easing function for movement; default is linear */
520
- easing?: EasingFunction;
521
- }
522
- /**
523
- * The Transition class has static methods for creating animations that run as one scene transitions to another.
524
- */
525
- declare abstract class Transition {
526
- abstract type: TransitionType;
527
- abstract easing: EasingFunction;
528
- abstract duration: number;
609
+ onCancel(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
529
610
  /**
530
- * Creates a scene transition in which the outgoing scene slides out and the incoming scene slides in, as if the incoming scene pushes it.
611
+ * Executes a callback when the activity ends.
531
612
  *
532
- * @param options - {@link SlideTransitionOptions}
533
- * @returns
613
+ * @param callback - function to execute.
614
+ * @param options - options for the callback.
534
615
  */
535
- static slide(options: SlideTransitionOptions): SlideTransition;
616
+ onEnd(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
536
617
  /**
537
- * Creates a scene transition with no animation or duration. The next scene is immediately drawn.
618
+ * Executes a callback when the activity generates data.
619
+ *
620
+ * @param callback - function to execute.
621
+ * @param options - options for the callback.
538
622
  */
539
- static none(): NoneTransition;
540
- }
541
- declare class NoneTransition extends Transition {
542
- type: TransitionType;
543
- easing: EasingFunction;
544
- duration: number;
545
- constructor();
546
- }
547
- declare class SlideTransition extends Transition {
548
- type: TransitionType;
549
- easing: EasingFunction;
550
- duration: number;
551
- direction: TransitionDirection;
552
- constructor(direction: TransitionDirection, duration: number, easing: EasingFunction);
553
- }
554
- declare enum TransitionType {
555
- Slide = "Slide",
556
- None = "None"
557
- }
558
- declare enum TransitionDirection {
559
- Up = "Up",
560
- Down = "Down",
561
- Right = "Right",
562
- Left = "Left"
563
- }
564
- declare class SceneTransition {
565
- scene: Scene;
566
- transition: Transition;
567
- constructor(scene: Scene, transition: Transition);
623
+ onData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
624
+ /** The activity's parent session unique identifier. */
625
+ sessionUuid: string;
626
+ /** The activity's unique identifier. NOTE: This is newly generated each session. The uuid for an activity will vary across sessions. */
627
+ uuid: string;
628
+ /** Human-friendly name of this activity */
629
+ name: string;
630
+ /** Short identifier of this activity */
631
+ id: string;
632
+ /** The value of performance.now() immediately before the activity begins */
633
+ beginTimestamp: number;
634
+ /** The value of new Date().toISOString() immediately before the activity begins */
635
+ beginIso8601Timestamp: string;
636
+ /** Sets additional activity parameters if defaults are not sufficient. */
637
+ setParameters(additionalParameters: unknown): void;
638
+ /** Additional activity parameters that were set. */
639
+ readonly additionalParameters?: unknown;
640
+ /** Optional stores to use for saving data. The implementation of the store is not provided by the \@m2c2kit/core library. */
641
+ dataStores?: IDataStore[];
568
642
  }
569
643
 
570
- /** Base interface for all Entity events. */
571
- interface EntityEvent extends EventBase {
572
- /** The Entity on which the event occurred. */
573
- target: Entity;
574
- /** For composites that raise events, type of the composite custom event. */
575
- compositeType?: string;
644
+ /**
645
+ * Image that can be rendered by a browser from a URL or from a
646
+ * HTML svg tag in string form. Provide either url or svgString, not both.
647
+ */
648
+ interface BrowserImage {
649
+ /** Name that will be used to refer to the image. Must be unique among all
650
+ * images within a game */
651
+ imageName: string;
652
+ /** Width to scale image to */
653
+ width: number;
654
+ /** Height to scale image to */
655
+ height: number;
656
+ /** The HTML SVG tag, in string form, that will be rendered and loaded.
657
+ * Must begin with &#60;svg> and end with &#60;/svg> */
658
+ svgString?: string;
659
+ /** URL of image asset (svg, png, jpg) to render and load */
660
+ url?: string;
661
+ /** If true, the image will not be fully loaded until it is needed. Default
662
+ * is false. Lazy loading is useful for localized images or large "banks"
663
+ * of images. These should be lazy loaded because they may not be needed. */
664
+ lazy?: boolean;
576
665
  }
577
666
 
578
667
  /**
@@ -621,6 +710,19 @@ interface Translations {
621
710
  };
622
711
  }
623
712
 
713
+ /**
714
+ * Font url and raw data that has been shared with other games in the session.
715
+ *
716
+ * @remarks Font sharing will happen only if the font filename is the same AND
717
+ * a game's `shareAssets` property is not false.
718
+ */
719
+ interface SharedFont {
720
+ /** url that the shared font was loaded from */
721
+ url: string;
722
+ /** raw data of the shared font */
723
+ data: ArrayBuffer;
724
+ }
725
+
624
726
  /**
625
727
  * Font asset to use in the game.
626
728
  */
@@ -629,6 +731,27 @@ interface FontAsset {
629
731
  fontName: string;
630
732
  /** URL of font (TrueType font) to load */
631
733
  url: string;
734
+ /** If true, the font will not be fully loaded until it is needed. Default
735
+ * is false. Lazy loading is useful for fonts involved in localization.
736
+ * These should be lazy loaded because they may not be needed.
737
+ */
738
+ lazy?: boolean;
739
+ /** Font url and raw data that has been shared with other games in the session. Undefined if this font was not shared. @internal For m2c2kit library use only */
740
+ sharedFont?: SharedFont;
741
+ }
742
+
743
+ /**
744
+ * Game's module name, version, and dependencies.
745
+ */
746
+ interface ModuleMetadata {
747
+ /** name property from package.json */
748
+ name: string;
749
+ /** version property from package.json */
750
+ version: string;
751
+ /** dependency property from package.json */
752
+ dependencies: {
753
+ [key: string]: string;
754
+ };
632
755
  }
633
756
 
634
757
  /**
@@ -671,16 +794,16 @@ interface GameOptions {
671
794
  maximumRecordedActivityMetrics?: number;
672
795
  /** 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 */
673
796
  fpsMetricReportThreshold?: number;
674
- /** Adapt execution for unit testing? Default is false */
675
- _unitTesting?: boolean;
676
797
  /** Advance through time step-by-step, for development and debugging */
677
798
  timeStepping?: boolean;
678
799
  /** Translations for localization. */
679
800
  translations?: Translations;
680
801
  /** Show logs for WebGl activity? */
681
802
  logWebGl?: boolean;
682
- /** URL of game assets folder, if not the default location of "assets/id of game from GameOptions" */
683
- assetsUrl?: string;
803
+ /** Should games within a session share wasm and font assets that have identical filenames, in order to reduce bandwidth? Default is true. */
804
+ shareAssets?: boolean;
805
+ /** Game's module name, version, and dependencies. @internal For m2c2kit library use only */
806
+ moduleMetadata?: ModuleMetadata;
684
807
  }
685
808
 
686
809
  interface GameData extends ActivityKeyValueData {
@@ -718,20 +841,286 @@ declare class I18n {
718
841
  private mergeAdditionalTranslations;
719
842
  }
720
843
 
721
- interface CallbackOptions {
722
- /** Should the provided callback replace any existing callbacks of the same event type for this target? Default is false */
723
- replaceExisting?: boolean;
724
- /** String identifier used to identify the callback. Only needed if the callback will be removed later */
725
- key?: string;
844
+ /**
845
+ * A Plugin is code that can be registered to run at certain points in the game loop.
846
+ */
847
+ interface Plugin {
848
+ /** Short identifier of the plugin. */
849
+ id: string;
850
+ /** What kind of m2c2kit object does the plugin work with? */
851
+ type: "Game" | "Session" | "Survey";
852
+ /** Initialization code run when the plugin is registered with the game. */
853
+ initialize?: (game: Game) => Promise<void>;
854
+ /** Is the plugin disabled and not to be run? Default is false. @remarks Disabled plugins will still be initialized. */
855
+ disabled?: boolean;
856
+ /** Plugin code run before the frame update, but before the frame draw. */
857
+ beforeUpdate?: (game: Game, deltaTime: number) => void;
858
+ /** Plugin code run after the frame update, but before the frame draw. */
859
+ afterUpdate?: (game: Game, deltaTime: number) => void;
860
+ }
861
+
862
+ interface M2Font {
863
+ fontName: string;
864
+ typeface: Typeface | undefined;
865
+ data: ArrayBuffer | undefined;
866
+ url: string;
867
+ status: M2FontStatus;
868
+ default: boolean;
869
+ }
870
+ declare const M2FontStatus: {
871
+ /** Font was set for lazy loading, and loading has not yet been requested. */
872
+ readonly Deferred: "Deferred";
873
+ /** Font is in the process of loading. */
874
+ readonly Loading: "Loading";
875
+ /** Font has fully finished loading and is ready to use. */
876
+ readonly Ready: "Ready";
877
+ /** Error occurred in loading. */
878
+ readonly Error: "Error";
879
+ };
880
+ type M2FontStatus = (typeof M2FontStatus)[keyof typeof M2FontStatus];
881
+
882
+ /**
883
+ * Base URLs for game resources.
884
+ */
885
+ interface GameBaseUrls {
886
+ /** Base URL for fonts and images. */
887
+ assets: string;
888
+ /** Base URL for CanvasKit wasm binary. */
889
+ canvasKitWasm: string;
890
+ }
891
+
892
+ /**
893
+ * Fetches, loads, and provides fonts to the game.
894
+ *
895
+ * @internal For m2c2kit library use only
896
+ */
897
+ declare class FontManager {
898
+ fonts: Record<string, M2Font>;
899
+ provider: TypefaceFontProvider;
900
+ private canvasKit;
901
+ private game;
902
+ private baseUrls;
903
+ constructor(game: Game, baseUrls: GameBaseUrls);
904
+ /**
905
+ * Loads font assets and makes them ready to use during the game initialization.
906
+ *
907
+ * @internal For m2c2kit library use only
908
+ *
909
+ * @remarks Typically, a user won't call this because the m2c2kit
910
+ * framework will call this automatically.
911
+ *
912
+ * @param fonts - array of FontAsset objects (name and url)
913
+ */
914
+ initializeFonts(fonts: Array<FontAsset> | undefined): Promise<void>;
915
+ /**
916
+ * Loads an array of fonts and makes them ready for the game.
917
+ *
918
+ * @param fonts - an array of {@link FontAsset}
919
+ * @returns A promise that completes when all fonts have loaded
920
+ */
921
+ loadFonts(fonts: Array<FontAsset>): Promise<void>;
922
+ private prepareFont;
923
+ /**
924
+ * Makes ready to the game a m2c2kit font ({@link M2Font}) that was
925
+ * previously loaded, but whose processing was deferred.
926
+ *
927
+ * @internal For m2c2kit library use only
928
+ *
929
+ * @param font - M2Font to make ready
930
+ * @returns A promise that completes when the font is ready
931
+ */
932
+ prepareDeferredFont(font: M2Font): Promise<void>;
933
+ private fetchFontAsArrayBuffer;
934
+ private registerFont;
935
+ /**
936
+ * Returns a m2c2kit font ({@link M2Font}) that has been loaded by the
937
+ * FontManager.
938
+ *
939
+ * @internal For m2c2kit library use only
940
+ *
941
+ * @remarks Typically, a user won't need to call this because font
942
+ * initialization and processing is handled by the framework.
943
+ *
944
+ * @param fontName - font's name as defined in the game's font assets
945
+ * @returns a m2c2kit font
946
+ */
947
+ getFont(fontName: string): M2Font;
948
+ /**
949
+ * Returns the m2c2kit default font ({@link M2Font}) that has been loaded
950
+ * by the FontManager.
951
+ *
952
+ * @internal For m2c2kit library use only
953
+ *
954
+ * @remarks Typically, a user won't need to call this because font
955
+ * initialization and processing is handled by the framework.
956
+ *
957
+ * @returns a m2c2kit font
958
+ */
959
+ getDefaultFont(): M2Font;
960
+ /**
961
+ * Frees up resources allocated by the FontManager.
962
+ *
963
+ * @internal For m2c2kit library use only
964
+ *
965
+ * @remarks This will be done automatically by the m2c2kit library; the
966
+ * end-user must not call this.
967
+ */
968
+ dispose(): void;
969
+ /**
970
+ * Gets a CanvasKit Typeface that has been loaded.
971
+ *
972
+ * @internal For m2c2kit library use only
973
+ *
974
+ * @remarks Typically, a user won't need to call this because font
975
+ * initialization and processing is handled by the framework.
976
+ *
977
+ * @param fontName - name as defined in the game's font assets
978
+ * @returns the requested Typeface
979
+ */
980
+ getTypeface(fontName: string): Typeface;
981
+ /**
982
+ * Gets names of fonts loaded.
983
+ *
984
+ * @returns array of font names loaded from the game's font assets and
985
+ * converted into M2Font objects. The names are the names as defined
986
+ * in the game's font assets.
987
+ */
988
+ getFontNames(): Array<string>;
989
+ }
990
+
991
+ /**
992
+ * An image that has been loaded into the game.
993
+ *
994
+ * @remarks An M2Image is a wrapper around a CanvasKit Image, with some
995
+ * additional properties.
996
+ */
997
+ interface M2Image {
998
+ imageName: string;
999
+ canvaskitImage: Image | undefined;
1000
+ width: number;
1001
+ height: number;
1002
+ status: M2ImageStatus;
1003
+ url?: string;
1004
+ svgString?: string;
726
1005
  }
1006
+ declare const M2ImageStatus: {
1007
+ /** Image was set for lazy loading, and loading has not yet been requested. */
1008
+ readonly Deferred: "Deferred";
1009
+ /** Image is in the process of loading (fetching, rendering, and conversion to CanvasKit Image). */
1010
+ readonly Loading: "Loading";
1011
+ /** Image has fully finished loading and is ready to use. */
1012
+ readonly Ready: "Ready";
1013
+ /** Error occurred in loading. */
1014
+ readonly Error: "Error";
1015
+ };
1016
+ type M2ImageStatus = (typeof M2ImageStatus)[keyof typeof M2ImageStatus];
727
1017
 
728
1018
  /**
729
- * Notifies when events in the Frame cycle occur on a Game.
1019
+ * Fetches, loads, and provides images to the game.
730
1020
  */
731
- interface FrameCycleEvent extends EventBase {
1021
+ declare class ImageManager {
1022
+ images: Record<string, M2Image>;
1023
+ private canvasKit;
1024
+ private _scratchCanvas?;
1025
+ private ctx?;
1026
+ private scale?;
1027
+ private game;
1028
+ private baseUrls;
1029
+ constructor(game: Game, baseUrls: GameBaseUrls);
1030
+ /**
1031
+ * Loads image assets and makes them ready to use during the game initialization.
1032
+ *
1033
+ * @internal For m2c2kit library use only
1034
+ *
1035
+ * @remarks Typically, a user won't call this because the m2c2kit
1036
+ * framework will call this automatically.
1037
+ *
1038
+ * @param browserImages - array of BrowserImage objects
1039
+ * @returns A promise that completes when all images have loaded
1040
+ */
1041
+ initializeImages(browserImages: Array<BrowserImage> | undefined): Promise<void>;
1042
+ /**
1043
+ * Loads an array of images and makes them ready for the game.
1044
+ *
1045
+ * @remarks Using the browser's image rendering, this method converts the
1046
+ * images (png, jpg, svg, or svg string) into m2c2kit images ({@link M2Image}).
1047
+ * Rendering is an async activity, and thus this method returns a promise.
1048
+ * Rendering of all images is done in parallel.
1049
+ *
1050
+ * @param browserImages - an array of {@link BrowserImage}
1051
+ * @returns A promise that completes when all images have loaded
1052
+ */
1053
+ loadImages(browserImages: Array<BrowserImage>): Promise<void>;
1054
+ private checkImageNamesForDuplicates;
1055
+ /**
1056
+ * Makes ready to the game a m2c2kit image ({@link M2Image}) that was
1057
+ * previously loaded, but whose browser rendering was deferred.
1058
+ *
1059
+ * @internal For m2c2kit library use only
1060
+ *
1061
+ * @param image - M2Image to render and make ready
1062
+ * @returns A promise that completes when the image is ready
1063
+ */
1064
+ prepareDeferredImage(image: M2Image): Promise<void>;
1065
+ /**
1066
+ * Uses the browser to render an image to a CanvasKit Image and make it
1067
+ * ready to the game as an M2Image.
1068
+ *
1069
+ * @remarks This is complex because we rely on the browser's rendering
1070
+ * and HTML image element processing. This involves a number of steps,
1071
+ * including events, callbacks, and error handling. In addition, there
1072
+ * are two types of images to be rendered: 1) url to an image (e.g., jpg,
1073
+ * png, svg), and 2) svg string.
1074
+ *
1075
+ * @param image - The M2Image to render
1076
+ * @returns A promise of type void that resolves when the image has been
1077
+ * rendered
1078
+ */
1079
+ private renderM2Image;
1080
+ private arrayBufferToBase64Async;
1081
+ private inferImageSubtypeFromUrl;
1082
+ /**
1083
+ * Returns a m2c2kit image ({@link M2Image}) that has been loaded by the ImageManager.
1084
+ *
1085
+ * @internal For m2c2kit library use only
1086
+ *
1087
+ * @remarks Typically, a user won't call this because they use a higher-level
1088
+ * abstraction (m2c2kit Sprite).
1089
+ *
1090
+ * @param imageName - The name given to the previously rendered image
1091
+ * @returns A m2c2kit image
1092
+ */
1093
+ getImage(imageName: string): M2Image;
1094
+ /**
1095
+ * Adds a m2c2kit image ({@link M2Image}) to the images ready for the game.
1096
+ *
1097
+ * @internal For m2c2kit library use only
1098
+ *
1099
+ * @remarks Typically, a programmer won't call this because images will be
1100
+ * automatically rendered and loaded in initializeImages().
1101
+ * One reason this function is called in-game is when the game takes
1102
+ * a screenshot and adds it as an outgoing image for transitions.
1103
+ *
1104
+ * @param image - A m2c2kit image
1105
+ */
1106
+ addImage(image: M2Image): void;
1107
+ /**
1108
+ * Returns the scratchCanvas, which is an extra, non-visible canvas in the
1109
+ * DOM we use so the native browser can render images like svg, png, jpg,
1110
+ * that we later will convert to CanvasKit Image.
1111
+ */
1112
+ private get scratchCanvas();
1113
+ private removeScratchCanvas;
1114
+ }
1115
+
1116
+ /** Key value pairs of file URLs and hashed file URLs */
1117
+ type Manifest = {
1118
+ [originalUrl: string]: string;
1119
+ };
1120
+
1121
+ /** Base interface for all Game events. */
1122
+ interface GameEvent extends M2Event<Activity> {
732
1123
  target: Game;
733
- /** difference in milliseconds since the last Frame lifecycle began */
734
- deltaTime: number;
735
1124
  }
736
1125
 
737
1126
  interface TrialData {
@@ -740,10 +1129,12 @@ interface TrialData {
740
1129
  declare class Game implements Activity {
741
1130
  readonly type = ActivityType.Game;
742
1131
  _canvasKit?: CanvasKit;
743
- _session?: Session;
1132
+ sessionUuid: string;
744
1133
  uuid: string;
745
1134
  name: string;
746
1135
  id: string;
1136
+ moduleMetadata: ModuleMetadata;
1137
+ readonly canvasKitWasmVersion = "__CANVASKITWASM_VERSION__";
747
1138
  options: GameOptions;
748
1139
  beginTimestamp: number;
749
1140
  beginIso8601Timestamp: string;
@@ -755,21 +1146,65 @@ declare class Game implements Activity {
755
1146
  private steppingNow;
756
1147
  i18n?: I18n;
757
1148
  private warmupFunctionQueue;
758
- private loaderElementsRemoved;
1149
+ private warmupFinished;
759
1150
  private _dataStores?;
1151
+ private plugins;
760
1152
  additionalParameters?: unknown;
761
1153
  staticTrialSchema: {
762
1154
  [key: string]: JsonSchemaDataTypeScriptTypes;
763
1155
  };
1156
+ private _fontManager?;
1157
+ private _imageManager?;
1158
+ manifest?: Manifest;
764
1159
  /**
765
1160
  * The base class for all games. New games should extend this class.
766
1161
  *
767
1162
  * @param options - {@link GameOptions}
768
1163
  */
769
1164
  constructor(options: GameOptions);
1165
+ private getImportedModuleBaseUrl;
770
1166
  private addLocalizationParametersToGameParameters;
771
1167
  init(): Promise<void>;
1168
+ /**
1169
+ * Loads the canvaskit wasm binary.
1170
+ *
1171
+ * @internal For m2c2kit library use only
1172
+ *
1173
+ * @remarks The CanvasKit object is initialized with this method, rather
1174
+ * than calling `CanvasKitInit()` directly, so that this method can be
1175
+ * easily mocked in tests.
1176
+ *
1177
+ * @param canvasKitWasmUrl - URL to the canvaskit wasm binary
1178
+ * @returns a promise that resolves to a CanvasKit object
1179
+ */
1180
+ loadCanvasKit(canvasKitWasmUrl: string): Promise<CanvasKit>;
1181
+ /**
1182
+ * Resolves base URL locations for game assets and CanvasKit wasm binary.
1183
+ *
1184
+ * @internal For m2c2kit library use only
1185
+ *
1186
+ * @param game - game to resolve base URLs for
1187
+ * @returns base URLs for game assets and CanvasKit wasm binary
1188
+ */
1189
+ resolveGameBaseUrls(game: Game): Promise<GameBaseUrls>;
772
1190
  initialize(): Promise<void>;
1191
+ /**
1192
+ * Returns the manifest, if manifest.json was created during the build.
1193
+ *
1194
+ * @internal For m2c2kit library use only
1195
+ *
1196
+ * @remarks This should be called without any parameters. The
1197
+ * `manifestJsonUrl` parameter's default value will be modified during the
1198
+ * build step, if the build was configured to include the manifest.json
1199
+ *
1200
+ * @param manifestJsonUrl - Do not use this parameter. Allow the default.
1201
+ * @returns a promise that resolves to the manifest object, or an empty object if there is no manifest
1202
+ */
1203
+ loadManifest(manifestJsonUrl?: string): Promise<Manifest>;
1204
+ get fontManager(): FontManager;
1205
+ set fontManager(fontManager: FontManager);
1206
+ get imageManager(): ImageManager;
1207
+ set imageManager(imageManager: ImageManager);
773
1208
  /**
774
1209
  * Saves an item to the activity's key-value store.
775
1210
  *
@@ -878,8 +1313,6 @@ declare class Game implements Activity {
878
1313
  setParameters(additionalParameters: unknown): void;
879
1314
  get canvasKit(): CanvasKit;
880
1315
  set canvasKit(canvasKit: CanvasKit);
881
- get session(): Session;
882
- set session(session: Session);
883
1316
  /** The scene, or its name as a string, to be presented when the game is started. If this is undefined, the game will start with the first scene that has been added */
884
1317
  entryScene?: Scene | string;
885
1318
  data: GameData;
@@ -899,54 +1332,69 @@ declare class Game implements Activity {
899
1332
  private fpsRate;
900
1333
  private animationFramesRequested;
901
1334
  private limitFps;
902
- private unitTesting;
903
1335
  private gameStopRequested;
904
1336
  private webGlRendererInfo;
905
1337
  canvasCssWidth: number;
906
1338
  canvasCssHeight: number;
907
1339
  scenes: Scene[];
908
- private freeEntitiesScene;
1340
+ private freeNodesScene;
909
1341
  private incomingSceneTransitions;
910
1342
  private currentSceneSnapshot?;
911
1343
  private pendingScreenshot?;
912
1344
  /**
913
- * Adds an entity as a free entity (an entity that is not part of a scene)
1345
+ * Adds a node as a free node (a node that is not part of a scene)
914
1346
  * to the game.
915
1347
  *
916
- * @remarks Once added to the game, a free entity will always be drawn,
1348
+ * @remarks Once added to the game, a free node will always be drawn,
917
1349
  * and it will not be part of any scene transitions. This is useful if
918
- * an entity must persistently be drawn and not move with scene
919
- * transitions. The appearance of the free entity must be managed
920
- * by the programmer. Note: internally, the free entities are part of a
921
- * special scene (named "__freeEntitiesScene"), but this scene is handled
922
- * apart from regular scenes in order to achieve the free entity behavior.
1350
+ * a node must persistently be drawn and not move with scene
1351
+ * transitions. The appearance of the free node must be managed
1352
+ * by the programmer. Note: internally, the free nodes are part of a
1353
+ * special scene (named "__freeNodesScene"), but this scene is handled
1354
+ * apart from regular scenes in order to achieve the free node behavior.
923
1355
  *
924
- * @param entity - entity to add as a free entity
1356
+ * @param node - node to add as a free node
1357
+ */
1358
+ addFreeNode(node: M2Node): void;
1359
+ /**
1360
+ * @deprecated Use addFreeNode() instead
925
1361
  */
926
- addFreeEntity(entity: Entity): void;
1362
+ addFreeEntity(node: M2Node): void;
927
1363
  /**
928
- * Removes a free entity from the game.
1364
+ * Removes a free node from the game.
929
1365
  *
930
- * @remarks Throws exception if the entity to remove is not currently added
931
- * to the game as a free entity
1366
+ * @remarks Throws exception if the node to remove is not currently added
1367
+ * to the game as a free node
932
1368
  *
933
- * @param entity - the free entity to remove or its name as a string
1369
+ * @param node - the free node to remove or its name as a string
1370
+ */
1371
+ removeFreeNode(node: M2Node | string): void;
1372
+ /**
1373
+ * @deprecated Use removeFreeNode() instead
1374
+ */
1375
+ removeFreeEntity(node: M2Node | string): void;
1376
+ /**
1377
+ * Removes all free nodes from the game.
934
1378
  */
935
- removeFreeEntity(entity: Entity | string): void;
1379
+ removeAllFreeNodes(): void;
936
1380
  /**
937
- * Removes all free entities from the game.
1381
+ * @deprecated Use removeAllFreeNodes() instead
938
1382
  */
939
1383
  removeAllFreeEntities(): void;
940
1384
  /**
941
- * Returns array of free entities that have been added to the game.
1385
+ * Returns array of free nodes that have been added to the game.
942
1386
  *
943
- * @returns array of free entities
1387
+ * @returns array of free nodes
1388
+ */
1389
+ get freeNodes(): Array<M2Node>;
1390
+ /**
1391
+ * @deprecated Use Game.freeEntities instead
944
1392
  */
945
- get freeEntities(): Array<Entity>;
1393
+ get freeEntities(): Array<M2Node>;
946
1394
  /**
947
1395
  * Adds a scene to the game.
948
1396
  *
949
- * @remarks A scene, and its children entities, cannot be presented unless it has been added to the game object.
1397
+ * @remarks A scene, and its children nodes, cannot be presented unless it has been added to the game object.
950
1398
  *
951
1399
  * @param scene
952
1400
  */
@@ -983,7 +1431,7 @@ declare class Game implements Activity {
983
1431
  * is not found, then return fallback value
984
1432
  *
985
1433
  * @param parameterName - the name of the game parameter whose value is requested
986
- * @param fallback - the value to return if parameterName is not found
1434
+ * @param fallbackValue - the value to return if parameterName is not found
987
1435
  * @returns
988
1436
  */
989
1437
  getParameterOrFallback<T, U>(parameterName: string, fallbackValue: U): T | U;
@@ -1035,12 +1483,12 @@ declare class Game implements Activity {
1035
1483
  private warmupShadersWithPrimitives;
1036
1484
  /**
1037
1485
  * Warms up the Skia-based shaders underlying canvaskit by drawing
1038
- * m2c2kit entities.
1486
+ * m2c2kit nodes.
1039
1487
  *
1040
1488
  * @remarks While warmupShadersWithPrimitives draws a predefined set of
1041
1489
  * primitives, this function initializes and draws all canvaskit objects
1042
- * that have been defined as m2c2kit entities. This not only is another
1043
- * opportunity for shader warmup, it also does the entity initialization.
1490
+ * that have been defined as m2c2kit nodes. This not only is another
1491
+ * opportunity for shader warmup, it also does the node initialization.
1044
1492
  *
1045
1493
  * @param canvas - the canvaskit-canvas to draw on
1046
1494
  */
@@ -1049,8 +1497,8 @@ declare class Game implements Activity {
1049
1497
  /**
1050
1498
  * Frees up resources that were allocated to run the game.
1051
1499
  *
1052
- * @remarks This will be done automatically by the m2c2kit library;
1053
- * the end-user must not call this.
1500
+ * @remarks This will be done automatically by the m2c2kit library; the
1501
+ * end-user must not call this. FOR INTERNAL USE ONLY.
1054
1502
  */
1055
1503
  dispose(): void;
1056
1504
  private initData;
@@ -1095,683 +1543,226 @@ declare class Game implements Activity {
1095
1543
  * type: "string",
1096
1544
  * description: "ID of the participant",
1097
1545
  * &#125;
1098
- * &#125;);
1099
- * game.addStaticTrialData("participant_id", "12345");
1100
- *
1101
- * When Game.trialComplete() is called, the participant_id variable will
1102
- * be saved for the trial with the value "12345".
1103
- *
1104
- * @param variableName - variable to be set
1105
- * @param value - value of the variable to set
1106
- */
1107
- addStaticTrialData(variableName: string, value: JsonSchemaDataTypeScriptTypes): void;
1108
- /**
1109
- * Should be called when the current trial has completed. It will
1110
- * also increment the trial index.
1111
- *
1112
- * @remarks Calling will trigger the onActivityResults callback function,
1113
- * if one was provided in SessionOptions. This is how the game communicates
1114
- * trial data to the parent session, which can then save or process the data.
1115
- * It is the responsibility of the the game programmer to call this at
1116
- * the appropriate time. It is not triggered automatically.
1117
- */
1118
- trialComplete(): void;
1119
- /**
1120
- * The m2c2kit engine will automatically include these schema and their
1121
- * values in the trial data.
1122
- */
1123
- private readonly automaticTrialSchema;
1124
- private makeNewGameDataSchema;
1125
- private makeGameDataSchema;
1126
- /**
1127
- * GameParameters combines default parameters values and
1128
- * JSON Schema to describe what the parameters are.
1129
- * The next two functions extract GameParameters's two parts
1130
- * (the default values and the schema) so they can be returned
1131
- * separately in the activityData event
1132
- */
1133
- private makeGameActivityConfiguration;
1134
- private makeGameActivityConfigurationSchema;
1135
- /**
1136
- * Should be called when current game has ended successfully.
1137
- *
1138
- * @remarks This will send an ActivityEnd event to any listeners, such as
1139
- * a function provided to Game.onEnd() or a callback defined in
1140
- * SessionOptions.activityCallbacks.onActivityLifecycle. This is how the
1141
- * game can communicate changes in activity state to the parent session.
1142
- * It is the responsibility of the the game programmer to call this at the
1143
- * appropriate time. It is not triggered automatically.
1144
- */
1145
- end(): void;
1146
- /**
1147
- * Should be called when current game has been canceled by a user action.
1148
- *
1149
- * @remarks This will send an ActivityCancel event to any listeners, such as
1150
- * a function provided to Game.onCancel() or a callback defined in
1151
- * SessionOptions.activityCallbacks.onActivityLifecycle. This is how the
1152
- * game can communicate changes in activity state to the parent session.
1153
- * It is the responsibility of the the game programmer to call this at the
1154
- * appropriate time. It is not triggered automatically.
1155
- */
1156
- cancel(): void;
1157
- private setupHtmlCanvases;
1158
- private setupCanvasKitSurface;
1159
- private interceptWebGlCalls;
1160
- private setupFpsFont;
1161
- private setupCanvasDomEventHandlers;
1162
- private loop;
1163
- snapshots: Image[];
1164
- private updateGameTime;
1165
- private handleIncomingSceneTransitions;
1166
- /**
1167
- * Creates a scene that has a screen shot of the current scene.
1168
- *
1169
- * @param outgoingSceneImage - an image of the current scene
1170
- * @returns - the scene with the screen shot
1171
- */
1172
- private createOutgoingScene;
1173
- /**
1174
- * Executes a callback when the frame has finished simulating physics.
1175
- *
1176
- * @param callback - function to execute.
1177
- * @param options - options for the callback.
1178
- */
1179
- onFrameDidSimulatePhysics(callback: (frameCycleEvent: FrameCycleEvent) => void, options?: CallbackOptions): void;
1180
- private update;
1181
- private draw;
1182
- private calculateFps;
1183
- private takeCurrentSceneSnapshot;
1184
- private handlePendingScreenshot;
1185
- /**
1186
- * Takes screenshot of canvas
1187
- *
1188
- * @remarks Coordinates should be provided unscaled; that is, the method
1189
- * will handle any scaling that happened due to device pixel ratios
1190
- * not equal to 1. This returns a promise because the screenshot request
1191
- * must be queued and completed once a draw cycle has completed. See
1192
- * the loop() method.
1193
- *
1194
- * @param sx - Upper left coordinate of screenshot
1195
- * @param sy - Upper right coordinate of screenshot
1196
- * @param sw - width of area to screenshot
1197
- * @param sh - height of area to screenshot
1198
- * @returns Promise of Uint8Array of image data
1199
- */
1200
- takeScreenshot(sx?: number, sy?: number, sw?: number, sh?: number): Promise<Uint8Array | null>;
1201
- private animateSceneTransition;
1202
- private drawFps;
1203
- /**
1204
- * Creates an event listener for an entity based on the entity name
1205
- *
1206
- * @remarks Typically, event listeners will be created using a method specific to the event, such as onTapDown(). This alternative allows creation with entity name.
1207
- *
1208
- * @param type - the type of event to listen for, e.g., "tapDown"
1209
- * @param entityName - the entity name for which an event will be listened
1210
- * @param callback - the callback to be invoked when the event occurs
1211
- * @param callbackOptions
1212
- */
1213
- createEventListener(type: EventType, entityName: string, callback: (event: EntityEvent) => void, callbackOptions?: CallbackOptions): void;
1214
- /**
1215
- * Returns array of all entities that have been added to the game object.
1216
- */
1217
- get entities(): Array<Entity>;
1218
- /**
1219
- * Receives callback from DOM PointerDown event
1220
- *
1221
- * @param domPointerEvent - PointerEvent from the DOM
1222
- * @returns
1223
- */
1224
- private htmlCanvasPointerDownHandler;
1225
- private htmlCanvasPointerUpHandler;
1226
- private htmlCanvasPointerMoveHandler;
1227
- /**
1228
- * Adjusts dragging behavior when the pointer leaves the canvas
1229
- *
1230
- * @remarks This is necessary because the pointerup event is not fired when
1231
- * the pointer leaves the canvas. On desktop, this means that the user might
1232
- * lift the pointer outside the canvas, but the entity will still be dragged
1233
- * when the pointer is moved back into the canvas.
1234
- *
1235
- * @param domPointerEvent
1236
- * @returns
1237
- */
1238
- private htmlCanvasPointerLeaveHandler;
1239
- /**
1240
- * Determines if/how m2c2kit entities respond to the DOM PointerDown event
1241
- *
1242
- * @param entity - entity that might be affected by the DOM PointerDown event
1243
- * @param m2Event
1244
- * @param domPointerEvent
1245
- */
1246
- private processDomPointerDown;
1247
- private processDomPointerUp;
1248
- private processDomPointerMove;
1249
- private raiseM2PointerDownEvent;
1250
- private raiseTapDownEvent;
1251
- private raiseTapLeaveEvent;
1252
- private raiseM2PointerUpEvent;
1253
- private raiseTapUpEvent;
1254
- private raiseTapUpAny;
1255
- private raiseM2PointerMoveEvent;
1256
- private raiseM2PointerLeaveEvent;
1257
- private raiseM2DragStartEvent;
1258
- private raiseM2DragEvent;
1259
- private raiseM2DragEndEvent;
1260
- private calculatePointWithinEntityFromDomPointerEvent;
1261
- /**
1262
- * Executes a callback when the game starts.
1263
- *
1264
- * @param callback - function to execute.
1265
- * @param options - options for the callback.
1266
- */
1267
- onStart(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1268
- /**
1269
- * Executes a callback when the game is canceled.
1270
- *
1271
- * @param callback - function to execute.
1272
- * @param options - options for the callback.
1273
- */
1274
- onCancel(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1275
- /**
1276
- * Executes a callback when the game ends.
1277
- *
1278
- * @param callback - function to execute.
1279
- * @param options - options for the callback.
1280
- */
1281
- onEnd(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1282
- /**
1283
- * Executes a callback when the game generates data.
1284
- *
1285
- * @param callback - function to execute.
1286
- * @param options - options for the callback.
1287
- */
1288
- onData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
1289
- private addEventListener;
1290
- private raiseActivityEventOnListeners;
1291
- private raiseEventOnListeningEntities;
1292
- private sceneCanReceiveUserInteraction;
1293
- /**
1294
- *
1295
- * Checks if the given canvas point is within the entity's bounds.
1296
- *
1297
- * @param entity - entity to check bounds for
1298
- * @param x - x coordinate of the canvas point
1299
- * @param y - y coordinate of the canvas point
1300
- * @returns true if x, y point is within the entity's bounds
1301
- */
1302
- private IsCanvasPointWithinEntityBounds;
1303
- prependAssetsGameIdUrl(url: string): string;
1304
- }
1305
-
1306
- /**
1307
- * This class contains all the fonts for all the games in the activity.
1308
- * Fonts have been converted to canvaskit Typeface.
1309
- *
1310
- * @remarks fontName is how the user will refer to the font in the game.
1311
- * fontFamily is the name of the font as it was specified within the TTF file.
1312
- * We must retain the fontFamily name because we must provide fontFamily (not
1313
- * fontName!) to canvaskit when rendering paragraphs.
1314
- */
1315
- declare class GameTypefaces {
1316
- [gameUuid: string]: {
1317
- [fontName: string]: {
1318
- fontFamily: string;
1319
- typeface: Typeface;
1320
- isDefault: boolean;
1321
- };
1322
- };
1323
- }
1324
- /**
1325
- * Class for loading, preparing, and providing fonts to games.
1326
- *
1327
- * @remarks FOR INTERNAL USE ONLY
1328
- */
1329
- declare class FontManager {
1330
- canvasKit?: CanvasKit;
1331
- fontMgr?: FontMgr;
1332
- gameTypefaces: GameTypefaces;
1333
- fontData: Array<FontData>;
1334
- session: Session;
1335
- games?: Array<Game>;
1336
- constructor(session: Session);
1337
- /**
1338
- * Gets a typeface that was previously loaded for the specified game.
1339
- *
1340
- * @param gameUuid
1341
- * @param fontName
1342
- * @returns the requested Typeface
1343
- */
1344
- getTypeface(gameUuid: string, fontName: string): Typeface;
1345
- /**
1346
- * Gets names of fonts loaded for the specified game.
1347
- *
1348
- * @param gameUuid
1349
- * @returns array of font names
1350
- */
1351
- getFontNames(gameUuid: string): Array<string>;
1352
- /**
1353
- * Fetches all fonts games.
1354
- *
1355
- * @param games - array of games
1356
- * @returns
1357
- */
1358
- fetchFonts(games: Array<Game>): Promise<void[]>;
1359
- /**
1360
- * Takes the fonts, which have been previously fetched and converted into
1361
- * Array Buffers using FontManager.fetchFonts(), and makes them available
1362
- * to our engine by creating canvaskit Typefaces.
1363
- */
1364
- loadAllGamesFontData(): void;
1365
- }
1366
-
1367
- interface ActivityCallbacks {
1368
- /** Callback executed when the activity lifecycle changes, such as when it ends. */
1369
- onActivityLifecycle?: (event: ActivityLifecycleEvent) => void;
1370
- /** Callback executed when an activity creates some data. */
1371
- onActivityResults?: (event: ActivityResultsEvent) => void;
1372
- }
1373
-
1374
- /** Base interface for all Session events. */
1375
- interface SessionEvent extends EventBase {
1376
- target: Session;
1377
- }
1378
-
1379
- /**
1380
- * Notifies when a session starts, ends, or initializes.
1381
- */
1382
- interface SessionLifecycleEvent extends SessionEvent {
1383
- }
1384
-
1385
- interface SessionCallbacks {
1386
- /** Callback executed when the session lifecycle changes, such as when it is initialized. */
1387
- onSessionLifecycle?: (event: SessionLifecycleEvent) => void;
1388
- }
1389
-
1390
- interface SessionOptions {
1391
- /** The activities that compose this session */
1392
- activities: Array<Activity>;
1393
- /** Callbacks executed when activity events occurs, such as when activity creates data or ends */
1394
- activityCallbacks?: ActivityCallbacks;
1395
- /** Callbacks executed when session events occur */
1396
- sessionCallbacks?: SessionCallbacks;
1397
- /** Url of the canvaskit.wasm binary. Always set to the default value of "canvaskit.wasm" */
1398
- canvasKitWasmUrl: "canvaskit.wasm";
1399
- /** Use a specified session UUID, rather than create a new one */
1400
- sessionUuid?: string;
1401
- /** URL of session assets folder (which contains wasm binary), if not the default location of "assets" */
1402
- assetsUrl?: string;
1403
- /** Array of one or more optional databases that implement the IDataStore interface for persisting data. For store item operations, the first data store will be used. */
1404
- dataStores?: IDataStore[];
1405
- /** After the session initializes, should the session automatically start? Default is true */
1406
- autoStartAfterInit?: boolean;
1407
- /** When an activity ends or is canceled, should the session automatically go to the next activity? Default is true */
1408
- autoGoToNextActivity?: boolean;
1409
- /** After the last activity ends or is canceled, should the session automatically end? Default is true */
1410
- autoEndAfterLastActivity?: boolean;
1411
- /** NOT IMPLEMENTED YET: Orientation the screen should be locked to for this session. Value will be passed into the ScreenOrientation.lock() Web API. */
1412
- orientation?: "natural" | "landscape" | "portrait" | "portrait-primary" | "portrait-secondary" | "landscape-primary" | "landscape-secondary";
1413
- }
1414
-
1415
- declare class Session {
1416
- options: SessionOptions;
1417
- fontManager: FontManager;
1418
- imageManager: ImageManager;
1419
- currentActivity?: Activity;
1420
- uuid: string;
1421
- dataStores?: IDataStore[];
1422
- private eventListeners;
1423
- private sessionDictionary;
1424
- private canvasKit?;
1425
- private initialized;
1426
- private version;
1427
- /**
1428
- * A Session contains one or more activities. The session manages the start
1429
- * and stop of activities, and advancement to next activity
1430
- *
1431
- * @param options
1432
- */
1433
- constructor(options: SessionOptions);
1434
- /**
1435
- * Executes a callback when the session initializes.
1436
- *
1437
- * @param callback - function to execute.
1438
- * @param options - options for the callback.
1439
- */
1440
- onInitialize(callback: (sessionLifecycleEvent: SessionLifecycleEvent) => void, options?: CallbackOptions): void;
1441
- /**
1442
- * Executes a callback when the session starts.
1443
- *
1444
- * @param callback - function to execute.
1445
- * @param options - options for the callback.
1446
- */
1447
- onStart(callback: (sessionLifecycleEvent: SessionLifecycleEvent) => void, options?: CallbackOptions): void;
1448
- /**
1449
- * Executes a callback when the session ends.
1450
- *
1451
- * @param callback - function to execute.
1452
- * @param options - options for the callback.
1453
- */
1454
- onEnd(callback: (sessionLifecycleEvent: SessionLifecycleEvent) => void, options?: CallbackOptions): void;
1455
- /**
1456
- * Executes a callback when any activity in the session generates data.
1457
- *
1458
- * @param callback - function to execute.
1459
- * @param options - options for the callback.
1460
- */
1461
- onActivityData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
1462
- private addEventListener;
1463
- private raiseEventOnListeners;
1464
- private sessionActivityStartHandler;
1465
- private sessionActivityCancelHandler;
1466
- private sessionActivityEndHandler;
1467
- private sessionActivityLifecycleHandler;
1468
- private activityResultsEventHandler;
1469
- /**
1470
- * Asynchronously initializes the m2c2kit engine and loads assets
1471
- *
1472
- * @deprecated Use Session.initialize() instead.
1473
- */
1474
- init(): Promise<void>;
1475
- /**
1476
- * Check if the Activity uses the deprecated init() method.
1546
+ * &#125;);
1547
+ * game.addStaticTrialData("participant_id", "12345");
1477
1548
  *
1478
- * @remarks Activity.init() is deprecated and should be replaced with
1479
- * Activity.initialize().
1549
+ * When Game.trialComplete() is called, the participant_id variable will
1550
+ * be saved for the trial with the value "12345".
1480
1551
  *
1481
- * @param activity
1482
- * @returns true if the activity defines its own init() method, false otherwise.
1483
- */
1484
- private activityUsesDeprecatedInit;
1485
- /**
1486
- * Asynchronously initializes the m2c2kit engine and loads assets
1552
+ * @param variableName - variable to be set
1553
+ * @param value - value of the variable to set
1487
1554
  */
1488
- initialize(): Promise<void>;
1555
+ addStaticTrialData(variableName: string, value: JsonSchemaDataTypeScriptTypes): void;
1489
1556
  /**
1490
- * Waits for the session to be initialized.
1557
+ * Should be called when the current trial has completed. It will
1558
+ * also increment the trial index.
1491
1559
  *
1492
- * @remarks Session.initialize() is asynchronous, and it should be awaited
1493
- * so that the session is fully initialized before calling Session.start().
1494
- * If it is not awaited (or it cannot be awaited because the target
1495
- * environment does not support top-level await), this function ensures that
1496
- * the session has been initialized.
1560
+ * @remarks Calling will trigger the onActivityResults callback function,
1561
+ * if one was provided in SessionOptions. This is how the game communicates
1562
+ * trial data to the parent session, which can then save or process the data.
1563
+ * It is the responsibility of the the game programmer to call this at
1564
+ * the appropriate time. It is not triggered automatically.
1497
1565
  */
1498
- private waitForSessionInitialization;
1566
+ trialComplete(): void;
1499
1567
  /**
1500
- * Starts the session and starts the first activity.
1568
+ * The m2c2kit engine will automatically include these schema and their
1569
+ * values in the trial data.
1501
1570
  */
1502
- start(): Promise<void>;
1571
+ private readonly automaticTrialSchema;
1572
+ private makeNewGameDataSchema;
1573
+ private makeGameDataSchema;
1503
1574
  /**
1504
- * Declares the session ended and sends callback.
1575
+ * GameParameters combines default parameters values and
1576
+ * JSON Schema to describe what the parameters are.
1577
+ * The next two functions extract GameParameters's two parts
1578
+ * (the default values and the schema) so they can be returned
1579
+ * separately in the activityData event
1505
1580
  */
1506
- end(): void;
1507
- private stop;
1581
+ private makeGameActivityConfiguration;
1582
+ private makeGameActivityConfigurationSchema;
1508
1583
  /**
1509
- * Frees up resources that were allocated to run the session.
1584
+ * Should be called when current game has ended successfully.
1510
1585
  *
1511
- * @remarks This will be done automatically by the m2c2kit library;
1512
- * the end-user must not call this.
1586
+ * @remarks This will send an ActivityEnd event to any listeners, such as
1587
+ * a function provided to Game.onEnd() or a callback defined in
1588
+ * SessionOptions.activityCallbacks.onActivityLifecycle. This is how the
1589
+ * game can communicate changes in activity state to the parent session.
1590
+ * It is the responsibility of the the game programmer to call this at the
1591
+ * appropriate time. It is not triggered automatically.
1513
1592
  */
1514
- private dispose;
1593
+ end(): void;
1515
1594
  /**
1516
- * Stops the current activity and goes to the activity with the provided id.
1595
+ * Should be called when current game has been canceled by a user action.
1517
1596
  *
1518
- * @param options
1519
- */
1520
- goToActivity(options: GoToActivityOptions): Promise<void>;
1521
- /**
1522
- * Stops the current activity and advances to next activity in the session.
1523
- * If there is no activity after the current activity, throws error.
1597
+ * @remarks This will send an ActivityCancel event to any listeners, such as
1598
+ * a function provided to Game.onCancel() or a callback defined in
1599
+ * SessionOptions.activityCallbacks.onActivityLifecycle. This is how the
1600
+ * game can communicate changes in activity state to the parent session.
1601
+ * It is the responsibility of the the game programmer to call this at the
1602
+ * appropriate time. It is not triggered automatically.
1524
1603
  */
1525
- goToNextActivity(): Promise<void>;
1604
+ cancel(): void;
1605
+ private setupHtmlCanvases;
1606
+ private setupCanvasKitSurface;
1607
+ private interceptWebGlCalls;
1608
+ private setupFpsFont;
1609
+ private setupCanvasDomEventHandlers;
1610
+ private loop;
1611
+ snapshots: Image[];
1612
+ private updateGameTime;
1613
+ private handleIncomingSceneTransitions;
1526
1614
  /**
1527
- * Stops the current activity and advances to next activity in the session.
1528
- * If there is no activity after the current activity, throws error.
1615
+ * Creates a scene that has a screen shot of the current scene.
1529
1616
  *
1530
- * @deprecated Use goToNextActivity() instead.
1531
- */
1532
- advanceToNextActivity(): Promise<void>;
1533
- /**
1534
- * Gets the next activity after the current one, or undefined if
1535
- * this is the last activity.
1617
+ * @param outgoingSceneImage - an image of the current scene
1618
+ * @returns - the scene with the screen shot
1536
1619
  */
1537
- get nextActivity(): Activity | undefined;
1620
+ private createOutgoingScene;
1538
1621
  /**
1539
- * Saves an item to the session's key-value dictionary.
1622
+ * Registers a plugin with the game.
1540
1623
  *
1541
- * @remarks The session dictionary is not persisted. It is available only
1542
- * during the actively running session. It is useful for storing temporary
1543
- * data to coordinate between activities.
1624
+ * @remarks Upon registration, the plugin's optional asynchronous
1625
+ * `initialize()` method will be called.
1544
1626
  *
1545
- * @param key - item key
1546
- * @param value - item value
1627
+ * @param plugin - Plugin to register
1547
1628
  */
1548
- dictionarySetItem(key: string, value: SessionDictionaryValues): void;
1629
+ registerPlugin(plugin: Plugin): Promise<void>;
1630
+ private update;
1631
+ private draw;
1632
+ private calculateFps;
1633
+ private takeCurrentSceneSnapshot;
1634
+ private handlePendingScreenshot;
1549
1635
  /**
1550
- * Gets an item value from the session's key-value dictionary.
1636
+ * Takes screenshot of canvas
1551
1637
  *
1552
- * @remarks The session dictionary is not persisted. It is available only
1553
- * during the actively running session. It is useful for storing temporary
1554
- * data to coordinate between activities.
1638
+ * @remarks Coordinates should be provided unscaled; that is, the method
1639
+ * will handle any scaling that happened due to device pixel ratios
1640
+ * not equal to 1. This returns a promise because the screenshot request
1641
+ * must be queued and completed once a draw cycle has completed. See
1642
+ * the loop() method.
1555
1643
  *
1556
- * @param key - item key
1557
- * @returns value of the item
1644
+ * @param sx - Upper left coordinate of screenshot
1645
+ * @param sy - Upper right coordinate of screenshot
1646
+ * @param sw - width of area to screenshot
1647
+ * @param sh - height of area to screenshot
1648
+ * @returns Promise of Uint8Array of image data
1558
1649
  */
1559
- dictionaryGetItem<T extends SessionDictionaryValues>(key: string): T;
1650
+ takeScreenshot(sx?: number, sy?: number, sw?: number, sh?: number): Promise<Uint8Array | null>;
1651
+ private animateSceneTransition;
1652
+ private drawFps;
1560
1653
  /**
1561
- * Deletes an item value from the session's key-value dictionary.
1654
+ * Creates an event listener for a node based on the node name
1562
1655
  *
1563
- * @remarks The session dictionary is not persisted. It is available only
1564
- * during the actively running session. It is useful for storing temporary
1565
- * data to coordinate between activities.
1656
+ * @remarks Typically, event listeners will be created using a method specific to the event, such as onTapDown(). This alternative allows creation with node name.
1566
1657
  *
1567
- * @param key - item key
1568
- * @returns true if the item was deleted, false if it did not exist
1658
+ * @param type - the type of event to listen for, e.g., "tapDown"
1659
+ * @param nodeName - the node name for which an event will be listened
1660
+ * @param callback - the callback to be invoked when the event occurs
1661
+ * @param callbackOptions
1569
1662
  */
1570
- dictionaryDeleteItem(key: string): boolean;
1663
+ createEventListener(type: M2EventType, nodeName: string, callback: (event: M2NodeEvent) => void, callbackOptions?: CallbackOptions): void;
1571
1664
  /**
1572
- * Determines if a key exists in the activity's key-value dictionary.
1573
- *
1574
- * @remarks The session dictionary is not persisted. It is available only
1575
- * during the actively running session. It is useful for storing temporary
1576
- * data to coordinate between activities.
1577
- *
1578
- * @param key - item key
1579
- * @returns true if the key exists, false otherwise
1665
+ * Returns array of all nodes that have been added to the game object.
1580
1666
  */
1581
- dictionaryItemExists(key: string): boolean;
1667
+ get nodes(): Array<M2Node>;
1582
1668
  /**
1583
- * Gets asynchronous assets, including initialization of canvaskit wasm,
1584
- * fetching of fonts from specified urls, and rendering and fetching
1585
- * of images
1586
- * @returns
1669
+ * @deprecated use Game.nodes instead
1587
1670
  */
1588
- private getAsynchronousAssets;
1589
- private loadCanvasKit;
1590
- private loadAssets;
1591
- private assignCanvasKit;
1592
- private getImagesConfigurationFromGames;
1593
- prependAssetsUrl(url: string): string;
1594
- }
1595
- interface GoToActivityOptions {
1596
- /** ActivityId of the activity to go to. */
1597
- id: string;
1598
- }
1599
- /**
1600
- * Types of values that can be stored in the session dictionary.
1601
- */
1602
- type SessionDictionaryValues = string | number | boolean | object | null | undefined;
1603
-
1604
- interface Activity {
1605
- /** The type of activity: Game or Survey */
1606
- type: ActivityType;
1671
+ get entities(): Array<M2Node>;
1607
1672
  /**
1608
- * Initializes the activity.
1673
+ * Receives callback from DOM PointerDown event
1609
1674
  *
1610
- * @remarks All code to create the activity's appearance and behavior must
1611
- * be placed in this method. This method is asynchronous, and must be
1612
- * awaited. When writing a new game by extending the `Game` class, this
1613
- * method will be overridden, but the base method must still be called with
1614
- * `await super.initialize()`.
1675
+ * @param domPointerEvent - PointerEvent from the DOM
1676
+ * @returns
1615
1677
  */
1616
- initialize(): Promise<void>;
1678
+ private htmlCanvasPointerDownHandler;
1679
+ private htmlCanvasPointerUpHandler;
1680
+ private htmlCanvasPointerMoveHandler;
1681
+ private htmlCanvasPointerLeaveHandler;
1617
1682
  /**
1618
- * Initializes the activity.
1619
- *
1620
- * @remarks All code to create the activity's appearance and behavior must
1621
- * be placed in this method. This method is asynchronous, and must be
1622
- * awaited. When writing a new game by extending the `Game` class, this
1623
- * method will be overridden, but the base method must still be called with
1624
- * `await super.init()`.
1683
+ * Determines if/how m2c2kit nodes respond to the DOM PointerDown event
1625
1684
  *
1626
- * @deprecated use Game.initialize() instead.
1685
+ * @param node - node that might be affected by the DOM PointerDown event
1686
+ * @param nodeEvent
1687
+ * @param domPointerEvent
1627
1688
  */
1628
- init(): Promise<void>;
1629
- /** Starts the activity */
1630
- start(): Promise<void>;
1631
- /** Stops the activity */
1632
- stop(): void;
1689
+ private processDomPointerDown;
1690
+ private processDomPointerUp;
1691
+ private processDomPointerMove;
1692
+ private processDomPointerLeave;
1693
+ private raiseM2PointerDownEvent;
1694
+ private raiseTapDownEvent;
1695
+ private raiseTapLeaveEvent;
1696
+ private raiseM2PointerUpEvent;
1697
+ private raiseTapUpEvent;
1698
+ private raiseTapUpAny;
1699
+ private raiseM2PointerMoveEvent;
1700
+ private raiseM2PointerLeaveEvent;
1701
+ private raiseM2DragStartEvent;
1702
+ private raiseM2DragEvent;
1703
+ private raiseM2DragEndEvent;
1704
+ private raiseSceneEvent;
1705
+ private calculatePointWithinNodeFromDomPointerEvent;
1633
1706
  /**
1634
- * Executes a callback when the activity starts.
1707
+ * Executes a callback when the game starts.
1635
1708
  *
1636
1709
  * @param callback - function to execute.
1637
1710
  * @param options - options for the callback.
1638
1711
  */
1639
1712
  onStart(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1640
1713
  /**
1641
- * Executes a callback when the activity is canceled.
1714
+ * Executes a callback when the game is canceled.
1642
1715
  *
1643
1716
  * @param callback - function to execute.
1644
1717
  * @param options - options for the callback.
1645
1718
  */
1646
1719
  onCancel(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1647
1720
  /**
1648
- * Executes a callback when the activity ends.
1649
- *
1650
- * @param callback - function to execute.
1651
- * @param options - options for the callback.
1652
- */
1653
- onEnd(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1654
- /**
1655
- * Executes a callback when the activity generates data.
1721
+ * Executes a callback when the game ends.
1656
1722
  *
1657
1723
  * @param callback - function to execute.
1658
1724
  * @param options - options for the callback.
1659
1725
  */
1660
- onData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
1661
- /** The activity's parent session */
1662
- session: Session;
1663
- /** The activity's unique identifier. NOTE: This is newly generated each session. The uuid for an activity will vary across sessions. */
1664
- uuid: string;
1665
- /** Human-friendly name of this activity */
1666
- name: string;
1667
- /** Short identifier of this activity */
1668
- id: string;
1669
- /** The value of performance.now() immediately before the activity begins */
1670
- beginTimestamp: number;
1671
- /** The value of new Date().toISOString() immediately before the activity begins */
1672
- beginIso8601Timestamp: string;
1673
- /** Sets additional activity parameters if defaults are not sufficient. */
1674
- setParameters(additionalParameters: unknown): void;
1675
- /** Additional activity parameters that were set. */
1676
- readonly additionalParameters?: unknown;
1677
- /** Optional stores to use for saving data. The implementation of the store is not provided by the \@m2c2kit/core library. */
1678
- dataStores?: IDataStore[];
1679
- }
1680
-
1681
- /**
1682
- * Base interface for all m2c2kit events.
1683
- *
1684
- * @remarks I would have named it Event, but that would collide with
1685
- * the existing DOM Event
1686
- */
1687
- interface EventBase {
1688
- /** Type of event. */
1689
- type: EventType | string;
1690
- /** The object on which the event occurred. */
1691
- target: Entity | Session | Activity;
1692
- /** Has the event been taken care of by the listener and not be dispatched to other targets? */
1693
- handled?: boolean;
1694
- }
1695
- /**
1696
- * The different events that are dispatched by m2c2kit core.
1697
- */
1698
- declare const EventType: {
1699
- readonly SessionInitialize: "SessionInitialize";
1700
- readonly SessionStart: "SessionStart";
1701
- readonly SessionEnd: "SessionEnd";
1702
- readonly ActivityStart: "ActivityStart";
1703
- readonly ActivityEnd: "ActivityEnd";
1704
- readonly ActivityCancel: "ActivityCancel";
1705
- readonly ActivityData: "ActivityData";
1706
- readonly TapDown: "TapDown";
1707
- readonly TapUp: "TapUp";
1708
- readonly TapUpAny: "TapUpAny";
1709
- readonly TapLeave: "TapLeave";
1710
- readonly PointerDown: "PointerDown";
1711
- readonly PointerUp: "PointerUp";
1712
- readonly PointerMove: "PointerMove";
1713
- readonly PointerLeave: "PointerLeave";
1714
- readonly Drag: "Drag";
1715
- readonly DragStart: "DragStart";
1716
- readonly DragEnd: "DragEnd";
1717
- readonly CompositeCustom: "CompositeCustom";
1718
- readonly FrameDidSimulatePhysics: "FrameDidSimulatePhysics";
1719
- };
1720
- type EventType = (typeof EventType)[keyof typeof EventType];
1721
-
1722
- interface EntityEventListener {
1723
- type: EventType | string;
1724
- /** For composites that raise events, type of the composite custom event. */
1725
- compositeType?: string;
1726
- entityUuid: string;
1727
- callback: (event: EntityEvent) => void;
1728
- }
1729
-
1730
- /**
1731
- * Describes an interaction between the pointer (mouse, touches) and an entity.
1732
- *
1733
- * @remarks I would have named it PointerEvent, but that would collide with
1734
- * the existing DOM PointerEvent.
1735
- */
1736
- interface M2PointerEvent extends EntityEvent {
1737
- /** Point that was tapped on entity, relative to the entity coordinate system */
1738
- point: Point;
1739
- /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
1740
- buttons: number;
1741
- }
1742
-
1743
- /**
1744
- * Describes an interaction of a pointer (mouse, touches) pressing an entity.
1745
- *
1746
- * @remarks Unlike M2PointerEvent, TapEvent considers how the pointer, while
1747
- * in the down state, moves in relation to the bounds of the entity.
1748
- */
1749
- interface TapEvent extends EntityEvent {
1750
- /** Point that was tapped on entity, relative to the entity coordinate system */
1751
- point: Point;
1752
- /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
1753
- buttons: number;
1754
- }
1755
-
1756
- interface TextOptions {
1757
- /** Text to be displayed */
1758
- text?: string;
1759
- /** Name of font to use for text. Must have been previously loaded */
1760
- fontName?: string;
1761
- /** Color of text. Default is Constants.DEFAULT_FONT_COLOR (WebColors.Black) */
1762
- fontColor?: RgbaColor;
1763
- /** Size of text. Default is Constants.DEFAULT_FONT_SIZE (16) */
1764
- fontSize?: number;
1765
- }
1766
-
1767
- /**
1768
- * Width and height on two-dimensional space
1769
- */
1770
- interface Size {
1771
- /** Horizontal width, x-axis */
1772
- width: number;
1773
- /** Vertical height, y-axis */
1774
- height: number;
1726
+ onEnd(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1727
+ /**
1728
+ * Executes a callback when the game generates data.
1729
+ *
1730
+ * @param callback - function to execute.
1731
+ * @param options - options for the callback.
1732
+ */
1733
+ onData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
1734
+ /**
1735
+ * Executes a callback when the game begins its warmup.
1736
+ *
1737
+ * @internal For m2c2kit library use only
1738
+ *
1739
+ * @param callback - function to execute.
1740
+ * @param options - options for the callback.
1741
+ */
1742
+ onWarmupStart(callback: (gameEvent: GameEvent) => void, options?: CallbackOptions): void;
1743
+ /**
1744
+ * Executes a callback when the game ends its warmup.
1745
+ *
1746
+ * @internal For m2c2kit library use only
1747
+ *
1748
+ * @param callback - function to execute.
1749
+ * @param options - options for the callback.
1750
+ */
1751
+ onWarmupEnd(callback: (activityEvent: ActivityEvent) => void, options?: CallbackOptions): void;
1752
+ private addEventListener;
1753
+ private raiseActivityEventOnListeners;
1754
+ private raiseEventOnListeningNodes;
1755
+ private sceneCanReceiveUserInteraction;
1756
+ /**
1757
+ *
1758
+ * Checks if the given canvas point is within the node's bounds.
1759
+ *
1760
+ * @param node - node to check bounds for
1761
+ * @param x - x coordinate of the canvas point
1762
+ * @param y - y coordinate of the canvas point
1763
+ * @returns true if x, y point is within the node's bounds
1764
+ */
1765
+ private IsCanvasPointWithinNodeBounds;
1775
1766
  }
1776
1767
 
1777
1768
  /**
@@ -1780,31 +1771,31 @@ interface Size {
1780
1771
  * @remarks I would have named it DragEvent, but that would collide with
1781
1772
  * the existing DOM DragEvent.
1782
1773
  */
1783
- interface M2DragEvent extends EntityEvent {
1784
- /** Position of the entity at the time of the M2DragEvent, relative to the parent entity coordinate system. */
1774
+ interface M2DragEvent extends M2NodeEvent {
1775
+ /** Position of the node at the time of the M2DragEvent, relative to the parent node coordinate system. */
1785
1776
  position: Point;
1786
1777
  /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons. */
1787
1778
  buttons: number;
1788
1779
  }
1789
1780
 
1790
- declare function handleInterfaceOptions(entity: Entity, options: EntityOptions): void;
1791
- declare abstract class Entity implements EntityOptions {
1792
- type: EntityType;
1781
+ declare function handleInterfaceOptions(node: M2Node, options: M2NodeOptions): void;
1782
+ declare abstract class M2Node implements M2NodeOptions {
1783
+ type: M2NodeType;
1793
1784
  isDrawable: boolean;
1794
1785
  isShape: boolean;
1795
1786
  isText: boolean;
1796
1787
  name: string;
1797
- position: Point;
1798
- scale: number;
1788
+ _position: Point;
1789
+ _scale: number;
1799
1790
  alpha: number;
1800
- zRotation: number;
1791
+ _zRotation: number;
1801
1792
  isUserInteractionEnabled: boolean;
1802
1793
  draggable: boolean;
1803
1794
  hidden: boolean;
1804
1795
  layout: Layout;
1805
1796
  _game?: Game;
1806
- parent?: Entity;
1807
- children: Entity[];
1797
+ parent?: M2Node;
1798
+ children: M2Node[];
1808
1799
  absolutePosition: Point;
1809
1800
  size: Size;
1810
1801
  absoluteScale: number;
@@ -1813,100 +1804,100 @@ declare abstract class Entity implements EntityOptions {
1813
1804
  actions: Action[];
1814
1805
  queuedAction?: Action;
1815
1806
  originalActions: Action[];
1816
- eventListeners: EntityEventListener[];
1807
+ eventListeners: M2NodeEventListener<M2NodeEvent>[];
1817
1808
  readonly uuid: string;
1818
1809
  needsInitialization: boolean;
1819
1810
  userData: any;
1820
1811
  loopMessages: Set<string>;
1821
- /** Is the entity in a pressed state? E.g., did the user put the pointer
1822
- * down on the entity and not yet release it? */
1812
+ /** Is the node in a pressed state? E.g., did the user put the pointer
1813
+ * down on the node and not yet release it? */
1823
1814
  pressed: boolean;
1824
1815
  withinHitArea: boolean;
1825
- /** Is the entity in a pressed state AND is the pointer within the entity's
1826
- * hit area? For example, a user may put the pointer down on the entity, but
1827
- * then move the pointer, while still down, beyond the entity's hit area. In
1816
+ /** Is the node in a pressed state AND is the pointer within the node's
1817
+ * hit area? For example, a user may put the pointer down on the node, but
1818
+ * then move the pointer, while still down, beyond the node's hit area. In
1828
1819
  * this case, pressed = true, but pressedAndWithinHitArea = false. */
1829
1820
  pressedAndWithinHitArea: boolean;
1830
- /** When the entity initially enters the pressed state, what is the pointer
1821
+ /** When the node initially enters the pressed state, what is the pointer
1831
1822
  * offset? (offset from the canvas's origin to the pointer position). We
1832
1823
  * save this because it will be needed if this press then led to a drag. */
1833
1824
  pressedInitialPointerOffset: Point;
1834
- /** What was the previous pointer offset when the entity was in a dragging
1825
+ /** What was the previous pointer offset when the node was in a dragging
1835
1826
  * state? */
1836
1827
  draggingLastPointerOffset: Point;
1837
- /** Is the entity in a dragging state? */
1828
+ /** Is the node in a dragging state? */
1838
1829
  dragging: boolean;
1839
- constructor(options?: EntityOptions);
1830
+ constructor(options?: M2NodeOptions);
1840
1831
  initialize(): void;
1841
1832
  /**
1842
- * The game which this entity is a part of.
1833
+ * The game which this node is a part of.
1843
1834
  *
1844
- * @remarks Throws error if entity is not part of the game object.
1835
+ * @remarks Throws error if node is not part of the game object.
1845
1836
  */
1846
1837
  get game(): Game;
1847
1838
  /**
1848
- * Determines if the entity has been added to the game object.
1839
+ * Determines if the node has been added to the game object.
1849
1840
  *
1850
- * @returns true if entity has been added
1841
+ * @returns true if node has been added
1851
1842
  */
1852
1843
  private isPartOfGame;
1853
1844
  /**
1854
- * Overrides toString() and returns a human-friendly description of the entity.
1845
+ * Overrides toString() and returns a human-friendly description of the node.
1855
1846
  *
1856
1847
  * @remarks Inspiration from https://stackoverflow.com/a/35361695
1857
1848
  */
1858
1849
  toString: () => string;
1859
1850
  /**
1860
- * Adds a child to this parent entity. Throws exception if the child's name
1851
+ * Adds a child to this parent node. Throws exception if the child's name
1861
1852
  * is not unique with respect to other children of this parent, or if the
1862
1853
  * child has already been added to another parent.
1863
1854
  *
1864
- * @param child - The child entity to add
1855
+ * @param child - The child node to add
1865
1856
  */
1866
- addChild(child: Entity): void;
1857
+ addChild(child: M2Node): void;
1867
1858
  /**
1868
- * Removes all children from the entity.
1859
+ * Removes all children from the node.
1869
1860
  */
1870
1861
  removeAllChildren(): void;
1871
1862
  /**
1872
- * Removes the specific child from this parent entity. Throws exception if
1863
+ * Removes the specific child from this parent node. Throws exception if
1873
1864
  * this parent does not contain the child.
1874
1865
  *
1875
1866
  * @param child
1876
1867
  */
1877
- removeChild(child: Entity): void;
1868
+ removeChild(child: M2Node): void;
1878
1869
  /**
1879
1870
  * Removes the children from the parent. Throws error if the parent does not
1880
1871
  * contain all of the children.
1881
1872
  *
1882
- * @param children - An array of children to remove from the parent entity
1873
+ * @param children - An array of children to remove from the parent node
1883
1874
  */
1884
- removeChildren(children: Array<Entity>): void;
1875
+ removeChildren(children: Array<M2Node>): void;
1885
1876
  /**
1886
- * Searches all descendants by name and returns first matching entity.
1877
+ * Searches all descendants by name and returns first matching node.
1887
1878
  *
1888
1879
  * @remarks Descendants are children and children of children, recursively.
1889
1880
  * Throws exception if no descendant with the given name is found.
1890
1881
  *
1891
- * @param name - Name of the descendant entity to return
1882
+ * @param name - Name of the descendant node to return
1892
1883
  * @returns
1893
1884
  */
1894
- descendant<T extends Entity>(name: string): T;
1885
+ descendant<T extends M2Node>(name: string): T;
1895
1886
  /**
1896
- * Returns all descendant entities.
1887
+ * Returns all descendant nodes.
1897
1888
  *
1898
1889
  * @remarks Descendants are children and children of children, recursively.
1899
1890
  */
1900
- get descendants(): Array<Entity>;
1891
+ get descendants(): Array<M2Node>;
1901
1892
  /**
1902
- * Returns all ancestor entities, not including the entity itself.
1893
+ * Returns all ancestor nodes, not including the node itself.
1903
1894
  */
1904
- get ancestors(): Array<Entity>;
1895
+ get ancestors(): Array<M2Node>;
1905
1896
  /**
1906
- * Determines if this entity or ancestor is part of an active action that
1897
+ * Determines if this node or ancestor is part of an active action that
1907
1898
  * affects it appearance.
1908
1899
  *
1909
- * @remarks This is used to determine if the entity should be rendered with
1900
+ * @remarks This is used to determine if the node should be rendered with
1910
1901
  * anti-aliasing or not. Anti-aliasing on some devices causes a new shader
1911
1902
  * to be compiled during the action, which causes jank.
1912
1903
  *
@@ -1914,17 +1905,17 @@ declare abstract class Entity implements EntityOptions {
1914
1905
  */
1915
1906
  involvedInActionAffectingAppearance(): boolean;
1916
1907
  /**
1917
- * Determines if the entity is a transitioning Scene or a descendant of a
1908
+ * Determines if the node is a transitioning Scene or a descendant of a
1918
1909
  * transitioning Scene.
1919
1910
  *
1920
1911
  * @returns true if transitioning
1921
1912
  */
1922
1913
  involvedInSceneTransition(): boolean;
1923
1914
  /**
1924
- * Executes a callback when the user presses down on the entity.
1915
+ * Executes a callback when the user presses down on the node.
1925
1916
  *
1926
1917
  * @remarks TapDown is a pointer down (mouse click or touches begin) within
1927
- * the bounds of the entity.
1918
+ * the bounds of the node.
1928
1919
  *
1929
1920
  * @param callback - function to execute
1930
1921
  * @param options - {@link CallbackOptions}
@@ -1932,23 +1923,23 @@ declare abstract class Entity implements EntityOptions {
1932
1923
  onTapDown(callback: (tapEvent: TapEvent) => void, options?: CallbackOptions): void;
1933
1924
  /**
1934
1925
  * Executes a callback when the user releases a press, that has been fully
1935
- * within the entity, from the entity.
1926
+ * within the node, from the node.
1936
1927
  *
1937
1928
  * @remarks TapUp is a pointer up (mouse click release or touches end) within
1938
- * the bounds of the entity and the pointer, while down, has never moved
1939
- * beyond the bounds of the entity.
1929
+ * the bounds of the node and the pointer, while down, has never moved
1930
+ * beyond the bounds of the node.
1940
1931
  *
1941
1932
  * @param callback - function to execute
1942
1933
  * @param options - {@link CallbackOptions}ue.
1943
1934
  */
1944
1935
  onTapUp(callback: (tapEvent: TapEvent) => void, options?: CallbackOptions): void;
1945
1936
  /**
1946
- * Executes a callback when the user releases a press from the entity within
1947
- * the bounds of the entity.
1937
+ * Executes a callback when the user releases a press from the node within
1938
+ * the bounds of the node.
1948
1939
  *
1949
1940
  * @remarks TapUpAny is a pointer up (mouse click release or touches end)
1950
- * within the bounds of the entity and the pointer, while down, is allowed to
1951
- * have been beyond the bounds of the entity during the press before the
1941
+ * within the bounds of the node and the pointer, while down, is allowed to
1942
+ * have been beyond the bounds of the node during the press before the
1952
1943
  * release.
1953
1944
  *
1954
1945
  * @param callback - function to execute
@@ -1957,10 +1948,10 @@ declare abstract class Entity implements EntityOptions {
1957
1948
  onTapUpAny(callback: (tapEvent: TapEvent) => void, options?: CallbackOptions): void;
1958
1949
  /**
1959
1950
  * Executes a callback when the user moves the pointer (mouse, touches) beyond
1960
- * the bounds of the entity while the pointer is down.
1951
+ * the bounds of the node while the pointer is down.
1961
1952
  *
1962
1953
  * @remarks TapLeave occurs when the pointer (mouse, touches) that has
1963
- * previously pressed the entity moves beyond the bounds of the entity
1954
+ * previously pressed the node moves beyond the bounds of the node
1964
1955
  * before the press release.
1965
1956
  *
1966
1957
  * @param callback - function to execute
@@ -1968,22 +1959,22 @@ declare abstract class Entity implements EntityOptions {
1968
1959
  */
1969
1960
  onTapLeave(callback: (tapEvent: TapEvent) => void, options?: CallbackOptions): void;
1970
1961
  /**
1971
- * Executes a callback when the pointer first is down on the entity.
1962
+ * Executes a callback when the pointer first is down on the node.
1972
1963
  *
1973
1964
  * @remarks PointerDown is a pointer down (mouse click or touches begin) within
1974
- * the bounds of the entity. It occurs under the same conditions as TapDown.
1965
+ * the bounds of the node. It occurs under the same conditions as TapDown.
1975
1966
  *
1976
1967
  * @param callback - function to execute
1977
1968
  * @param options - {@link CallbackOptions}
1978
1969
  */
1979
1970
  onPointerDown(callback: (m2PointerEvent: M2PointerEvent) => void, options?: CallbackOptions): void;
1980
1971
  /**
1981
- * Executes a callback when the user releases a press from the entity within
1982
- * the bounds of the entity.
1972
+ * Executes a callback when the user releases a press from the node within
1973
+ * the bounds of the node.
1983
1974
  *
1984
1975
  * @remarks PointerUp is a pointer up (mouse click release or touches end)
1985
- * within the bounds of the entity. It does not require that there was a
1986
- * previous PointerDown on the entity.
1976
+ * within the bounds of the node. It does not require that there was a
1977
+ * previous PointerDown on the node.
1987
1978
  *
1988
1979
  * @param callback - function to execute
1989
1980
  * @param options - {@link CallbackOptions}
@@ -1991,7 +1982,7 @@ declare abstract class Entity implements EntityOptions {
1991
1982
  onPointerUp(callback: (m2PointerEvent: M2PointerEvent) => void, options?: CallbackOptions): void;
1992
1983
  /**
1993
1984
  * Executes a callback when the user moves the pointer (mouse or touches)
1994
- * within the bounds of the entity.
1985
+ * within the bounds of the node.
1995
1986
  *
1996
1987
  * @param callback - function to execute
1997
1988
  * @param options - {@link CallbackOptions}
@@ -1999,62 +1990,62 @@ declare abstract class Entity implements EntityOptions {
1999
1990
  onPointerMove(callback: (m2PointerEvent: M2PointerEvent) => void, options?: CallbackOptions): void;
2000
1991
  /**
2001
1992
  * Executes a callback when the user moves the pointer (mouse or touches)
2002
- * outside the bounds of the entity.
1993
+ * outside the bounds of the node.
2003
1994
  *
2004
1995
  * @param callback - function to execute
2005
1996
  * @param options - {@link CallbackOptions}
2006
1997
  */
2007
1998
  onPointerLeave(callback: (m2PointerEvent: M2PointerEvent) => void, options?: CallbackOptions): void;
2008
1999
  /**
2009
- * Executes a callback when the user begins dragging an entity.
2000
+ * Executes a callback when the user begins dragging a node.
2010
2001
  *
2011
2002
  * @param callback - function to execute
2012
2003
  * @param options - {@link CallbackOptions}
2013
2004
  */
2014
2005
  onDragStart(callback: (m2DragEvent: M2DragEvent) => void, options?: CallbackOptions): void;
2015
2006
  /**
2016
- * Executes a callback when the user continues dragging an entity.
2007
+ * Executes a callback when the user continues dragging a node.
2017
2008
  *
2018
2009
  * @param callback - function to execute
2019
2010
  * @param options - {@link CallbackOptions}
2020
2011
  */
2021
2012
  onDrag(callback: (m2DragEvent: M2DragEvent) => void, options?: CallbackOptions): void;
2022
2013
  /**
2023
- * Executes a callback when the user stop dragging an entity.
2014
+ * Executes a callback when the user stop dragging a node.
2024
2015
  *
2025
2016
  * @param callback - function to execute
2026
2017
  * @param options - {@link CallbackOptions}
2027
2018
  */
2028
2019
  onDragEnd(callback: (m2DragEvent: M2DragEvent) => void, options?: CallbackOptions): void;
2029
- addEventListener(type: EventType | string, callback: (ev: EntityEvent) => void, callbackOptions?: CallbackOptions): void;
2020
+ addEventListener<T extends M2NodeEvent>(type: M2EventType | string, callback: (ev: T) => void, callbackOptions?: CallbackOptions): void;
2030
2021
  private parseLayoutConstraints;
2031
2022
  private calculateYFromConstraint;
2032
2023
  private calculateXFromConstraint;
2033
2024
  /**
2034
- * Calculates the absolute alpha of the entity, taking into account the
2035
- * alpha of all ancestor parent entities.
2025
+ * Calculates the absolute alpha of the node, taking into account the
2026
+ * alpha of all ancestor parent nodes.
2036
2027
  *
2037
2028
  * @remarks Alpha has multiplicative inheritance from all ancestors.
2038
2029
  *
2039
- * @param alpha - Opacity of the entity
2040
- * @param ancestors - Array of ancestor parent entities
2030
+ * @param alpha - Opacity of the node
2031
+ * @param ancestors - Array of ancestor parent nodes
2041
2032
  * @returns
2042
2033
  */
2043
2034
  private calculateAbsoluteAlpha;
2044
2035
  update(): void;
2045
2036
  /**
2046
- * Draws each child entity that is Drawable and is not hidden, by zPosition
2037
+ * Draws each child node that is Drawable and is not hidden, by zPosition
2047
2038
  * order (highest zPosition on top).
2048
2039
  *
2049
2040
  * @param canvas - CanvasKit canvas
2050
2041
  */
2051
2042
  drawChildren(canvas: Canvas): void;
2052
2043
  /**
2053
- * Runs an action on this entity.
2044
+ * Runs an action on this node.
2054
2045
  *
2055
- * @remarks If the entity is part of an active scene, the action runs
2056
- * immediately. Otherwise, the action will run when the entity's scene
2057
- * becomes active. Calling run() multiple times on an entity will add
2046
+ * @remarks If the node is part of an active scene, the action runs
2047
+ * immediately. Otherwise, the action will run when the node's scene
2048
+ * becomes active. Calling run() multiple times on a node will add
2058
2049
  * to existing actions, not replace them.
2059
2050
  *
2060
2051
  * @param action - The action to run
@@ -2063,38 +2054,44 @@ declare abstract class Entity implements EntityOptions {
2063
2054
  */
2064
2055
  run(action: Action, key?: string): void;
2065
2056
  /**
2066
- * Remove an action from this entity. If the action is running, it will be
2057
+ * Remove an action from this node. If the action is running, it will be
2067
2058
  * stopped.
2068
2059
  *
2069
2060
  * @param key - key (string identifier) of the action to remove
2070
2061
  */
2071
2062
  removeAction(key: string): void;
2072
2063
  /**
2073
- * Remove all actions from this entity. If actions are running, they will be
2064
+ * Remove all actions from this node. If actions are running, they will be
2074
2065
  * stopped.
2075
2066
  */
2076
2067
  removeAllActions(): void;
2077
2068
  /**
2078
- * Duplicates an entity using deep copy.
2069
+ * Duplicates a node using deep copy.
2079
2070
  *
2080
- * @remarks This is a deep recursive clone (entity and children).
2081
- * The uuid property of all duplicated entities will be newly created,
2071
+ * @remarks This is a deep recursive clone (node and children).
2072
+ * The uuid property of all duplicated nodes will be newly created,
2082
2073
  * because uuid must be unique.
2083
2074
  *
2084
- * @param newName - optional name of the new, duplicated entity. If not
2075
+ * @param newName - optional name of the new, duplicated node. If not
2085
2076
  * provided, name will be the new uuid
2086
2077
  */
2087
- abstract duplicate(newName?: string): Entity;
2088
- protected getEntityOptions(): EntityOptions;
2078
+ abstract duplicate(newName?: string): M2Node;
2079
+ protected getNodeOptions(): M2NodeOptions;
2089
2080
  protected getDrawableOptions(): DrawableOptions;
2090
2081
  protected getTextOptions(): TextOptions;
2091
2082
  /**
2092
- * Gets the scene that contains this entity by searching up the ancestor tree recursively. Throws exception if entity is not part of a scene.
2083
+ * Gets the scene that contains this node by searching up the ancestor tree recursively. Throws exception if node is not part of a scene.
2093
2084
  *
2094
- * @returns Scene that contains this entity
2085
+ * @returns Scene that contains this node
2095
2086
  */
2096
2087
  get canvasKit(): CanvasKit;
2097
- get parentSceneAsEntity(): Entity;
2088
+ get parentSceneAsNode(): M2Node;
2089
+ get position(): Point;
2090
+ set position(position: Point);
2091
+ get zRotation(): number;
2092
+ set zRotation(zRotation: number);
2093
+ get scale(): number;
2094
+ set scale(scale: number);
2098
2095
  /**
2099
2096
  * For a given directed acyclic graph, topological ordering of the vertices will be identified using BFS
2100
2097
  * @param adjList Adjacency List that represent a graph with vertices and edges
@@ -2103,7 +2100,7 @@ declare abstract class Entity implements EntityOptions {
2103
2100
  }
2104
2101
 
2105
2102
  interface MoveActionOptions {
2106
- /** Destination point. The point is relative to the entity's parent coordinate system */
2103
+ /** Destination point. The point is relative to the node's parent coordinate system */
2107
2104
  point: Point;
2108
2105
  /** Duration of move, in milliseconds */
2109
2106
  duration: number;
@@ -2137,7 +2134,7 @@ interface ScaleActionOptions {
2137
2134
  }
2138
2135
 
2139
2136
  interface FadeAlphaActionOptions {
2140
- /** Opacity of the entity. 0 is fully transparent, 1 is fully opaque. */
2137
+ /** Opacity of the node. 0 is fully transparent, 1 is fully opaque. */
2141
2138
  alpha: number;
2142
2139
  /** Duration of scale, in milliseconds */
2143
2140
  duration: number;
@@ -2146,9 +2143,9 @@ interface FadeAlphaActionOptions {
2146
2143
  }
2147
2144
 
2148
2145
  interface RotateActionOptions {
2149
- /** Relative amount to rotate the entity, in counter-clockwise radians */
2146
+ /** Relative amount to rotate the node, in counter-clockwise radians */
2150
2147
  byAngle?: number;
2151
- /** Absolute angle to which rotate the entity, in counter-clockwise radians */
2148
+ /** Absolute angle to which rotate the node, in counter-clockwise radians */
2152
2149
  toAngle?: number;
2153
2150
  /** If `toAngle` is provided, should the rotation be performed in the direction that leads to the smallest rotation? Default is true */
2154
2151
  shortestUnitArc?: boolean;
@@ -2176,7 +2173,7 @@ declare enum ActionType {
2176
2173
 
2177
2174
  /**
2178
2175
  * The Action class has static methods for creating actions to be executed by
2179
- * an Entity.
2176
+ * an M2Node.
2180
2177
  */
2181
2178
  declare abstract class Action {
2182
2179
  abstract type: ActionType;
@@ -2194,7 +2191,7 @@ declare abstract class Action {
2194
2191
  key?: string;
2195
2192
  constructor(runDuringTransition?: boolean);
2196
2193
  /**
2197
- * Creates an action that will move an entity to a point on the screen.
2194
+ * Creates an action that will move a node to a point on the screen.
2198
2195
  *
2199
2196
  * @param options - {@link MoveActionOptions}
2200
2197
  * @returns The move action
@@ -2215,27 +2212,27 @@ declare abstract class Action {
2215
2212
  */
2216
2213
  static custom(options: CustomActionOptions): Action;
2217
2214
  /**
2218
- * Creates an action that will scale the entity's size.
2215
+ * Creates an action that will scale the node's size.
2219
2216
  *
2220
- * @remarks Scaling is relative to any inherited scaling, which is multiplicative. For example, if the entity's parent is scaled to 2.0 and this entity's action scales to 3.0, then the entity will appear 6 times as large as original.
2217
+ * @remarks Scaling is relative to any inherited scaling, which is multiplicative. For example, if the node's parent is scaled to 2.0 and this node's action scales to 3.0, then the node will appear 6 times as large as original.
2221
2218
  *
2222
2219
  * @param options - {@link ScaleActionOptions}
2223
2220
  * @returns The scale action
2224
2221
  */
2225
2222
  static scale(options: ScaleActionOptions): Action;
2226
2223
  /**
2227
- * Creates an action that will change the entity's alpha (opacity).
2224
+ * Creates an action that will change the node's alpha (opacity).
2228
2225
  *
2229
- * @remarks Alpha has multiplicative inheritance. For example, if the entity's parent is alpha .5 and this entity's action fades alpha to .4, then the entity will appear with alpha .2.
2226
+ * @remarks Alpha has multiplicative inheritance. For example, if the node's parent is alpha .5 and this node's action fades alpha to .4, then the node will appear with alpha .2.
2230
2227
  *
2231
2228
  * @param options - {@link FadeAlphaActionOptions}
2232
2229
  * @returns The fadeAlpha action
2233
2230
  */
2234
2231
  static fadeAlpha(options: FadeAlphaActionOptions): Action;
2235
2232
  /**
2236
- * Creates an action that will rotate the entity.
2233
+ * Creates an action that will rotate the node.
2237
2234
  *
2238
- * @remarks Rotate actions are applied to their children. In addition to this entity's rotate action, all ancestors' rotate actions will also be applied.
2235
+ * @remarks Rotate actions are applied to their children. In addition to this node's rotate action, all ancestors' rotate actions will also be applied.
2239
2236
  *
2240
2237
  * @param options - {@link RotateActionOptions}
2241
2238
  * @returns The rotate action
@@ -2259,9 +2256,9 @@ declare abstract class Action {
2259
2256
  * @returns
2260
2257
  */
2261
2258
  static group(actions: Array<Action>): Action;
2262
- initialize(entity: Entity, key?: string): Array<Action>;
2259
+ initialize(node: M2Node, key?: string): Array<Action>;
2263
2260
  static cloneAction(action: Action, key?: string): Action;
2264
- static evaluateAction(action: Action, entity: Entity, now: number, dt: number): void;
2261
+ static evaluateAction(action: Action, node: M2Node, now: number, dt: number): void;
2265
2262
  /**
2266
2263
  * Calculates the duration of an action, including any children actions
2267
2264
  * the action may contain.
@@ -2357,6 +2354,18 @@ declare class RotateAction extends Action {
2357
2354
  constructor(byAngle: number | undefined, toAngle: number | undefined, shortestUnitArc: boolean | undefined, duration: number, runDuringTransition?: boolean);
2358
2355
  }
2359
2356
 
2357
+ interface ActivityCallbacks {
2358
+ /** Callback executed when the activity lifecycle changes, such as when it ends. */
2359
+ onActivityLifecycle?: (event: ActivityLifecycleEvent) => void;
2360
+ /** Callback executed when an activity creates some data. */
2361
+ onActivityResults?: (event: ActivityResultsEvent) => void;
2362
+ }
2363
+
2364
+ interface ActivityEventListener<ActivityEvent> extends M2EventListener<ActivityEvent> {
2365
+ /** UUID of the activity that the event listener is listening for. */
2366
+ activityUuid: string;
2367
+ }
2368
+
2360
2369
  declare class CanvasKitHelpers {
2361
2370
  /**
2362
2371
  * Frees up resources that were allocated by CanvasKit.
@@ -2365,7 +2374,7 @@ declare class CanvasKitHelpers {
2365
2374
  * canvaskit-wasm. JavaScript garbage collection won't
2366
2375
  * free these wasm objects.
2367
2376
  */
2368
- static Dispose(objects: Array<undefined | null | EmbindObject<Font | Paint | ParagraphBuilder | Paragraph | Image | Typeface | FontMgr | Path>>): void;
2377
+ static Dispose(objects: Array<undefined | null | Font | Paint | ParagraphBuilder | Paragraph | Image | Typeface | TypefaceFontProvider | FontMgr | Path>): void;
2369
2378
  static makePaint(canvasKit: CanvasKit, color: RgbaColor, style: PaintStyle, isAntialiased: boolean): Paint;
2370
2379
  }
2371
2380
 
@@ -2464,17 +2473,17 @@ declare class ColorfulMutablePath extends MutablePath {
2464
2473
  duplicate(): ColorfulMutablePath;
2465
2474
  }
2466
2475
 
2467
- interface CompositeOptions extends EntityOptions, DrawableOptions {
2476
+ interface CompositeOptions extends M2NodeOptions, DrawableOptions {
2468
2477
  }
2469
2478
 
2470
- declare abstract class Composite extends Entity implements IDrawable {
2471
- readonly type = EntityType.Composite;
2479
+ declare abstract class Composite extends M2Node implements IDrawable {
2480
+ readonly type = M2NodeType.Composite;
2472
2481
  compositeType: string;
2473
2482
  isDrawable: boolean;
2474
2483
  anchorPoint: Point;
2475
2484
  zPosition: number;
2476
2485
  /**
2477
- * Base Drawable object for creating custom entities ("composites") composed of primitive entities.
2486
+ * Base Drawable object for creating custom nodes ("composites") composed of primitive nodes.
2478
2487
  *
2479
2488
  * @param options
2480
2489
  */
@@ -2513,11 +2522,14 @@ declare class Constants {
2513
2522
  /** Font size in Label and TextLine, if none is specified. */
2514
2523
  static readonly DEFAULT_FONT_SIZE = 16;
2515
2524
  static readonly LIMITED_FPS_RATE = 5;
2516
- static readonly FREE_ENTITIES_SCENE_NAME = "__freeEntitiesScene";
2525
+ static readonly FREE_NODES_SCENE_NAME = "__freeNodesScene";
2517
2526
  static readonly OUTGOING_SCENE_NAME = "__outgoingScene";
2518
2527
  static readonly OUTGOING_SCENE_SPRITE_NAME = "__outgoingSceneSprite";
2519
2528
  static readonly OUTGOING_SCENE_IMAGE_NAME = "__outgoingSceneSnapshot";
2520
2529
  static readonly SESSION_INITIALIZATION_POLLING_INTERVAL_MS = 50;
2530
+ /** Placeholder that will be populated during the build process. */
2531
+ static readonly MODULE_METADATA_PLACEHOLDER: ModuleMetadata;
2532
+ static readonly DEFAULT_ROOT_ELEMENT_ID = "m2c2kit";
2521
2533
  }
2522
2534
 
2523
2535
  /**
@@ -2560,10 +2572,187 @@ declare class Equals {
2560
2572
  static rgbaColor(color1?: RgbaColor, color2?: RgbaColor): boolean;
2561
2573
  }
2562
2574
 
2563
- interface EventListenerBase {
2564
- type: EventType;
2565
- callback: (event: EventBase) => void;
2566
- key?: string;
2575
+ /**
2576
+ * Bounding box of a node.
2577
+ *
2578
+ * @remarks In the m2c2kit coordinate system, the origin (0, 0) is at the top
2579
+ * left corner.
2580
+ */
2581
+ interface BoundingBox {
2582
+ /** The minimum x value of the bounding box */
2583
+ xMin: number;
2584
+ /** The maximum x value of the bounding box */
2585
+ xMax: number;
2586
+ /** The minimum y value of the bounding box */
2587
+ yMin: number;
2588
+ /** The maximum y value of the bounding box */
2589
+ yMax: number;
2590
+ }
2591
+
2592
+ interface RotationTransform {
2593
+ /** Counterclockwise radians of the rotation */
2594
+ radians: number;
2595
+ /** Point around which to rotate */
2596
+ center: Point;
2597
+ }
2598
+ declare class M2c2KitHelpers {
2599
+ /**
2600
+ * Returns the URL as it appears in the game's manifest.json file.
2601
+ *
2602
+ * @remarks This is used to return the hashed URL.
2603
+ *
2604
+ * @param game - game object
2605
+ * @param url - the URL
2606
+ * @returns the hashed URL from the manifest, or the original URL if there is no manifest or the URL is not in the manifest.
2607
+ */
2608
+ static getUrlFromManifest(game: Game, url: string): string;
2609
+ /**
2610
+ * Does the URL have a scheme?
2611
+ *
2612
+ * @param url - the URL to test
2613
+ * @returns true if the url begins with a scheme (e.g., "http://",
2614
+ * "https://", "file://", etc.)
2615
+ */
2616
+ static urlHasScheme(url: string): boolean;
2617
+ /**
2618
+ * Calculates the four points of the bounding box of the node, taking
2619
+ * into account the node's rotation (as well as the rotation of its
2620
+ * ancestors).
2621
+ *
2622
+ * @remarks This method is used to calculate the rotated bounding box of an
2623
+ * node when in order to determine if a point is inside the node in
2624
+ * response to DOM pointer events. This method is NOT used to prepare the
2625
+ * CanvasKit canvas for drawing the node.
2626
+ *
2627
+ * @param drawableNode
2628
+ * @returns array of points representing the rotated node
2629
+ */
2630
+ static calculateRotatedPoints(drawableNode: IDrawable & M2Node): Point[];
2631
+ /**
2632
+ * Rotates the canvas so the node appears rotated when drawn.
2633
+ *
2634
+ * @remarks Nodes inherit rotations from their ancestors. Each ancestor,
2635
+ * however, rotates around its own anchor point. Thus, we must rotate the
2636
+ * canvas around the anchor point of each ancestor as well as the node's
2637
+ * anchor point.
2638
+ *
2639
+ * @param canvas - CanvasKit canvas to rotate
2640
+ * @param drawableNode - Node to rotate the canvas for
2641
+ */
2642
+ static rotateCanvasForDrawableNode(canvas: Canvas, drawableNode: IDrawable & M2Node): void;
2643
+ /**
2644
+ * Calculates the absolute bounding box of the node before any rotation
2645
+ * is applied.
2646
+ *
2647
+ * @remarks The absolute bounding box is the bounding box of the node
2648
+ * relative to the scene's origin (0, 0).
2649
+ *
2650
+ * @param node
2651
+ * @returns the bounding box of the node
2652
+ */
2653
+ static calculateNodeAbsoluteBoundingBox(node: M2Node): BoundingBox;
2654
+ /**
2655
+ * Converts an angle from radians to degrees.
2656
+ *
2657
+ * @remarks In m2c2kit, radians are counter clockwise from the positive
2658
+ * x-axis, but the rotate method in CanvasKit uses degrees clockwise. Thus
2659
+ * we negate after conversion from radians to degrees.
2660
+ *
2661
+ * @param radians - The angle in radians
2662
+ * @returns The angle in degrees
2663
+ */
2664
+ static radiansToDegrees(radians: number): number;
2665
+ /**
2666
+ * Normalizes an angle in radians to the range [0, 2*Math.PI)
2667
+ *
2668
+ * @param radians - angle in radians
2669
+ * @returns normalized angle in radians
2670
+ */
2671
+ static normalizeAngleRadians(radians: number): number;
2672
+ /**
2673
+ * Checks if two points are on the same side of a line.
2674
+ *
2675
+ * @remarks The line is defined by two points, a and b. The function uses
2676
+ * the cross product to determine the relative position of the points.
2677
+ *
2678
+ * @param p1 - point to check
2679
+ * @param p2 - point to check
2680
+ * @param a - point that defines one end of the line
2681
+ * @param b - point that defines the other end of the line
2682
+ * @returns true if p1 and p2 are on the same side of the line, or false
2683
+ * otherwise
2684
+ */
2685
+ static arePointsOnSameSideOfLine(p1: Point, p2: Point, a: Point, b: Point): boolean;
2686
+ /**
2687
+ * Checks if a point is inside a rectangle.
2688
+ *
2689
+ * @remarks The rectangle may have been rotated (sides might not be parallel
2690
+ * to the axes).
2691
+ *
2692
+ * @param point - The Point to check
2693
+ * @param rect - An array of four Points representing the vertices of the
2694
+ * rectangle in clockwise order
2695
+ * @returns true if the Point is inside the rectangle
2696
+ */
2697
+ static isPointInsideRectangle(point: Point, rect: Point[]): boolean;
2698
+ /**
2699
+ * Checks if the node or any of its ancestors have been rotated.
2700
+ *
2701
+ * @param node - node to check
2702
+ * @returns true if the node or any of its ancestors have been rotated
2703
+ */
2704
+ static nodeOrAncestorHasBeenRotated(node: M2Node): boolean;
2705
+ /**
2706
+ * Converts a bounding box to an array of four points representing the
2707
+ * vertices of the rectangle.
2708
+ *
2709
+ * @remarks In m2c2kit, the y-axis is inverted: origin is in the upper-left.
2710
+ * Vertices are returned in clockwise order starting from the upper-left.
2711
+ *
2712
+ * @param boundingBox
2713
+ * @returns An array of four points
2714
+ */
2715
+ static boundingBoxToPoints(boundingBox: BoundingBox): Point[];
2716
+ /**
2717
+ * Finds the centroid of a rectangle.
2718
+ *
2719
+ * @param points - An array of four points representing the vertices of the
2720
+ * rectangle.
2721
+ * @returns array of points representing the centroid of the rectangle.
2722
+ */
2723
+ static findCentroid(points: Point[]): Point;
2724
+ /**
2725
+ * Rotates a point, counterclockwise, around another point by an angle in
2726
+ * radians.
2727
+ *
2728
+ * @param point - Point to rotate
2729
+ * @param radians - angle in radians
2730
+ * @param center - Point to rotate around
2731
+ * @returns rotated point
2732
+ */
2733
+ static rotatePoint(point: Point, radians: number, center: Point): Point;
2734
+ /**
2735
+ * Calculates the rotation transforms to apply to node, respecting any
2736
+ * ancestor rotations.
2737
+ *
2738
+ * @param drawableNode - node to calculate rotation transforms for
2739
+ * @returns array of rotation transforms to apply
2740
+ */
2741
+ static calculateRotationTransforms(drawableNode: IDrawable & M2Node): RotationTransform[];
2742
+ }
2743
+
2744
+ /**
2745
+ * FontData holds metadata about the font (names, url) and the raw bytes of
2746
+ * the font TTF in an ArrayBuffer. This ArrayBuffer font data cannot be used
2747
+ * by canvaskit directly. These data are later used to create a canvaskit
2748
+ * TypeFace in FontManager.loadFonts().
2749
+ */
2750
+ interface FontData {
2751
+ fontUrl: string;
2752
+ fontName: string;
2753
+ fontFamilyName: string;
2754
+ fontArrayBuffer: ArrayBuffer;
2755
+ isDefault: boolean;
2567
2756
  }
2568
2757
 
2569
2758
  interface IText {
@@ -2579,7 +2768,7 @@ declare enum LabelHorizontalAlignmentMode {
2579
2768
  Right = 2
2580
2769
  }
2581
2770
 
2582
- interface LabelOptions extends EntityOptions, DrawableOptions, TextOptions {
2771
+ interface LabelOptions extends M2NodeOptions, DrawableOptions, TextOptions {
2583
2772
  /** Horizontal alignment of label text. see {@link LabelHorizontalAlignmentMode}. Default is LabelHorizontalAlignmentMode.center */
2584
2773
  horizontalAlignmentMode?: LabelHorizontalAlignmentMode;
2585
2774
  /** Maximum width of label text before wrapping occurs. Default is the canvas width */
@@ -2590,8 +2779,8 @@ interface LabelOptions extends EntityOptions, DrawableOptions, TextOptions {
2590
2779
  fontNames?: Array<string>;
2591
2780
  }
2592
2781
 
2593
- declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2594
- readonly type = EntityType.Label;
2782
+ declare class Label extends M2Node implements IDrawable, IText, LabelOptions {
2783
+ readonly type = M2NodeType.Label;
2595
2784
  isDrawable: boolean;
2596
2785
  isText: boolean;
2597
2786
  anchorPoint: {
@@ -2622,6 +2811,17 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2622
2811
  */
2623
2812
  constructor(options?: LabelOptions);
2624
2813
  initialize(): void;
2814
+ /**
2815
+ * Determines the M2Font objects that need to be ready in order to draw
2816
+ * the Label.
2817
+ *
2818
+ * @remarks It needs a FontManager because it may need to look up the
2819
+ * default font.
2820
+ *
2821
+ * @param fontManager - {@link FontManager}
2822
+ * @returns an array of M2Font objects that are required for the Label
2823
+ */
2824
+ private getRequiredLabelFonts;
2625
2825
  dispose(): void;
2626
2826
  get text(): string;
2627
2827
  set text(text: string);
@@ -2645,13 +2845,13 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2645
2845
  private get fontPaint();
2646
2846
  private set fontPaint(value);
2647
2847
  /**
2648
- * Duplicates an entity using deep copy.
2848
+ * Duplicates a node using deep copy.
2649
2849
  *
2650
- * @remarks This is a deep recursive clone (entity and children).
2651
- * The uuid property of all duplicated entities will be newly created,
2850
+ * @remarks This is a deep recursive clone (node and children).
2851
+ * The uuid property of all duplicated nodes will be newly created,
2652
2852
  * because uuid must be unique.
2653
2853
  *
2654
- * @param newName - optional name of the new, duplicated entity. If not
2854
+ * @param newName - optional name of the new, duplicated node. If not
2655
2855
  * provided, name will be the new uuid
2656
2856
  */
2657
2857
  duplicate(newName?: string): Label;
@@ -2664,23 +2864,143 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2664
2864
  * This class is used internally for processing layout constraints that
2665
2865
  * have been defined according to the Constraints interface.
2666
2866
  *
2667
- * Imagine we have two entities, A and B. B's position is set
2867
+ * Imagine we have two nodes, A and B. B's position is set
2668
2868
  * using its position property. A's position is set using the layout
2669
- * constraint "bottomToTopOf B." A is the focal entity in this example.
2869
+ * constraint "bottomToTopOf B." A is the focal node in this example.
2670
2870
  * What this means is that A's y coordinate will be computed such that
2671
2871
  * the bottom of A is the top of B. If A and B are squares, then A sits
2672
2872
  * on top of B with no gap.
2673
2873
  */
2674
2874
  declare class LayoutConstraint {
2675
2875
  type: ConstraintType;
2676
- alterEntity: Entity;
2876
+ alterNode: M2Node;
2677
2877
  verticalConstraint: boolean;
2678
- focalEntityMinimum: boolean;
2679
- alterEntityMinimum: boolean;
2878
+ focalNodeMinimum: boolean;
2879
+ alterNodeMinimum: boolean;
2680
2880
  verticalTypes: ConstraintType[];
2681
- focalEntityMinimumTypes: ConstraintType[];
2682
- alterEntityMinimumTypes: ConstraintType[];
2683
- constructor(type: ConstraintType, alterEntity: Entity);
2881
+ focalNodeMinimumTypes: ConstraintType[];
2882
+ alterNodeMinimumTypes: ConstraintType[];
2883
+ constructor(type: ConstraintType, alterNode: M2Node);
2884
+ }
2885
+
2886
+ /**
2887
+ * A class to create, start, and stop named timers that measure elapsed time in milliseconds.
2888
+ *
2889
+ * @deprecated Use Timer class instead. To migrate to the Timer class, use Timer.startNew() to create and start a new timer instead
2890
+ * of LegacyTimer.start().
2891
+ */
2892
+ declare class LegacyTimer {
2893
+ private startTime;
2894
+ private stopTime;
2895
+ private stopped;
2896
+ /**
2897
+ * cumulativeElapsed is a cumulative total of elapsed time while the timer
2898
+ * was in previous started (running) states, NOT INCLUDING the possibly
2899
+ * active run's duration
2900
+ */
2901
+ private cumulativeElapsed;
2902
+ private name;
2903
+ private static _timers;
2904
+ constructor(name: string);
2905
+ /**
2906
+ * Aliases performance.now()
2907
+ *
2908
+ * @remarks The m2c2kit Timer class is designed to measure elapsed durations
2909
+ * after a designated start point for a uniquely named timer. However, if a
2910
+ * timestamp based on the
2911
+ * [time origin](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp#the_time_origin)
2912
+ * is needed, this method can be used.
2913
+ *
2914
+ * @deprecated Use Timer class.
2915
+ *
2916
+ * @returns a [DOMHighResTimeStamp](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp)
2917
+ */
2918
+ static now(): number;
2919
+ /**
2920
+ * Starts a millisecond-resolution timer based on
2921
+ * [performance.now()](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now).
2922
+ *
2923
+ * @remarks The method throws an error if a timer with the given
2924
+ * name is already in a started state.
2925
+ *
2926
+ * @deprecated Use Timer class. Use Timer.startNew() to create and start a new timer or Timer.new() to create a new timer without starting it.
2927
+ *
2928
+ * @param name - The name of the timer to be started
2929
+ */
2930
+ static start(name: string): void;
2931
+ /**
2932
+ * Stops a timer.
2933
+ *
2934
+ * @remarks The method throws an error if a timer with the given
2935
+ * name is already in a stopped state, or if a timer with the
2936
+ * given name has not been started.
2937
+ *
2938
+ * @deprecated Use Timer class.
2939
+ *
2940
+ * @param name - The name of the timer to be stopped
2941
+ */
2942
+ static stop(name: string): void;
2943
+ /**
2944
+ * Restarts a timer.
2945
+ *
2946
+ * @remarks The timer elapsed duration is set to 0 and it starts anew.
2947
+ * The method throws an error if a timer with the given
2948
+ * name does not exist (if there is not a started or stopped timer
2949
+ * with the given name).
2950
+ *
2951
+ * @deprecated Use Timer class. Use Timer.startNew() to create and start a new timer with the same name.
2952
+ *
2953
+ * @param name - The name of the timer to be restarted
2954
+ */
2955
+ static restart(name: string): void;
2956
+ /**
2957
+ * Returns the total time elapsed, in milliseconds, of the timer.
2958
+ *
2959
+ * @remarks The total time elapsed will include all durations from multiple
2960
+ * starts and stops of the timer, if applicable. A timer's elapsed duration
2961
+ * can be read while it is in started or stopped state. The method throws
2962
+ * an error if a timer with the given name does not exist.
2963
+ *
2964
+ * @deprecated Use Timer class.
2965
+ *
2966
+ * @param name - The name of the timer whose elapsed duration is requested
2967
+ */
2968
+ static elapsed(name: string): number;
2969
+ /**
2970
+ * Removes a timer.
2971
+ *
2972
+ * @remarks After removal, no additional methods can be used with a timer
2973
+ * of the given name, other than to start a new timer with the given name,
2974
+ * whose duration will begin at 0 again. The method throws an error if
2975
+ * a timer with the given name does not exist.
2976
+ *
2977
+ * @deprecated Use Timer class.
2978
+ *
2979
+ * @param name - The name of the timer to be removed
2980
+ */
2981
+ static remove(name: string): void;
2982
+ /**
2983
+ * Remove all timers.
2984
+ *
2985
+ * @remarks This method will {@link remove} any timers in a started or
2986
+ * stopped state. This method is idempotent; method is safe to call even
2987
+ * if there are no timers to remove; no errors are thrown if there are
2988
+ * not any timers that can be removed.
2989
+ *
2990
+ * @deprecated Use Timer class.
2991
+ */
2992
+ static removeAll(): void;
2993
+ /**
2994
+ * Checks if a timer of the given name exists.
2995
+ *
2996
+ * @remarks The method checks if there is a timer with the given name.
2997
+ *
2998
+ * @deprecated Use Timer class.
2999
+ *
3000
+ * @param name - The name of the timer to check for existence
3001
+ * @returns boolean
3002
+ */
3003
+ static exists(name: string): boolean;
2684
3004
  }
2685
3005
 
2686
3006
  /**
@@ -2694,6 +3014,11 @@ interface M2ColorfulPath extends M2Path {
2694
3014
  linePresentations: Array<LinePresentation>;
2695
3015
  }
2696
3016
 
3017
+ /** Base interface for all Plugin events. */
3018
+ interface PluginEvent extends M2Event<Plugin> {
3019
+ target: Plugin;
3020
+ }
3021
+
2697
3022
  declare class RandomDraws {
2698
3023
  /**
2699
3024
  * Draws a single random integer from a uniform distribution of integers in
@@ -2772,7 +3097,7 @@ interface SvgStringPath {
2772
3097
  width?: number;
2773
3098
  }
2774
3099
 
2775
- interface ShapeOptions extends EntityOptions, DrawableOptions {
3100
+ interface ShapeOptions extends M2NodeOptions, DrawableOptions {
2776
3101
  shapeType?: ShapeType;
2777
3102
  /** If provided, shape will be a circle with given radius */
2778
3103
  circleOfRadius?: number;
@@ -2794,8 +3119,8 @@ interface ShapeOptions extends EntityOptions, DrawableOptions {
2794
3119
  isAntialiased?: boolean;
2795
3120
  }
2796
3121
 
2797
- declare class Shape extends Entity implements IDrawable, ShapeOptions {
2798
- readonly type = EntityType.Shape;
3122
+ declare class Shape extends M2Node implements IDrawable, ShapeOptions {
3123
+ readonly type = M2NodeType.Shape;
2799
3124
  isDrawable: boolean;
2800
3125
  isShape: boolean;
2801
3126
  anchorPoint: {
@@ -2837,13 +3162,13 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2837
3162
  initialize(): void;
2838
3163
  dispose(): void;
2839
3164
  /**
2840
- * Duplicates an entity using deep copy.
3165
+ * Duplicates a node using deep copy.
2841
3166
  *
2842
- * @remarks This is a deep recursive clone (entity and children).
2843
- * The uuid property of all duplicated entities will be newly created,
3167
+ * @remarks This is a deep recursive clone (node and children).
3168
+ * The uuid property of all duplicated nodes will be newly created,
2844
3169
  * because uuid must be unique.
2845
3170
  *
2846
- * @param newName - optional name of the new, duplicated entity. If not
3171
+ * @param newName - optional name of the new, duplicated node. If not
2847
3172
  * provided, name will be the new uuid
2848
3173
  */
2849
3174
  duplicate(newName?: string): Shape;
@@ -2888,13 +3213,13 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2888
3213
  set strokeColorPaintNotAntialiased(value: Paint);
2889
3214
  }
2890
3215
 
2891
- interface SpriteOptions extends EntityOptions, DrawableOptions {
3216
+ interface SpriteOptions extends M2NodeOptions, DrawableOptions {
2892
3217
  /** Name of image to use for sprite. Must have been previously loaded */
2893
3218
  imageName?: string;
2894
3219
  }
2895
3220
 
2896
- declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2897
- readonly type = EntityType.Sprite;
3221
+ declare class Sprite extends M2Node implements IDrawable, SpriteOptions {
3222
+ readonly type = M2NodeType.Sprite;
2898
3223
  isDrawable: boolean;
2899
3224
  anchorPoint: {
2900
3225
  x: number;
@@ -2902,7 +3227,7 @@ declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2902
3227
  };
2903
3228
  zPosition: number;
2904
3229
  private _imageName;
2905
- private loadedImage?;
3230
+ private m2Image?;
2906
3231
  private _paint?;
2907
3232
  /**
2908
3233
  * Visual image displayed on the screen.
@@ -2919,13 +3244,13 @@ declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2919
3244
  private set paint(value);
2920
3245
  private get paint();
2921
3246
  /**
2922
- * Duplicates an entity using deep copy.
3247
+ * Duplicates a node using deep copy.
2923
3248
  *
2924
- * @remarks This is a deep recursive clone (entity and children).
2925
- * The uuid property of all duplicated entities will be newly created,
3249
+ * @remarks This is a deep recursive clone (node and children).
3250
+ * The uuid property of all duplicated nodes will be newly created,
2926
3251
  * because uuid must be unique.
2927
3252
  *
2928
- * @param newName - optional name of the new, duplicated entity. If not
3253
+ * @param newName - optional name of the new, duplicated node. If not
2929
3254
  * provided, name will be the new uuid
2930
3255
  */
2931
3256
  duplicate(newName?: string): Sprite;
@@ -2939,15 +3264,15 @@ interface StoryOptions {
2939
3264
  }
2940
3265
 
2941
3266
  declare abstract class Story {
2942
- static Create(options: StoryOptions): Array<Scene>;
3267
+ static create(options?: StoryOptions): Array<Scene>;
2943
3268
  }
2944
3269
 
2945
- interface TextLineOptions extends EntityOptions, DrawableOptions, TextOptions {
3270
+ interface TextLineOptions extends M2NodeOptions, DrawableOptions, TextOptions {
2946
3271
  width?: number;
2947
3272
  }
2948
3273
 
2949
- declare class TextLine extends Entity implements IDrawable, IText, TextLineOptions {
2950
- readonly type = EntityType.TextLine;
3274
+ declare class TextLine extends M2Node implements IDrawable, IText, TextLineOptions {
3275
+ readonly type = M2NodeType.TextLine;
2951
3276
  isDrawable: boolean;
2952
3277
  isText: boolean;
2953
3278
  zPosition: number;
@@ -2983,15 +3308,26 @@ declare class TextLine extends Entity implements IDrawable, IText, TextLineOptio
2983
3308
  set fontSize(fontSize: number);
2984
3309
  update(): void;
2985
3310
  initialize(): void;
3311
+ /**
3312
+ * Determines the M2Font object that needs to be ready in order to draw
3313
+ * the TextLine.
3314
+ *
3315
+ * @remarks It needs a FontManager because it may need to look up the
3316
+ * default font.
3317
+ *
3318
+ * @param fontManager - {@link FontManager}
3319
+ * @returns a M2Font object that is required for the TextLine
3320
+ */
3321
+ private getRequiredTextLineFont;
2986
3322
  dispose(): void;
2987
3323
  /**
2988
- * Duplicates an entity using deep copy.
3324
+ * Duplicates a node using deep copy.
2989
3325
  *
2990
- * @remarks This is a deep recursive clone (entity and children).
2991
- * The uuid property of all duplicated entities will be newly created,
3326
+ * @remarks This is a deep recursive clone (node and children).
3327
+ * The uuid property of all duplicated nodes will be newly created,
2992
3328
  * because uuid must be unique.
2993
3329
  *
2994
- * @param newName - optional name of the new, duplicated entity. If not
3330
+ * @param newName - optional name of the new, duplicated node. If not
2995
3331
  * provided, name will be the new uuid
2996
3332
  */
2997
3333
  duplicate(newName?: string): TextLine;
@@ -2999,6 +3335,9 @@ declare class TextLine extends Entity implements IDrawable, IText, TextLineOptio
2999
3335
  warmup(canvas: Canvas): void;
3000
3336
  }
3001
3337
 
3338
+ /**
3339
+ * A class to create, start, and stop named timers that measure elapsed time in milliseconds.
3340
+ */
3002
3341
  declare class Timer {
3003
3342
  private startTime;
3004
3343
  private stopTime;
@@ -3011,7 +3350,7 @@ declare class Timer {
3011
3350
  private cumulativeElapsed;
3012
3351
  private name;
3013
3352
  private static _timers;
3014
- constructor(name: string);
3353
+ private constructor();
3015
3354
  /**
3016
3355
  * Aliases performance.now()
3017
3356
  *
@@ -3025,11 +3364,31 @@ declare class Timer {
3025
3364
  */
3026
3365
  static now(): number;
3027
3366
  /**
3028
- * Starts a millisecond-resolution timer based on
3367
+ * Creates, but does not start, a new millisecond-resolution timer based on
3029
3368
  * [performance.now()](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now).
3030
3369
  *
3031
- * @remarks The method throws an error if a timer with the given
3032
- * name is already in a started state.
3370
+ * @remarks If a timer with the given name already exists, it will be created
3371
+ * and set back to zero, but not started.
3372
+ *
3373
+ * @param name - The name of the timer to be started
3374
+ */
3375
+ static new(name: string): void;
3376
+ /**
3377
+ * Creates and starts a new millisecond-resolution timer based on
3378
+ * [performance.now()](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now).
3379
+ *
3380
+ * @remarks If a timer with the given name already exists, it will be created,
3381
+ * set back to zero, and started.
3382
+ *
3383
+ * @param name - The name of the timer to be started
3384
+ */
3385
+ static startNew(name: string): void;
3386
+ /**
3387
+ * Starts a stopped millisecond-resolution timer based on
3388
+ * [performance.now()](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now).
3389
+ *
3390
+ * @remarks The method throws an error if a timer with the given name does
3391
+ * not exist or is not in a stopped state.
3033
3392
  *
3034
3393
  * @param name - The name of the timer to be started
3035
3394
  */
@@ -3044,17 +3403,6 @@ declare class Timer {
3044
3403
  * @param name - The name of the timer to be stopped
3045
3404
  */
3046
3405
  static stop(name: string): void;
3047
- /**
3048
- * Restarts a timer.
3049
- *
3050
- * @remarks The timer elapsed duration is set to 0 and it starts anew.
3051
- * The method throws an error if a timer with the given
3052
- * name does not exist (if there is not a started or stopped timer
3053
- * with the given name).
3054
- *
3055
- * @param name - The name of the timer to be restarted
3056
- */
3057
- static restart(name: string): void;
3058
3406
  /**
3059
3407
  * Returns the total time elapsed, in milliseconds, of the timer.
3060
3408
  *
@@ -3070,8 +3418,8 @@ declare class Timer {
3070
3418
  * Removes a timer.
3071
3419
  *
3072
3420
  * @remarks After removal, no additional methods can be used with a timer
3073
- * of the given name, other than to start a new timer with the given name,
3074
- * whose duration will begin at 0 again. The method throws an error if
3421
+ * of the given name, other than to create a new timer with the given name,
3422
+ * whose duration will be set at 0 again. The method throws an error if
3075
3423
  * a timer with the given name does not exist.
3076
3424
  *
3077
3425
  * @param name - The name of the timer to be removed
@@ -3263,4 +3611,4 @@ declare class WebGlInfo {
3263
3611
  static dispose(): void;
3264
3612
  }
3265
3613
 
3266
- export { Action, type Activity, 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, Entity, type EntityEvent, type EntityEventListener, type EntityOptions, EntityType, Equals, type EventBase, type EventListenerBase, EventType, FadeAlphaAction, type FadeAlphaActionOptions, type FontData, FontManager, Game, type GameData, type GameOptions, type GameParameters, GlobalVariables, type GoToActivityOptions, GroupAction, I18n, type IDataStore, type IDrawable, type IText, ImageManager, Label, LabelHorizontalAlignmentMode, type LabelOptions, type Layout, LayoutConstraint, LoadedImage, type M2ColorfulPath, type M2DragEvent, type M2Path, type M2PointerEvent, MoveAction, type MoveActionOptions, MutablePath, NoneTransition, type Point, RandomDraws, type RectOptions, type RgbaColor, RotateAction, ScaleAction, type ScaleActionOptions, Scene, type SceneOptions, SceneTransition, SequenceAction, Session, type SessionDictionaryValues, type SessionLifecycleEvent, type SessionOptions, Shape, type ShapeOptions, ShapeType, type Size, SlideTransition, type SlideTransitionOptions, Sprite, type SpriteOptions, Story, type StoryOptions, type TapEvent, TextLine, type TextLineOptions, type TextOptions, Timer, Transition, TransitionDirection, TransitionType, type Translations, type TrialData, type TrialSchema, Uuid, WaitAction, type WaitActionOptions, WebColors, WebGlInfo, handleInterfaceOptions };
3614
+ 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 M2ColorfulPath, type M2DragEvent, type M2Event, type M2EventListener, M2EventType, type M2Image, M2ImageStatus, M2Node, type M2NodeEvent, type M2NodeEventListener, type M2NodeOptions, M2NodeType, type M2Path, type M2PointerEvent, M2c2KitHelpers, MoveAction, type MoveActionOptions, MutablePath, NoneTransition, type Plugin, type PluginEvent, type Point, RandomDraws, type RectOptions, type RgbaColor, RotateAction, ScaleAction, type ScaleActionOptions, Scene, type SceneOptions, SceneTransition, SequenceAction, Shape, type ShapeOptions, ShapeType, type Size, SlideTransition, type SlideTransitionOptions, Sprite, type SpriteOptions, Story, type StoryOptions, type TapEvent, TextLine, type TextLineOptions, type TextOptions, Timer, Transition, TransitionDirection, TransitionType, type Translations, type TrialData, type TrialSchema, Uuid, WaitAction, type WaitActionOptions, WebColors, WebGlInfo, handleInterfaceOptions };