@m2c2kit/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1125 @@
1
+ import { FontMgr, Typeface, Image, CanvasKit, Canvas } from 'canvaskit-wasm';
2
+
3
+ interface FontData {
4
+ fontUrl: string;
5
+ fontArrayBuffer: ArrayBuffer;
6
+ }
7
+
8
+ declare class FontManager {
9
+ _fontMgr?: FontMgr;
10
+ private _typefaces;
11
+ _getTypeface(name: string): Typeface;
12
+ FetchFontsAsArrayBuffers(fontUrls: Array<string>): Promise<FontData>[];
13
+ LoadFonts(fonts: Array<ArrayBuffer>): void;
14
+ }
15
+
16
+ declare class LoadedImage {
17
+ name: string;
18
+ image: Image;
19
+ width: number;
20
+ height: number;
21
+ constructor(name: string, image: Image, width: number, height: number);
22
+ }
23
+
24
+ declare class RenderedDataUrlImage {
25
+ name: string;
26
+ dataUrlImage: string;
27
+ width: number;
28
+ height: number;
29
+ constructor(name: string, dataUrlImage: string, width: number, height: number);
30
+ }
31
+
32
+ /**
33
+ * SVG image to be rendered and loaded from a URL or HTML svg tag in string form.
34
+ */
35
+ interface SvgImage {
36
+ /** Name that will be used to refer to the SVG image. Must be unique among all images */
37
+ name: string;
38
+ /** Width to scale SVG image to */
39
+ width: number;
40
+ /** Height to scale SVG image to */
41
+ height: number;
42
+ /** The HTML SVG tag, in string form, that will be rendered and loaded. Must begin with &#60;svg> and end with &#60;/svg> */
43
+ svgString?: string;
44
+ /** URL of SVG asset to render and load */
45
+ url?: string;
46
+ }
47
+
48
+ declare class ImageManager {
49
+ private scratchCanvas?;
50
+ private ctx?;
51
+ private scale?;
52
+ _renderedDataUrlImages: Record<string, RenderedDataUrlImage>;
53
+ _loadedImages: Record<string, LoadedImage>;
54
+ initialize(scratchCanvas: HTMLCanvasElement): void;
55
+ renderSvgImage(svgImage: SvgImage): Promise<RenderedDataUrlImage>;
56
+ LoadRenderedSvgImages(urls: RenderedDataUrlImage[]): void;
57
+ private convertRenderedDataUrlImage;
58
+ private dataURLtoArrayBuffer;
59
+ }
60
+
61
+ declare class GlobalVariables {
62
+ canvasKit: CanvasKit;
63
+ fontManager: FontManager;
64
+ imageManager: ImageManager;
65
+ now: number;
66
+ deltaTime: number;
67
+ canvasScale: number;
68
+ rootScale: number;
69
+ canvasCssWidth: number;
70
+ canvasCssHeight: number;
71
+ }
72
+
73
+ declare global {
74
+ var Globals: GlobalVariables;
75
+ }
76
+
77
+ /**
78
+ * Position in two-dimensional space.
79
+ */
80
+ declare class Point {
81
+ x: number;
82
+ y: number;
83
+ constructor(x?: number, y?: number);
84
+ }
85
+
86
+ declare class TapListener {
87
+ entityName?: string;
88
+ codeCallback?: (tapevent: TapEvent) => void;
89
+ }
90
+ /**
91
+ * Object passed to the tap event handler when the entity is tapped.
92
+ */
93
+ interface TapEvent {
94
+ /** The entity that was tapped */
95
+ tappedEntity: Entity;
96
+ /** Point that was tapped on entity, relative to the entity coordinate system */
97
+ point: Point;
98
+ }
99
+
100
+ interface Constraints {
101
+ topToTopOf?: Entity | string;
102
+ topToBottomOf?: Entity | string;
103
+ bottomToTopOf?: Entity | string;
104
+ bottomToBottomOf?: Entity | string;
105
+ startToStartOf?: Entity | string;
106
+ startToEndOf?: Entity | string;
107
+ endToEndOf?: Entity | string;
108
+ endToStartOf?: Entity | string;
109
+ horizontalBias?: number;
110
+ verticalBias?: number;
111
+ [key: string]: Entity | string | number | undefined;
112
+ }
113
+
114
+ /**
115
+ * The Layout allows relative positioning via constraints.
116
+ * This is not fully implemented yet: DO NOT USE!
117
+ * We use it internally for instructions.
118
+ */
119
+ interface Layout {
120
+ height?: number;
121
+ width?: number;
122
+ marginStart?: number;
123
+ marginEnd?: number;
124
+ marginTop?: number;
125
+ marginBottom?: number;
126
+ constraints?: Constraints;
127
+ }
128
+
129
+ /**
130
+ * Width and height on two-dimensional space
131
+ */
132
+ declare class Size {
133
+ width: number;
134
+ height: number;
135
+ constructor(width?: number, height?: number);
136
+ }
137
+
138
+ interface EntityOptions {
139
+ name?: string;
140
+ position?: Point;
141
+ scale?: number;
142
+ isUserInteractionEnabled?: boolean;
143
+ hidden?: boolean;
144
+ layout?: Layout;
145
+ }
146
+
147
+ declare enum EntityType {
148
+ entity = "Entity",
149
+ scene = "Scene",
150
+ sprite = "Sprite",
151
+ label = "Label",
152
+ textline = "TextLine",
153
+ shape = "Shape",
154
+ composite = "Composite"
155
+ }
156
+
157
+ declare function handleInterfaceOptions(entity: Entity, options: EntityOptions): void;
158
+ declare abstract class Entity {
159
+ type: EntityType;
160
+ isDrawable: boolean;
161
+ isShape: boolean;
162
+ isText: boolean;
163
+ name: string;
164
+ position: Point;
165
+ scale: number;
166
+ isUserInteractionEnabled: boolean;
167
+ hidden: boolean;
168
+ layout: Layout;
169
+ parent?: Entity;
170
+ children: Entity[];
171
+ absolutePosition: Point;
172
+ size: Size;
173
+ absoluteScale: number;
174
+ actions: Action[];
175
+ queuedAction?: Action;
176
+ originalActions: Action[];
177
+ tapListeners: TapListener[];
178
+ uuid: string;
179
+ needsInitialization: boolean;
180
+ userData: any;
181
+ loopMessages: Set<string>;
182
+ constructor(options?: EntityOptions);
183
+ initialize(): void;
184
+ /**
185
+ * Overrides toString() and returns a human-friendly description of the entity.
186
+ *
187
+ * @remarks Inspiration from https://stackoverflow.com/a/35361695
188
+ */
189
+ toString: () => string;
190
+ /**
191
+ * Adds a child to this parent entity. Thows exception if the child's name is not unique with respect to other children of this parent.
192
+ *
193
+ * @param child - The child entity to add
194
+ */
195
+ addChild(child: Entity): void;
196
+ /**
197
+ * Removes all children from the entity
198
+ */
199
+ removeAllChildren(): void;
200
+ /**
201
+ * Removes the specific child from this parent entity. Throws exception if this parent does not contain the child.
202
+ *
203
+ * @param child
204
+ */
205
+ removeChild(child: Entity): void;
206
+ /**
207
+ * Searches all descendants by name and returns first matching entity. Descendants are children and children of children, recursively.
208
+ *
209
+ * @param name - Name of the descendant entity to return
210
+ * @returns
211
+ */
212
+ descendant<T extends Entity>(name: string): T;
213
+ /**
214
+ * Returns all descendant entities. Descendants are children and children of children, recursively.
215
+ */
216
+ get descendants(): Array<Entity>;
217
+ onTap(codeCallback: (tapEvent: TapEvent) => void, replaceExistingCodeCallback?: boolean): void;
218
+ private parseLayoutConstraints;
219
+ private calculateYFromConstraint;
220
+ private calculateXFromConstraint;
221
+ update(): void;
222
+ /**
223
+ * Draws each child entity that is Drawable and is not hidden, by zPosition order (highest zPosition on top).
224
+ *
225
+ * @param canvas - CanvasKit canvas
226
+ */
227
+ drawChildren(canvas: Canvas): void;
228
+ /**
229
+ * Runs an action on this entity.
230
+ *
231
+ * @remarks If the entity is part of an active scene, the action runs immediately. Otherwise, the action will run when the entity's scene becomes active. Calling run() multiple times on an entity will add to existing actions, not replace them.
232
+ *
233
+ * @param action - The action to run
234
+ * @param key - key (string identifier) used to identify the action. Only needed if the action will be referred to later
235
+ */
236
+ run(action: Action, key?: string): void;
237
+ /**
238
+ * Remove an action from this entity. If the action is running, it will be stopped.
239
+ *
240
+ * @param key - key (string identifier) of the action to remove
241
+ */
242
+ removeAction(key: string): void;
243
+ /**
244
+ * Remove all actions from this entity. If actions are running, they will be stopped.
245
+ */
246
+ removeAllActions(): void;
247
+ private static getEntityOptions;
248
+ private static getDrawableOptions;
249
+ private static getTextOptions;
250
+ /**
251
+ * Gets the scene that contains this entity by searching up the ancestor tree recursively. Throws exception if entity is not part of a scene.
252
+ *
253
+ * @returns Scene that contains this entity
254
+ */
255
+ get parentSceneAsEntity(): Entity;
256
+ private generateUUID;
257
+ /**
258
+ * For a given directed acyclic graph, topological ordering of the vertices will be identified using BFS
259
+ * @param adjList Adjacency List that represent a graph with vertices and edges
260
+ */
261
+ private findTopologicalSort;
262
+ }
263
+
264
+ interface MoveActionOptions {
265
+ /** Destination point. The point is relative to the entity's parent coordinate system */
266
+ point: Point;
267
+ /** Duration of move, in milliseconds */
268
+ duration: number;
269
+ /** Should the action run during screen transitions? Default is no */
270
+ runDuringTransition?: boolean;
271
+ }
272
+
273
+ interface WaitActionOptions {
274
+ /** Duration of wait, in milliseconds */
275
+ duration: number;
276
+ /** Should the action run during screen transitions? Default is no */
277
+ runDuringTransition?: boolean;
278
+ }
279
+
280
+ interface CustomActionOptions {
281
+ /** callback - The callback function to be executed */
282
+ callback: () => void;
283
+ /** Should the action run during screen transitions? Default is no */
284
+ runDuringTransition?: boolean;
285
+ }
286
+
287
+ interface ScaleActionOptions {
288
+ /** The scaling ratio. 1 is no change, greater than 1 is make bigger, less than 1 is make smaller */
289
+ scale: number;
290
+ /** Duration of scale, in milliseconds */
291
+ duration: number;
292
+ /** Should the action run during screen transitions? Default is no */
293
+ runDuringTransition?: boolean;
294
+ }
295
+
296
+ interface IActionContainer {
297
+ children?: Array<Action>;
298
+ }
299
+
300
+ declare enum ActionType {
301
+ sequence = "Sequence",
302
+ group = "Group",
303
+ wait = "Wait",
304
+ custom = "Custom",
305
+ move = "Move",
306
+ scale = "Scale"
307
+ }
308
+
309
+ declare abstract class Action {
310
+ abstract type: ActionType;
311
+ startOffset: number;
312
+ endOffset: number;
313
+ started: boolean;
314
+ running: boolean;
315
+ completed: boolean;
316
+ runStartTime: number;
317
+ duration: number;
318
+ runDuringTransition: boolean;
319
+ parent?: Action;
320
+ isParent: boolean;
321
+ isChild: boolean;
322
+ key?: string;
323
+ constructor(runDuringTransition?: boolean);
324
+ /**
325
+ * Creates an action that will move an entity to a point on the screen.
326
+ *
327
+ * @param options - {@link MoveActionOptions}
328
+ * @returns The move action
329
+ */
330
+ static Move(options: MoveActionOptions): Action;
331
+ /**
332
+ * Creates an action that will wait a given duration before it is considered complete.
333
+ *
334
+ * @param options - {@link WaitActionOptions}
335
+ * @returns The wait action
336
+ */
337
+ static Wait(options: WaitActionOptions): Action;
338
+ /**
339
+ * Creates an action that will execute a callback function.
340
+ *
341
+ * @param options - {@link CustomActionOptions}
342
+ * @returns The custom action
343
+ */
344
+ static Custom(options: CustomActionOptions): Action;
345
+ /**
346
+ * Creates an action that will scale the entity's size.
347
+ *
348
+ * @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.
349
+ *
350
+ * @param options - {@link ScaleActionOptions}
351
+ * @returns The scale action
352
+ */
353
+ static Scale(options: ScaleActionOptions): Action;
354
+ /**
355
+ * Creates an array of actions that will be run in order.
356
+ *
357
+ * @remarks The next action will not begin until the current one has finished. The sequence will be considered completed when the last action has completed.
358
+ *
359
+ * @param actions - One or more actions that form the sequence
360
+ * @returns
361
+ */
362
+ static Sequence(actions: Array<Action>): Action;
363
+ /**
364
+ * Create an array of actions that will be run simultaneously.
365
+ *
366
+ * @remarks All actions within the group will begin to run at the same time. The group will be considered completed when the longest-running action has completed.
367
+ *
368
+ * @param actions - One or more actions that form the group
369
+ * @returns
370
+ */
371
+ static Group(actions: Array<Action>): Action;
372
+ initialize(entity: Entity, key?: string): Array<Action>;
373
+ static cloneAction(action: Action, key?: string): Action;
374
+ static evaluateAction(action: Action, entity: Entity, now: number, dt: number): void;
375
+ private calculateDuration;
376
+ private calculateStartEndOffsets;
377
+ private flattenActions;
378
+ private assignParents;
379
+ }
380
+ declare class SequenceAction extends Action implements IActionContainer {
381
+ type: ActionType;
382
+ children: Array<Action>;
383
+ constructor(actions: Array<Action>);
384
+ }
385
+ declare class GroupAction extends Action implements IActionContainer {
386
+ type: ActionType;
387
+ children: Action[];
388
+ constructor(actions: Array<Action>);
389
+ }
390
+ declare class CustomAction extends Action {
391
+ type: ActionType;
392
+ codeCallback: () => void;
393
+ constructor(codeCallback: () => void, runDuringTransition?: boolean);
394
+ }
395
+ declare class WaitAction extends Action {
396
+ type: ActionType;
397
+ constructor(duration: number, runDuringTransition: boolean);
398
+ }
399
+ declare class MoveAction extends Action {
400
+ type: ActionType;
401
+ point: Point;
402
+ dx: number;
403
+ dy: number;
404
+ constructor(point: Point, duration: number, runDuringTransition: boolean);
405
+ }
406
+ declare class ScaleAction extends Action {
407
+ type: ActionType;
408
+ scale: number;
409
+ delta: number;
410
+ constructor(scale: number, duration: number, runDuringTransition?: boolean);
411
+ }
412
+
413
+ interface IDrawable {
414
+ draw(canvas: Canvas): void;
415
+ anchorPoint: Point;
416
+ zPosition: number;
417
+ }
418
+
419
+ interface DrawableOptions {
420
+ anchorPoint?: Point;
421
+ zPosition?: number;
422
+ }
423
+
424
+ interface CompositeOptions extends EntityOptions, DrawableOptions {
425
+ }
426
+
427
+ declare abstract class Composite extends Entity implements IDrawable {
428
+ readonly type = EntityType.composite;
429
+ compositeType: string;
430
+ isDrawable: boolean;
431
+ anchorPoint: Point;
432
+ zPosition: number;
433
+ /**
434
+ * Base Drawable object for creating custom entities ("composites") composed of primitive entities.
435
+ *
436
+ * @param options
437
+ */
438
+ constructor(options?: CompositeOptions);
439
+ initialize(): void;
440
+ update(): void;
441
+ draw(canvas: Canvas): void;
442
+ }
443
+
444
+ /**
445
+ * Color in red (0-255), green (0-255), blue (0-255), alpha (0-1) format. Must be numeric array of length 4.
446
+ */
447
+ declare type RgbaColor = [number, number, number, number];
448
+
449
+ /**
450
+ * Reasonable defaults to use if values are not specified.
451
+ */
452
+ declare class Constants {
453
+ static readonly FPS_DISPLAY_TEXT_FONT_SIZE = 12;
454
+ static readonly FPS_DISPLAY_TEXT_COLOR: RgbaColor;
455
+ static readonly FPS_DISPLAY_UPDATE_INTERVAL = 500;
456
+ static readonly DEFAULT_SCENE_BACKGROUND_COLOR: RgbaColor;
457
+ static readonly DEFAULT_SHAPE_FILL_COLOR: RgbaColor;
458
+ static readonly DEFAULT_FONT_COLOR: RgbaColor;
459
+ static readonly DEFAULT_FONT_SIZE = 16;
460
+ static readonly LIMITED_FPS_RATE = 5;
461
+ }
462
+
463
+ /**
464
+ * This enum is used interally for processing the layout constraints. We use
465
+ * an enum to avoid magic strings.
466
+ */
467
+ declare enum ConstraintType {
468
+ topToTopOf = "topToTopOf",
469
+ topToBottomOf = "topToBottomOf",
470
+ bottomToTopOf = "bottomToTopOf",
471
+ bottomToBottomOf = "bottomToBottomOf",
472
+ startToStartOf = "startToStartOf",
473
+ startToEndOf = "startToEndOf",
474
+ endToEndOf = "endToEndOf",
475
+ endToStartOf = "endToStartOf"
476
+ }
477
+
478
+ declare enum Dimensions {
479
+ MATCH_CONSTRAINT = 0
480
+ }
481
+
482
+ interface SceneOptions extends EntityOptions, DrawableOptions {
483
+ backgroundColor?: RgbaColor;
484
+ }
485
+
486
+ declare class Scene extends Entity implements IDrawable {
487
+ readonly type = EntityType.scene;
488
+ isDrawable: boolean;
489
+ anchorPoint: Point;
490
+ zPosition: number;
491
+ private _backgroundColor;
492
+ _active: boolean;
493
+ _transitioning: boolean;
494
+ _setupCallback?: (scene: Scene) => void;
495
+ private _game?;
496
+ private backgroundPaint?;
497
+ /**
498
+ * Top-level entity that holds all other entities, such as sprites, rectangles, or labels, that will be displayed on the screen
499
+ *
500
+ * @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.
501
+ *
502
+ * @param options
503
+ * @see {@link SceneOptions}
504
+ */
505
+ constructor(options?: SceneOptions);
506
+ initialize(): void;
507
+ set game(game: Game);
508
+ get game(): Game;
509
+ get backgroundColor(): RgbaColor;
510
+ set backgroundColor(backgroundColor: RgbaColor);
511
+ /**
512
+ * Code that will be called every time the screen is shown.
513
+ *
514
+ * @remarks Use this callback to "reset" entities to their initial state. For example, if a screen allows players to place dots on a grid, the setup() method should ensure the grid is clear of any prior dots from previous times this screen may have been displayed. In addition, if entities should vary in each iteration, that should be done here.
515
+ *
516
+ * @param codeCallback
517
+ */
518
+ setup(codeCallback: (scene: Scene) => void): void;
519
+ draw(canvas: Canvas): void;
520
+ }
521
+
522
+ declare abstract class Transition {
523
+ abstract type: TransitionType;
524
+ duration: number;
525
+ static push(direction: TransitionDirection, duration: number): PushTransition;
526
+ }
527
+ declare class PushTransition extends Transition {
528
+ type: TransitionType;
529
+ direction: TransitionDirection;
530
+ constructor(direction: TransitionDirection, duration: number);
531
+ }
532
+ declare enum TransitionType {
533
+ push = "Push"
534
+ }
535
+ declare enum TransitionDirection {
536
+ up = "Up",
537
+ down = "Down",
538
+ right = "Right",
539
+ left = "Left"
540
+ }
541
+ declare class SceneTransition {
542
+ scene: Scene;
543
+ transition?: Transition | undefined;
544
+ constructor(scene: Scene, transition?: Transition | undefined);
545
+ }
546
+
547
+ /**
548
+ * Options to specify HTML canvas, set game canvas size, and load game assets.
549
+ */
550
+ interface GameInitOptions {
551
+ /** Id of the HTML canvas that game will be drawn on. If not provided, the first canvas found will be used */
552
+ canvasId?: string;
553
+ /** Width of game canvas */
554
+ width: number;
555
+ /** Height of game canvas */
556
+ height: number;
557
+ /** Stretch to fill screen? Default is false */
558
+ stretch?: boolean;
559
+ /** Schema of trial data; JSON object where key is variable name, value is data type */
560
+ trialSchema?: object;
561
+ /** Default game parameters; JSON object where key is the game parameter, value is default value */
562
+ defaultParameters?: object;
563
+ /** String array of urls from which to load fonts. The first element will be the default font */
564
+ fontUrls?: Array<string>;
565
+ /** Array of SvgImage objects to render and load */
566
+ svgImages?: SvgImage[];
567
+ /** Show FPS in upper left corner? Default is false */
568
+ showFps?: boolean;
569
+ /** Color of the html body, if the game does not fill the screen. Useful for showing scene boundaries. Default is the scene background color */
570
+ bodyBackgroundColor?: RgbaColor;
571
+ /** Adapt execution for unit testing? Default is false */
572
+ _unitTesting?: boolean;
573
+ }
574
+
575
+ interface TrialData {
576
+ [key: string]: string | number | boolean | undefined | null;
577
+ }
578
+ interface Metadata {
579
+ userAgent?: string;
580
+ }
581
+ interface GameData {
582
+ trials: Array<TrialData>;
583
+ metadata: Metadata;
584
+ }
585
+ interface LifecycleCallbacks {
586
+ trialComplete: (trialNumber: number, data: GameData, trialSchema: object) => void;
587
+ allTrialsComplete: (data: GameData, trialSchema: object) => void;
588
+ }
589
+ declare class Game {
590
+ entryScene?: Scene | string;
591
+ parameters: any;
592
+ private defaultParameters;
593
+ data: GameData;
594
+ trialNumber: number;
595
+ trialSchema: {};
596
+ lifecycle: LifecycleCallbacks;
597
+ private trialSchemaMap;
598
+ private htmlCanvas?;
599
+ private scratchHtmlCanvas?;
600
+ private surface?;
601
+ private showFps?;
602
+ private bodyBackgroundColor?;
603
+ private currentScene?;
604
+ private priorUpdateTime?;
605
+ private fpsTextFont?;
606
+ private fpsTextPaint?;
607
+ private drawnFrames;
608
+ private lastFpsUpdate;
609
+ private nextFpsUpdate;
610
+ private fps;
611
+ private animationFramesRequested;
612
+ private limitFps;
613
+ private unitTesting;
614
+ canvasCssWidth: number;
615
+ canvasCssHeight: number;
616
+ private scenes;
617
+ private incomingSceneTransitions;
618
+ private currentSceneSnapshot?;
619
+ /**
620
+ * Asynchronously initializes the game engine and load assets
621
+ *
622
+ * @param gameInitOptions
623
+ * @returns Promise<void>
624
+ */
625
+ init(gameInitOptions: GameInitOptions): Promise<void>;
626
+ /**
627
+ * Provide a callback function to be invoked when a trial has completed.
628
+ * It is the responsibility of the the game programmer to call this
629
+ * at the appropriate time. It is not triggered automatically.
630
+ * @param codeCallback
631
+ */
632
+ onTrialComplete(codeCallback: (trialNumber: number, data: GameData, trialSchema: object) => void): void;
633
+ /**
634
+ * Provide a callback function to be invoked when all trials are complete.
635
+ * It is the responsibility of the the game programmer to call this
636
+ * at the appropriate time. It is not triggered automatically.
637
+ * @param codeCallback
638
+ */
639
+ onAllTrialsComplete(codeCallback: (data: GameData) => void): void;
640
+ /**
641
+ * Adds a scene to the game.
642
+ *
643
+ * @remarks A scene, and its children entities, cannot be preseneted unless it has been added to the game object.
644
+ *
645
+ * @param scene
646
+ */
647
+ addScene(scene: Scene): void;
648
+ addScenes(scenes: Array<Scene>): void;
649
+ /**
650
+ * Specifies the scene that will be presented upon the next frame draw.
651
+ *
652
+ * @param scene
653
+ * @param transition
654
+ */
655
+ presentScene(scene: string | Scene, transition?: Transition): void;
656
+ /**
657
+ * Gets the value of the specified game parameter. If the value was not
658
+ * provided in the parameters property above, then return the value in
659
+ * defaultParameters. If the parameterName is still not found, then
660
+ * throw exception.
661
+ * @param parameterName - the name of the game parameter whose value is requested
662
+ * @returns
663
+ */
664
+ getParameter<T>(parameterName: string): T;
665
+ /**
666
+ * Starts the game loop. If entryScene is undefined, the game object's entryScene must be set.
667
+ *
668
+ * @param entryScene - The scene (Scene object or its string name) to display when the game starts
669
+ */
670
+ start(entryScene?: Scene | string): void;
671
+ initData(trialSchema: object): void;
672
+ addTrialData(variableName: string, value: any): void;
673
+ private loadCanvasKit;
674
+ private setupHtmlCanvases;
675
+ private fetchFonts;
676
+ private renderSvgImages;
677
+ private loadFonts;
678
+ private setupCanvasKitSurface;
679
+ private setupFpsFont;
680
+ private setupEventHandlers;
681
+ private loop;
682
+ private updateGameTime;
683
+ private handleIncomingSceneTransitions;
684
+ private update;
685
+ private draw;
686
+ private takeCurrentSceneSnapshot;
687
+ private animateSceneTransition;
688
+ private drawFps;
689
+ /**
690
+ * Creates a tap listener for an entity based on the entity name
691
+ *
692
+ * @remarks Typically, tap listeners will be created using the onTap() method of each entity. This alternative allows creation with entity name.
693
+ *
694
+ * @param entityName
695
+ * @param codeCallback
696
+ * @param replaceExistingCodeCallback
697
+ */
698
+ createTapListener(entityName: string, codeCallback: (tapEvent: TapEvent) => void, replaceExistingCodeCallback?: boolean): void;
699
+ /**
700
+ * Returns array of all entities that have been added to the game object.
701
+ */
702
+ get entities(): Array<Entity>;
703
+ private htmlCanvasMouseDownHandler;
704
+ private htmlCanvasTouchStartHandler;
705
+ private processTaps;
706
+ private handleEntityTapped;
707
+ private tapIsWithinEntityBounds;
708
+ private calculateEntityAbsoluteBoundingBox;
709
+ }
710
+
711
+ interface IText {
712
+ text?: string;
713
+ fontName?: string;
714
+ fontColor?: RgbaColor;
715
+ fontSize?: number;
716
+ }
717
+
718
+ interface TextOptions {
719
+ text?: string;
720
+ fontName?: string;
721
+ fontColor?: RgbaColor;
722
+ fontSize?: number;
723
+ }
724
+
725
+ declare enum LabelHorizontalAlignmentMode {
726
+ center = 0,
727
+ left = 1,
728
+ right = 2
729
+ }
730
+
731
+ interface LabelOptions extends EntityOptions, DrawableOptions, TextOptions {
732
+ horizontalAlignmentMode?: LabelHorizontalAlignmentMode;
733
+ preferredMaxLayoutWidth?: number;
734
+ backgroundColor?: RgbaColor;
735
+ }
736
+
737
+ declare class Label extends Entity implements IDrawable, IText {
738
+ readonly type = EntityType.label;
739
+ isDrawable: boolean;
740
+ isText: boolean;
741
+ anchorPoint: Point;
742
+ zPosition: number;
743
+ private _text;
744
+ private _fontName;
745
+ private _fontColor;
746
+ private _fontSize;
747
+ private _horizontalAlignmentMode;
748
+ private _preferredMaxLayoutWidth;
749
+ private _backgroundColor?;
750
+ private paragraph?;
751
+ private paraStyle?;
752
+ /**
753
+ * Single or multi-line text formatted and rendered on the screen.
754
+ *
755
+ * @remarks Label (in contrast to TextLine) has enhanced text support for line wrapping, centering/alignment, and background colors.
756
+ *
757
+ * @param options
758
+ */
759
+ constructor(options?: LabelOptions);
760
+ initialize(): void;
761
+ get text(): string;
762
+ set text(text: string);
763
+ get fontName(): string | undefined;
764
+ set fontName(fontName: string | undefined);
765
+ get fontColor(): RgbaColor;
766
+ set fontColor(fontColor: RgbaColor);
767
+ get fontSize(): number;
768
+ set fontSize(fontSize: number);
769
+ get horizontalAlignmentMode(): LabelHorizontalAlignmentMode;
770
+ set horizontalAlignmentMode(horizontalAlignmentMode: LabelHorizontalAlignmentMode);
771
+ get preferredMaxLayoutWidth(): number | undefined;
772
+ set preferredMaxLayoutWidth(preferredMaxLayoutWidth: number | undefined);
773
+ get backgroundColor(): RgbaColor | undefined;
774
+ set backgroundColor(backgroundColor: RgbaColor | undefined);
775
+ update(): void;
776
+ draw(canvas: Canvas): void;
777
+ }
778
+
779
+ /**
780
+ * This class is used internally for processing layout constraints that
781
+ * have been defined according to the Contraints interface.
782
+ *
783
+ * Imagine we have two entities, A and B. B's position is set
784
+ * using its position property. A's position is set using the layout
785
+ * constraint "bottomToTopOf B." A is the focal entity in this example.
786
+ * What this means is that A's y coordinate will be computed such that
787
+ * the bottom of A is the top of B. If A and B are squares, then A sits
788
+ * on top of B with no gap.
789
+ */
790
+ declare class LayoutConstraint {
791
+ type: ConstraintType;
792
+ alterEntity: Entity;
793
+ verticalConstraint: boolean;
794
+ focalEntityMinimum: boolean;
795
+ alterEntityMinimum: boolean;
796
+ verticalTypes: ConstraintType[];
797
+ focalEntityMinimumTypes: ConstraintType[];
798
+ alterEntityMinimumTypes: ConstraintType[];
799
+ constructor(type: ConstraintType, alterEntity: Entity);
800
+ }
801
+
802
+ declare class RandomDraws {
803
+ /**
804
+ * Draw random integers, without replacement, from a uniform distribution.
805
+ *
806
+ * @param n
807
+ * @param minimumInclusive
808
+ * @param maximumInclusive
809
+ * @returns array of integers
810
+ */
811
+ static FromRangeWithoutReplacement(n: number, minimumInclusive: number, maximumInclusive: number): Array<number>;
812
+ /**
813
+ * Draw random grid cell locations, without replacement, from a uniform distribution of all grid cells. Grid cell locations are zero-based, i.e., upper-left is (0,0).
814
+ *
815
+ * @param n - Number of draws
816
+ * @param rows - Number of rows in grid; must be at least 1
817
+ * @param columns - Number of columns in grid; must be at least 1
818
+ * @param predicate - Optional lambda function that takes a grid row number and grid column number pair and returns a boolean to indicate if the pair should be allowed. For example, if one wanted to constrain the random grid location to be along the diagonal, the predicate would be: (row, column) => row === column
819
+ * @returns array of grid cells. Each cell is object in form of { row: number, column: number }). Grid cell locations are zero-based
820
+ */
821
+ static FromGridWithoutReplacement(n: number, rows: number, columns: number, predicate?: (row: number, column: number) => boolean): Array<{
822
+ row: number;
823
+ column: number;
824
+ }>;
825
+ }
826
+
827
+ interface RectOptions {
828
+ origin?: Point;
829
+ size?: Size;
830
+ x?: number;
831
+ y?: number;
832
+ width?: number;
833
+ height?: number;
834
+ }
835
+
836
+ declare class Rect implements RectOptions {
837
+ origin?: Point;
838
+ size?: Size;
839
+ x?: number;
840
+ y?: number;
841
+ width?: number;
842
+ height?: number;
843
+ constructor(options: RectOptions);
844
+ }
845
+
846
+ interface ShapeOptions extends EntityOptions, DrawableOptions {
847
+ circleOfRadius?: number;
848
+ rect?: Rect;
849
+ cornerRadius?: number;
850
+ fillColor?: RgbaColor;
851
+ strokeColor?: RgbaColor;
852
+ lineWidth?: number;
853
+ }
854
+
855
+ declare enum ShapeType {
856
+ undefined = "Undefined",
857
+ rectangle = "Rectangle",
858
+ circle = "Circle"
859
+ }
860
+
861
+ declare class Shape extends Entity implements IDrawable {
862
+ readonly type = EntityType.shape;
863
+ isDrawable: boolean;
864
+ isShape: boolean;
865
+ anchorPoint: Point;
866
+ zPosition: number;
867
+ shapeType: ShapeType;
868
+ circleOfRadius?: number;
869
+ rect?: Rect;
870
+ cornerRadius: number;
871
+ private _fillColor;
872
+ private _strokeColor?;
873
+ lineWidth?: number;
874
+ private fillColorPaint?;
875
+ private strokeColorPaint?;
876
+ /**
877
+ * Rectangular shape
878
+ *
879
+ * @param options
880
+ */
881
+ constructor(options?: ShapeOptions);
882
+ initialize(): void;
883
+ get fillColor(): RgbaColor;
884
+ set fillColor(fillColor: RgbaColor);
885
+ get strokeColor(): RgbaColor | undefined;
886
+ set strokeColor(strokeColor: RgbaColor | undefined);
887
+ update(): void;
888
+ draw(canvas: Canvas): void;
889
+ }
890
+
891
+ interface SpriteOptions extends EntityOptions, DrawableOptions {
892
+ imageName?: string;
893
+ }
894
+
895
+ declare class Sprite extends Entity implements IDrawable {
896
+ readonly type = EntityType.sprite;
897
+ isDrawable: boolean;
898
+ anchorPoint: Point;
899
+ zPosition: number;
900
+ private _imageName;
901
+ private loadedImage?;
902
+ /**
903
+ * Visual image displayed on the screen.
904
+ *
905
+ * @remarks Sprites must be loaded during the Game.init() method prior to their use.
906
+ *
907
+ * @param options
908
+ */
909
+ constructor(options?: SpriteOptions);
910
+ initialize(): void;
911
+ set imageName(imageName: string);
912
+ get imageName(): string;
913
+ update(): void;
914
+ draw(canvas: Canvas): void;
915
+ }
916
+
917
+ interface StoryOptions {
918
+ sceneNamePrefix: string;
919
+ }
920
+
921
+ declare abstract class Story {
922
+ static Create(options: StoryOptions): Array<Scene>;
923
+ }
924
+
925
+ interface TextLineOptions extends EntityOptions, DrawableOptions, TextOptions {
926
+ width?: number;
927
+ }
928
+
929
+ declare class TextLine extends Entity implements IDrawable, IText {
930
+ readonly type = EntityType.textline;
931
+ isDrawable: boolean;
932
+ isText: boolean;
933
+ zPosition: number;
934
+ anchorPoint: Point;
935
+ private _text;
936
+ private _fontName;
937
+ private _fontColor;
938
+ private _fontSize;
939
+ private paint?;
940
+ private font?;
941
+ /**
942
+ * Single-line text rendered on the screen.
943
+ *
944
+ * @remarks TextLine has no paragraph formatting options; Label will be preferred in most use cases.
945
+ *
946
+ * @param options
947
+ */
948
+ constructor(options?: TextLineOptions);
949
+ get text(): string;
950
+ set text(text: string);
951
+ get fontName(): string | undefined;
952
+ set fontName(fontName: string | undefined);
953
+ get fontColor(): RgbaColor;
954
+ set fontColor(fontColor: RgbaColor);
955
+ get fontSize(): number;
956
+ set fontSize(fontSize: number);
957
+ update(): void;
958
+ initialize(): void;
959
+ draw(canvas: Canvas): void;
960
+ }
961
+
962
+ declare class Timer {
963
+ private originTime;
964
+ private startTime;
965
+ private stopTime;
966
+ private stopped;
967
+ private _elapsed;
968
+ private name;
969
+ private static _timers;
970
+ constructor(name: string);
971
+ static Start(name: string): void;
972
+ static Stop(name: string): void;
973
+ static Restart(name: string): void;
974
+ static Elapsed(name: string): number;
975
+ static Remove(name: string): void;
976
+ static Exists(name: string): boolean;
977
+ static RemoveAll(): void;
978
+ }
979
+
980
+ declare class WebColors {
981
+ static Transparent: RgbaColor;
982
+ static MediumVioletRed: RgbaColor;
983
+ static DeepPink: RgbaColor;
984
+ static PaleVioletRed: RgbaColor;
985
+ static HotPink: RgbaColor;
986
+ static LightPink: RgbaColor;
987
+ static Pink: RgbaColor;
988
+ static DarkRed: RgbaColor;
989
+ static Red: RgbaColor;
990
+ static Firebrick: RgbaColor;
991
+ static Crimson: RgbaColor;
992
+ static IndianRed: RgbaColor;
993
+ static LightCoral: RgbaColor;
994
+ static Salmon: RgbaColor;
995
+ static DarkSalmon: RgbaColor;
996
+ static LightSalmon: RgbaColor;
997
+ static OrangeRed: RgbaColor;
998
+ static Tomato: RgbaColor;
999
+ static DarkOrange: RgbaColor;
1000
+ static Coral: RgbaColor;
1001
+ static Orange: RgbaColor;
1002
+ static DarkKhaki: RgbaColor;
1003
+ static Gold: RgbaColor;
1004
+ static Khaki: RgbaColor;
1005
+ static PeachPuff: RgbaColor;
1006
+ static Yellow: RgbaColor;
1007
+ static PaleGoldenrod: RgbaColor;
1008
+ static Moccasin: RgbaColor;
1009
+ static PapayaWhip: RgbaColor;
1010
+ static LightGoldenrodYellow: RgbaColor;
1011
+ static LemonChiffon: RgbaColor;
1012
+ static LightYellow: RgbaColor;
1013
+ static Maroon: RgbaColor;
1014
+ static Brown: RgbaColor;
1015
+ static SaddleBrown: RgbaColor;
1016
+ static Sienna: RgbaColor;
1017
+ static Chocolate: RgbaColor;
1018
+ static DarkGoldenrod: RgbaColor;
1019
+ static Peru: RgbaColor;
1020
+ static RosyBrown: RgbaColor;
1021
+ static Goldenrod: RgbaColor;
1022
+ static SandyBrown: RgbaColor;
1023
+ static Tan: RgbaColor;
1024
+ static Burlywood: RgbaColor;
1025
+ static Wheat: RgbaColor;
1026
+ static NavajoWhite: RgbaColor;
1027
+ static Bisque: RgbaColor;
1028
+ static BlanchedAlmond: RgbaColor;
1029
+ static Cornsilk: RgbaColor;
1030
+ static DarkGreen: RgbaColor;
1031
+ static Green: RgbaColor;
1032
+ static DarkOliveGreen: RgbaColor;
1033
+ static ForestGreen: RgbaColor;
1034
+ static SeaGreen: RgbaColor;
1035
+ static Olive: RgbaColor;
1036
+ static OliveDrab: RgbaColor;
1037
+ static MediumSeaGreen: RgbaColor;
1038
+ static LimeGreen: RgbaColor;
1039
+ static Lime: RgbaColor;
1040
+ static SpringGreen: RgbaColor;
1041
+ static MediumSpringGreen: RgbaColor;
1042
+ static DarkSeaGreen: RgbaColor;
1043
+ static MediumAquamarine: RgbaColor;
1044
+ static YellowGreen: RgbaColor;
1045
+ static LawnGreen: RgbaColor;
1046
+ static Chartreuse: RgbaColor;
1047
+ static LightGreen: RgbaColor;
1048
+ static GreenYellow: RgbaColor;
1049
+ static PaleGreen: RgbaColor;
1050
+ static Teal: RgbaColor;
1051
+ static DarkCyan: RgbaColor;
1052
+ static LightSeaGreen: RgbaColor;
1053
+ static CadetBlue: RgbaColor;
1054
+ static DarkTurquoise: RgbaColor;
1055
+ static MediumTurquoise: RgbaColor;
1056
+ static Turquoise: RgbaColor;
1057
+ static Aqua: RgbaColor;
1058
+ static Cyan: RgbaColor;
1059
+ static Aquamarine: RgbaColor;
1060
+ static PaleTurquoise: RgbaColor;
1061
+ static LightCyan: RgbaColor;
1062
+ static Navy: RgbaColor;
1063
+ static DarkBlue: RgbaColor;
1064
+ static MediumBlue: RgbaColor;
1065
+ static Blue: RgbaColor;
1066
+ static MidnightBlue: RgbaColor;
1067
+ static RoyalBlue: RgbaColor;
1068
+ static SteelBlue: RgbaColor;
1069
+ static DodgerBlue: RgbaColor;
1070
+ static DeepSkyBlue: RgbaColor;
1071
+ static CornflowerBlue: RgbaColor;
1072
+ static SkyBlue: RgbaColor;
1073
+ static LightSkyBlue: RgbaColor;
1074
+ static LightSteelBlue: RgbaColor;
1075
+ static LightBlue: RgbaColor;
1076
+ static PowderBlue: RgbaColor;
1077
+ static Indigo: RgbaColor;
1078
+ static Purple: RgbaColor;
1079
+ static DarkMagenta: RgbaColor;
1080
+ static DarkViolet: RgbaColor;
1081
+ static DarkSlateBlue: RgbaColor;
1082
+ static BlueViolet: RgbaColor;
1083
+ static DarkOrchid: RgbaColor;
1084
+ static Fuchsia: RgbaColor;
1085
+ static Magenta: RgbaColor;
1086
+ static SlateBlue: RgbaColor;
1087
+ static MediumSlateBlue: RgbaColor;
1088
+ static MediumOrchid: RgbaColor;
1089
+ static MediumPurple: RgbaColor;
1090
+ static Orchid: RgbaColor;
1091
+ static Violet: RgbaColor;
1092
+ static Plum: RgbaColor;
1093
+ static Thistle: RgbaColor;
1094
+ static Lavender: RgbaColor;
1095
+ static MistyRose: RgbaColor;
1096
+ static AntiqueWhite: RgbaColor;
1097
+ static Linen: RgbaColor;
1098
+ static Beige: RgbaColor;
1099
+ static WhiteSmoke: RgbaColor;
1100
+ static LavenderBlush: RgbaColor;
1101
+ static OldLace: RgbaColor;
1102
+ static AliceBlue: RgbaColor;
1103
+ static Seashell: RgbaColor;
1104
+ static GhostWhite: RgbaColor;
1105
+ static Honeydew: RgbaColor;
1106
+ static FloralWhite: RgbaColor;
1107
+ static Azure: RgbaColor;
1108
+ static MintCream: RgbaColor;
1109
+ static Snow: RgbaColor;
1110
+ static Ivory: RgbaColor;
1111
+ static White: RgbaColor;
1112
+ static Black: RgbaColor;
1113
+ static DarkSlateGray: RgbaColor;
1114
+ static DimGray: RgbaColor;
1115
+ static SlateGray: RgbaColor;
1116
+ static Gray: RgbaColor;
1117
+ static LightSlateGray: RgbaColor;
1118
+ static DarkGray: RgbaColor;
1119
+ static Silver: RgbaColor;
1120
+ static LightGray: RgbaColor;
1121
+ static Gainsboro: RgbaColor;
1122
+ static RebeccaPurple: RgbaColor;
1123
+ }
1124
+
1125
+ export { Action, Composite, CompositeOptions, Constants, ConstraintType, Constraints, CustomAction, CustomActionOptions, Dimensions, DrawableOptions, Entity, EntityOptions, EntityType, FontData, FontManager, Game, GameInitOptions, GlobalVariables, GroupAction, IDrawable, IText, ImageManager, Label, LabelHorizontalAlignmentMode, LabelOptions, Layout, LayoutConstraint, LoadedImage, MoveAction, MoveActionOptions, Point, PushTransition, RandomDraws, Rect, RectOptions, RgbaColor, ScaleAction, ScaleActionOptions, Scene, SceneOptions, SceneTransition, SequenceAction, Shape, ShapeOptions, ShapeType, Size, Sprite, SpriteOptions, Story, StoryOptions, SvgImage, TapEvent, TapListener, TextLine, TextLineOptions, TextOptions, Timer, Transition, TransitionDirection, TransitionType, WaitAction, WaitActionOptions, WebColors, handleInterfaceOptions };