-
Notifications
You must be signed in to change notification settings - Fork 0
/
raw-directories.js
57 lines (56 loc) · 1.84 KB
/
raw-directories.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
(function() {
let TreeView = $gmedit["ui.treeview.TreeView"];
let RawLoader = $gmedit["raw.RawLoader"];
let Preferences = $gmedit["ui.Preferences"];
let ProjectProperties = $gmedit["ui.project.ProjectProperties"];
let FileSystem = Electron_FS;
function onOpen(e) {
let pj = e.project;
switch (pj.version.config.loadingMode) {
case "gms1": case "gms2": break;
default: return;
}
if (pj.path == null) return;
let arr = pj.properties.rawDirectories || ["."];
for (let path of arr) (function addRawDirectory(path) {
if (path != "." && !pj.existsSync(path)) {
console.error(`Can't add ${path} - it does not exist`);
return;
}
let fullPath = pj.fullPath(path);
let name = path != "." ? path : "Raw view";
if (!FileSystem.statSync(fullPath).isDirectory()) {
let item = TreeView.makeAssetItem(path, path, fullPath, "file");
TreeView.element.appendChild(item);
return;
}
let dir = TreeView.makeAssetDir(name, path, "file");
let isReady = false;
dir.treeHeader.addEventListener("click", function ensureRawDirectory(_) {
if (isReady || !dir.classList.contains("open")) return;
RawLoader.loadDirRec(pj, dir.treeItems, path);
isReady = true;
});
TreeView.element.appendChild(dir);
})(path);
}
GMEdit.register("raw-directories", {
init: function() {
GMEdit.on("projectOpen", onOpen);
GMEdit.on("projectPropertiesBuilt", function addPropertiesUI(e) {
let pj = e.project;
let out = e.target;
let gr = Preferences.addGroup(out, "Raw directories");
let arr = pj.properties.rawDirectories || ["."];
let el = Preferences.addInput(gr,
"Directory list (separated with `|`)",
arr.join("|"),
function updateDirList(s) {
pj.properties.rawDirectories = s ? s.split("|") : [];
ProjectProperties.save(pj, pj.properties);
pj.reload();
});
});
}
});
})();