-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
gmm.js
200 lines (177 loc) · 6.09 KB
/
gmm.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import GmmActor from './scripts/classes/GmmActor.js';
import GmmItem from './scripts/classes/GmmItem.js';
import MonsterSheet from './scripts/classes/MonsterSheet.js';
import ActionSheet from './scripts/classes/ActionSheet.js';
import Templates from './scripts/classes/Templates.js';
import { GMM_GUI_SKINS } from "./scripts/consts/GmmGuiSkins.js";
import { GMM_GUI_COLORS } from "./scripts/consts/GmmGuiColors.js";
import { GMM_GUI_LAYOUTS } from "./scripts/consts/GmmGuiLayouts.js";
import { GMM_MODULE_TITLE } from "./scripts/consts/GmmModuleTitle.js";
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("init", function() {
console.log(`Giffyglyph's 5e Monster Maker | Initialising`);
Actors.registerSheet(GMM_MODULE_TITLE, MonsterSheet, {
types: ["npc"],
label: "gmm.sheet.monster.label"
});
Items.registerSheet(GMM_MODULE_TITLE, ActionSheet, {
label: "gmm.sheet.action.label"
});
Templates.preloadTemplates();
Templates.registerTemplateHelpers();
GmmActor.patchActor5e();
GmmItem.patchItem5e();
// Reprepare actor/item data when the default sheet is changed
Hooks.on("updateSetting", (setting, data, options, userId) => {
if ( setting.key === "core.sheetClasses" ) {
game.actors.forEach(x => x.prepareData());
game.items.forEach(x => x.prepareData());
game.scenes.forEach(x => x.tokens.forEach(y => y.actor.prepareData()));
}
});
Hooks.on("renderActorDirectory", (app, html, data) => {
if (game.user.isGM) {
_hookActorDirectory(html);
}
});
Hooks.on("renderItemDirectory", (app, html, data) => {
if (game.user.isGM) {
_hookItemDirectory(html);
}
});
_registerSettings();
console.log(`Giffyglyph's 5e Monster Maker | Initialised`);
});
async function _hookActorDirectory(html) {
let section = document.createElement("div");
section.classList.add("header-actions", "action-buttons", "flexrow", "giffyglyph");
section.insertAdjacentHTML(
"afterbegin",
`
<div class="btn-group">
<button data-action="create-scaling-monster"><i class="fas fa-skull"></i> ${game.i18n.format('gmm.sidebar.create_monster')}</button>
</div>
`
);
section.querySelector("[data-action='create-scaling-monster']").addEventListener("click", (ev) => {
Actor.create({
name: "New Scaling Monster",
type: "npc",
img: "icons/svg/eye.svg",
flags: { "core.sheetClass": `${GMM_MODULE_TITLE}.MonsterSheet` },
data: {
"details.alignment": "unaligned",
"details.type.value": "humanoid",
"details.xp.value": 50
},
});
});
const dirHeader = html[0].querySelector(".directory-header .header-search");
dirHeader.parentNode.insertBefore(section, dirHeader);
}
async function _hookItemDirectory(html) {
let section = document.createElement("div");
section.classList.add("header-actions", "action-buttons", "flexrow", "giffyglyph");
section.insertAdjacentHTML(
"afterbegin",
`
<div class="btn-group">
<button data-action="create-scaling-action"><i class="fas fa-skull"></i> ${game.i18n.format('gmm.sidebar.create_action')}</button>
</div>
`
);
section.querySelector("[data-action='create-scaling-action']").addEventListener("click", (ev) => {
Item.create({
name: "New Scaling Action",
type: "feat",
img: "icons/svg/clockwork.svg",
flags: { "core.sheetClass": `${GMM_MODULE_TITLE}.ActionSheet` }
});
});
const dirHeader = html[0].querySelector(".directory-header .header-search");
dirHeader.parentNode.insertBefore(section, dirHeader);
}
function _registerSettings() {
game.settings.register(GMM_MODULE_TITLE, "monsterLayout", {
name: "Monster Menu Layout",
scope: "world",
config: true,
default: "slide-out",
type: String,
choices: Object.fromEntries(GMM_GUI_LAYOUTS.monster.map((x) => [ x.code, x.name]))
});
game.settings.register(GMM_MODULE_TITLE, "monsterArtifactSkin", {
name: "Monster Artifact Skin",
scope: "world",
config: true,
default: "vanity",
type: String,
choices: Object.fromEntries(GMM_GUI_SKINS.monster.artifact.map((x) => [ x.code, x.name]))
});
game.settings.register(GMM_MODULE_TITLE, "monsterBlueprintSkin", {
name: "Monster Blueprint Skin",
scope: "world",
config: true,
default: "vanity",
type: String,
choices: Object.fromEntries(GMM_GUI_SKINS.monster.blueprint.map((x) => [ x.code, x.name]))
});
game.settings.register(GMM_MODULE_TITLE, "monsterPrimaryColor", {
name: "Monster Primary Color",
scope: "world",
config: true,
default: "blue",
type: String,
choices: Object.fromEntries(GMM_GUI_COLORS.map((x) => [ x.code, x.name]))
});
game.settings.register(GMM_MODULE_TITLE, "monsterSecondaryColor", {
name: "Monster Secondary Color",
scope: "world",
config: true,
default: "orange",
type: String,
choices: Object.fromEntries(GMM_GUI_COLORS.map((x) => [ x.code, x.name]))
});
game.settings.register(GMM_MODULE_TITLE, "actionLayout", {
name: "Action Menu Layout",
scope: "world",
config: true,
default: "slide-out",
type: String,
choices: Object.fromEntries(GMM_GUI_LAYOUTS.action.map((x) => [ x.code, x.name]))
});
game.settings.register(GMM_MODULE_TITLE, "actionArtifactSkin", {
name: "Action Artifact Skin",
scope: "world",
config: true,
default: "vanity",
type: String,
choices: Object.fromEntries(GMM_GUI_SKINS.action.artifact.map((x) => [ x.code, x.name]))
});
game.settings.register(GMM_MODULE_TITLE, "actionBlueprintSkin", {
name: "Action Blueprint Skin",
scope: "world",
config: true,
default: "vanity",
type: String,
choices: Object.fromEntries(GMM_GUI_SKINS.action.blueprint.map((x) => [ x.code, x.name]))
});
game.settings.register(GMM_MODULE_TITLE, "actionPrimaryColor", {
name: "Action Primary Color",
scope: "world",
config: true,
default: "blue-gray",
type: String,
choices: Object.fromEntries(GMM_GUI_COLORS.map((x) => [ x.code, x.name]))
});
game.settings.register(GMM_MODULE_TITLE, "actionSecondaryColor", {
name: "Action Secondary Color",
scope: "world",
config: true,
default: "amber",
type: String,
choices: Object.fromEntries(GMM_GUI_COLORS.map((x) => [ x.code, x.name]))
});
}