/
AnimationOptions.ts
84 lines (67 loc) · 2.2 KB
/
AnimationOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import type { IAnimation, IRangedAnimation } from "../Interfaces/IAnimation.js";
import { AnimationMode } from "../../Enums/Modes/AnimationMode.js";
import type { IOptionLoader } from "../Interfaces/IOptionLoader.js";
import type { RangeValue } from "../../Types/RangeValue.js";
import type { RecursivePartial } from "../../Types/RecursivePartial.js";
import { StartValueType } from "../../Enums/Types/StartValueType.js";
import { setRangeValue } from "../../Utils/NumberUtils.js";
export class AnimationOptions implements IAnimation, IOptionLoader<IAnimation> {
count: RangeValue;
decay: RangeValue;
delay: RangeValue;
enable;
speed: RangeValue;
sync;
constructor() {
this.count = 0;
this.enable = false;
this.speed = 1;
this.decay = 0;
this.delay = 0;
this.sync = false;
}
load(data?: RecursivePartial<IAnimation>): void {
if (!data) {
return;
}
if (data.count !== undefined) {
this.count = setRangeValue(data.count);
}
if (data.enable !== undefined) {
this.enable = data.enable;
}
if (data.speed !== undefined) {
this.speed = setRangeValue(data.speed);
}
if (data.decay !== undefined) {
this.decay = setRangeValue(data.decay);
}
if (data.delay !== undefined) {
this.delay = setRangeValue(data.delay);
}
if (data.sync !== undefined) {
this.sync = data.sync;
}
}
}
export class RangedAnimationOptions extends AnimationOptions implements IOptionLoader<IRangedAnimation> {
mode: AnimationMode | keyof typeof AnimationMode;
startValue: StartValueType | keyof typeof StartValueType;
constructor() {
super();
this.mode = AnimationMode.auto;
this.startValue = StartValueType.random;
}
load(data?: RecursivePartial<IRangedAnimation>): void {
super.load(data);
if (!data) {
return;
}
if (data.mode !== undefined) {
this.mode = data.mode;
}
if (data.startValue !== undefined) {
this.startValue = data.startValue;
}
}
}