forked from cswendrowski/FoundryVTT-Custom-CSS
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsettings.js
More file actions
132 lines (120 loc) · 4.04 KB
/
settings.js
File metadata and controls
132 lines (120 loc) · 4.04 KB
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
import { CcssEditor } from './ccss-editor.js';
export const modName = 'Custom Css';
const mod = 'custom-css';
/**
* Provides functionality for interaction with module settings
*
* @export
* @class Settings
*/
export class Settings {
/**
* Retrieves the combined stylesheet data from settings.
*
* @static
* @param {scope} Which stylesheet to retrieve ("world" or "user")
* @return {string} The CSS stored in the stylesheet setting.
* @memberof Settings
*/
static getStylesheet(scope) {
if (scope === "world") {
const newSheet = game.settings.get(mod, "worldStylesheet");
if (newSheet === "/* Custom CSS */" || newSheet === "" ) {
try {
const oldSheet = game.settings.get(mod, "stylesheet");
if (oldSheet !== "/* Custom CSS */" && oldSheet !== "") {
this.setStylesheet(oldSheet, "world");
return oldSheet;
}
} catch (error) {
return newSheet; // If the old setting doesn't exist, return the new default
}
} else {
return newSheet;
}
} else if (scope === "user") {
return game.settings.get(mod, "userStylesheet");
}
return "";
}
/**
* Stores data in the world stylesheet settings.
*
* @static
* @param {string} css - The new CSS to be stored
* @param {string} scope - The scope of the stylesheet ("world" or "user")
* @return {Promise} A promise fulfilled once the setting has been stored.
* @memberof Settings
*/
static async setStylesheet(css, scope) {
const cssOrDefault = (css == null || css == undefined || css == "") ? "/* Custom CSS */" : css;
return game.settings.set(mod, `${scope}Stylesheet`, cssOrDefault);
}
/**
* Saves new stylesheet data, then reapplies the styles.
*
* @static
* @param {string} worldCss - The new CSS to be updated for the world.
* @param {string} userCss - The new CSS to be updated for the user.
* @memberof Settings
*/
static async updateStylesheets(worldCss, userCss) {
if (game.user.isGM) {
await this.setStylesheet(worldCss, "world");
}
await this.setStylesheet(userCss, "user");
window.CustomCss.applyStyles();
if (game.user.isGM) game.socket.emit("module.custom-css");
}
/**
* Fetch the game setting for whether or not to do a transition animation.
*
* @readonly
* @static
* @memberof Settings
*/
static get doTransition() {
return game.settings.get(mod, "transition");
}
/**
* Registers all of the necessary game settings for the module
*
* @static
* @memberof Settings
*/
static registerSettings() {
game.settings.register(mod, "stylesheet", {
scope: "world",
config: false,
type: String,
default: "/* Custom CSS */"
});
game.settings.register(mod, "worldStylesheet", {
scope: "world",
config: false,
type: String,
default: "/* Custom CSS */"
});
game.settings.register(mod, "userStylesheet", {
scope: "client",
config: false,
type: String,
default: "/* Custom CSS */"
});
game.settings.registerMenu(mod, 'settingsMenu', {
name: game.i18n.localize("CCSS.settings.settingsMenu.name"),
label: game.i18n.localize("CCSS.settings.settingsMenu.label"),
icon: "fas fa-wrench",
type: CcssEditor,
restricted: false
});
game.settings.register(mod, "transition", {
name: game.i18n.localize("CCSS.settings.transition.name"),
hint: game.i18n.localize("CCSS.settings.transition.hint"),
scope: "client",
config: true,
type: Boolean,
default: true
});
}
}