@m2c2kit/core 0.1.3 → 0.1.4
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 +362 -190
- package/dist/index.js +15 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,67 +1,6 @@
|
|
|
1
|
-
import {
|
|
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 <svg> and end with </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
|
-
}
|
|
1
|
+
import { Canvas, CanvasKit, Image, FontMgr, Typeface } from 'canvaskit-wasm';
|
|
60
2
|
|
|
61
3
|
declare class GlobalVariables {
|
|
62
|
-
canvasKit: CanvasKit;
|
|
63
|
-
fontManager: FontManager;
|
|
64
|
-
imageManager: ImageManager;
|
|
65
4
|
now: number;
|
|
66
5
|
deltaTime: number;
|
|
67
6
|
canvasScale: number;
|
|
@@ -75,6 +14,16 @@ declare global {
|
|
|
75
14
|
}
|
|
76
15
|
//# sourceMappingURL=Globals.d.ts.map
|
|
77
16
|
|
|
17
|
+
interface EntityEvent {
|
|
18
|
+
target: Entity;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface EntityEventListener {
|
|
22
|
+
eventType: string;
|
|
23
|
+
entityName: string;
|
|
24
|
+
callback: (event: EntityEvent) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
78
27
|
/**
|
|
79
28
|
* Position in two-dimensional space.
|
|
80
29
|
*/
|
|
@@ -86,16 +35,7 @@ declare class Point {
|
|
|
86
35
|
constructor(x?: number, y?: number);
|
|
87
36
|
}
|
|
88
37
|
|
|
89
|
-
|
|
90
|
-
entityName?: string;
|
|
91
|
-
codeCallback?: (tapevent: TapEvent) => void;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Object passed to the tap event handler when the entity is tapped.
|
|
95
|
-
*/
|
|
96
|
-
interface TapEvent {
|
|
97
|
-
/** The entity that was tapped */
|
|
98
|
-
tappedEntity: Entity;
|
|
38
|
+
interface TapEvent extends EntityEvent {
|
|
99
39
|
/** Point that was tapped on entity, relative to the entity coordinate system */
|
|
100
40
|
point: Point;
|
|
101
41
|
}
|
|
@@ -193,7 +133,7 @@ declare abstract class Entity implements EntityOptions {
|
|
|
193
133
|
actions: Action[];
|
|
194
134
|
queuedAction?: Action;
|
|
195
135
|
originalActions: Action[];
|
|
196
|
-
|
|
136
|
+
eventListeners: EntityEventListener[];
|
|
197
137
|
uuid: string;
|
|
198
138
|
needsInitialization: boolean;
|
|
199
139
|
userData: any;
|
|
@@ -234,12 +174,12 @@ declare abstract class Entity implements EntityOptions {
|
|
|
234
174
|
*/
|
|
235
175
|
get descendants(): Array<Entity>;
|
|
236
176
|
/**
|
|
237
|
-
*
|
|
177
|
+
* Takes the callback function to be executed when the user taps down on the entity. A TapDown is either a mouse click within the bounds of an entity OR the beginning of touches within the bounds of an entity.
|
|
238
178
|
*
|
|
239
|
-
* @param
|
|
240
|
-
* @param
|
|
179
|
+
* @param callback - function to execute
|
|
180
|
+
* @param replaceExistingCallback - should the provided callback replace any existing callbacks? Usually we want to have only one callback defined, instead of chaining multiple ones. It is strongly recommended not to change this, unless you have a special use case. Default is true.
|
|
241
181
|
*/
|
|
242
|
-
|
|
182
|
+
onTapDown(callback: (tapEvent: TapEvent) => void, replaceExistingCallback?: boolean): void;
|
|
243
183
|
private parseLayoutConstraints;
|
|
244
184
|
private calculateYFromConstraint;
|
|
245
185
|
private calculateXFromConstraint;
|
|
@@ -277,8 +217,8 @@ declare abstract class Entity implements EntityOptions {
|
|
|
277
217
|
*
|
|
278
218
|
* @returns Scene that contains this entity
|
|
279
219
|
*/
|
|
220
|
+
get canvasKit(): CanvasKit;
|
|
280
221
|
get parentSceneAsEntity(): Entity;
|
|
281
|
-
private generateUUID;
|
|
282
222
|
/**
|
|
283
223
|
* For a given directed acyclic graph, topological ordering of the vertices will be identified using BFS
|
|
284
224
|
* @param adjList Adjacency List that represent a graph with vertices and edges
|
|
@@ -414,8 +354,8 @@ declare class GroupAction extends Action implements IActionContainer {
|
|
|
414
354
|
}
|
|
415
355
|
declare class CustomAction extends Action {
|
|
416
356
|
type: ActionType;
|
|
417
|
-
|
|
418
|
-
constructor(
|
|
357
|
+
callback: () => void;
|
|
358
|
+
constructor(callback: () => void, runDuringTransition?: boolean);
|
|
419
359
|
}
|
|
420
360
|
declare class WaitAction extends Action {
|
|
421
361
|
type: ActionType;
|
|
@@ -435,73 +375,147 @@ declare class ScaleAction extends Action {
|
|
|
435
375
|
constructor(scale: number, duration: number, runDuringTransition?: boolean);
|
|
436
376
|
}
|
|
437
377
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
378
|
+
declare class LoadedImage {
|
|
379
|
+
name: string;
|
|
380
|
+
image: Image;
|
|
381
|
+
width: number;
|
|
382
|
+
height: number;
|
|
383
|
+
constructor(name: string, image: Image, width: number, height: number);
|
|
442
384
|
}
|
|
443
385
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
386
|
+
/**
|
|
387
|
+
* Image that can be rendered by a browser and loaded from a URL or HTML svg tag in string form.
|
|
388
|
+
*/
|
|
389
|
+
interface BrowserImage {
|
|
390
|
+
/** Name that will be used to refer to the SVG image. Must be unique among all images */
|
|
391
|
+
name: string;
|
|
392
|
+
/** Width to scale SVG image to */
|
|
393
|
+
width: number;
|
|
394
|
+
/** Height to scale SVG image to */
|
|
395
|
+
height: number;
|
|
396
|
+
/** The HTML SVG tag, in string form, that will be rendered and loaded. Must begin with <svg> and end with </svg> */
|
|
397
|
+
svgString?: string;
|
|
398
|
+
/** URL of SVG asset to render and load */
|
|
399
|
+
url?: string;
|
|
447
400
|
}
|
|
448
401
|
|
|
449
|
-
interface
|
|
402
|
+
interface GameImages {
|
|
403
|
+
uuid: string;
|
|
404
|
+
images: Array<BrowserImage>;
|
|
450
405
|
}
|
|
451
406
|
|
|
452
|
-
declare
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
407
|
+
declare class ImageManager {
|
|
408
|
+
canvasKit?: CanvasKit;
|
|
409
|
+
private renderedImages;
|
|
410
|
+
private loadedImages;
|
|
411
|
+
private _scratchCanvas?;
|
|
412
|
+
private ctx?;
|
|
413
|
+
private scale?;
|
|
414
|
+
getLoadedImage(gameUuid: string, imageName: string): LoadedImage;
|
|
458
415
|
/**
|
|
459
|
-
*
|
|
416
|
+
* Adds a CanvasKit image to the images available to a given game.
|
|
417
|
+
* Typically, this won't be called directly because images will be
|
|
418
|
+
* automatically rendered and loaded in the Activity async init.
|
|
419
|
+
* The only time this function is called in-game is to add
|
|
420
|
+
* screenshot images needed for transitions
|
|
460
421
|
*
|
|
461
|
-
* @param
|
|
422
|
+
* @param loadedImage
|
|
423
|
+
* @param gameUuid
|
|
462
424
|
*/
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
425
|
+
addLoadedImage(loadedImage: LoadedImage, gameUuid: string): void;
|
|
426
|
+
renderImages(allGamesImages: Array<GameImages>): Promise<void[]>;
|
|
427
|
+
loadAllGamesRenderedImages(): void;
|
|
428
|
+
private renderBrowserImage;
|
|
429
|
+
private convertRenderedDataUrlImageToCanvasKitImage;
|
|
430
|
+
/**
|
|
431
|
+
* scratchCanvas is an extra, non-visible canvas in the DOM we use so the native browser can render images
|
|
432
|
+
*/
|
|
433
|
+
private get scratchCanvas();
|
|
434
|
+
private dataURLtoArrayBuffer;
|
|
467
435
|
}
|
|
468
436
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
437
|
+
interface GameFontUrls {
|
|
438
|
+
uuid: string;
|
|
439
|
+
fontUrls: Array<string>;
|
|
440
|
+
}
|
|
473
441
|
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
442
|
+
declare class FontManager {
|
|
443
|
+
canvasKit?: CanvasKit;
|
|
444
|
+
fontMgr?: FontMgr;
|
|
445
|
+
private gameTypefaces;
|
|
446
|
+
private allGamesFontData?;
|
|
447
|
+
/**
|
|
448
|
+
* Gets a typeface that was previously loaded for the specified game.
|
|
449
|
+
*
|
|
450
|
+
* @param gameUuid
|
|
451
|
+
* @param fontFamily
|
|
452
|
+
* @returns the requested Typeface
|
|
453
|
+
*/
|
|
454
|
+
getTypeface(gameUuid: string, fontFamily: string): Typeface;
|
|
455
|
+
/**
|
|
456
|
+
* Fetches all fonts for all games.
|
|
457
|
+
*
|
|
458
|
+
* @param allGamesFontUrls
|
|
459
|
+
* @returns
|
|
460
|
+
*/
|
|
461
|
+
fetchFonts(allGamesFontUrls: Array<GameFontUrls>): Promise<void>;
|
|
462
|
+
/**
|
|
463
|
+
* Takes the fonts, which have been previously fetched and converted into
|
|
464
|
+
* Array Buffers using FontManager.fetchFonts(), and makes them available
|
|
465
|
+
* to our engine
|
|
466
|
+
*/
|
|
467
|
+
loadAllGamesFontData(): void;
|
|
468
|
+
/**
|
|
469
|
+
* For the specified game, fetches all fonts in the array of urls and
|
|
470
|
+
* stores fonts as array buffers.
|
|
471
|
+
*
|
|
472
|
+
* @param gameUuid
|
|
473
|
+
* @param fontUrls - array of font urls
|
|
474
|
+
* @returns
|
|
475
|
+
*/
|
|
476
|
+
private fetchGameFontsAsArrayBuffers;
|
|
477
|
+
/**
|
|
478
|
+
* For the specified game, loads all fonts from array buffers and makes
|
|
479
|
+
* fonts available within canvaskit as a Typeface
|
|
480
|
+
*
|
|
481
|
+
* @param gameUuid
|
|
482
|
+
* @param fonts - array of fonts in array buffer form
|
|
483
|
+
*/
|
|
484
|
+
private loadGameFonts;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
interface GameEvent {
|
|
488
|
+
gameUuid: string;
|
|
489
|
+
gameName: string;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
interface GameLifecycleEvent extends GameEvent {
|
|
493
|
+
ended: boolean;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
interface GameParameters {
|
|
497
|
+
[key: string]: DefaultParameter;
|
|
498
|
+
}
|
|
499
|
+
interface DefaultParameter {
|
|
500
|
+
value: any;
|
|
501
|
+
type?: "number" | "string" | "boolean" | "object";
|
|
502
|
+
description?: string;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
interface IDrawable {
|
|
506
|
+
draw(canvas: Canvas): void;
|
|
507
|
+
anchorPoint: Point;
|
|
508
|
+
zPosition: number;
|
|
486
509
|
}
|
|
487
510
|
|
|
488
511
|
/**
|
|
489
|
-
*
|
|
490
|
-
* an enum to avoid magic strings.
|
|
512
|
+
* Color in red (0-255), green (0-255), blue (0-255), alpha (0-1) format. Must be numeric array of length 4.
|
|
491
513
|
*/
|
|
492
|
-
declare
|
|
493
|
-
topToTopOf = "topToTopOf",
|
|
494
|
-
topToBottomOf = "topToBottomOf",
|
|
495
|
-
bottomToTopOf = "bottomToTopOf",
|
|
496
|
-
bottomToBottomOf = "bottomToBottomOf",
|
|
497
|
-
startToStartOf = "startToStartOf",
|
|
498
|
-
startToEndOf = "startToEndOf",
|
|
499
|
-
endToEndOf = "endToEndOf",
|
|
500
|
-
endToStartOf = "endToStartOf"
|
|
501
|
-
}
|
|
514
|
+
declare type RgbaColor = [number, number, number, number];
|
|
502
515
|
|
|
503
|
-
|
|
504
|
-
|
|
516
|
+
interface DrawableOptions {
|
|
517
|
+
anchorPoint?: Point;
|
|
518
|
+
zPosition?: number;
|
|
505
519
|
}
|
|
506
520
|
|
|
507
521
|
interface SceneOptions extends EntityOptions, DrawableOptions {
|
|
@@ -538,9 +552,9 @@ declare class Scene extends Entity implements IDrawable, SceneOptions {
|
|
|
538
552
|
*
|
|
539
553
|
* @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.
|
|
540
554
|
*
|
|
541
|
-
* @param
|
|
555
|
+
* @param callback
|
|
542
556
|
*/
|
|
543
|
-
setup(
|
|
557
|
+
setup(callback: (scene: Scene) => void): void;
|
|
544
558
|
draw(canvas: Canvas): void;
|
|
545
559
|
}
|
|
546
560
|
|
|
@@ -576,10 +590,28 @@ declare class SceneTransition {
|
|
|
576
590
|
constructor(scene: Scene, transition?: Transition | undefined);
|
|
577
591
|
}
|
|
578
592
|
|
|
593
|
+
interface TrialSchema {
|
|
594
|
+
[key: string]: PropertySchema;
|
|
595
|
+
}
|
|
596
|
+
interface PropertySchema {
|
|
597
|
+
type: "number" | "string" | "boolean" | "object";
|
|
598
|
+
description?: string;
|
|
599
|
+
}
|
|
600
|
+
|
|
579
601
|
/**
|
|
580
602
|
* Options to specify HTML canvas, set game canvas size, and load game assets.
|
|
581
603
|
*/
|
|
582
|
-
interface
|
|
604
|
+
interface GameOptions {
|
|
605
|
+
/** Human-friendly name of this game */
|
|
606
|
+
name: string;
|
|
607
|
+
/** Version of this game */
|
|
608
|
+
version?: string;
|
|
609
|
+
/** Uri (repository, webpage, or other location where full information about the game can be found) */
|
|
610
|
+
uri?: string;
|
|
611
|
+
/** Brief description of game */
|
|
612
|
+
shortDescription?: string;
|
|
613
|
+
/** Full description of game */
|
|
614
|
+
longDescription?: string;
|
|
583
615
|
/** Id of the HTML canvas that game will be drawn on. If not provided, the first canvas found will be used */
|
|
584
616
|
canvasId?: string;
|
|
585
617
|
/** Width of game canvas */
|
|
@@ -589,13 +621,13 @@ interface GameInitOptions {
|
|
|
589
621
|
/** Stretch to fill screen? Default is false */
|
|
590
622
|
stretch?: boolean;
|
|
591
623
|
/** Schema of trial data; JSON object where key is variable name, value is data type */
|
|
592
|
-
trialSchema?:
|
|
624
|
+
trialSchema?: TrialSchema;
|
|
593
625
|
/** Default game parameters; JSON object where key is the game parameter, value is default value */
|
|
594
|
-
|
|
626
|
+
parameters?: GameParameters;
|
|
595
627
|
/** String array of urls from which to load fonts. The first element will be the default font */
|
|
596
628
|
fontUrls?: Array<string>;
|
|
597
|
-
/** Array of
|
|
598
|
-
|
|
629
|
+
/** Array of BrowserImage objects to render and load */
|
|
630
|
+
images?: Array<BrowserImage>;
|
|
599
631
|
/** Show FPS in upper left corner? Default is false */
|
|
600
632
|
showFps?: boolean;
|
|
601
633
|
/** Color of the html body, if the game does not fill the screen. Useful for showing scene boundaries. Default is the scene background color */
|
|
@@ -610,25 +642,20 @@ interface TrialData {
|
|
|
610
642
|
interface Metadata {
|
|
611
643
|
userAgent?: string;
|
|
612
644
|
}
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
645
|
+
declare class Game implements Activity {
|
|
646
|
+
_canvasKit?: CanvasKit;
|
|
647
|
+
_session?: Session;
|
|
648
|
+
uuid: string;
|
|
649
|
+
options: GameOptions;
|
|
650
|
+
constructor(options: GameOptions, specifiedParameters?: any);
|
|
651
|
+
get canvasKit(): CanvasKit;
|
|
652
|
+
set canvasKit(canvasKit: CanvasKit);
|
|
653
|
+
get session(): Session;
|
|
654
|
+
set session(session: Session);
|
|
622
655
|
entryScene?: Scene | string;
|
|
623
|
-
parameters: any;
|
|
624
|
-
private defaultParameters;
|
|
625
656
|
data: GameData;
|
|
626
|
-
|
|
627
|
-
trialSchema: {};
|
|
628
|
-
lifecycle: LifecycleCallbacks;
|
|
629
|
-
private trialSchemaMap;
|
|
657
|
+
trialIndex: number;
|
|
630
658
|
private htmlCanvas?;
|
|
631
|
-
private scratchHtmlCanvas?;
|
|
632
659
|
private surface?;
|
|
633
660
|
private showFps?;
|
|
634
661
|
private bodyBackgroundColor?;
|
|
@@ -643,32 +670,12 @@ declare class Game {
|
|
|
643
670
|
private animationFramesRequested;
|
|
644
671
|
private limitFps;
|
|
645
672
|
private unitTesting;
|
|
673
|
+
private gameStopRequested;
|
|
646
674
|
canvasCssWidth: number;
|
|
647
675
|
canvasCssHeight: number;
|
|
648
676
|
private scenes;
|
|
649
677
|
private incomingSceneTransitions;
|
|
650
678
|
private currentSceneSnapshot?;
|
|
651
|
-
/**
|
|
652
|
-
* Asynchronously initializes the game engine and load assets
|
|
653
|
-
*
|
|
654
|
-
* @param gameInitOptions
|
|
655
|
-
* @returns Promise<void>
|
|
656
|
-
*/
|
|
657
|
-
init(gameInitOptions: GameInitOptions): Promise<void>;
|
|
658
|
-
/**
|
|
659
|
-
* Provide a callback function to be invoked when a trial has completed.
|
|
660
|
-
* It is the responsibility of the the game programmer to call this
|
|
661
|
-
* at the appropriate time. It is not triggered automatically.
|
|
662
|
-
* @param codeCallback
|
|
663
|
-
*/
|
|
664
|
-
onTrialComplete(codeCallback: (trialNumber: number, data: GameData, trialSchema: object) => void): void;
|
|
665
|
-
/**
|
|
666
|
-
* Provide a callback function to be invoked when all trials are complete.
|
|
667
|
-
* It is the responsibility of the the game programmer to call this
|
|
668
|
-
* at the appropriate time. It is not triggered automatically.
|
|
669
|
-
* @param codeCallback
|
|
670
|
-
*/
|
|
671
|
-
onAllTrialsComplete(codeCallback: (data: GameData, trialSchema: object) => void): void;
|
|
672
679
|
/**
|
|
673
680
|
* Adds a scene to the game.
|
|
674
681
|
*
|
|
@@ -691,10 +698,8 @@ declare class Game {
|
|
|
691
698
|
*/
|
|
692
699
|
presentScene(scene: string | Scene, transition?: Transition): void;
|
|
693
700
|
/**
|
|
694
|
-
* Gets the value of the
|
|
695
|
-
*
|
|
696
|
-
* defaultParameters. If the parameterName is still not found, then
|
|
697
|
-
* throw exception.
|
|
701
|
+
* Gets the value of the game parameter. If parameterName
|
|
702
|
+
* is not found, then throw exception.
|
|
698
703
|
* @param parameterName - the name of the game parameter whose value is requested
|
|
699
704
|
* @returns
|
|
700
705
|
*/
|
|
@@ -705,7 +710,8 @@ declare class Game {
|
|
|
705
710
|
* @param entryScene - The scene (Scene object or its string name) to display when the game starts
|
|
706
711
|
*/
|
|
707
712
|
start(entryScene?: Scene | string): void;
|
|
708
|
-
|
|
713
|
+
stop(): void;
|
|
714
|
+
initData(): void;
|
|
709
715
|
/**
|
|
710
716
|
* Adds data to the game's TrialData object.
|
|
711
717
|
*
|
|
@@ -715,11 +721,26 @@ declare class Game {
|
|
|
715
721
|
* @param value - value of the variable to set
|
|
716
722
|
*/
|
|
717
723
|
addTrialData(variableName: string, value: any): void;
|
|
718
|
-
|
|
724
|
+
/**
|
|
725
|
+
* Should be called when the current trial has completed. It will
|
|
726
|
+
* also increment the trial index.
|
|
727
|
+
* Calling this will trigger the onTrialComplete callback function,
|
|
728
|
+
* if one was provided in SessionOptions. This is how the game communicates
|
|
729
|
+
* trial data to the parent session, which can then save or process the data.
|
|
730
|
+
* It is the responsibility of the the game programmer to call this at
|
|
731
|
+
* the appropriate time. It is not triggered automatically.
|
|
732
|
+
*/
|
|
733
|
+
trialComplete(): void;
|
|
734
|
+
/**
|
|
735
|
+
* Should be called when the current game has ended. This will trigger
|
|
736
|
+
* the onGameEnd callback function, if one was provided in SessionOptions.
|
|
737
|
+
* This is how the game communicates its ended or "finished" state to the
|
|
738
|
+
* parent session.
|
|
739
|
+
* It is the responsibility of the the game programmer to call this at
|
|
740
|
+
* the appropriate time. It is not triggered automatically.
|
|
741
|
+
*/
|
|
742
|
+
end(): void;
|
|
719
743
|
private setupHtmlCanvases;
|
|
720
|
-
private fetchFonts;
|
|
721
|
-
private renderSvgImages;
|
|
722
|
-
private loadFonts;
|
|
723
744
|
private setupCanvasKitSurface;
|
|
724
745
|
private setupFpsFont;
|
|
725
746
|
private setupEventHandlers;
|
|
@@ -732,27 +753,174 @@ declare class Game {
|
|
|
732
753
|
private animateSceneTransition;
|
|
733
754
|
private drawFps;
|
|
734
755
|
/**
|
|
735
|
-
* Creates
|
|
756
|
+
* Creates an event listener for an entity based on the entity name
|
|
736
757
|
*
|
|
737
|
-
* @remarks Typically,
|
|
758
|
+
* @remarks Typically, event listeners will be created using a method specific to the event, such as onTapDown(). This alternative allows creation with entity name.
|
|
738
759
|
*
|
|
739
|
-
* @param
|
|
740
|
-
* @param
|
|
741
|
-
* @param
|
|
760
|
+
* @param eventType - the type of event to listen for, e.g., "tapdown"
|
|
761
|
+
* @param entityName - the entity name for which an event will be listened
|
|
762
|
+
* @param callback
|
|
763
|
+
* @param replaceExistingCallback
|
|
742
764
|
*/
|
|
743
|
-
|
|
765
|
+
createEventListener(eventType: string, entityName: string, callback: (event: EntityEvent) => void, replaceExistingCallback?: boolean): void;
|
|
744
766
|
/**
|
|
745
767
|
* Returns array of all entities that have been added to the game object.
|
|
746
768
|
*/
|
|
747
769
|
get entities(): Array<Entity>;
|
|
748
770
|
private htmlCanvasMouseDownHandler;
|
|
749
771
|
private htmlCanvasTouchStartHandler;
|
|
772
|
+
private sceneCanReceiveUserInteraction;
|
|
750
773
|
private processTaps;
|
|
751
774
|
private handleEntityTapped;
|
|
752
775
|
private tapIsWithinEntityBounds;
|
|
753
776
|
private calculateEntityAbsoluteBoundingBox;
|
|
754
777
|
}
|
|
755
778
|
|
|
779
|
+
interface GameData {
|
|
780
|
+
trials: Array<TrialData>;
|
|
781
|
+
metadata: Metadata;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
interface GameTrialEvent extends GameEvent {
|
|
785
|
+
trialIndex: number;
|
|
786
|
+
trialSchema: TrialSchema;
|
|
787
|
+
gameData: GameData;
|
|
788
|
+
gameParameters: GameParameters;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
interface GameCallbacks {
|
|
792
|
+
/** Callback executed when the current game has ended. */
|
|
793
|
+
onGameEnd?: (event: GameLifecycleEvent) => void;
|
|
794
|
+
/** Callback executed when a game trial has completed. */
|
|
795
|
+
onGameTrialComplete?: (event: GameTrialEvent) => void;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
interface SessionOptions {
|
|
799
|
+
/** The activities that compose this session */
|
|
800
|
+
activities: Array<Activity>;
|
|
801
|
+
/** Callbacks executed when trials are completed and when game ends */
|
|
802
|
+
gameCallbacks?: GameCallbacks;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
declare class Session {
|
|
806
|
+
options: SessionOptions;
|
|
807
|
+
fontManager: FontManager;
|
|
808
|
+
imageManager: ImageManager;
|
|
809
|
+
currentActivity?: Activity;
|
|
810
|
+
uuid: string;
|
|
811
|
+
private canvasKit?;
|
|
812
|
+
/**
|
|
813
|
+
* A Session contains one or more activities; currently, the only
|
|
814
|
+
* class that implements Activity is Game, but Survey is planned.
|
|
815
|
+
* The session manages the start and stop of activities, and
|
|
816
|
+
* advancement to next activity
|
|
817
|
+
*
|
|
818
|
+
* @param options
|
|
819
|
+
*/
|
|
820
|
+
constructor(options: SessionOptions);
|
|
821
|
+
/**
|
|
822
|
+
* Asynchronously initializes the m2c2kit engine and loads assets
|
|
823
|
+
*/
|
|
824
|
+
init(): Promise<void>;
|
|
825
|
+
/**
|
|
826
|
+
* Starts the session and starts the first activity.
|
|
827
|
+
*/
|
|
828
|
+
start(): void;
|
|
829
|
+
/**
|
|
830
|
+
* Stops the current activity and advances to next activity in the session.
|
|
831
|
+
* If there is no activity after the current activity, throws error
|
|
832
|
+
*/
|
|
833
|
+
advanceToNextActivity(): void;
|
|
834
|
+
/**
|
|
835
|
+
* Gets the next activity after the current one, or undefined if
|
|
836
|
+
* this is the last activity.
|
|
837
|
+
*/
|
|
838
|
+
get nextActivity(): Activity | undefined;
|
|
839
|
+
private logStartingActivity;
|
|
840
|
+
/**
|
|
841
|
+
* Gets asynchronous assets, including initialization of canvaskit wasm,
|
|
842
|
+
* fetching of fonts from specified urls, and rendering and fetching
|
|
843
|
+
* of images
|
|
844
|
+
* @returns
|
|
845
|
+
*/
|
|
846
|
+
private getAsynchronousAssets;
|
|
847
|
+
private loadCanvasKit;
|
|
848
|
+
private loadAssets;
|
|
849
|
+
private assignCanvasKit;
|
|
850
|
+
private getFontsConfigurationFromGames;
|
|
851
|
+
private getImagesConfigurationFromGames;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
interface Activity {
|
|
855
|
+
/** Starts the activity */
|
|
856
|
+
start(): void;
|
|
857
|
+
/** Stops the activity */
|
|
858
|
+
stop(): void;
|
|
859
|
+
/** The activity's parent session */
|
|
860
|
+
session: Session;
|
|
861
|
+
/** The activity's unique identifier. NOTE: This is newly generated each session. The uuid for an activity will vary across sessions. */
|
|
862
|
+
uuid: string;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
interface CompositeOptions extends EntityOptions, DrawableOptions {
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
declare abstract class Composite extends Entity implements IDrawable {
|
|
869
|
+
readonly type = EntityType.composite;
|
|
870
|
+
compositeType: string;
|
|
871
|
+
isDrawable: boolean;
|
|
872
|
+
anchorPoint: Point;
|
|
873
|
+
zPosition: number;
|
|
874
|
+
/**
|
|
875
|
+
* Base Drawable object for creating custom entities ("composites") composed of primitive entities.
|
|
876
|
+
*
|
|
877
|
+
* @param options
|
|
878
|
+
*/
|
|
879
|
+
constructor(options?: CompositeOptions);
|
|
880
|
+
initialize(): void;
|
|
881
|
+
update(): void;
|
|
882
|
+
draw(canvas: Canvas): void;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Reasonable defaults to use if values are not specified.
|
|
887
|
+
*/
|
|
888
|
+
declare class Constants {
|
|
889
|
+
static readonly FPS_DISPLAY_TEXT_FONT_SIZE = 12;
|
|
890
|
+
static readonly FPS_DISPLAY_TEXT_COLOR: RgbaColor;
|
|
891
|
+
static readonly FPS_DISPLAY_UPDATE_INTERVAL = 500;
|
|
892
|
+
static readonly DEFAULT_SCENE_BACKGROUND_COLOR: RgbaColor;
|
|
893
|
+
static readonly DEFAULT_SHAPE_FILL_COLOR: RgbaColor;
|
|
894
|
+
static readonly DEFAULT_FONT_COLOR: RgbaColor;
|
|
895
|
+
static readonly DEFAULT_FONT_SIZE = 16;
|
|
896
|
+
static readonly LIMITED_FPS_RATE = 5;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* This enum is used interally for processing the layout constraints. We use
|
|
901
|
+
* an enum to avoid magic strings.
|
|
902
|
+
*/
|
|
903
|
+
declare enum ConstraintType {
|
|
904
|
+
topToTopOf = "topToTopOf",
|
|
905
|
+
topToBottomOf = "topToBottomOf",
|
|
906
|
+
bottomToTopOf = "bottomToTopOf",
|
|
907
|
+
bottomToBottomOf = "bottomToBottomOf",
|
|
908
|
+
startToStartOf = "startToStartOf",
|
|
909
|
+
startToEndOf = "startToEndOf",
|
|
910
|
+
endToEndOf = "endToEndOf",
|
|
911
|
+
endToStartOf = "endToStartOf"
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
declare enum Dimensions {
|
|
915
|
+
MATCH_CONSTRAINT = 0
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
interface FontData {
|
|
919
|
+
gameUuid: string;
|
|
920
|
+
fontUrl: string;
|
|
921
|
+
fontArrayBuffer: ArrayBuffer;
|
|
922
|
+
}
|
|
923
|
+
|
|
756
924
|
interface IText {
|
|
757
925
|
text?: string;
|
|
758
926
|
fontName?: string;
|
|
@@ -1042,6 +1210,10 @@ declare class Timer {
|
|
|
1042
1210
|
static RemoveAll(): void;
|
|
1043
1211
|
}
|
|
1044
1212
|
|
|
1213
|
+
declare class Uuid {
|
|
1214
|
+
static generate(): string;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1045
1217
|
declare class WebColors {
|
|
1046
1218
|
static Transparent: RgbaColor;
|
|
1047
1219
|
static MediumVioletRed: RgbaColor;
|
|
@@ -1187,4 +1359,4 @@ declare class WebColors {
|
|
|
1187
1359
|
static RebeccaPurple: RgbaColor;
|
|
1188
1360
|
}
|
|
1189
1361
|
|
|
1190
|
-
export { Action, Composite, CompositeOptions, Constants, ConstraintType, Constraints, CustomAction, CustomActionOptions, Dimensions, DrawableOptions, Entity, EntityOptions, EntityType, FontData, FontManager, Game, GameData,
|
|
1362
|
+
export { Action, Activity, BrowserImage, Composite, CompositeOptions, Constants, ConstraintType, Constraints, CustomAction, CustomActionOptions, DefaultParameter, Dimensions, DrawableOptions, Entity, EntityEventListener, EntityOptions, EntityType, FontData, FontManager, Game, GameCallbacks, GameData, GameLifecycleEvent, GameOptions, GameParameters, GameTrialEvent, GlobalVariables, GroupAction, IDrawable, IText, ImageManager, Label, LabelHorizontalAlignmentMode, LabelOptions, Layout, LayoutConstraint, LoadedImage, Metadata, MoveAction, MoveActionOptions, Point, PropertySchema, PushTransition, RandomDraws, Rect, RectOptions, RgbaColor, ScaleAction, ScaleActionOptions, Scene, SceneOptions, SceneTransition, SequenceAction, Session, SessionOptions, Shape, ShapeOptions, ShapeType, Size, Sprite, SpriteOptions, Story, StoryOptions, TextLine, TextLineOptions, TextOptions, Timer, Transition, TransitionDirection, TransitionType, TrialData, TrialSchema, Uuid, WaitAction, WaitActionOptions, WebColors, handleInterfaceOptions };
|