@m2c2kit/addons 0.3.16 → 0.3.18
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 +178 -19
- package/dist/index.js +427 -17
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -869,6 +869,181 @@ declare class Instructions extends Story {
|
|
|
869
869
|
static Create(options: InstructionsOptions): Array<Scene>;
|
|
870
870
|
}
|
|
871
871
|
|
|
872
|
+
interface CountdownTimerOptions extends CompositeOptions {
|
|
873
|
+
/** Duration of the countdown, in milliseconds. Must be multiple of 1000. Default is 3000. */
|
|
874
|
+
milliseconds?: number;
|
|
875
|
+
/** Duration of each tick interval, in milliseconds. Default is 1000. */
|
|
876
|
+
tickIntervalMilliseconds?: number;
|
|
877
|
+
/** Font name for timer text (numbers). */
|
|
878
|
+
fontName?: string;
|
|
879
|
+
/** Font size for timer text (numbers). Default is 50. */
|
|
880
|
+
fontSize?: number;
|
|
881
|
+
/** Font size for timer text (numbers). Default is white. */
|
|
882
|
+
fontColor?: RgbaColor;
|
|
883
|
+
/** String to show when the timer reaches zero. Default is "0". This could be changed to another value, such as "GO!" */
|
|
884
|
+
zeroString?: string;
|
|
885
|
+
/** Shape of the timer. Default is a Royal Blue circle with a radius of 100. */
|
|
886
|
+
timerShape?: TimerShape;
|
|
887
|
+
/** Default is to center the timer text (numbers) vertically within the timer shape (verticalBias = .5). Setting verticalBias less than .5 will pull the text towards the top of the timer shape. Setting verticalBias greater than .5 will pull the text towards the bottom of the timer shape. */
|
|
888
|
+
textVerticalBias?: number;
|
|
889
|
+
}
|
|
890
|
+
interface TimerShape {
|
|
891
|
+
circle?: {
|
|
892
|
+
/** Radius of the circle timer shape. */
|
|
893
|
+
radius: number;
|
|
894
|
+
};
|
|
895
|
+
rectangle?: {
|
|
896
|
+
/** Width of the rectangle timer shape. */
|
|
897
|
+
width: number;
|
|
898
|
+
/** Height of the rectangle timer shape. */
|
|
899
|
+
height: number;
|
|
900
|
+
/** Corner radius of the rectangle timer shape. Default is 0. */
|
|
901
|
+
cornerRadius?: number;
|
|
902
|
+
};
|
|
903
|
+
/** Color of the timer shape. Default is Royal Blue. */
|
|
904
|
+
fillColor?: RgbaColor;
|
|
905
|
+
}
|
|
906
|
+
interface CountdownTimerEvent extends CompositeEvent {
|
|
907
|
+
type: "Composite";
|
|
908
|
+
compositeType: "CountdownTimer";
|
|
909
|
+
compositeEventType: "CountdownTimerTick" | "CountdownTimerComplete";
|
|
910
|
+
millisecondsRemaining: number;
|
|
911
|
+
target: CountdownTimer | string;
|
|
912
|
+
}
|
|
913
|
+
declare class CountdownTimer extends Composite implements CountdownTimerOptions {
|
|
914
|
+
readonly compositeType = "CountdownTimer";
|
|
915
|
+
private originalOptions;
|
|
916
|
+
private _milliseconds;
|
|
917
|
+
private _tickIntervalMilliseconds;
|
|
918
|
+
private _fontName;
|
|
919
|
+
private _fontSize;
|
|
920
|
+
private _fontColor;
|
|
921
|
+
private _zeroString;
|
|
922
|
+
private _timerShape;
|
|
923
|
+
private _textVerticalBias;
|
|
924
|
+
private countdownSequence;
|
|
925
|
+
private timerShapeNode?;
|
|
926
|
+
private timerNumberLabel?;
|
|
927
|
+
private _isRunning;
|
|
928
|
+
private hasStopped;
|
|
929
|
+
/**
|
|
930
|
+
* A countdown timer displays a number that counts down to zero.
|
|
931
|
+
*
|
|
932
|
+
* @param options
|
|
933
|
+
*/
|
|
934
|
+
constructor(options: CountdownTimerOptions);
|
|
935
|
+
get completeNodeOptions(): {
|
|
936
|
+
/** Duration of the countdown, in milliseconds. Must be multiple of 1000. Default is 3000. */
|
|
937
|
+
milliseconds?: number;
|
|
938
|
+
/** Duration of each tick interval, in milliseconds. Default is 1000. */
|
|
939
|
+
tickIntervalMilliseconds?: number;
|
|
940
|
+
/** Font name for timer text (numbers). */
|
|
941
|
+
fontName?: string;
|
|
942
|
+
/** Font size for timer text (numbers). Default is 50. */
|
|
943
|
+
fontSize?: number;
|
|
944
|
+
/** Font size for timer text (numbers). Default is white. */
|
|
945
|
+
fontColor?: RgbaColor;
|
|
946
|
+
/** String to show when the timer reaches zero. Default is "0". This could be changed to another value, such as "GO!" */
|
|
947
|
+
zeroString?: string;
|
|
948
|
+
/** Shape of the timer. Default is a Royal Blue circle with a radius of 100. */
|
|
949
|
+
timerShape?: TimerShape;
|
|
950
|
+
/** Default is to center the timer text (numbers) vertically within the timer shape (verticalBias = .5). Setting verticalBias less than .5 will pull the text towards the top of the timer shape. Setting verticalBias greater than .5 will pull the text towards the bottom of the timer shape. */
|
|
951
|
+
textVerticalBias?: number;
|
|
952
|
+
name?: string;
|
|
953
|
+
position?: _m2c2kit_core.Point;
|
|
954
|
+
scale?: number;
|
|
955
|
+
alpha?: number;
|
|
956
|
+
zRotation?: number;
|
|
957
|
+
isUserInteractionEnabled?: boolean;
|
|
958
|
+
draggable?: boolean;
|
|
959
|
+
hidden?: boolean;
|
|
960
|
+
layout?: _m2c2kit_core.Layout;
|
|
961
|
+
uuid?: string;
|
|
962
|
+
suppressEvents?: boolean;
|
|
963
|
+
anchorPoint?: _m2c2kit_core.Point;
|
|
964
|
+
zPosition?: number;
|
|
965
|
+
};
|
|
966
|
+
initialize(): void;
|
|
967
|
+
private tick;
|
|
968
|
+
/**
|
|
969
|
+
* Starts the countdown timer.
|
|
970
|
+
*
|
|
971
|
+
* @remarks Calling `start()` on a timer whose state is running (already started)
|
|
972
|
+
* or stopped will raise an error.
|
|
973
|
+
*/
|
|
974
|
+
start(): void;
|
|
975
|
+
/**
|
|
976
|
+
* Stops the countdown timer.
|
|
977
|
+
*
|
|
978
|
+
* @remarks This method is idempotent. Calling `stop()` on a stopped timer
|
|
979
|
+
* has no effect and will not raise an error. This can be called on a
|
|
980
|
+
* CountdownTimer in any state.
|
|
981
|
+
*/
|
|
982
|
+
stop(): void;
|
|
983
|
+
/**
|
|
984
|
+
* Resets the countdown timer to its initial state so it can be started
|
|
985
|
+
* again.
|
|
986
|
+
*
|
|
987
|
+
* @remarks This method is idempotent. Calling reset() multiple times will
|
|
988
|
+
* not raise an error. This can be called on a CountdownTimer in any state.
|
|
989
|
+
*/
|
|
990
|
+
reset(): void;
|
|
991
|
+
/**
|
|
992
|
+
* Returns true if the countdown timer is running.
|
|
993
|
+
*/
|
|
994
|
+
get isRunning(): boolean;
|
|
995
|
+
handleCompositeEvent(event: CountdownTimerEvent): void;
|
|
996
|
+
/**
|
|
997
|
+
* Executes a callback when the timer ticks.
|
|
998
|
+
*
|
|
999
|
+
* @remarks The callback is also executed when the timer completes.
|
|
1000
|
+
*
|
|
1001
|
+
* @param callback - function to execute
|
|
1002
|
+
* @param options
|
|
1003
|
+
*/
|
|
1004
|
+
onTick(callback: (countdownTimerEvent: CountdownTimerEvent) => void, options?: CallbackOptions): void;
|
|
1005
|
+
/**
|
|
1006
|
+
* Executes a callback when the timer completes.
|
|
1007
|
+
*
|
|
1008
|
+
* @remarks This is the last tick of the timer.
|
|
1009
|
+
*
|
|
1010
|
+
* @param callback - function to execute.
|
|
1011
|
+
* @param options
|
|
1012
|
+
*/
|
|
1013
|
+
onComplete(callback: (countdownTimerEvent: CountdownTimerEvent) => void, options?: CallbackOptions): void;
|
|
1014
|
+
private addCountdownTimerEventListener;
|
|
1015
|
+
get milliseconds(): number;
|
|
1016
|
+
set milliseconds(milliseconds: number);
|
|
1017
|
+
get tickIntervalMilliseconds(): number;
|
|
1018
|
+
set tickIntervalMilliseconds(tickIntervalMilliseconds: number);
|
|
1019
|
+
get fontColor(): RgbaColor;
|
|
1020
|
+
set fontColor(fontColor: RgbaColor);
|
|
1021
|
+
get fontName(): string | undefined;
|
|
1022
|
+
set fontName(fontName: string | undefined);
|
|
1023
|
+
get fontSize(): number;
|
|
1024
|
+
set fontSize(fontSize: number);
|
|
1025
|
+
get zeroString(): string;
|
|
1026
|
+
set zeroString(zeroString: string);
|
|
1027
|
+
get timerShape(): TimerShape;
|
|
1028
|
+
set timerShape(shape: TimerShape);
|
|
1029
|
+
get textVerticalBias(): number;
|
|
1030
|
+
set textVerticalBias(textVerticalBias: number);
|
|
1031
|
+
/**
|
|
1032
|
+
* Duplicates a node using deep copy.
|
|
1033
|
+
*
|
|
1034
|
+
* @remarks This is a deep recursive clone (node and children).
|
|
1035
|
+
* The uuid property of all duplicated nodes will be newly created,
|
|
1036
|
+
* because uuid must be unique.
|
|
1037
|
+
*
|
|
1038
|
+
* @param newName - optional name of the new, duplicated node. If not
|
|
1039
|
+
* provided, name will be the new uuid
|
|
1040
|
+
*/
|
|
1041
|
+
duplicate(newName?: string | undefined): CountdownTimer;
|
|
1042
|
+
update(): void;
|
|
1043
|
+
draw(canvas: Canvas): void;
|
|
1044
|
+
warmup(canvas: Canvas): void;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
872
1047
|
interface CountdownSceneOptions extends SceneOptions {
|
|
873
1048
|
/** Duration of the countdown, in milliseconds. */
|
|
874
1049
|
milliseconds: number;
|
|
@@ -895,27 +1070,11 @@ interface CountdownSceneOptions extends SceneOptions {
|
|
|
895
1070
|
/** Font size for timer numbers. Default is white. */
|
|
896
1071
|
timerNumbersFontColor?: RgbaColor;
|
|
897
1072
|
/** String to show when the timer reaches zero. Default is "0". This could be changed to another value, such as "GO!" */
|
|
898
|
-
|
|
1073
|
+
zeroString?: string;
|
|
899
1074
|
/** Shape of the timer. Default is a Royal Blue circle with a radius of 100 centered vertically. */
|
|
900
1075
|
timerShape?: TimerShape;
|
|
901
|
-
}
|
|
902
|
-
interface TimerShape {
|
|
903
|
-
circle?: {
|
|
904
|
-
/** Radius of the circle timer shape. */
|
|
905
|
-
radius: number;
|
|
906
|
-
};
|
|
907
|
-
rectangle?: {
|
|
908
|
-
/** Width of the rectangle timer shape. */
|
|
909
|
-
width: number;
|
|
910
|
-
/** Height of the rectangle timer shape. */
|
|
911
|
-
height: number;
|
|
912
|
-
/** Corner radius of the rectangle timer shape. Default is 0. */
|
|
913
|
-
cornerRadius?: number;
|
|
914
|
-
};
|
|
915
|
-
/** Color of the timer shape. Default is Royal Blue. */
|
|
916
|
-
fillColor?: RgbaColor;
|
|
917
1076
|
/** Default is to center the timer shape vertically within the scene (verticalBias = .5). Setting verticalBias less than .5 will pull the shape towards the top. Setting verticalBias greater than .5 will pull the shape towards the bottom. */
|
|
918
|
-
|
|
1077
|
+
shapeVerticalBias?: number;
|
|
919
1078
|
}
|
|
920
1079
|
declare class CountdownScene extends Scene {
|
|
921
1080
|
/**
|
|
@@ -1081,4 +1240,4 @@ declare class LocalePicker extends Composite {
|
|
|
1081
1240
|
duplicate(newName?: string): LocalePicker;
|
|
1082
1241
|
}
|
|
1083
1242
|
|
|
1084
|
-
export { Button, type ButtonOptions, CountdownScene, type CountdownSceneOptions, Dialog, type DialogEvent, type DialogOptions, DialogResult, DrawPad, type DrawPadEvent, DrawPadEventType, type DrawPadItem, type DrawPadItemEvent, DrawPadItemEventType, type DrawPadOptions, type DrawPadStroke, Grid, type GridChild, type GridOptions, type InstructionScene, Instructions, type InstructionsOptions, type KeyConfiguration, type KeyTapMetadata, type LocaleOption, LocalePicker, type LocalePickerEvent, type LocalePickerIcon, type LocalePickerOptions, type LocalePickerResult, type StrokeInteraction, type TimerShape, VirtualKeyboard, type VirtualKeyboardEvent, type VirtualKeyboardOptions, type VirtualKeyboardRow };
|
|
1243
|
+
export { Button, type ButtonOptions, CountdownScene, type CountdownSceneOptions, CountdownTimer, type CountdownTimerEvent, type CountdownTimerOptions, Dialog, type DialogEvent, type DialogOptions, DialogResult, DrawPad, type DrawPadEvent, DrawPadEventType, type DrawPadItem, type DrawPadItemEvent, DrawPadItemEventType, type DrawPadOptions, type DrawPadStroke, Grid, type GridChild, type GridOptions, type InstructionScene, Instructions, type InstructionsOptions, type KeyConfiguration, type KeyTapMetadata, type LocaleOption, LocalePicker, type LocalePickerEvent, type LocalePickerIcon, type LocalePickerOptions, type LocalePickerResult, type StrokeInteraction, type TimerShape, VirtualKeyboard, type VirtualKeyboardEvent, type VirtualKeyboardOptions, type VirtualKeyboardRow };
|
package/dist/index.js
CHANGED
|
@@ -293,18 +293,16 @@ class Grid extends Composite {
|
|
|
293
293
|
set gridChildren(gridChildren) {
|
|
294
294
|
this._gridChildren = gridChildren;
|
|
295
295
|
this.needsInitialization = true;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
);
|
|
307
|
-
}
|
|
296
|
+
this.savePropertyChangeEvent(
|
|
297
|
+
"gridChildren",
|
|
298
|
+
this.gridChildren.map(
|
|
299
|
+
(gridChild) => ({
|
|
300
|
+
node: gridChild.node.uuid,
|
|
301
|
+
row: gridChild.row,
|
|
302
|
+
column: gridChild.column
|
|
303
|
+
})
|
|
304
|
+
)
|
|
305
|
+
);
|
|
308
306
|
}
|
|
309
307
|
/**
|
|
310
308
|
* Removes all grid children from the grid.
|
|
@@ -2398,7 +2396,7 @@ class CountdownScene extends Scene {
|
|
|
2398
2396
|
bottomToBottomOf: this,
|
|
2399
2397
|
startToStartOf: this,
|
|
2400
2398
|
endToEndOf: this,
|
|
2401
|
-
verticalBias: options?.
|
|
2399
|
+
verticalBias: options?.shapeVerticalBias ?? 0.5
|
|
2402
2400
|
}
|
|
2403
2401
|
},
|
|
2404
2402
|
fillColor: options?.timerShape?.fillColor ?? WebColors.RoyalBlue
|
|
@@ -2417,7 +2415,7 @@ class CountdownScene extends Scene {
|
|
|
2417
2415
|
bottomToBottomOf: this,
|
|
2418
2416
|
startToStartOf: this,
|
|
2419
2417
|
endToEndOf: this,
|
|
2420
|
-
verticalBias: options
|
|
2418
|
+
verticalBias: options.shapeVerticalBias ?? 0.5
|
|
2421
2419
|
}
|
|
2422
2420
|
},
|
|
2423
2421
|
fillColor: options?.timerShape?.fillColor ?? WebColors.RoyalBlue
|
|
@@ -2465,7 +2463,7 @@ class CountdownScene extends Scene {
|
|
|
2465
2463
|
countdownSequence.push(
|
|
2466
2464
|
Action.custom({
|
|
2467
2465
|
callback: () => {
|
|
2468
|
-
timerNumberLabel.text = options?.
|
|
2466
|
+
timerNumberLabel.text = options?.zeroString ?? "0";
|
|
2469
2467
|
}
|
|
2470
2468
|
})
|
|
2471
2469
|
);
|
|
@@ -2965,7 +2963,419 @@ class LocalePicker extends Composite {
|
|
|
2965
2963
|
}
|
|
2966
2964
|
}
|
|
2967
2965
|
|
|
2968
|
-
|
|
2966
|
+
class CountdownTimer extends Composite {
|
|
2967
|
+
/**
|
|
2968
|
+
* A countdown timer displays a number that counts down to zero.
|
|
2969
|
+
*
|
|
2970
|
+
* @param options
|
|
2971
|
+
*/
|
|
2972
|
+
constructor(options) {
|
|
2973
|
+
super(options);
|
|
2974
|
+
this.compositeType = "CountdownTimer";
|
|
2975
|
+
this._milliseconds = 3e3;
|
|
2976
|
+
this._tickIntervalMilliseconds = 1e3;
|
|
2977
|
+
this._fontSize = 50;
|
|
2978
|
+
this._fontColor = WebColors.White;
|
|
2979
|
+
this._zeroString = "0";
|
|
2980
|
+
this._timerShape = {
|
|
2981
|
+
circle: {
|
|
2982
|
+
radius: 100
|
|
2983
|
+
},
|
|
2984
|
+
fillColor: WebColors.RoyalBlue
|
|
2985
|
+
};
|
|
2986
|
+
this._textVerticalBias = 0.5;
|
|
2987
|
+
this.countdownSequence = new Array();
|
|
2988
|
+
this._isRunning = false;
|
|
2989
|
+
this.hasStopped = false;
|
|
2990
|
+
this.originalOptions = JSON.parse(JSON.stringify(options));
|
|
2991
|
+
if (options.milliseconds) {
|
|
2992
|
+
this.milliseconds = options.milliseconds;
|
|
2993
|
+
}
|
|
2994
|
+
if (options.tickIntervalMilliseconds) {
|
|
2995
|
+
this.tickIntervalMilliseconds = options.tickIntervalMilliseconds;
|
|
2996
|
+
}
|
|
2997
|
+
if (options.fontName) {
|
|
2998
|
+
this.fontName = options.fontName;
|
|
2999
|
+
}
|
|
3000
|
+
if (options.fontSize !== void 0) {
|
|
3001
|
+
this.fontSize = options.fontSize;
|
|
3002
|
+
}
|
|
3003
|
+
if (options.fontColor) {
|
|
3004
|
+
this.fontColor = options.fontColor;
|
|
3005
|
+
}
|
|
3006
|
+
if (options.zeroString !== void 0) {
|
|
3007
|
+
this.zeroString = options.zeroString;
|
|
3008
|
+
}
|
|
3009
|
+
if (options.timerShape) {
|
|
3010
|
+
this.timerShape = options.timerShape;
|
|
3011
|
+
}
|
|
3012
|
+
if (options.textVerticalBias !== void 0) {
|
|
3013
|
+
this.textVerticalBias = options.textVerticalBias;
|
|
3014
|
+
}
|
|
3015
|
+
this.saveNodeNewEvent();
|
|
3016
|
+
}
|
|
3017
|
+
get completeNodeOptions() {
|
|
3018
|
+
return {
|
|
3019
|
+
...this.options,
|
|
3020
|
+
...this.getNodeOptions(),
|
|
3021
|
+
...this.getDrawableOptions(),
|
|
3022
|
+
...this.originalOptions
|
|
3023
|
+
};
|
|
3024
|
+
}
|
|
3025
|
+
initialize() {
|
|
3026
|
+
this.removeAllChildren();
|
|
3027
|
+
this._isRunning = false;
|
|
3028
|
+
this.hasStopped = false;
|
|
3029
|
+
if (this.timerShape?.circle === void 0 && this.timerShape?.rectangle === void 0 || this.timerShape?.circle !== void 0) {
|
|
3030
|
+
this.timerShapeNode = new Shape({
|
|
3031
|
+
circleOfRadius: this.timerShape.circle?.radius ?? 100,
|
|
3032
|
+
fillColor: this.timerShape?.fillColor ?? WebColors.RoyalBlue,
|
|
3033
|
+
suppressEvents: true
|
|
3034
|
+
});
|
|
3035
|
+
this.addChild(this.timerShapeNode);
|
|
3036
|
+
} else if (this.timerShape?.rectangle !== void 0) {
|
|
3037
|
+
this.timerShapeNode = new Shape({
|
|
3038
|
+
rect: {
|
|
3039
|
+
width: this.timerShape?.rectangle?.width ?? 200,
|
|
3040
|
+
height: this.timerShape?.rectangle?.height ?? 200
|
|
3041
|
+
},
|
|
3042
|
+
cornerRadius: this.timerShape?.rectangle?.cornerRadius,
|
|
3043
|
+
fillColor: this.timerShape?.fillColor ?? WebColors.RoyalBlue,
|
|
3044
|
+
suppressEvents: true
|
|
3045
|
+
});
|
|
3046
|
+
this.addChild(this.timerShapeNode);
|
|
3047
|
+
} else {
|
|
3048
|
+
throw new Error("Invalid timer shape options.");
|
|
3049
|
+
}
|
|
3050
|
+
this.size = this.timerShapeNode.size;
|
|
3051
|
+
if (this.milliseconds % 1e3 !== 0) {
|
|
3052
|
+
throw new Error(
|
|
3053
|
+
"CountdownTimer milliseconds must be a multiple of 1000."
|
|
3054
|
+
);
|
|
3055
|
+
}
|
|
3056
|
+
const timerInitialNumber = Math.floor(this.milliseconds / 1e3);
|
|
3057
|
+
this.timerNumberLabel = new Label({
|
|
3058
|
+
text: timerInitialNumber.toString(),
|
|
3059
|
+
fontSize: this.fontSize,
|
|
3060
|
+
fontName: this._fontName,
|
|
3061
|
+
fontColor: this.fontColor,
|
|
3062
|
+
layout: {
|
|
3063
|
+
constraints: {
|
|
3064
|
+
topToTopOf: this.timerShapeNode,
|
|
3065
|
+
bottomToBottomOf: this.timerShapeNode,
|
|
3066
|
+
startToStartOf: this.timerShapeNode,
|
|
3067
|
+
endToEndOf: this.timerShapeNode,
|
|
3068
|
+
verticalBias: this.textVerticalBias
|
|
3069
|
+
}
|
|
3070
|
+
},
|
|
3071
|
+
suppressEvents: true
|
|
3072
|
+
});
|
|
3073
|
+
this.timerShapeNode.addChild(this.timerNumberLabel);
|
|
3074
|
+
this.countdownSequence = new Array();
|
|
3075
|
+
for (let i = this.milliseconds; i > this.tickIntervalMilliseconds; i = i - this.tickIntervalMilliseconds) {
|
|
3076
|
+
this.countdownSequence.push(
|
|
3077
|
+
Action.wait({ duration: this.tickIntervalMilliseconds })
|
|
3078
|
+
);
|
|
3079
|
+
this.countdownSequence.push(
|
|
3080
|
+
Action.custom({
|
|
3081
|
+
callback: () => {
|
|
3082
|
+
this.tick(i - this.tickIntervalMilliseconds);
|
|
3083
|
+
}
|
|
3084
|
+
})
|
|
3085
|
+
);
|
|
3086
|
+
}
|
|
3087
|
+
this.countdownSequence.push(
|
|
3088
|
+
Action.wait({ duration: this.tickIntervalMilliseconds })
|
|
3089
|
+
);
|
|
3090
|
+
this.countdownSequence.push(
|
|
3091
|
+
Action.custom({
|
|
3092
|
+
callback: () => {
|
|
3093
|
+
this.tick(0);
|
|
3094
|
+
const countdownTimerEvent = {
|
|
3095
|
+
type: M2EventType.Composite,
|
|
3096
|
+
compositeType: this.compositeType,
|
|
3097
|
+
compositeEventType: "CountdownTimerComplete",
|
|
3098
|
+
target: this,
|
|
3099
|
+
handled: false,
|
|
3100
|
+
millisecondsRemaining: 0,
|
|
3101
|
+
...M2c2KitHelpers.createTimestamps()
|
|
3102
|
+
};
|
|
3103
|
+
this.handleCompositeEvent(countdownTimerEvent);
|
|
3104
|
+
this.saveEvent(countdownTimerEvent);
|
|
3105
|
+
if (this.eventListeners.length > 0) {
|
|
3106
|
+
this.eventListeners.filter(
|
|
3107
|
+
(listener) => listener.type === M2EventType.Composite && listener.compositeType === "CountdownTimer" && listener.compositeEventType === "CountdownTimerComplete"
|
|
3108
|
+
).forEach((listener) => {
|
|
3109
|
+
listener.callback(countdownTimerEvent);
|
|
3110
|
+
});
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
})
|
|
3114
|
+
);
|
|
3115
|
+
this.needsInitialization = false;
|
|
3116
|
+
}
|
|
3117
|
+
tick(millisecondsRemaining) {
|
|
3118
|
+
const countdownTimerEvent = {
|
|
3119
|
+
type: M2EventType.Composite,
|
|
3120
|
+
compositeType: this.compositeType,
|
|
3121
|
+
compositeEventType: "CountdownTimerTick",
|
|
3122
|
+
target: this,
|
|
3123
|
+
handled: false,
|
|
3124
|
+
millisecondsRemaining,
|
|
3125
|
+
...M2c2KitHelpers.createTimestamps()
|
|
3126
|
+
};
|
|
3127
|
+
this.handleCompositeEvent(countdownTimerEvent);
|
|
3128
|
+
this.saveEvent(countdownTimerEvent);
|
|
3129
|
+
if (this.eventListeners.length > 0) {
|
|
3130
|
+
this.eventListeners.filter(
|
|
3131
|
+
(listener) => listener.type === M2EventType.Composite && listener.compositeType === "CountdownTimer" && listener.compositeEventType === "CountdownTimerTick"
|
|
3132
|
+
).forEach((listener) => {
|
|
3133
|
+
listener.callback(countdownTimerEvent);
|
|
3134
|
+
});
|
|
3135
|
+
}
|
|
3136
|
+
}
|
|
3137
|
+
/**
|
|
3138
|
+
* Starts the countdown timer.
|
|
3139
|
+
*
|
|
3140
|
+
* @remarks Calling `start()` on a timer whose state is running (already started)
|
|
3141
|
+
* or stopped will raise an error.
|
|
3142
|
+
*/
|
|
3143
|
+
start() {
|
|
3144
|
+
if (this.isRunning) {
|
|
3145
|
+
throw new Error("CountdownTimer: cannot start. It is already running.");
|
|
3146
|
+
}
|
|
3147
|
+
if (this.hasStopped) {
|
|
3148
|
+
throw new Error(
|
|
3149
|
+
"CountdownTimer: It has stopped. You cannot start a stopped CountdownTimer. Instead, create a new CountdownTimer or call CountdownTimer.reset() before starting."
|
|
3150
|
+
);
|
|
3151
|
+
}
|
|
3152
|
+
if (this.needsInitialization) {
|
|
3153
|
+
this.initialize();
|
|
3154
|
+
}
|
|
3155
|
+
this.run(
|
|
3156
|
+
Action.sequence(this.countdownSequence),
|
|
3157
|
+
"__countdownSequenceAction"
|
|
3158
|
+
);
|
|
3159
|
+
this._isRunning = true;
|
|
3160
|
+
}
|
|
3161
|
+
/**
|
|
3162
|
+
* Stops the countdown timer.
|
|
3163
|
+
*
|
|
3164
|
+
* @remarks This method is idempotent. Calling `stop()` on a stopped timer
|
|
3165
|
+
* has no effect and will not raise an error. This can be called on a
|
|
3166
|
+
* CountdownTimer in any state.
|
|
3167
|
+
*/
|
|
3168
|
+
stop() {
|
|
3169
|
+
if (this.isRunning) {
|
|
3170
|
+
this.removeAction("__countdownSequenceAction");
|
|
3171
|
+
this._isRunning = false;
|
|
3172
|
+
this.hasStopped = true;
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
/**
|
|
3176
|
+
* Resets the countdown timer to its initial state so it can be started
|
|
3177
|
+
* again.
|
|
3178
|
+
*
|
|
3179
|
+
* @remarks This method is idempotent. Calling reset() multiple times will
|
|
3180
|
+
* not raise an error. This can be called on a CountdownTimer in any state.
|
|
3181
|
+
*/
|
|
3182
|
+
reset() {
|
|
3183
|
+
this.stop();
|
|
3184
|
+
this.initialize();
|
|
3185
|
+
}
|
|
3186
|
+
/**
|
|
3187
|
+
* Returns true if the countdown timer is running.
|
|
3188
|
+
*/
|
|
3189
|
+
get isRunning() {
|
|
3190
|
+
return this._isRunning;
|
|
3191
|
+
}
|
|
3192
|
+
handleCompositeEvent(event) {
|
|
3193
|
+
if (!this.timerNumberLabel) {
|
|
3194
|
+
throw new Error("Timer number label not found.");
|
|
3195
|
+
}
|
|
3196
|
+
switch (event.compositeEventType) {
|
|
3197
|
+
case "CountdownTimerTick": {
|
|
3198
|
+
this.timerNumberLabel.text = Math.ceil(
|
|
3199
|
+
event.millisecondsRemaining / 1e3
|
|
3200
|
+
).toString();
|
|
3201
|
+
break;
|
|
3202
|
+
}
|
|
3203
|
+
case "CountdownTimerComplete": {
|
|
3204
|
+
this.timerNumberLabel.text = this.zeroString;
|
|
3205
|
+
break;
|
|
3206
|
+
}
|
|
3207
|
+
default:
|
|
3208
|
+
throw new Error(
|
|
3209
|
+
`Invalid TimerCountdown event type: ${event.compositeEventType}`
|
|
3210
|
+
);
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3213
|
+
/**
|
|
3214
|
+
* Executes a callback when the timer ticks.
|
|
3215
|
+
*
|
|
3216
|
+
* @remarks The callback is also executed when the timer completes.
|
|
3217
|
+
*
|
|
3218
|
+
* @param callback - function to execute
|
|
3219
|
+
* @param options
|
|
3220
|
+
*/
|
|
3221
|
+
onTick(callback, options) {
|
|
3222
|
+
const eventListener = {
|
|
3223
|
+
type: M2EventType.Composite,
|
|
3224
|
+
compositeEventType: "CountdownTimerTick",
|
|
3225
|
+
compositeType: this.compositeType,
|
|
3226
|
+
nodeUuid: this.uuid,
|
|
3227
|
+
callback
|
|
3228
|
+
};
|
|
3229
|
+
this.addCountdownTimerEventListener(eventListener, options);
|
|
3230
|
+
}
|
|
3231
|
+
/**
|
|
3232
|
+
* Executes a callback when the timer completes.
|
|
3233
|
+
*
|
|
3234
|
+
* @remarks This is the last tick of the timer.
|
|
3235
|
+
*
|
|
3236
|
+
* @param callback - function to execute.
|
|
3237
|
+
* @param options
|
|
3238
|
+
*/
|
|
3239
|
+
onComplete(callback, options) {
|
|
3240
|
+
const eventListener = {
|
|
3241
|
+
type: M2EventType.Composite,
|
|
3242
|
+
compositeEventType: "CountdownTimerComplete",
|
|
3243
|
+
compositeType: this.compositeType,
|
|
3244
|
+
nodeUuid: this.uuid,
|
|
3245
|
+
callback
|
|
3246
|
+
};
|
|
3247
|
+
this.addCountdownTimerEventListener(eventListener, options);
|
|
3248
|
+
}
|
|
3249
|
+
addCountdownTimerEventListener(eventListener, options) {
|
|
3250
|
+
if (options?.replaceExisting) {
|
|
3251
|
+
this.eventListeners = this.eventListeners.filter(
|
|
3252
|
+
(listener) => !(listener.nodeUuid === eventListener.nodeUuid && listener.type === eventListener.type && listener.compositeType === eventListener.compositeType)
|
|
3253
|
+
);
|
|
3254
|
+
}
|
|
3255
|
+
this.eventListeners.push(eventListener);
|
|
3256
|
+
}
|
|
3257
|
+
get milliseconds() {
|
|
3258
|
+
return this._milliseconds;
|
|
3259
|
+
}
|
|
3260
|
+
set milliseconds(milliseconds) {
|
|
3261
|
+
if (Equal.value(this._milliseconds, milliseconds)) {
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3264
|
+
this._milliseconds = milliseconds;
|
|
3265
|
+
this.needsInitialization = true;
|
|
3266
|
+
this.savePropertyChangeEvent("milliseconds", milliseconds);
|
|
3267
|
+
}
|
|
3268
|
+
get tickIntervalMilliseconds() {
|
|
3269
|
+
return this._tickIntervalMilliseconds;
|
|
3270
|
+
}
|
|
3271
|
+
set tickIntervalMilliseconds(tickIntervalMilliseconds) {
|
|
3272
|
+
if (Equal.value(this._tickIntervalMilliseconds, tickIntervalMilliseconds)) {
|
|
3273
|
+
return;
|
|
3274
|
+
}
|
|
3275
|
+
this._tickIntervalMilliseconds = tickIntervalMilliseconds;
|
|
3276
|
+
this.needsInitialization = true;
|
|
3277
|
+
this.savePropertyChangeEvent(
|
|
3278
|
+
"tickIntervalMilliseconds",
|
|
3279
|
+
tickIntervalMilliseconds
|
|
3280
|
+
);
|
|
3281
|
+
}
|
|
3282
|
+
get fontColor() {
|
|
3283
|
+
return this._fontColor;
|
|
3284
|
+
}
|
|
3285
|
+
set fontColor(fontColor) {
|
|
3286
|
+
if (Equal.value(this._fontColor, fontColor)) {
|
|
3287
|
+
return;
|
|
3288
|
+
}
|
|
3289
|
+
this._fontColor = fontColor;
|
|
3290
|
+
this.needsInitialization = true;
|
|
3291
|
+
this.savePropertyChangeEvent("fontColor", fontColor);
|
|
3292
|
+
}
|
|
3293
|
+
get fontName() {
|
|
3294
|
+
return this._fontName;
|
|
3295
|
+
}
|
|
3296
|
+
set fontName(fontName) {
|
|
3297
|
+
if (this._fontName === fontName) {
|
|
3298
|
+
return;
|
|
3299
|
+
}
|
|
3300
|
+
this._fontName = fontName;
|
|
3301
|
+
this.needsInitialization = true;
|
|
3302
|
+
this.savePropertyChangeEvent("fontName", fontName);
|
|
3303
|
+
}
|
|
3304
|
+
get fontSize() {
|
|
3305
|
+
return this._fontSize;
|
|
3306
|
+
}
|
|
3307
|
+
set fontSize(fontSize) {
|
|
3308
|
+
if (Equal.value(this._fontSize, fontSize)) {
|
|
3309
|
+
return;
|
|
3310
|
+
}
|
|
3311
|
+
this._fontSize = fontSize;
|
|
3312
|
+
this.needsInitialization = true;
|
|
3313
|
+
this.savePropertyChangeEvent("fontSize", fontSize);
|
|
3314
|
+
}
|
|
3315
|
+
get zeroString() {
|
|
3316
|
+
return this._zeroString;
|
|
3317
|
+
}
|
|
3318
|
+
set zeroString(zeroString) {
|
|
3319
|
+
if (this._zeroString === zeroString) {
|
|
3320
|
+
return;
|
|
3321
|
+
}
|
|
3322
|
+
this._zeroString = zeroString;
|
|
3323
|
+
this.needsInitialization = true;
|
|
3324
|
+
this.savePropertyChangeEvent("zeroString", zeroString);
|
|
3325
|
+
}
|
|
3326
|
+
get timerShape() {
|
|
3327
|
+
return this._timerShape;
|
|
3328
|
+
}
|
|
3329
|
+
set timerShape(shape) {
|
|
3330
|
+
if (Equal.value(this._timerShape, shape)) {
|
|
3331
|
+
return;
|
|
3332
|
+
}
|
|
3333
|
+
this._timerShape = shape;
|
|
3334
|
+
this.needsInitialization = true;
|
|
3335
|
+
this.savePropertyChangeEvent("timerShape", shape);
|
|
3336
|
+
}
|
|
3337
|
+
get textVerticalBias() {
|
|
3338
|
+
return this._textVerticalBias;
|
|
3339
|
+
}
|
|
3340
|
+
set textVerticalBias(textVerticalBias) {
|
|
3341
|
+
if (Equal.value(this._textVerticalBias, textVerticalBias)) {
|
|
3342
|
+
return;
|
|
3343
|
+
}
|
|
3344
|
+
this._textVerticalBias = textVerticalBias;
|
|
3345
|
+
this.needsInitialization = true;
|
|
3346
|
+
this.savePropertyChangeEvent("textVerticalBias", textVerticalBias);
|
|
3347
|
+
}
|
|
3348
|
+
/**
|
|
3349
|
+
* Duplicates a node using deep copy.
|
|
3350
|
+
*
|
|
3351
|
+
* @remarks This is a deep recursive clone (node and children).
|
|
3352
|
+
* The uuid property of all duplicated nodes will be newly created,
|
|
3353
|
+
* because uuid must be unique.
|
|
3354
|
+
*
|
|
3355
|
+
* @param newName - optional name of the new, duplicated node. If not
|
|
3356
|
+
* provided, name will be the new uuid
|
|
3357
|
+
*/
|
|
3358
|
+
duplicate(newName) {
|
|
3359
|
+
throw new Error(`Method not implemented. ${newName}`);
|
|
3360
|
+
}
|
|
3361
|
+
update() {
|
|
3362
|
+
super.update();
|
|
3363
|
+
}
|
|
3364
|
+
draw(canvas) {
|
|
3365
|
+
super.drawChildren(canvas);
|
|
3366
|
+
}
|
|
3367
|
+
warmup(canvas) {
|
|
3368
|
+
this.initialize();
|
|
3369
|
+
this.children.filter((child) => child.isDrawable).forEach((child) => {
|
|
3370
|
+
child.warmup(canvas);
|
|
3371
|
+
});
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
M2c2KitHelpers.registerM2NodeClass(
|
|
3375
|
+
CountdownTimer
|
|
3376
|
+
);
|
|
3377
|
+
|
|
3378
|
+
console.log("\u26AA @m2c2kit/addons version 0.3.18 (b6c9faab)");
|
|
2969
3379
|
|
|
2970
|
-
export { Button, CountdownScene, Dialog, DialogResult, DrawPad, DrawPadEventType, DrawPadItemEventType, Grid, Instructions, LocalePicker, VirtualKeyboard };
|
|
3380
|
+
export { Button, CountdownScene, CountdownTimer, Dialog, DialogResult, DrawPad, DrawPadEventType, DrawPadItemEventType, Grid, Instructions, LocalePicker, VirtualKeyboard };
|
|
2971
3381
|
//# sourceMappingURL=index.js.map
|