-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdnd5edark.js
155 lines (127 loc) · 4.5 KB
/
dnd5edark.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
class Dnd5eDark {
static init () {
this._initModule();
this._initWhetstone();
}
static _initModule () {
Hooks.on('init', () => {
this._initModuleCompat();
// If Whetstone is active, stop here
if (!!game.modules.get('Whetstone')?.active) return;
$(`<link href="modules/dnd5e-dark-mode/dark-mode.css" rel="stylesheet" type="text/css" media="all">`).appendTo(document.head);
game.settings.register("dnd5e-dark-mode", game.userId, {
name: "Activate Foundry wide Dark Mode?", // Change for description
// hint: "Hint?" // uncomment this line for a small description text/hint
config: true,
default: false,
type: Boolean,
scope: 'user',
onChange: data => {
if (data === true) document.body.classList.add(Dnd5eDark._CSS_CLASS_NAME);
else document.body.classList.remove(Dnd5eDark._CSS_CLASS_NAME);
}
});
const setDarkMode = game.settings.get('dnd5e-dark-mode', game.userId);
if (setDarkMode === true) document.body.classList.add(Dnd5eDark._CSS_CLASS_NAME);
});
}
static _initWhetstone () {
let isInit = false;
let isWhetstoneReady = false;
const doWhetstoneInit = () => {
const moduleJson = game.modules.get("dnd5e-dark-mode").data;
Hooks.on('onThemeActivate', (themeData) => {
if (themeData.id === moduleJson.name) {
document.body.classList.add(Dnd5eDark._CSS_CLASS_NAME);
}
return true
});
Hooks.on('onThemeDeactivate', (themeData) => {
if (themeData.id === moduleJson.name && document.body.classList.contains(Dnd5eDark._CSS_CLASS_NAME)) {
document.body.classList.remove(Dnd5eDark._CSS_CLASS_NAME);
}
});
game.Whetstone.themes.register('dnd5e-dark-mode', {
id: moduleJson.name,
name: moduleJson.name,
title: moduleJson.title,
description: moduleJson.description,
version: moduleJson.version,
authors: [
{
name: `Stryxin`,
contact: 'Github',
url: 'https://github.com/Stryxin'
}
],
variables: [],
styles: [
"modules/dnd5e-dark-mode/dark-mode.css"
],
presets: {},
dialog: '',
config: '',
dependencies: {},
systems: {core: moduleJson.minimumCoreVersion},
compatible: {dnd5e: '0.9.8'},
conflicts: {}
});
game.Whetstone.settings.registerMenu(moduleJson.name, moduleJson.name, {
name: game.i18n.localize('WHETSTONE.Config'),
label: game.i18n.localize('WHETSTONE.ConfigTitle'),
hint: game.i18n.localize('WHETSTONE.ConfigHint'),
icon: 'fas fa-paint-brush',
restricted: false
});
};
Hooks.once("init", () => {
isInit = true;
if (!isWhetstoneReady) return;
doWhetstoneInit();
})
Hooks.once('WhetstoneReady', () => {
isWhetstoneReady = true;
if (!isInit) return;
doWhetstoneInit();
});
}
static _initModuleCompat () {
this._initCompat_betterNpcSheets();
this._initCompat_plutonium();
this._initCompat_beyond20();
this._initCompat_tokenHealth();
}
static async _initCompat_betterNpcSheets () {
if (!game.modules.get("betternpcsheet5e")?.active) return;
$(`<link href="modules/dnd5e-dark-mode/compat/betternpcsheet-dark.css" rel="stylesheet" type="text/css" media="all">`).appendTo(document.head);
// dynamically import the js file and get the needed class
const BetterNPCActor5eSheet = (await import('../../modules/betternpcsheet5e/betternpcsheet.js')).BetterNPCActor5eSheet;
// Define your custom class
class BetterNPCActor5eSheetDark extends BetterNPCActor5eSheet {
static get defaultOptions () {
const options = super.defaultOptions;
options.classes.push('betternpcsheet-dark'); // this is the css class selector to apply the dark theme to
return options;
}
}
// Register the sheet
Actors.registerSheet("dnd5e", BetterNPCActor5eSheetDark, {
types: ["npc"],
makeDefault: true
});
}
static _initCompat_plutonium () {
if (!game.modules.get("plutonium")?.active) return;
$(`<link href="modules/dnd5e-dark-mode/compat/plutonium-dark.css" rel="stylesheet" type="text/css" media="all">`).appendTo(document.head);
}
static _initCompat_beyond20 () {
if (!game.modules.get("beyond20")?.active) return;
$(`<link href="modules/dnd5e-dark-mode/compat/beyond20-dark.css" rel="stylesheet" type="text/css" media="all">`).appendTo(document.head);
}
static _initCompat_tokenHealth () {
if (!game.modules.get("token-health")?.active) return;
$(`<link href="modules/dnd5e-dark-mode/compat/token-health-dark.css" rel="stylesheet" type="text/css" media="all">`).appendTo(document.head);
}
}
Dnd5eDark._CSS_CLASS_NAME = "dark-mode";
Dnd5eDark.init();