@m2c2kit/core 0.3.31 → 0.3.33
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 +406 -120
- package/dist/index.js +3450 -2948
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +4 -4
- package/package.json +8 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as canvaskit_wasm from 'canvaskit-wasm';
|
|
1
2
|
import { Canvas, Typeface, TypefaceFontProvider, Image, Paint, CanvasKit, Surface, Font, ParagraphBuilder, Paragraph, FontMgr, Path, PaintStyle } from 'canvaskit-wasm';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -1006,6 +1007,10 @@ interface GameOptions extends LocalizationOptions {
|
|
|
1006
1007
|
moduleMetadata?: ModuleMetadata;
|
|
1007
1008
|
}
|
|
1008
1009
|
|
|
1010
|
+
interface TrialData {
|
|
1011
|
+
[key: string]: string | number | boolean | object | undefined | null;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1009
1014
|
interface GameData extends ActivityKeyValueData {
|
|
1010
1015
|
trials: Array<TrialData>;
|
|
1011
1016
|
scoring: ActivityKeyValueData;
|
|
@@ -1556,9 +1561,316 @@ declare class EventMaterializer {
|
|
|
1556
1561
|
private materializeScenePresentEvent;
|
|
1557
1562
|
}
|
|
1558
1563
|
|
|
1559
|
-
|
|
1560
|
-
|
|
1564
|
+
declare class InputManager {
|
|
1565
|
+
private game;
|
|
1566
|
+
private htmlCanvas;
|
|
1567
|
+
constructor(game: Game, htmlCanvas: HTMLCanvasElement);
|
|
1568
|
+
dispose(): void;
|
|
1569
|
+
private addEventListeners;
|
|
1570
|
+
private removeEventListeners;
|
|
1571
|
+
private touchStartHandler;
|
|
1572
|
+
/**
|
|
1573
|
+
* Receives callback from DOM PointerDown event
|
|
1574
|
+
*
|
|
1575
|
+
* @param domPointerEvent - PointerEvent from the DOM
|
|
1576
|
+
* @returns
|
|
1577
|
+
*/
|
|
1578
|
+
private htmlCanvasPointerDownHandler;
|
|
1579
|
+
private htmlCanvasPointerUpHandler;
|
|
1580
|
+
private htmlCanvasPointerMoveHandler;
|
|
1581
|
+
private htmlCanvasPointerLeaveHandler;
|
|
1582
|
+
private documentKeyDownHandler;
|
|
1583
|
+
private documentKeyUpHandler;
|
|
1584
|
+
/**
|
|
1585
|
+
* Determines if/how m2c2kit nodes respond to the DOM PointerDown event
|
|
1586
|
+
*
|
|
1587
|
+
* @param node - node that might be affected by the DOM PointerDown event
|
|
1588
|
+
* @param nodeEvent
|
|
1589
|
+
* @param domPointerEvent
|
|
1590
|
+
*/
|
|
1591
|
+
private processDomPointerDown;
|
|
1592
|
+
private processDomPointerUp;
|
|
1593
|
+
private processDomPointerMove;
|
|
1594
|
+
private processDomPointerLeave;
|
|
1595
|
+
private raiseEventOnListeningNodes;
|
|
1596
|
+
private raiseM2PointerDownEvent;
|
|
1597
|
+
private raiseTapDownEvent;
|
|
1598
|
+
private raiseTapLeaveEvent;
|
|
1599
|
+
private raiseM2PointerUpEvent;
|
|
1600
|
+
private raiseTapUpEvent;
|
|
1601
|
+
private raiseTapUpAny;
|
|
1602
|
+
private raiseM2PointerMoveEvent;
|
|
1603
|
+
private raiseM2PointerLeaveEvent;
|
|
1604
|
+
private raiseM2DragStartEvent;
|
|
1605
|
+
private raiseM2DragEvent;
|
|
1606
|
+
private raiseM2DragEndEvent;
|
|
1607
|
+
private sceneCanReceiveUserInteraction;
|
|
1608
|
+
/**
|
|
1609
|
+
*
|
|
1610
|
+
* Checks if the given canvas point is within the node's bounds.
|
|
1611
|
+
*
|
|
1612
|
+
* @param node - node to check bounds for
|
|
1613
|
+
* @param x - x coordinate of the canvas point
|
|
1614
|
+
* @param y - y coordinate of the canvas point
|
|
1615
|
+
* @returns true if x, y point is within the node's bounds
|
|
1616
|
+
*/
|
|
1617
|
+
private IsCanvasPointWithinNodeBounds;
|
|
1618
|
+
private calculatePointWithinNodeFromDomPointerEvent;
|
|
1561
1619
|
}
|
|
1620
|
+
|
|
1621
|
+
declare class SceneManager {
|
|
1622
|
+
private game;
|
|
1623
|
+
scenes: Scene[];
|
|
1624
|
+
freeNodesScene: Scene;
|
|
1625
|
+
currentScene?: Scene;
|
|
1626
|
+
incomingSceneTransitions: SceneTransition[];
|
|
1627
|
+
snapshots: Image[];
|
|
1628
|
+
private currentSceneSnapshot?;
|
|
1629
|
+
private pendingScreenshot?;
|
|
1630
|
+
constructor(game: Game);
|
|
1631
|
+
/**
|
|
1632
|
+
* Clears the current game scene by setting it to undefined.
|
|
1633
|
+
*/
|
|
1634
|
+
clearCurrentScene(): void;
|
|
1635
|
+
/**
|
|
1636
|
+
* Updates all active scenes and their children.
|
|
1637
|
+
*/
|
|
1638
|
+
updateScenes(): void;
|
|
1639
|
+
/**
|
|
1640
|
+
* Draws all active scenes and their children on the provided canvas.
|
|
1641
|
+
*
|
|
1642
|
+
* @param canvas - the canvas to draw the scenes on
|
|
1643
|
+
*/
|
|
1644
|
+
drawScenes(canvas: Canvas): void;
|
|
1645
|
+
/**
|
|
1646
|
+
* Adds events from a node and its children to the game's event store.
|
|
1647
|
+
*
|
|
1648
|
+
* @remarks This method is first called when a scene is added to the game.
|
|
1649
|
+
* If the scene or any of its descendants was constructed or had its
|
|
1650
|
+
* properties changed before it was added to the game, these events were
|
|
1651
|
+
* stored within the node (because the game event store was not yet
|
|
1652
|
+
* available). This method retrieves these events from the node and adds
|
|
1653
|
+
* them to the game's event store.
|
|
1654
|
+
*
|
|
1655
|
+
* @param node - node that contains events to add
|
|
1656
|
+
*/
|
|
1657
|
+
private addNodeEvents;
|
|
1658
|
+
/**
|
|
1659
|
+
* Adds a scene to the game.
|
|
1660
|
+
*
|
|
1661
|
+
* @remarks A scene, and its children nodes, cannot be presented unless it
|
|
1662
|
+
* has been added to the game object. A scene can be added to the game
|
|
1663
|
+
* only once.
|
|
1664
|
+
*
|
|
1665
|
+
* @param scene
|
|
1666
|
+
*/
|
|
1667
|
+
add(scene: Scene): void;
|
|
1668
|
+
/**
|
|
1669
|
+
* Removes a scene from the game.
|
|
1670
|
+
*
|
|
1671
|
+
* @param scene - the scene to remove or its name as a string
|
|
1672
|
+
*/
|
|
1673
|
+
remove(scene: Scene | string): void;
|
|
1674
|
+
/**
|
|
1675
|
+
* Specifies the scene that will be presented upon the next frame draw.
|
|
1676
|
+
*
|
|
1677
|
+
* @param scene - the scene, its string name, or UUID
|
|
1678
|
+
* @param transition
|
|
1679
|
+
*/
|
|
1680
|
+
present(scene: string | Scene, transition?: Transition): void;
|
|
1681
|
+
handleIncomingSceneTransitions(): void;
|
|
1682
|
+
/**
|
|
1683
|
+
* Creates a scene that has a screen shot of the current scene.
|
|
1684
|
+
*
|
|
1685
|
+
* @param outgoingSceneImage - an image of the current scene
|
|
1686
|
+
* @returns - the scene with the screen shot
|
|
1687
|
+
*/
|
|
1688
|
+
private createOutgoingScene;
|
|
1689
|
+
private animateSceneTransition;
|
|
1690
|
+
/**
|
|
1691
|
+
* Takes screenshot of canvas
|
|
1692
|
+
*
|
|
1693
|
+
* @remarks Coordinates should be provided unscaled; that is, the method
|
|
1694
|
+
* will handle any scaling that happened due to device pixel ratios
|
|
1695
|
+
* not equal to 1. This returns a promise because the screenshot request
|
|
1696
|
+
* must be queued and completed once a draw cycle has completed. See
|
|
1697
|
+
* the handleScreenshots() method.
|
|
1698
|
+
*
|
|
1699
|
+
* @param sx - Upper left coordinate of screenshot
|
|
1700
|
+
* @param sy - Upper right coordinate of screenshot
|
|
1701
|
+
* @param sw - width of area to screenshot
|
|
1702
|
+
* @param sh - height of area to screenshot
|
|
1703
|
+
* @returns Promise of Uint8Array of image data
|
|
1704
|
+
*/
|
|
1705
|
+
takeScreenshot(sx?: number, sy?: number, sw?: number, sh?: number): Promise<Uint8Array | null>;
|
|
1706
|
+
/**
|
|
1707
|
+
* Handles game screenshots.
|
|
1708
|
+
*
|
|
1709
|
+
* @remarks This is called on every iteration of the game loop.
|
|
1710
|
+
* In prior versions, I took a snapshot only when needed, e.g.,
|
|
1711
|
+
* after a new scene transition was requested. From performance testing,
|
|
1712
|
+
* however, I found that taking a snapshot has negligible impact on
|
|
1713
|
+
* performance. It is only encoding the image to bytes, i.e.,
|
|
1714
|
+
* image.encodeToBytes(), that is expensive. Thus, we can take a snapshot
|
|
1715
|
+
* after every draw, in case we'll need the snapshot. IMPORTANT: snapshots
|
|
1716
|
+
* must be deleted when not needed, otherwise we will create a massive memory
|
|
1717
|
+
* leak because we are creating them 60 times per second.
|
|
1718
|
+
*/
|
|
1719
|
+
handleScreenshots(): void;
|
|
1720
|
+
takeCurrentSceneSnapshot(): Image;
|
|
1721
|
+
private handlePendingScreenshot;
|
|
1722
|
+
private raiseSceneEvent;
|
|
1723
|
+
private createFreeNodesScene;
|
|
1724
|
+
get freeNodes(): Array<M2Node>;
|
|
1725
|
+
addFreeNode(node: M2Node): void;
|
|
1726
|
+
removeFreeNode(node: M2Node | string): void;
|
|
1727
|
+
removeAllFreeNodes(): void;
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
interface DeviceMetadata {
|
|
1731
|
+
userAgent?: string;
|
|
1732
|
+
devicePixelRatio?: number;
|
|
1733
|
+
screen?: screenMetadata;
|
|
1734
|
+
webGlRenderer?: string;
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* screenMetadata is similar to window.Screen, except we don't want the
|
|
1738
|
+
* methods on the window.Screen.ScreenOrientation
|
|
1739
|
+
*/
|
|
1740
|
+
interface screenMetadata {
|
|
1741
|
+
readonly availHeight: number;
|
|
1742
|
+
readonly availWidth: number;
|
|
1743
|
+
readonly colorDepth: number;
|
|
1744
|
+
readonly height: number;
|
|
1745
|
+
/** ScreenOrientation has some methods on it; we only want these two properties
|
|
1746
|
+
* However, when unit testing, orientation is not available to us. Thus, make this
|
|
1747
|
+
* property optional
|
|
1748
|
+
*/
|
|
1749
|
+
readonly orientation?: Pick<ScreenOrientation, "type" | "angle">;
|
|
1750
|
+
readonly pixelDepth: number;
|
|
1751
|
+
readonly width: number;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
/**
|
|
1755
|
+
* Manages the participant data for a game.
|
|
1756
|
+
*
|
|
1757
|
+
* @internal For m2c2kit library use only
|
|
1758
|
+
*
|
|
1759
|
+
* @param game - The game instance that this DataManager is associated with.
|
|
1760
|
+
*/
|
|
1761
|
+
declare class DataManager {
|
|
1762
|
+
private game;
|
|
1763
|
+
private webGlRendererInfo;
|
|
1764
|
+
data: GameData;
|
|
1765
|
+
trialIndex: number;
|
|
1766
|
+
staticTrialSchema: {
|
|
1767
|
+
[key: string]: JsonSchemaDataTypeScriptTypes;
|
|
1768
|
+
};
|
|
1769
|
+
constructor(game: Game);
|
|
1770
|
+
/**
|
|
1771
|
+
* Initializes the participant data structure for a new game.
|
|
1772
|
+
*
|
|
1773
|
+
* @remarks This method should be called once at the start of a new game.
|
|
1774
|
+
*/
|
|
1775
|
+
initializeData(): void;
|
|
1776
|
+
/**
|
|
1777
|
+
* The m2c2kit engine will automatically include these schema and their
|
|
1778
|
+
* values in the trial data.
|
|
1779
|
+
*
|
|
1780
|
+
* @remarks These are in the `Game` class, rather than in the `DataManager`
|
|
1781
|
+
* class, because the schema-util parses the code to find these
|
|
1782
|
+
* properties, and it expects them in the `Game` class.
|
|
1783
|
+
*/
|
|
1784
|
+
private readonly automaticTrialSchema;
|
|
1785
|
+
/**
|
|
1786
|
+
* The m2c2kit engine will automatically include these schema and their
|
|
1787
|
+
* values in the scoring data.
|
|
1788
|
+
*
|
|
1789
|
+
* @remarks These are in the `Game` class, rather than in the `DataManager`
|
|
1790
|
+
* class, because the schema-util parses the code to find these
|
|
1791
|
+
* properties, and it expects them in the `Game` class.
|
|
1792
|
+
*/
|
|
1793
|
+
private readonly automaticScoringSchema;
|
|
1794
|
+
/**
|
|
1795
|
+
* Queries the WebGL renderer for graphics drivers information and stores
|
|
1796
|
+
* it so it can be included in the device metadata.
|
|
1797
|
+
*
|
|
1798
|
+
* @remarks This method should be called once during the game start to avoid
|
|
1799
|
+
* performance issues (it could be slow on some devices/browsers).
|
|
1800
|
+
*/
|
|
1801
|
+
queryWebGlRendererInfo(): void;
|
|
1802
|
+
private propertySchemaDataTypeIsValid;
|
|
1803
|
+
/**
|
|
1804
|
+
* Increments the trial index by 1.
|
|
1805
|
+
*/
|
|
1806
|
+
incrementTrialIndex(): void;
|
|
1807
|
+
/**
|
|
1808
|
+
* Adds data to the game's TrialData object.
|
|
1809
|
+
*
|
|
1810
|
+
* @remarks `variableName` must be previously defined in the
|
|
1811
|
+
* {@link TrialSchema} object in {@link GameOptions}. The type of the value
|
|
1812
|
+
* must match what was defined in the trial schema, otherwise an error is
|
|
1813
|
+
* thrown.
|
|
1814
|
+
*
|
|
1815
|
+
* @param variableName - variable to be set
|
|
1816
|
+
* @param value - value of the variable to set
|
|
1817
|
+
*/
|
|
1818
|
+
addTrialData(variableName: string, value: JsonSchemaDataTypeScriptTypes): void;
|
|
1819
|
+
/**
|
|
1820
|
+
* Sets the value of a variable that will be the same for all trials.
|
|
1821
|
+
*
|
|
1822
|
+
* @remarks This sets the value of a variable that is the same across
|
|
1823
|
+
* all trials ("static"). This is useful for variables that are not
|
|
1824
|
+
* part of the trial schema, but that you want to save for each trial in
|
|
1825
|
+
* your use case. For example, you might want to save the subject's
|
|
1826
|
+
* participant ID for each trial, but this is not part of the trial schema.
|
|
1827
|
+
* Rather than modify the source code for the game, you can do the following
|
|
1828
|
+
* to ensure that the participant ID is saved for each trial:
|
|
1829
|
+
*
|
|
1830
|
+
* game.addTrialSchema({
|
|
1831
|
+
* participant_id: {
|
|
1832
|
+
* type: "string",
|
|
1833
|
+
* description: "ID of the participant",
|
|
1834
|
+
* }
|
|
1835
|
+
* });
|
|
1836
|
+
* game.addStaticTrialData("participant_id", "12345");
|
|
1837
|
+
*
|
|
1838
|
+
* When Game.trialComplete() is called, the participant_id variable will
|
|
1839
|
+
* be saved for the trial with the value "12345".
|
|
1840
|
+
*
|
|
1841
|
+
* @param variableName - variable to be set
|
|
1842
|
+
* @param value - value of the variable to set
|
|
1843
|
+
*/
|
|
1844
|
+
addStaticTrialData(variableName: string, value: JsonSchemaDataTypeScriptTypes): void;
|
|
1845
|
+
/**
|
|
1846
|
+
* Adds data to the game's scoring data.
|
|
1847
|
+
*
|
|
1848
|
+
* @remarks The variable name (or object property names) must be previously
|
|
1849
|
+
* defined in the {@link ScoringSchema} object in {@link GameOptions}.
|
|
1850
|
+
* The type of the value must match what was defined in the scoring schema,
|
|
1851
|
+
* otherwise an error is thrown.
|
|
1852
|
+
*
|
|
1853
|
+
* @param variableNameOrObject - Either a variable name (string) or an object
|
|
1854
|
+
* containing multiple key-value pairs to add all at once.
|
|
1855
|
+
* @param value - Value of the variable to set (only used when
|
|
1856
|
+
* variableNameOrObject is a variable name string).
|
|
1857
|
+
*/
|
|
1858
|
+
addScoringData(variableNameOrObject: string | Record<string, JsonSchemaDataTypeScriptTypes> | Array<Record<string, JsonSchemaDataTypeScriptTypes>>, value?: JsonSchemaDataTypeScriptTypes): void;
|
|
1859
|
+
/**
|
|
1860
|
+
* Helper method to validate and set a single scoring variable
|
|
1861
|
+
*
|
|
1862
|
+
* @param variableName - Name of the variable to set
|
|
1863
|
+
* @param value - Value to set
|
|
1864
|
+
* @private
|
|
1865
|
+
*/
|
|
1866
|
+
private validateAndSetScoringVariable;
|
|
1867
|
+
getDeviceMetadata(): DeviceMetadata;
|
|
1868
|
+
makeNewGameDataSchema(): JsonSchema;
|
|
1869
|
+
makeGameDataSchema(): JsonSchema;
|
|
1870
|
+
makeScoringDataSchema(): JsonSchema;
|
|
1871
|
+
private validateSchema;
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1562
1874
|
declare class Game implements Activity {
|
|
1563
1875
|
readonly type = ActivityType.Game;
|
|
1564
1876
|
_canvasKit?: CanvasKit;
|
|
@@ -1586,12 +1898,12 @@ declare class Game implements Activity {
|
|
|
1586
1898
|
private _dataStores?;
|
|
1587
1899
|
private plugins;
|
|
1588
1900
|
additionalParameters?: unknown;
|
|
1589
|
-
staticTrialSchema: {
|
|
1590
|
-
[key: string]: JsonSchemaDataTypeScriptTypes;
|
|
1591
|
-
};
|
|
1592
1901
|
private _fontManager?;
|
|
1593
1902
|
private _imageManager?;
|
|
1594
1903
|
private _soundManager?;
|
|
1904
|
+
private _inputManager?;
|
|
1905
|
+
sceneManager: SceneManager;
|
|
1906
|
+
dataManager: DataManager;
|
|
1595
1907
|
manifest?: Manifest;
|
|
1596
1908
|
eventStore: EventStore;
|
|
1597
1909
|
private nodeFactory;
|
|
@@ -1604,7 +1916,6 @@ declare class Game implements Activity {
|
|
|
1604
1916
|
* @param options - {@link GameOptions}
|
|
1605
1917
|
*/
|
|
1606
1918
|
constructor(options: GameOptions);
|
|
1607
|
-
private createFreeNodesScene;
|
|
1608
1919
|
/**
|
|
1609
1920
|
* Returns the base URL of an imported module.
|
|
1610
1921
|
*
|
|
@@ -1670,6 +1981,29 @@ declare class Game implements Activity {
|
|
|
1670
1981
|
set soundManager(soundManager: SoundManager);
|
|
1671
1982
|
get eventMaterializer(): EventMaterializer;
|
|
1672
1983
|
set eventMaterializer(eventMaterializer: EventMaterializer);
|
|
1984
|
+
get inputManager(): InputManager;
|
|
1985
|
+
set inputManager(inputManager: InputManager);
|
|
1986
|
+
/**
|
|
1987
|
+
* Returns the scenes that have been added to the game.
|
|
1988
|
+
*/
|
|
1989
|
+
get scenes(): Scene[];
|
|
1990
|
+
/**
|
|
1991
|
+
* Returns the current game scene.
|
|
1992
|
+
*
|
|
1993
|
+
* @remarks The current scene is the scene that is currently being
|
|
1994
|
+
* rendered. If no scene has been set as the current scene, this will
|
|
1995
|
+
* return undefined.
|
|
1996
|
+
*/
|
|
1997
|
+
get currentScene(): Scene | undefined;
|
|
1998
|
+
/**
|
|
1999
|
+
* Returns the game snapshots.
|
|
2000
|
+
*
|
|
2001
|
+
* @remarks Snapshots are the most recent images of the current scene. These
|
|
2002
|
+
* are in raw CanvasKit `Image` format and must be converted to another
|
|
2003
|
+
* format, such as PNG via `CanvasKit.MakeImage()`, before they can be
|
|
2004
|
+
* meaningfully exported.
|
|
2005
|
+
*/
|
|
2006
|
+
get snapshots(): canvaskit_wasm.Image[];
|
|
1673
2007
|
/**
|
|
1674
2008
|
* Adds prefixes to a key to ensure that keys are unique across activities
|
|
1675
2009
|
* and studies.
|
|
@@ -1795,14 +2129,14 @@ declare class Game implements Activity {
|
|
|
1795
2129
|
set canvasKit(canvasKit: CanvasKit);
|
|
1796
2130
|
/** 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 */
|
|
1797
2131
|
entryScene?: Scene | string;
|
|
1798
|
-
data
|
|
2132
|
+
/** The participant data generated by the game. */
|
|
2133
|
+
get data(): GameData;
|
|
1799
2134
|
/** The 0-based index of the current trial */
|
|
1800
|
-
trialIndex: number;
|
|
2135
|
+
get trialIndex(): number;
|
|
1801
2136
|
private htmlCanvas?;
|
|
1802
2137
|
surface?: Surface;
|
|
1803
2138
|
private showFps?;
|
|
1804
|
-
|
|
1805
|
-
currentScene?: Scene;
|
|
2139
|
+
bodyBackgroundColor?: RgbaColor;
|
|
1806
2140
|
private priorUpdateTime?;
|
|
1807
2141
|
private fpsTextFont?;
|
|
1808
2142
|
private fpsTextPaint?;
|
|
@@ -1813,14 +2147,8 @@ declare class Game implements Activity {
|
|
|
1813
2147
|
private animationFramesRequested;
|
|
1814
2148
|
private limitFps;
|
|
1815
2149
|
private gameStopRequested;
|
|
1816
|
-
private webGlRendererInfo;
|
|
1817
2150
|
canvasCssWidth: number;
|
|
1818
2151
|
canvasCssHeight: number;
|
|
1819
|
-
scenes: Scene[];
|
|
1820
|
-
freeNodesScene: Scene;
|
|
1821
|
-
private incomingSceneTransitions;
|
|
1822
|
-
private currentSceneSnapshot?;
|
|
1823
|
-
private pendingScreenshot?;
|
|
1824
2152
|
/**
|
|
1825
2153
|
* Adds a node as a free node (a node that is not part of a scene)
|
|
1826
2154
|
* to the game.
|
|
@@ -1881,19 +2209,6 @@ declare class Game implements Activity {
|
|
|
1881
2209
|
* @param scene
|
|
1882
2210
|
*/
|
|
1883
2211
|
addScene(scene: Scene): void;
|
|
1884
|
-
/**
|
|
1885
|
-
* Adds events from a node and its children to the game's event store.
|
|
1886
|
-
*
|
|
1887
|
-
* @remarks This method is first called when a scene is added to the game.
|
|
1888
|
-
* If the scene or any of its descendants was constructed or had its
|
|
1889
|
-
* properties changed before it was added to the game, these events were
|
|
1890
|
-
* stored within the node (because the game event store was not yet
|
|
1891
|
-
* available). This method retrieves these events from the node and adds
|
|
1892
|
-
* them to the game's event store.
|
|
1893
|
-
*
|
|
1894
|
-
* @param node - node that contains events to add
|
|
1895
|
-
*/
|
|
1896
|
-
private addNodeEvents;
|
|
1897
2212
|
/**
|
|
1898
2213
|
* Adds multiple scenes to the game.
|
|
1899
2214
|
*
|
|
@@ -2001,10 +2316,6 @@ declare class Game implements Activity {
|
|
|
2001
2316
|
* end-user must not call this. FOR INTERNAL USE ONLY.
|
|
2002
2317
|
*/
|
|
2003
2318
|
dispose(): void;
|
|
2004
|
-
private initData;
|
|
2005
|
-
private validateSchema;
|
|
2006
|
-
private propertySchemaDataTypeIsValid;
|
|
2007
|
-
private getDeviceMetadata;
|
|
2008
2319
|
/**
|
|
2009
2320
|
* Adds data to the game's TrialData object.
|
|
2010
2321
|
*
|
|
@@ -2031,14 +2342,6 @@ declare class Game implements Activity {
|
|
|
2031
2342
|
* variableNameOrObject is a variable name string).
|
|
2032
2343
|
*/
|
|
2033
2344
|
addScoringData(variableNameOrObject: string | Record<string, JsonSchemaDataTypeScriptTypes> | Array<Record<string, JsonSchemaDataTypeScriptTypes>>, value?: JsonSchemaDataTypeScriptTypes): void;
|
|
2034
|
-
/**
|
|
2035
|
-
* Helper method to validate and set a single scoring variable
|
|
2036
|
-
*
|
|
2037
|
-
* @param variableName - Name of the variable to set
|
|
2038
|
-
* @param value - Value to set
|
|
2039
|
-
* @private
|
|
2040
|
-
*/
|
|
2041
|
-
private validateAndSetScoringVariable;
|
|
2042
2345
|
/**
|
|
2043
2346
|
* Adds custom trial schema to the game's trialSchema object.
|
|
2044
2347
|
*
|
|
@@ -2098,18 +2401,6 @@ declare class Game implements Activity {
|
|
|
2098
2401
|
* to call this at the appropriate time. It is not triggered automatically.
|
|
2099
2402
|
*/
|
|
2100
2403
|
scoringComplete(): void;
|
|
2101
|
-
/**
|
|
2102
|
-
* The m2c2kit engine will automatically include these schema and their
|
|
2103
|
-
* values in the scoring data.
|
|
2104
|
-
*/
|
|
2105
|
-
private readonly automaticScoringSchema;
|
|
2106
|
-
/**
|
|
2107
|
-
* The m2c2kit engine will automatically include these schema and their
|
|
2108
|
-
* values in the trial data.
|
|
2109
|
-
*/
|
|
2110
|
-
private readonly automaticTrialSchema;
|
|
2111
|
-
private makeNewGameDataSchema;
|
|
2112
|
-
private makeGameDataSchema;
|
|
2113
2404
|
/**
|
|
2114
2405
|
* GameParameters combines default parameters values and
|
|
2115
2406
|
* JSON Schema to describe what the parameters are.
|
|
@@ -2119,7 +2410,6 @@ declare class Game implements Activity {
|
|
|
2119
2410
|
*/
|
|
2120
2411
|
private makeGameActivityConfiguration;
|
|
2121
2412
|
private makeGameActivityConfigurationSchema;
|
|
2122
|
-
private makeScoringDataSchema;
|
|
2123
2413
|
/**
|
|
2124
2414
|
* Should be called when current game has ended successfully.
|
|
2125
2415
|
*
|
|
@@ -2144,20 +2434,10 @@ declare class Game implements Activity {
|
|
|
2144
2434
|
cancel(): void;
|
|
2145
2435
|
private setupHtmlCanvases;
|
|
2146
2436
|
private setupCanvasKitSurface;
|
|
2147
|
-
private interceptWebGlCalls;
|
|
2148
2437
|
private setupFpsFont;
|
|
2149
|
-
private
|
|
2438
|
+
private setupInputManager;
|
|
2150
2439
|
private loop;
|
|
2151
|
-
snapshots: Image[];
|
|
2152
2440
|
private updateGameTime;
|
|
2153
|
-
private handleIncomingSceneTransitions;
|
|
2154
|
-
/**
|
|
2155
|
-
* Creates a scene that has a screen shot of the current scene.
|
|
2156
|
-
*
|
|
2157
|
-
* @param outgoingSceneImage - an image of the current scene
|
|
2158
|
-
* @returns - the scene with the screen shot
|
|
2159
|
-
*/
|
|
2160
|
-
private createOutgoingScene;
|
|
2161
2441
|
/**
|
|
2162
2442
|
* Registers a plugin with the game.
|
|
2163
2443
|
*
|
|
@@ -2172,10 +2452,6 @@ declare class Game implements Activity {
|
|
|
2172
2452
|
*
|
|
2173
2453
|
*/
|
|
2174
2454
|
private update;
|
|
2175
|
-
/**
|
|
2176
|
-
* Updates all active scenes and their children.
|
|
2177
|
-
*/
|
|
2178
|
-
private updateScenes;
|
|
2179
2455
|
/**
|
|
2180
2456
|
* Executes all active plugins before scenes are updated.
|
|
2181
2457
|
*/
|
|
@@ -2186,8 +2462,6 @@ declare class Game implements Activity {
|
|
|
2186
2462
|
private executeAfterUpdatePlugins;
|
|
2187
2463
|
private draw;
|
|
2188
2464
|
private calculateFps;
|
|
2189
|
-
private takeCurrentSceneSnapshot;
|
|
2190
|
-
private handlePendingScreenshot;
|
|
2191
2465
|
/**
|
|
2192
2466
|
* Takes screenshot of canvas
|
|
2193
2467
|
*
|
|
@@ -2204,7 +2478,6 @@ declare class Game implements Activity {
|
|
|
2204
2478
|
* @returns Promise of Uint8Array of image data
|
|
2205
2479
|
*/
|
|
2206
2480
|
takeScreenshot(sx?: number, sy?: number, sw?: number, sh?: number): Promise<Uint8Array | null>;
|
|
2207
|
-
private animateSceneTransition;
|
|
2208
2481
|
private drawFps;
|
|
2209
2482
|
/**
|
|
2210
2483
|
* Creates an event listener for a node based on the node name
|
|
@@ -2225,42 +2498,6 @@ declare class Game implements Activity {
|
|
|
2225
2498
|
* @deprecated use Game.nodes instead
|
|
2226
2499
|
*/
|
|
2227
2500
|
get entities(): Array<M2Node>;
|
|
2228
|
-
/**
|
|
2229
|
-
* Receives callback from DOM PointerDown event
|
|
2230
|
-
*
|
|
2231
|
-
* @param domPointerEvent - PointerEvent from the DOM
|
|
2232
|
-
* @returns
|
|
2233
|
-
*/
|
|
2234
|
-
private htmlCanvasPointerDownHandler;
|
|
2235
|
-
private htmlCanvasPointerUpHandler;
|
|
2236
|
-
private htmlCanvasPointerMoveHandler;
|
|
2237
|
-
private htmlCanvasPointerLeaveHandler;
|
|
2238
|
-
private documentKeyDownHandler;
|
|
2239
|
-
private documentKeyUpHandler;
|
|
2240
|
-
/**
|
|
2241
|
-
* Determines if/how m2c2kit nodes respond to the DOM PointerDown event
|
|
2242
|
-
*
|
|
2243
|
-
* @param node - node that might be affected by the DOM PointerDown event
|
|
2244
|
-
* @param nodeEvent
|
|
2245
|
-
* @param domPointerEvent
|
|
2246
|
-
*/
|
|
2247
|
-
private processDomPointerDown;
|
|
2248
|
-
private processDomPointerUp;
|
|
2249
|
-
private processDomPointerMove;
|
|
2250
|
-
private processDomPointerLeave;
|
|
2251
|
-
private raiseM2PointerDownEvent;
|
|
2252
|
-
private raiseTapDownEvent;
|
|
2253
|
-
private raiseTapLeaveEvent;
|
|
2254
|
-
private raiseM2PointerUpEvent;
|
|
2255
|
-
private raiseTapUpEvent;
|
|
2256
|
-
private raiseTapUpAny;
|
|
2257
|
-
private raiseM2PointerMoveEvent;
|
|
2258
|
-
private raiseM2PointerLeaveEvent;
|
|
2259
|
-
private raiseM2DragStartEvent;
|
|
2260
|
-
private raiseM2DragEvent;
|
|
2261
|
-
private raiseM2DragEndEvent;
|
|
2262
|
-
private raiseSceneEvent;
|
|
2263
|
-
private calculatePointWithinNodeFromDomPointerEvent;
|
|
2264
2501
|
/**
|
|
2265
2502
|
* Executes a callback when the game starts.
|
|
2266
2503
|
*
|
|
@@ -2309,18 +2546,6 @@ declare class Game implements Activity {
|
|
|
2309
2546
|
onWarmupEnd(callback: (activityEvent: ActivityEvent) => void, options?: CallbackOptions): void;
|
|
2310
2547
|
private addEventListener;
|
|
2311
2548
|
private raiseActivityEventOnListeners;
|
|
2312
|
-
private raiseEventOnListeningNodes;
|
|
2313
|
-
private sceneCanReceiveUserInteraction;
|
|
2314
|
-
/**
|
|
2315
|
-
*
|
|
2316
|
-
* Checks if the given canvas point is within the node's bounds.
|
|
2317
|
-
*
|
|
2318
|
-
* @param node - node to check bounds for
|
|
2319
|
-
* @param x - x coordinate of the canvas point
|
|
2320
|
-
* @param y - y coordinate of the canvas point
|
|
2321
|
-
* @returns true if x, y point is within the node's bounds
|
|
2322
|
-
*/
|
|
2323
|
-
private IsCanvasPointWithinNodeBounds;
|
|
2324
2549
|
}
|
|
2325
2550
|
|
|
2326
2551
|
/**
|
|
@@ -4043,6 +4268,13 @@ declare class M2c2KitHelpers {
|
|
|
4043
4268
|
* "https://", "file://", etc.)
|
|
4044
4269
|
*/
|
|
4045
4270
|
static urlHasScheme(url: string): boolean;
|
|
4271
|
+
/**
|
|
4272
|
+
* Sanitizes parameters object to prevent prototype pollution.
|
|
4273
|
+
*
|
|
4274
|
+
* @param parameters - parameters object to be sanitized
|
|
4275
|
+
* @returns sanitized parameters or undefined if parameters is undefined
|
|
4276
|
+
*/
|
|
4277
|
+
static sanitizeParameters(parameters: unknown | undefined): any;
|
|
4046
4278
|
/**
|
|
4047
4279
|
* Converts a value to a JSON schema type or one of types.
|
|
4048
4280
|
*
|
|
@@ -4635,6 +4867,44 @@ interface PluginEvent extends M2Event<Plugin> {
|
|
|
4635
4867
|
}
|
|
4636
4868
|
|
|
4637
4869
|
declare class RandomDraws {
|
|
4870
|
+
private static randomFunction;
|
|
4871
|
+
private static seededPRNG;
|
|
4872
|
+
/**
|
|
4873
|
+
* Sets the seed for the pseudo-random number generator (PRNG) and
|
|
4874
|
+
* instructs methods within `RandomDraws` to use a seeded PRNG
|
|
4875
|
+
* instead of the default `Math.random()`.
|
|
4876
|
+
*
|
|
4877
|
+
* @remarks The implementation of the seeded PRNG is based on David Bau's
|
|
4878
|
+
* `seedrandom` library at https://github.com/davidbau/seedrandom
|
|
4879
|
+
*
|
|
4880
|
+
* @param seed - The seed string to initialize the PRNG.
|
|
4881
|
+
*/
|
|
4882
|
+
static setSeed(seed: string): void;
|
|
4883
|
+
/**
|
|
4884
|
+
* Instructs methods within `RandomDraws` to use the default
|
|
4885
|
+
* `Math.random()` from the runtime environment as the random number
|
|
4886
|
+
* function instead of a seeded PRNG.
|
|
4887
|
+
*/
|
|
4888
|
+
static useDefaultRandom(): void;
|
|
4889
|
+
/**
|
|
4890
|
+
* Instructs methods within `RandomDraws` to use the seeded
|
|
4891
|
+
* pseudo-random number generator (PRNG).
|
|
4892
|
+
*
|
|
4893
|
+
* @remarks This method will throw an error if `setSeed()` has not
|
|
4894
|
+
* been called first to initialize the seeded PRNG.
|
|
4895
|
+
*/
|
|
4896
|
+
static useSeededRandom(): void;
|
|
4897
|
+
/**
|
|
4898
|
+
* Generates a random number in the range [0, 1) using the current
|
|
4899
|
+
* random function.
|
|
4900
|
+
*
|
|
4901
|
+
* @remarks This method will return a number from `Math.random()` in the
|
|
4902
|
+
* runtime environment, unless `setSeed()` has been called to initialize
|
|
4903
|
+
* a seeded PRNG.
|
|
4904
|
+
*
|
|
4905
|
+
* @returns A random number in the range [0, 1) using the current random function.
|
|
4906
|
+
*/
|
|
4907
|
+
static random(): number;
|
|
4638
4908
|
/**
|
|
4639
4909
|
* Draws a single random integer from a uniform distribution of integers in
|
|
4640
4910
|
* the specified range.
|
|
@@ -4643,6 +4913,10 @@ declare class RandomDraws {
|
|
|
4643
4913
|
* @param maximumInclusive - Upper bound of range
|
|
4644
4914
|
* @returns A sampled integer
|
|
4645
4915
|
*/
|
|
4916
|
+
static singleFromRange(minimumInclusive: number, maximumInclusive: number): number;
|
|
4917
|
+
/**
|
|
4918
|
+
* @deprecated Use `singleFromRange()` instead.
|
|
4919
|
+
*/
|
|
4646
4920
|
static SingleFromRange(minimumInclusive: number, maximumInclusive: number): number;
|
|
4647
4921
|
/**
|
|
4648
4922
|
* Draws random integers, without replacement, from a uniform distribution
|
|
@@ -4653,6 +4927,10 @@ declare class RandomDraws {
|
|
|
4653
4927
|
* @param maximumInclusive - Upper bound of range
|
|
4654
4928
|
* @returns An array of integers
|
|
4655
4929
|
*/
|
|
4930
|
+
static fromRangeWithoutReplacement(n: number, minimumInclusive: number, maximumInclusive: number): Array<number>;
|
|
4931
|
+
/**
|
|
4932
|
+
* @deprecated Use `fromRangeWithoutReplacement()` instead.
|
|
4933
|
+
*/
|
|
4656
4934
|
static FromRangeWithoutReplacement(n: number, minimumInclusive: number, maximumInclusive: number): Array<number>;
|
|
4657
4935
|
/**
|
|
4658
4936
|
* Draw random grid cell locations, without replacement, from a uniform
|
|
@@ -4670,6 +4948,13 @@ declare class RandomDraws {
|
|
|
4670
4948
|
* @returns Array of grid cells. Each cell is object in form of:
|
|
4671
4949
|
* { row: number, column: number }. Grid cell locations are zero-based
|
|
4672
4950
|
*/
|
|
4951
|
+
static fromGridWithoutReplacement(n: number, rows: number, columns: number, predicate?: (row: number, column: number) => boolean): Array<{
|
|
4952
|
+
row: number;
|
|
4953
|
+
column: number;
|
|
4954
|
+
}>;
|
|
4955
|
+
/**
|
|
4956
|
+
* @deprecated Use `fromGridWithoutReplacement()` instead.
|
|
4957
|
+
*/
|
|
4673
4958
|
static FromGridWithoutReplacement(n: number, rows: number, columns: number, predicate?: (row: number, column: number) => boolean): Array<{
|
|
4674
4959
|
row: number;
|
|
4675
4960
|
column: number;
|
|
@@ -5521,6 +5806,7 @@ declare class WebGlInfo {
|
|
|
5521
5806
|
* Removes the temporary canvas that was created to get WebGL information.
|
|
5522
5807
|
*/
|
|
5523
5808
|
static dispose(): void;
|
|
5809
|
+
static interceptWebGlCalls(htmlCanvas: HTMLCanvasElement): void;
|
|
5524
5810
|
}
|
|
5525
5811
|
|
|
5526
5812
|
export { Action, ActivityType, CanvasKitHelpers, ColorfulMutablePath, Composite, Constants, ConstraintType, CustomAction, Dimensions, Easings, Equal, Equals, EventStore, EventStoreMode, FadeAlphaAction, FontManager, Game, GroupAction, I18n, ImageManager, Label, LabelHorizontalAlignmentMode, LayoutConstraint, LegacyTimer, M2Error, M2EventType, M2ImageStatus, M2Node, M2NodeFactory, M2NodeType, M2SoundStatus, M2c2KitHelpers, MoveAction, MutablePath, NoneTransition, PlayAction, RandomDraws, RepeatAction, RepeatForeverAction, RotateAction, ScaleAction, Scene, SceneTransition, SequenceAction, Shape, ShapeType, SlideTransition, SoundManager, SoundPlayer, SoundRecorder, Sprite, Story, TextLine, Timer, Transition, TransitionDirection, TransitionType, Uuid, WaitAction, WebColors, WebGlInfo, handleInterfaceOptions };
|