-
Notifications
You must be signed in to change notification settings - Fork 64
/
Settings.js
1609 lines (1475 loc) · 70.9 KB
/
Settings.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 token_setting_options() {
return [
{
name: 'tokenStyleSelect',
label: 'Token Style',
type: 'dropdown',
options: [
{ value: "circle", label: "Circle", description: `The token is round and is contained within the border. We set "Ignore Aspect Ratio" to true and "Square" to false. Great for tokens with a portrait art style!` },
{ value: "square", label: "Square", description: `The token is square and is contained within the border. We set "Ignore Aspect Ratio" to true and "Square" to true. Great for tokens with a portrait art style!` },
{ value: "virtualMiniCircle", label: "Virtual Mini w/ Round Base", description: `The token looks like a physical mini with a round base. The image will show up as it is naturally with the largest side being equal to the token size, we set "Ignore Aspect Ratio" to false and "Square" to true. We also add a virtual token base to this Style with Borders and Health Aura on the base of the token. Great for tokens with a top-down art style!` },
{ value: "virtualMiniSquare", label: "Virtual Mini w/ Square Base", description: `The token looks like a physical mini with a round base. The image will show up as it is naturally with The largest side being equal to the token size, we set "Ignore Aspect Ratio" to false and "Square" to true. We also add a virtual token base to this Style with Borders and Health Aura on the base of the token. Great for tokens with a top-down art style!` },
{ value: "noConstraint", label: "No Constraint", description: `The token will show up as it is naturally largest side being equal to token size, we set "Ignore Aspect Ratio" to false and "Square to true. Borders and Health Aura are drawn as a drop shadow to fit the shape of the token.` },
{ value: "definitelyNotAToken", label: "Definitely Not a Token", description: `This token will have the shape of no contraints and be made to appear as a object tile` },
{ value: "labelToken", label: "Map Pin Token", description: `This token will have the settings of Definitely Not a Token and have it's name always displayed` }
],
defaultValue: "circle"
},
{
name: 'tokenBaseStyleSelect',
label: 'Token Base Style',
type: 'dropdown',
options: [
{ value: "default", label: "Default", description: "A default dark semi-opaque plastic base." },
{ value: "border-color", label: "Match Border Color", description: "A base that matches the border color of the token." },
{ value: "grass", label: "Grass", description: "A grass covered base.." },
{ value: "tile", label: "Tile", description: "A tile base." },
{ value: "sand", label: "Sand", description: "A sand covered base." },
{ value: "rock", label: "Rock", description: "A rock base." },
{ value: "water", label: "Water", description: "A water base." }
],
defaultValue: "default"
},
{
name: "healthauratype",
label: "Health Visual",
type: 'dropdown',
options: [
{ value: "aura", label: "Aura", description: "Tokens will have a colored aura" },
{ value: "aura-bloodied-50", label: "Bloodied 50", description: "Tokens will have a red aura when bloodied" },
{ value: "bar", label: "HP Meter", description: "How this meter is displayed depends on token type. Color blind alternative to auras." },
{ value: "none", label: "None", description: "Tokens will not have a health visual" }
],
defaultValue: "aura"
},
{
name: 'lockRestrictDrop',
label: 'Token Lock',
type: 'dropdown',
options: [
{ value: "none", label: "None", description: "Token is freely moveable by all players and the DM." },
{ value: "restrict", label: "Restrict player access", description: "Players will not be able to move this token unless it is thier owned PC Token. Will not be added to Players group selections." },
{ value: "lock", label: "Lock", description: "Locks token for both DM and Players. Will not be added to group selections." },
{ value: "declutter", label: "Lock and Declutter Hidden", description: "Locks token for both DM and Players. Will fully hide for DM when hidden."}
],
defaultValue: "none"
},
{
name: 'hidden',
label: 'Hide',
type: 'toggle',
options: [
{ value: true, label: "Hidden", description: "The token is hidden to players." },
{ value: false, label: "Visible", description: "The token is visible to players." }
],
defaultValue: false
},
{
name: 'square',
label: 'Square Token',
type: 'toggle',
options: [
{ value: true, label: "Square", description: "The token is square." },
{ value: false, label: "Round", description: "The token is clipped to fit within a circle." }
],
defaultValue: false,
hiddenSetting: true
},
{
name: 'locked',
label: 'Disable All Interaction',
type: 'toggle',
options: [
{ value: true, label: "Interaction Disabled", description: "The token can not be interacted with in any way. Not movable, not selectable by players, no hp/ac displayed, no border displayed, no nothing. Players shouldn't even know it's a token." },
{ value: false, label: "Interaction Allowed", description: "The token can be interacted with." }
],
defaultValue: false,
hiddenSetting: true
},
{
name: 'restrictPlayerMove',
label: 'Restrict Player Movement',
type: 'toggle',
options: [
{ value: true, label: "Restricted", description: "Players can not move the token unless it is their token." },
{ value: false, label: "Unrestricted", description: "Players can move the token." }
],
defaultValue: false,
hiddenSetting: true
},
{
name: 'revealInFog',
label: 'Reveal in Fog',
type: 'toggle',
options: [
{ value: true, label: "Revealed in Fog", description: "The token will not be hidden by fog." },
{ value: false, label: "Hidden in Fog", description: "The token will be hidden if in fog" }
],
defaultValue: false
},
{
name: 'underDarkness',
label: 'Move token below darkness/light',
type: 'toggle',
options: [
{ value: true, label: "Below darkness", description: "The token will appear below darkness/light." },
{ value: false, label: "Above darkness", description: "The token will appear above darkness/light" }
],
defaultValue: false
},
{
name: 'disablestat',
label: 'Remove HP/AC',
type: 'toggle',
options: [
{ value: true, label: "Removed", description: "The token does not have HP/AC shown to either the DM or the players." },
{ value: false, label: "Visible to DM", description: "The token has HP/AC shown to only the DM." }
],
defaultValue: false
},
{
name: 'hidestat',
label: 'Hide Player HP/AC',
type: 'toggle',
options: [
{ value: true, label: "Hidden", description: "Each player can see their own HP/AC, but can't see the HP/AC of other players." },
{ value: false, label: "Visible", description: "Each player can see their own HP/AC as well as the HP/AC of other players." }
],
defaultValue: false
},
{
name: 'hidehpbar',
label: 'Only show HP values on hover',
type: 'toggle',
options: [
{ value: true, label: "On Hover", description: "HP values are only shown when you hover or select the token. The 'Disable HP/AC' option overrides this one." },
{ value: false, label: "Always", description: "HP values are always displayed on the token. The 'Disable HP/AC' option overrides this one." }
],
defaultValue: false
},
{
name: 'disableborder',
label: 'Disable Border',
type: 'toggle',
options: [
{ value: true, label: 'No Border', description: "The token does not have a border around it." },
{ value: false, label: 'Border', description: "The token has a border around it." }
],
defaultValue: false
},
{
name: 'disableaura',
label: 'Disable Health Aura',
type: 'toggle',
options: [
{ value: true, label: 'No Aura', description: "The token does not have an aura representing its current health." },
{ value: false, label: 'Health Aura', description: "The token has an aura representing current health around it." }
],
defaultValue: false,
hiddenSetting: true
},
{
name: 'enablepercenthpbar',
label: 'Enable Token HP% Bar',
type: 'toggle',
options: [
{ value: true, label: 'Health Bar', description: "The token has a traditional visual hp% bar below it" },
{ value: false, label: 'No Bar', description: "The token does not have a traditional visual hp% bar below it" }
],
defaultValue: false,
hiddenSetting: true
},
{
name: 'revealname',
label: 'Show name to players',
type: 'toggle',
options: [
{ value: true, label: 'Visible', description: "The token's name is visible to players" },
{ value: false, label: 'Hidden', description: "The token's name is hidden from players" }
],
defaultValue: false
},
{
name: 'alwaysshowname',
label: 'Always display name',
type: 'toggle',
options: [
{ value: true, label: "Always display name", description: "Always displays name." },
{ value: false, label: "Only display name on hover", description: "Only displays name on hover" }
],
defaultValue: false
},
{
name: 'legacyaspectratio',
label: 'Ignore Image Aspect Ratio',
type: 'toggle',
options: [
{ value: true, label: 'Stretch', description: "The token's image will stretch to fill the token space" },
{ value: false, label: 'Maintain', description: "New token's image will respect the aspect ratio of the image provided" }
],
defaultValue: false,
hiddenSetting: true
},
{
name: "player_owned",
label: "Player Accessible Stats",
type: 'toggle',
options: [
{ value: true, label: 'Player & DM', description: "The token's stat block is accessible to players via the token context menu. Players can also alter the HP/AC of this token." },
{ value: false, label: 'DM only', description: "The token's stat block is not accessible to players via the token context menu. Players can not alter the HP/AC of this token." }
],
defaultValue: false
},
{
name: "defaultmaxhptype",
label: "Max HP Calculation",
type: 'dropdown',
options: [
{ value: "average", label: "Average", description: "Monster Max HP will be set to the average value." },
{ value: "roll", label: "Roll", description: "Monster Max HP will be individually rolled." },
{ value: "max", label: "Max", description: "Monster Max HP will be set to the maximum value." }
],
defaultValue: "average"
},
{
name: "placeType",
label: "Token Name Adjustment",
type: 'dropdown',
options: [
{ value: "count", label: "Count", description: "Tokens's name have a number appended to them." },
{ value: "personality", label: "Personality Trait", description: "Tokens's name have a personaility trait prepended." },
{ value: "none", label: "None", description: "Tokens's name will not be modified." }
],
defaultValue: "count"
},
{
name: "auraislight",
label: "Enable Token Vision/Light",
type: 'toggle',
globalSettingOnly: true,
options: [
{ value: true, label: 'Enabled', description: "Token line of sight will be calculated and token vision/light can be used." },
{ value: false, label: 'Disabled', description: "Token line of sight will be disabled and token vision/light can not be used." }
],
defaultValue: true
},
{
name: "videoToken",
label: "Video Token",
type: 'toggle',
options: [
{ value: true, label: 'Enabled', description: "Token is using a video file for an image (webm, mp4, m4v, etc.) Use this if the URL does not have the file extention at the end." },
{ value: false, label: 'Disabled', description: "The Token is using an image file for it's image (png, jpg, gif, etc.)" }
],
defaultValue: false
},
{
name: "maxAge",
label: "Token has time limit",
type: 'dropdown',
options: [
{ value: false, label: "None", description: "No timer added." },
{ value: "1", label: "1 round", description: "Duration of one round - timer will turn red after it's reached it's time limit." },
{ value: "10", label: "1 minute", description: "Duration of 10 rounds - timer will turn red after it's reached it's time limit." },
{ value: "custom", label: "Custom Timer", description: "Timer will be added - timer will turn red after it's reached it's time limit." }
],
defaultValue: false,
hiddenSetting: true
}
];
}
function avtt_settings() {
let settings = [
{
name: 'alwaysShowSplash',
label: 'Always show splash screen',
type: 'toggle',
options: [
{ value: true, label: "Always", description: `You will always see the splash screen on startup.` },
{ value: false, label: "Only When New", description: `You will only see the splash screen on startup after updating to a new version.` }
],
defaultValue: true
},
{
name: 'allowTokenMeasurement',
label: 'Measure while dragging tokens',
type: 'toggle',
options: [
{ value: true, label: "Measure", description: `When you drag a token, the distance dragged will automatically be measured. Dropping the token and picking it back up will create a waypoint in the measurement. Clicking anywhere else, or dragging another token will stop the measurement.` },
{ value: false, label: "Not Measuring", description: `Enable this to automatically measure the distance that you drag a token. When enabled, dropping the token and picking it back up will create a waypoint in the measurement. Clicking anywhere else, or dragging another token will stop the measurement.` }
],
defaultValue: false
},
{
name: 'streamDiceRolls',
label: 'Stream Dice Rolls',
type: 'toggle',
options: [
{ value: true, label: "Streaming", description: `When you roll DDB dice (to Everyone), all players who also enable this feature will see your rolls and you will see theirs. Disclaimer: the dice will start small then grow to normal size after a few rolls. They will be contained to the smaller of your window or the sending screen size.` },
{ value: false, label: "Not Streaming", description: `When you enable this, DDB dice rolls will be visible to you and all other players who also enable this. Disclaimer: the dice will start small then grow to normal size after a few rolls. They will be contained to the smaller of your window or the sending screen size.` }
],
defaultValue: false
},
{
name: 'iframeStatBlocks',
label: 'Fetch Monster Stat Blocks',
type: 'toggle',
options: [
{ value: true, label: "Load from DDB", description: `Monster details pages are being fetched and shown as Stat Blocks. Disabling this will build monster stat blocks locally instead. Disabling this will improve performance and reduce network data usage. Enabling this is not recommended unless you are experiencing issues with the default stat blocks.` },
{ value: false, label: "Build Locally", description: `Monster stat blocks are currently being built locally by AboveVTT. Enabling this will fetch and load monster details pages rather than building stat blocks locally. Enabling this will impact performance and will use a lot more network data. Enabling this is not recommended unless you are experiencing issues with the default stat blocks.` }
],
defaultValue: false
},
{
name: "peerStreaming",
label: "Allow Streaming Cursor/Ruler",
type: "toggle",
options: [
{ value: true, label: "Allow", description: `If you are experiencing performance issues or if you have slow internet, you may want to disable this.` },
{ value: false, label: "Never", description: `If you are experiencing performance issues or if you have slow internet, you may want to disable this.` }
],
defaultValue: false
},
{
name: "iconUi",
label: "Mobile/Icon UI",
type: "toggle",
options: [
{ value: true, label: "Enable", description: `` },
{ value: false, label: "Disable", description: `` }
],
defaultValue: false
},
{
name: "dragLight",
label: "Update vision during token move",
type: "toggle",
options: [
{ value: true, label: "Enable", description: `While move a token vision will update` },
{ value: false, label: "Disable", description: `Vision will only update on finishing it's movement` }
],
defaultValue: false
}
];
if (window.DM) {
// Remove the `dm` an option for the DM and tweak the descriptions to remove references to the DM.
settings.push(
{
name: "receiveCursorFromPeers",
label: "Cursors You See",
type: "dropdown",
options: [
{ value: "all", label: "Everyone", description: `When players move their cursor, you will see where their cursor is. You will not see cursors of any player that disables cursor/ruler streaming.` },
{ value: "none", label: "No One", description: `You will not see the cursor position of any player.` },
{ value: "combatTurn", label: "Current Combat Turn", description: `You will only see players' cursors during their turn in combat. You will not see cursors of any player that disables cursor/ruler streaming.` }
],
defaultValue: "all"
},
{
name: "receiveRulerFromPeers",
label: "Rulers You See",
type: "dropdown",
options: [
{ value: "all", label: "Everyone", description: `When players measure while dragging a token or measure with the ruler tool, you will see their ruler. You will not see rulers of any player that disables cursor/ruler streaming.` },
{ value: "none", label: "No One", description: `You will not see any token measurement or ruler measurement from any player.` },
{ value: "combatTurn", label: "Current Combat Turn", description: `You will only see players' token measurement and ruler measurement during their turn in combat. You will not see rulers of any player that disables cursor/ruler streaming.` }
],
defaultValue: "all"
},
{
name: "projector",
label: "Streaming/TV Projector Mode",
type: "toggle",
options: [
{ value: true, label: "Enable", description: `If you have another tab with the player view open it will receive your scroll and zoom events.` },
{ value: false, label: "Disable", description: `If you have another tab with the player view open it will not receive your scroll and zoom events.` }
],
defaultValue: false
},
{
name: "disableCombatText",
label: "Disable DM Damage Button Text",
type: "toggle",
options: [
{ value: true, label: "Enable", description: `If enabled removes the scrolling text on tokens displayed to DM when using gamelog damage buttons.` },
{ value: false, label: "Disable", description: `If enabled removes the scrolling text on tokens displayed to DM when using gamelog damage buttons.` }
],
defaultValue: false
}
);
} else {
settings.push(
{
name: "receiveCursorFromPeers",
label: "Cursors You See",
type: "dropdown",
options: [
{ value: "all", label: "Everyone", description: `When other players or the DM move their cursor, you will see where their cursor is. You will not see cursors of any player or DM that disables cursor/ruler streaming.` },
{ value: "none", label: "No One", description: `You will not see the cursor position of any player or the DM.` },
{ value: "dm", label: "DM Only", description: `You will only see the DM's cursor position. You will not see cursors of any player or DM that disables cursor/ruler streaming.` },
{ value: "combatTurn", label: "Current Combat Turn", description: `You will only see other players' cursors during their turn in combat. You will also see the DM's cursor position. You will not see cursors of any player or DM that disables cursor/ruler streaming.` }
],
defaultValue: "all"
},
{
name: "receiveRulerFromPeers",
label: "Rulers You See",
type: "dropdown",
options: [
{ value: "all", label: "Everyone", description: `When other players or the DM measure while dragging a token or measure with the ruler tool, you will see their ruler. You will not see rulers of any player or DM that disables cursor/ruler streaming.` },
{ value: "none", label: "No One", description: `You will not see any token measurement or ruler measurement from any player or the DM.` },
{ value: "dm", label: "DM Only", description: `You will only see the DM's token or ruler measurement. You will not see rulers of any player or DM that disables cursor/ruler streaming.` },
{ value: "combatTurn", label: "Current Combat Turn", description: `You will only see other players' token measurement and ruler measurement during their turn in combat. You will also see the DM's token measurement and ruler tool. You will not see rulers of any player or DM that disables cursor/ruler streaming.` }
],
defaultValue: "all"
}
);
}
settings.push(
{
name: "rpgRoller",
label: "Disable DDB dice where possible",
type: "toggle",
options: [
{ value: true, label: "RNG Dice", description: `Disables DDB dice and uses a random number generator` },
{ value: false, label: "DDB Dice", description: `Defaults to DDB dice` }
],
defaultValue: false
})
settings.push(
{
name: "disableSendToTab",
label: "Disable capture of pc tab rolls",
type: "toggle",
options: [
{ value: true, label: "Disabled", description: `Rolls will occur on the tab the button is clicked` },
{ value: false, label: "Enabled", description: `Rolls from other tabs will occur here` }
],
defaultValue: false
})
settings.push(
{
name: "reduceMovement",
label: "Reduce animation movement",
type: "toggle",
options: [
{ value: true, label: "Disabled", description: `Reduces movement by disabling some animations` },
{ value: false, label: "Enabled", description: `All animations will be enabled` }
],
defaultValue: false
})
if (AVTT_ENVIRONMENT.versionSuffix) {
// This is either a local or a beta build, so allow this helpful debugging tool
settings.push({
name: "aggressiveErrorMessages",
label: "Alert Every Concerning Log",
type: "toggle",
options: [
{ value: true, label: "Show", description: `This will show an error dialog for every error or warning log that AboveVTT encounters.` },
{ value: false, label: "Don't Show", description: `Only show an error dialog when AboveVTT explicitly coded for it.` }
],
defaultValue: false
});
}
return settings;
}
function get_avtt_setting_default_value(name) {
return avtt_settings().find(s => s.name === name)?.defaultValue;
}
function get_avtt_setting_value(name) {
if (name === "aggressiveErrorMessages" && is_release_build()) {
return false; // never allow this in a release build
}
switch (name) {
case "iframeStatBlocks": return should_use_iframes_for_monsters();
default:
const setValue = window.EXPERIMENTAL_SETTINGS[name];
if (setValue !== undefined) {
return setValue;
}
return get_avtt_setting_default_value(name);
}
}
function set_avtt_setting_value(name, newValue) {
console.log(`set_avtt_setting_value ${name} is now ${newValue}`);
// store the setting
window.EXPERIMENTAL_SETTINGS[name] = newValue;
persist_experimental_settings(window.EXPERIMENTAL_SETTINGS);
// take action based on the newly changed setting
switch (name) {
case "iframeStatBlocks":
// TODO: change this to use window.EXPERIMENTAL_SETTINGS[name] instead of using special logic
if (newValue === true) {
use_iframes_for_monsters();
} else {
stop_using_iframes_for_monsters();
}
break;
case "streamDiceRolls":
// TODO: change this to use window.EXPERIMENTAL_SETTINGS[name] instead of using special logic
if (newValue === true || newValue === false) {
window.JOINTHEDICESTREAM = newValue;
enable_dice_streaming_feature(newValue)
} else {
const defaultValue = get_avtt_setting_default_value(name);
window.JOINTHEDICESTREAM = defaultValue;
enable_dice_streaming_feature(defaultValue);
}
break;
case "peerStreaming":
toggle_peer_settings_visibility(newValue);
local_peer_setting_changed(name, newValue);
break;
case "projector":
$('#projector_toggle, #projector_zoom_lock').toggleClass('enabled', newValue);
break;
case "receiveCursorFromPeers":
case "receiveRulerFromPeers":
local_peer_setting_changed(name, newValue);
break;
case "rpgRoller":
if(is_abovevtt_page()){
tabCommunicationChannel.postMessage({
msgType: 'setupObserver',
tab: (window.EXPERIMENTAL_SETTINGS['disableSendToTab'] == true) ? undefined : window.PLAYER_ID,
rpgTab: (window.EXPERIMENTAL_SETTINGS['rpgRoller'] == true) ? window.PLAYER_ID : undefined,
iframeTab: window.PLAYER_ID,
rpgRoller: newValue
})
}
break;
case "disableSendToTab":
if(is_abovevtt_page()){
tabCommunicationChannel.postMessage({
msgType: 'setupObserver',
tab: (window.EXPERIMENTAL_SETTINGS['disableSendToTab'] == true) ? undefined : window.PLAYER_ID,
rpgTab: (window.EXPERIMENTAL_SETTINGS['rpgRoller'] == true) ? window.PLAYER_ID : undefined,
iframeTab: window.PLAYER_ID,
rpgRoller: window.EXPERIMENTAL_SETTINGS['rpgRoller']
})
}
break;
case "reduceMovement":
$('body').toggleClass('reduceMovement', newValue)
if(newValue == false)
animationSetup()
break;
case "iconUi":
$('body').toggleClass('mobileAVTTUI', newValue)
break;
}
}
function is_valid_token_option_value(tokenOptionName, value) {
return token_setting_options().find(o => o.name === tokenOptionName)?.options?.map(value).includes(value);
}
function convert_option_to_override_dropdown(tokenOption) {
// Note: Spread syntax effectively goes one level deep while copying an array/object. Therefore, it may be unsuitable for copying multidimensional arrays or objects
// we are explicitly not using the spread operator at this level because we need to deep copy the object
let converted = {
name: tokenOption.name,
label: tokenOption.label,
type: 'dropdown',
options: tokenOption.options.map(option => { return {...option} }),
defaultValue: undefined,
hiddenSetting: tokenOption.hiddenSetting
};
converted.options.push({ value: undefined, label: "Not Overridden", description: "Changing this setting will override the default settings" });
return converted;
}
function b64EncodeUnicode(str) {
// first we use encodeURIComponent to get percent-encoded UTF-8,
// then we convert the percent encodings into raw bytes which
// can be fed into btoa.
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
function toSolidBytes(match, p1) {
return String.fromCharCode('0x' + p1);
}));
}
function b64DecodeUnicode(str) {
// Going backwards: from bytestream, to percent-encoding, to original string.
return decodeURIComponent(atob(str).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
function download(data, filename, type) {
let file = new Blob([data], {type: type});
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
else { // Others
let a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
function init_settings() {
let body = settingsPanel.body;
body.append(`<h2 style='margin-top:10px; padding-bottom:2px;margin-bottom:2px; text-align:center'><img width='200px' src='${window.EXTENSION_PATH}assets/logo.png'><div style='margin-left:20px; display:inline;vertical-align:bottom;'>${window.AVTT_VERSION}${AVTT_ENVIRONMENT.versionSuffix}</div></h2>`);
if (window.DM) {
body.append(`
<h3 class="token-image-modal-footer-title">Import / Export</h3>
<div class="sidebar-panel-header-explanation">
<p>Export will download a file containing all of your scenes, custom tokens, journal, audio library and mixer state.
Import will allow you to upload an exported file. Scenes from that file will be added to the scenes in this campaign.</p>
<div class="sidebar-panel-footer-horizontal-wrapper">
<button onclick='import_openfile();' class="sidebar-panel-footer-button sidebar-hover-text" data-hover="Upload a file containing scenes, custom tokens, journal, audio library and mixer state. This will not overwrite your existing scenes. Any scenes found in the uploaded file will be added to your current list scenes">IMPORT</button>
<button onclick='export_file();' class="sidebar-panel-footer-button sidebar-hover-text" data-hover="Download a file containing all of your scenes, custom tokens, and soundpads">EXPORT</button>
<input accept='.abovevtt' id='input_file' type='file' style='display: none' />
</div>
<div id='export_current_scene_container'>
<button id='export_current_scene' onclick='export_current_scene();' class="sidebar-panel-footer-button sidebar-hover-text" data-hover="Download a file containing the current scene data including token notes">EXPORT CURRENT SCENE ONLY</button>
</div>
<div id='other_export_container'>
<span>Specific Local Data Exports:</span>
<button id='export_token' onclick='export_token_customization();' class="sidebar-panel-footer-button sidebar-hover-text" data-hover="Download a file containing your token customizations">TOKEN CUSTOMIZATIONS</button>
<button id='export_journal' onclick='export_journal();' class="sidebar-panel-footer-button sidebar-hover-text" data-hover="Download a file containing the journal data">JOURNAL</button>
<button id='export_audio' onclick='export_audio();' class="sidebar-panel-footer-button sidebar-hover-text" data-hover="Download a file containing the audio data">AUDIO</button>
</div>
</div>
`);
$("#input_file").change(import_readfile);
body.append(`
<br />
<h3 class="token-image-modal-footer-title">Default Token Options</h3>
<div class="sidebar-panel-header-explanation">Every time you place a token on the scene, these settings will be used. You can override these settings on a per-token basis by clicking the gear on a specific token row in the tokens tab.</div>
`);
let tokenOptionsButton = $(`<button class="sidebar-panel-footer-button">Change The Default Token Options</button>`);
tokenOptionsButton.on("click", function (clickEvent) {
build_and_display_sidebar_flyout(clickEvent.clientY, function (flyout) {
let optionsContainer = build_sidebar_token_options_flyout(token_setting_options(), window.TOKEN_SETTINGS, function (name, value) {
if (value === true || value === false || typeof value === 'string' || typeof value === 'object') {
window.TOKEN_SETTINGS[name] = value;
} else {
delete window.TOKEN_SETTINGS[name];
}
}, function() {
let visionInput = $("input[name='visionColor']").spectrum("get");
let light1Input = $("input[name='light1Color']").spectrum("get");
let light2Input = $("input[name='light2Color']").spectrum("get");
window.TOKEN_SETTINGS.vision.color= `rgba(${visionInput._r}, ${visionInput._g}, ${visionInput._b}, ${visionInput._a})`;
window.TOKEN_SETTINGS.light1.color = `rgba(${light1Input._r}, ${light1Input._g}, ${light1Input._b}, ${light1Input._a})`;
window.TOKEN_SETTINGS.light2.color = `rgba(${light2Input._r}, ${light2Input._g}, ${light2Input._b}, ${light2Input._a})`;
persist_token_settings(window.TOKEN_SETTINGS);
redraw_settings_panel_token_examples();
}, true);
optionsContainer.prepend(`<div class="sidebar-panel-header-explanation">Every time you place a token on the scene, these settings will be used. You can override these settings on a per-token basis by clicking the gear on a specific token row in the tokens tab.</div>`);
flyout.append(optionsContainer);
position_flyout_left_of(body, flyout);
});
});
body.append(tokenOptionsButton);
const clearAllOverridesWarning = `This will remove ALL overridden token options from every player, monster, custom token, and folder in the Tokens Panel. This shouldn't remove any custom images from those tokens. This will not update any tokens that have been placed on a scene. This cannot be undone.`;
let clearAllTokenOverrides = $(`<button class='token-image-modal-remove-all-button sidebar-hover-text' data-hover="${clearAllOverridesWarning}" style="width:100%;padding:8px;margin:10px 0px;">Clear All Token Option Overrides</button>`);
clearAllTokenOverrides.on("click", function() {
if (confirm(clearAllOverridesWarning)) {
window.TOKEN_CUSTOMIZATIONS.forEach(tc => tc.clearTokenOptions());
persist_all_token_customizations(window.TOKEN_CUSTOMIZATIONS);
}
});
body.append(clearAllTokenOverrides);
body.append(`<br />`);
}
let experimental_features = avtt_settings();
body.append(`
<br />
<h3 class="token-image-modal-footer-title" >Above VTT Settings</h3>
<div class="sidebar-panel-header-explanation">These are settings for AboveVTT. Some of them are experimental, and some of them are temporary. These may change or go away at any time, so we recommend using the defaults values.<br><b>WARNING! Enabling these will affect performance!</b></div>
`);
for(let i = 0; i < experimental_features.length; i++) {
let setting = experimental_features[i];
if (setting.dmOnly === true && !window.DM) {
continue;
}
let currentValue = get_avtt_setting_value(setting.name);
let inputWrapper;
switch (setting.type) {
case "toggle":
inputWrapper = build_toggle_input(setting, currentValue, function(name, newValue) {
set_avtt_setting_value(name, newValue);
});
break;
case "dropdown":
inputWrapper = build_dropdown_input(setting, currentValue, function (name, newValue) {
set_avtt_setting_value(name, newValue);
})
break;
}
if (inputWrapper) {
body.append(inputWrapper);
}
}
let clearSceneExploredData = $(`<button id='clearExploredData' onclick='deleteCurrentExploredScene()' class="sidebar-panel-footer-button sidebar-hover-text" data-hover="Clear locally stored explored scene data from this scene">Clear Current Scene Explored Data</button>`)
let clearExploredData = $(`<button id='clearExploredData' onclick='deleteDB()' class="sidebar-panel-footer-button sidebar-hover-text" data-hover="Clear locally stored explored scene data from this campaign">Clear Campaign Explored Data</button>`)
let optOutOfAll = $(`<button class="token-image-modal-remove-all-button" title="Reset to defaults." style="width:100%;padding:8px;margin:10px 0px 30px 0px;">Reset to Defaults</button>`);
optOutOfAll.click(function () {
for (let i = 0; i < experimental_features.length; i++) {
let setting = experimental_features[i];
switch (setting.type) {
case "toggle":
let toggle = body.find(`button[name=${setting.name}]`);
toggle.removeClass("rc-switch-checked").removeClass("rc-switch-unknown");
if (setting.defaultValue === true) {
toggle.addClass("rc-switch-checked");
}
break;
case "dropdown":
let dropdown = body.find(`select[name=${setting.name}]`);
const index = setting.options.findIndex(op => op.value === setting.defaultValue);
dropdown[0].selectedIndex = index;
dropdown.prop("selectedIndex", index);
break;
default:
console.warn("optOutOfAll button is not handling setting with type", setting.type, setting);
break;
}
set_avtt_setting_value(setting.name, setting.defaultValue);
}
});
if(!window.DM){
body.append(clearSceneExploredData, clearExploredData, optOutOfAll);
}
else{
body.append(optOutOfAll);
}
toggle_peer_settings_visibility(get_avtt_setting_value("peerStreaming"));
redraw_settings_panel_token_examples();
}
function redraw_settings_panel_token_examples(settings) {
console.log("redraw_settings_panel_token_examples", settings);
let mergedSettings = {...window.TOKEN_SETTINGS};
if (settings !== undefined) {
mergedSettings = {...mergedSettings, ...settings};
}
delete mergedSettings.imageSize;
let items = $(".example-tokens-wrapper .example-token");
for (let i = 0; i < items.length; i++) {
let item = $(items[i]);
mergedSettings.imgsrc = item.find(".token-image").attr("src");
item.replaceWith(build_example_token(mergedSettings));
}
}
function build_example_token(options) {
let mergedOptions = {...default_options(), ...window.TOKEN_SETTINGS, ...options};
let hpnum;
switch (mergedOptions['defaultmaxhptype']) {
case 'max':
hpnum = 15;
break;
case 'roll':
hpnum = 5 + Math.floor(Math.random() * 11); // Random 5-15
break;
case 'average':
default:
hpnum = 10;
break;
}
mergedOptions.hitPointInfo = {
current: hpnum,
maximum: hpnum,
temp: 0
}
mergedOptions.id = `exampleToken-${uuid()}`;
mergedOptions.size = 90;
// mergedOptions.gridHeight = 1;
// mergedOptions.gridWidth = 1;
mergedOptions.armorClass = 10;
if(mergedOptions.maxAge == undefined){
mergedOptions.maxAge = false;
}
if(mergedOptions.maxAge !== false && isNaN(parseInt(mergedOptions.age))){
mergedOptions.age = 1;
}
mergedOptions.exampleToken = true;
// TODO: this is horribly inneficient. Clean up token.place and then update this
let token = new Token(mergedOptions);
token.place(0);
let html = $(`#tokens div[data-id='${mergedOptions.id}']`).clone();
html.find('.token-image').attr('src', mergedOptions.imgsrc);
html.find('div.token-image').attr('background-image', `url(${mergedOptions.imgsrc})`);
token.delete(false);
html.addClass("example-token");
// html.css({
// float: "left",
// width: 90,
// height: 90,
// position: "relative",
// opacity: 1,
// top: 0,
// left: 0,
// padding: "3px 0px"
// });
return html;
}
// used for settings tab, and tokens tab configuration modals. For placed tokens, see `build_options_flyout_menu`
// updateValue: function(name, newValue) {} // only update the data here
// didChange: function() {} // do ui things here
function build_sidebar_token_options_flyout(availableOptions, setValues, updateValue, didChange, showExtraOptions=false) {
if (typeof updateValue !== 'function') {
updateValue = function(name, newValue){
console.warn("build_sidebar_token_options_flyout was not given an updateValue function so we can't set ", name, "to", value);
};
}
if (typeof didChange !== 'function') {
didChange = function(){
console.log("build_sidebar_token_options_flyout was not given adidChange function");
};
}
let container = $(`<div class="sidebar-token-options-flyout-container prevent-sidebar-modal-close"></div>`);
// const updateValue = function(name, newValue) {
// if (is_valid_token_option_value(name, newValue)) {
// setValues[name] = newValue;
// } else {
// delete setValues[name];
// }
// };
availableOptions.forEach(option => {
if(option.hiddenSetting == true)
return;
const currentValue = setValues[option.name];
if (option.type === "dropdown") {
let inputWrapper = build_dropdown_input(option, currentValue, function(name, newValue) {
updateValue(name, newValue);
didChange();
});
container.append(inputWrapper);
} else if (option.type === "toggle") {
let inputWrapper = build_toggle_input(option, currentValue, function (name, newValue) {
updateValue(name, newValue);
didChange();
});
container.append(inputWrapper)
} else {
console.warn("build_sidebar_token_options_flyout failed to handle token setting option with type", option.type);
}
});
container.append(build_age_inputs([setValues['age']], [setValues['maxAge']],
function(age){
updateValue("age", age)
didChange();
},
function(maxAge, updateToken){
updateValue("maxAge", maxAge)
didChange();
}));
if(showExtraOptions){
window.TOKEN_SETTINGS.vision = (window.TOKEN_SETTINGS?.vision) ? window.TOKEN_SETTINGS.vision : {color: 'rgba(142, 142, 142, 1)'};
window.TOKEN_SETTINGS.light1 = (window.TOKEN_SETTINGS?.light1) ? window.TOKEN_SETTINGS.light1 : {color: 'rgba(255, 255, 255, 1)'};
window.TOKEN_SETTINGS.light2 = (window.TOKEN_SETTINGS?.light2) ? window.TOKEN_SETTINGS.light2 : {color: 'rgba(142, 142, 142, 1)'};
let lightInputs = `<div class="token-image-modal-footer-select-wrapper">
<div class="token-image-modal-footer-title">Darkvision Color</div>
<div style="padding-left: 2px">
<input class="spectrum" name="visionColor" value="${window.TOKEN_SETTINGS.vision.color}" >
</div>
</div>
<div class="token-image-modal-footer-select-wrapper">
<div class="token-image-modal-footer-title">Inner Light Color</div>
<div style="padding-left: 2px">
<input class="spectrum" name="light1Color" value="${window.TOKEN_SETTINGS.light1.color}" >
</div>
</div>
<div class="token-image-modal-footer-select-wrapper">
<div class="token-image-modal-footer-title">Outer Light Color</div>
<div style="padding-left: 2px">
<input class="spectrum" name="light2Color" value="${window.TOKEN_SETTINGS.light2.color}" >
</div>
</div>`;
container.append(lightInputs);
let colorPickers = container.find('input.spectrum');
colorPickers.spectrum({
type: "color",
showInput: true,
showInitial: true,
containerClassName: 'prevent-sidebar-modal-close',
clickoutFiresChange: true,
appendTo: "parent"
});
container.find("input[name='visionColor']").spectrum("set", window.TOKEN_SETTINGS.vision.color);
container.find("input[name='light1Color']").spectrum("set", window.TOKEN_SETTINGS.light1.color);
container.find("input[name='light2Color']").spectrum("set", window.TOKEN_SETTINGS.light2.color);
const colorPickerChange = function(e, tinycolor) {
didChange();
};
colorPickers.on('dragstop.spectrum', colorPickerChange); // update the token as the player messes around with colors
colorPickers.on('change.spectrum', colorPickerChange); // commit the changes when the user clicks the submit button
colorPickers.on('hide.spectrum', colorPickerChange); // the hide event includes the original color so let's change it back when we get it
}
update_token_base_visibility(container);
// Build example tokens to show the settings changes
container.append(`<h5 class="token-image-modal-footer-title" style="margin-top:15px;">Example Tokens</h5>`);
let tokenExamplesWrapper = $(`<div class="example-tokens-wrapper"></div>`);
container.append(tokenExamplesWrapper);
// not square image to show aspect ratio
tokenExamplesWrapper.append(build_example_token({imgsrc: "https://www.dndbeyond.com/avatars/thumbnails/6/359/420/618/636272697874197438.png"}));
// perfectly square image
tokenExamplesWrapper.append(build_example_token({imgsrc: "https://www.dndbeyond.com/avatars/8/441/636306375308314493.jpeg"}));
// idk, something else I guess
tokenExamplesWrapper.append(build_example_token({imgsrc: "https://i.imgur.com/2Lglcip.png"}));
let resetToDefaults = $(`<button class='token-image-modal-remove-all-button' title="Reset all token settings back to their default values." style="width:100%;padding:8px;margin:10px 0px;">Reset Token Settings to Defaults</button>`);
resetToDefaults.on("click", function (clickEvent) {
let tokenOptionsFlyoutContainer = $(clickEvent.currentTarget).parent();
// disable all toggle switches
tokenOptionsFlyoutContainer
.find(".rc-switch")
.each(function (){
let el = $(this);
let matchingOption = availableOptions.find(o => o.name === el.attr("name"));
el.toggleClass("rc-switch-checked", matchingOption.defaultValue)
})
.removeClass("rc-switch-unknown");
// set all dropdowns to their default values
tokenOptionsFlyoutContainer
.find("select")
.each(function () {
let el = $(this);
let matchingOption = availableOptions.find(o => o.name === el.attr("name"));
el.find(`option[value=${matchingOption.defaultValue}]`).attr('selected','selected');
});
// This is why we want multiple callback functions.