-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathScenesPanel.js
3326 lines (2831 loc) · 126 KB
/
ScenesPanel.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
function consider_upscaling(target){
if(target.hpps < 60 && target.hpps > 25 && target.vpps < 60 && target.vpps > 25){
target.scale_factor=2;
}
else if(target.hpps <=25 || target.vpps <=25){
target.scale_factor=4;
}
else{
target.scale_factor=1;
}
}
function handle_basic_form_toggle_click(event){
if ($(event.currentTarget).hasClass("rc-switch-checked")) {
// it was checked. now it is no longer checked
$(event.currentTarget).removeClass("rc-switch-checked");
} else {
// it was not checked. now it is checked
$(event.currentTarget).removeClass("rc-switch-unknown");
$(event.currentTarget).addClass("rc-switch-checked");
}
}
function handle_map_toggle_click(event){
handle_basic_form_toggle_click(event)
// validate image input expects the target to be the input not the t oggle
//validate_image_input($(event.currentTarget).prev().find("input")[0])
}
async function get_edit_form_data(){
// bain todo, call image validation here and stop if it's not valid
let data = {}
let promises = [];
$("#edit_scene_form").find("input, button.rc-switch").each(function(index) {
promises.push(new Promise(async (resolve, reject) => {
const inputName = $(this).attr('name');
if(inputName == undefined)
return resolve();
let inputValue = $(this).val();
if ( ((inputName === 'player_map') || (inputName==='dm_map')) ) {
inputValue = await parse_img(inputValue);
}
else if ($(this).is("button")){
inputValue = $(this).hasClass("rc-switch-checked") ? "1" : "0"
}
data[inputName] = await inputValue;
resolve();
}))
})
await Promise.all(promises);
return data;
}
async function validate_image_input(element){
const self = element
$(`#${self.name}_validator`).remove()
// no value so can't validate, return early
if (self.value?.length === 0) return
if(self.value.startsWith("data:")){
$(element).val("URLs that start with 'data:' will cause crashes. URL has been removed");
return;
}
const img = await parse_img(self.value)
const validIcon = $(`<span id="${self.name}_validator" data-hover="Map image valid" class="sidebar-hovertext material-icons url-validator valid">check_circle_outline</span>`)
// default as valid
$(self).parent().css("position","relative")
$(self).before(validIcon)
$(self).attr("data-valid",true)
const display_not_valid = (hoverText) => {
$(self).prev().html("highlight_off")
$(self).prev().removeClass("valid loading")
$(self).prev().addClass("invalid")
$(self).prev().attr("data-hover", hoverText)
$(self).attr("data-valid", false)
$(self).addClass("chat-error-shake");
setTimeout(function () {
$(self).removeClass("chat-error-shake");
}, 150);
}
const display_unsure = () => {
$(self).prev().html("question_mark")
$(self).prev().attr("title")
$(self).prev().removeClass("valid loading")
$(self).prev().addClass("unsure")
$(self).prev().attr("data-hover", "URL is ok. Video/UVTT validation not available")
$(self).attr("data-valid", false)
}
let url
try {
url = new URL(img)
} catch (_) {
display_not_valid("URL is invalid")
return
}
let sceneData = window.ScenesHandler.scenes.filter(d => d.id == $('#edit_dialog').attr('data-scene-id'))[0];
if (sceneData.UVTTFile == 1 || $("#player_map_is_video_toggle").hasClass("rc-switch-checked") || $("#dm_map_is_video_toggle").hasClass("rc-switch-checked")){
display_unsure()
return
}
try{
function testImage(URL) {
const tester=new Image();
tester.onload=imageFound;
tester.onerror=imageNotFound;
tester.src=URL;
$(self).prev().removeClass("valid invalid")
$(self).prev().addClass("loading")
$(self).prev().html("autorenew")
}
function imageFound() {
$(self).prev().removeClass("loading invalid")
$(self).prev().addClass("valid")
$(self).prev().html("check_circle_outline")
}
function imageNotFound() {
display_not_valid("Image not found")
}
testImage(url);
} catch (_) {
display_not_valid("Image not found")
}
}
async function getUvttData(url){
return await throttleGoogleApi(async () => {
let api_url = url;
let jsonData = {};
if(api_url.startsWith('https://drive.google.com')){
api_url = await getGoogleDriveAPILink(api_url);
}
else if(api_url.includes('dropbox.com')){
let splitUrl = url.split('dropbox.com');
api_url = `https://dl.dropboxusercontent.com${splitUrl[splitUrl.length-1]}`
}
else if(url.includes("https://1drv.ms/"))
{
if(url.split('/')[4].length == 1){
alert('Your onedrive files are stored on sharepoint servers which prevents UVTT files from working')
}
else{
api_url = "https://api.onedrive.com/v1.0/shares/u!" + btoa(url) + "/root/content";
}
}
await $.getJSON(api_url, function(data){
jsonData = data;
});
return Promise.resolve(jsonData);
})
}
function getGoogleDriveAPILink(url){
return throttleGoogleApi(() => {
if (url.startsWith("https://drive.google.com") && url.indexOf("uc?id=") < 0 && url.indexOf("thumbnail?id=") < 0) {
const parsed = 'https://drive.google.com/uc?id=' + url.split('/')[5];
const fileid = parsed.split('=')[1];
url = `https://www.googleapis.com/drive/v3/files/${fileid}?alt=media&key=AIzaSyBcA_C2gXjTueKJY2iPbQbDvkZWrTzvs5I`;
}
else if (url.startsWith("https://drive.google.com") && (url.indexOf("uc?id=") > -1 || url.indexOf("thumbnail?id=") > -1 )) {
const fileid = url.split('=')[1].split('&')[0];
url = `https://www.googleapis.com/drive/v3/files/${fileid}?alt=media&key=AIzaSyBcA_C2gXjTueKJY2iPbQbDvkZWrTzvs5I`;
}
return url;
})
}
async function import_uvtt_scene_to_new_scene(url, title='New Scene', folderPath, parentId, doorType, doorHidden){
try{
let sceneData = await getUvttData(url);
let aboveSceneData = {
...create_full_scene_from_uvtt(sceneData, url, doorType, doorHidden),
title: title,
folderPath: folderPath,
parentId: parentId
} // this sets up scene data for import
await AboveApi.migrateScenes(window.gameId, [aboveSceneData]);
window.ScenesHandler.scenes.push(aboveSceneData);
did_update_scenes();
$(`.scene-item[data-scene-id='${aboveSceneData.id}'] .dm_scenes_button`).click();
$("#sources-import-main-container").remove();
expand_all_folders_up_to_id(aboveSceneData.id);
}
catch{
$("#sources-import-main-container").remove();
showError('Unexpected file format. The file may be on a host that does not support UVTT files or is not a UVTT file.')
}
}
async function get_map_from_uvtt_file(url){
let sceneData = await getUvttData(url);
return `data:image/png;base64,${sceneData.image}`
}
function create_full_scene_from_uvtt(data, url, doorType, doorHidden){ //this sets up scene data for import
DataFile = data;
/*
Even though grid size is provided in the UVTT we set it manually to prevent performance issues.
This should help in the majority of cases for now.
For larger maps we can consider dropping this to 25 and scaling up instead.
Similar to the grid wizard function consider_upscaling() but inverse where we look at the total size to determine grid size and scale.
Possibly when DataFile.resolution.map_size is > 100 on one side (this would mean 5000px for 50px squares - we often start to get reports of performance issues around this size)
*/
let gridSize = 50;
let sceneDrawings = []
let mapOriginX = DataFile.resolution.map_origin?.x != undefined ? DataFile.resolution.map_origin.x : 0;
let mapOriginY = DataFile.resolution.map_origin?.y != undefined ? DataFile.resolution.map_origin.y : 0;
let mapSizeX = DataFile.resolution.map_size.x;
let mapSizeY = DataFile.resolution.map_size.y;
for(let i = 0; i<DataFile.line_of_sight.length; i++){
for(let j = 1; j<DataFile.line_of_sight[i].length; j++){
if((DataFile.line_of_sight[i][j-1].x) < mapOriginX && (DataFile.line_of_sight[i][j].x) < mapOriginX){
continue;
}
if((DataFile.line_of_sight[i][j-1].y) < mapOriginY && (DataFile.line_of_sight[i][j].y) < mapOriginY){
continue;
}
if((DataFile.line_of_sight[i][j-1].x) > mapOriginX+mapSizeX && (DataFile.line_of_sight[i][j-1].x) > mapOriginX + mapSizeX){
continue;
}
if((DataFile.line_of_sight[i][j-1].y) > mapOriginY+mapSizeY && (DataFile.line_of_sight[i][j].y) > mapOriginY + mapSizeY){
continue;
}
sceneDrawings.push(['line',
'wall',
"rgba(0, 255, 0, 1)",
(DataFile.line_of_sight[i][j-1].x-mapOriginX)*gridSize,
(DataFile.line_of_sight[i][j-1].y-mapOriginY)*gridSize,
(DataFile.line_of_sight[i][j].x-mapOriginX)*gridSize,
(DataFile.line_of_sight[i][j].y-mapOriginY)*gridSize,
6,
1,
])
}
}
for(let i = 0; i<DataFile.portals.length; i++){
let closed = (DataFile.portals[i].closed) ? 'closed' : 'open'
let color = doorColors[doorType][closed];
if((DataFile.portals[i].bounds[0].x) < mapOriginX && (DataFile.portals[i].bounds[1].x) < mapOriginX){
continue;
}
if((DataFile.portals[i].bounds[0].y) < mapOriginY && (DataFile.portals[i].bounds[1].y) < mapOriginY){
continue;
}
if((DataFile.portals[i].bounds[0].x) > mapOriginX+mapSizeX && (DataFile.portals[i].bounds[1].x) > mapOriginX + mapSizeX){
continue;
}
if((DataFile.portals[i].bounds[0].y) > mapOriginY+mapSizeY && (DataFile.portals[i].bounds[1].y) > mapOriginY + mapSizeY){
continue;
}
sceneDrawings.push(['line',
'wall',
color,
(DataFile.portals[i].bounds[0].x-mapOriginX)*gridSize,
(DataFile.portals[i].bounds[0].y-mapOriginY)*gridSize,
(DataFile.portals[i].bounds[1].x-mapOriginX)*gridSize,
(DataFile.portals[i].bounds[1].y-mapOriginY)*gridSize,
12,
1,
doorHidden
])
}
function hexToRGB(hex, alpha) {
let r = parseInt(hex.slice(1, 3), 16),
g = parseInt(hex.slice(3, 5), 16),
b = parseInt(hex.slice(5, 7), 16);
if (alpha) {
return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
} else {
return "rgb(" + r + ", " + g + ", " + b + ")";
}
}
let sceneTokens = {};
for(let i = 0; i<DataFile.lights.length; i++){
if((DataFile.lights[i].position.x) < mapOriginX){
continue;
}
if((DataFile.lights[i].position.y) < mapOriginY){
continue;
}
if((DataFile.lights[i].position.x) > mapOriginX+mapSizeX){
continue;
}
if((DataFile.lights[i].position.y) > mapOriginY+mapSizeY){
continue;
}
let hexTransparency = parseInt(DataFile.lights[i].color.substring(DataFile.lights[i].color.length - 2, DataFile.lights[i].color.length), 16)/255;
let intensity = DataFile.lights[i].intensity;
let clippedColor = `#${(DataFile.lights[i].color.substring(0, DataFile.lights[i].color.length - 2))}`;
if(hexTransparency > 0)
intensity = intensity*hexTransparency;
let lightColor = hexToRGB(clippedColor, intensity);
let options = {
...default_options(),
imgsrc : `https://www.googleapis.com/drive/v3/files/1_QnkvmGct2dzeu-pBO9ofT-828pWvCcn?alt=media&key=AIzaSyBcA_C2gXjTueKJY2iPbQbDvkZWrTzvs5I`,
hidden : true,
tokenStyleSelect : 'definitelyNotAToken',
light1 : {
feet: `${DataFile.lights[i].range * parseInt(window.CURRENT_SCENE_DATA.fpsq)}`,
color: lightColor
},
light2 : {
feet: '0',
color: 'rgba(255, 255, 255, 0.5)'
},
vision : {
feet: '0',
color: 'rgba(255, 255, 255, 0.5)'
},
left : `${(DataFile.lights[i].position.x - mapOriginX) * gridSize - gridSize/4}px`,
top : `${(DataFile.lights[i].position.y - mapOriginY) * gridSize - gridSize/4}px`,
gridSquares: 0.5,
size: gridSize/2,
auraislight: true,
scaleCreated: 1
};
sceneTokens[options.id] = options;
}
let sceneData = {
...default_scene_data(),
'player_map': url,
'hpps': gridSize,
'vpps': gridSize,
'height': gridSize * DataFile.resolution.map_size.y,
'width': gridSize * DataFile.resolution.map_size.x,
'offsetx': 0,
'offsety': 0,
'scale_factor': 1,
'drawings': sceneDrawings,
'tokens': sceneTokens,
'UVTTFile': 1
};
return sceneData;
}
function open_grid_wizard_controls(scene_id, aligner1, aligner2, regrid=function(){}, copiedSceneData = window.CURRENT_SCENE_DATA) {
let scene = window.ScenesHandler.scenes[scene_id];
window.WIZARDING = true;
function form_row(name, title, inputOverride=null, imageValidation=false) {
const row = $(`<div style='width:100%;' id='${name}_row'/>`);
const rowLabel = $("<div style='display: inline-block; width:30%'>" + title + "</div>");
rowLabel.css("font-weight", "bold");
const rowInputWrapper = $("<div style='display:inline-block; width:60%; padding-right:8px' />");
let rowInput
if(!inputOverride){
if (imageValidation){
rowInput = $(`<input type="text" onClick="this.select();" name=${name} style='width:100%' autocomplete="off" value="${scene[name] || "" }" />`);
}else{
rowInput = $(`<input type="text" name=${name} style='width:100%' autocomplete="off" value="${scene[name] || ""}" />`);
}
}
else{
rowInput = inputOverride
}
rowInputWrapper.append(rowInput);
row.append(rowLabel);
row.append(rowInputWrapper);
return row
};
function form_toggle(name, hoverText, defaultOn, callback){
const toggle = $(
`<button id="${name}_toggle" name=${name} type="button" role="switch" data-hover="${hoverText}"
class="rc-switch sidebar-hovertext"><span class="rc-switch-inner" /></button>`)
if (!hoverText) toggle.removeClass("sidebar-hovertext")
toggle.on("click", callback)
if (scene[name] === "1" || defaultOn){
toggle.addClass("rc-switch-checked")
}
return toggle
}
async function handle_form_grid_on_change(){
// not editting this scene, don't show live updates to grid
if (scene.id !== window.CURRENT_SCENE_DATA.id){
return
}
const {hpps, vpps, offsetx, offsety, grid_color, grid_line_width, grid_subdivided, grid} = await get_edit_form_data()
// redraw grid with new information
if(grid === "1" && window.CURRENT_SCENE_DATA.scale_check){
let conversion = window.CURRENT_SCENE_DATA.scale_factor * window.CURRENT_SCENE_DATA.conversion
redraw_grid(parseFloat(hpps*conversion), parseFloat(vpps*conversion), offsetx*conversion, offsety*conversion, grid_color, grid_line_width, grid_subdivided )
}
else if(grid === "1"){
redraw_grid(parseFloat(hpps), parseFloat(vpps), offsetx, offsety, grid_color, grid_line_width, grid_subdivided )
}
// redraw grid using current scene data
else if(grid === "0"){
clear_grid()
}
}
$("#edit_dialog").remove();
scene.fog_of_war = "1"; // ALWAYS ON since 0.0.18
console.log('edit_scene_dialog');
$("#scene_selector").attr('disabled', 'disabled');
dialog = $(`<div id='edit_dialog' data-scene-id='${scene.id}'></div>`);
dialog.css('background', "url('/content/1-0-1487-0/skins/waterdeep/images/mon-summary/paper-texture.png')");
scene_properties = $('<div id="scene_properties"/>');
dialog.append(scene_properties);
adjust_create_import_edit_container(dialog, undefined, undefined, window.innerWidth-340, 340);
let container = scene_properties;
container.empty();
const form = $("<form id='edit_scene_form'/>");
form.on('submit', function(e) { e.preventDefault(); });
let uuid_hidden = $("<input name='uuid' type='hidden'/>");
uuid_hidden.val(scene['uuid']);
form.append(uuid_hidden);
let grid_buttons = $("<div/>");
let gridType = $(`
<div id="gridType">
<fieldset>
<legend>Select a grid type:</legend>
<div>
<input type="radio" id="squareGrid" name='grid' value="1" checked='checked'>
<label for="squareGrid">Square</label>
<input type="radio" id="horizontalHexGrid" name='grid' value="2">
<label for="horizontalHexGrid">Horizontal Hex</label>
<input type="radio" id="verticalHexGrid" name='grid' value="3">
<label for="verticalHexGrid">Vertical Hex</label>
</div>
</fieldset>
</div>`
);
gridType.find('input').on('change', function(){
window.CURRENT_SCENE_DATA.gridType = $(this).val();
if($(this).val() == 3){
$(scene_properties).toggleClass('verticalHex', true);
$(scene_properties).toggleClass('horizontalHex', false);
$('span.squaresWide').text(' hex columns');
$('#additionalGridInfo').toggleClass('closed', false);
$('#gridInstructions').text(`Top left draggable will position the hex grid, bottom right will adjust it's size. Use minor adjustment bars to skew the hex if it isn't a 'perfect hex' on the map. These bars will stretch/squash starting in the top left. To use manual options: Count the number of hex columns for sizing. If the hexes on the map are squashed/stretched at all use the minor adjustment sliders.`)
} else if($(this).val() == 2){
$(scene_properties).toggleClass('verticalHex', false);
$(scene_properties).toggleClass('horizontalHex', true);
$('span.squaresTall').text(` hex rows`);
$('#additionalGridInfo').toggleClass('closed', false);
$('#gridInstructions').text(`Top left draggable will position the hex grid, bottom right will adjust it's size. Use minor adjustment bars to skew the hex if it isn't a 'perfect hex' on the map. These bars will stretch/squash starting in the top left. To use manual options: Count the number of hex rows for sizing. If the hexes on the map are squashed/stretched at all use the minor adjustment sliders.`)
} else if($(this).val() == 1){
$(scene_properties).toggleClass('verticalHex', false);
$(scene_properties).toggleClass('horizontalHex', false);
$('span.squaresTall').text(' squares tall');
$('span.squaresWide').text(' squares wide');
$('#verticalMinorAdjustment label').text('Minor Vertical Adjustment')
$('#horizontalMinorAdjustment label').text('Minor Horizontal Adjustment')
$('#gridInstructions').text(`Select a 3x3 square using the selectors to align your grid.`)
$('input[name="fpsq"]').trigger('change');
}
regrid();
})
let verticalMinorAdjustment = $(`<div id="verticalMinorAdjustment">
<label for="verticalMinorAdjustmentInput">Minor Vertical Adjustment</label>
<input type="range" name='verticalMinorAdjustmentInput' min="1" max="100" value="50" class="slider" id="verticalMinorAdjustmentInput" data-orientation="vertical">
<button id="resetMinorVerticalAdjustmentRange">Reset</button>
</div>`);
let horizontalMinorAdjustment = $(`<div id="horizontalMinorAdjustment">
<label for="horizontalMinorAdjustmentInput">Minor Horizontal Adjustment</label>
<input type="range" name='horizontalMinorAdjustmentInput' min="1" max="100" value="50" class="slider" id="horizontalMinorAdjustmentInput">
<button id="resetMinorHorizontalAdjustmentRange">Reset</button>
</div>`);
horizontalMinorAdjustment.find('#resetMinorHorizontalAdjustmentRange').on('click', function(){
$("#horizontalMinorAdjustmentInput").val('50');
horizontalMinorAdjustment.find('input').trigger('change');
})
verticalMinorAdjustment.find('#resetMinorVerticalAdjustmentRange').on('click', function(){
$("#verticalMinorAdjustmentInput").val('50');
verticalMinorAdjustment.find('input').trigger('change');
})
verticalMinorAdjustment.find('input').on('change input',function(){
if(window.CURRENT_SCENE_DATA.gridType == 1){
window.CURRENT_SCENE_DATA.vpps = $("#scene_map").height()/parseFloat($('#squaresTall').val());
window.CURRENT_SCENE_DATA.hpps = $("#scene_map").width()/parseFloat($('#squaresWide').val());
}
else{
window.CURRENT_SCENE_DATA.scaleAdjustment = {
x: 1 + ($('#horizontalMinorAdjustmentInput').val()-50)/500,
y: 1 + ($('#verticalMinorAdjustmentInput').val()-50)/500
}
}
moveAligners(false, true);
console.log('verticalMinorAdjustment');
});
horizontalMinorAdjustment.find('input').on('change input',function(){
if(window.CURRENT_SCENE_DATA.gridType == 1){
window.CURRENT_SCENE_DATA.vpps = $("#scene_map").height()/parseFloat($('#squaresTall').val());
window.CURRENT_SCENE_DATA.hpps = $("#scene_map").width()/parseFloat($('#squaresWide').val());
}
else{
window.CURRENT_SCENE_DATA.scaleAdjustment = {
x: 1 + ($('#horizontalMinorAdjustmentInput').val()-50)/500,
y: 1 + ($('#verticalMinorAdjustmentInput').val()-50)/500
}
}
moveAligners(false, true);
console.log('horizontalMinorAdjustment');
});
form.append(gridType, verticalMinorAdjustment, horizontalMinorAdjustment)
let manual = $("<div id='manual_grid_data'/>");
manual.append($(`
<div id='linkAligners' title='Locks the draggable grid aligners to 1:1 aspect ratio' class='hideHex'><div style='display:inline-block; width:40%'>Link Aligners 1:1</div><input style='display: none;' type='number' min='0' max='1' step='1' name='alignersLinked'></div></div>
<div title='The size the ruler will measure a side of a square.'><div style='display:inline-block; width:40%'>Measurement:</div><div style='display:inline-block; width:60'%'><input type='number' name='fpsq' placeholder='5' value='${window.CURRENT_SCENE_DATA.fpsq}'> <input name='upsq' placeholder='ft' value='${window.CURRENT_SCENE_DATA.upsq}'></div></div>
<div id='gridSubdividedRow' class='hideHex' style='display: ${(window.CURRENT_SCENE_DATA.fpsq == 10 || window.CURRENT_SCENE_DATA.fpsq == 15 || window.CURRENT_SCENE_DATA.fpsq == 20) ? 'block' : 'none'}' title='Split grid into 5ft sections'><div style='display:inline-block; width:40%'>Split into 5ft squares</div><div style='display:inline-block; width:60'%'><input style='display: none;' type='number' min='0' max='1' step='1' name='grid_subdivided'></div></div>
<div id='additionalGridInfo' class='closed'>Additional Grid Info / Manual Settings</div>
<div title='Number of grid squares Width x Height.'><div style='display:inline-block; width:30%'>Grid size</div><div style='display:inline-block;width:70%;'><input id='squaresWide' class='hideHorizontalHex' type='number' min='10' value='${$("#scene_map").width()/window.CURRENT_SCENE_DATA.hpps}'><span style='display: inline' class='squaresWide hideHorizontalHex'> squares wide</span><br class='hideHorizontalHex'/><input type='number' id='squaresTall' class='hideVerticalHex' value='${$("#scene_map").height()/window.CURRENT_SCENE_DATA.vpps}' min='10'><span style='display: inline' class='squaresTall hideVerticalHex'> squares tall</span></div></div>
<div title='Grid offset from the sides of the map in pixels. From top left corner of square and from middle of hex.'>
<div style='display:inline-block; width:30%'>Offset</div><div style='display:inline-block;width:70%;'>
<input type='number' name='offsetx'>px from left<br/>
<input type='number' name='offsety'>px from top
</div>
</div>
`));
manual.find('#linkAligners').append(form_toggle("linkAlignersToggle",null, false, function(event) {
handle_basic_form_toggle_click(event);
if ($(event.currentTarget).hasClass("rc-switch-checked")) {
manual.find("#linkAligners input").val('1');
} else {
manual.find("#linkAligners input").val('0');
}
}));
manual.find('#gridSubdividedRow').append(form_toggle("gridSubdividedToggle",null, false, function(event) {
handle_basic_form_toggle_click(event);
if ($(event.currentTarget).hasClass("rc-switch-checked")) {
manual.find("#gridSubdividedRow input").val('1');
} else {
manual.find("#gridSubdividedRow input").val('0');
}
window.CURRENT_SCENE_DATA.grid_subdivided = $(this).val();
}));
manual.find('input[name="fpsq"]').on('change blur', function(){
if(window.CURRENT_SCENE_DATA.gridType == 1 && $(this).val() == 10 || $(this).val() == 15 || $(this).val() == 20){
$('#gridSubdividedRow').css('display', 'block');
$('#gridInstructions').text(`Select a 3x3 square using the selectors to align your grid. To change the grid to be appropriately sized for medium creatures enable split grid.`)
}
else{
$("#gridSubdividedRow input").val('0');
$('#gridSubdividedRow').css('display', 'none');
$('#gridInstructions').text(`Select a 3x3 square using the selectors to align your grid.`)
}
window.CURRENT_SCENE_DATA.fpsq = $(this).val();
});
manual.find('input[name="upsq"]').on('change blur', function(){
window.CURRENT_SCENE_DATA.upsq = $(this).val();
});
manual.find('#additionalGridInfo').on('click', function(){
$(this).toggleClass('closed');
})
manual.find('#squaresWide').on('blur change', function(){
window.CURRENT_SCENE_DATA.vpps = $("#scene_map").height()/parseFloat($('#squaresTall').val());
window.CURRENT_SCENE_DATA.hpps = $("#scene_map").width()/parseFloat($('#squaresWide').val());
moveAligners(true)
});
manual.find('#squaresTall').on('blur change', function(){
window.CURRENT_SCENE_DATA.vpps = $("#scene_map").height()/parseFloat($('#squaresTall').val());
window.CURRENT_SCENE_DATA.hpps = $("#scene_map").width()/parseFloat($('#squaresWide').val());
moveAligners(true)
})
manual.find('input[name="offsetx"]').on('blur change', function(){
window.CURRENT_SCENE_DATA.vpps = $("#scene_map").height()/parseFloat($('#squaresTall').val());
window.CURRENT_SCENE_DATA.hpps = $("#scene_map").width()/parseFloat($('#squaresWide').val());
let withoutOffset = parseFloat($('#aligner1').css("left")) - parseFloat($(this).attr('data-prev-value'));
window.CURRENT_SCENE_DATA.offsetx = parseFloat($(this).val());
$(this).attr('data-prev-value', window.CURRENT_SCENE_DATA.offsetx);
$('#aligner1').css("left", withoutOffset+window.CURRENT_SCENE_DATA.offsetx);
moveAligners(true)
})
manual.find('input[name="offsety"]').on('blur change', function(){
window.CURRENT_SCENE_DATA.vpps = $("#scene_map").height()/parseFloat($('#squaresTall').val());
window.CURRENT_SCENE_DATA.hpps = $("#scene_map").width()/parseFloat($('#squaresWide').val());
let withoutOffset = parseFloat($('#aligner1').css("top")) - parseFloat($(this).attr('data-prev-value'));
window.CURRENT_SCENE_DATA.offsety = parseFloat($(this).val());
$(this).attr('data-prev-value', window.CURRENT_SCENE_DATA.offsety);
$('#aligner1').css("top", withoutOffset+window.CURRENT_SCENE_DATA.offsety);
moveAligners(true)
})
manual.find('input').on('keydown.enter', function(e){
if (e.keyCode == 13) {
e.preventDefault();
$(this).trigger('change')
let nextVisibleInput = $('#scene_properties input:visible')[$('#scene_properties input:visible').index(this)+1]
if(nextVisibleInput)
nextVisibleInput.select();
}
})
manual.find('input').on('click.select', function(e){
$(this).select();
})
let moveAligners = function(moveAligner1 = false, minorAdjustments = false){
let width
if (window.ScenesHandler.scene.upscaled == "1")
width = 2;
else
width = 1;
const dash = [30, 5]
const color = "rgba(255, 0, 0,0.5)";
window.CURRENT_SCENE_DATA.gridType = $('#gridType input:checked').val();
if(manual.find('input[name="offsety"]').val()== undefined || manual.find('input[name="offsetx"]').val()==undefined || (manual.find('#squaresTall').val()==undefined || manual.find('#squaresWide').val()==undefined ))
return;
if(window.CURRENT_SCENE_DATA.gridType == 1){
let adjustmentSliders = {
x: ($('#horizontalMinorAdjustmentInput').val()-50)/10,
y: ($('#verticalMinorAdjustmentInput').val()-50)/10,
}
window.CURRENT_SCENE_DATA.hpps += adjustmentSliders.x;
window.CURRENT_SCENE_DATA.vpps += adjustmentSliders.y;
window.CURRENT_SCENE_DATA.offsetx = parseFloat($('input[name="offsetx"]').val());
window.CURRENT_SCENE_DATA.offsety = parseFloat($('input[name="offsety"]').val());
if(moveAligner1){
$('#aligner1').css({
'top': `${(Math.floor(($('#scene_map').height()/2)/window.CURRENT_SCENE_DATA.vpps)-1)*window.CURRENT_SCENE_DATA.vpps + window.CURRENT_SCENE_DATA.offsety - 29}px`,
'left': `${(Math.floor(($('#scene_map').width()/2)/window.CURRENT_SCENE_DATA.hpps)-1)*window.CURRENT_SCENE_DATA.hpps + window.CURRENT_SCENE_DATA.offsetx - 29}px`
});
}
$('#aligner2').css({
"left": `${parseFloat($('#aligner1').css("left")) + window.CURRENT_SCENE_DATA.hpps*3}px`,
"top": `${parseFloat($('#aligner1').css("top")) + window.CURRENT_SCENE_DATA.vpps*3}px`
})
if(minorAdjustments){
let al1 = {
x: parseInt(aligner1.css("left")) + 29,
y: parseInt(aligner1.css("top")) + 29,
};
window.CURRENT_SCENE_DATA.offsetx = al1.x % window.CURRENT_SCENE_DATA.hpps;
window.CURRENT_SCENE_DATA.offsety = al1.y % window.CURRENT_SCENE_DATA.vpps;
$('input[name="offsetx"]').val(`${window.CURRENT_SCENE_DATA.offsetx}`)
$('input[name="offsety"]').val(`${window.CURRENT_SCENE_DATA.offsety}`)
$('input[name="offsetx"]').attr('data-prev-value', window.CURRENT_SCENE_DATA.offsetx);
$('input[name="offsety"]').attr('data-prev-value', window.CURRENT_SCENE_DATA.offsety);
}
redraw_grid(null,null,null,null,color,width,null,dash);
}
else if(window.CURRENT_SCENE_DATA.gridType == 2){
redraw_hex_grid(null,null,null,null,color,width,null,dash, false);
}
else if(window.CURRENT_SCENE_DATA.gridType == 3){
redraw_hex_grid(null,null,null,null,color,width,null,dash, true);
}
//to do: move the grid aligners to match the input settings.
}
manual.find("input").each(function() {
$(this).css("width", "60px");
$(this).val(scene[$(this).attr('name')]);
})
form.append(manual);
form.append(`
<div style='margin-top:20px; font-size:11px; font-weight: bold'>Instructions:</div>
<div style='font-size:11px;' id='gridInstructions'>Select a 3x3 square using the selectors to align your grid.</div>
<div style='margin-top:20px; font-size:11px; font-weight: bold'>Hover settings for more info</div>
`);
if (typeof scene.fog_of_war == "undefined")
scene.fog_of_war = "1";
const submitButton = $("<button type='button'>Save</button>");
submitButton.click(function() {
remove_zoom_from_storage()
$('[id="aligner1"]').remove();
$('[id="aligner2"]').remove();
let gridMeasurement = $('input[name="fpsq"]').val();
if(gridMeasurement == 5){
grid_5();
}else if(gridMeasurement == 10){
grid_10();
}else if(gridMeasurement == 15){
grid_15();
}else if(gridMeasurement == 20){
grid_20();
}else{
$("#scene_selector_toggle").show();
$("#tokens").show();
window.WIZARDING = false;
window.CURRENT_SCENE_DATA = {
...window.CURRENT_SCENE_DATA,
upsq: $('input[name="upsq"]').val(),
fpsq: $('input[name="fpsq"]').val(),
grid_subdivided: "0"
}
consider_upscaling(window.CURRENT_SCENE_DATA);
window.ScenesHandler.persist_current_scene();
$("#wizard_popup").empty().append("You're good to go!!");
$("#exitWizard").remove();
$("#wizard_popup").delay(2000).animate({ opacity: 0 }, 4000, function() {
$("#wizard_popup").remove();
});
$("#light_container, #darkness_layer, #raycastingCanvas").css('visibility', 'visible');
}
$(`#sources-import-main-container`).remove();
$('#scene_map_container').css('background', '');
});
let grid_5 = function() {
$("#scene_selector_toggle").show();
$("#tokens").show();
window.WIZARDING = false;
window.CURRENT_SCENE_DATA = {
...window.CURRENT_SCENE_DATA,
fpsq: "5",
grid_subdivided: "0"
}
consider_upscaling(window.CURRENT_SCENE_DATA);
window.ScenesHandler.persist_current_scene();
$("#light_container").css('visibility', 'visible');
$("#darkness_layer").css('visibility', 'visible');
};
let grid_10 = function() {
window.WIZARDING = false;
let subdivided = $('input[name="grid_subdivided"]').val() == 1;
$("#scene_selector_toggle").show();
$("#tokens").show();
$("#wizard_popup").empty().append("You're good to go! AboveVTT is now super-imposing a grid that divides the original grid map in half. If you want to hide this grid just edit the manual grid data.");
window.CURRENT_SCENE_DATA = {
...window.CURRENT_SCENE_DATA,
hpps: (subdivided) ? window.CURRENT_SCENE_DATA.hpps/2 : window.CURRENT_SCENE_DATA.hpps,
vpps: (subdivided) ? window.CURRENT_SCENE_DATA.vpps/2 : window.CURRENT_SCENE_DATA.vpps,
fpsq: (subdivided) ? '5' : '10',
grid_subdivided: $('input[name="grid_subdivided"]').val()
}
consider_upscaling(window.CURRENT_SCENE_DATA);
window.ScenesHandler.persist_current_scene();
$("#light_container").css('visibility', 'visible');
$("#darkness_layer").css('visibility', 'visible');
}
let grid_15 = function() {
window.WIZARDING = false;
let subdivided = $('input[name="grid_subdivided"]').val() == 1;
$("#scene_selector_toggle").show();
$("#tokens").show();
window.CURRENT_SCENE_DATA = {
...window.CURRENT_SCENE_DATA,
hpps: (subdivided) ? window.CURRENT_SCENE_DATA.hpps/3 : window.CURRENT_SCENE_DATA.hpps,
vpps: (subdivided) ? window.CURRENT_SCENE_DATA.vpps/3 : window.CURRENT_SCENE_DATA.vpps,
fpsq: (subdivided) ? '5' : '15',
grid_subdivided: "0"
}
consider_upscaling(window.CURRENT_SCENE_DATA);
window.ScenesHandler.persist_current_scene();
$("#light_container").css('visibility', 'visible');
$("#darkness_layer").css('visibility', 'visible');
}
let grid_20 = function() {
window.WIZARDING = false;
let subdivided = $('input[name="grid_subdivided"]').val() == 1;
$("#scene_selector_toggle").show();
$("#tokens").show();
window.CURRENT_SCENE_DATA = {
...window.CURRENT_SCENE_DATA,
hpps: (subdivided) ? window.CURRENT_SCENE_DATA.hpps/4 : window.CURRENT_SCENE_DATA.hpps,
vpps: (subdivided) ? window.CURRENT_SCENE_DATA.vpps/4 : window.CURRENT_SCENE_DATA.vpps,
fpsq: (subdivided) ? '5' : '20',
grid_subdivided: "0"
}
consider_upscaling(window.CURRENT_SCENE_DATA);
window.ScenesHandler.persist_current_scene();
$("#light_container").css('visibility', 'visible');
$("#darkness_layer").css('visibility', 'visible');
}
cancel = $("<button type='button' id='cancel_importer'>Cancel</button>");
cancel.click(function() {
$('[id="aligner1"]').remove();
$('[id="aligner2"]').remove();
window.WIZARDING = false;
window.ScenesHandler.scenes[window.ScenesHandler.current_scene_id] = copiedSceneData;
window.ScenesHandler.scene = copiedSceneData;
window.CURRENT_SCENE_DATA = copiedSceneData;
window.ScenesHandler.persist_current_scene();
$("#light_container").css('visibility', 'visible');
$("#darkness_layer").css('visibility', 'visible');
$("#tokens").show();
$(`#sources-import-main-container`).remove();
})
form.append(submitButton);
form.append(cancel);
container.css('opacity', '0.0');
container.append(form);
container.animate({
opacity: '1.0'
}, 1000);
}
function edit_scene_vision_settings(scene_id){
let scene = window.ScenesHandler.scenes[scene_id];
function form_row(name, title, inputOverride=null, imageValidation=false) {
const row = $(`<div class='lightRow' id='${name}_row'/>`);
const rowLabel = $("<div class='lightRowLabel'>" + title + "</div>");
rowLabel.css("font-weight", "700");
const rowInputWrapper = $("<div style='display:inline-block; flex-grow: 1; padding-right:8px' />");
let rowInput
if(!inputOverride){
if (imageValidation){
rowInput = $(`<input type="text" onClick="this.select();" name=${name} style='width:100%;' autocomplete="off" value="${scene[name] || "" }" />`);
}else{
rowInput = $(`<input type="text" name=${name} style='width:100%' autocomplete="off" value="${scene[name] || ""}" />`);
}
}
else{
rowInput = inputOverride
}
rowInput.toggleClass('lightRowInput', true)
rowInputWrapper.append(rowInput);
row.append(rowLabel);
row.append(rowInputWrapper);
return row
};
function form_toggle(name, hoverText, defaultOn, callback){
const toggle = $(
`<button id="${name}_toggle" name=${name} type="button" role="switch" data-hover="${hoverText}"
class="rc-switch sidebar-hovertext"><span class="rc-switch-inner" /></button>`)
if (!hoverText) toggle.removeClass("sidebar-hovertext")
toggle.on("click", callback)
if (scene[name] === "1" || defaultOn){
toggle.addClass("rc-switch-checked")
}
return toggle
}
$("#edit_dialog").remove();
scene.fog_of_war = "1"; // ALWAYS ON since 0.0.18
console.log('edit_scene_dialog');
$("#scene_selector").attr('disabled', 'disabled');
dialog = $(`<div id='edit_dialog' data-scene-id='${scene.id}'></div>`);
dialog.css('background', "url('/content/1-0-1487-0/skins/waterdeep/images/mon-summary/paper-texture.png')");
scene_properties = $('<div id="scene_properties"/>');
dialog.append(scene_properties);
adjust_create_import_edit_container(dialog, undefined, undefined, 1000);
let container = scene_properties;
container.empty();
const form = $("<form id='edit_scene_form'/>");
form.on('submit', function(e) { e.preventDefault(); });
let uuid_hidden = $("<input name='uuid' type='hidden'/>");
uuid_hidden.val(scene['uuid']);
form.append(uuid_hidden);
let darknessValue = scene.darkness_filter || 0;
let darknessFilterRange = $(`<input name="darkness_filter" class="darkness-filter-range" type="range" value="${darknessValue}" min="0" max="100" step="1"/>`);
let darknessNumberInput = $(`<input name='darkness_filter_number' class='styled-number-input' type='number' min='0' max='100' value='${darknessValue}'/>`)
darknessFilterRange.on('input change', function(){
$("#darkness_layer").toggleClass("smooth-transition", true);
let darknessFilterRangeValue = parseInt(darknessFilterRange.val());
let darknessPercent = 100 - darknessFilterRangeValue;
if(window.CURRENT_SCENE_DATA.id == window.ScenesHandler.scenes[scene_id].id) {
$('#VTT').css('--darkness-filter', darknessPercent + "%");
}
setTimeout(function(){
$("#darkness_layer").toggleClass("smooth-transition", false);
}, 400);
darknessNumberInput.val(darknessFilterRange.val());
if(darknessFilterRange.val() == 100){
playerPreviewHiddenMap.toggleClass('selected', true);
playerPreviewVisibleMap.toggleClass('selected', false);
}
else{
playerPreviewHiddenMap.toggleClass('selected', false);
playerPreviewVisibleMap.toggleClass('selected', true);
}
});
darknessFilterRange.on('mouseup', function(){
let darknessFilterRangeValue = parseInt(darknessFilterRange.val());
scene.darkness_filter = darknessFilterRangeValue;
});
form.append(form_row('disableSceneVision',
'Disable token vision/light',
form_toggle("disableSceneVision",null, false, function(event) {
handle_basic_form_toggle_click(event);
})
)
);
form.append(form_row('darknessFilter',
'Line of Sight/Darkness Opacity',
darknessFilterRange)
);
form.find('#darknessFilter_row').attr('title', `This will darken the map by the percentage indicated. This filter interacts with light auras. Any light aura on the map will reveal the darkness. Fully opaque white light will completely eliminate the darkness in it's area.`)
darknessFilterRange.after(darknessNumberInput);