forked from digitsensitive/astar-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dat-gui.service.ts
80 lines (71 loc) · 1.95 KB
/
dat-gui.service.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
/**
* @author Digitsensitive <[email protected]>
* @copyright 2019 - 2023 digitsensitive
* @description Dat.Gui Service
* dat.gui is a lightweight controller library for JavaScript.
* https://github.com/dataarts/dat.gui
* @version 1.0.0
* @license {@link https://github.com/digitsensitive/phaser3-typescript/blob/master/LICENSE.md | MIT License}
*/
import * as dat from 'dat.gui';
export class DatGuiService {
private gui: dat.GUI;
private controllers: dat.GUIController[];
constructor() {
this.gui = new dat.GUI();
this.controllers = [];
}
public addFolder(folderName: string): void {
this.gui.addFolder(folderName);
}
public addController(
controllerName: string,
target: Object,
propName: string,
hasController: boolean,
controllerFunction?: (value) => void,
items?: string[] | number[] | Object
): void {
this.controllers.push(
this.gui.add(target, propName, items).name(controllerName)
);
if (hasController) {
this.addOnChangeToController(
this.controllers[this.controllers.length - 1],
controllerFunction
);
}
}
public addNumberController(
controllerName: string,
target: Object,
propName: string,
hasController: boolean,
configNumber: { min: number; max: number; step: number },
controllerFunction?: (value) => void
): void {
this.controllers.push(
this.gui
.add(
target,
propName,
configNumber.min,
configNumber.max,
configNumber.step
)
.name(controllerName)
);
if (hasController) {
this.addOnChangeToController(
this.controllers[this.controllers.length - 1],
controllerFunction
);
}
}
private addOnChangeToController(
controller: dat.GUIController,
onChangeFunction?: (value) => void
): void {
controller.onChange(onChangeFunction);
}
}