-
Notifications
You must be signed in to change notification settings - Fork 9
/
sgrpg.js
90 lines (65 loc) · 3.08 KB
/
sgrpg.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
import { SGRPG } from "./module/config.js";
import "./module/scene-config.js";
import "./module/externals.js"; // Setup external module integrations here, so sgrpg.js doesn't need to otherwise care
import ItemSg from "./module/item/entity.js"
import ActorSg from "./module/actor/entity.js"
import SGItemSheet from "./module/item/sheet/itemSheet.js";
import SGActorSheet from "./module/actor/sheet/actorSheet.js";
import D20Roll from "./module/dice/d20-roll.js";
import DamageRoll from "./module/dice/damage-roll.js"
import * as chat from "./module/chat.js"
import * as macros from "./module/macros.js"
import { _getInitiativeFormula } from "./module/combat.js";
import { preloadHandlebarsTemplates } from "./module/templates.js";
Hooks.once("init", function(){
console.log("Initializing StarGate systems");
CONFIG.SGRPG = SGRPG;
game.sgrpg = {
config: SGRPG,
rollItemMacro: macros.rollItemMacro,
getTensionDie
};
CONFIG.Item.documentClass = ItemSg;
CONFIG.Actor.documentClass = ActorSg;
// 5e cone RAW should be 53.13 degrees
CONFIG.MeasuredTemplate.defaults.angle = 53.13;
CONFIG.Dice.D20Roll = D20Roll;
CONFIG.Dice.DamageRoll = DamageRoll;
CONFIG.Dice.rolls.push(D20Roll);
CONFIG.Dice.rolls.push(DamageRoll);
CONFIG.Combat.initiative.formula = "1d20 + @initiative";
Combatant.prototype._getInitiativeFormula = _getInitiativeFormula;
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("sgrpg", SGItemSheet, {makeDefault: true});
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("sgrpg", SGActorSheet, { makeDefault: true });
game.settings.register("sgrpg", "campaignTension", {
name: "Campaign Tension Level",
hint: "Set the campaign's base Tension level and the Tension Die.",
scope: "world",
type: String,
choices: SGRPG.tensionDice,
default: SGRPG.defaultTensionDie,
config: true
});
preloadHandlebarsTemplates()
});
Hooks.once("ready", function() {
console.log("Registering StarGate systems");
// Wait to register hotbar drop hook on ready so that modules could register earlier if they want to
Hooks.on("hotbarDrop", (bar, data, slot) => macros.createSgMacro(data, slot));
});
Hooks.on("renderChatMessage", (app, html, data) => {
// Highlight critical success or failure die
chat.highlightCriticalSuccessFailure(app, html, data);
});
Hooks.on("getChatLogEntryContext", chat.addChatMessageContextOptions);
Hooks.on("renderChatLog", (app, html, data) => ItemSg.chatListeners(html));
Hooks.on("renderChatPopout", (app, html, data) => ItemSg.chatListeners(html));
/** Returns the current Tension Die, either from the base campaign level, or the currently active scene level if overridden there
* @returns {string} The current Tension Die
*/
function getTensionDie() {
// First, try to get the Tension Die of the currently active scene, if that turns out unset, get the Tension Die of the campaign
return game.scenes.active?.getFlag("sgrpg", "sceneTensionDie") || game.settings.get("sgrpg", "campaignTension");
}