-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder23.js
66 lines (66 loc) · 1.63 KB
/
order23.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
(function() {
function run(custom) {
let project = $gmedit["gml.Project"].current;
if (!project.isGMS23) throw "Has to be a GMS2.3+ project!";
let yyp = project.readYyFileSync(project.name);
//
let order = {};
let index = 0;
let list = [];
//
if (custom != "") for (let mt of custom.matchAll(/\w+/g)) {
let name = mt[0];
if (order[name] == null) {
list.push(name);
order[name] = index++;
}
}
console.log("custom", list.slice());
//
let treeview = document.querySelector("#tree-td .treeview");
for (let el of treeview.querySelectorAll("div[data-ident]")) {
let name = el.dataset["ident"];
if (name && order[name] == null) {
list.push(name);
order[name] = index++;
//console.log(index, name);
}
}
//
console.log("list", list);
console.log("map", order);
//
let resources = yyp.resources;
resources.sort((a, b) => {
return (order[a.id.name] || 0) - (order[b.id.name] || 0);
});
//console.log(resources.map((r) => r.id.name));
project.writeYyFileSync(project.name, yyp);
}
function init() {
$gmedit["ui.CommandPalette"].add({
name: "Match 2.3 resource indexes to tree order",
exec: function() {
let custom = aceEditor.getSelectedText().trim();
if (custom != "") {
if (!$gmedit["electron.Dialog"].showConfirm(
"Use selection as list of front-first names?"
)) custom = "";
}
try {
run(custom);
$gmedit["electron.Dialog"].showAlert("Done!");
} catch (e) {
$gmedit["electron.Dialog"].showError("Error! " + e);
}
}
});
}
//
GMEdit.register("order23", {
init: init,
cleanup: function() {
hide();
},
});
})();