forked from cyruzzo/AboveVTT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScenesPanel.js
1096 lines (871 loc) · 33 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.scale_factor=2;
target.hpps *= 2;
target.vpps *= 2;
target.offsetx*=2;
target.offsety*=2;
}
else if(target.hpps <=25){
target.scale_factor=4;
target.hpps *= 4;
target.vpps *= 4;
target.offsetx*=4;
target.offsety*=4;
}
else{
target.scale_factor=1;
}
}
function preset_importer(target, key) {
target.empty();
let sel = $("<select/>");
for (var i = 0; i < PRESET[key].length; i++) {
cur = PRESET[key][i];
o = $("<option/>");
o.html(cur.title);
o.val(i);
sel.append(o);
}
import_button = $("<button>IMPORT</button>");
import_button.click(function() {
i = sel.val();
scene = PRESET[key][i];
$("#scene_properties input[name='player_map']").val(scene.player_map);
$("#scene_properties input[name='dm_map']").val(scene.dm_map);
$("#scene_properties input[name='title']").val(scene.title);
$("#scene_properties input[name='scale']").val(scene.scale);
});
target.append(sel);
target.append(import_button);
}
function edit_scene_dialog(scene_id) {
let scene = window.ScenesHandler.scenes[scene_id];
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'></div>");
dialog.css('background', "url('/content/1-0-1487-0/skins/waterdeep/images/mon-summary/paper-texture.png')");
template_section = $("<div id='template_section'/>");
dialog.append(template_section);
controls = $("<div/>");
controls.append("Import Template FROM:");
toggle_ddb = $("<button>DnDBeyond.com</button>")
toggle_ddb.click(function() {
mega_importer(true);
});
controls.append(toggle_ddb);
toggle_grimorium = $("<button>FREE MAPS</button>");
toggle_grimorium.click(function() {
mega_importer();
});
controls.append(toggle_grimorium);
template_section.append(controls);
scene_properties = $('<div id="scene_properties"/>');
dialog.append(scene_properties);
dialog.css('position', 'fixed');
dialog.css('width', '600px');
dialog.css('top', '100px');
dialog.css('left', '300px');
dialog.css('height', '350px');
dialog.css('z-index', 99999);
dialog.css('border', 'solid 1px black');
$("#site").append(dialog);
var container = scene_properties;
container.empty();
let f = $("<form />");
f.on('submit', function(e) { e.preventDefault(); });
let addrow = function(name, title, type = 'text') {
var row = $("<div style='width:100%;'/>");
var c1 = $("<div style='display: inline-block; width:30%'>" + title + "</div>");
c1.css("font-weight", "bold");
var c2 = $("<div style='display:inline-block; width:70%'/>");
var i = $("<input />");
i.attr('type', type);
i.attr('name', name);
i.val(scene[name]);
i.css("width", "70%");
c2.append(i);
row.append(c1);
row.append(c2);
f.append(row);
};
var uuid_hidden = $("<input name='uuid' type='hidden'/>");
uuid_hidden.val(scene['uuid']);
f.append(uuid_hidden);
addrow('title', 'Scene Title');
addrow('player_map', 'Player Map');
addrow('dm_map', 'Dm Map');
addrow('dm_map_usable', 'Use DM Map (1 to enable)');
wizard = $("<button><b>Super Mega Wizard</b></button>");
manual_button = $("<button>Manual Grid Data</button>");
grid_buttons = $("<div style='display:inline-block; width:70%'/>");
grid_buttons.append(wizard);
grid_buttons.append(manual_button);
f.append($("<div><div style='display:inline-block;width:30%'><b>Grid and Scale</b></div></div>").append(grid_buttons));
var manual = $("<div/>");
manual.append($("<div><div style='display:inline-block; width:30%'>Grid size in original image</div><div style='display:inline-block;width:70%;'><input name='hpps'> X <input name='vpps'></div></div>"));
manual.append($("<div><div style='display:inline-block; width:30%'>Offset</div><div style='display:inline-block;width:70%;'><input name='offsetx'> X <input name='offsety'></div></div>"));
manual.append($("<div><div style='display:inline-block; width:30%'>Snap to Grid(1 to enable)</div><div style='display:inline-block; width:70'%'><input name='snap'></div></div>"));
manual.append($("<div><div style='display:inline-block; width:30%'>Show Grid(1 to enable)</div><div style='display:inline-block; width:70'%'><input name='grid'></div></div>"));
manual.append($("<div><div style='display:inline-block; width:30%'>Foot per square</div><div style='display:inline-block; width:70'%'><input name='fpsq'></div></div>"));
manual.append($("<div><div style='display:inline-block; width:30%'>Grid is a subdivided 10ft</div><div style='display:inline-block; width:70'%'><input name='grid_subdivided'></div></div>"));
manual.append($("<div><div style='display:inline-block; width:30%'>Image Scale Factor</div><div style='display:inline-block; width:70'%'><input name='scale_factor'></div></div>"));
manual.hide();
manual.find("input").each(function() {
$(this).css("width", "60px");
$(this).val(scene[$(this).attr('name')]);
})
f.append(manual);
manual_button.click(function() {
if (manual.is(":visible"))
manual.hide();
else
manual.show();
});
if (typeof scene.fog_of_war == "undefined")
scene.fog_of_war = "1";
var sub = $("<button>Save And Switch</button>");
sub.click(function() {
f.find("input").each(function() {
var n = $(this).attr('name');
let nValue = $(this).val();
if (n === 'player_map'
&& nValue.startsWith("https://drive.google.com")
&& nValue.indexOf("uc?id=") < 0
) {
nValue = 'https://drive.google.com/uc?id=' + nValue.split('/')[5];
}
scene[n] = nValue;
console.log('setto ' + n + ' a ' + $(this).val());
});
window.ScenesHandler.persist();
window.ScenesHandler.switch_scene(scene_id);
$("#edit_dialog").remove();
$("#scene_selector").removeAttr("disabled");
$("#scene_selector_toggle").click();
});
let grid_5 = function(enable_grid = false, enable_snap = true) {
console.log("enable_grid " + enable_grid + " enable_snap" + enable_snap);
$("#scene_selector_toggle").show();
$("#tokens").show();
window.WIZARDING = false;
if (enable_snap)
window.ScenesHandler.scene.snap = "1";
else
window.ScenesHandler.scene.snap = "0";
if (enable_grid)
window.ScenesHandler.scene.grid = "1";
else
window.ScenesHandler.scene.grid = "0";
window.ScenesHandler.scene.fpsq = "5";
window.ScenesHandler.scene.grid_subdivided = "0";
consider_upscaling(window.ScenesHandler.scene);
window.ScenesHandler.persist();
window.ScenesHandler.reload();
$("#wizard_popup").empty().append("You're good to go!!");
$("#wizard_popup").delay(2000).animate({ opacity: 0 }, 4000, function() {
$("#wizard_popup").remove();
});
};
let grid_10 = function() {
$("#wizard_popup").empty().append("Do you want me to subdivide the map grid in 2 so you can get correct token size? <button id='grid_divide'>Yes</button> <button id='grid_nodivide'>No</button>");
$("#grid_divide").click(function() {
window.WIZARDING = false;
$("#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.ScenesHandler.scene.grid_subdivided = "1";
window.ScenesHandler.scene.snap = "1";
window.ScenesHandler.scene.grid = "1";
window.ScenesHandler.scene.fpsq = "5";
window.ScenesHandler.scene.hpps /= 2;
window.ScenesHandler.scene.vpps /= 2;
consider_upscaling(window.ScenesHandler.scene);
$("#wizard_popup").delay(5000).animate({ opacity: 0 }, 4000, function() {
$("#wizard_popup").remove();
});
window.ScenesHandler.persist();
window.ScenesHandler.reload();
});
$("#grid_nodivide").click(function() {
window.WIZARDING = false;
$("#scene_selector_toggle").show();
$("#tokens").show();
window.ScenesHandler.scene.snap = "1";
window.ScenesHandler.scene.grid_subdivided = "0";
window.ScenesHandler.scene.grid = "0";
window.ScenesHandler.scene.fpsq = "10";
consider_upscaling(window.ScenesHandler.scene);
window.ScenesHandler.persist();
window.ScenesHandler.reload();
$("#wizard_popup").empty().append("You're good to go! Medium token will match the original grid size");
$("#wizard_popup").delay(5000).animate({ opacity: 0 }, 4000, function() {
$("#wizard_popup").remove();
});
});
}
let grid_15 = function() {
window.WIZARDING = false;
$("#scene_selector_toggle").show();
$("#tokens").show();
$("#wizard_popup").empty().append("You're good to go! Token will be of the correct scale and snapping is enabled. We don't currently support overimposing a grid in this scale..'");
window.ScenesHandler.scene.grid_subdivided = "0";
window.ScenesHandler.scene.snap = "1";
window.ScenesHandler.scene.grid = "0";
window.ScenesHandler.scene.fpsq = "5";
window.ScenesHandler.scene.hpps /= 3;
window.ScenesHandler.scene.vpps /= 3;
consider_upscaling(window.ScenesHandler.scene);
$("#wizard_popup").delay(5000).animate({ opacity: 0 }, 4000, function() {
$("#wizard_popup").remove();
});
window.ScenesHandler.persist();
window.ScenesHandler.reload();
}
let grid_20 = function() {
window.WIZARDING = false;
$("#scene_selector_toggle").show();
$("#tokens").show();
$("#wizard_popup").empty().append("You're good to go! Token will be of the correct scale and snapping is enabled.");
window.ScenesHandler.scene.grid_subdivided = "0";
window.ScenesHandler.scene.snap = "1";
window.ScenesHandler.scene.grid = "1";
window.ScenesHandler.scene.fpsq = "5";
window.ScenesHandler.scene.hpps /= 4;
window.ScenesHandler.scene.vpps /= 4;
consider_upscaling(window.ScenesHandler.scene);
$("#wizard_popup").delay(5000).animate({ opacity: 0 }, 4000, function() {
$("#wizard_popup").remove();
});
window.ScenesHandler.persist();
window.ScenesHandler.reload();
}
let align_grid = function(square = false, just_rescaling = true) {
/*window.ScenesHandler.persist();*/
window.ScenesHandler.switch_scene(scene_id, function() {
$("#tokens").hide();
if (!just_rescaling)
window.CURRENT_SCENE_DATA.grid = "1";
else
window.CURRENT_SCENE_DATA.grid = "0";
window.CURRENT_SCENE_DATA.grid_subdivided = "0";
window.CURRENT_SCENE_DATA.scale_factor=1;
var aligner1 = $("<canvas id='aligner1'/>");
aligner1.width(59);
aligner1.height(59);
aligner1.css("position", "absolute");
aligner1.css("border-radius", "50%");
aligner1.css("top", ($("#scene_map").height() / 2) + "px");
aligner1.css("left", ($("#scene_map").width() / 2) + "px");
aligner1.css("z-index", 40);
drawX = function(canvas) {
var ctx = canvas.getContext("2d");
ctx.strokeStyle = "red";
ctx.lineWidth = 1;
ctx.setLineDash([10, 10, 19, 10, 10]);
ctx.beginPath();
ctx.moveTo(29, 0);
ctx.lineTo(29, 58);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, 29);
ctx.lineTo(58, 29);
ctx.stroke();
};
var canvas1 = aligner1.get(0);
var ctx = canvas1.getContext("2d");
canvas1.width = 59;
canvas1.height = 59;
ctx.fillStyle = "rgba(255, 255, 255, 0.2)";
ctx.fillRect(0, 0, canvas1.width, canvas1.height);
if (square)
ctx.fillStyle = "rgba(255,0,0,0.5)";
else
ctx.fillStyle = "rgba(0,255,0,0.5)";
ctx.fillRect(0, 0, 59, 29);
ctx.fillRect(0, 29, 29, 29);
drawX(canvas1);
var aligner2 = $("<canvas id='aligner2'/>");
aligner2.width(59);
aligner2.height(59);
aligner2.css("position", "absolute");
aligner2.css("border-radius", "50%");
if (!just_rescaling) {
aligner2.css("top", ($("#scene_map").height() / 2) + 150 + "px");
aligner2.css("left", ($("#scene_map").width() / 2) + 150 + "px");
}
else {
aligner2.css("top", ($("#scene_map").height() / 2) + 50 + "px");
aligner2.css("left", ($("#scene_map").width() / 2) + 50 + "px");
}
aligner2.css("z-index", 40);
var canvas2 = aligner2.get(0);
canvas2.width = 59;
canvas2.height = 59;
var ctx = canvas2.getContext("2d");
ctx.fillStyle = "rgba(255, 255, 255, 0.2)";
ctx.fillRect(0, 0, canvas2.width, canvas2.height);
ctx.fillStyle = "rgba(0,255,0,0.5)";
ctx.fillRect(0, 29, 59, 29);
ctx.fillRect(29, 0, 29, 29);
drawX(canvas2);
var pageX = Math.round(parseInt(aligner1.css('left')) * window.ZOOM - ($(window).width() / 2));
var pageY = Math.round(parseInt(aligner1.css('top')) * window.ZOOM - ($(window).height() / 2));
$("html,body").animate({
scrollTop: pageY + 200,
scrollLeft: pageX + 200,
}, 500);
let regrid = function(e) {
window.WIZARDING = true;
if (!just_rescaling)
window.CURRENT_SCENE_DATA.grid = 1;
else
window.CURRENT_SCENE_DATA.grid = 0;
let al1 = {
x: parseInt(aligner1.css("left")) + 29,
y: parseInt(aligner1.css("top")) + 29,
};
let al2 = {
x: parseInt(aligner2.css("left")) + 29,
y: parseInt(aligner2.css("top")) + 29,
};
if (just_rescaling) {
ppsx = (al2.x - al1.x);
ppsy = (al2.y - al1.y);
offsetx = 0;
offsety = 0;
}
else {
ppsx = (al2.x - al1.x) / 3.0;
ppsy = (al2.y - al1.y) / 3.0;
offsetx = al1.x % ppsx;
offsety = al1.y % ppsy;
}
console.log("ppsx " + ppsx + "ppsy " + ppsy + "offsetx " + offsetx + "offsety " + offsety)
window.CURRENT_SCENE_DATA.hpps = ppsx;
window.CURRENT_SCENE_DATA.vpps = ppsy;
window.CURRENT_SCENE_DATA.offsetx = offsetx;
window.CURRENT_SCENE_DATA.offsety = offsety;
reset_canvas();
redraw_canvas();
};
let click2 = {
x: 0,
y: 0
};
aligner2.draggable({
stop: regrid,
start: function(event) {
window.CURRENT_SCENE_DATA.grid = 0;
reset_canvas(); redraw_canvas();
click2.x = event.clientX;
click2.y = event.clientY;
$("#aligner2").attr('original-top', parseInt($("#aligner2").css("top")));
$("#aligner2").attr('original-left', parseInt($("#aligner2").css("left")));
},
drag: function(event, ui) {
let zoom = window.ZOOM;
let original = ui.originalPosition;
ui.position = {
left: Math.round((event.clientX - click2.x + original.left) / zoom),
top: Math.round((event.clientY - click2.y + original.top) / zoom)
};
if (square) { // restrict on 45
console.log("PRE");
console.log(ui.position);
var rad = Math.PI / 180;
var angle;
var offsetLeft = Math.round(ui.position.left - parseInt($("#aligner2").attr('original-left')));
var offsetTop = Math.round(ui.position.top - parseInt($("#aligner2").attr('original-top')));
var offset = {
x: offsetLeft,
y: offsetTop,
};
console.log(offset);
var distance = Math.sqrt(offset.x * offset.x + offset.y * offset.y);
console.log("distanza " + distance);
if (offset.y > 0)
angle = 45 * rad;
else
angle = 225 * rad;
ui.position.top = Math.sin(angle) * distance + parseInt($("#aligner2").attr('original-top'));
console.log(Math.sin(angle) * distance);
console.log(parseInt($("#aligner2").attr('original-top')));
ui.position.left = Math.cos(angle) * distance + parseInt($("#aligner2").attr('original-left'));
console.log(ui.position);
}
}
});
let click1 = {
x: 0,
y: 0
};
aligner1.draggable({
stop: regrid,
start: function(event) {
window.CURRENT_SCENE_DATA.grid = 0;
reset_canvas(); redraw_canvas();
click1.x = event.clientX;
click1.y = event.clientY;
$("#aligner1").attr('original-top', parseInt($(event.target).css("top")));
$("#aligner1").attr('original-left', parseInt($(event.target).css("left")));
$("#aligner2").attr('original-top', parseInt($("#aligner2").css("top")));
$("#aligner2").attr('original-left', parseInt($("#aligner2").css("left")));
},
drag: function(event, ui) {
let zoom = window.ZOOM;
let original = ui.originalPosition;
ui.position = {
left: Math.round((event.clientX - click1.x + original.left) / zoom),
top: Math.round((event.clientY - click1.y + original.top) / zoom)
};
if (square) {
var offsetLeft = Math.round(ui.position.left - parseInt($("#aligner1").attr('original-left')));
var offsetTop = Math.round(ui.position.top - parseInt($("#aligner1").attr('original-top')));
console.log("off " + offsetLeft + " " + offsetTop);
$("#aligner2").css('left', (parseInt($("#aligner2").attr("original-left")) + offsetLeft) + "px");
$("#aligner2").css('top', (parseInt($("#aligner2").attr("original-top")) + offsetTop) + "px");
}
}
});
$("#VTT").append(aligner1);
$("#VTT").append(aligner2);
wizard_popup = $("<div id='wizard_popup'></div>");
wizard_popup.css("position", "fixed");
wizard_popup.css("max-width", "800px");
wizard_popup.css("top", "40px");
wizard_popup.css("left", "250px");
wizard_popup.css("z-index", "200px");
wizard_popup.css("background", "rgba(254,215,62,0.8)");
wizard_popup.css("font-size", "20px");
if (!just_rescaling)
wizard_popup.append("Move the pointers at the center of the map to define 3x3 Square on the map! ZOOM IN with the Top Right + button. <button id='step2btn'>Press when it's good enough</button>");
else
wizard_popup.append("Set the green square to roughly the size of a medium token! <button id='step2btn'>Press when it's good enough</button>");
$("body").append(wizard_popup);
regrid();
wizard_popup.find("#step2btn").click(
function() {
aligner1.remove();
aligner2.remove();
if (just_rescaling) {
grid_5(false, false);
}
else if (!square) {
$("#wizard_popup").empty().append("Nice!! How many feet per square ? <button id='grid_5'>5</button> <button id='grid_10'>10</button> <button id='grid_15'>15</button> <button id='grid_20'>20</button>");
$("#grid_5").click(function() { grid_5(); });
$("#grid_10").click(function() { grid_10(); });
$("#grid_15").click(function() { grid_15(); });
$("#grid_20").click(function() { grid_20(); });
$("#grid_100").click(function() { grid_100(); });
}
else { // just creating a 5 foot grid
grid_5(true);
}
}
);
});
}; // END OF ALIGN GRID WIZARD!
wizard.click(
function() {
f.find("input").each(function() {
var n = $(this).attr('name');
let nValue = $(this).val();
if (n === 'player_map'
&& nValue.startsWith("https://drive.google.com")
&& nValue.indexOf("uc?id=") < 0
) {
nValue = 'https://drive.google.com/uc?id=' + nValue.split('/')[5];
}
scene[n] = nValue;
});
scene.scale_factor=1;
window.ScenesHandler.persist();
window.ScenesHandler.switch_scene(scene_id);
$("#edit_dialog").remove();
$("#scene_selector").removeAttr("disabled");
$("#scene_selector_toggle").click();
$("#scene_selector_toggle").hide();
prewiz = $("<table id='prewiz'/>");
prewiz.append("<tr><td><button id='align_grid'>Align to Grid</button></td><td>Use this if you're working on a pre-gridded map and you want all features to work (precise token size, measurament tool,grid snapping!)</td></tr>");
prewiz.append("<tr><td><button id='create_grid'>Create Grid</button></td><td>Use this if you want advanced features on a map that don't have a grid!'</td></tr>");
prewiz.append("<tr><td><button id='rescale'>Just Rescale the Image</button></td><td>Use this if you just wanna change the size of the image.. It's good for generic images, world maps, or if you don't care about features and just want to have fun quickly</td></tr>");
prewiz.css("position", "fixed");
prewiz.css("max-width", "800px");
prewiz.css("top", "150px");
prewiz.css("left", "250px");
prewiz.css("z-index", "200px");
prewiz.css("background", "rgba(254,215,62,1)");
prewiz.css("font-size", "20px");
$("body").append(prewiz);
$("#align_grid").click(function() {
$("#prewiz").remove();
align_grid(false, false);
});
$("#create_grid").click(function() {
$("#prewiz").remove();
align_grid(true, false);
});
$("#rescale").click(function() {
$("#prewiz").remove();
align_grid(true, true)
});
}
);
cancel = $("<button>Cancel</button>");
cancel.click(function() {
$("#edit_dialog").remove();
$("#scene_selector").removeAttr("disabled");
})
var hide_all_button = $("<button>COVER WITH FOG</button>");
hide_all_button.click(function() {
r = confirm("This will delete all current FOG zones on this scene and HIDE ALL THE MAP to the player. Are you sure?");
if (r == true) {
scene.reveals = [];
if (scene_id == window.ScenesHandler.current_scene_id) {
window.REVEALED = [];
redraw_canvas();
}
window.ScenesHandler.persist();
window.ScenesHandler.sync();
}
});
/*var export_grid=$("<button>Send Grid Data to the Community</button>")
export_grid.click(function(){
});*/
f.append(sub);
f.append(cancel);
f.append(hide_all_button);
// f.append(export_grid);
container.css('opacity', '0.0');
container.append(f);
container.animate({
opacity: '1.0'
}, 1000);
}
function refresh_scenes() {
target = $("#scene_selector");
target.find(".scene").remove();
for (var i = 0; i < window.ScenesHandler.scenes.length; i++) {
let scene_id = i;
var scene = window.ScenesHandler.scenes[i];
var newobj = $("<div class='scene' style='float:left;overflow: hidden;display:block;border: 1px solid black;margin: 5px;'/>");
title = $("<div style='text-align:center;'/>");
title.html(scene.title);
if (i == window.ScenesHandler.current_scene_id)
title.css('background', 'red');
newobj.append(title);
controls = $("<div/>");
switch_button = $("<button>SWITCH</button>");
switch_button.click(function() {
window.ScenesHandler.switch_scene(scene_id);
$("#scene_selector_toggle").click();
refresh_scenes();
});
controls.append(switch_button);
edit_button = $("<button>EDIT</button>");
edit_button.click(function() {
edit_scene_dialog(scene_id);
});
controls.append(edit_button);
delete_button = $("<button>DELETE</button>")
delete_button.click(function() {
r = confirm("Are you sure that you want to delete this scene?");
if (r == true) {
window.ScenesHandler.scenes.splice(scene_id, 1);
window.ScenesHandler.persist();
refresh_scenes();
}
});
controls.append(delete_button);
newobj.append(controls);
target.append(newobj);
}
}
function init_scene_selector() {
ss = $("<div id='scene_selector' />");
ss.css('position', 'fixed');
ss.css('height', 0);
ss.css('top', '0px');
ss.css('left', '250px');
addblock = $("<div style='float:left;overflow: hidden;display:block;'/>");
addbutton = $("<button id='addscene'>ADDSCENE</button>");
addbutton.click(function() {
window.ScenesHandler.scenes.push({
title: "New Scene",
dm_map: "",
player_map: "",
scale: "100",
dm_map_usable: "0",
fog_of_war: "1",
tokens: {},
fpsq: 5,
hpps: 60,
vpps: 60,
offsetx: 0,
offsety: 0,
grid: 0,
snap: 0,
reveals: [[0, 0, 0, 0, 2, 0]], // SPECIAL MESSAGE TO REVEAL EVERYTHING
}
);
window.ScenesHandler.persist();
refresh_scenes();
});
addblock.append(addbutton);
ss.append(addblock);
let toggle = $("<button id='scene_selector_toggle'>SCENES</button>");
toggle.css('position', 'fixed');
toggle.css('width', '75px');
toggle.css('top', '5px'); // IMPORTANT
toggle.css('left', '325px');
toggle.css('z-index', '9999')
toggle.click(function() {
if (toggle.css('top') == "5px") {
toggle.animate({
top: '200px',
}, 500);
ss.animate({
height: '200px'
}, 500);
ss.css("overflow","auto");
refresh_scenes();
}
else {
toggle.animate({
top: '5px',
}, 500);
ss.animate({
height: '0px'
}, 500);
}
});
$(window.document.body).append(ss);
$(window.document.body).append(toggle);
}
function display_sources() {
$("#source_select").empty();
$("#chapter_select").empty();
$("#scene_select").empty();
for (property in window.ScenesHandler.sources) {
var source = window.ScenesHandler.sources[property];
$("#source_select").append($("<option value='" + property + "'>" + source.title + "</option>"));
}
}
function display_chapters() {
$("#chapter_select").empty();
$("#scene_select").empty();
var source_name = $("#source_select").val();
for (property in window.ScenesHandler.sources[source_name].chapters) {
var chapter = window.ScenesHandler.sources[source_name].chapters[property];
$("#chapter_select").append($("<option value='" + property + "'>" + chapter.title + "</option>"))
}
$("#chapter_select").change();
}
function display_scenes() {
var source_name = $("#source_select").val();
var chapter_name = $("#chapter_select").val();
fill_importer(window.ScenesHandler.sources[source_name].chapters[chapter_name].scenes, 0);
console.log(window.ScenesHandler.sources[source_name].chapters[chapter_name].scenes);
console.log("mostrati...");
/*$("#scene_select").empty();
var source_name=$("#source_select").val();
var chapter_name=$("#chapter_select").val();
for(property in window.ScenesHandler.sources[source_name].chapters[chapter_name].scenes){
var scene=window.ScenesHandler.sources[source_name].chapters[chapter_name].scenes[property];
$("#scene_select").append($("<option value='"+property+"'>"+scene.title+"</option>"));
}
$("#scene_select").change();*/
}
function init_ddb_importer(target) {
panel = $("<div id='scenes-panel' class='sidepanel-content'></div>");
target.append(panel);
var source_select = $("<select id='source_select'/>");
source_select.css("display", "inline");
window.ScenesHandler.build_adventures(function() {
display_sources();
$("#source_select").change();
});
source_select.change(function() {
$("#chapter_select").empty();
$("#scenes_select").empty();
$("#import_button").attr('disabled', 'disabled');
var source_name = $("#source_select").val()
window.ScenesHandler.build_chapters(source_name, display_chapters);
});
var chapter_select = $("<select id='chapter_select'/>");
chapter_select.css("display", "inline");
chapter_select.change(function() {
$("#scene_select").empty();
$("#import_button").attr('disabled', 'disabled');
var source_name = $("#source_select").val();
var chapter_name = $("#chapter_select").val();
$("#importer_area").html("Loading........ please wait!");
window.ScenesHandler.build_scenes(source_name, chapter_name, display_scenes);
});
/* var scene_select=$("<select id='scene_select'/>");
scene_select.change(function(){
console.log('prepare scene properties');
var source_name=$("#source_select").val();
var chapter_name=$("#chapter_select").val();
var scene_name=$("#scene_select").val();
if(scene_name)
$("#import_button").removeAttr('disabled');
else
$("#import_button").attr('disabled','disabled');
//window.ScenesHandler.display_scene_properties(source_name,chapter_name,scene_name);
});*/
/*import_button=$("<button id='import_button'>IMPORT</button>");
import_button.attr('disabled','disabled');
import_button.click(function(){
var source_name=$("#source_select").val();
var chapter_name=$("#chapter_select").val();
var scene_name=$("#scene_select").val();
scene=window.ScenesHandler.sources[source_name].chapters[chapter_name].scenes[scene_name];
$("#scene_properties input[name='player_map']").val(scene.player_map);
$("#scene_properties input[name='dm_map']").val(scene.dm_map);
$("#scene_properties input[name='title']").val(scene.title);
});*/
panel.append(source_select);
panel.append(chapter_select);
//panel.append($("<div/>").append(scene_select));
//panel.append($("<div/>").append(import_button));
}
function fill_importer(scene_set, start) {
area = $("#importer_area");
area.empty();
area.css("opacity", "0");
area.animate({ opacity: "1" }, 300);
var ddb_extra_found=false;
for (var i = start; i < Math.min(start + 8, scene_set.length); i++) {
let current_scene = scene_set[i];
if (current_scene.uuid in DDB_EXTRAS) {
ddb_extra_found=true;
for (prop in DDB_EXTRAS[current_scene.uuid]) {
current_scene[prop] = DDB_EXTRAS[current_scene.uuid][prop];
}
}
entry = $("<div/>");
entry.css({
float: "left",
width: "180px",
height: "200px",
margin: "15px",
border: "2px solid black",
"border-radius": "5px 5px 5px 5px",
'text-align': 'center',
});
img = $("<img>");
img.css({
'max-width': '160px',
'max-height': '150px',
});
img.attr("src", scene_set[i].thumb);
imgcont = $("<div/>").css({ width: '100%', height: '150px' });
imgcont.append(img);
title = $("<div style='width: 180px;font-weight:bold'></div>");
title.text(current_scene.title);
entry.append(title);
entry.append(imgcont);
stats = $("<div/>");
stats.css("height", "15px");
stats.css("width", "100%");
if (scene_set[i].dm_map) {
stats.append("<b style='background: lightblue; border 1px solid back; margin: 5px;' title='Has DM Map'>DM</b>");
}
if ((scene_set[i].snap == "1") || ddb_extra_found) {
stats.append("<b style='background:gold; border 1px solid back; margin: 5px;' title='PRE-ALIGNED'>PRE-CONFIGURED!</b>");
}
entry.append(stats);
b = $("<button>Import</button>");
b.click(function() {
var scene = current_scene;
$("#scene_properties input[name='player_map']").val(scene.player_map);
$("#scene_properties input[name='dm_map']").val(scene.dm_map);
$("#scene_properties input[name='title']").val(scene.title);
$("#scene_properties input[name='scale']").val(scene.scale);
if (typeof scene.uuid !== "undefined")
$("#scene_properties input[name='uuid']").val(scene.uuid);
if (typeof scene.dm_map_usable !== "undefined")
$("#scene_properties input[name='dm_map_usable']").val(scene.dm_map_usable);
if (typeof scene.hpps !== "undefined")
$("#scene_properties input[name='hpps']").val(scene.hpps);