-
Notifications
You must be signed in to change notification settings - Fork 11
/
animabf.mjs
104 lines (81 loc) · 3.13 KB
/
animabf.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
import { registerSettings } from './utils/registerSettings';
import { Logger, preloadTemplates } from './utils';
import ABFActorSheet from './module/actor/ABFActorSheet';
import ABFFoundryRoll from './module/rolls/ABFFoundryRoll';
import ABFCombat from './module/combat/ABFCombat';
import { ABFActor } from './module/actor/ABFActor';
import { registerHelpers } from './utils/handlebars-helpers/registerHelpers';
import ABFItemSheet from './module/items/ABFItemSheet';
import { ABFConfig } from './module/ABFConfig';
import ABFItem from './module/items/ABFItem';
import ABFActorDirectory from './module/SidebarDirectories/ABFActorDirectory';
import { registerCombatWebsocketRoutes } from './module/combat/websocket/registerCombatWebsocketRoutes';
import { attachCustomMacroBar } from './utils/attachCustomMacroBar';
import { applyMigrations } from './module/migration/migrate';
import './scss/animabf.scss';
/* ------------------------------------ */
/* Initialize system */
/* ------------------------------------ */
Hooks.once('init', async () => {
Logger.log('Initializing system');
// Assign custom classes and constants here
CONFIG.Actor.documentClass = ABFActor;
CONFIG.config = ABFConfig;
window.ABFFoundryRoll = ABFFoundryRoll;
CONFIG.Dice.rolls = [ABFFoundryRoll, ...CONFIG.Dice.rolls];
CONFIG.Combat.documentClass = ABFCombat;
CONFIG.Combat.initiative = {
formula: '1d100Initiative',
decimals: 2
};
CONFIG.Item.documentClass = ABFItem;
CONFIG.ui.actors = ABFActorDirectory;
// Register custom sheets (if any)
Actors.unregisterSheet('core', ActorSheet);
Actors.registerSheet('abf', ABFActorSheet, { makeDefault: true });
Items.unregisterSheet('core', ItemSheet);
Items.registerSheet('abf', ABFItemSheet, {
makeDefault: true
});
// Register custom system settings
registerSettings();
registerHelpers();
// Preload Handlebars templates
await preloadTemplates();
});
/* ------------------------------------ */
/* Setup system */
/* ------------------------------------ */
Hooks.once('setup', () => {
// Do anything after initialization but before
// ready
});
/* ------------------------------------ */
/* When ready */
/* ------------------------------------ */
Hooks.once('ready', () => {
registerCombatWebsocketRoutes();
attachCustomMacroBar();
applyMigrations();
});
// Add any additional hooks if necessary
// This function allow us to use xRoot in templates to extract the root object in Handlebars template
// So, instead to do ../../../ etc... to obtain rootFolder, use xRoot instead
// https://handlebarsjs.com/guide/expressions.html#path-expressions
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line func-names
Handlebars.JavaScriptCompiler.prototype.nameLookup = function (parent, name) {
if (name.indexOf('xRoot') === 0) {
return 'data.root';
}
if (/^[0-9]+$/.test(name)) {
return `${parent}[${name}]`;
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
if (Handlebars.JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
return `${parent}.${name}`;
}
return `${parent}['${name}']`;
};