-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCutsceneMacroMakerV2.js
1483 lines (1416 loc) · 58.7 KB
/
CutsceneMacroMakerV2.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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
let cutsceneActions = [];
function addDialogAction(title, content, callback) {
const dialog = new Dialog({
title: title,
content: content,
buttons: {
ok: {
label: "OK",
callback: callback
},
cancel: {
label: "Cancel",
callback: () => openInitialDialog()
}
},
default: "ok",
render: html => {
// Position the dialog on the right-hand side of the screen
setTimeout(() => {
dialog.element[0].style.top = "25vh";
dialog.element[0].style.left = "65vw";
}, 0);
}
});
dialog.render(true);
}
function openInitialDialog() {
const d = new Dialog({
title: "Cutscene Macro Maker",
content: `
<style>
.cutscene-maker-buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.cutscene-maker-button {
text-align: center;
padding: 5px;
border: 1px solid #ccc;
cursor: pointer;
}
.cutscene-maker-finish {
grid-column: 1 / -1;
text-align: center;
padding: 5px;
border: 1px solid #ccc;
cursor: pointer;
}
</style>
<div class="cutscene-maker-buttons">
<div class="cutscene-maker-button" id="cameraButton">Camera</div>
<div class="cutscene-maker-button" id="sceneButton">Switch Scene</div>
<div class="cutscene-maker-button" id="movementButton">Token Movement</div>
<div class="cutscene-maker-button" id="showhideButton">Show/Hide Token</div>
<div class="cutscene-maker-button" id="chatButton">Chat</div>
<div class="cutscene-maker-button" id="branchButton">Conditional Branch</div>
<div class="cutscene-maker-button" id="flashButton">Screen Flash</div>
<div class="cutscene-maker-button" id="shakeButton">Screen Shake</div>
<div class="cutscene-maker-button" id="tileButton">Tile Movement</div>
<div class="cutscene-maker-button" id="doorButton">Door State</div>
<div class="cutscene-maker-button" id="lightButton">Light State</div>
<div class="cutscene-maker-button" id="ambientButton">Ambient Sound State</div>
<div class="cutscene-maker-button" id="imageButton">Show Image</div>
<div class="cutscene-maker-button" id="animationButton">Play Animation</div>
<div class="cutscene-maker-button" id="soundButton">Play Sound</div>
<div class="cutscene-maker-button" id="playlistButton">Change Playlist</div>
<div class="cutscene-maker-button" id="fadeoutButton">Fade Out</div>
<div class="cutscene-maker-button" id="fadeinButton">Fade In</div>
<div class="cutscene-maker-button" id="hideUIButton">Hide UI</div>
<div class="cutscene-maker-button" id="showUIButton">Show UI</div>
<div class="cutscene-maker-button" id="effectsButton">Weather/Particle Effects</div>
<div class="cutscene-maker-button" id="roomKeyButton">Location Banner</div>
<div class="cutscene-maker-button" id="macroButton">Run Macro</div>
<div class="cutscene-maker-button" id="waitButton">Wait</div>
<div class="cutscene-maker-finish" id="finishButton">Export Macro</div>
</div>
`,
buttons: {},
render: html => {
const closeDialogAndExecute = actionFunction => {
d.close();
actionFunction();
};
html.find("#cameraButton").click(() => closeDialogAndExecute(addCameraPositionAction));
html.find("#sceneButton").click(() => closeDialogAndExecute(addSwitchSceneAction));
html.find("#movementButton").click(() => closeDialogAndExecute(addTokenMovementAction));
html.find("#showhideButton").click(() => closeDialogAndExecute(addHideToggleAction));
html.find("#chatButton").click(() => closeDialogAndExecute(addChatCommandAction));
html.find("#branchButton").click(() => closeDialogAndExecute(addConditionalBranchAction));
html.find("#flashButton").click(() => closeDialogAndExecute(addScreenFlashAction));
html.find("#shakeButton").click(() => closeDialogAndExecute(addScreenShakeAction));
html.find("#tileButton").click(() => closeDialogAndExecute(addTileMovementAction));
html.find("#doorButton").click(() => closeDialogAndExecute(addDoorStateAction));
html.find("#lightButton").click(() => closeDialogAndExecute(addLightStateAction));
html.find("#ambientButton").click(() => closeDialogAndExecute(addAmbientSoundStateAction));
html.find("#effectsButton").click(() => closeDialogAndExecute(addWeatherEffectAction));
html.find("#imageButton").click(() => closeDialogAndExecute(addImageDisplayAction));
html.find("#animationButton").click(() => closeDialogAndExecute(addAnimationAction));
html.find("#soundButton").click(() => closeDialogAndExecute(addPlaySoundAction));
html.find("#playlistButton").click(() => closeDialogAndExecute(addPlayPlaylistAction));
html.find("#fadeoutButton").click(() => closeDialogAndExecute(addFadeOutAction));
html.find("#fadeinButton").click(() => closeDialogAndExecute(addFadeInAction));
html.find("#hideUIButton").click(() => closeDialogAndExecute(addHideUIAction));
html.find("#showUIButton").click(() => closeDialogAndExecute(addShowUIAction));
html.find("#roomKeyButton").click(() => closeDialogAndExecute(addRoomKeyAction));
html.find("#macroButton").click(() => closeDialogAndExecute(addRunMacroAction));
html.find("#waitButton").click(() => closeDialogAndExecute(addWaitAction));
html.find("#finishButton").click(() => closeDialogAndExecute(outputCutsceneScript));
// Position the initial dialog
setTimeout(() => {
d.element[0].style.top = "25vh";
d.element[0].style.left = "75vw";
}, 0);
}
});
d.render(true);
}
function addDialogAction(title, formContent, callback) {
new Dialog({
title: title,
content: formContent,
buttons: {
ok: {
label: "Add",
callback: html => {
try {
callback(html);
ui.notifications.info(`${title} added to the cutscene.`);
} catch (error) {
console.error(`Error adding ${title} action:`, error);
ui.notifications.error(`Failed to add ${title} action.`);
}
openInitialDialog();
}
},
cancel: {
label: "Cancel",
callback: () => openInitialDialog()
}
},
default: "ok"
}).render(true);
}
function addCameraPositionAction() {
addDialogAction(
"Camera Position Action",
`
<form>
<div class="form-group">
<label for="panDuration">Pan Duration (in milliseconds):</label>
<input type="number" id="panDuration" name="panDuration" value="1000" step="100" style="width: 100%;">
</div>
</form>
<p>Current position and zoom level will be used.</p>
`,
html => {
const duration = html.find("#panDuration").val();
const viewPosition = canvas.scene._viewPosition;
cutsceneActions.push(`
// Camera Position Action
// This script pans the camera to the specified position and zoom level over the given duration.
(async function() {
try {
// Define the target position and zoom level.
const targetPosition = {
x: ${viewPosition.x}, // X-coordinate for the camera position
y: ${viewPosition.y}, // Y-coordinate for the camera position
scale: ${viewPosition.scale} // Zoom level for the camera
};
// Animate the camera pan to the target position.
await canvas.animatePan({
x: targetPosition.x,
y: targetPosition.y,
scale: targetPosition.scale,
duration: ${duration} // Duration of the pan in milliseconds
});
// Wait for the duration to ensure the pan completes.
await new Promise(resolve => setTimeout(resolve, ${duration}));
} catch (error) {
console.error("Error in camera position action:", error);
}
})();
`.trim());
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addDialogAction(title, content, callback) {
const dialog = new Dialog({
title: title,
content: content,
buttons: {
ok: {
label: "OK",
callback: callback
},
cancel: {
label: "Cancel",
callback: () => openInitialDialog()
}
},
default: "ok",
render: html => {
// Position the dialog on the right-hand side of the screen
setTimeout(() => {
dialog.element[0].style.top = "25vh";
dialog.element[0].style.left = "75vw";
}, 0);
}
});
dialog.render(true);
}
function addSwitchSceneAction() {
addDialogAction(
"Switch Scene",
`
<form>
<div class="form-group">
<label for="sceneId">Scene ID:</label>
<input type="text" id="sceneId" name="sceneId" placeholder="Enter the scene ID here" style="width: 100%;">
</div>
</form>
<p>Enter the ID of the scene you wish to switch to.</p>
`,
html => {
const sceneId = html.find("#sceneId").val();
cutsceneActions.push(`
// Switch Scene Action
// This script switches the view to the specified scene by its ID.
(async function() {
try {
// Get the scene object using the provided scene ID.
const scene = game.scenes.get("${sceneId}");
if (scene) {
// If the scene exists, switch the view to this scene.
await scene.view();
console.log("Switched to scene: " + scene.name); // Log the scene switch action.
} else {
console.error("Scene not found with ID: ${sceneId}"); // Error if the scene ID is not found.
}
} catch (error) {
console.error("Error in scene switch action:", error);
}
})();
`);
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addTokenMovementAction() {
if (canvas.tokens.controlled.length !== 1) {
ui.notifications.warn("Please select exactly one token.");
openInitialDialog();
return;
}
const selectedToken = canvas.tokens.controlled[0];
addDialogAction(
"Token Movement",
`
<p>Move the selected token to the new position, then click OK.</p>
<form>
<div class="form-group">
<label for="animatePan">Enable Screen Panning:</label>
<input type="checkbox" id="animatePan" name="animatePan" value="1" style="margin-top: 5px;">
<p style="font-size: 0.8em; margin-top: 5px;">Camera Panning.</p>
</div>
<div class="form-group">
<label for="teleport">Teleport:</label>
<input type="checkbox" id="teleport" name="teleport" style="margin-top: 5px;">
<p style="font-size: 0.8em; margin-top: 5px;">Instantly move to the new position without animation.</p>
</div>
<div class="form-group">
<label for="tokenRotation">Token Rotation (in degrees):</label>
<input type="number" id="tokenRotation" name="tokenRotation" value="${selectedToken.data.rotation}" step="1" style="width: 100%;">
</div>
</form>
`,
html => {
const newPosition = { x: selectedToken.x, y: selectedToken.y };
const newRotation = parseFloat(html.find("#tokenRotation").val());
const animatePan = html.find("#animatePan")[0].checked;
const teleport = html.find("#teleport")[0].checked;
let tokenMovementScript;
if (teleport) {
tokenMovementScript = `
// Token Teleport Action
// This script instantly teleports the selected token to a new position and rotation without animation.
(async function() {
try {
// Get the token object using its ID.
const token = canvas.tokens.get("${selectedToken.id}");
if (token) {
// Update the token's position and rotation without animation.
await token.document.update({ x: ${newPosition.x}, y: ${newPosition.y}, rotation: ${newRotation} }, { animate: false });
}
} catch (error) {
console.error("Error in token teleport action:", error);
}
})();
`;
} else {
tokenMovementScript = `
// Token Movement Action
// This script moves the selected token to a new position and rotation with animation.
(async function() {
try {
// Get the token object using its ID.
const token = canvas.tokens.get("${selectedToken.id}");
if (token) {
// Update the token's position and rotation with animation.
await token.document.update({ x: ${newPosition.x}, y: ${newPosition.y}, rotation: ${newRotation} });
${animatePan ? `
// Animate the camera pan to follow the token's new position.
await canvas.animatePan({ x: ${newPosition.x}, y: ${newPosition.y}, duration: 1000 });
` : ""}
}
// Wait for a short duration to ensure the movement animation completes.
await new Promise(resolve => setTimeout(resolve, 1000));
} catch (error) {
console.error("Error in token movement action:", error);
}
})();
`;
}
cutsceneActions.push(tokenMovementScript.trim());
ui.notifications.info(`Token ${teleport ? "teleport" : "movement"} action added to the cutscene.`);
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addHideToggleAction() {
if (canvas.tokens.controlled.length !== 1) {
ui.notifications.warn("Please select exactly one token.");
openInitialDialog();
return;
}
const selectedToken = canvas.tokens.controlled[0];
cutsceneActions.push(`
// Show/Hide Token Action
// This script toggles the visibility of the selected token.
(async function() {
try {
// Get the token object using its ID.
const token = canvas.tokens.get("${selectedToken.id}");
if (token) {
// Toggle the hidden property of the token.
await token.document.update({ hidden: !token.data.hidden });
console.log("Token visibility toggled: " + (!token.data.hidden ? "Visible" : "Hidden"));
} else {
console.error("Token not found with ID: ${selectedToken.id}");
}
} catch (error) {
console.error("Error in show/hide token action:", error);
}
})();
`);
openInitialDialog();
}
function addChatCommandAction() {
if (canvas.tokens.controlled.length !== 1) {
ui.notifications.warn("Please select exactly one token.");
openInitialDialog();
return;
}
const selectedToken = canvas.tokens.controlled[0];
addDialogAction(
"Chat Command",
`
<form>
<div class="form-group">
<label for="messageContent">Message:</label>
<input type="text" id="messageContent" name="messageContent" style="width: 100%;">
</div>
</form>
<p>Enter the message you want the selected token to say in chat. This will be added to your cutscene script.</p>
`,
html => {
const messageContent = html.find("#messageContent").val();
cutsceneActions.push(`
// Chat Command Action
// This script makes the selected token say a specified message in chat.
(async function() {
try {
// Define the speaker object with token and actor information.
const speaker = {
alias: "${selectedToken.name}", // Token name as the alias
token: "${selectedToken.id}", // Token ID
actor: "${selectedToken.actor.id}" // Actor ID
};
// Define the message content.
const content = "${messageContent.replace(/"/g, '\\"')}";
// Create a chat message with the defined speaker and content.
ChatMessage.create({ speaker, content });
} catch (error) {
console.error("Error in chat command action:", error);
}
})();
`.trim());
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addConditionalBranchAction() {
function renderDialog() {
let dialogContent = `
<style>
.choice-input-set {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
}
.choice-input-set input {
flex: 1;
margin-right: 5px;
}
#add-choice {
margin-top: 10px;
}
</style>
<div id="conditional-choices-container">
<p>Add choices and corresponding macros. Use the '+' button to add more choices.</p>
<div class="choice-input-set">
<input type="text" placeholder="Choice Text" class="choice-text" style="margin-right: 5px;">
<input type="text" placeholder="Macro Name" class="macro-name">
</div>
</div>
<button type="button" id="add-choice">Add Choice</button>
`;
const d = new Dialog({
title: "Configure Conditional Branch",
content: dialogContent,
buttons: {
done: {
icon: '<i class="fas fa-check"></i>',
label: "Done",
callback: html => {
const choiceTexts = html.find(".choice-text").map(function () { return $(this).val(); }).get();
const macroNames = html.find(".macro-name").map(function () { return $(this).val(); }).get();
choices = choiceTexts.map((text, index) => ({ text, macro: macroNames[index] }));
generateConditionalBranchScript();
}
},
cancel: {
label: "Cancel",
callback: () => openInitialDialog()
}
},
render: html => {
html.find("#add-choice").click(() => {
const container = html.find("#conditional-choices-container");
container.append(`
<div class="choice-input-set">
<input type="text" placeholder="Choice Text" class="choice-text" style="margin-right: 5px;">
<input type="text" placeholder="Macro Name" class="macro-name">
</div>
`);
});
}
});
d.render(true);
}
function generateConditionalBranchScript() {
let scriptContent = `
// Conditional Branch Action
// This script creates a dialog with multiple choices, each executing a specified macro when selected.
async function executeMacroByName(macroName) {
try {
// Find the macro by its name.
const macro = game.macros.contents.find(m => m.name === macroName);
if (macro) {
// Execute the macro if found.
await macro.execute();
} else {
console.error("Macro not found: " + macroName);
}
} catch (error) {
console.error("Error executing macro:", error);
}
}
// Create a new dialog with the defined choices.
new Dialog({
title: "Choose an Action",
content: "<p>What would you like to do?</p>",
buttons: {`;
choices.forEach((choice, index) => {
scriptContent += `
'choice${index}': {
label: "${choice.text}",
callback: () => {
// Execute the macro associated with this choice.
executeMacroByName("${choice.macro}");
}
},`;
});
scriptContent += `
},
default: 'choice0'
}).render(true);
`;
cutsceneActions.push(scriptContent);
openInitialDialog();
}
renderDialog();
}
function addRunMacroAction() {
addDialogAction(
"Run Macro Action",
`
<form>
<div class="form-group">
<label for="macroName">Macro Name:</label>
<input type="text" id="macroName" name="macroName" placeholder="Enter macro name here" style="width: 100%;">
</div>
</form>
<p>Enter the name of the macro you wish to run.</p>
`,
html => {
const macroName = html.find("#macroName").val();
cutsceneActions.push(`
// Run Macro Action
// This script runs the specified macro by its name.
(async function() {
try {
// Find the macro by its name.
const macro = game.macros.find(m => m.name === "${macroName}");
if (macro) {
// Execute the macro if found.
await macro.execute();
console.log("Executed macro: ${macroName}");
} else {
console.warn("Macro not found: ${macroName}");
}
} catch (error) {
console.error("Error in run macro action:", error);
}
})();
`.trim());
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addWaitAction() {
addDialogAction(
"Wait Duration",
`
<form>
<div class="form-group">
<label for="waitDuration">Enter wait duration in milliseconds:</label>
<input type="number" id="waitDuration" name="waitDuration" min="0" step="100" value="1000" style="width: 100%;">
</div>
</form>
`,
html => {
const duration = html.find("#waitDuration").val();
cutsceneActions.push(`
// Wait for specific duration in milliseconds.
await new Promise(resolve => setTimeout(resolve, ${duration}));
`.trim());
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addScreenFlashAction() {
addDialogAction(
"Add Screen Flash Effect",
`
<form>
<div class="form-group">
<label for="flashColor">Flash Color (hex):</label>
<input type="text" id="flashColor" name="flashColor" value="#FFFFFF" placeholder="#FFFFFF" style="width: 100%;">
</div>
<div class="form-group">
<label for="flashOpacity">Opacity (0.0 - 1.0):</label>
<input type="number" id="flashOpacity" name="flashOpacity" step="0.1" min="0.0" max="1.0" value="0.5" style="width: 100%;">
</div>
<div class="form-group">
<label for="flashDuration">Duration (milliseconds):</label>
<input type="number" id="flashDuration" name="flashDuration" step="100" min="100" value="1000" style="width: 100%;">
</div>
</form>
`,
html => {
const flashColor = html.find("#flashColor").val();
const flashOpacity = parseFloat(html.find("#flashOpacity").val());
const flashDuration = parseInt(html.find("#flashDuration").val());
cutsceneActions.push(`
// Screen Flash Action
// This script creates a screen flash effect with the specified color, opacity, and duration.
(function() {
try {
// Create a div element to cover the screen for the flash effect.
const flashEffect = document.createElement("div");
flashEffect.style.position = "fixed";
flashEffect.style.left = 0;
flashEffect.style.top = 0;
flashEffect.style.width = "100vw";
flashEffect.style.height = "100vh";
flashEffect.style.backgroundColor = "${flashColor}"; // Set the flash color
flashEffect.style.opacity = ${flashOpacity}; // Set the flash opacity
flashEffect.style.pointerEvents = "none"; // Ensure the flash effect doesn't interfere with interactions
flashEffect.style.zIndex = "10000"; // Ensure the flash effect is above all other elements
document.body.appendChild(flashEffect);
// Start the fade-out transition after a short delay.
setTimeout(() => {
flashEffect.style.transition = "opacity ${flashDuration}ms";
flashEffect.style.opacity = 0;
}, 50);
// Remove the flash effect element after the transition completes.
setTimeout(() => {
flashEffect.remove();
}, ${flashDuration} + 50);
} catch (error) {
console.error("Error in screen flash action:", error);
}
})();
`);
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addScreenShakeAction() {
addDialogAction(
"Add Screen Shake Effect",
`
<form>
<div class="form-group">
<label for="shakeDuration">Duration (milliseconds):</label>
<input type="number" id="shakeDuration" name="shakeDuration" value="1000" step="100" min="100" style="width: 100%;">
</div>
<div class="form-group">
<label for="shakeSpeed">Speed (frequency of shakes):</label>
<input type="number" id="shakeSpeed" name="shakeSpeed" value="10" step="1" min="1" style="width: 100%;">
</div>
<div class="form-group">
<label for="shakeIntensity">Intensity (pixel displacement):</label>
<input type="number" id="shakeIntensity" name="shakeIntensity" value="5" step="1" min="1" style="width: 100%;">
</div>
</form>
`,
html => {
const duration = parseInt(html.find("#shakeDuration").val());
const speed = parseInt(html.find("#shakeSpeed").val());
const intensity = parseInt(html.find("#shakeIntensity").val());
cutsceneActions.push(`
// Screen Shake Action
// This script creates a screen shake effect with the specified duration, speed, and intensity.
(function() {
try {
// Save the original transform style of the document body.
const originalTransform = document.body.style.transform;
let startTime = performance.now();
// Function to perform the shaking effect.
function shakeScreen(currentTime) {
const elapsedTime = currentTime - startTime;
const progress = elapsedTime / ${duration}; // Calculate the progress as a fraction of the duration
if (progress < 1) {
// Calculate the displacement using a sine wave for smooth shaking.
let displacement = ${intensity} * Math.sin(progress * ${speed} * 2 * Math.PI);
displacement *= 1 - progress; // Reduce the intensity over time
// Apply the displacement to the document body's transform style.
document.body.style.transform = \`translate(\${displacement}px, \${displacement}px)\`;
// Continue the animation until the duration is complete.
requestAnimationFrame(shakeScreen);
} else {
// Restore the original transform style once the shake effect is complete.
document.body.style.transform = originalTransform;
}
}
// Start the shake effect animation.
requestAnimationFrame(shakeScreen);
} catch (error) {
console.error("Error in screen shake action:", error);
}
})();
`);
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addTileMovementAction() {
if (canvas.tiles.controlled.length < 1) {
ui.notifications.warn("Please select at least one tile.");
openInitialDialog();
return;
}
addDialogAction(
"Tile Movement",
`
<p>Move the selected tiles to the new positions, then click OK.</p>
<form>
<div class="form-group">
<label for="animate">Animate Movement:</label>
<input type="checkbox" id="animate" name="animate" checked style="margin-top: 5px;">
<p style="font-size: 0.8em; margin-top: 5px;">Check this if you want the tiles to move smoothly to their new positions.</p>
</div>
</form>
`,
html => {
const animate = html.find("#animate")[0].checked;
let tileMovementScript = `
// Tile Movement Action
// This script moves the selected tiles to their new positions.
(async function() {
try {
// Update each selected tile's position.
${canvas.tiles.controlled.map(t => {
return `
// Move tile with ID: ${t.id}
await canvas.tiles.get("${t.id}").document.update({ x: ${t.x}, y: ${t.y} }, { animate: ${animate} });`;
}).join('\n')}
// Wait for the movement animation to complete.
await new Promise(resolve => setTimeout(resolve, canvas.tiles.controlled.length * 1000));
} catch (error) {
console.error("Error in tile movement action:", error);
}
})();
`;
cutsceneActions.push(tileMovementScript.trim());
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addDoorStateAction() {
if (canvas.walls.controlled.length !== 1) {
ui.notifications.warn("Please select exactly one door.");
openInitialDialog();
return;
}
const selectedWall = canvas.walls.controlled[0];
if (!selectedWall.data.door) {
ui.notifications.warn("The selected wall is not a door.");
openInitialDialog();
return;
}
new Dialog({
title: "Door Options",
content: "<p>Choose an action for the selected door:</p>",
buttons: {
openClose: {
label: "Open/Close",
callback: () => {
cutsceneActions.push(`
// Door Open/Close Action
// This script toggles the open/close state of the selected door.
(async function() {
try {
// Get the door object using its ID.
const wall = canvas.walls.get("${selectedWall.id}");
if (wall) {
// Determine the new door state (open or closed).
let newState = wall.data.ds === CONST.WALL_DOOR_STATES.CLOSED ? CONST.WALL_DOOR_STATES.OPEN : CONST.WALL_DOOR_STATES.CLOSED;
// Update the door state.
await wall.document.update({ ds: newState });
}
} catch (error) {
console.error("Error in door open/close action:", error);
}
// Wait for a short duration to ensure the state change completes.
await new Promise(resolve => setTimeout(resolve, 1000));
})();
`.trim());
openInitialDialog();
}
},
lockUnlock: {
label: "Lock/Unlock",
callback: () => {
const isLocked = selectedWall.data.ds === CONST.WALL_DOOR_STATES.LOCKED;
const newLockState = isLocked ? CONST.WALL_DOOR_STATES.CLOSED : CONST.WALL_DOOR_STATES.LOCKED;
cutsceneActions.push(`
// Door Lock/Unlock Action
// This script toggles the lock/unlock state of the selected door.
(async function() {
try {
// Get the door object using its ID.
const wall = canvas.walls.get("${selectedWall.id}");
if (wall) {
// Update the lock state of the door.
await wall.document.update({ ds: ${newLockState} });
}
} catch (error) {
console.error("Error in door lock/unlock action:", error);
}
})();
`.trim());
openInitialDialog();
}
},
cancel: {
label: "Cancel",
callback: () => openInitialDialog()
}
}
}).render(true);
}
function addLightStateAction() {
addDialogAction(
"Light State Action",
`
<form>
<div class="form-group">
<label for="lightId">Light Source ID:</label>
<input type="text" id="lightId" name="lightId" placeholder="Enter light source ID here" style="width: 100%;">
</div>
</form>
<p>Enter the light source ID and choose to toggle its state in the cutscene.</p>
`,
html => {
const lightId = html.find("#lightId").val();
if (!lightId) {
ui.notifications.warn("Please enter a light source ID.");
return;
}
cutsceneActions.push(`
// Light State Action
// This script toggles the visibility of the specified light source.
(async function() {
try {
// Get the light object using its ID.
const light = canvas.lighting.get("${lightId}");
if (light) {
// Toggle the hidden property of the light.
const newVisibility = !light.data.hidden;
await light.document.update({ hidden: newVisibility });
console.log("Light " + (newVisibility ? "enabled" : "disabled") + ".");
} else {
console.warn("Light source not found with ID: ${lightId}");
}
} catch (error) {
console.error("Error in light state action:", error);
}
})();
`);
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addAmbientSoundStateAction() {
addDialogAction(
"Ambient Sound State Action",
`
<form>
<div class="form-group">
<label for="soundId">Ambient Sound ID:</label>
<input type="text" id="soundId" name="soundId" placeholder="Enter ambient sound ID here" style="width: 100%;" autocomplete="off">
</div>
</form>
<p>Toggle the on/off state of the specified ambient sound in your cutscene.</p>
`,
html => {
const soundId = html.find("#soundId").val();
const sound = canvas.scene.sounds.find(s => s.id === soundId);
if (sound) {
cutsceneActions.push(`
// Ambient Sound State Action
// This script toggles the on/off state of the specified ambient sound.
(async function() {
try {
// Find the ambient sound by its ID.
const sound = canvas.scene.sounds.find(s => s.id === "${soundId}");
if (sound) {
// Toggle the hidden state of the ambient sound.
const currentHiddenState = sound.data.hidden;
await sound.update({ hidden: !currentHiddenState });
console.log("Ambient sound toggled: " + (!currentHiddenState ? "On" : "Off"));
} else {
console.error("Ambient sound not found with ID: ${soundId}");
}
} catch (error) {
console.error("Error in ambient sound state action:", error);
}
})();
`);
openInitialDialog(); // Reopen the initial dialog
} else {
ui.notifications.error("Ambient sound not found with ID: " + soundId);
}
}
);
}
function addWeatherEffectAction() {
const weatherTypes = [{ name: "None", value: "none" }, { name: "Clouds", value: "clouds" }, { name: "Rain", value: "rain" }, { name: "Snow", value: "snow" }];
const weatherOptions = weatherTypes.map(type => `<option value="${type.value}">${type.name}</option>`).join("");
addDialogAction(
"Add Weather Effect",
`
<form>
<div class="form-group">
<label for="weatherType">Weather Effect:</label>
<select id="weatherType" name="weatherType" style="width: 100%;">${weatherOptions}</select>
</div>
<div class="form-group">
<label for="density">Density:</label>
<input type="number" id="density" name="density" step="0.01" min="0" max="1" value="0.5" style="width: 100%;">
</div>
<div class="form-group">
<label for="speed">Speed:</label>
<input type="number" id="speed" name="speed" step="0.1" min="0" value="1" style="width: 100%;">
</div>
<div class="form-group">
<label for="scale">Scale:</label>
<input type="number" id="scale" name="scale" step="0.1" min="0" value="1" style="width: 100%;">
</div>
<div class="form-group">
<label for="tint">Tint (hex color):</label>
<input type="text" id="tint" name="tint" value="#FFFFFF" placeholder="#FFFFFF" style="width: 100%;">
</div>
<div class="form-group">
<label for="direction">Direction (degrees):</label>
<input type="number" id="direction" name="direction" value="90" placeholder="90" step="1" min="0" max="360" value="0" style="width: 100%;">
</div>
</form>
`,
html => {
const selectedWeatherType = html.find("#weatherType").val();
const density = parseFloat(html.find("#density").val());
const speed = parseFloat(html.find("#speed").val());
const scale = parseFloat(html.find("#scale").val());
const tint = html.find("#tint").val();
const direction = parseInt(html.find("#direction").val());
cutsceneActions.push(`
// Weather Effect Action
// This script applies a weather effect with the specified parameters.
Hooks.call("fxmaster.updateParticleEffects", [
{
type: "${selectedWeatherType}", // Type of weather effect (e.g., "rain", "snow")
options: {
density: ${density}, // Density of the weather effect particles
speed: ${speed}, // Speed of the weather effect particles
scale: ${scale}, // Scale of the weather effect particles
tint: { value: "${tint}", apply: true }, // Tint color of the weather effect particles
direction: ${direction} // Direction of the weather effect particles
}
}
]);
`);
openInitialDialog(); // Reopen the initial dialog
}
);
}
function addImageDisplayAction() {
addDialogAction(
"Add Image Display Action",
`
<form>
<div class="form-group">
<label for="imageUrl">Image URL:</label>
<input type="text" id="imageUrl" name="imageUrl" placeholder="http://example.com/image.png" style="width: 100%;">
</div>
</form>
`,
html => {
const imageUrl = html.find("#imageUrl").val();
if (imageUrl) {
cutsceneActions.push(`
// Image Display Action
// This script displays an image from the specified URL in a dialog.
(async function() {
try {
// Create and render a new dialog to display the image.
new Dialog({