forked from kakaroto/Beyond20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.pyj
681 lines (607 loc) · 33 KB
/
settings.pyj
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
from elementmaker import E
from utils import roll20Title, fvttTitle, isFVTT
class WhisperType:
NO = 0
YES = 1
QUERY = 2
HIDE_NAMES = 3
class RollType:
NORMAL = 0
DOUBLE = 1
QUERY = 2
ADVANTAGE = 3
DISADVANTAGE = 4
THRICE = 5
SUPER_ADVANTAGE = 6
SUPER_DISADVANTAGE = 7
# If a feat overrides it to have advantage
OVERRIDE_ADVANTAGE = 8
class CriticalRules:
PHB = 0
HOMEBREW_MAX = 1
HOMEBREW_DOUBLE = 2 # Impossible to achieve with Roll20 and hard with RollRenderer because of brutal and other mods.
HOMEBREW_MOD = 3
HOMEBREW_REROLL = 4
# keys: [short, title, description, type, default]
# Types: bool, string, combobox, link, special
# combobox extra options:
# choices: {value: string}
# special extra options:
# createHTMLElement: function
# set: function
# get: function
options_list = {
"whisper-type": {"short": "Whisper rolls",
"title": "Whisper rolls to the DM",
"description": "Determines if the rolls will be whispered to the DM.\n" \
"In the case of Foundry VTT, the 'ask every time' option will use the setting in the chat box.",
"type": "combobox",
"default": WhisperType.NO,
"choices": {str(WhisperType.NO): "Never whisper",
str(WhisperType.YES): "Always whisper",
str(WhisperType.QUERY): "Ask every time"}},
"whisper-type-monsters": {"title": "Whisper monster rolls to the DM",
"description": "Overrides the global whisper setting from monster stat blocks",
"type": "combobox",
"default": WhisperType.YES,
"choices": {str(WhisperType.NO): "Use general whisper setting",
str(WhisperType.HIDE_NAMES): "Hide monster and attack name",
str(WhisperType.YES): "Always whisper monster rolls",
str(WhisperType.QUERY): "Ask every time"}},
"roll-type": {"short": "Type of Roll",
"title": "Type of Roll (Advantange/Disadvantage)",
"description": "Determines if rolls should be with advantage, disadvantage, double rolls or user queries",
"type": "combobox",
"default": RollType.NORMAL,
"choices": {str(RollType.NORMAL): "Normal Roll",
str(RollType.DOUBLE): "Always roll twice",
str(RollType.QUERY): "Ask every time",
str(RollType.ADVANTAGE): "Roll with Advantage",
str(RollType.DISADVANTAGE): "Roll with Disadvantage",
str(RollType.THRICE): "Always roll thrice (limited support on Roll20)",
str(RollType.SUPER_ADVANTAGE): "Roll with Super Advantage",
str(RollType.SUPER_DISADVANTAGE): "Roll with Super Disadvantage",}},
"quick-rolls": {"short": "Add Quick Roll areas",
"title": "Add Quick Rolls areas to main page",
"description": "Listen to clicks in specific areas of the abilities, skills, actions and spells to quickly roll them.",
"type": "bool",
"default": True},
"auto-roll-damage": {"title": "Auto roll Damage and Crit",
"description": "Always roll damage and critical hit dice when doing an attack",
"type": "bool",
"default": True},
"initiative-tracker": {"title": "Add initiative roll to the Turn Tracker",
"description": "Adds the result of the initiative roll to the turn tracker.\n" \
"This requires you to have a token selected in the VTT\n" \
"If using Roll20, it will also change the way the output of 'Advantage on initiative' rolls appear.",
"type": "bool",
"default": True},
"initiative-tiebreaker": {"title": "Add tiebreaker to initiative rolls",
"description": "Adds the dexterity score as a decimal to initiative rolls to break any initiative ties.",
"type": "bool",
"default": False},
"critical-homebrew": {"title": "Critical hit rule",
"description": "Determines how the additional critical hit damages are determined",
"type": "combobox",
"default": CriticalRules.PHB,
"choices": {str(CriticalRules.PHB): "Standard PHB Rules (reroll dice)",
str(CriticalRules.HOMEBREW_MAX): "Homebrew: Perfect rolls",
str(CriticalRules.HOMEBREW_REROLL): "Homebrew: Reroll all damages"}},
"weapon-force-critical": {"title": "Force all attacks as Critical Hits",
"description": "Forces all attacks to be considered as critical hits. Useful for melee attacks against paralyzed enemies or using adamantine weapons against objects",
"short": "Force Critical Hits",
"short_description": "Useful for melee attacks against paralyzed enemies or using adamantine weapons against objects",
"type": "bool",
"default": False},
"update-hp": {"title": "Update VTT Token HP",
"description": "When changing HP in D&D Beyond, update it in the VTT tokens and sheets",
"type": "bool",
"default": True},
"display-conditions": {"title": "Display Condition updates to VTT",
"description": "When updating character conditions in D&D Beyond, display a message in the VTT chat.\n" \
"If using FVTT with the Beyond20 module, it will also update the token's status icons appropriately.",
"type": "bool",
"default": True},
"template": {"type": "migrate",
"default": "roll20-template"},
"roll20-template": {"title": "Roll20 Character Sheet Setting",
"description": "Select the Character Sheet Template that you use in Roll20\n" \
"If the templates do not match, you will not see anything printed in the Roll20 chat.",
"type": "combobox",
"default": "roll20",
"choices": {"roll20": "D&D 5E By Roll20", "default": "Other templates"}},
"subst-roll20": {"type": "migrate",
"default": "subst-vtt"},
"subst-vtt": {"title": "Replace Dices formulas in the VTT",
"description": "In Roll20 or Foundry VTT, if a spell card or an item or a feat has a dice formula in its description,\n" \
"enabling this will make the formula clickable to generate the roll in chat.",
"type": "bool",
"default": True},
"subst-dndbeyond": {"title": "Replace Dices formulas in D&D Beyond (Spells & Character Sheet)",
"description": "In the D&D Beyond Spell page or Character sheet side panel, if a spell, item, feat or action has a dice formula in its description,\n" \
"enabling this will add a dice icon next to the formula to allow you to roll it.",
"type": "bool",
"default": True},
"subst-dndbeyond-stat-blocks": {"title": "Replace Dices formulas in D&D Beyond (Stat blocks)",
"description": "In D&D Beyond, if a dice formula is found in the stat block of a creature, monster, vehicle,\n" \
"enabling this will add a dice icon next to the formula to allow you to roll it.",
"type": "bool",
"default": True},
"handle-stat-blocks": {"title": "Add roll buttons to stat blocks",
"description": "In D&D Beyond, adds roll buttons for abilities/saving throws/skills/actions to the stat block of a creature, monster or vehicle.",
"type": "bool",
"default": True},
"crit-prefix": {"title": "Critical Hit Prefix",
"description": "Prefix to add to the Critical Hit dice result.\nIt might be less confusing to explicitely show the crit damage",
"type": "string",
"default": "Crit: "},
"components-display": {"title": "Components to display in spell attacks",
"description": "When doing a spell attack, what components to show alongside the spell roll.",
"type": "combobox",
"default": "all",
"choices": {"all": "All components", "material": "Only material components", "none": "Do not display anything"}},
"component-prefix": {"title": "Component Prefix",
"description": "Prefix to the components display of a spell attack.\nIf displaying material components only, you may want to set it to 'Materials used :' for example",
"type": "string",
"default": "Components: "},
"roll20-tab": {"type": "migrate",
"default": "vtt-tab"},
"vtt-tab": {"title": "Select the VTT tab or Game to send rolls to",
"description": "Select the tab to send rolls to or the specific Game.\nYou can select the Game or tab from the extension's popup menu in the VTT tab itself.\nAfter a specific tab is selected and that tab is closed, it will revert to sending rolls to the same Game.",
"type": "special",
"default": None}, # callbacks will be added after the functions are defined
"discord-integration": {"title": "Discord Integration",
"description": "You can get rolls sent to Discord by enabling Discord Integration!\n" \
"Click the link, follow the instructions and enter your secret key below.",
"type": "link",
"default": "https://beyond20.here-for-more.info/discord",
"icon": "https://discordapp.com/assets/fc0b01fe10a0b8c602fb0106d8189d9b.png",
"icon-height": "80"},
"discord-secret": {"title": "Discord Bot Secret Key",
"description": "Enter the secret key the Bot gave you, or Discord server owner. Clear it to disable Discord integration.\n" \
"Note that sending to Discord only works with the D&D Beyond Dice Roller, and Foundry VTT.",
"type": "string",
"default": ""},
"show-changelog": {"title": "Show Changelog when installing a new version",
"description": "When a new version is released and the extension has been updated,\n" \
"open the changelog in a new window",
"type": "bool",
"default": True},
"last-version": {"description": "Last version that was installed. Used to check if an update just happened",
"type": "string",
"hidden": True,
"default": ""},
"donate": {"short": "Buy rations (1 day) to feed my familiar",
"title": "Become a patron of the art of software development!",
"description": "If you wish to support my work on Beyond 20 or my other D&D related project, subscribe to my patreon " \
"or donate via paypal!\nI am grateful for your generosity!",
"type": "link",
"default": "https://beyond20.here-for-more.info/rations",
"icon": "/images/donate.png",
"icon-width": "64",
"icon-height": "64"}
}
character_settings = {
"versatile-choice": {"title": "Versatile weapon choice",
"description": "How to roll damage for Versatile weapons",
"type": "combobox",
"default": "both",
"choices": {"both": "Roll both damages separately", "one": "Use weapon One-handed", "two": "Use weapon Two-handed"}},
"custom-roll-dice": {"title": "Custom Roll dice formula bonus",
"description": "Add custom formula to d20 rolls (Bless, Guidance, Bane, Magic Weapon, etc..)",
"type": "string",
"default": ""},
"custom-damage-dice": {"title": "Custom Damage dice formula bonus",
"description": "Add custom dice to damage rolls (Magic Weapon, Elemental Weapon, Green-flame Blade, etc..). Use a comma to separate multiple independent rolls.",
"type": "string",
"default": ""},
"rogue-sneak-attack": {"title": "Rogue: Sneak Attack",
"description": "Send Sneak Attack damage with each attack roll",
"type": "bool",
"default": True},
"cleric-disciple-life": {"title": "Cleric: Disciple of Life",
"description": "Send Disciple of Life healing bonus",
"type": "bool",
"default": True},
"bard-joat": {"title": "Bard: Jack of All Trades",
"description": "Add JoaT bonus to raw ability checks",
"type": "bool",
"default": True},
"sharpshooter": {"title": "Fighter: Sharpshooter (Apply to next roll only)",
"description": "Apply Sharpshooter -5 penalty to roll and +10 to damage",
"type": "bool",
"default": False},
"great-weapon-master": {"title": "Great Weapon Master Feat (Apply to next roll only)",
"description": "Apply Great Weapon Master -5 penalty to roll and +10 to damage",
"type": "bool",
"default": False},
"brutal-critical": {"title": "Brutal Critical/Savage Attacks: Roll extra die",
"description": "Roll extra damage die on crit for Brutal Critical and Savage Attacks features",
"type": "bool",
"default": True},
"barbarian-rage": {"title": "Rage: You are raging, ARRGGHHHHHH",
"description": "Add Rage damage to melee attacks and add advantage to Strength checks and saving throws",
"type": "bool",
"default": False},
"bloodhunter-crimson-rite": {"title": "Bloodhunter: Crimson Rite",
"description": "Add Crimson Rite damage",
"type": "bool",
"default": False},
"ranger-dread-ambusher": {"title": "Ranger: Dread Ambusher",
"description": "Add Dread Ambusher attack 1d8 extra damage",
"type": "bool",
"default": False},
"paladin-legendary-strike": {"title": "Paladin: Legendary Strike",
"description": "Channel Divinity and score critical hits on rolls of 19 and 20",
"type": "bool",
"default": False},
"paladin-improved-divine-smite": {"title": "Paladin: Improved Divine Smite",
"description": "Roll an extra 1d8 radiant damage whenever you hit with a melee weapon",
"type": "bool",
"default": True},
"warlock-hexblade-curse": {"title": "Warlock: Hexblade's Curse",
"description": "Apply the Hexblade's Curse extra damage on attack rolls and score critical hits on rolls of 19 and 20",
"type": "bool",
"default": False},
"rogue-assassinate": {"title": "Rogue: Assassinate surprise attack (Apply to next roll only)",
"description": "Roll with advantage and roll critical damage dice",
"type": "bool",
"default": False},
"fighter-giant-might": {"title": "Fighter: Giant Might",
"description": "Activate Giant Might to get advantage on Strength checks and saving throws and deal 1d6 extra damage",
"type": "bool",
"default": False},
"artificer-arcane-firearm": {"title": "Artificer: Use Arcane Firearm",
"description": "Use an Arcane Firearm for your Artificer spells. Deals extra 1d8 damage",
"type": "bool",
"default": False},
"cleric-divine-strike": {"title": "Cleric: Divine Strike",
"description": "Deal an extra 1d8 (2d8 at level 14) damage to melee weapon attacks",
"type": "bool",
"default": True},
"bard-psychic-blades": {"title": "Bard: Psychic Blades",
"description": "Use your Bardic Inspiration to deal extra psychic damage (Apply to next roll only)",
"type": "bool",
"default": False}
}
def getStorage():
return chrome.storage.sync
def storageGet(name, default_value, cb):
getStorage().get({name: default_value}, def (items):
cb(items[name])
)
def storageSet(name, value, cb=None):
getStorage().set({name: value}, def ():
if chrome.runtime.lastError:
console.log('Chrome Runtime Error', chrome.runtime.lastError.message)
elif cb:
cb(value)
)
def storageRemove(names, cb=None):
getStorage().remove(names, def ():
if cb:
cb(names)
)
def getDefaultSettings(_list=options_list):
settings = {}
for option in _list:
settings[option] = _list[option].default
#console.log("Default settings :", settings)
return settings
def getStoredSettings(cb, key="settings", _list=options_list):
settings = getDefaultSettings(_list)
gotSettings = def(stored_settings):
#print("Beyond20: Stored settings (" + key + "):", stored_settings)
migrated_keys = []
for opt in settings:
if _list[opt].type == "migrate":
if opt in stored_settings:
if stored_settings[opt] != _list[opt].default:
# Migrate opts over when loading them
stored_settings[_list[opt].default] = stored_settings[opt]
migrated_keys.append(opt)
del stored_settings[opt]
elif opt not in stored_settings:
# On Firefox, if setting is not in storage, it won't return the default value
stored_settings[opt] = settings[opt]
if migrated_keys.length > 0:
print("Beyond20: Migrated some keys:", stored_settings)
storageSet(key, stored_settings)
cb(stored_settings)
storageGet(key, settings, gotSettings)
def setSettings(settings, cb=None, key="settings"):
storageSet(key, settings, def(settings):
console.log("Beyond20: Saved settings (" + key + "): ", settings)
if cb:
cb(settings)
)
def mergeSettings(settings, cb=None, key="settings", _list=options_list):
console.log("Saving new settings (" + key + "): ", settings)
def setNewSettings(stored_settings):
for k in settings:
stored_settings[k] = settings[k]
setSettings(stored_settings, cb, key)
getStoredSettings(setNewSettings, key, _list)
def resetSettings(cb=None, _list=options_list):
setSettings(getDefaultSettings(_list), cb)
def createHTMLOptionEx(name, option, short=False):
if (option.hidden == True) or \
(short and not option.short?) or \
(not option.title?):
return None
description = option.short_description if short else option.description
description_p = list(map(E.p, description.split("\n"))) if description else []
title = option.short if short else option.title
if option.type == "bool":
e = E.li(class_="list-group-item beyond20-option beyond20-option-bool",
E.label(class_="list-content", for_=name,
E.h4(title),
*description_p,
E.div(class_='material-switch pull-right',
E.input(id=name, class_="beyond20-option-input", name=name, type_="checkbox"),
E.label(for_=name, class_="label-default")
)
)
)
elif option.type == "string":
e = E.li(class_="list-group-item beyond20-option beyond20-option-string",
E.label(class_="list-content", for_=name,
E.h4(title),
*description_p,
E.div(class_="right-entry",
E.input(id=name, class_="beyond20-option-input", name=name, type_="text")
)
)
)
elif option.type == "combobox":
make_li = def(o):
return E.li(E.a(href="#", o))
dropdown_options = list(map(make_li, Object.values(option.choices)))
for p in description_p:
p.classList.add("select")
e = E.li(class_="list-group-item beyond20-option beyond20-option-combobox",
E.label(class_="list-content", for_=name,
E.h4(class_="select", title),
*description_p,
E.div(class_="button-group",
E.a(id=name, class_="input select beyond20-option-input", href="", option.choices[option.default]),
E.ul(class_="dropdown-menu",
*dropdown_options),
E.i(id=name + "--icon", class_="icon select")
)
)
)
elif option.type == "link":
e = E.li(class_="list-group-item beyond20-option beyond20-option-link",
E.label(class_="list-content", id=name,
E.a(href=option.default,
E.h4(title)),
*description_p,
E.a(href=option.default,
E.div(class_="image-link",
E.img(class_="link-image", width=option['icon-width'], height=option['icon-height'], src=chrome.extension.getURL(option.icon) if option.icon.startsWith("/") else option.icon)
)
)
)
)
elif option.type == "special":
e = option.createHTMLElement(name, short)
return e
def createHTMLOption(name, short=False, _list=options_list):
return createHTMLOptionEx(name, _list[name], short)
def initializeMarkaGroup(group):
triggerOpen = $(group).find('.select')
triggerClose = $(group).find('.dropdown-menu li')
dropdown_menu = $(group).find(".dropdown-menu")
button_group = $(group).find(".button-group")
marka = $(group).find('.icon')
input = $(group).find('.input')
# set initial Marka icon
m = new Marka('#' + marka.attr("id"))
m.set('triangle').size(10)
m.rotate('down')
# trigger dropdown
$(group).find('.button-group').append(marka)
makeOpenCB = def(dropdown_menu, icon, m):
return def(event):
event.preventDefault()
dropdown_menu.toggleClass('open')
button_group.toggleClass('open')
if icon.hasClass("marka-icon-times"):
m.set('triangle').size(10)
else:
m.set('times').size(15)
makeCloseCB = def(dropdown_menu, input, m):
return def(event):
event.preventDefault()
input.text(this.innerText)
input.trigger("markaChanged")
dropdown_menu.removeClass('open')
button_group.removeClass('open')
m.set('triangle').size(10)
triggerOpen.bind("click", makeOpenCB(dropdown_menu, marka, m))
triggerClose.bind("click", makeCloseCB(dropdown_menu, input, m))
def initializeMarka():
groups = $('.beyond20-option-combobox')
for group in groups:
initializeMarkaGroup(group)
def extractSettingsData(_list=options_list):
settings = {}
for option in _list:
e = $("#" + option)
if e.length > 0:
o_type = _list[option].type
if o_type == "bool":
settings[option] = e.prop('checked')
elif o_type == "combobox":
val = e.text()
choices = _list[option].choices
for key in choices:
if choices[key] == val:
settings[option] = key
break
elif o_type == "string":
settings[option] = e.val()
elif o_type == "special":
settings[option] = _list[option].get(option)
return settings
def loadSettings(settings, _list=options_list):
for option in settings:
if not _list[option]:
continue
o_type = _list[option].type
if o_type == "bool":
$("#" + option).prop('checked', settings[option])
elif o_type == "combobox":
val = settings[option]
choices = _list[option].choices
$("#" + option).text(choices[val])
elif o_type == "string":
$("#" + option).val(settings[option])
elif o_type == "special":
_list[option].set(option, settings)
def restoreSavedSettings(cb=None, key="settings", _list=options_list):
load = def(stored_settings):
loadSettings(stored_settings, _list)
if cb:
cb(stored_settings)
getStoredSettings(load, key, _list)
def saveSettings(cb, key="settings", _list=options_list):
mergeSettings(extractSettingsData(_list), cb, key, _list)
def initializeSettings(cb=None):
initializeMarka()
restoreSavedSettings(cb)
def createRoll20TabCombobox(name, short, dropdown_options):
opt = options_list[name]
description = "Restrict where rolls are sent.\nUseful if you have multiple VTT windows open" if short else opt.description
title = "Send Beyond 20 rolls to" if short else opt.title
description_p = list(map(E.p, description.split("\n")))
options = []
for option in dropdown_options:
options.append(E.li(E.a(href="#", option)))
for p in description_p:
p.classList.add("select")
return E.li(id="beyond20-option-vtt-tab",
class_="list-group-item beyond20-option beyond20-option-combobox" + (" vtt-tab-short" if short else ""),
E.label(class_="list-content", for_=name,
E.h4(class_="select", title),
*description_p,
E.div(class_="button-group",
E.a(id=name, class_="input select beyond20-option-input", href="", "All VTT Tabs"),
E.ul(class_="dropdown-menu",
*options),
E.i(id=name + "--icon", class_="icon select")
)
)
)
def createVTTTabSetting(name, short):
nonlocal current_tab
dropdown_options = ["All VTT Tabs",
"Only Roll20 Tabs",
"Only Foundry VTT Tabs",
"D&D Beyond Dice Roller & Discord"]
if short:
vtt = "Foundry VTT" if isFVTT(current_tab.title) else "Roll20"
campaign = "World" if vtt == "Foundry VTT" else "Campaign"
dropdown_options.append("This " + campaign)
dropdown_options.append("This Specific Tab")
return createRoll20TabCombobox(name, short, dropdown_options)
def setVTTTabSetting(name, settings):
nonlocal current_tab
val = settings[name]
combobox = $("#beyond20-option-vtt-tab")
if combobox.length == 0:
return
if val is None:
$("#" + name).text("All VTT Tabs")
elif val.title is None:
vtt = val.vtt ? "roll20"
if vtt == "dndbeyond":
choice = "D&D Beyond Dice Roller & Discord"
else:
vtt_name = "Roll 20" if vtt == "roll20" else "Foundry VTT"
choice = "Only " + vtt_name + " Tabs"
$("#" + name).text(choice)
else:
id, title, vtt = (val.id, val.title, val.vtt ? "roll20")
vtt_name = "Roll 20" if vtt == "roll20" else "Foundry VTT"
campaign = "Campaign" if vtt == "roll20" else "World"
short = combobox.hasClass("vtt-tab-short")
if short:
console.log("Set roll20 tab, is SHORT ", val)
current_vtt = "fvtt" if isFVTT(current_tab.title) else "roll20"
current_campaign = "Campaign" if current_vtt == "roll20" else "World"
current_title = roll20Title(current_tab.title) if current_vtt == "roll20" else fvttTitle(current_tab.title)
current_id = current_tab.id
console.log("vtt-tab settings are : ", id, title, vtt, current_id, current_title, current_vtt)
if id == 0 and title == current_title and current_vtt == vtt:
$("#" + name).text("This " + campaign)
elif id == current_id and title == current_title and current_vtt == vtt:
$("#" + name).text("This Specific Tab")
else:
new_options = [ "All VTT Tabs",
"Only Roll20 Tabs",
"Only Foundry VTT Tabs",
"D&D Beyond Dice Roller & Discord",
"This " + current_campaign,
"This Specific Tab"]
if current_vtt == vtt:
new_options.append("Another tab or " + campaign.toLowerCase() + "(No change)")
else:
new_options.append("A " + vtt_name + " " + campaign.toLowerCase() + "(No change)")
else:
console.log("Set vtt tab, is LONG ", val)
console.log("vtt-tab settings are : ", id, title, vtt)
new_options = ["All VTT Tabs",
"Only Roll20 Tabs",
"Only Foundry VTT Tabs",
"D&D Beyond Dice Roller & Discord",
campaign + ": " + title]
if id != 0:
new_options.append("Tab #" + id + " (" + title +")")
if new_options?:
dropdown_options = []
for option in new_options:
dropdown_options.append(E.li(E.a(href="#", option)))
combobox.replaceWith(createRoll20TabCombobox("vtt-tab", short, dropdown_options))
initializeMarkaGroup($("#beyond20-option-vtt-tab"))
console.log("Added new options", dropdown_options)
$("#" + name).text(new_options[-1].replace("(No change)", ""))
$("#" + name).attr("x-beyond20-id", id)
$("#" + name).attr("x-beyond20-title", title)
$("#" + name).attr("x-beyond20-vtt", vtt)
def getVTTTabSetting(name):
nonlocal current_tab
opt = $("#" + name)
value = opt.text()
saved_id = opt.attr("x-beyond20-id")
saved_title = opt.attr("x-beyond20-title")
saved_vtt = opt.attr("x-beyond20-vtt")
if value == "All VTT Tabs":
ret = None
elif value in ["This Campaign", "This World", "This Specific Tab"]:
vtt = "fvtt" if isFVTT(current_tab.title) else "roll20"
title = fvttTitle(current_tab.title) if vtt == "fvtt" else roll20Title(current_tab.title)
ret = {"id": (0 if value in ["This Campaign", "This World"] else current_tab.id),
"title": title,
"vtt": vtt}
elif value == "Only Roll20 Tabs":
ret = {"id": 0, "title": None, "vtt": "roll20"}
elif value == "Only Foundry VTT Tabs":
ret = {"id": 0, "title": None, "vtt": "fvtt"}
elif value == "D&D Beyond Dice Roller & Discord":
ret = {"id": 0, "title": None, "vtt": "dndbeyond"}
elif value.startsWith("Campaign: ") or value.startsWith("World: "):
ret = {"id": 0, "title": saved_title, "vtt": saved_vtt}
else:
# "Another tab or campaign (No change)", "A Roll20 game", "A FVTT game", "Tab #"
ret = {"id": saved_id, "title": saved_title, "vtt": saved_vtt}
console.log("Get " + vtt + " tab: ", ret)
return ret
def setCurrentTab(tab):
nonlocal current_tab
current_tab = tab
current_tab = None
options_list["vtt-tab"]["createHTMLElement"] = createVTTTabSetting
options_list["vtt-tab"]["set"] = setVTTTabSetting
options_list["vtt-tab"]["get"] = getVTTTabSetting