-
Notifications
You must be signed in to change notification settings - Fork 232
/
dnd5e.mjs
630 lines (554 loc) · 23.1 KB
/
dnd5e.mjs
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
/**
* The D&D fifth edition game system for Foundry Virtual Tabletop
* A system for playing the fifth edition of the world's most popular role-playing game.
* Author: Atropos
* Software License: MIT
* Content License: https://www.dndbeyond.com/attachments/39j2li89/SRD5.1-CCBY4.0License.pdf
* Repository: https://github.com/foundryvtt/dnd5e
* Issue Tracker: https://github.com/foundryvtt/dnd5e/issues
*/
// Import Configuration
import DND5E from "./module/config.mjs";
import { registerSystemKeybindings, registerSystemSettings, registerDeferredSettings } from "./module/settings.mjs";
// Import Submodules
import * as applications from "./module/applications/_module.mjs";
import * as canvas from "./module/canvas/_module.mjs";
import * as dataModels from "./module/data/_module.mjs";
import * as dice from "./module/dice/_module.mjs";
import * as documents from "./module/documents/_module.mjs";
import * as enrichers from "./module/enrichers.mjs";
import * as Filter from "./module/filter.mjs";
import * as migrations from "./module/migration.mjs";
import {default as registry} from "./module/registry.mjs";
import * as utils from "./module/utils.mjs";
import {ModuleArt} from "./module/module-art.mjs";
import registerModuleData from "./module/module-registration.mjs";
import Tooltips5e from "./module/tooltips.mjs";
/* -------------------------------------------- */
/* Define Module Structure */
/* -------------------------------------------- */
globalThis.dnd5e = {
applications,
canvas,
config: DND5E,
dataModels,
dice,
documents,
enrichers,
Filter,
migrations,
registry,
utils
};
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("init", function() {
globalThis.dnd5e = game.dnd5e = Object.assign(game.system, globalThis.dnd5e);
console.log(`D&D 5e | Initializing the D&D Fifth Game System - Version ${dnd5e.version}\n${DND5E.ASCII}`);
// Record Configuration Values
CONFIG.DND5E = DND5E;
CONFIG.ActiveEffect.documentClass = documents.ActiveEffect5e;
CONFIG.ActiveEffect.legacyTransferral = false;
CONFIG.Actor.documentClass = documents.Actor5e;
CONFIG.ChatMessage.documentClass = documents.ChatMessage5e;
CONFIG.Combat.documentClass = documents.Combat5e;
CONFIG.Combatant.documentClass = documents.Combatant5e;
CONFIG.Item.collection = dataModels.collection.Items5e;
CONFIG.Item.compendiumIndexFields.push("system.container");
CONFIG.Item.documentClass = documents.Item5e;
CONFIG.Token.documentClass = documents.TokenDocument5e;
CONFIG.Token.objectClass = canvas.Token5e;
CONFIG.User.documentClass = documents.User5e;
CONFIG.time.roundTime = 6;
Roll.TOOLTIP_TEMPLATE = "systems/dnd5e/templates/chat/roll-breakdown.hbs";
CONFIG.Dice.BasicRoll = dice.BasicRoll;
CONFIG.Dice.DamageRoll = dice.DamageRoll;
CONFIG.Dice.D20Die = dice.D20Die;
CONFIG.Dice.D20Roll = dice.D20Roll;
CONFIG.MeasuredTemplate.defaults.angle = 53.13; // 5e cone RAW should be 53.13 degrees
CONFIG.Note.objectClass = canvas.Note5e;
CONFIG.ui.combat = applications.combat.CombatTracker5e;
CONFIG.ui.items = dnd5e.applications.item.ItemDirectory5e;
// Register System Settings
registerSystemSettings();
registerSystemKeybindings();
// Configure module art & register module data
game.dnd5e.moduleArt = new ModuleArt();
registerModuleData();
// Configure bastions
game.dnd5e.bastion = new documents.Bastion();
// Configure tooltips
game.dnd5e.tooltips = new Tooltips5e();
// Set up status effects
_configureStatusEffects();
// Remove honor & sanity from configuration if they aren't enabled
if ( !game.settings.get("dnd5e", "honorScore") ) delete DND5E.abilities.hon;
if ( !game.settings.get("dnd5e", "sanityScore") ) delete DND5E.abilities.san;
// Legacy rules.
if ( game.settings.get("dnd5e", "rulesVersion") === "legacy" ) {
// Set half-casters to round down.
delete DND5E.spellcastingTypes.leveled.progression.half.roundUp;
// Adjust Wild Shape and Polymorph presets.
delete DND5E.transformationPresets.wildshape.options.keepHP;
delete DND5E.transformationPresets.wildshape.options.keepType;
delete DND5E.transformationPresets.polymorph.options.addTemp;
delete DND5E.transformationPresets.polymorph.options.keepHP;
delete DND5E.transformationPresets.polymorph.options.keepType;
// Adjust language categories.
delete DND5E.languages.standard.children.sign;
DND5E.languages.exotic.children.draconic = DND5E.languages.standard.children.draconic;
delete DND5E.languages.standard.children.draconic;
DND5E.languages.cant = DND5E.languages.exotic.children.cant;
delete DND5E.languages.exotic.children.cant;
DND5E.languages.druidic = DND5E.languages.exotic.children.druidic;
delete DND5E.languages.exotic.children.druidic;
// Stunned stops movement in legacy.
DND5E.conditionEffects.noMovement.add("stunned");
}
// Register Roll Extensions
CONFIG.Dice.rolls = [dice.BasicRoll, dice.D20Roll, dice.DamageRoll];
// Hook up system data types
CONFIG.ActiveEffect.dataModels = dataModels.activeEffect.config;
CONFIG.Actor.dataModels = dataModels.actor.config;
CONFIG.Item.dataModels = dataModels.item.config;
CONFIG.JournalEntryPage.dataModels = dataModels.journal.config;
// Add fonts
_configureFonts();
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("dnd5e", applications.actor.ActorSheet5eCharacter, {
types: ["character"],
label: "DND5E.SheetClassCharacterLegacy"
});
DocumentSheetConfig.registerSheet(Actor, "dnd5e", applications.actor.ActorSheet5eCharacter2, {
types: ["character"],
makeDefault: true,
label: "DND5E.SheetClassCharacter"
});
Actors.registerSheet("dnd5e", applications.actor.ActorSheet5eNPC, {
types: ["npc"],
label: "DND5E.SheetClassNPCLegacy"
});
DocumentSheetConfig.registerSheet(Actor, "dnd5e", applications.actor.ActorSheet5eNPC2, {
types: ["npc"],
makeDefault: true,
label: "DND5E.SheetClassNPC"
});
Actors.registerSheet("dnd5e", applications.actor.ActorSheet5eVehicle, {
types: ["vehicle"],
makeDefault: true,
label: "DND5E.SheetClassVehicle"
});
Actors.registerSheet("dnd5e", applications.actor.GroupActorSheet, {
types: ["group"],
makeDefault: true,
label: "DND5E.SheetClassGroup"
});
DocumentSheetConfig.unregisterSheet(Item, "core", ItemSheet);
DocumentSheetConfig.registerSheet(Item, "dnd5e", applications.item.ItemSheet5e2, {
makeDefault: true,
label: "DND5E.SheetClassItem"
});
DocumentSheetConfig.unregisterSheet(Item, "dnd5e", applications.item.ItemSheet5e, { types: ["container"] });
DocumentSheetConfig.unregisterSheet(Item, "dnd5e", applications.item.ItemSheet5e2, { types: ["container"] });
DocumentSheetConfig.registerSheet(Item, "dnd5e", applications.item.ContainerSheet2, {
makeDefault: true,
types: ["container"],
label: "DND5E.SheetClassContainer"
});
DocumentSheetConfig.registerSheet(JournalEntry, "dnd5e", applications.journal.JournalSheet5e, {
makeDefault: true,
label: "DND5E.SheetClassJournalEntry"
});
DocumentSheetConfig.registerSheet(JournalEntryPage, "dnd5e", applications.journal.JournalClassPageSheet, {
label: "DND5E.SheetClassClassSummary",
types: ["class", "subclass"]
});
DocumentSheetConfig.registerSheet(JournalEntryPage, "dnd5e", applications.journal.JournalMapLocationPageSheet, {
label: "DND5E.SheetClassMapLocation",
types: ["map"]
});
DocumentSheetConfig.registerSheet(JournalEntryPage, "dnd5e", applications.journal.JournalRulePageSheet, {
label: "DND5E.SheetClassRule",
types: ["rule"]
});
DocumentSheetConfig.registerSheet(JournalEntryPage, "dnd5e", applications.journal.JournalSpellListPageSheet, {
label: "DND5E.SheetClassSpellList",
types: ["spells"]
});
if ( game.release.generation === 12 ) {
// TODO: Update sheet classes and remove the above check
CONFIG.Token.prototypeSheetClass = applications.TokenConfig5e;
DocumentSheetConfig.unregisterSheet(TokenDocument, "core", TokenConfig);
DocumentSheetConfig.registerSheet(TokenDocument, "dnd5e", applications.TokenConfig5e, {
label: "DND5E.SheetClassToken"
});
}
// Preload Handlebars helpers & partials
utils.registerHandlebarsHelpers();
utils.preloadHandlebarsTemplates();
// Enrichers
enrichers.registerCustomEnrichers();
// Exhaustion handling
documents.ActiveEffect5e.registerHUDListeners();
});
/* -------------------------------------------- */
/**
* Configure explicit lists of attributes that are trackable on the token HUD and in the combat tracker.
* @internal
*/
function _configureTrackableAttributes() {
const common = {
bar: [],
value: [
...Object.keys(DND5E.abilities).map(ability => `abilities.${ability}.value`),
...Object.keys(DND5E.movementTypes).map(movement => `attributes.movement.${movement}`),
"attributes.ac.value", "attributes.init.total"
]
};
const altSpells = Object.entries(DND5E.spellPreparationModes).reduce((acc, [k, v]) => {
if ( !["prepared", "always"].includes(k) && v.upcast ) acc.push(`spells.${k}`);
return acc;
}, []);
const creature = {
bar: [
...common.bar,
"attributes.hp",
...altSpells,
...Array.fromRange(Object.keys(DND5E.spellLevels).length - 1, 1).map(l => `spells.spell${l}`)
],
value: [
...common.value,
...Object.keys(DND5E.skills).map(skill => `skills.${skill}.passive`),
...Object.keys(DND5E.senses).map(sense => `attributes.senses.${sense}`),
"attributes.spelldc"
]
};
CONFIG.Actor.trackableAttributes = {
character: {
bar: [...creature.bar, "resources.primary", "resources.secondary", "resources.tertiary", "details.xp"],
value: [...creature.value]
},
npc: {
bar: [...creature.bar, "resources.legact", "resources.legres"],
value: [...creature.value, "details.cr", "details.spellLevel", "details.xp.value"]
},
vehicle: {
bar: [...common.bar, "attributes.hp"],
value: [...common.value]
},
group: {
bar: [],
value: []
}
};
}
/* -------------------------------------------- */
/**
* Configure which attributes are available for item consumption.
* @internal
*/
function _configureConsumableAttributes() {
const altSpells = Object.entries(DND5E.spellPreparationModes).reduce((acc, [k, v]) => {
if ( !["prepared", "always"].includes(k) && v.upcast ) acc.push(`spells.${k}.value`);
return acc;
}, []);
CONFIG.DND5E.consumableResources = [
...Object.keys(DND5E.abilities).map(ability => `abilities.${ability}.value`),
"attributes.ac.flat",
"attributes.hp.value",
"attributes.exhaustion",
...Object.keys(DND5E.senses).map(sense => `attributes.senses.${sense}`),
...Object.keys(DND5E.movementTypes).map(type => `attributes.movement.${type}`),
...Object.keys(DND5E.currencies).map(denom => `currency.${denom}`),
"details.xp.value",
"resources.primary.value", "resources.secondary.value", "resources.tertiary.value",
"resources.legact.value", "resources.legres.value",
...altSpells,
...Array.fromRange(Object.keys(DND5E.spellLevels).length - 1, 1).map(level => `spells.spell${level}.value`)
];
}
/* -------------------------------------------- */
/**
* Configure additional system fonts.
*/
function _configureFonts() {
Object.assign(CONFIG.fontDefinitions, {
Roboto: {
editor: true,
fonts: [
{ urls: ["systems/dnd5e/fonts/roboto/Roboto-Regular.woff2"] },
{ urls: ["systems/dnd5e/fonts/roboto/Roboto-Bold.woff2"], weight: "bold" },
{ urls: ["systems/dnd5e/fonts/roboto/Roboto-Italic.woff2"], style: "italic" },
{ urls: ["systems/dnd5e/fonts/roboto/Roboto-BoldItalic.woff2"], weight: "bold", style: "italic" }
]
},
"Roboto Condensed": {
editor: true,
fonts: [
{ urls: ["systems/dnd5e/fonts/roboto-condensed/RobotoCondensed-Regular.woff2"] },
{ urls: ["systems/dnd5e/fonts/roboto-condensed/RobotoCondensed-Bold.woff2"], weight: "bold" },
{ urls: ["systems/dnd5e/fonts/roboto-condensed/RobotoCondensed-Italic.woff2"], style: "italic" },
{
urls: ["systems/dnd5e/fonts/roboto-condensed/RobotoCondensed-BoldItalic.woff2"], weight: "bold",
style: "italic"
}
]
},
"Roboto Slab": {
editor: true,
fonts: [
{ urls: ["systems/dnd5e/fonts/roboto-slab/RobotoSlab-Regular.ttf"] },
{ urls: ["systems/dnd5e/fonts/roboto-slab/RobotoSlab-Bold.ttf"], weight: "bold" }
]
}
});
}
/* -------------------------------------------- */
/**
* Configure system status effects.
*/
function _configureStatusEffects() {
const addEffect = (effects, {special, ...data}) => {
data = foundry.utils.deepClone(data);
data._id = utils.staticID(`dnd5e${data.id}`);
data.img = data.icon ?? data.img;
delete data.icon;
effects.push(data);
if ( special ) CONFIG.specialStatusEffects[special] = data.id;
};
CONFIG.statusEffects = Object.entries(CONFIG.DND5E.statusEffects).reduce((arr, [id, data]) => {
const original = CONFIG.statusEffects.find(s => s.id === id);
addEffect(arr, foundry.utils.mergeObject(original ?? {}, { id, ...data }, { inplace: false }));
return arr;
}, []);
for ( const [id, {label: name, ...data}] of Object.entries(CONFIG.DND5E.conditionTypes) ) {
addEffect(CONFIG.statusEffects, { id, name, ...data });
}
for ( const [id, data] of Object.entries(CONFIG.DND5E.encumbrance.effects) ) {
addEffect(CONFIG.statusEffects, { id, ...data, hud: false });
}
}
/* -------------------------------------------- */
/* Foundry VTT Setup */
/* -------------------------------------------- */
/**
* Prepare attribute lists.
*/
Hooks.once("setup", function() {
// Configure trackable & consumable attributes.
_configureTrackableAttributes();
_configureConsumableAttributes();
CONFIG.DND5E.trackableAttributes = expandAttributeList(CONFIG.DND5E.trackableAttributes);
game.dnd5e.moduleArt.registerModuleArt();
Tooltips5e.activateListeners();
game.dnd5e.tooltips.observe();
// Register settings after modules have had a chance to initialize
registerDeferredSettings();
// Apply table of contents compendium style if specified in flags
game.packs
.filter(p => p.metadata.flags?.display === "table-of-contents")
.forEach(p => p.applicationClass = applications.journal.TableOfContentsCompendium);
// Apply custom item compendium
game.packs.filter(p => p.metadata.type === "Item")
.forEach(p => p.applicationClass = applications.item.ItemCompendium5e);
// Create CSS for currencies
const style = document.createElement("style");
const currencies = append => Object.entries(CONFIG.DND5E.currencies)
.map(([key, { icon }]) => `&.${key}${append ?? ""} { background-image: url("${icon}"); }`);
style.innerHTML = `
:is(.dnd5e2, .dnd5e2-journal) :is(i, span).currency {
${currencies().join("\n")}
}
.dnd5e2 .form-group label.label-icon.currency {
${currencies("::after").join("\n")}
}
`;
document.head.append(style);
});
/* --------------------------------------------- */
/**
* Expand a list of attribute paths into an object that can be traversed.
* @param {string[]} attributes The initial attributes configuration.
* @returns {object} The expanded object structure.
*/
function expandAttributeList(attributes) {
return attributes.reduce((obj, attr) => {
foundry.utils.setProperty(obj, attr, true);
return obj;
}, {});
}
/* --------------------------------------------- */
/**
* Perform one-time pre-localization and sorting of some configuration objects
*/
Hooks.once("i18nInit", () => {
if ( game.settings.get("dnd5e", "rulesVersion") === "legacy" ) {
const { translations, _fallback } = game.i18n;
foundry.utils.mergeObject(translations, {
"TYPES.Item": {
race: game.i18n.localize("TYPES.Item.raceLegacy"),
racePl: game.i18n.localize("TYPES.Item.raceLegacyPl")
},
DND5E: {
"Feature.Species": game.i18n.localize("DND5E.Feature.SpeciesLegacy"),
FlagsAlertHint: game.i18n.localize("DND5E.FlagsAlertHintLegacy"),
LanguagesExotic: game.i18n.localize("DND5E.LanguagesExoticLegacy"),
LongRestHint: game.i18n.localize("DND5E.LongRestHintLegacy"),
LongRestHintGroup: game.i18n.localize("DND5E.LongRestHintGroupLegacy"),
"TARGET.Type.Emanation": foundry.utils.mergeObject(
_fallback.DND5E?.TARGET?.Type?.Radius ?? {},
translations.DND5E?.TARGET?.Type?.Radius ?? {},
{ inplace: false }
),
TraitArmorPlural: foundry.utils.mergeObject(
_fallback.DND5E?.TraitArmorLegacyPlural ?? {},
translations.DND5E?.TraitArmorLegacyPlural ?? {},
{ inplace: false }
),
TraitArmorProf: game.i18n.localize("DND5E.TraitArmorLegacyProf")
}
});
}
utils.performPreLocalization(CONFIG.DND5E);
Object.values(CONFIG.DND5E.activityTypes).forEach(c => c.documentClass.localize());
});
/* -------------------------------------------- */
/* Foundry VTT Ready */
/* -------------------------------------------- */
/**
* Once the entire VTT framework is initialized, check to see if we should perform a data migration
*/
Hooks.once("ready", function() {
// Wait to register hotbar drop hook on ready so that modules could register earlier if they want to
Hooks.on("hotbarDrop", (bar, data, slot) => {
if ( ["Item", "ActiveEffect"].includes(data.type) ) {
documents.macro.create5eMacro(data, slot);
return false;
}
});
// Register items by type
dnd5e.registry.classes.initialize();
// Chat message listeners
documents.ChatMessage5e.activateListeners();
// Bastion initialization
game.dnd5e.bastion.initializeUI();
// Determine whether a system migration is required and feasible
if ( !game.user.isGM ) return;
const cv = game.settings.get("dnd5e", "systemMigrationVersion") || game.world.flags.dnd5e?.version;
const totalDocuments = game.actors.size + game.scenes.size + game.items.size;
if ( !cv && totalDocuments === 0 ) return game.settings.set("dnd5e", "systemMigrationVersion", game.system.version);
if ( cv && !foundry.utils.isNewerVersion(game.system.flags.needsMigrationVersion, cv) ) return;
// Compendium pack folder migration.
if ( foundry.utils.isNewerVersion("3.0.0", cv) ) {
migrations.reparentCompendiums("DnD5e SRD Content", "D&D SRD Content");
}
// Perform the migration
if ( cv && foundry.utils.isNewerVersion(game.system.flags.compatibleMigrationVersion, cv) ) {
ui.notifications.error("MIGRATION.5eVersionTooOldWarning", {localize: true, permanent: true});
}
migrations.migrateWorld();
});
/* -------------------------------------------- */
/* System Styling */
/* -------------------------------------------- */
Hooks.on("renderPause", (app, [html]) => {
html.classList.add("dnd5e2");
const img = html.querySelector("img");
img.src = "systems/dnd5e/ui/official/ampersand.svg";
img.className = "";
});
Hooks.on("renderSettings", (app, [html]) => {
const details = html.querySelector("#game-details");
const pip = details.querySelector(".system-info .update");
details.querySelector(".system").remove();
const heading = document.createElement("div");
heading.classList.add("dnd5e2", "sidebar-heading");
heading.innerHTML = `
<h2>${game.i18n.localize("WORLD.GameSystem")}</h2>
<ul class="links">
<li>
<a href="https://github.com/foundryvtt/dnd5e/releases/latest" target="_blank">
${game.i18n.localize("DND5E.Notes")}
</a>
</li>
<li>
<a href="https://github.com/foundryvtt/dnd5e/issues" target="_blank">${game.i18n.localize("DND5E.Issues")}</a>
</li>
<li>
<a href="https://github.com/foundryvtt/dnd5e/wiki" target="_blank">${game.i18n.localize("DND5E.Wiki")}</a>
</li>
<li>
<a href="https://discord.com/channels/170995199584108546/670336046164213761" target="_blank">
${game.i18n.localize("DND5E.Discord")}
</a>
</li>
</ul>
`;
details.insertAdjacentElement("afterend", heading);
const badge = document.createElement("div");
badge.classList.add("dnd5e2", "system-badge");
badge.innerHTML = `
<img src="systems/dnd5e/ui/official/dnd-badge-32.webp" data-tooltip="${dnd5e.title}" alt="${dnd5e.title}">
<span class="system-info">${dnd5e.version}</span>
`;
if ( pip ) badge.querySelector(".system-info").insertAdjacentElement("beforeend", pip);
heading.insertAdjacentElement("afterend", badge);
});
/* -------------------------------------------- */
/* Other Hooks */
/* -------------------------------------------- */
Hooks.on("renderChatPopout", documents.ChatMessage5e.onRenderChatPopout);
Hooks.on("getChatLogEntryContext", documents.ChatMessage5e.addChatMessageContextOptions);
Hooks.on("renderChatLog", (app, html, data) => {
documents.Item5e.chatListeners(html);
documents.ChatMessage5e.onRenderChatLog(html);
});
Hooks.on("renderChatPopout", (app, html, data) => documents.Item5e.chatListeners(html));
Hooks.on("chatMessage", (app, message, data) => applications.Award.chatMessage(message));
Hooks.on("renderActorDirectory", (app, html, data) => documents.Actor5e.onRenderActorDirectory(html));
Hooks.on("getActorDirectoryEntryContext", documents.Actor5e.addDirectoryContextOptions);
Hooks.on("renderCompendiumDirectory", (app, [html], data) => applications.CompendiumBrowser.injectSidebarButton(html));
Hooks.on("getCompendiumEntryContext", documents.Item5e.addCompendiumContextOptions);
Hooks.on("getItemDirectoryEntryContext", documents.Item5e.addDirectoryContextOptions);
Hooks.on("renderJournalPageSheet", applications.journal.JournalSheet5e.onRenderJournalPageSheet);
Hooks.on("targetToken", canvas.Token5e.onTargetToken);
Hooks.on("preCreateScene", (doc, createData, options, userId) => {
// Set default grid units based on metric length setting
const units = utils.defaultUnits("length");
if ( (units !== dnd5e.grid.units) && !foundry.utils.getProperty(createData, "grid.distance")
&& !foundry.utils.getProperty(createData, "grid.units") ) {
const C = CONFIG.DND5E.movementUnits;
doc.updateSource({
grid: {
// TODO: Replace with `convertLength` method once added
distance: dnd5e.grid.distance * (C[dnd5e.grid.units]?.conversion ?? 1) / (C[units]?.conversion ?? 1), units
}
});
}
});
// TODO: Generalize this logic and make it available in the re-designed transform application.
Hooks.on("dnd5e.transformActor", (subject, target, d, options) => {
const isLegacy = game.settings.get("dnd5e", "rulesVersion") === "legacy";
if ( (options.preset !== "wildshape") || !subject.classes?.druid || isLegacy ) return;
let temp = subject.classes.druid.system.levels;
if ( subject.classes.druid.subclass?.identifier === "moon" ) temp *= 3;
d.system.attributes.hp.temp = temp;
});
/* -------------------------------------------- */
/* Bundled Module Exports */
/* -------------------------------------------- */
export {
applications,
canvas,
dataModels,
dice,
documents,
enrichers,
Filter,
migrations,
registry,
utils,
DND5E
};