-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdraw-steel.mjs
119 lines (104 loc) · 4.69 KB
/
draw-steel.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
import * as documents from "./src/module/documents/_module.mjs";
import * as applications from "./src/module/apps/_module.mjs";
import * as helpers from "./src/module/helpers/_module.mjs";
import * as rolls from "./src/module/rolls/_module.mjs";
import * as data from "./src/module/data/_module.mjs";
import {DRAW_STEEL} from "./src/module/config.mjs";
import * as DS_CONST from "./src/module/constants.mjs";
globalThis.ds = {
documents,
applications,
helpers,
rolls,
data,
CONST: DS_CONST,
CONFIG: DRAW_STEEL
};
Hooks.once("init", function () {
CONFIG.DRAW_STEEL = DRAW_STEEL;
game.system.socketHandler = new helpers.DrawSteelSocketHandler();
helpers.DrawSteelSettingsHandler.registerSettings();
// Assign document classes
for (const docCls of Object.values(documents)) {
if (!foundry.utils.isSubclass(docCls, foundry.abstract.Document)) continue;
CONFIG[docCls.documentName].documentClass = docCls;
}
const templates = ["templates/item/embeds/ability.hbs"].map(t => DS_CONST.systemPath(t));
// Assign data models & setup templates
for (const [doc, models] of Object.entries(data)) {
if (!CONST.ALL_DOCUMENT_TYPES.includes(doc)) continue;
for (const modelCls of Object.values(models)) {
if (modelCls.metadata?.type) CONFIG[doc].dataModels[modelCls.metadata.type] = modelCls;
if (modelCls.metadata?.detailsPartial) templates.push(...modelCls.metadata.detailsPartial);
}
}
loadTemplates(templates);
//Remove Status Effects Not Available in DrawSteel
const toRemove = ["bleeding", "bless", "burrow", "corrode", "curse", "degen", "disease", "upgrade", "fireShield", "fear", "holyShield", "hover", "coldShield", "magicShield", "paralysis", "poison", "prone", "regen", "restrain", "shock", "silence", "stun", "unconscious", "downgrade"];
CONFIG.statusEffects = CONFIG.statusEffects.filter(effect => !toRemove.includes(effect.id));
// Status Effect Transfer
for (const [id, value] of Object.entries(DRAW_STEEL.conditions)) {
CONFIG.statusEffects.push({id, ...value});
}
for (const [id, value] of Object.entries(DS_CONST.staminaEffects)) {
CONFIG.statusEffects.push({id, ...value});
}
// Necessary until foundry makes this default behavior in v13
CONFIG.ActiveEffect.legacyTransferral = false;
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet(DS_CONST.systemID, applications.DrawSteelCharacterSheet, {
types: ["character"],
makeDefault: true,
label: "DRAW_STEEL.Sheet.Labels.Character"
});
Actors.registerSheet(DS_CONST.systemID, applications.DrawSteelNPCSheet, {
types: ["npc"],
makeDefault: true,
label: "DRAW_STEEL.Sheet.Labels.NPC"
});
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet(DS_CONST.systemID, applications.DrawSteelItemSheet, {
makeDefault: true,
label: "DRAW_STEEL.Sheet.Labels.Item"
});
// Register dice rolls
CONFIG.Dice.rolls = [rolls.DSRoll, rolls.PowerRoll, rolls.ProjectRoll, rolls.DamageRoll, rolls.SavingThrowRoll];
});
/**
* Perform one-time pre-localization and sorting of some configuration objects
*/
Hooks.once("i18nInit", () => {
helpers.utils.performPreLocalization(CONFIG.DRAW_STEEL);
// These fields are not auto-localized due to having a different location in en.json
for (const model of Object.values(CONFIG.Actor.dataModels)) {
/** @type {InstanceType<foundry["data"]["fields"]["SchemaField"]>} */
const characteristicSchema = model.schema.getField("characteristics");
if (!characteristicSchema) continue;
for (const [characteristic, {label, hint}] of Object.entries(ds.CONFIG.characteristics)) {
const field = characteristicSchema.getField(`${characteristic}.value`);
if (!field) continue;
field.label = label;
field.hint = hint;
}
}
});
/* -------------------------------------------- */
/* Ready Hook */
/* -------------------------------------------- */
Hooks.once("ready", async function () {
await data.migrations.migrateWorld();
// Wait to register hotbar drop hook on ready so that modules could register earlier if they want to
// Hooks.on("hotbarDrop", (bar, data, slot) => helpers.macros.createDocMacro(data, slot));
Hooks.callAll("ds.ready");
console.log(DS_CONST.ASCII);
});
/**
* Render hooks
*/
Hooks.on("renderActiveEffectConfig", applications.hooks.renderActiveEffectConfig);
Hooks.on("renderChatMessage", applications.hooks.renderChatMessage);
Hooks.on("renderCombatantConfig", applications.hooks.renderCombatantConfig);
Hooks.on("renderCombatTracker", applications.hooks.renderCombatTracker);
Hooks.on("getCombatTrackerEntryContext", applications.hooks.getCombatTrackerEntryContext);
Hooks.on("hotReload", helpers.hotReload);