forked from alto-io/xgr-arcadians
-
Notifications
You must be signed in to change notification settings - Fork 1
/
uiPartsPicker.jsx
94 lines (73 loc) · 2.43 KB
/
uiPartsPicker.jsx
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
window.onload = function () {
initUI();
};
async function initUI() {
await waitForLoading();
initParts("Male");
}
function showPartsList(id, matName) {
if (g_config == null) return;
var div = document.getElementById("list-pick");
if (div == null) return;
div.innerHTML = "";
var files = [];
var avatar = g_fileList.find((x) => x.Gender == id);
if (avatar == null) return;
for (var i of avatar.Parts) {
if (i.Name == matName) {
files = i.Files;
}
}
var header = document.createElement("H2");
var text = document.createTextNode(matName);
header.appendChild(text);
div.appendChild(header);
for (var i of files) {
var group = document.createElement("div");
group.id = "button-group";
var text = document.createElement("p");
text.innerText = i.Name;
var button = document.createElement("button");
button.innerText = i.Name;
button.innerHTML = `<button class="img-size"><img src='${i.Path}' /></button>`;
button.setAttribute("onClick", `replaceParts('${matName}', '${i.Path}')`);
// Add button to group
group.appendChild(button);
// Add text to group;
group.appendChild(text);
// Add group to grid div
div.appendChild(group);
}
}
export function changeGender(id) {
loadAvatar(id);
initParts(id);
}
function initParts(id) {
if (g_config == null) return;
if (g_config.list <= 0) return;
var avatar = g_config.list.find((x) => x.id == id);
if (avatar == null) return;
// Load Gender buttons
var genderDiv = document.getElementById("gender-pick");
if (genderDiv == null) return;
genderDiv.innerHTML = "";
for (var g of g_config.list) {
var button = document.createElement("button");
button.innerHTML = g.id;
button.setAttribute("onClick", `changeGender('${g.id}')`);
genderDiv.appendChild(button);
}
// Load Parts buttons
var partsDiv = document.getElementById("parts-pick");
if (partsDiv == null) return;
partsDiv.innerHTML = "";
for (var m of avatar.materials) {
var button = document.createElement("button");
button.innerText = m.name;
button.setAttribute("onClick", `showPartsList('${id}', '${m.name}')`);
partsDiv.appendChild(button);
}
// Default to the first material
showPartsList(id, avatar.materials[0].name);
}