-
Notifications
You must be signed in to change notification settings - Fork 18
/
ffg-star-wars-enhancements.js
172 lines (154 loc) · 5.21 KB
/
ffg-star-wars-enhancements.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
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
import { init as settings_init } from "./scripts/settings.js";
import { FfgEnhancementsLayer, log_msg as log } from "./scripts/util.js";
import { init as attack_animation_init, attack_animation_check, attack_animation } from "./scripts/animation.js";
import { init as opening_crawl_init, ready as opening_crawl_ready } from "./scripts/opening_crawl.js";
import { init as title_cards_init, ready as title_cards_ready } from "./scripts/title_cards.js";
import { init as hyperspace_init, ready as hyperspace_ready } from "./scripts/hyperspace.js";
import { init as rename_init, rename_combatant } from "./scripts/rename.js";
import {
init as dice_helper_init,
dice_helper,
create_and_populate_journal as dice_helper_setup,
} from "./scripts/dice_helper.js";
import { init as strain_reminder_init, strain_reminder } from "./scripts/strain_reminder.js";
import { init as talent_checker_init, talent_checker } from "./scripts/talent_checker.js";
import { init as shop_generator_init, ready as shop_sheet_ready } from "./scripts/shop_sheet.js";
import { stim_sync } from "./scripts/stim_sync.js";
import { minionsize_sync } from "./scripts/minionsize_sync.js";
import { register_controls } from "./scripts/controls_layer.js";
import { init as quench_tests_init } from "./tests/quench.js";
Hooks.once("init", async function () {
log("base_module", "Initializing");
register_layers();
settings_init();
rename_init();
attack_animation_init();
dice_helper_init();
strain_reminder_init();
talent_checker_init();
opening_crawl_init();
title_cards_init();
shop_generator_init();
hyperspace_init();
quench_tests_init(); // Will have no effect unless Quench is active
log("base_module", "registering helpers");
Handlebars.registerHelper("iff_custom", function (a, operator, b, opts) {
var bool = false;
switch (operator) {
case "==":
bool = a == b;
break;
case ">":
bool = a > b;
break;
case "<":
bool = a < b;
break;
case "!=":
bool = a != b;
break;
case "in":
bool = b.indexOf(a) > 0;
break;
case "not in":
bool = b.indexOf(a) < 0;
break;
case "contains":
if (a && b) {
bool = a.includes(b);
} else {
bool = false;
}
break;
default:
throw "Unknown operator " + operator;
}
if (bool) {
return opts.fn(this);
} else {
return opts.inverse(this);
}
});
Handlebars.registerHelper("times", function (times, opts) {
var out = "";
var i;
var data = {};
if (times) {
for (i = 0; i < times; i += 1) {
data.index = i;
out += opts.fn(this, {
data: data,
});
}
} else {
out = opts.inverse(this);
}
return out;
});
log("base_module", "Done registering helpers");
log("base_module", "Initializing finished");
});
Hooks.once("ready", async () => {
/* register functionality here */
attack_animation_check();
opening_crawl_ready();
title_cards_ready();
shop_sheet_ready();
dice_helper();
talent_checker();
register_hooks();
await dice_helper_setup();
hyperspace_ready();
});
Hooks.on("getSceneControlButtons", (controls) => {
if (!game.user.isGM) {
return;
}
register_controls(controls);
});
Hooks.on("createCombatant", (combatant) => {
strain_reminder(combatant);
});
Hooks.on("preCreateCombatant", (combatant) => {
rename_combatant(combatant);
});
Hooks.on("updateActor", (...args) => {
stim_sync("updateActor", ...args);
});
Hooks.on("canvasReady", (...args) => {
stim_sync("scene", ...args);
});
Hooks.on("updateActor", (...args) => {
minionsize_sync("updateActor", ...args);
});
Hooks.on("canvasReady", (...args) => {
minionsize_sync("canvasReady", ...args);
});
Hooks.on("createToken", async (...args) => {
minionsize_sync("createToken", ...args);
});
function register_hooks() {
libWrapper.register(
"ffg-star-wars-enhancements",
"game.ffg.RollFFG.prototype.toMessage",
async function (wrapped, ...args) {
/*
we may want to monkeypatch a different function in the future. this location doesn't seem to have access
to the actual weapon in use. I'm not sure if we actually care yet, but worth considering.
*/
if (!this.evaluated) {
try {
await this.evaluate();
} catch (e) {
// do nothing
log("ffg-star-wars-enhancements", "Error evaluating roll: " + e);
}
}
var data = attack_animation(this, ...args);
return wrapped(...data);
}
);
}
function register_layers() {
CONFIG.Canvas.layers.ffgenhancements = { layerClass: FfgEnhancementsLayer, group: "interface" };
}