-
Notifications
You must be signed in to change notification settings - Fork 20
/
wwn.js
143 lines (123 loc) · 4.74 KB
/
wwn.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
// Import Modules
import { WwnItemSheet } from "./module/item/item-sheet.js";
import { WwnActorSheetCharacter } from "./module/actor/character-sheet.js";
import { WwnActorSheetMonster } from "./module/actor/monster-sheet.js";
import { WwnActorSheetFaction } from "./module/actor/faction-sheet.js";
import { preloadHandlebarsTemplates } from "./module/preloadTemplates.js";
import { WwnActor } from "./module/actor/entity.js";
import { WwnItem } from "./module/item/entity.js";
import { WWN } from "./module/config.js";
import { registerSettings } from "./module/settings.js";
import { registerHelpers } from "./module/helpers.js";
import * as chat from "./module/chat.js";
import * as treasure from "./module/treasure.js";
import * as macros from "./module/macros.js";
import * as party from "./module/party.js";
import { WwnCombat } from "./module/combat.js";
import * as migrations from "./module/migration.js";
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks.once("init", async function () {
/**
* Set an initiative formula for the system
* @type {String}
*/
CONFIG.Combat.initiative = {
formula: "1d8 + @initiative.value",
decimals: 2,
};
CONFIG.WWN = WWN;
game.wwn = {
rollItemMacro: macros.rollItemMacro,
};
// Custom Handlebars helpers
registerHelpers();
// Register custom system settings
registerSettings();
CONFIG.Actor.documentClass = WwnActor;
CONFIG.Item.documentClass = WwnItem;
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("wwn", WwnActorSheetCharacter, {
types: ["character"],
makeDefault: true,
label: "WWN.SheetClassCharacter"
});
Actors.registerSheet("wwn", WwnActorSheetMonster, {
types: ["monster"],
makeDefault: true,
label: "WWN.SheetClassMonster"
});
Actors.registerSheet("wwn", WwnActorSheetFaction, {
types: ["faction"],
makeDefault: true,
label: "WWN.SheetClassFaction"
});
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("wwn", WwnItemSheet, {
makeDefault: true,
label: "WWN.SheetClassItem"
});
await preloadHandlebarsTemplates();
});
/**
* This function runs after game data has been requested and loaded from the servers, so entities exist
*/
Hooks.once("setup", function () {
// Localize CONFIG objects once up-front
const toLocalize = ["saves", "scores", "armor", "weightless", "colors", "tags", "skills", "encumbLocation", "assetTypes", "assetMagic"];
for (let o of toLocalize) {
CONFIG.WWN[o] = Object.entries(CONFIG.WWN[o]).reduce((obj, e) => {
obj[e[0]] = game.i18n.localize(e[1]);
return obj;
}, {});
}
});
Hooks.once("ready", async () => {
Hooks.on("hotbarDrop", (bar, data, slot) =>
macros.createWwnMacro(data, slot)
);
// Check migration
if (!game.user.isGM) return;
const currentVersion = game.settings.get("wwn", "systemMigrationVersion");
const NEEDS_MIGRATION_VERSION = "1.1.2";
const totalDocuments = game.actors.size + game.scenes.size + game.items.size;
if (!currentVersion && totalDocuments === 0) return game.settings.set("wwn", "systemMigrationVersion", game.system.version);
const needsMigration = foundry.utils.isNewerVersion(NEEDS_MIGRATION_VERSION, currentVersion);
if (needsMigration) {
migrations.migrateWorld();
}
});
// License and KOFI infos
Hooks.on("renderSidebarTab", async (object, html) => {
if (object instanceof ActorDirectory) {
party.addControl(object, html);
}
if (object instanceof Settings) {
let gamesystem = html.find("#game-details");
// SRD Link
let wwn = gamesystem.find('h4').last();
wwn.append(` <sub><a href="https://oldschoolessentials.necroticgnome.com/srd/index.php">SRD<a></sub>`);
// License text
const template = "systems/wwn/templates/chat/license.html";
const rendered = await renderTemplate(template);
gamesystem.find(".system").append(rendered);
}
});
Hooks.on("preCreateCombatant", (combat, data, options, id) => {
let init = game.settings.get("wwn", "initiative");
if (init === "group") {
WwnCombat.addCombatant(combat, data, options, id);
}
});
Hooks.on("updateCombatant", WwnCombat.updateCombatant);
Hooks.on("renderCombatTracker", WwnCombat.format);
Hooks.on("preUpdateCombat", WwnCombat.preUpdateCombat);
Hooks.on("getCombatTrackerEntryContext", WwnCombat.addContextEntry);
Hooks.on("preCreateToken", WwnCombat.preCreateToken);
Hooks.on("renderChatLog", (app, html, data) => WwnItem.chatListeners(html));
Hooks.on("getChatLogEntryContext", chat.addChatMessageContextOptions);
Hooks.on("renderChatMessage", chat.addChatMessageButtons);
Hooks.on("renderRollTableConfig", treasure.augmentTable);
Hooks.on("updateActor", party.update);