/
FireworkOptions.ts
97 lines (84 loc) · 2.42 KB
/
FireworkOptions.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
85
86
87
88
89
90
91
92
93
94
95
96
97
import {
type IOptionLoader,
type RangeValue,
type RecursivePartial,
type SingleOrMultiple,
isArray,
setRangeValue,
} from "@tsparticles/engine";
import type { IFireworkOptions } from "./IFireworkOptions.js";
export class FireworkOptions implements IFireworkOptions, IOptionLoader<IFireworkOptions> {
background: string;
brightness: RangeValue;
colors: SingleOrMultiple<string>;
gravity: RangeValue;
minHeight: RangeValue;
rate: RangeValue;
saturation: RangeValue;
sounds;
speed: RangeValue;
splitCount: RangeValue;
constructor() {
this.background = "none";
this.brightness = {
min: -30,
max: 30,
};
this.colors = ["#ff595e", "#ffca3a", "#8ac926", "#1982c4", "#6a4c93"];
this.gravity = 5;
this.minHeight = {
min: 10,
max: 30,
};
this.rate = 10;
this.saturation = {
min: -30,
max: 30,
};
this.sounds = true;
this.speed = { min: 5, max: 15 };
this.splitCount = {
min: 75,
max: 150,
};
}
load(data?: RecursivePartial<IFireworkOptions>): void {
if (!data) {
return;
}
if (data.background !== undefined) {
this.background = data.background;
}
if (data.colors !== undefined) {
if (isArray(data.colors)) {
this.colors = [...data.colors];
} else {
this.colors = data.colors;
}
}
if (data.brightness !== undefined) {
this.brightness = setRangeValue(data.brightness);
}
if (data.gravity !== undefined) {
this.gravity = setRangeValue(data.gravity);
}
if (data.minHeight !== undefined) {
this.minHeight = setRangeValue(data.minHeight);
}
if (data.rate !== undefined) {
this.rate = setRangeValue(data.rate);
}
if (data.saturation !== undefined) {
this.saturation = setRangeValue(data.saturation);
}
if (data.sounds !== undefined) {
this.sounds = data.sounds;
}
if (data.speed !== undefined) {
this.speed = setRangeValue(data.speed);
}
if (data.splitCount !== undefined) {
this.splitCount = setRangeValue(data.splitCount);
}
}
}