@m2c2kit/core 0.3.29 → 0.3.30
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/assets/{canvaskit-0.39.1.wasm → canvaskit-0.40.0.wasm} +0 -0
- package/dist/index.d.ts +162 -22
- package/dist/index.js +993 -577
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +4 -4
- package/package.json +8 -8
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -937,6 +937,15 @@ interface LocalizationOptions {
|
|
|
937
937
|
additionalTranslation?: Translation;
|
|
938
938
|
}
|
|
939
939
|
|
|
940
|
+
/**
|
|
941
|
+
* ScoringSchema defines the data that are generated by the scoring code. They
|
|
942
|
+
* are key-value pairs in which the key is the variable name, and the value is
|
|
943
|
+
* JSON Schema that defines the type of the variable.
|
|
944
|
+
*/
|
|
945
|
+
interface ScoringSchema {
|
|
946
|
+
[key: string]: JsonSchema;
|
|
947
|
+
}
|
|
948
|
+
|
|
940
949
|
/**
|
|
941
950
|
* Options to specify HTML canvas, set game canvas size, and load game assets.
|
|
942
951
|
*/
|
|
@@ -965,6 +974,8 @@ interface GameOptions extends LocalizationOptions {
|
|
|
965
974
|
stretch?: boolean;
|
|
966
975
|
/** Schema of trial data; JSON object where key is variable name, value is data type */
|
|
967
976
|
trialSchema?: TrialSchema;
|
|
977
|
+
/** Schema of scoring data; JSON object where key is variable name, value is data type */
|
|
978
|
+
scoringSchema?: ScoringSchema;
|
|
968
979
|
/** Default game parameters; JSON object where key is the game parameter, value is default value */
|
|
969
980
|
parameters?: GameParameters;
|
|
970
981
|
/** Font assets to use. The first element will be the default font */
|
|
@@ -997,6 +1008,7 @@ interface GameOptions extends LocalizationOptions {
|
|
|
997
1008
|
|
|
998
1009
|
interface GameData extends ActivityKeyValueData {
|
|
999
1010
|
trials: Array<TrialData>;
|
|
1011
|
+
scoring: ActivityKeyValueData;
|
|
1000
1012
|
}
|
|
1001
1013
|
|
|
1002
1014
|
/**
|
|
@@ -1974,20 +1986,43 @@ declare class Game implements Activity {
|
|
|
1974
1986
|
*/
|
|
1975
1987
|
dispose(): void;
|
|
1976
1988
|
private initData;
|
|
1989
|
+
private validateSchema;
|
|
1977
1990
|
private propertySchemaDataTypeIsValid;
|
|
1978
1991
|
private getDeviceMetadata;
|
|
1979
1992
|
/**
|
|
1980
1993
|
* Adds data to the game's TrialData object.
|
|
1981
1994
|
*
|
|
1982
|
-
* @remarks
|
|
1983
|
-
* object
|
|
1984
|
-
*
|
|
1985
|
-
*
|
|
1995
|
+
* @remarks `variableName` must be previously defined in the
|
|
1996
|
+
* {@link TrialSchema} object in {@link GameOptions}. The type of the value
|
|
1997
|
+
* must match what was defined in the trial schema, otherwise an error is
|
|
1998
|
+
* thrown.
|
|
1986
1999
|
*
|
|
1987
2000
|
* @param variableName - variable to be set
|
|
1988
2001
|
* @param value - value of the variable to set
|
|
1989
2002
|
*/
|
|
1990
2003
|
addTrialData(variableName: string, value: JsonSchemaDataTypeScriptTypes): void;
|
|
2004
|
+
/**
|
|
2005
|
+
* Adds data to the game's scoring data.
|
|
2006
|
+
*
|
|
2007
|
+
* @remarks The variable name (or object property names) must be previously
|
|
2008
|
+
* defined in the {@link ScoringSchema} object in {@link GameOptions}.
|
|
2009
|
+
* The type of the value must match what was defined in the scoring schema,
|
|
2010
|
+
* otherwise an error is thrown.
|
|
2011
|
+
*
|
|
2012
|
+
* @param variableNameOrObject - Either a variable name (string) or an object
|
|
2013
|
+
* containing multiple key-value pairs to add all at once.
|
|
2014
|
+
* @param value - Value of the variable to set (only used when
|
|
2015
|
+
* variableNameOrObject is a variable name string).
|
|
2016
|
+
*/
|
|
2017
|
+
addScoringData(variableNameOrObject: string | Record<string, JsonSchemaDataTypeScriptTypes> | Array<Record<string, JsonSchemaDataTypeScriptTypes>>, value?: JsonSchemaDataTypeScriptTypes): void;
|
|
2018
|
+
/**
|
|
2019
|
+
* Helper method to validate and set a single scoring variable
|
|
2020
|
+
*
|
|
2021
|
+
* @param variableName - Name of the variable to set
|
|
2022
|
+
* @param value - Value to set
|
|
2023
|
+
* @private
|
|
2024
|
+
*/
|
|
2025
|
+
private validateAndSetScoringVariable;
|
|
1991
2026
|
/**
|
|
1992
2027
|
* Adds custom trial schema to the game's trialSchema object.
|
|
1993
2028
|
*
|
|
@@ -2036,6 +2071,22 @@ declare class Game implements Activity {
|
|
|
2036
2071
|
* the appropriate time. It is not triggered automatically.
|
|
2037
2072
|
*/
|
|
2038
2073
|
trialComplete(): void;
|
|
2074
|
+
/**
|
|
2075
|
+
* Marks scoring as complete.
|
|
2076
|
+
*
|
|
2077
|
+
* @remarks This method must be called after the game has finished adding
|
|
2078
|
+
* scores using addScoringData(). Calling will trigger the onActivityResults
|
|
2079
|
+
* callback function, if one was provided in SessionOptions. This is how the
|
|
2080
|
+
* game communicates scoring data to the parent session, which can then save
|
|
2081
|
+
* or process the data. It is the responsibility of the the game programmer
|
|
2082
|
+
* to call this at the appropriate time. It is not triggered automatically.
|
|
2083
|
+
*/
|
|
2084
|
+
scoringComplete(): void;
|
|
2085
|
+
/**
|
|
2086
|
+
* The m2c2kit engine will automatically include these schema and their
|
|
2087
|
+
* values in the scoring data.
|
|
2088
|
+
*/
|
|
2089
|
+
private readonly automaticScoringSchema;
|
|
2039
2090
|
/**
|
|
2040
2091
|
* The m2c2kit engine will automatically include these schema and their
|
|
2041
2092
|
* values in the trial data.
|
|
@@ -2052,6 +2103,7 @@ declare class Game implements Activity {
|
|
|
2052
2103
|
*/
|
|
2053
2104
|
private makeGameActivityConfiguration;
|
|
2054
2105
|
private makeGameActivityConfigurationSchema;
|
|
2106
|
+
private makeScoringDataSchema;
|
|
2055
2107
|
/**
|
|
2056
2108
|
* Should be called when current game has ended successfully.
|
|
2057
2109
|
*
|
|
@@ -2298,14 +2350,69 @@ declare class I18n {
|
|
|
2298
2350
|
private localeTranslationAvailable;
|
|
2299
2351
|
switchToLocale(locale: string): void;
|
|
2300
2352
|
/**
|
|
2353
|
+
* Returns the localized text and font information for the given key in the
|
|
2354
|
+
* current locale.
|
|
2301
2355
|
*
|
|
2302
2356
|
* @param key - Translation key
|
|
2303
2357
|
* @param interpolation - Interpolation keys and values to replace
|
|
2304
|
-
* placeholders in the translated text
|
|
2305
|
-
* @returns
|
|
2306
|
-
*
|
|
2358
|
+
* string interpolation placeholders in the translated text
|
|
2359
|
+
* @returns object with the localized text, font information, and whether the
|
|
2360
|
+
* translation is a fallback.
|
|
2307
2361
|
*/
|
|
2308
2362
|
getTextLocalization(key: string, interpolation?: StringInterpolationMap): TextLocalizationResult;
|
|
2363
|
+
/**
|
|
2364
|
+
*
|
|
2365
|
+
* @param key - Translation key to be translated
|
|
2366
|
+
* @param interpolation - String interpolation keys and values to replace
|
|
2367
|
+
* @returns result object with the localized text, font
|
|
2368
|
+
*/
|
|
2369
|
+
private attemptTranslation;
|
|
2370
|
+
/**
|
|
2371
|
+
* Handles translation placeholders in a string.
|
|
2372
|
+
*
|
|
2373
|
+
* @remarks The value of a translation placeholder (text within `[[]]`)
|
|
2374
|
+
* may also contain string interpolation placeholders (`{{}}`), so we need
|
|
2375
|
+
* to handle that as well.
|
|
2376
|
+
*
|
|
2377
|
+
* @param key - Translation key for the string to be localized
|
|
2378
|
+
* @param initialResult - Initial translation result for the string
|
|
2379
|
+
* @param interpolation - Interpolation keys and values to replace
|
|
2380
|
+
* interpolation placeholders in the translated text
|
|
2381
|
+
* @returns result object with the localized text,
|
|
2382
|
+
*/
|
|
2383
|
+
private handleTranslationPlaceholders;
|
|
2384
|
+
/**
|
|
2385
|
+
* Translates a translation placeholder key to its text and collects font properties.
|
|
2386
|
+
*
|
|
2387
|
+
* @param placeholderKey - Translation key for the placeholder
|
|
2388
|
+
* @param fontProps - Font properties sets to collect font information
|
|
2389
|
+
* @param interpolation - Interpolation keys and values to replace
|
|
2390
|
+
* string interpolation placeholders in the translated text
|
|
2391
|
+
* @returns result object with the translated text and whether it is a fallback translation
|
|
2392
|
+
*/
|
|
2393
|
+
private translatePlaceholder;
|
|
2394
|
+
/**
|
|
2395
|
+
* Extracts translation key placeholders from a string.
|
|
2396
|
+
*
|
|
2397
|
+
* @remarks Translation key placeholders are denoted by double square brackets,
|
|
2398
|
+
* e.g., "The translated word is [[RED]]", and RED is a key for translation.
|
|
2399
|
+
*
|
|
2400
|
+
* @param s - string to search for placeholders
|
|
2401
|
+
* @returns an array of placeholders found in the string, without the square
|
|
2402
|
+
* brackets
|
|
2403
|
+
*/
|
|
2404
|
+
private getTranslationPlaceholders;
|
|
2405
|
+
/**
|
|
2406
|
+
* Logs warnings if the string to be localized has conflicting font
|
|
2407
|
+
* properties.
|
|
2408
|
+
*
|
|
2409
|
+
* @remarks This can happen due to multiple placeholders in the string
|
|
2410
|
+
* that specify different font sizes, font names, or font names arrays.
|
|
2411
|
+
*
|
|
2412
|
+
* @param key - Translation key for which the string is being localized
|
|
2413
|
+
* @param fontProps - font properties sets collected from the placeholders
|
|
2414
|
+
*/
|
|
2415
|
+
private warnConflictingFontProperties;
|
|
2309
2416
|
/**
|
|
2310
2417
|
* Returns the translation text for the given key in the current locale.
|
|
2311
2418
|
*
|
|
@@ -3761,6 +3868,13 @@ declare enum Dimensions {
|
|
|
3761
3868
|
MatchConstraint = 0
|
|
3762
3869
|
}
|
|
3763
3870
|
|
|
3871
|
+
/**
|
|
3872
|
+
* Custom error class for m2c2kit errors.
|
|
3873
|
+
*/
|
|
3874
|
+
declare class M2Error extends Error {
|
|
3875
|
+
constructor(...params: string[]);
|
|
3876
|
+
}
|
|
3877
|
+
|
|
3764
3878
|
type M2NodeConstructor = new (options?: M2NodeOptions) => M2Node;
|
|
3765
3879
|
|
|
3766
3880
|
/**
|
|
@@ -4197,7 +4311,7 @@ declare enum LabelHorizontalAlignmentMode {
|
|
|
4197
4311
|
}
|
|
4198
4312
|
|
|
4199
4313
|
interface LabelOptions extends M2NodeOptions, DrawableOptions, TextOptions {
|
|
4200
|
-
/** Text to be displayed. Tags for bold, italic, and
|
|
4314
|
+
/** Text to be displayed. When operating with localization, text within double square brackets will be replaced with the value of the key in the translation. For example, if the text is `The translated word is [[RED]]`, `[[RED]]` will be replaced with the translation. If no localization is used, or a translation for the key is missing, then the text will be rendered as is. Tags for bold (`b`), italic (`i`), underline (`u`), overline(`o`), and strikethrough (`s`) are supported, e.g., `<b><u>Bold and underline</u></b>`. Note that while bold and italic and be combined, only one of underline, overline, and strikethrough can be used on a text segment. */
|
|
4201
4315
|
text?: string;
|
|
4202
4316
|
/** Horizontal alignment of label text. see {@link LabelHorizontalAlignmentMode}. Default is LabelHorizontalAlignmentMode.center */
|
|
4203
4317
|
horizontalAlignmentMode?: LabelHorizontalAlignmentMode;
|
|
@@ -4230,14 +4344,12 @@ declare class Label extends M2Node implements IDrawable, IText, LabelOptions {
|
|
|
4230
4344
|
private builder?;
|
|
4231
4345
|
private _fontPaint?;
|
|
4232
4346
|
private _backgroundPaint?;
|
|
4233
|
-
private _underlinePaint?;
|
|
4234
4347
|
private localizedFontSize;
|
|
4235
4348
|
private localizedFontName;
|
|
4236
4349
|
private localizedFontNames;
|
|
4350
|
+
private textAfterLocalization;
|
|
4237
4351
|
private plainText;
|
|
4238
4352
|
private styleSegments;
|
|
4239
|
-
private underlinedRanges;
|
|
4240
|
-
private currentBuilderPosition;
|
|
4241
4353
|
/**
|
|
4242
4354
|
* Single or multi-line text formatted and rendered on the screen.
|
|
4243
4355
|
*
|
|
@@ -4284,7 +4396,23 @@ declare class Label extends M2Node implements IDrawable, IText, LabelOptions {
|
|
|
4284
4396
|
* @throws Error if tags are improperly nested or unclosed
|
|
4285
4397
|
*/
|
|
4286
4398
|
private parseFormattedText;
|
|
4287
|
-
|
|
4399
|
+
/**
|
|
4400
|
+
* Adds text segments with consistent styling to the paragraph builder.
|
|
4401
|
+
*
|
|
4402
|
+
* @param builder - {@link ParagraphBuilder}
|
|
4403
|
+
* @param styleSegments - Segments of text with consistent styling
|
|
4404
|
+
* @param defaultStyle - Default style to apply
|
|
4405
|
+
*/
|
|
4406
|
+
private addStyleSegmentsToParagraphBuilder;
|
|
4407
|
+
/**
|
|
4408
|
+
* Helper that adds text to the paragraph builder with the specified style.
|
|
4409
|
+
*
|
|
4410
|
+
* @param builder - {@link ParagraphBuilder}
|
|
4411
|
+
* @param text - The text to add
|
|
4412
|
+
* @param defaultStyle - The default style to apply
|
|
4413
|
+
* @param styleModifiers - Additional style modifications
|
|
4414
|
+
* @returns void
|
|
4415
|
+
*/
|
|
4288
4416
|
private addTextWithStyle;
|
|
4289
4417
|
/**
|
|
4290
4418
|
* Determines the M2Font objects that need to be ready in order to draw
|
|
@@ -4326,8 +4454,6 @@ declare class Label extends M2Node implements IDrawable, IText, LabelOptions {
|
|
|
4326
4454
|
private set backgroundPaint(value);
|
|
4327
4455
|
private get fontPaint();
|
|
4328
4456
|
private set fontPaint(value);
|
|
4329
|
-
private get underlinePaint();
|
|
4330
|
-
private set underlinePaint(value);
|
|
4331
4457
|
/**
|
|
4332
4458
|
* Duplicates a node using deep copy.
|
|
4333
4459
|
*
|
|
@@ -4341,7 +4467,6 @@ declare class Label extends M2Node implements IDrawable, IText, LabelOptions {
|
|
|
4341
4467
|
duplicate(newName?: string): Label;
|
|
4342
4468
|
update(): void;
|
|
4343
4469
|
draw(canvas: Canvas): void;
|
|
4344
|
-
private drawUnderlines;
|
|
4345
4470
|
warmup(canvas: Canvas): void;
|
|
4346
4471
|
}
|
|
4347
4472
|
|
|
@@ -4536,12 +4661,27 @@ declare class RandomDraws {
|
|
|
4536
4661
|
}
|
|
4537
4662
|
|
|
4538
4663
|
/**
|
|
4539
|
-
*
|
|
4540
|
-
*
|
|
4541
|
-
* JSON Schema that defines the type of the variable.
|
|
4664
|
+
* Assessments that generate scoring data must implement the ScoringProvider
|
|
4665
|
+
* interface
|
|
4542
4666
|
*/
|
|
4543
|
-
interface
|
|
4544
|
-
|
|
4667
|
+
interface ScoringProvider {
|
|
4668
|
+
/**
|
|
4669
|
+
* Calculates scores based on the provided activity data and optional
|
|
4670
|
+
* additional parameters.
|
|
4671
|
+
*
|
|
4672
|
+
* @param data - Activity data from which to calculate scores.
|
|
4673
|
+
* @param extras - Optional additional parameters that are needed for an
|
|
4674
|
+
* activity's scoring calculations. This can include things like
|
|
4675
|
+
* game parameters, user context, or other metadata that is relevant
|
|
4676
|
+
* to the scoring logic. The structure of this object is not
|
|
4677
|
+
* defined by this interface, as it can vary widely between different
|
|
4678
|
+
* activities.
|
|
4679
|
+
* @returns The calculated scores object or an array of such objects. If an
|
|
4680
|
+
* array of is returned, it should have length 1.
|
|
4681
|
+
*/
|
|
4682
|
+
calculateScores(data: ActivityKeyValueData[], extras?: {
|
|
4683
|
+
[key: string]: unknown;
|
|
4684
|
+
}): ActivityKeyValueData | Array<ActivityKeyValueData>;
|
|
4545
4685
|
}
|
|
4546
4686
|
|
|
4547
4687
|
declare enum ShapeType {
|
|
@@ -5367,5 +5507,5 @@ declare class WebGlInfo {
|
|
|
5367
5507
|
static dispose(): void;
|
|
5368
5508
|
}
|
|
5369
5509
|
|
|
5370
|
-
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, 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 };
|
|
5371
|
-
export type { Activity, ActivityCallbacks, ActivityEvent, ActivityEventListener, ActivityKeyValueData, ActivityLifecycleEvent, ActivityResultsEvent, BrowserImage, BrowserImageDataReadyEvent, CallbackOptions, CompositeEvent, CompositeOptions, Constraints, CustomActionOptions, DefaultParameter, DomPointerDownEvent, DrawableOptions, EasingFunction, FadeAlphaActionOptions, FontAsset, FontData, GameData, GameEvent, GameOptions, GameParameters, GlobalVariables, I18nDataReadyEvent, IDataStore, IDrawable, IText, LabelOptions, Layout, LocaleSvg, M2ColorfulPath, M2DragEvent, M2Event, M2EventListener, M2Image, M2KeyboardEvent, M2NodeAddChildEvent, M2NodeConstructor, M2NodeEvent, M2NodeEventListener, M2NodeNewEvent, M2NodeOptions, M2NodePropertyChangeEvent, M2NodeRemoveChildEvent, M2Path, M2PointerEvent, M2Sound, MoveActionOptions, PlayActionOptions, Plugin, PluginEvent, Point, RectOptions, RgbaColor, ScaleActionOptions, SceneOptions, ScenePresentEvent, ScoringSchema, ShapeOptions, Size, SlideTransitionOptions, SoundAsset, SoundPlayerOptions, SoundRecorderOptions, SoundRecorderResults, SpriteOptions, StoryOptions, StringInterpolationMap, TapEvent, TextAndFont, TextLineOptions, TextLocalizationResult, TextOptions, TextWithFontCustomization, Translation, TranslationConfiguration, TranslationOptions, TrialData, TrialSchema, WaitActionOptions };
|
|
5510
|
+
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 };
|
|
5511
|
+
export type { Activity, ActivityCallbacks, ActivityEvent, ActivityEventListener, ActivityKeyValueData, ActivityLifecycleEvent, ActivityResultsEvent, BrowserImage, BrowserImageDataReadyEvent, CallbackOptions, CompositeEvent, CompositeOptions, Constraints, CustomActionOptions, DefaultParameter, DomPointerDownEvent, DrawableOptions, EasingFunction, FadeAlphaActionOptions, FontAsset, FontData, GameData, GameEvent, GameOptions, GameParameters, GlobalVariables, I18nDataReadyEvent, IDataStore, IDrawable, IText, LabelOptions, Layout, LocaleSvg, M2ColorfulPath, M2DragEvent, M2Event, M2EventListener, M2Image, M2KeyboardEvent, M2NodeAddChildEvent, M2NodeConstructor, M2NodeEvent, M2NodeEventListener, M2NodeNewEvent, M2NodeOptions, M2NodePropertyChangeEvent, M2NodeRemoveChildEvent, M2Path, M2PointerEvent, M2Sound, MoveActionOptions, PlayActionOptions, Plugin, PluginEvent, Point, RectOptions, RgbaColor, ScaleActionOptions, SceneOptions, ScenePresentEvent, ScoringProvider, ScoringSchema, ShapeOptions, Size, SlideTransitionOptions, SoundAsset, SoundPlayerOptions, SoundRecorderOptions, SoundRecorderResults, SpriteOptions, StoryOptions, StringInterpolationMap, TapEvent, TextAndFont, TextLineOptions, TextLocalizationResult, TextOptions, TextWithFontCustomization, Translation, TranslationConfiguration, TranslationOptions, TrialData, TrialSchema, WaitActionOptions };
|