-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBB_kuenaimaku_v11.js
140 lines (135 loc) · 3.56 KB
/
BB_kuenaimaku_v11.js
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
const bars = {
bar1: {
id: "bar1",
ignoreMin: true,
ignoreMax: false,
mincolor: "#FF0000",
maxcolor: "#80FF00",
position: "bottom-inner",
attribute: "hp",
indentLeft: 30,
indentRight: null,
shareHeight: true,
otherVisibility: CONST.TOKEN_DISPLAY_MODES.HOVER,
ownerVisibility: CONST.TOKEN_DISPLAY_MODES.INHERIT,
gmVisibility: CONST.TOKEN_DISPLAY_MODES.INHERIT,
style: "fraction",
label: "",
invert: false,
subdivisions: null,
subdivisionsOwner: false,
fgImage: "",
bgImage: "",
opacity: null,
max: null
},
structure: {
id: "structure",
attribute: "structure",
mincolor: "#1F9EFF",
maxcolor: "#1F9EFF",
position: "bottom-inner",
indentLeft: null,
indentRight: 70,
shareHeight: true,
subdivisions: 4,
subdivisionsOwner: true,
otherVisibility: CONST.TOKEN_DISPLAY_MODES.HOVER,
ownerVisibility: CONST.TOKEN_DISPLAY_MODES.INHERIT
},
stress: {
id: "stress",
mincolor: "#FF7B00",
maxcolor: "#FF7B00",
position: "bottom-outer",
attribute: "stress",
indentLeft: null,
indentRight: 70,
shareHeight: true,
subdivisions: 4,
subdivisionsOwner: true,
otherVisibility: CONST.TOKEN_DISPLAY_MODES.HOVER,
ownerVisibility: CONST.TOKEN_DISPLAY_MODES.INHERIT
},
bar2: {
id: "bar2",
ignoreMax: true,
ignoreMin: false,
mincolor: "#700000",
maxcolor: "#ff0000",
position: "bottom-outer",
attribute: "heat",
indentLeft: 30,
indentRight: 0,
shareHeight: true,
otherVisibility: CONST.TOKEN_DISPLAY_MODES.HOVER,
ownerVisibility: CONST.TOKEN_DISPLAY_MODES.INHERIT,
gmVisibility: CONST.TOKEN_DISPLAY_MODES.INHERIT,
style: "fraction",
label: "",
invert: false,
subdivisions: null,
subdivisionsOwner: false,
fgImage: "",
bgImage: "",
},
burn: {
id: "burn",
mincolor: "#992222",
maxcolor: "#992222",
position: "top-outer",
attribute: "burn",
otherVisibility: CONST.TOKEN_DISPLAY_MODES.ALWAYS,
ownerVisibility: CONST.TOKEN_DISPLAY_MODES.INHERIT
},
overshield: {
id: "overshield",
mincolor: "#222299",
maxcolor: "#222299",
position: "top-outer",
attribute: "overshield.value",
otherVisibility: CONST.TOKEN_DISPLAY_MODES.ALWAYS,
ownerVisibility: CONST.TOKEN_DISPLAY_MODES.INHERIT
}
};
const barConfig = game.settings.get("barbrawl", "defaultTypeResources") ?? {};
barConfig['mech'] = bars;
barConfig['npc'] = bars;
barConfig['pilot'] = bars;
barConfig['deployable'] = bars;
await game.settings.set("barbrawl", "defaultTypeResources", bars);
// :warning: Reset all actors' prototype token bars
await Promise.all(game.actors.map(a => {
// Get existing flags to preserve them
const existingFlags = a.flags || {};
return a.update({
"flags.barbrawl.resourceBars": bars,
flags: {
...existingFlags, // Merge existing flags
barbrawl: {
...existingFlags.barbrawl,
resourceBars: bars
}
}
}, { 'diff': false, 'recursive': false });
}));
// Reset the bars on all existing tokens
await Promise.all(
game.scenes.map(s => {
const updates = s.tokens.filter(t => t.actor).map(t => {
return {
_id: t.id,
"flags.barbrawl.resourceBars": bars,
flags: {
...t.flags, // Preserve existing token flags
barbrawl: {
...t.flags?.barbrawl,
resourceBars: bars
}
}
};
});
return s.updateEmbeddedDocuments("Token", updates, { 'diff': false, 'recursive': false });
})
);
ui.notifications.info("Done");