-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfsminit.js
356 lines (315 loc) · 10.7 KB
/
fsminit.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
// (F O U N D R Y - S T R E A M - M O D 0 . 2 . 7)
//(() => {})();
import "./scripts/tmi.min.js"; // I M P O R T S
import * as fsmcore from "./scripts/fsmcore.js";
import { fsMod } from "./scripts/streamTwitch.js";
import fsmLayer from "./scripts/modLayer.js";
import * as settings from "./scripts/settings.js";
import { DiceRoller } from "https://cdn.jsdelivr.net/npm/rpg-dice-roller@4.5.2/lib/esm/bundle.min.js";
const roller = new DiceRoller(); // C O N S T A N T S A N D V A R I A B L E S
const CHAT_MESSAGE_TYPES = {
OTHER: 0,
OOC: 1,
IC: 2,
EMOTE: 3,
WHISPER: 4,
ROLL: 5,
};
let currentTab = "foundry";
Hooks.on("renderChatLog", async function (chatLog, html, user) {
// S O R T T A B B E D M S G S
if (fsmcore.TabbedChat()) return;
if (game.settings.get("streamMod", "hideTwitchChat")) return;
var toPrepend = '<nav class="fsmtabs tabs">';
toPrepend += `<a class="item foundry" data-tab="foundry">Foundry</a><i id="foundryNotification" class="notification-pip fas fa-exclamation-circle" style="display: none;"></i>`;
toPrepend += `<a class="item fsm" data-tab="fsm">Twitch</a></nav><i id="fsmNotification" class="notification-pip fas fa-exclamation-circle" style="display: none;"></i>`;
html.prepend(toPrepend);
var me = this;
const tabs = new TabsV2({
navSelector: ".tabs",
contentSelector: ".content",
initial: "tab1",
callback: function (event, html, tab) {
currentTab = tab;
let chatLog = $("#chat-log");
let itemType0 = chatLog.find(".type0");
let itemType1 = chatLog.find(".type1");
let itemType2 = chatLog.find(".type2");
let itemType3 = chatLog.find(".type3");
let itemType4 = chatLog.find(".type4");
let itemType5 = chatLog.find(".type5");
if (tab == "foundry") {
itemType0.removeClass("hardHide");
itemType0.show();
itemType1.hide();
itemType2.removeClass("hardHide");
itemType2.show();
itemType3.removeClass("hardHide");
itemType3.show();
itemType4.removeClass("hardHide");
itemType4.show();
itemType5.removeClass("hardHide");
itemType5.not(".gm-roll-hidden").show();
$("#foundryNotification").hide();
} else if (tab == "fsm") {
itemType1.removeClass("hardHide");
itemType1.show();
itemType2.hide();
itemType3.hide();
itemType4.hide();
itemType5.hide();
itemType0.hide();
$("#fsmNotification").hide();
} else {
console.log("Unknown tab " + tab + "!");
}
chatLog.scrollTop(9999999);
},
});
tabs.bind(html[0]);
});
Hooks.on("renderChatMessage", (chatMessage, html, data) => {
// R E N D E R T A B B E D C H A T
//if (fsmcore.TabbedChat()) return;
html.addClass("type" + data.message.type);
var sceneMatches = true;
if (
data.message.type == 0 ||
data.message.type == 2 ||
data.message.type == 3 ||
data.message.type == 4 ||
data.message.type == 5
) {
if (data.message.speaker.scene != undefined) {
html.addClass("scenespecific");
html.addClass("scene" + data.message.speaker.scene);
if (data.message.speaker.scene != game.user.viewedScene) {
sceneMatches = false;
}
}
}
if (currentTab == "foundry") {
/*if (
(fsmcore.xCmd()) &&
data.message.type == 1) {
data.message.type == 2}*/
if (
(data.message.type == 2 ||
data.message.type == 0 ||
data.message.type == 4 ||
data.message.type == 3) &&
sceneMatches
) {
html.css("display", "list-item");
} else if (data.message.type == 5 && sceneMatches) {
if (!html.hasClass("gm-roll-hidden")) {
if (
game.dice3d &&
game.settings.get("dice-so-nice", "settings").enabled &&
game.settings.get("dice-so-nice", "enabled")
) {
if (
!game.settings.get("dice-so-nice", "immediatelyDisplayChatMessages")
)
return;
}
html.css("display", "list-item");
}
} else {
html.css("display", "none");
html.css("cssText", "display: none !important;");
html.addClass("hardHide");
}
} else if (currentTab == "fsm") {
if (data.message.type == 1) {
html.css("display", "list-item");
} else {
html.css("display", "none");
}
}
});
Hooks.on("diceSoNiceRollComplete", (id) => {
// P L A Y N I C E W I T H D S N
if (fsmcore.TabbedChat()) return;
if (currentTab != "foundry") {
$("#chat-log .message[data-message-id=" + id + "]").css("display", "none");
}
});
Hooks.on("createChatMessage", (chatMessage, content) => {
// C H A T N O T I F I C A T I O N S
if (fsmcore.TabbedChat()) return;
var sceneMatches = true;
if (chatMessage.data.speaker.scene) {
if (chatMessage.data.speaker.scene != game.user.viewedScene) {
sceneMatches = false;
}
}
if (
chatMessage.data.type == 0 ||
chatMessage.data.type == 2 ||
chatMessage.data.type == 3 ||
chatMessage.data.type == 4
) {
if (currentTab != "foundry" && sceneMatches) {
$("#foundryNotification").show();
}
} else if (chatMessage.data.type == 5) {
if (
currentTab != "foundry" &&
sceneMatches &&
chatMessage.data.whisper.length == 0
) {
$("#foundryNotification").show();
}
} else if (chatMessage.data.type == 1) {
if (currentTab != "fsm" && sceneMatches) {
$("#fsmNotification").show();
}
} else {
if (currentTab != "fsm") {
$("#fsmNotification").show();
}
}
});
Hooks.on("preCreateChatMessage", (chatMessage, content) => {
// T U R N I C M S G S I N T O O O C I F x C m d O F F
if (fsmcore.xCmd()) {
if (currentTab == "foundry") {
if (chatMessage.type == 2) {
chatMessage.type = 2;
}
}
}
if (!fsmcore.xCmd()) {
if (game.settings.get("streamMod", "icChatInOoc")) {
if (currentTab == "fsm") {
if (chatMessage.type == 2) {
chatMessage.type = 1;
delete chatMessage.speaker;
console.log(chatMessage);
}
}
}
}
});
Hooks.on("renderSceneNavigation", (sceneNav, html, data) => {
// R E N D E R N A V F O R T A B S
if (fsmcore.TabbedChat()) return;
var viewedScene = sceneNav.scenes.find((x) => x.isView);
$(".scenespecific").hide();
if (currentTab == "fsm") {
$(".type1.scene" + game.user.viewedScene).removeClass("hardHide");
$(".type1.scene" + viewedScene.id).show();
} else if (currentTab == "foundry") {
$(".type0.scene" + game.user.viewedScene).removeClass("hardHide");
$(".type0.scene" + viewedScene.id).show();
$(".type2.scene" + game.user.viewedScene).removeClass("hardHide");
$(".type2.scene" + viewedScene.id).show();
$(".type3.scene" + game.user.viewedScene).removeClass("hardHide");
$(".type3.scene" + viewedScene.id).show();
$(".type4.scene" + game.user.viewedScene).removeClass("hardHide");
$(".type4.scene" + viewedScene.id).show();
$(".type5.scene" + game.user.viewedScene).removeClass("hardHide");
$(".type5.scene" + viewedScene.id)
.not(".gm-roll-hidden")
.show();
}
});
Hooks.on("init", function () {
// M O D - S E T T I N G S
settings.registerSettings();
});
Hooks.once("canvasReady", () => {
// C A N V A S L A Y E R
// Add fsmLayer to canvas
const layerct = canvas.stage.children.length;
let tbLayer = new fsmLayer();
tbLayer.setButtons();
tbLayer.roleTest();
canvas.fsMod = canvas.stage.addChildAt(tbLayer, layerct);
canvas.fsMod.draw();
let theLayers = Canvas.layers;
theLayers.fsMod = fsmLayer;
Object.defineProperty(Canvas, "layers", {
get: function () {
return theLayers;
},
});
});
Hooks.on("ready", function () {
// O N - R E A D Y - C O N N E C T I O N S
fsmcore.SetupTwitchClient();
onStream();
fsmcore.streamDice();
fsmcore.AnnounceTime1();
fsmcore.AnnounceTime2();
});
Hooks.on("createChatMessage", async (message) => {
// F O U N D R Y => T W I T C H
if (fsmcore.xCmd()) return;
if (message.data.type === 4) return;
let testQuiet = game.settings.get("streamMod", "streamQuiet");
if (testQuiet === true) {
if (message.data.type === 0) return;
if (message.data.type === 5) return;
if (message.export().includes("Stream Chat")) return;
if (message.export().includes("#00000004.0000AC0")) return;
if (game.settings.get("streamMod", "streamModEcho")) {
let firstGm = game.users.find((u) => u.isGM && u.active);
if (firstGm && game.user === firstGm) {
let myChannel = game.settings.get("streamMod", "streamChannel");
let tempAlias = message.alias;
let tempM = message.export();
let res = tempM.slice(23);
let res1 = res.replace(/(^|\s)] \s?/g, " "); // Removes '] ' that may appear when stripping the timestamp
let res2 = res1.replace(/(^|\s)Damage Apply Apply Half\s?/g, " "); // <= PF1e specific roll cleanup
let res3 = res2.replace(/(^|\s)Info Attack Action\s?/g, " "); // <= PF1e specific roll cleanup
let fin = res3.replace(tempAlias, "[" + tempAlias + "]: ");
fsMod.client.say(myChannel, fin);
}
}
}});
Hooks.on('preCreateChatMessage', (data, opts, usr) => {
if (!fsmcore.xCmd()) return
if (game.user.isGM && data.type === CONST.CHAT_MESSAGE_TYPES.OOC) data.type = CONST.CHAT_MESSAGE_TYPES.IC;
})
Hooks.on("chatCommandsReady", function(chatCommands) {
if (!fsmcore.xCmd()) {
console.log("Registering Chat Commands: OFF")
let ctype = game.settings.get("streamMod", "streamChatType");
chatCommands.registerCommand(chatCommands.createCommandFromData({
commandKey: "/t",
invokeOnCommand: (chatlog, messageText, chatdata) => {
ChatMessage.create({
speaker: {
alias: "Foundry Stream Module"
},
content: `Guru Meditation: Error #00000004.0000AC0 - Message not sent to Twitch because you used the /t command without having it enabled in your FSM config.`
});
console.log(messageText);
},
shouldDisplayToChat: false,
createdMessageType: ctype,
iconClass: "fa-sticky-note",
description: "Please enable in FSM config"
}));
return
}
if (fsmcore.xCmd()) {
console.log("Registering Chat Commands: ON")
let ctype = game.settings.get("streamMod", "streamChatType");
chatCommands.registerCommand(chatCommands.createCommandFromData({
commandKey: "/t",
invokeOnCommand: (chatlog, messageText, chatdata) => {
let who = chatdata.speaker.alias;
streamOut(messageText, who);
console.log(messageText, chatdata.speaker.alias);
},
shouldDisplayToChat: true,
createdMessageType: ctype,
iconClass: "fa-sticky-note",
description: "Sends message to Twitch"
}));
console.log("commandKey loaded")
}
});