@m2c2kit/core 0.3.16 → 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,13 +841,6 @@ 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;
726
- }
727
-
728
844
  /**
729
845
  * A Plugin is code that can be registered to run at certain points in the game loop.
730
846
  */
@@ -743,16 +859,282 @@ interface Plugin {
743
859
  afterUpdate?: (game: Game, deltaTime: number) => void;
744
860
  }
745
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;
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];
1017
+
1018
+ /**
1019
+ * Fetches, loads, and provides images to the game.
1020
+ */
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> {
1123
+ target: Game;
1124
+ }
1125
+
746
1126
  interface TrialData {
747
1127
  [key: string]: string | number | boolean | object | undefined | null;
748
1128
  }
749
1129
  declare class Game implements Activity {
750
1130
  readonly type = ActivityType.Game;
751
1131
  _canvasKit?: CanvasKit;
752
- _session?: Session;
1132
+ sessionUuid: string;
753
1133
  uuid: string;
754
1134
  name: string;
755
1135
  id: string;
1136
+ moduleMetadata: ModuleMetadata;
1137
+ readonly canvasKitWasmVersion = "__CANVASKITWASM_VERSION__";
756
1138
  options: GameOptions;
757
1139
  beginTimestamp: number;
758
1140
  beginIso8601Timestamp: string;
@@ -764,22 +1146,65 @@ declare class Game implements Activity {
764
1146
  private steppingNow;
765
1147
  i18n?: I18n;
766
1148
  private warmupFunctionQueue;
767
- private loaderElementsRemoved;
1149
+ private warmupFinished;
768
1150
  private _dataStores?;
769
1151
  private plugins;
770
1152
  additionalParameters?: unknown;
771
1153
  staticTrialSchema: {
772
1154
  [key: string]: JsonSchemaDataTypeScriptTypes;
773
1155
  };
1156
+ private _fontManager?;
1157
+ private _imageManager?;
1158
+ manifest?: Manifest;
774
1159
  /**
775
1160
  * The base class for all games. New games should extend this class.
776
1161
  *
777
1162
  * @param options - {@link GameOptions}
778
1163
  */
779
1164
  constructor(options: GameOptions);
1165
+ private getImportedModuleBaseUrl;
780
1166
  private addLocalizationParametersToGameParameters;
781
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>;
782
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);
783
1208
  /**
784
1209
  * Saves an item to the activity's key-value store.
785
1210
  *
@@ -888,8 +1313,6 @@ declare class Game implements Activity {
888
1313
  setParameters(additionalParameters: unknown): void;
889
1314
  get canvasKit(): CanvasKit;
890
1315
  set canvasKit(canvasKit: CanvasKit);
891
- get session(): Session;
892
- set session(session: Session);
893
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 */
894
1317
  entryScene?: Scene | string;
895
1318
  data: GameData;
@@ -909,54 +1332,69 @@ declare class Game implements Activity {
909
1332
  private fpsRate;
910
1333
  private animationFramesRequested;
911
1334
  private limitFps;
912
- private unitTesting;
913
1335
  private gameStopRequested;
914
1336
  private webGlRendererInfo;
915
1337
  canvasCssWidth: number;
916
1338
  canvasCssHeight: number;
917
1339
  scenes: Scene[];
918
- private freeEntitiesScene;
1340
+ private freeNodesScene;
919
1341
  private incomingSceneTransitions;
920
1342
  private currentSceneSnapshot?;
921
1343
  private pendingScreenshot?;
922
1344
  /**
923
- * 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)
924
1346
  * to the game.
925
1347
  *
926
- * @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,
927
1349
  * and it will not be part of any scene transitions. This is useful if
928
- * an entity must persistently be drawn and not move with scene
929
- * transitions. The appearance of the free entity must be managed
930
- * by the programmer. Note: internally, the free entities are part of a
931
- * special scene (named "__freeEntitiesScene"), but this scene is handled
932
- * 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.
933
1355
  *
934
- * @param entity - entity to add as a free entity
1356
+ * @param node - node to add as a free node
935
1357
  */
936
- addFreeEntity(entity: Entity): void;
1358
+ addFreeNode(node: M2Node): void;
937
1359
  /**
938
- * Removes a free entity from the game.
1360
+ * @deprecated Use addFreeNode() instead
1361
+ */
1362
+ addFreeEntity(node: M2Node): void;
1363
+ /**
1364
+ * Removes a free node from the game.
939
1365
  *
940
- * @remarks Throws exception if the entity to remove is not currently added
941
- * 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
942
1368
  *
943
- * @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
944
1374
  */
945
- removeFreeEntity(entity: Entity | string): void;
1375
+ removeFreeEntity(node: M2Node | string): void;
946
1376
  /**
947
- * Removes all free entities from the game.
1377
+ * Removes all free nodes from the game.
1378
+ */
1379
+ removeAllFreeNodes(): void;
1380
+ /**
1381
+ * @deprecated Use removeAllFreeNodes() instead
948
1382
  */
949
1383
  removeAllFreeEntities(): void;
950
1384
  /**
951
- * 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.
952
1386
  *
953
- * @returns array of free entities
1387
+ * @returns array of free nodes
1388
+ */
1389
+ get freeNodes(): Array<M2Node>;
1390
+ /**
1391
+ * @deprecated Use Game.freeEntities instead
954
1392
  */
955
- get freeEntities(): Array<Entity>;
1393
+ get freeEntities(): Array<M2Node>;
956
1394
  /**
957
1395
  * Adds a scene to the game.
958
1396
  *
959
- * @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.
960
1398
  *
961
1399
  * @param scene
962
1400
  */
@@ -1045,12 +1483,12 @@ declare class Game implements Activity {
1045
1483
  private warmupShadersWithPrimitives;
1046
1484
  /**
1047
1485
  * Warms up the Skia-based shaders underlying canvaskit by drawing
1048
- * m2c2kit entities.
1486
+ * m2c2kit nodes.
1049
1487
  *
1050
1488
  * @remarks While warmupShadersWithPrimitives draws a predefined set of
1051
1489
  * primitives, this function initializes and draws all canvaskit objects
1052
- * that have been defined as m2c2kit entities. This not only is another
1053
- * 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.
1054
1492
  *
1055
1493
  * @param canvas - the canvaskit-canvas to draw on
1056
1494
  */
@@ -1059,8 +1497,8 @@ declare class Game implements Activity {
1059
1497
  /**
1060
1498
  * Frees up resources that were allocated to run the game.
1061
1499
  *
1062
- * @remarks This will be done automatically by the m2c2kit library;
1063
- * 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.
1064
1502
  */
1065
1503
  dispose(): void;
1066
1504
  private initData;
@@ -1114,666 +1552,217 @@ declare class Game implements Activity {
1114
1552
  * @param variableName - variable to be set
1115
1553
  * @param value - value of the variable to set
1116
1554
  */
1117
- addStaticTrialData(variableName: string, value: JsonSchemaDataTypeScriptTypes): void;
1118
- /**
1119
- * Should be called when the current trial has completed. It will
1120
- * also increment the trial index.
1121
- *
1122
- * @remarks Calling will trigger the onActivityResults callback function,
1123
- * if one was provided in SessionOptions. This is how the game communicates
1124
- * trial data to the parent session, which can then save or process the data.
1125
- * It is the responsibility of the the game programmer to call this at
1126
- * the appropriate time. It is not triggered automatically.
1127
- */
1128
- trialComplete(): void;
1129
- /**
1130
- * The m2c2kit engine will automatically include these schema and their
1131
- * values in the trial data.
1132
- */
1133
- private readonly automaticTrialSchema;
1134
- private makeNewGameDataSchema;
1135
- private makeGameDataSchema;
1136
- /**
1137
- * GameParameters combines default parameters values and
1138
- * JSON Schema to describe what the parameters are.
1139
- * The next two functions extract GameParameters's two parts
1140
- * (the default values and the schema) so they can be returned
1141
- * separately in the activityData event
1142
- */
1143
- private makeGameActivityConfiguration;
1144
- private makeGameActivityConfigurationSchema;
1145
- /**
1146
- * Should be called when current game has ended successfully.
1147
- *
1148
- * @remarks This will send an ActivityEnd event to any listeners, such as
1149
- * a function provided to Game.onEnd() or a callback defined in
1150
- * SessionOptions.activityCallbacks.onActivityLifecycle. This is how the
1151
- * game can communicate changes in activity state to the parent session.
1152
- * It is the responsibility of the the game programmer to call this at the
1153
- * appropriate time. It is not triggered automatically.
1154
- */
1155
- end(): void;
1156
- /**
1157
- * Should be called when current game has been canceled by a user action.
1158
- *
1159
- * @remarks This will send an ActivityCancel event to any listeners, such as
1160
- * a function provided to Game.onCancel() or a callback defined in
1161
- * SessionOptions.activityCallbacks.onActivityLifecycle. This is how the
1162
- * game can communicate changes in activity state to the parent session.
1163
- * It is the responsibility of the the game programmer to call this at the
1164
- * appropriate time. It is not triggered automatically.
1165
- */
1166
- cancel(): void;
1167
- private setupHtmlCanvases;
1168
- private setupCanvasKitSurface;
1169
- private interceptWebGlCalls;
1170
- private setupFpsFont;
1171
- private setupCanvasDomEventHandlers;
1172
- private loop;
1173
- snapshots: Image[];
1174
- private updateGameTime;
1175
- private handleIncomingSceneTransitions;
1176
- /**
1177
- * Creates a scene that has a screen shot of the current scene.
1178
- *
1179
- * @param outgoingSceneImage - an image of the current scene
1180
- * @returns - the scene with the screen shot
1181
- */
1182
- private createOutgoingScene;
1183
- /**
1184
- * Registers a plugin with the game.
1185
- *
1186
- * @remarks Upon registration, the plugin's optional asynchronous
1187
- * `initialize()` method will be called.
1188
- *
1189
- * @param plugin - Plugin to register
1190
- */
1191
- registerPlugin(plugin: Plugin): Promise<void>;
1192
- private update;
1193
- private draw;
1194
- private calculateFps;
1195
- private takeCurrentSceneSnapshot;
1196
- private handlePendingScreenshot;
1197
- /**
1198
- * Takes screenshot of canvas
1199
- *
1200
- * @remarks Coordinates should be provided unscaled; that is, the method
1201
- * will handle any scaling that happened due to device pixel ratios
1202
- * not equal to 1. This returns a promise because the screenshot request
1203
- * must be queued and completed once a draw cycle has completed. See
1204
- * the loop() method.
1205
- *
1206
- * @param sx - Upper left coordinate of screenshot
1207
- * @param sy - Upper right coordinate of screenshot
1208
- * @param sw - width of area to screenshot
1209
- * @param sh - height of area to screenshot
1210
- * @returns Promise of Uint8Array of image data
1211
- */
1212
- takeScreenshot(sx?: number, sy?: number, sw?: number, sh?: number): Promise<Uint8Array | null>;
1213
- private animateSceneTransition;
1214
- private drawFps;
1215
- /**
1216
- * Creates an event listener for an entity based on the entity name
1217
- *
1218
- * @remarks Typically, event listeners will be created using a method specific to the event, such as onTapDown(). This alternative allows creation with entity name.
1219
- *
1220
- * @param type - the type of event to listen for, e.g., "tapDown"
1221
- * @param entityName - the entity name for which an event will be listened
1222
- * @param callback - the callback to be invoked when the event occurs
1223
- * @param callbackOptions
1224
- */
1225
- createEventListener(type: EventType, entityName: string, callback: (event: EntityEvent) => void, callbackOptions?: CallbackOptions): void;
1226
- /**
1227
- * Returns array of all entities that have been added to the game object.
1228
- */
1229
- get entities(): Array<Entity>;
1230
- /**
1231
- * Receives callback from DOM PointerDown event
1232
- *
1233
- * @param domPointerEvent - PointerEvent from the DOM
1234
- * @returns
1235
- */
1236
- private htmlCanvasPointerDownHandler;
1237
- private htmlCanvasPointerUpHandler;
1238
- private htmlCanvasPointerMoveHandler;
1239
- private htmlCanvasPointerLeaveHandler;
1240
- /**
1241
- * Determines if/how m2c2kit entities respond to the DOM PointerDown event
1242
- *
1243
- * @param entity - entity that might be affected by the DOM PointerDown event
1244
- * @param m2Event
1245
- * @param domPointerEvent
1246
- */
1247
- private processDomPointerDown;
1248
- private processDomPointerUp;
1249
- private processDomPointerMove;
1250
- private processDomPointerLeave;
1251
- private raiseM2PointerDownEvent;
1252
- private raiseTapDownEvent;
1253
- private raiseTapLeaveEvent;
1254
- private raiseM2PointerUpEvent;
1255
- private raiseTapUpEvent;
1256
- private raiseTapUpAny;
1257
- private raiseM2PointerMoveEvent;
1258
- private raiseM2PointerLeaveEvent;
1259
- private raiseM2DragStartEvent;
1260
- private raiseM2DragEvent;
1261
- private raiseM2DragEndEvent;
1262
- private calculatePointWithinEntityFromDomPointerEvent;
1263
- /**
1264
- * Executes a callback when the game starts.
1265
- *
1266
- * @param callback - function to execute.
1267
- * @param options - options for the callback.
1268
- */
1269
- onStart(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1270
- /**
1271
- * Executes a callback when the game is canceled.
1272
- *
1273
- * @param callback - function to execute.
1274
- * @param options - options for the callback.
1275
- */
1276
- onCancel(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1277
- /**
1278
- * Executes a callback when the game ends.
1279
- *
1280
- * @param callback - function to execute.
1281
- * @param options - options for the callback.
1282
- */
1283
- onEnd(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1284
- /**
1285
- * Executes a callback when the game generates data.
1286
- *
1287
- * @param callback - function to execute.
1288
- * @param options - options for the callback.
1289
- */
1290
- onData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
1291
- private addEventListener;
1292
- private raiseActivityEventOnListeners;
1293
- private raiseEventOnListeningEntities;
1294
- private sceneCanReceiveUserInteraction;
1295
- /**
1296
- *
1297
- * Checks if the given canvas point is within the entity's bounds.
1298
- *
1299
- * @param entity - entity to check bounds for
1300
- * @param x - x coordinate of the canvas point
1301
- * @param y - y coordinate of the canvas point
1302
- * @returns true if x, y point is within the entity's bounds
1303
- */
1304
- private IsCanvasPointWithinEntityBounds;
1305
- prependAssetsGameIdUrl(url: string): string;
1306
- }
1307
-
1308
- /**
1309
- * This class contains all the fonts for all the games in the activity.
1310
- * Fonts have been converted to canvaskit Typeface.
1311
- *
1312
- * @remarks fontName is how the user will refer to the font in the game.
1313
- * fontFamily is the name of the font as it was specified within the TTF file.
1314
- * We must retain the fontFamily name because we must provide fontFamily (not
1315
- * fontName!) to canvaskit when rendering paragraphs.
1316
- */
1317
- declare class GameTypefaces {
1318
- [gameUuid: string]: {
1319
- [fontName: string]: {
1320
- fontFamily: string;
1321
- typeface: Typeface;
1322
- isDefault: boolean;
1323
- };
1324
- };
1325
- }
1326
- /**
1327
- * Class for loading, preparing, and providing fonts to games.
1328
- *
1329
- * @remarks FOR INTERNAL USE ONLY
1330
- */
1331
- declare class FontManager {
1332
- canvasKit?: CanvasKit;
1333
- fontMgr?: FontMgr;
1334
- gameTypefaces: GameTypefaces;
1335
- fontData: Array<FontData>;
1336
- session: Session;
1337
- games?: Array<Game>;
1338
- constructor(session: Session);
1339
- /**
1340
- * Gets a typeface that was previously loaded for the specified game.
1341
- *
1342
- * @param gameUuid
1343
- * @param fontName
1344
- * @returns the requested Typeface
1345
- */
1346
- getTypeface(gameUuid: string, fontName: string): Typeface;
1347
- /**
1348
- * Gets names of fonts loaded for the specified game.
1349
- *
1350
- * @param gameUuid
1351
- * @returns array of font names
1352
- */
1353
- getFontNames(gameUuid: string): Array<string>;
1354
- /**
1355
- * Fetches all fonts games.
1356
- *
1357
- * @param games - array of games
1358
- * @returns
1359
- */
1360
- fetchFonts(games: Array<Game>): Promise<void[]>;
1361
- /**
1362
- * Takes the fonts, which have been previously fetched and converted into
1363
- * Array Buffers using FontManager.fetchFonts(), and makes them available
1364
- * to our engine by creating canvaskit Typefaces.
1365
- */
1366
- loadAllGamesFontData(): void;
1367
- }
1368
-
1369
- interface ActivityCallbacks {
1370
- /** Callback executed when the activity lifecycle changes, such as when it ends. */
1371
- onActivityLifecycle?: (event: ActivityLifecycleEvent) => void;
1372
- /** Callback executed when an activity creates some data. */
1373
- onActivityResults?: (event: ActivityResultsEvent) => void;
1374
- }
1375
-
1376
- /** Base interface for all Session events. */
1377
- interface SessionEvent extends EventBase {
1378
- target: Session;
1379
- }
1380
-
1381
- /**
1382
- * Notifies when a session starts, ends, or initializes.
1383
- */
1384
- interface SessionLifecycleEvent extends SessionEvent {
1385
- }
1386
-
1387
- interface SessionCallbacks {
1388
- /** Callback executed when the session lifecycle changes, such as when it is initialized. */
1389
- onSessionLifecycle?: (event: SessionLifecycleEvent) => void;
1390
- }
1391
-
1392
- interface SessionOptions {
1393
- /** The activities that compose this session */
1394
- activities: Array<Activity>;
1395
- /** Callbacks executed when activity events occurs, such as when activity creates data or ends */
1396
- activityCallbacks?: ActivityCallbacks;
1397
- /** Callbacks executed when session events occur */
1398
- sessionCallbacks?: SessionCallbacks;
1399
- /** Url of the canvaskit.wasm binary. Always set to the default value of "canvaskit.wasm" */
1400
- canvasKitWasmUrl: "canvaskit.wasm";
1401
- /** Use a specified session UUID, rather than create a new one */
1402
- sessionUuid?: string;
1403
- /** URL of session assets folder (which contains wasm binary), if not the default location of "assets" */
1404
- assetsUrl?: string;
1405
- /** 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. */
1406
- dataStores?: IDataStore[];
1407
- /** After the session initializes, should the session automatically start? Default is true */
1408
- autoStartAfterInit?: boolean;
1409
- /** When an activity ends or is canceled, should the session automatically go to the next activity? Default is true */
1410
- autoGoToNextActivity?: boolean;
1411
- /** After the last activity ends or is canceled, should the session automatically end? Default is true */
1412
- autoEndAfterLastActivity?: boolean;
1413
- /** NOT IMPLEMENTED YET: Orientation the screen should be locked to for this session. Value will be passed into the ScreenOrientation.lock() Web API. */
1414
- orientation?: "natural" | "landscape" | "portrait" | "portrait-primary" | "portrait-secondary" | "landscape-primary" | "landscape-secondary";
1415
- }
1416
-
1417
- declare class Session {
1418
- options: SessionOptions;
1419
- fontManager: FontManager;
1420
- imageManager: ImageManager;
1421
- currentActivity?: Activity;
1422
- uuid: string;
1423
- dataStores?: IDataStore[];
1424
- private eventListeners;
1425
- private sessionDictionary;
1426
- private canvasKit?;
1427
- private initialized;
1428
- private version;
1429
- /**
1430
- * A Session contains one or more activities. The session manages the start
1431
- * and stop of activities, and advancement to next activity
1432
- *
1433
- * @param options
1434
- */
1435
- constructor(options: SessionOptions);
1436
- /**
1437
- * Executes a callback when the session initializes.
1438
- *
1439
- * @param callback - function to execute.
1440
- * @param options - options for the callback.
1441
- */
1442
- onInitialize(callback: (sessionLifecycleEvent: SessionLifecycleEvent) => void, options?: CallbackOptions): void;
1443
- /**
1444
- * Executes a callback when the session starts.
1445
- *
1446
- * @param callback - function to execute.
1447
- * @param options - options for the callback.
1448
- */
1449
- onStart(callback: (sessionLifecycleEvent: SessionLifecycleEvent) => void, options?: CallbackOptions): void;
1450
- /**
1451
- * Executes a callback when the session ends.
1452
- *
1453
- * @param callback - function to execute.
1454
- * @param options - options for the callback.
1455
- */
1456
- onEnd(callback: (sessionLifecycleEvent: SessionLifecycleEvent) => void, options?: CallbackOptions): void;
1457
- /**
1458
- * Executes a callback when any activity in the session generates data.
1459
- *
1460
- * @param callback - function to execute.
1461
- * @param options - options for the callback.
1462
- */
1463
- onActivityData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
1464
- private addEventListener;
1465
- private raiseEventOnListeners;
1466
- private sessionActivityStartHandler;
1467
- private sessionActivityCancelHandler;
1468
- private sessionActivityEndHandler;
1469
- private sessionActivityLifecycleHandler;
1470
- private activityResultsEventHandler;
1471
- /**
1472
- * Asynchronously initializes the m2c2kit engine and loads assets
1473
- *
1474
- * @deprecated Use Session.initialize() instead.
1475
- */
1476
- init(): Promise<void>;
1477
- /**
1478
- * Check if the Activity uses the deprecated init() method.
1479
- *
1480
- * @remarks Activity.init() is deprecated and should be replaced with
1481
- * Activity.initialize().
1482
- *
1483
- * @param activity
1484
- * @returns true if the activity defines its own init() method, false otherwise.
1485
- */
1486
- private activityUsesDeprecatedInit;
1487
- /**
1488
- * Asynchronously initializes the m2c2kit engine and loads assets
1489
- */
1490
- initialize(): Promise<void>;
1555
+ addStaticTrialData(variableName: string, value: JsonSchemaDataTypeScriptTypes): void;
1491
1556
  /**
1492
- * 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.
1493
1559
  *
1494
- * @remarks Session.initialize() is asynchronous, and it should be awaited
1495
- * so that the session is fully initialized before calling Session.start().
1496
- * If it is not awaited (or it cannot be awaited because the target
1497
- * environment does not support top-level await), this function ensures that
1498
- * 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.
1499
1565
  */
1500
- private waitForSessionInitialization;
1566
+ trialComplete(): void;
1501
1567
  /**
1502
- * 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.
1503
1570
  */
1504
- start(): Promise<void>;
1571
+ private readonly automaticTrialSchema;
1572
+ private makeNewGameDataSchema;
1573
+ private makeGameDataSchema;
1505
1574
  /**
1506
- * 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
1507
1580
  */
1508
- end(): void;
1509
- private stop;
1581
+ private makeGameActivityConfiguration;
1582
+ private makeGameActivityConfigurationSchema;
1510
1583
  /**
1511
- * Frees up resources that were allocated to run the session.
1584
+ * Should be called when current game has ended successfully.
1512
1585
  *
1513
- * @remarks This will be done automatically by the m2c2kit library;
1514
- * 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.
1515
1592
  */
1516
- private dispose;
1593
+ end(): void;
1517
1594
  /**
1518
- * 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.
1519
1596
  *
1520
- * @param options
1521
- */
1522
- goToActivity(options: GoToActivityOptions): Promise<void>;
1523
- /**
1524
- * Stops the current activity and advances to next activity in the session.
1525
- * 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.
1526
1603
  */
1527
- 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;
1528
1614
  /**
1529
- * Stops the current activity and advances to next activity in the session.
1530
- * If there is no activity after the current activity, throws error.
1615
+ * Creates a scene that has a screen shot of the current scene.
1531
1616
  *
1532
- * @deprecated Use goToNextActivity() instead.
1533
- */
1534
- advanceToNextActivity(): Promise<void>;
1535
- /**
1536
- * Gets the next activity after the current one, or undefined if
1537
- * this is the last activity.
1617
+ * @param outgoingSceneImage - an image of the current scene
1618
+ * @returns - the scene with the screen shot
1538
1619
  */
1539
- get nextActivity(): Activity | undefined;
1620
+ private createOutgoingScene;
1540
1621
  /**
1541
- * Saves an item to the session's key-value dictionary.
1622
+ * Registers a plugin with the game.
1542
1623
  *
1543
- * @remarks The session dictionary is not persisted. It is available only
1544
- * during the actively running session. It is useful for storing temporary
1545
- * data to coordinate between activities.
1624
+ * @remarks Upon registration, the plugin's optional asynchronous
1625
+ * `initialize()` method will be called.
1546
1626
  *
1547
- * @param key - item key
1548
- * @param value - item value
1627
+ * @param plugin - Plugin to register
1549
1628
  */
1550
- 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;
1551
1635
  /**
1552
- * Gets an item value from the session's key-value dictionary.
1636
+ * Takes screenshot of canvas
1553
1637
  *
1554
- * @remarks The session dictionary is not persisted. It is available only
1555
- * during the actively running session. It is useful for storing temporary
1556
- * 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.
1557
1643
  *
1558
- * @param key - item key
1559
- * @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
1560
1649
  */
1561
- 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;
1562
1653
  /**
1563
- * Deletes an item value from the session's key-value dictionary.
1654
+ * Creates an event listener for a node based on the node name
1564
1655
  *
1565
- * @remarks The session dictionary is not persisted. It is available only
1566
- * during the actively running session. It is useful for storing temporary
1567
- * 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.
1568
1657
  *
1569
- * @param key - item key
1570
- * @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
1571
1662
  */
1572
- dictionaryDeleteItem(key: string): boolean;
1663
+ createEventListener(type: M2EventType, nodeName: string, callback: (event: M2NodeEvent) => void, callbackOptions?: CallbackOptions): void;
1573
1664
  /**
1574
- * Determines if a key exists in the activity's key-value dictionary.
1575
- *
1576
- * @remarks The session dictionary is not persisted. It is available only
1577
- * during the actively running session. It is useful for storing temporary
1578
- * data to coordinate between activities.
1579
- *
1580
- * @param key - item key
1581
- * @returns true if the key exists, false otherwise
1665
+ * Returns array of all nodes that have been added to the game object.
1582
1666
  */
1583
- dictionaryItemExists(key: string): boolean;
1667
+ get nodes(): Array<M2Node>;
1584
1668
  /**
1585
- * Gets asynchronous assets, including initialization of canvaskit wasm,
1586
- * fetching of fonts from specified urls, and rendering and fetching
1587
- * of images
1588
- * @returns
1669
+ * @deprecated use Game.nodes instead
1589
1670
  */
1590
- private getAsynchronousAssets;
1591
- private loadCanvasKit;
1592
- private loadAssets;
1593
- private assignCanvasKit;
1594
- private getImagesConfigurationFromGames;
1595
- prependAssetsUrl(url: string): string;
1596
- }
1597
- interface GoToActivityOptions {
1598
- /** ActivityId of the activity to go to. */
1599
- id: string;
1600
- }
1601
- /**
1602
- * Types of values that can be stored in the session dictionary.
1603
- */
1604
- type SessionDictionaryValues = string | number | boolean | object | null | undefined;
1605
-
1606
- interface Activity {
1607
- /** The type of activity: Game or Survey */
1608
- type: ActivityType;
1671
+ get entities(): Array<M2Node>;
1609
1672
  /**
1610
- * Initializes the activity.
1673
+ * Receives callback from DOM PointerDown event
1611
1674
  *
1612
- * @remarks All code to create the activity's appearance and behavior must
1613
- * be placed in this method. This method is asynchronous, and must be
1614
- * awaited. When writing a new game by extending the `Game` class, this
1615
- * method will be overridden, but the base method must still be called with
1616
- * `await super.initialize()`.
1675
+ * @param domPointerEvent - PointerEvent from the DOM
1676
+ * @returns
1617
1677
  */
1618
- initialize(): Promise<void>;
1678
+ private htmlCanvasPointerDownHandler;
1679
+ private htmlCanvasPointerUpHandler;
1680
+ private htmlCanvasPointerMoveHandler;
1681
+ private htmlCanvasPointerLeaveHandler;
1619
1682
  /**
1620
- * Initializes the activity.
1621
- *
1622
- * @remarks All code to create the activity's appearance and behavior must
1623
- * be placed in this method. This method is asynchronous, and must be
1624
- * awaited. When writing a new game by extending the `Game` class, this
1625
- * method will be overridden, but the base method must still be called with
1626
- * `await super.init()`.
1683
+ * Determines if/how m2c2kit nodes respond to the DOM PointerDown event
1627
1684
  *
1628
- * @deprecated use Game.initialize() instead.
1685
+ * @param node - node that might be affected by the DOM PointerDown event
1686
+ * @param nodeEvent
1687
+ * @param domPointerEvent
1629
1688
  */
1630
- init(): Promise<void>;
1631
- /** Starts the activity */
1632
- start(): Promise<void>;
1633
- /** Stops the activity */
1634
- 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;
1635
1706
  /**
1636
- * Executes a callback when the activity starts.
1707
+ * Executes a callback when the game starts.
1637
1708
  *
1638
1709
  * @param callback - function to execute.
1639
1710
  * @param options - options for the callback.
1640
1711
  */
1641
1712
  onStart(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1642
1713
  /**
1643
- * Executes a callback when the activity is canceled.
1714
+ * Executes a callback when the game is canceled.
1644
1715
  *
1645
1716
  * @param callback - function to execute.
1646
1717
  * @param options - options for the callback.
1647
1718
  */
1648
1719
  onCancel(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1649
1720
  /**
1650
- * Executes a callback when the activity ends.
1651
- *
1652
- * @param callback - function to execute.
1653
- * @param options - options for the callback.
1654
- */
1655
- onEnd(callback: (activityLifecycleEvent: ActivityLifecycleEvent) => void, options?: CallbackOptions): void;
1656
- /**
1657
- * Executes a callback when the activity generates data.
1721
+ * Executes a callback when the game ends.
1658
1722
  *
1659
1723
  * @param callback - function to execute.
1660
- * @param options - options for the callback.
1661
- */
1662
- onData(callback: (activityResultsEvent: ActivityResultsEvent) => void, options?: CallbackOptions): void;
1663
- /** The activity's parent session */
1664
- session: Session;
1665
- /** The activity's unique identifier. NOTE: This is newly generated each session. The uuid for an activity will vary across sessions. */
1666
- uuid: string;
1667
- /** Human-friendly name of this activity */
1668
- name: string;
1669
- /** Short identifier of this activity */
1670
- id: string;
1671
- /** The value of performance.now() immediately before the activity begins */
1672
- beginTimestamp: number;
1673
- /** The value of new Date().toISOString() immediately before the activity begins */
1674
- beginIso8601Timestamp: string;
1675
- /** Sets additional activity parameters if defaults are not sufficient. */
1676
- setParameters(additionalParameters: unknown): void;
1677
- /** Additional activity parameters that were set. */
1678
- readonly additionalParameters?: unknown;
1679
- /** Optional stores to use for saving data. The implementation of the store is not provided by the \@m2c2kit/core library. */
1680
- dataStores?: IDataStore[];
1681
- }
1682
-
1683
- /**
1684
- * Base interface for all m2c2kit events.
1685
- *
1686
- * @remarks I would have named it Event, but that would collide with
1687
- * the existing DOM Event
1688
- */
1689
- interface EventBase {
1690
- /** Type of event. */
1691
- type: EventType | string;
1692
- /** The object on which the event occurred. */
1693
- target: Entity | Session | Activity | Plugin;
1694
- /** Has the event been taken care of by the listener and not be dispatched to other targets? */
1695
- handled?: boolean;
1696
- }
1697
- /**
1698
- * The different events that are dispatched by m2c2kit core.
1699
- */
1700
- declare const EventType: {
1701
- readonly SessionInitialize: "SessionInitialize";
1702
- readonly SessionStart: "SessionStart";
1703
- readonly SessionEnd: "SessionEnd";
1704
- readonly ActivityStart: "ActivityStart";
1705
- readonly ActivityEnd: "ActivityEnd";
1706
- readonly ActivityCancel: "ActivityCancel";
1707
- readonly ActivityData: "ActivityData";
1708
- readonly TapDown: "TapDown";
1709
- readonly TapUp: "TapUp";
1710
- readonly TapUpAny: "TapUpAny";
1711
- readonly TapLeave: "TapLeave";
1712
- readonly PointerDown: "PointerDown";
1713
- readonly PointerUp: "PointerUp";
1714
- readonly PointerMove: "PointerMove";
1715
- readonly PointerLeave: "PointerLeave";
1716
- readonly Drag: "Drag";
1717
- readonly DragStart: "DragStart";
1718
- readonly DragEnd: "DragEnd";
1719
- readonly CompositeCustom: "CompositeCustom";
1720
- readonly FrameDidSimulatePhysics: "FrameDidSimulatePhysics";
1721
- };
1722
- type EventType = (typeof EventType)[keyof typeof EventType];
1723
-
1724
- interface EntityEventListener {
1725
- type: EventType | string;
1726
- /** For composites that raise events, type of the composite custom event. */
1727
- compositeType?: string;
1728
- entityUuid: string;
1729
- callback: (event: EntityEvent) => void;
1730
- }
1731
-
1732
- /**
1733
- * Describes an interaction between the pointer (mouse, touches) and an entity.
1734
- *
1735
- * @remarks I would have named it PointerEvent, but that would collide with
1736
- * the existing DOM PointerEvent.
1737
- */
1738
- interface M2PointerEvent extends EntityEvent {
1739
- /** Point that was tapped on entity, relative to the entity coordinate system */
1740
- point: Point;
1741
- /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
1742
- buttons: number;
1743
- }
1744
-
1745
- /**
1746
- * Describes an interaction of a pointer (mouse, touches) pressing an entity.
1747
- *
1748
- * @remarks Unlike M2PointerEvent, TapEvent considers how the pointer, while
1749
- * in the down state, moves in relation to the bounds of the entity.
1750
- */
1751
- interface TapEvent extends EntityEvent {
1752
- /** Point that was tapped on entity, relative to the entity coordinate system */
1753
- point: Point;
1754
- /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons */
1755
- buttons: number;
1756
- }
1757
-
1758
- interface TextOptions {
1759
- /** Text to be displayed */
1760
- text?: string;
1761
- /** Name of font to use for text. Must have been previously loaded */
1762
- fontName?: string;
1763
- /** Color of text. Default is Constants.DEFAULT_FONT_COLOR (WebColors.Black) */
1764
- fontColor?: RgbaColor;
1765
- /** Size of text. Default is Constants.DEFAULT_FONT_SIZE (16) */
1766
- fontSize?: number;
1767
- }
1768
-
1769
- /**
1770
- * Width and height on two-dimensional space
1771
- */
1772
- interface Size {
1773
- /** Horizontal width, x-axis */
1774
- width: number;
1775
- /** Vertical height, y-axis */
1776
- height: number;
1724
+ * @param options - options for the callback.
1725
+ */
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;
1777
1766
  }
1778
1767
 
1779
1768
  /**
@@ -1782,16 +1771,16 @@ interface Size {
1782
1771
  * @remarks I would have named it DragEvent, but that would collide with
1783
1772
  * the existing DOM DragEvent.
1784
1773
  */
1785
- interface M2DragEvent extends EntityEvent {
1786
- /** 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. */
1787
1776
  position: Point;
1788
1777
  /** Buttons being pressed when event was fired. Taken from DOM MouseEvent.buttons. */
1789
1778
  buttons: number;
1790
1779
  }
1791
1780
 
1792
- declare function handleInterfaceOptions(entity: Entity, options: EntityOptions): void;
1793
- declare abstract class Entity implements EntityOptions {
1794
- type: EntityType;
1781
+ declare function handleInterfaceOptions(node: M2Node, options: M2NodeOptions): void;
1782
+ declare abstract class M2Node implements M2NodeOptions {
1783
+ type: M2NodeType;
1795
1784
  isDrawable: boolean;
1796
1785
  isShape: boolean;
1797
1786
  isText: boolean;
@@ -1805,8 +1794,8 @@ declare abstract class Entity implements EntityOptions {
1805
1794
  hidden: boolean;
1806
1795
  layout: Layout;
1807
1796
  _game?: Game;
1808
- parent?: Entity;
1809
- children: Entity[];
1797
+ parent?: M2Node;
1798
+ children: M2Node[];
1810
1799
  absolutePosition: Point;
1811
1800
  size: Size;
1812
1801
  absoluteScale: number;
@@ -1815,100 +1804,100 @@ declare abstract class Entity implements EntityOptions {
1815
1804
  actions: Action[];
1816
1805
  queuedAction?: Action;
1817
1806
  originalActions: Action[];
1818
- eventListeners: EntityEventListener[];
1807
+ eventListeners: M2NodeEventListener<M2NodeEvent>[];
1819
1808
  readonly uuid: string;
1820
1809
  needsInitialization: boolean;
1821
1810
  userData: any;
1822
1811
  loopMessages: Set<string>;
1823
- /** Is the entity in a pressed state? E.g., did the user put the pointer
1824
- * 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? */
1825
1814
  pressed: boolean;
1826
1815
  withinHitArea: boolean;
1827
- /** Is the entity in a pressed state AND is the pointer within the entity's
1828
- * hit area? For example, a user may put the pointer down on the entity, but
1829
- * 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
1830
1819
  * this case, pressed = true, but pressedAndWithinHitArea = false. */
1831
1820
  pressedAndWithinHitArea: boolean;
1832
- /** 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
1833
1822
  * offset? (offset from the canvas's origin to the pointer position). We
1834
1823
  * save this because it will be needed if this press then led to a drag. */
1835
1824
  pressedInitialPointerOffset: Point;
1836
- /** 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
1837
1826
  * state? */
1838
1827
  draggingLastPointerOffset: Point;
1839
- /** Is the entity in a dragging state? */
1828
+ /** Is the node in a dragging state? */
1840
1829
  dragging: boolean;
1841
- constructor(options?: EntityOptions);
1830
+ constructor(options?: M2NodeOptions);
1842
1831
  initialize(): void;
1843
1832
  /**
1844
- * The game which this entity is a part of.
1833
+ * The game which this node is a part of.
1845
1834
  *
1846
- * @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.
1847
1836
  */
1848
1837
  get game(): Game;
1849
1838
  /**
1850
- * Determines if the entity has been added to the game object.
1839
+ * Determines if the node has been added to the game object.
1851
1840
  *
1852
- * @returns true if entity has been added
1841
+ * @returns true if node has been added
1853
1842
  */
1854
1843
  private isPartOfGame;
1855
1844
  /**
1856
- * Overrides toString() and returns a human-friendly description of the entity.
1845
+ * Overrides toString() and returns a human-friendly description of the node.
1857
1846
  *
1858
1847
  * @remarks Inspiration from https://stackoverflow.com/a/35361695
1859
1848
  */
1860
1849
  toString: () => string;
1861
1850
  /**
1862
- * 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
1863
1852
  * is not unique with respect to other children of this parent, or if the
1864
1853
  * child has already been added to another parent.
1865
1854
  *
1866
- * @param child - The child entity to add
1855
+ * @param child - The child node to add
1867
1856
  */
1868
- addChild(child: Entity): void;
1857
+ addChild(child: M2Node): void;
1869
1858
  /**
1870
- * Removes all children from the entity.
1859
+ * Removes all children from the node.
1871
1860
  */
1872
1861
  removeAllChildren(): void;
1873
1862
  /**
1874
- * Removes the specific child from this parent entity. Throws exception if
1863
+ * Removes the specific child from this parent node. Throws exception if
1875
1864
  * this parent does not contain the child.
1876
1865
  *
1877
1866
  * @param child
1878
1867
  */
1879
- removeChild(child: Entity): void;
1868
+ removeChild(child: M2Node): void;
1880
1869
  /**
1881
1870
  * Removes the children from the parent. Throws error if the parent does not
1882
1871
  * contain all of the children.
1883
1872
  *
1884
- * @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
1885
1874
  */
1886
- removeChildren(children: Array<Entity>): void;
1875
+ removeChildren(children: Array<M2Node>): void;
1887
1876
  /**
1888
- * Searches all descendants by name and returns first matching entity.
1877
+ * Searches all descendants by name and returns first matching node.
1889
1878
  *
1890
1879
  * @remarks Descendants are children and children of children, recursively.
1891
1880
  * Throws exception if no descendant with the given name is found.
1892
1881
  *
1893
- * @param name - Name of the descendant entity to return
1882
+ * @param name - Name of the descendant node to return
1894
1883
  * @returns
1895
1884
  */
1896
- descendant<T extends Entity>(name: string): T;
1885
+ descendant<T extends M2Node>(name: string): T;
1897
1886
  /**
1898
- * Returns all descendant entities.
1887
+ * Returns all descendant nodes.
1899
1888
  *
1900
1889
  * @remarks Descendants are children and children of children, recursively.
1901
1890
  */
1902
- get descendants(): Array<Entity>;
1891
+ get descendants(): Array<M2Node>;
1903
1892
  /**
1904
- * Returns all ancestor entities, not including the entity itself.
1893
+ * Returns all ancestor nodes, not including the node itself.
1905
1894
  */
1906
- get ancestors(): Array<Entity>;
1895
+ get ancestors(): Array<M2Node>;
1907
1896
  /**
1908
- * 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
1909
1898
  * affects it appearance.
1910
1899
  *
1911
- * @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
1912
1901
  * anti-aliasing or not. Anti-aliasing on some devices causes a new shader
1913
1902
  * to be compiled during the action, which causes jank.
1914
1903
  *
@@ -1916,17 +1905,17 @@ declare abstract class Entity implements EntityOptions {
1916
1905
  */
1917
1906
  involvedInActionAffectingAppearance(): boolean;
1918
1907
  /**
1919
- * 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
1920
1909
  * transitioning Scene.
1921
1910
  *
1922
1911
  * @returns true if transitioning
1923
1912
  */
1924
1913
  involvedInSceneTransition(): boolean;
1925
1914
  /**
1926
- * Executes a callback when the user presses down on the entity.
1915
+ * Executes a callback when the user presses down on the node.
1927
1916
  *
1928
1917
  * @remarks TapDown is a pointer down (mouse click or touches begin) within
1929
- * the bounds of the entity.
1918
+ * the bounds of the node.
1930
1919
  *
1931
1920
  * @param callback - function to execute
1932
1921
  * @param options - {@link CallbackOptions}
@@ -1934,23 +1923,23 @@ declare abstract class Entity implements EntityOptions {
1934
1923
  onTapDown(callback: (tapEvent: TapEvent) => void, options?: CallbackOptions): void;
1935
1924
  /**
1936
1925
  * Executes a callback when the user releases a press, that has been fully
1937
- * within the entity, from the entity.
1926
+ * within the node, from the node.
1938
1927
  *
1939
1928
  * @remarks TapUp is a pointer up (mouse click release or touches end) within
1940
- * the bounds of the entity and the pointer, while down, has never moved
1941
- * 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.
1942
1931
  *
1943
1932
  * @param callback - function to execute
1944
1933
  * @param options - {@link CallbackOptions}ue.
1945
1934
  */
1946
1935
  onTapUp(callback: (tapEvent: TapEvent) => void, options?: CallbackOptions): void;
1947
1936
  /**
1948
- * Executes a callback when the user releases a press from the entity within
1949
- * 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.
1950
1939
  *
1951
1940
  * @remarks TapUpAny is a pointer up (mouse click release or touches end)
1952
- * within the bounds of the entity and the pointer, while down, is allowed to
1953
- * 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
1954
1943
  * release.
1955
1944
  *
1956
1945
  * @param callback - function to execute
@@ -1959,10 +1948,10 @@ declare abstract class Entity implements EntityOptions {
1959
1948
  onTapUpAny(callback: (tapEvent: TapEvent) => void, options?: CallbackOptions): void;
1960
1949
  /**
1961
1950
  * Executes a callback when the user moves the pointer (mouse, touches) beyond
1962
- * the bounds of the entity while the pointer is down.
1951
+ * the bounds of the node while the pointer is down.
1963
1952
  *
1964
1953
  * @remarks TapLeave occurs when the pointer (mouse, touches) that has
1965
- * previously pressed the entity moves beyond the bounds of the entity
1954
+ * previously pressed the node moves beyond the bounds of the node
1966
1955
  * before the press release.
1967
1956
  *
1968
1957
  * @param callback - function to execute
@@ -1970,22 +1959,22 @@ declare abstract class Entity implements EntityOptions {
1970
1959
  */
1971
1960
  onTapLeave(callback: (tapEvent: TapEvent) => void, options?: CallbackOptions): void;
1972
1961
  /**
1973
- * 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.
1974
1963
  *
1975
1964
  * @remarks PointerDown is a pointer down (mouse click or touches begin) within
1976
- * 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.
1977
1966
  *
1978
1967
  * @param callback - function to execute
1979
1968
  * @param options - {@link CallbackOptions}
1980
1969
  */
1981
1970
  onPointerDown(callback: (m2PointerEvent: M2PointerEvent) => void, options?: CallbackOptions): void;
1982
1971
  /**
1983
- * Executes a callback when the user releases a press from the entity within
1984
- * 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.
1985
1974
  *
1986
1975
  * @remarks PointerUp is a pointer up (mouse click release or touches end)
1987
- * within the bounds of the entity. It does not require that there was a
1988
- * 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.
1989
1978
  *
1990
1979
  * @param callback - function to execute
1991
1980
  * @param options - {@link CallbackOptions}
@@ -1993,7 +1982,7 @@ declare abstract class Entity implements EntityOptions {
1993
1982
  onPointerUp(callback: (m2PointerEvent: M2PointerEvent) => void, options?: CallbackOptions): void;
1994
1983
  /**
1995
1984
  * Executes a callback when the user moves the pointer (mouse or touches)
1996
- * within the bounds of the entity.
1985
+ * within the bounds of the node.
1997
1986
  *
1998
1987
  * @param callback - function to execute
1999
1988
  * @param options - {@link CallbackOptions}
@@ -2001,62 +1990,62 @@ declare abstract class Entity implements EntityOptions {
2001
1990
  onPointerMove(callback: (m2PointerEvent: M2PointerEvent) => void, options?: CallbackOptions): void;
2002
1991
  /**
2003
1992
  * Executes a callback when the user moves the pointer (mouse or touches)
2004
- * outside the bounds of the entity.
1993
+ * outside the bounds of the node.
2005
1994
  *
2006
1995
  * @param callback - function to execute
2007
1996
  * @param options - {@link CallbackOptions}
2008
1997
  */
2009
1998
  onPointerLeave(callback: (m2PointerEvent: M2PointerEvent) => void, options?: CallbackOptions): void;
2010
1999
  /**
2011
- * Executes a callback when the user begins dragging an entity.
2000
+ * Executes a callback when the user begins dragging a node.
2012
2001
  *
2013
2002
  * @param callback - function to execute
2014
2003
  * @param options - {@link CallbackOptions}
2015
2004
  */
2016
2005
  onDragStart(callback: (m2DragEvent: M2DragEvent) => void, options?: CallbackOptions): void;
2017
2006
  /**
2018
- * Executes a callback when the user continues dragging an entity.
2007
+ * Executes a callback when the user continues dragging a node.
2019
2008
  *
2020
2009
  * @param callback - function to execute
2021
2010
  * @param options - {@link CallbackOptions}
2022
2011
  */
2023
2012
  onDrag(callback: (m2DragEvent: M2DragEvent) => void, options?: CallbackOptions): void;
2024
2013
  /**
2025
- * Executes a callback when the user stop dragging an entity.
2014
+ * Executes a callback when the user stop dragging a node.
2026
2015
  *
2027
2016
  * @param callback - function to execute
2028
2017
  * @param options - {@link CallbackOptions}
2029
2018
  */
2030
2019
  onDragEnd(callback: (m2DragEvent: M2DragEvent) => void, options?: CallbackOptions): void;
2031
- 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;
2032
2021
  private parseLayoutConstraints;
2033
2022
  private calculateYFromConstraint;
2034
2023
  private calculateXFromConstraint;
2035
2024
  /**
2036
- * Calculates the absolute alpha of the entity, taking into account the
2037
- * 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.
2038
2027
  *
2039
2028
  * @remarks Alpha has multiplicative inheritance from all ancestors.
2040
2029
  *
2041
- * @param alpha - Opacity of the entity
2042
- * @param ancestors - Array of ancestor parent entities
2030
+ * @param alpha - Opacity of the node
2031
+ * @param ancestors - Array of ancestor parent nodes
2043
2032
  * @returns
2044
2033
  */
2045
2034
  private calculateAbsoluteAlpha;
2046
2035
  update(): void;
2047
2036
  /**
2048
- * 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
2049
2038
  * order (highest zPosition on top).
2050
2039
  *
2051
2040
  * @param canvas - CanvasKit canvas
2052
2041
  */
2053
2042
  drawChildren(canvas: Canvas): void;
2054
2043
  /**
2055
- * Runs an action on this entity.
2044
+ * Runs an action on this node.
2056
2045
  *
2057
- * @remarks If the entity is part of an active scene, the action runs
2058
- * immediately. Otherwise, the action will run when the entity's scene
2059
- * 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
2060
2049
  * to existing actions, not replace them.
2061
2050
  *
2062
2051
  * @param action - The action to run
@@ -2065,38 +2054,38 @@ declare abstract class Entity implements EntityOptions {
2065
2054
  */
2066
2055
  run(action: Action, key?: string): void;
2067
2056
  /**
2068
- * 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
2069
2058
  * stopped.
2070
2059
  *
2071
2060
  * @param key - key (string identifier) of the action to remove
2072
2061
  */
2073
2062
  removeAction(key: string): void;
2074
2063
  /**
2075
- * 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
2076
2065
  * stopped.
2077
2066
  */
2078
2067
  removeAllActions(): void;
2079
2068
  /**
2080
- * Duplicates an entity using deep copy.
2069
+ * Duplicates a node using deep copy.
2081
2070
  *
2082
- * @remarks This is a deep recursive clone (entity and children).
2083
- * 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,
2084
2073
  * because uuid must be unique.
2085
2074
  *
2086
- * @param newName - optional name of the new, duplicated entity. If not
2075
+ * @param newName - optional name of the new, duplicated node. If not
2087
2076
  * provided, name will be the new uuid
2088
2077
  */
2089
- abstract duplicate(newName?: string): Entity;
2090
- protected getEntityOptions(): EntityOptions;
2078
+ abstract duplicate(newName?: string): M2Node;
2079
+ protected getNodeOptions(): M2NodeOptions;
2091
2080
  protected getDrawableOptions(): DrawableOptions;
2092
2081
  protected getTextOptions(): TextOptions;
2093
2082
  /**
2094
- * 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.
2095
2084
  *
2096
- * @returns Scene that contains this entity
2085
+ * @returns Scene that contains this node
2097
2086
  */
2098
2087
  get canvasKit(): CanvasKit;
2099
- get parentSceneAsEntity(): Entity;
2088
+ get parentSceneAsNode(): M2Node;
2100
2089
  get position(): Point;
2101
2090
  set position(position: Point);
2102
2091
  get zRotation(): number;
@@ -2111,7 +2100,7 @@ declare abstract class Entity implements EntityOptions {
2111
2100
  }
2112
2101
 
2113
2102
  interface MoveActionOptions {
2114
- /** 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 */
2115
2104
  point: Point;
2116
2105
  /** Duration of move, in milliseconds */
2117
2106
  duration: number;
@@ -2145,7 +2134,7 @@ interface ScaleActionOptions {
2145
2134
  }
2146
2135
 
2147
2136
  interface FadeAlphaActionOptions {
2148
- /** 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. */
2149
2138
  alpha: number;
2150
2139
  /** Duration of scale, in milliseconds */
2151
2140
  duration: number;
@@ -2154,9 +2143,9 @@ interface FadeAlphaActionOptions {
2154
2143
  }
2155
2144
 
2156
2145
  interface RotateActionOptions {
2157
- /** Relative amount to rotate the entity, in counter-clockwise radians */
2146
+ /** Relative amount to rotate the node, in counter-clockwise radians */
2158
2147
  byAngle?: number;
2159
- /** Absolute angle to which rotate the entity, in counter-clockwise radians */
2148
+ /** Absolute angle to which rotate the node, in counter-clockwise radians */
2160
2149
  toAngle?: number;
2161
2150
  /** If `toAngle` is provided, should the rotation be performed in the direction that leads to the smallest rotation? Default is true */
2162
2151
  shortestUnitArc?: boolean;
@@ -2184,7 +2173,7 @@ declare enum ActionType {
2184
2173
 
2185
2174
  /**
2186
2175
  * The Action class has static methods for creating actions to be executed by
2187
- * an Entity.
2176
+ * an M2Node.
2188
2177
  */
2189
2178
  declare abstract class Action {
2190
2179
  abstract type: ActionType;
@@ -2202,7 +2191,7 @@ declare abstract class Action {
2202
2191
  key?: string;
2203
2192
  constructor(runDuringTransition?: boolean);
2204
2193
  /**
2205
- * 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.
2206
2195
  *
2207
2196
  * @param options - {@link MoveActionOptions}
2208
2197
  * @returns The move action
@@ -2223,27 +2212,27 @@ declare abstract class Action {
2223
2212
  */
2224
2213
  static custom(options: CustomActionOptions): Action;
2225
2214
  /**
2226
- * Creates an action that will scale the entity's size.
2215
+ * Creates an action that will scale the node's size.
2227
2216
  *
2228
- * @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.
2229
2218
  *
2230
2219
  * @param options - {@link ScaleActionOptions}
2231
2220
  * @returns The scale action
2232
2221
  */
2233
2222
  static scale(options: ScaleActionOptions): Action;
2234
2223
  /**
2235
- * Creates an action that will change the entity's alpha (opacity).
2224
+ * Creates an action that will change the node's alpha (opacity).
2236
2225
  *
2237
- * @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.
2238
2227
  *
2239
2228
  * @param options - {@link FadeAlphaActionOptions}
2240
2229
  * @returns The fadeAlpha action
2241
2230
  */
2242
2231
  static fadeAlpha(options: FadeAlphaActionOptions): Action;
2243
2232
  /**
2244
- * Creates an action that will rotate the entity.
2233
+ * Creates an action that will rotate the node.
2245
2234
  *
2246
- * @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.
2247
2236
  *
2248
2237
  * @param options - {@link RotateActionOptions}
2249
2238
  * @returns The rotate action
@@ -2267,9 +2256,9 @@ declare abstract class Action {
2267
2256
  * @returns
2268
2257
  */
2269
2258
  static group(actions: Array<Action>): Action;
2270
- initialize(entity: Entity, key?: string): Array<Action>;
2259
+ initialize(node: M2Node, key?: string): Array<Action>;
2271
2260
  static cloneAction(action: Action, key?: string): Action;
2272
- static evaluateAction(action: Action, entity: Entity, now: number, dt: number): void;
2261
+ static evaluateAction(action: Action, node: M2Node, now: number, dt: number): void;
2273
2262
  /**
2274
2263
  * Calculates the duration of an action, including any children actions
2275
2264
  * the action may contain.
@@ -2365,6 +2354,18 @@ declare class RotateAction extends Action {
2365
2354
  constructor(byAngle: number | undefined, toAngle: number | undefined, shortestUnitArc: boolean | undefined, duration: number, runDuringTransition?: boolean);
2366
2355
  }
2367
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
+
2368
2369
  declare class CanvasKitHelpers {
2369
2370
  /**
2370
2371
  * Frees up resources that were allocated by CanvasKit.
@@ -2373,7 +2374,7 @@ declare class CanvasKitHelpers {
2373
2374
  * canvaskit-wasm. JavaScript garbage collection won't
2374
2375
  * free these wasm objects.
2375
2376
  */
2376
- 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;
2377
2378
  static makePaint(canvasKit: CanvasKit, color: RgbaColor, style: PaintStyle, isAntialiased: boolean): Paint;
2378
2379
  }
2379
2380
 
@@ -2472,17 +2473,17 @@ declare class ColorfulMutablePath extends MutablePath {
2472
2473
  duplicate(): ColorfulMutablePath;
2473
2474
  }
2474
2475
 
2475
- interface CompositeOptions extends EntityOptions, DrawableOptions {
2476
+ interface CompositeOptions extends M2NodeOptions, DrawableOptions {
2476
2477
  }
2477
2478
 
2478
- declare abstract class Composite extends Entity implements IDrawable {
2479
- readonly type = EntityType.Composite;
2479
+ declare abstract class Composite extends M2Node implements IDrawable {
2480
+ readonly type = M2NodeType.Composite;
2480
2481
  compositeType: string;
2481
2482
  isDrawable: boolean;
2482
2483
  anchorPoint: Point;
2483
2484
  zPosition: number;
2484
2485
  /**
2485
- * 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.
2486
2487
  *
2487
2488
  * @param options
2488
2489
  */
@@ -2521,11 +2522,14 @@ declare class Constants {
2521
2522
  /** Font size in Label and TextLine, if none is specified. */
2522
2523
  static readonly DEFAULT_FONT_SIZE = 16;
2523
2524
  static readonly LIMITED_FPS_RATE = 5;
2524
- static readonly FREE_ENTITIES_SCENE_NAME = "__freeEntitiesScene";
2525
+ static readonly FREE_NODES_SCENE_NAME = "__freeNodesScene";
2525
2526
  static readonly OUTGOING_SCENE_NAME = "__outgoingScene";
2526
2527
  static readonly OUTGOING_SCENE_SPRITE_NAME = "__outgoingSceneSprite";
2527
2528
  static readonly OUTGOING_SCENE_IMAGE_NAME = "__outgoingSceneSnapshot";
2528
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";
2529
2533
  }
2530
2534
 
2531
2535
  /**
@@ -2568,10 +2572,187 @@ declare class Equals {
2568
2572
  static rgbaColor(color1?: RgbaColor, color2?: RgbaColor): boolean;
2569
2573
  }
2570
2574
 
2571
- interface EventListenerBase {
2572
- type: EventType;
2573
- callback: (event: EventBase) => void;
2574
- 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;
2575
2756
  }
2576
2757
 
2577
2758
  interface IText {
@@ -2587,7 +2768,7 @@ declare enum LabelHorizontalAlignmentMode {
2587
2768
  Right = 2
2588
2769
  }
2589
2770
 
2590
- interface LabelOptions extends EntityOptions, DrawableOptions, TextOptions {
2771
+ interface LabelOptions extends M2NodeOptions, DrawableOptions, TextOptions {
2591
2772
  /** Horizontal alignment of label text. see {@link LabelHorizontalAlignmentMode}. Default is LabelHorizontalAlignmentMode.center */
2592
2773
  horizontalAlignmentMode?: LabelHorizontalAlignmentMode;
2593
2774
  /** Maximum width of label text before wrapping occurs. Default is the canvas width */
@@ -2598,8 +2779,8 @@ interface LabelOptions extends EntityOptions, DrawableOptions, TextOptions {
2598
2779
  fontNames?: Array<string>;
2599
2780
  }
2600
2781
 
2601
- declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2602
- readonly type = EntityType.Label;
2782
+ declare class Label extends M2Node implements IDrawable, IText, LabelOptions {
2783
+ readonly type = M2NodeType.Label;
2603
2784
  isDrawable: boolean;
2604
2785
  isText: boolean;
2605
2786
  anchorPoint: {
@@ -2630,6 +2811,17 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2630
2811
  */
2631
2812
  constructor(options?: LabelOptions);
2632
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;
2633
2825
  dispose(): void;
2634
2826
  get text(): string;
2635
2827
  set text(text: string);
@@ -2653,13 +2845,13 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2653
2845
  private get fontPaint();
2654
2846
  private set fontPaint(value);
2655
2847
  /**
2656
- * Duplicates an entity using deep copy.
2848
+ * Duplicates a node using deep copy.
2657
2849
  *
2658
- * @remarks This is a deep recursive clone (entity and children).
2659
- * 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,
2660
2852
  * because uuid must be unique.
2661
2853
  *
2662
- * @param newName - optional name of the new, duplicated entity. If not
2854
+ * @param newName - optional name of the new, duplicated node. If not
2663
2855
  * provided, name will be the new uuid
2664
2856
  */
2665
2857
  duplicate(newName?: string): Label;
@@ -2672,23 +2864,143 @@ declare class Label extends Entity implements IDrawable, IText, LabelOptions {
2672
2864
  * This class is used internally for processing layout constraints that
2673
2865
  * have been defined according to the Constraints interface.
2674
2866
  *
2675
- * 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
2676
2868
  * using its position property. A's position is set using the layout
2677
- * constraint "bottomToTopOf B." A is the focal entity in this example.
2869
+ * constraint "bottomToTopOf B." A is the focal node in this example.
2678
2870
  * What this means is that A's y coordinate will be computed such that
2679
2871
  * the bottom of A is the top of B. If A and B are squares, then A sits
2680
2872
  * on top of B with no gap.
2681
2873
  */
2682
2874
  declare class LayoutConstraint {
2683
2875
  type: ConstraintType;
2684
- alterEntity: Entity;
2876
+ alterNode: M2Node;
2685
2877
  verticalConstraint: boolean;
2686
- focalEntityMinimum: boolean;
2687
- alterEntityMinimum: boolean;
2878
+ focalNodeMinimum: boolean;
2879
+ alterNodeMinimum: boolean;
2688
2880
  verticalTypes: ConstraintType[];
2689
- focalEntityMinimumTypes: ConstraintType[];
2690
- alterEntityMinimumTypes: ConstraintType[];
2691
- 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;
2692
3004
  }
2693
3005
 
2694
3006
  /**
@@ -2702,6 +3014,11 @@ interface M2ColorfulPath extends M2Path {
2702
3014
  linePresentations: Array<LinePresentation>;
2703
3015
  }
2704
3016
 
3017
+ /** Base interface for all Plugin events. */
3018
+ interface PluginEvent extends M2Event<Plugin> {
3019
+ target: Plugin;
3020
+ }
3021
+
2705
3022
  declare class RandomDraws {
2706
3023
  /**
2707
3024
  * Draws a single random integer from a uniform distribution of integers in
@@ -2780,7 +3097,7 @@ interface SvgStringPath {
2780
3097
  width?: number;
2781
3098
  }
2782
3099
 
2783
- interface ShapeOptions extends EntityOptions, DrawableOptions {
3100
+ interface ShapeOptions extends M2NodeOptions, DrawableOptions {
2784
3101
  shapeType?: ShapeType;
2785
3102
  /** If provided, shape will be a circle with given radius */
2786
3103
  circleOfRadius?: number;
@@ -2802,8 +3119,8 @@ interface ShapeOptions extends EntityOptions, DrawableOptions {
2802
3119
  isAntialiased?: boolean;
2803
3120
  }
2804
3121
 
2805
- declare class Shape extends Entity implements IDrawable, ShapeOptions {
2806
- readonly type = EntityType.Shape;
3122
+ declare class Shape extends M2Node implements IDrawable, ShapeOptions {
3123
+ readonly type = M2NodeType.Shape;
2807
3124
  isDrawable: boolean;
2808
3125
  isShape: boolean;
2809
3126
  anchorPoint: {
@@ -2845,13 +3162,13 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2845
3162
  initialize(): void;
2846
3163
  dispose(): void;
2847
3164
  /**
2848
- * Duplicates an entity using deep copy.
3165
+ * Duplicates a node using deep copy.
2849
3166
  *
2850
- * @remarks This is a deep recursive clone (entity and children).
2851
- * 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,
2852
3169
  * because uuid must be unique.
2853
3170
  *
2854
- * @param newName - optional name of the new, duplicated entity. If not
3171
+ * @param newName - optional name of the new, duplicated node. If not
2855
3172
  * provided, name will be the new uuid
2856
3173
  */
2857
3174
  duplicate(newName?: string): Shape;
@@ -2896,13 +3213,13 @@ declare class Shape extends Entity implements IDrawable, ShapeOptions {
2896
3213
  set strokeColorPaintNotAntialiased(value: Paint);
2897
3214
  }
2898
3215
 
2899
- interface SpriteOptions extends EntityOptions, DrawableOptions {
3216
+ interface SpriteOptions extends M2NodeOptions, DrawableOptions {
2900
3217
  /** Name of image to use for sprite. Must have been previously loaded */
2901
3218
  imageName?: string;
2902
3219
  }
2903
3220
 
2904
- declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2905
- readonly type = EntityType.Sprite;
3221
+ declare class Sprite extends M2Node implements IDrawable, SpriteOptions {
3222
+ readonly type = M2NodeType.Sprite;
2906
3223
  isDrawable: boolean;
2907
3224
  anchorPoint: {
2908
3225
  x: number;
@@ -2910,7 +3227,7 @@ declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2910
3227
  };
2911
3228
  zPosition: number;
2912
3229
  private _imageName;
2913
- private loadedImage?;
3230
+ private m2Image?;
2914
3231
  private _paint?;
2915
3232
  /**
2916
3233
  * Visual image displayed on the screen.
@@ -2927,13 +3244,13 @@ declare class Sprite extends Entity implements IDrawable, SpriteOptions {
2927
3244
  private set paint(value);
2928
3245
  private get paint();
2929
3246
  /**
2930
- * Duplicates an entity using deep copy.
3247
+ * Duplicates a node using deep copy.
2931
3248
  *
2932
- * @remarks This is a deep recursive clone (entity and children).
2933
- * 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,
2934
3251
  * because uuid must be unique.
2935
3252
  *
2936
- * @param newName - optional name of the new, duplicated entity. If not
3253
+ * @param newName - optional name of the new, duplicated node. If not
2937
3254
  * provided, name will be the new uuid
2938
3255
  */
2939
3256
  duplicate(newName?: string): Sprite;
@@ -2947,15 +3264,15 @@ interface StoryOptions {
2947
3264
  }
2948
3265
 
2949
3266
  declare abstract class Story {
2950
- static Create(options: StoryOptions): Array<Scene>;
3267
+ static create(options?: StoryOptions): Array<Scene>;
2951
3268
  }
2952
3269
 
2953
- interface TextLineOptions extends EntityOptions, DrawableOptions, TextOptions {
3270
+ interface TextLineOptions extends M2NodeOptions, DrawableOptions, TextOptions {
2954
3271
  width?: number;
2955
3272
  }
2956
3273
 
2957
- declare class TextLine extends Entity implements IDrawable, IText, TextLineOptions {
2958
- readonly type = EntityType.TextLine;
3274
+ declare class TextLine extends M2Node implements IDrawable, IText, TextLineOptions {
3275
+ readonly type = M2NodeType.TextLine;
2959
3276
  isDrawable: boolean;
2960
3277
  isText: boolean;
2961
3278
  zPosition: number;
@@ -2991,15 +3308,26 @@ declare class TextLine extends Entity implements IDrawable, IText, TextLineOptio
2991
3308
  set fontSize(fontSize: number);
2992
3309
  update(): void;
2993
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;
2994
3322
  dispose(): void;
2995
3323
  /**
2996
- * Duplicates an entity using deep copy.
3324
+ * Duplicates a node using deep copy.
2997
3325
  *
2998
- * @remarks This is a deep recursive clone (entity and children).
2999
- * 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,
3000
3328
  * because uuid must be unique.
3001
3329
  *
3002
- * @param newName - optional name of the new, duplicated entity. If not
3330
+ * @param newName - optional name of the new, duplicated node. If not
3003
3331
  * provided, name will be the new uuid
3004
3332
  */
3005
3333
  duplicate(newName?: string): TextLine;
@@ -3007,6 +3335,9 @@ declare class TextLine extends Entity implements IDrawable, IText, TextLineOptio
3007
3335
  warmup(canvas: Canvas): void;
3008
3336
  }
3009
3337
 
3338
+ /**
3339
+ * A class to create, start, and stop named timers that measure elapsed time in milliseconds.
3340
+ */
3010
3341
  declare class Timer {
3011
3342
  private startTime;
3012
3343
  private stopTime;
@@ -3019,7 +3350,7 @@ declare class Timer {
3019
3350
  private cumulativeElapsed;
3020
3351
  private name;
3021
3352
  private static _timers;
3022
- constructor(name: string);
3353
+ private constructor();
3023
3354
  /**
3024
3355
  * Aliases performance.now()
3025
3356
  *
@@ -3033,11 +3364,31 @@ declare class Timer {
3033
3364
  */
3034
3365
  static now(): number;
3035
3366
  /**
3036
- * Starts a millisecond-resolution timer based on
3367
+ * Creates, but does not start, a new millisecond-resolution timer based on
3037
3368
  * [performance.now()](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now).
3038
3369
  *
3039
- * @remarks The method throws an error if a timer with the given
3040
- * 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.
3041
3392
  *
3042
3393
  * @param name - The name of the timer to be started
3043
3394
  */
@@ -3052,17 +3403,6 @@ declare class Timer {
3052
3403
  * @param name - The name of the timer to be stopped
3053
3404
  */
3054
3405
  static stop(name: string): void;
3055
- /**
3056
- * Restarts a timer.
3057
- *
3058
- * @remarks The timer elapsed duration is set to 0 and it starts anew.
3059
- * The method throws an error if a timer with the given
3060
- * name does not exist (if there is not a started or stopped timer
3061
- * with the given name).
3062
- *
3063
- * @param name - The name of the timer to be restarted
3064
- */
3065
- static restart(name: string): void;
3066
3406
  /**
3067
3407
  * Returns the total time elapsed, in milliseconds, of the timer.
3068
3408
  *
@@ -3078,8 +3418,8 @@ declare class Timer {
3078
3418
  * Removes a timer.
3079
3419
  *
3080
3420
  * @remarks After removal, no additional methods can be used with a timer
3081
- * of the given name, other than to start a new timer with the given name,
3082
- * 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
3083
3423
  * a timer with the given name does not exist.
3084
3424
  *
3085
3425
  * @param name - The name of the timer to be removed
@@ -3271,4 +3611,4 @@ declare class WebGlInfo {
3271
3611
  static dispose(): void;
3272
3612
  }
3273
3613
 
3274
- 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 Plugin, 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 };