forked from nommiin/builder
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBuilderPreferences.js
171 lines (159 loc) · 5.82 KB
/
BuilderPreferences.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
class BuilderPreferences {
static path = Electron_App.getPath("userData") + "/GMEdit/config/Builder-preferences.json";
static current = {
reuseTab: false,
saveCompile: false,
stopCompile: false,
displayLine: true,
forkArguments: "",
forkInSideView: false,
showRunAndFork: false,
useVirtualDrives: false,
cleanOnError: false,
cleanAfterRun: false,
runtimeSettings: {
Stable: {
location: process.env.ProgramData + "/GameMakerStudio2/Cache/runtimes/",
runtimeList: [],
selection: ""
},
Beta: {
location: process.env.ProgramData + "/GameMakerStudio2-Beta/Cache/runtimes/",
runtimeList: [],
selection: ""
}
}
};
static save() {
Electron_FS.writeFileSync(this.path, JSON.stringify(this.current, (k, v) => {
return k == "runtimeList" ? undefined : v;
}, " "));
}
static load() {
Object.assign(this.current, JSON.parse(Electron_FS.readFileSync(this.path)));
}
static init() {
if (Electron_FS.existsSync(this.path)) {
try {
this.load();
let pref = this.current;
if (pref.runtimeLocation != null) {
// migrate legacy settings
this.Preferences.runtimeSettings.Stable.location = this.Preferences.runtimeLocation;
delete this.Preferences.runtimeLocation;
this.Preferences.runtimeSettings.Stable.selection = this.Preferences.runtimeSelection;
delete this.Preferences.runtimeSelection;
delete this.Preferences.runtimeList;
}
} catch (x) {
console.error("[Builder] Failed to load preferences:", x);
}
} else this.save();
}
static element;
static build() {
const Preferences = $gmedit["ui.Preferences"];
let root = document.createElement("div");
this.element = root;
const addSep = (out) => {
let hr = document.createElement("hr");
out.appendChild(hr);
}
for (let [key, set] of Object.entries(this.current.runtimeSettings)) {
let runtimeGroup = Preferences.addGroup(root, `Runtime Settings (${key})`);
let element, label;
element = Preferences.addInput(runtimeGroup, "Runtime Location", set.location, (value) => {
set.location = value;
BuilderPreferences.save();
});
let runtimeLocationInput = element.querySelector("input");
label = element.querySelector("label");
label.appendChild(document.createTextNode(" ("));
label.appendChild(Preferences.createFuncAnchor("Reset", function() {
switch (key) {
case "Stable": set.location = process.env.ProgramData + "/GameMakerStudio2/Cache/runtimes/"; break;
case "Beta": set.location = process.env.ProgramData + "/GameMakerStudio2-Beta/Cache/runtimes/"; break;
default: return;
}
runtimeLocationInput.value = set.location;
BuilderPreferences.save();
}));
label.appendChild(document.createTextNode(")"));
element = Preferences.addDropdown(runtimeGroup, "Current Runtime", set.selection, set.runtimeList, (value) => {
set.selection = value;
BuilderPreferences.save();
});
let runtimeListSelect = element.querySelector("select");
label = element.querySelector("label");
label.appendChild(document.createTextNode(" ("));
label.appendChild(Preferences.createFuncAnchor("Rescan", function() {
runtimeListSelect.innerHTML = "";
for (let rt of Builder.GetRuntimes(set.location)) {
let option = document.createElement("option");
option.innerHTML = option.value = rt;
runtimeListSelect.appendChild(option);
}
runtimeListSelect.value = set.selection;
BuilderPreferences.save();
}));
label.appendChild(document.createTextNode(")"));
}
let settingsGroup = Preferences.addGroup(root, "Builder Settings");
if (Builder.Platform == "win") {
Preferences.addCheckbox(settingsGroup, 'Use virtual drives', this.current.useVirtualDrives, (value) => {
this.current.useVirtualDrives = value;
this.save();
});
Preferences.addButton(settingsGroup, "Clean virtual drives", () => {
BuilderDrives.clean();
});
addSep(settingsGroup);
}
Preferences.addCheckbox(settingsGroup, 'Show "Run & Fork" in main menu', this.current.showRunAndFork, (value) => {
this.current.showRunAndFork = value;
Builder.MenuItems.runAndFork.visible = value;
this.save();
});
Preferences.addInput(settingsGroup, "Fork Arguments", this.current.forkArguments, (value) => {
this.current.forkArguments = value;
this.save();
});
Preferences.addCheckbox(settingsGroup, 'Show "fork" log in a side view', this.current.forkInSideView, (value) => {
this.current.forkInSideView = value;
this.save();
});
addSep(settingsGroup);
Preferences.addCheckbox(settingsGroup, "Reuse output tab", this.current.reuseTab, (value) => {
this.current.reuseTab = value;
this.save();
});
Preferences.addCheckbox(settingsGroup, "Save all tabs upon compile", this.current.saveCompile, (value) => {
this.current.saveCompile = value;
this.save();
});
Preferences.addCheckbox(settingsGroup, "Stop running instances upon compile", this.current.stopCompile, (value) => {
this.current.stopCompile = value;
this.save();
});
Preferences.addCheckbox(settingsGroup, "Open source file after fatal errors", this.current.displayLine, (value) => {
this.current.displayLine = value;
this.save();
});
Preferences.addCheckbox(settingsGroup, "Clean cache on compile error", this.current.cleanOnError, (value) => {
this.current.cleanOnError = value;
this.save();
});
Preferences.addCheckbox(settingsGroup, "Clean cache after run", this.current.cleanAfterRun, (value) => {
this.current.cleanAfterRun = value;
this.save();
});
Preferences.addText(root, `builder v${Builder.Version} by nommiin`);
}
static ready() {
GMEdit.on("preferencesBuilt", (e) => {
let out = e.target.querySelector('.plugin-settings[for="builder"]');
if (this.element == null) this.build();
out.appendChild(this.element);
});
}
}