forked from kakaroto/Beyond20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdndbeyond_vehicle.pyj
50 lines (39 loc) · 1.42 KB
/
dndbeyond_vehicle.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
from settings import getDefaultSettings, getStoredSettings
from dndbeyond import Monster, isRollButtonAdded
from utils import injectCSS, alertFullSettings
from constants import BUTTON_STYLE_CSS,ROLLTYPE_STYLE_CSS
print("Beyond20: D&D Beyond Vehicle module loaded.")
settings = getDefaultSettings()
character = None
def documentLoaded(settings):
nonlocal character
character = Monster("Vehicle", global_settings=settings)
# We reloaded the extension? reload the page too...
if isRollButtonAdded():
chrome.runtime.sendMessage({"action": "reload-me"})
else:
character.parseStatBlock()
def updateSettings(new_settings=None):
nonlocal settings
nonlocal character
if new_settings:
settings = new_settings
if character is not None:
character.setGlobalSettings(settings)
else:
getStoredSettings(def(saved_settings):
nonlocal settings
updateSettings(saved_settings)
documentLoaded(settings)
)
def handleMessage (request, sender, sendResponse):
if request.action == "settings":
if request.type == "general":
updateSettings(request.settings)
elif request.action == "open-options":
alertFullSettings()
injectCSS(BUTTON_STYLE_CSS)
injectCSS(ROLLTYPE_STYLE_CSS)
chrome.runtime.onMessage.addListener(handleMessage)
chrome.runtime.sendMessage({"action": "activate-icon"})
updateSettings()