forked from zeel01/MonsterBlocks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
monsterblock.js
124 lines (103 loc) · 4.06 KB
/
monsterblock.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
import MonsterBlock5e from "./scripts/dnd5e/MonsterBlock5e.js";
import { debug } from "./scripts/utilities.js";
import { inputExprInitHandler } from "./input-expressions/handler.js";
import PopupHandler from "./scripts/PopupHandler.js"
import Flags5e from "./scripts/dnd5e/Flags5e.js";
Hooks.once("init", () => {
Handlebars.registerHelper(MonsterBlock5e.handlebarsHelpers); // Register all the helpers needed for Handlebars
inputExprInitHandler();
console.log(`Monster Block | %cInitialized.`, "color: orange");
});
Hooks.once("ready", () => {
MonsterBlock5e.getQuickInserts();
MonsterBlock5e.preLoadTemplates();
if (debug.INFO) console.debug("Monster Blocks | Registering Settings");
Object.entries(Flags5e.flagDefaults)
.filter(([n, d]) => !d.hidden)
.forEach(([name, details]) =>
game.settings.register(Flags5e.scope, details.setting || name, {
name: game.i18n.localize(`MOBLOKS5E.${name}.settings.name`),
hint: game.i18n.localize(`MOBLOKS5E.${name}.settings.hint`),
scope: "world",
config: true,
type: details.type,
default: details.default
}
)
);
game.settings.register("monsterblock", "max-height-offset", {
name: game.i18n.localize("MOBLOKS5E.max-height-offset.settings.name"),
hint: game.i18n.localize("MOBLOKS5E.max-height-offset.settings.hint"),
scope: "world",
config: true,
type: Number,
range: {
min: 0,
max: 670,
step: 1
},
default: 72
});
let themeChoices = {};
for (let theme in MonsterBlock5e.themes)
themeChoices[theme] =
game.i18n.localize(MonsterBlock5e.themes[theme].name);
game.settings.register("monsterblock", "default-theme", {
name: game.i18n.localize("MOBLOKS5E.default-theme.settings.name"),
hint: game.i18n.localize("MOBLOKS5E.default-theme.settings.hint"),
scope: "world",
config: true,
type: String,
choices: themeChoices,
default: "default"
});
});
// This is how the box sizing is corrected to fit the statblock
// eslint-disable-next-line no-unused-vars
Hooks.on("renderMonsterBlock5e", (monsterblock, html, data) => { // When the sheet is rendered
if (debug.INFO) console.log("Monster Block | Rendering sheet");
if (debug.DEBUG) console.debug(`Monster Block |`, monsterblock, html, data);
if (html.parent().hasClass("grid-cell-content")) return;
if (monsterblock._minimized) return;
let popup = new PopupHandler(
monsterblock, // The Application window
"form.flexcol",
monsterblock.options.width, // From default options
window.innerHeight - game.settings.get("monsterblock", "max-height-offset"), // Configurable offset, default is 72 to give space for the macro bar and 10px of padding.
// (window.innerHeight - game.settings.get("monsterblock", "max-height-offset")) * (1 / monsterblock.flags.scale), // Configurable offset, default is 72 to give space for the macro bar and 10px of padding.
8,
monsterblock.flags.scale // The margins on the window content are 8px
);
popup.fix();
});
Hooks.on("renderActorSheet5eNPC", (sheet) => {
if (sheet.constructor.name != "ActorSheet5eNPC") return;
if (debug.INFO) console.log("Monster Block | Adding cog menu to standard sheet");
let nav = document.createElement("nav");
nav.innerHTML = `
<i class="fas fa-cog"></i>
<ul>
<li>
<a class="trigger" data-control="switchToMonsterBlock">${game.i18n.localize("MOBLOKS5E.SwitchToMobloks")}</a>
</li>
</ul>
`;
nav.classList.add("switches");
sheet.element.find(".window-content .editable").append(nav);
nav.addEventListener("click", async () => {
return await MonsterBlock5e.switchSheetTo("dnd5e.MonsterBlock5e", sheet);
});
});
Actors.registerSheet("dnd5e", MonsterBlock5e, {
types: ["npc"],
makeDefault: false,
label: "MOBLOKS5E.MonsterBlocks"
});
Hooks.on("renderActorSheet", () => { // This is just for debugging, it prevents this sheet's template from being cached.
if (!debug.enabled) return;
window._templateCache = [];
});
Hooks.once("devModeReady", ({ registerPackageDebugFlag }) => {
registerPackageDebugFlag("monsterblock", "level");
if (debug.INFO) console.log(`Monster Block | Debug level: ${debug.level}`);
});