Skip to main content

Class: Game

Implements

Constructors

new Game()

new Game(options): Game

The base class for all games. New games should extend this class.

Parameters

options: GameOptions

GameOptions

Returns

Game

Defined in

m2c2kit/packages/core/src/Game.ts:111

Properties

_canvasKit?

optional _canvasKit: CanvasKit

Defined in

m2c2kit/packages/core/src/Game.ts:68


additionalParameters?

optional additionalParameters: unknown

Additional activity parameters that were set.

Implementation of

Activity.additionalParameters

Defined in

m2c2kit/packages/core/src/Game.ts:92


beginIso8601Timestamp

beginIso8601Timestamp: string = ""

The value of new Date().toISOString() immediately before the activity begins

Implementation of

Activity.beginIso8601Timestamp

Defined in

m2c2kit/packages/core/src/Game.ts:80


beginTimestamp

beginTimestamp: number = NaN

The value of performance.now() immediately before the activity begins

Implementation of

Activity.beginTimestamp

Defined in

m2c2kit/packages/core/src/Game.ts:79


bodyBackgroundColor?

optional bodyBackgroundColor: RgbaColor

Defined in

m2c2kit/packages/core/src/Game.ts:911


canvasCssHeight

canvasCssHeight: number = 0

Defined in

m2c2kit/packages/core/src/Game.ts:925


canvasCssWidth

canvasCssWidth: number = 0

Defined in

m2c2kit/packages/core/src/Game.ts:924


canvasKitWasmVersion

readonly canvasKitWasmVersion: "__CANVASKITWASM_VERSION__" = "__CANVASKITWASM_VERSION__"

Defined in

m2c2kit/packages/core/src/Game.ts:77


dataManager

dataManager: DataManager

Defined in

m2c2kit/packages/core/src/Game.ts:98


entryScene?

optional entryScene: string | Scene

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

Defined in

m2c2kit/packages/core/src/Game.ts:899


eventStore

eventStore: EventStore

Defined in

m2c2kit/packages/core/src/Game.ts:100


i18n?

optional i18n: I18n

Defined in

m2c2kit/packages/core/src/Game.ts:87


id

id: string

Short identifier of this activity

Implementation of

Activity.id

Defined in

m2c2kit/packages/core/src/Game.ts:72


manifest?

optional manifest: Manifest

Defined in

m2c2kit/packages/core/src/Game.ts:99


materializedNodes

materializedNodes: M2Node[]

Nodes created during event replay

Defined in

m2c2kit/packages/core/src/Game.ts:104


moduleMetadata

moduleMetadata: ModuleMetadata

Defined in

m2c2kit/packages/core/src/Game.ts:76


name

name: string

Human-friendly name of this activity

Implementation of

Activity.name

Defined in

m2c2kit/packages/core/src/Game.ts:71


options

options: GameOptions

Defined in

m2c2kit/packages/core/src/Game.ts:78


publishUuid

publishUuid: string = ""

Persistent unique identifier (UUID) of the activity. Required for games. Optional or empty string if a survey.

Implementation of

Activity.publishUuid

Defined in

m2c2kit/packages/core/src/Game.ts:73


sceneManager

sceneManager: SceneManager

Defined in

m2c2kit/packages/core/src/Game.ts:97


sessionUuid

sessionUuid: string = ""

The activity's parent session unique identifier. This is newly generated each session.

Implementation of

Activity.sessionUuid

Defined in

m2c2kit/packages/core/src/Game.ts:69


studyId?

optional studyId: string

The ID of the study (protocol, experiment, or other aggregate) that contains the repeated administrations of this activity. The ID should be short, url-friendly, human-readable text (no spaces, special characters, or slashes), e.g., nyc-aging-cohort.

Implementation of

Activity.studyId

Defined in

m2c2kit/packages/core/src/Game.ts:74


studyUuid?

optional studyUuid: string

Unique identifier (UUID) of the study (protocol, experiment, or other aggregate) that contains the administration of this activity.

Implementation of

Activity.studyUuid

Defined in

m2c2kit/packages/core/src/Game.ts:75


surface?

optional surface: Surface

Defined in

m2c2kit/packages/core/src/Game.ts:909


type

readonly type: Game = ActivityType.Game

The type of activity: Game or Survey

Implementation of

Activity.type

Defined in

m2c2kit/packages/core/src/Game.ts:67


uuid

uuid: string

The activity's unique identifier. This is newly generated each session. The UUID for an activity will vary across sessions.

Implementation of

Activity.uuid

Defined in

m2c2kit/packages/core/src/Game.ts:70

Accessors

canvasKit

Get Signature

get canvasKit(): CanvasKit

Returns

CanvasKit

Set Signature

set canvasKit(canvasKit): void

Parameters

canvasKit: CanvasKit

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:887


currentScene

Get Signature

get currentScene(): undefined | Scene

Returns the current game scene.

Remarks

The current scene is the scene that is currently being rendered. If no scene has been set as the current scene, this will return undefined.

Returns

undefined | Scene

Defined in

m2c2kit/packages/core/src/Game.ts:551


data

Get Signature

get data(): GameData

The participant data generated by the game.

Returns

GameData

Defined in

m2c2kit/packages/core/src/Game.ts:901


dataStores

Get Signature

get dataStores(): IDataStore[]

Optional stores to use for saving data. The implementation of the store is not provided by the @m2c2kit/core library.

Returns

IDataStore[]

Set Signature

set dataStores(dataStores): void

Optional stores to use for saving data. The implementation of the store is not provided by the @m2c2kit/core library.

Parameters

dataStores: IDataStore[]

Returns

void

Optional stores to use for saving data. The implementation of the store is not provided by the @m2c2kit/core library.

Implementation of

Activity.dataStores

Defined in

m2c2kit/packages/core/src/Game.ts:728


entities

Get Signature

get entities(): M2Node[]

Deprecated

use Game.nodes instead

Returns

M2Node[]

Defined in

m2c2kit/packages/core/src/Game.ts:2336


eventMaterializer

Get Signature

get eventMaterializer(): EventMaterializer

Returns

EventMaterializer

Set Signature

set eventMaterializer(eventMaterializer): void

Parameters

eventMaterializer: EventMaterializer

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:516


fontManager

Get Signature

get fontManager(): FontManager

Returns

FontManager

Set Signature

set fontManager(fontManager): void

Parameters

fontManager: FontManager

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:483


freeEntities

Get Signature

get freeEntities(): M2Node[]

Deprecated

Use Game.freeEntities instead

Returns

M2Node[]

Defined in

m2c2kit/packages/core/src/Game.ts:997


freeNodes

Get Signature

get freeNodes(): M2Node[]

Returns array of free nodes that have been added to the game.

Returns

M2Node[]

array of free nodes

Defined in

m2c2kit/packages/core/src/Game.ts:990


imageManager

Get Signature

get imageManager(): ImageManager

Returns

ImageManager

Set Signature

set imageManager(imageManager): void

Parameters

imageManager: ImageManager

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:494


inputManager

Get Signature

get inputManager(): InputManager

Returns

InputManager

Set Signature

set inputManager(inputManager): void

Parameters

inputManager: InputManager

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:526


nodes

Get Signature

get nodes(): M2Node[]

Returns array of all nodes that have been added to the game object.

Returns

M2Node[]

Defined in

m2c2kit/packages/core/src/Game.ts:2320


scenes

Get Signature

get scenes(): Scene[]

Returns the scenes that have been added to the game.

Returns

Scene[]

Defined in

m2c2kit/packages/core/src/Game.ts:540


snapshots

Get Signature

get snapshots(): Image[]

Returns the game snapshots.

Remarks

Snapshots are the most recent images of the current scene. These are in raw CanvasKit Image format and must be converted to another format, such as PNG via CanvasKit.MakeImage(), before they can be meaningfully exported.

Returns

Image[]

Defined in

m2c2kit/packages/core/src/Game.ts:563


soundManager

Get Signature

get soundManager(): SoundManager

Returns

SoundManager

Set Signature

set soundManager(soundManager): void

Parameters

soundManager: SoundManager

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:505


trialIndex

Get Signature

get trialIndex(): number

The 0-based index of the current trial

Returns

number

Defined in

m2c2kit/packages/core/src/Game.ts:905

Methods

addFreeEntity()

addFreeEntity(node): void

Parameters

node: M2Node

Returns

void

Deprecated

Use addFreeNode() instead

Defined in

m2c2kit/packages/core/src/Game.ts:948


addFreeNode()

addFreeNode(node): void

Adds a node as a free node (a node that is not part of a scene) to the game.

Parameters

node: M2Node

node to add as a free node

Returns

void

Remarks

Once added to the game, a free node will always be drawn, and it will not be part of any scene transitions. This is useful if a node must persistently be drawn and not move with scene transitions. The appearance of the free node must be managed by the programmer. Note: internally, the free nodes are part of a special scene (named "__freeNodesScene"), but this scene is handled apart from regular scenes in order to achieve the free node behavior.

Defined in

m2c2kit/packages/core/src/Game.ts:941


addScene()

addScene(scene): void

Adds a scene to the game.

Parameters

scene: Scene

Returns

void

Remarks

A scene, and its children nodes, cannot be presented unless it has been added to the game object. A scene can be added to the game only once.

Defined in

m2c2kit/packages/core/src/Game.ts:1010


addScenes()

addScenes(scenes): void

Adds multiple scenes to the game.

Parameters

scenes: Scene[]

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:1019


addScoringData()

addScoringData(variableNameOrObject, value?): void

Adds data to the game's scoring data.

Parameters

variableNameOrObject: string | Record<string, JsonSchemaDataTypeScriptTypes> | Record<string, JsonSchemaDataTypeScriptTypes>[]

Either a variable name (string) or an object containing multiple key-value pairs to add all at once.

value?: JsonSchemaDataTypeScriptTypes

Value of the variable to set (only used when variableNameOrObject is a variable name string).

Returns

void

Remarks

The variable name (or object property names) must be previously defined in the ScoringSchema object in GameOptions. The type of the value must match what was defined in the scoring schema, otherwise an error is thrown.

Defined in

m2c2kit/packages/core/src/Game.ts:1630


addStaticTrialData()

addStaticTrialData(variableName, value): void

Sets the value of a variable that will be the same for all trials.

Parameters

variableName: string

variable to be set

value: JsonSchemaDataTypeScriptTypes

value of the variable to set

Returns

void

Remarks

This sets the value of a variable that is the same across all trials ("static"). This is useful for variables that are not part of the trial schema, but that you want to save for each trial in your use case. For example, you might want to save the subject's participant ID for each trial, but this is not part of the trial schema. Rather than modify the source code for the game, you can do the following to ensure that the participant ID is saved for each trial:

game.addTrialSchema(&#123 participant_id: &#123 type: "string", description: "ID of the participant", } }); game.addStaticTrialData("participant_id", "12345");

When Game.trialComplete() is called, the participant_id variable will be saved for the trial with the value "12345".

Defined in

m2c2kit/packages/core/src/Game.ts:1685


addTrialData()

addTrialData(variableName, value): void

Adds data to the game's TrialData object.

Parameters

variableName: string

variable to be set

value: JsonSchemaDataTypeScriptTypes

value of the variable to set

Returns

void

Remarks

variableName must be previously defined in the TrialSchema object in GameOptions. The type of the value must match what was defined in the trial schema, otherwise an error is thrown.

Defined in

m2c2kit/packages/core/src/Game.ts:1610


addTrialSchema()

addTrialSchema(schema): void

Adds custom trial schema to the game's trialSchema object.

Parameters

schema: TrialSchema

Trial schema to add

Returns

void

Remarks

This is useful if you want to add custom trial variables. This must be done before Session.start() is called, because Session.start() will call Game.start(), which will initialize the trial schema.

Defined in

m2c2kit/packages/core/src/Game.ts:1650


cancel()

cancel(): void

Should be called when current game has been canceled by a user action.

Returns

void

Remarks

This will send an ActivityCancel event to any listeners, such as a function provided to Game.onCancel() or a callback defined in SessionOptions.activityCallbacks.onActivityLifecycle. This is how the game can communicate changes in activity state to the parent session. It is the responsibility of the the game programmer to call this at the appropriate time. It is not triggered automatically.

Defined in

m2c2kit/packages/core/src/Game.ts:1889


createEventListener()

createEventListener(type, nodeName, callback, callbackOptions?): void

Creates an event listener for a node based on the node name

Parameters

type: M2EventType

the type of event to listen for, e.g., "tapDown"

nodeName: string

the node name for which an event will be listened

callback

the callback to be invoked when the event occurs

callbackOptions?: CallbackOptions

Returns

void

Remarks

Typically, event listeners will be created using a method specific to the event, such as onTapDown(). This alternative allows creation with node name.

Defined in

m2c2kit/packages/core/src/Game.ts:2290


dispose()

dispose(): void

Frees up resources that were allocated to run the game.

Returns

void

Remarks

This will be done automatically by the m2c2kit library; the end-user must not call this. FOR INTERNAL USE ONLY.

Defined in

m2c2kit/packages/core/src/Game.ts:1591


end()

end(): void

Should be called when current game has ended successfully.

Returns

void

Remarks

This will send an ActivityEnd event to any listeners, such as a function provided to Game.onEnd() or a callback defined in SessionOptions.activityCallbacks.onActivityLifecycle. This is how the game can communicate changes in activity state to the parent session. It is the responsibility of the the game programmer to call this at the appropriate time. It is not triggered automatically.

Defined in

m2c2kit/packages/core/src/Game.ts:1858


getParameter()

getParameter<T>(parameterName): T

Gets the value of the game parameter. If parameterName is not found, then throw exception.

Type Parameters

T

Parameters

parameterName: string

the name of the game parameter whose value is requested

Returns

T

Defined in

m2c2kit/packages/core/src/Game.ts:1051


getParameterOrFallback()

getParameterOrFallback<T, U>(parameterName, fallbackValue): T | U

Gets the value of the game parameter. If parameterName is not found, then return fallback value

Type Parameters

T

U

Parameters

parameterName: string

the name of the game parameter whose value is requested

fallbackValue: U

the value to return if parameterName is not found

Returns

T | U

Defined in

m2c2kit/packages/core/src/Game.ts:1070


hasDataStores()

hasDataStores(): boolean

Returns

boolean

Defined in

m2c2kit/packages/core/src/Game.ts:739


hasParameter()

hasParameter(parameterName): boolean

Returns true if a game parameter exists for the given string.

Parameters

parameterName: string

the name of the game parameter whose existence is queried

Returns

boolean

Defined in

m2c2kit/packages/core/src/Game.ts:1087


init()

init(): Promise<void>

Initializes the activity.

Returns

Promise<void>

Remarks

All code to create the activity's appearance and behavior must be placed in this method. This method is asynchronous, and must be awaited. When writing a new game by extending the Game class, this method will be overridden, but the base method must still be called with await super.init().

Deprecated

use Game.initialize() instead.

Implementation of

Activity.init

Defined in

m2c2kit/packages/core/src/Game.ts:246


initialize()

initialize(): Promise<void>

Initializes the activity.

Returns

Promise<void>

Remarks

All code to create the activity's appearance and behavior must be placed in this method. This method is asynchronous, and must be awaited. When writing a new game by extending the Game class, this method will be overridden, but the base method must still be called with await super.initialize().

Implementation of

Activity.initialize

Defined in

m2c2kit/packages/core/src/Game.ts:384


loadCanvasKit()

loadCanvasKit(canvasKitWasmUrl): Promise<CanvasKit>

Internal

Loads the canvaskit wasm binary.

For m2c2kit library use only

Parameters

canvasKitWasmUrl: string

URL to the canvaskit wasm binary

Returns

Promise<CanvasKit>

a promise that resolves to a CanvasKit object

Remarks

The CanvasKit object is initialized with this method, rather than calling CanvasKitInit() directly, so that this method can be easily mocked in tests.

Defined in

m2c2kit/packages/core/src/Game.ts:262


loadManifest()

loadManifest(manifestJsonUrl): Promise<Manifest>

Internal

Returns the manifest, if manifest.json was created during the build.

For m2c2kit library use only

Parameters

manifestJsonUrl: string = "__NO_M2C2KIT_MANIFEST_JSON_URL__"

Do not use this parameter. Allow the default.

Returns

Promise<Manifest>

a promise that resolves to the manifest object, or an empty object if there is no manifest

Remarks

This should be called without any parameters. The manifestJsonUrl parameter's default value will be modified during the build step, if the build was configured to include the manifest.json

Defined in

m2c2kit/packages/core/src/Game.ts:454


onCancel()

onCancel(callback, options?): void

Executes a callback when the game is canceled.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Implementation of

Activity.onCancel

Defined in

m2c2kit/packages/core/src/Game.ts:2359


onData()

onData(callback, options?): void

Executes a callback when the game generates data.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Implementation of

Activity.onData

Defined in

m2c2kit/packages/core/src/Game.ts:2385


onEnd()

onEnd(callback, options?): void

Executes a callback when the game ends.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Implementation of

Activity.onEnd

Defined in

m2c2kit/packages/core/src/Game.ts:2372


onStart()

onStart(callback, options?): void

Executes a callback when the game starts.

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Implementation of

Activity.onStart

Defined in

m2c2kit/packages/core/src/Game.ts:2346


onWarmupEnd()

onWarmupEnd(callback, options?): void

Internal

Executes a callback when the game ends its warmup.

For m2c2kit library use only

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:2415


onWarmupStart()

onWarmupStart(callback, options?): void

Internal

Executes a callback when the game begins its warmup.

For m2c2kit library use only

Parameters

callback

function to execute.

options?: CallbackOptions

options for the callback.

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:2400


playEventsHandler()

playEventsHandler(mouseEvent): void

Parameters

mouseEvent: MouseEvent

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:1205


presentScene()

presentScene(scene, transition?): void

Specifies the scene that will be presented upon the next frame draw.

Parameters

scene: string | Scene

the scene, its string name, or UUID

transition?: Transition

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:1040


registerPlugin()

registerPlugin(plugin): Promise<void>

Registers a plugin with the game.

Parameters

plugin: Plugin

Plugin to register

Returns

Promise<void>

Remarks

Upon registration, the plugin's optional asynchronous initialize() method will be called.

Defined in

m2c2kit/packages/core/src/Game.ts:2142


removeAllFreeEntities()

removeAllFreeEntities(): void

Returns

void

Deprecated

Use removeAllFreeNodes() instead

Defined in

m2c2kit/packages/core/src/Game.ts:981


removeAllFreeNodes()

removeAllFreeNodes(): void

Removes all free nodes from the game.

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:974


removeFreeEntity()

removeFreeEntity(node): void

Parameters

node: string | M2Node

Returns

void

Deprecated

Use removeFreeNode() instead

Defined in

m2c2kit/packages/core/src/Game.ts:967


removeFreeNode()

removeFreeNode(node): void

Removes a free node from the game.

Parameters

node: string | M2Node

the free node to remove or its name as a string

Returns

void

Remarks

Throws exception if the node to remove is not currently added to the game as a free node

Defined in

m2c2kit/packages/core/src/Game.ts:960


removeScene()

removeScene(scene): void

Removes a scene from the game.

Parameters

scene: string | Scene

the scene to remove or its name as a string

Returns

void

Defined in

m2c2kit/packages/core/src/Game.ts:1030


resolveGameBaseUrls()

resolveGameBaseUrls(game): Promise<GameBaseUrls>

Internal

Resolves base URL locations for game assets and CanvasKit wasm binary.

For m2c2kit library use only

Parameters

game: Game

game to resolve base URLs for

Returns

Promise<GameBaseUrls>

base URLs for game assets and CanvasKit wasm binary

Defined in

m2c2kit/packages/core/src/Game.ts:274


scoringComplete()

scoringComplete(): void

Marks scoring as complete.

Returns

void

Remarks

This method must be called after the game has finished adding scores using addScoringData(). Calling will trigger the onActivityResults callback function, if one was provided in SessionOptions. This is how the game communicates scoring data to the parent session, which can then save or process the data. It is the responsibility of the the game programmer to call this at the appropriate time. It is not triggered automatically.

Defined in

m2c2kit/packages/core/src/Game.ts:1756


setParameters()

setParameters(additionalParameters): void

Sets additional activity parameters if defaults are not sufficient.

Parameters

additionalParameters: unknown

Returns

void

Implementation of

Activity.setParameters

Defined in

m2c2kit/packages/core/src/Game.ts:797


start()

start(entryScene?): Promise<void>

Starts the game loop.

Parameters

entryScene?: string | Scene

The scene (Scene object or its string name) to display when the game starts

Returns

Promise<void>

Remarks

If entryScene is undefined, the game will start with scene defined in the game object's entryScene property. If that is undefined, the game will start with the first scene in the game object's scenes. If there are no scenes in the game object's scenes, it will throw an error. Although the method has no awaitable calls, we will likely do so in the future. Thus this method is async.

Implementation of

Activity.start

Defined in

m2c2kit/packages/core/src/Game.ts:1111


stop()

stop(): void

Stops the activity

Returns

void

Implementation of

Activity.stop

Defined in

m2c2kit/packages/core/src/Game.ts:1576


storeClearItems()

storeClearItems(): Promise<void>

Deletes all items from the activity's key-value store.

Returns

Promise<void>

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Defined in

m2c2kit/packages/core/src/Game.ts:681


storeDeleteItem()

storeDeleteItem(key, globalStore): Promise<void>

Deletes an item value from the activity's key-value store.

Parameters

key: string

item key

globalStore: boolean = false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<void>

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Defined in

m2c2kit/packages/core/src/Game.ts:664


storeGetItem()

storeGetItem<T>(key, globalStore): Promise<T>

Gets an item value from the activity's key-value store.

Type Parameters

T extends undefined | null | string | number | boolean | object

Parameters

key: string

item key

globalStore: boolean = false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<T>

value of the item

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Defined in

m2c2kit/packages/core/src/Game.ts:640


storeItemExists()

storeItemExists(key, globalStore): Promise<boolean>

Determines if a key exists in the activity's key-value store.

Parameters

key: string

item key

globalStore: boolean = false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<boolean>

true if the key exists, false otherwise

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Defined in

m2c2kit/packages/core/src/Game.ts:723


storeItemsKeys()

storeItemsKeys(globalStore): Promise<string[]>

Returns keys of all items in the activity's key-value store.

Parameters

globalStore: boolean = false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<string[]>

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Defined in

m2c2kit/packages/core/src/Game.ts:700


storeSetItem()

storeSetItem(key, value, globalStore): Promise<string>

Saves an item to the activity's key-value store.

Parameters

key: string

item key

value: undefined | null | string | number | boolean | object

item value

globalStore: boolean = false

if true, treat the item as "global" and not associated with a specific activity; global items can be accessed by any activity. Default is false.

Returns

Promise<string>

key

Remarks

The underlying persistence provider of the key-value store must have been previously provided in SessionOptions.

Example

import { LocalDatabase } from "@m2c2kit/db";
const session = new Session({
dataStores: [new LocalDatabase()]
...
});

Defined in

m2c2kit/packages/core/src/Game.ts:610


takeScreenshot()

takeScreenshot(sx?, sy?, sw?, sh?): Promise<null | Uint8Array>

Takes screenshot of canvas

Parameters

sx?: number

Upper left coordinate of screenshot

sy?: number

Upper right coordinate of screenshot

sw?: number

width of area to screenshot

sh?: number

height of area to screenshot

Returns

Promise<null | Uint8Array>

Promise of Uint8Array of image data

Remarks

Coordinates should be provided unscaled; that is, the method will handle any scaling that happened due to device pixel ratios not equal to 1. This returns a promise because the screenshot request must be queued and completed once a draw cycle has completed. See the loop() method.

Defined in

m2c2kit/packages/core/src/Game.ts:2254


trialComplete()

trialComplete(): void

Should be called when the current trial has completed. It will also increment the trial index.

Returns

void

Remarks

Calling will trigger the onActivityResults callback function, if one was provided in SessionOptions. This is how the game communicates trial data to the parent session, which can then save or process the data. It is the responsibility of the the game programmer to call this at the appropriate time. It is not triggered automatically.

Defined in

m2c2kit/packages/core/src/Game.ts:1702