-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
nmsr-debug-ui.html
459 lines (373 loc) · 16.6 KB
/
nmsr-debug-ui.html
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NMSR - Test GUI</title>
<style>
body {
box-sizing: border-box;
font-family: system-ui, sans-serif;
margin: 0;
padding: 1.5rem;
display: flex;
width: 100vw;
height: 100vh;
background-color: canvas;
color: canvastext;
color-scheme: light dark;
overflow: hidden;
gap: 1rem;
}
label,
p {
margin: 0;
}
#controls,
#image-preview {
flex: 1;
display: flex;
gap: 0.621rem;
justify-content: center;
}
#controls {
flex-direction: column;
}
#image-preview {
align-items: center;
justify-content: center;
}
input,
select,
button {
padding: 0.5rem;
margin-block-end: 0.5rem;
}
.group {
display: flex;
align-items: baseline;
gap: 0.2rem;
flex-wrap: wrap;
flex-direction: column;
}
.inner-group {
display: flex;
flex-direction: column;
flex: 1;
height: 100%;
}
.outer-group {
display: flex;
flex-direction: row;
justify-content: space-evenly;
align-items: center;
gap: 1rem;
}
h1 {
font-size: 3.5rem;
align-self: center;
}
</style>
</head>
<body>
<div id="image-preview">
<img src="#" alt="Image Preview" id="preview-image">
<p id="image-error"></p>
</div>
<div id="controls">
<h1>NMSR - Test GUI</h1>
<div class="outer-group" id="texture-group">
<div class="inner-group">
<label for="texture-group">Texture:</label>
<input type="text" id="texture" value="ad4569f3-7576-4376-a7c7-8e8cfcd9b832">
</div>
<div class="inner-group">
<div>
<label for="texture-file-group">Skin Upload:</label>
<input type="file" id="skin-upload">
</div>
<div>
<label for="texture-file-group">Cape Upload:</label>
<input type="file" id="cape-upload">
</div>
</div>
</div>
<div class="outer-group">
<div class="inner-group" id="general-controls-group">
<label for="general-controls-group">General:</label>
<label for="mode">Mode:</label>
<select id="mode">
<option value="full_body">FullBody</option>
<option value="body_bust">BodyBust</option>
<option value="front_full">FrontFull</option>
<option value="front_bust">FrontBust</option>
<option value="face">Face</option>
<option value="head">Head</option>
<option value="full_body_iso">FullBodyIso</option>
<option value="head_iso">HeadIso</option>
<option value="skin">Skin</option>
<option value="cape">Cape</option>
<option value="custom">Custom</option>
</select>
<label for="model">Model:</label>
<select id="model" name="model">
<option value="">(Default)</option>
<option value="wide">Wide</option>
<option value="slim">Slim</option>
</select>
</div>
<div class="inner-group" id="misc-controls-group">
<label for="misc-controls-group">Misc:</label>
<label for="arms">Arm Rotation:</label>
<input type="number" id="arms" name="arms" min="0" max="180" step="1">
<label for="distance">Camera Distance:</label>
<input type="number" id="distance" name="distance" step="1">
</div>
<div class="inner-group" id="features-group">
<label for="features-group">Features:</label>
<label><input class="feature" type="checkbox" checked value="layers">Layers</label>
<label><input class="feature" type="checkbox" checked value="helmet">Helmet</label>
<label><input class="feature" type="checkbox" checked value="shadow">Shadow</label>
<label><input class="feature" type="checkbox" checked value="shading">Shading</label>
<label><input class="feature" type="checkbox" checked value="cape">Cape</label>
<label><input class="feature" type="checkbox" value="ears">Ears</label>
<label><input id="back-chk" type="checkbox" value="Back">Back</label>
<label><input id="deadmau5ears" type="checkbox" value="deadmau5ears">Deadmau5 Ears</label>
<label><input id="upsidedown" type="checkbox" value="upsidedown">Upside Down</label>
</div>
</div>
<div class="outer-group" id="camera-group">
<div class="inner-group" id="camera-size-group">
<label for="camera-size-group">Size:</label>
<label for="width">Width:</label>
<input type="number" id="width" name="w">
<label for="height">Height:</label>
<input type="number" id="height" name="h">
</div>
<div class="inner-group" id="camera-rotation-group">
<label for="camera-rotation-group">Rotation:</label>
<label for="yaw">Yaw:</label>
<input type="number" id="yaw" name="y" step="1">
<label for="pitch">Pitch:</label>
<input type="number" id="pitch" name="p" step="1">
<label for="roll">Roll:</label>
<input type="number" id="roll" name="r" step="1">
</div>
<div class="inner-group" id="camera-position-group">
<label for="camera-position-group">Position:</label>
<label for="xpos">X Position:</label>
<input type="number" id="xpos" name="xpos" step="1" min="-50" max="50">
<label for="ypos">Y Position:</label>
<input type="number" id="ypos" name="ypos" step="1" min="-50" max="50">
<label for="zpos">Z Position:</label>
<input type="number" id="zpos" name="zpos" step="1" min="-50" max="50">
</div>
</div>
<div class="outer-group" id="armor-group">
<label for="armor-group">Armor:</label>
<div class="inner-group">
<label for="helmet">Helmet:</label>
<select name="helmet" id="helmet">
<option value="">(None)</option>
<option value="le">Leather Helmet</option>
<option value="ch">Chainmail Helmet</option>
<option value="ir">Iron Helmet</option>
<option value="di">Diamond Helmet</option>
<option value="go">Golden Helmet</option>
<option value="tu">Turtle Helmet</option>
<option value="ne">Netherite Helmet</option>
</select>
</div>
<div class="inner-group">
<label for="chestplate">Chestplate:</label>
<select name="chestplate" id="chestplate">
<option value="">(None)</option>
<option value="le">Leather Chestplate</option>
<option value="ch">Chainmail Chestplate</option>
<option value="ir">Iron Chestplate</option>
<option value="di">Diamond Chestplate</option>
<option value="go">Golden Chestplate</option>
<option value="tu">Turtle Chestplate</option>
<option value="ne">Netherite Chestplate</option>
</select>
</div>
<div class="inner-group">
<label for="leggings">Leggings:</label>
<select name="leggings" id="leggings">
<option value="">(None)</option>
<option value="le">Leather Leggings</option>
<option value="ch">Chainmail Leggings</option>
<option value="ir">Iron Leggings</option>
<option value="di">Diamond Leggings</option>
<option value="go">Golden Leggings</option>
<option value="tu">Turtle Leggings</option>
<option value="ne">Netherite Leggings</option>
</select>
</div>
<div class="inner-group">
<label for="boots">Boots:</label>
<select name="boots" id="boots">
<option value="">(None)</option>
<option value="le">Leather Boots</option>
<option value="ch">Chainmail Boots</option>
<option value="ir">Iron Boots</option>
<option value="di">Diamond Boots</option>
<option value="go">Golden Boots</option>
<option value="tu">Turtle Boots</option>
<option value="ne">Netherite Boots</option>
</select>
</div>
</div>
<button id="apply-button">Apply</button>
</div>
<script type="module">
let modeSelect = document.getElementById('mode');
let textureInput = document.getElementById('texture');
let featuresGroup = document.getElementById('features-group');
let applyButton = document.getElementById('apply-button');
let imagePreview = document.getElementById('preview-image');
let imageError = document.getElementById('image-error');
let skinUpload = document.getElementById('skin-upload');
let capeUpload = document.getElementById('cape-upload');
let resolvedNames = {};
let uploadedSkin = null;
let uploadedCape = null;
skinUpload.addEventListener('change', () => {
let file = skinUpload.files[0];
if (!file) return;
let reader = new FileReader();
reader.onload = async () => {
uploadedSkin = new Blob([/** @type {ArrayBuffer} */(reader.result)]);;
textureInput.value = '';
await updateImage();
};
reader.readAsArrayBuffer(file);
});
capeUpload.addEventListener('change', () => {
let file = capeUpload.files[0];
if (!file) return;
let reader = new FileReader();
reader.onload = async () => {
uploadedCape = new Blob([/** @type {ArrayBuffer} */(reader.result)]);;
textureInput.value = '';
await updateImage();
};
reader.readAsArrayBuffer(file);
});
if (window.location.search) {
let params = new URLSearchParams(window.location.search);
for (let [key, value] of params) {
let input = document.querySelector(`[name="${key}"]`) || (key == 'texture' ? textureInput : (key == 'mode' ? modeSelect : null));
if (input) {
input.value = value;
}
}
}
let validMinecraftName = /^[a-zA-Z0-9_]{2,16}$/;
applyButton.addEventListener('click', updateImage);
updateImage();
let debouncedUpdateImage = debounce(updateImage, 300);
document.querySelectorAll('input:not([type="checkbox"])').forEach(input => input.addEventListener('input', debouncedUpdateImage));
document.querySelectorAll('input[type="checkbox"]').forEach(input => input.addEventListener('input', updateImage));
document.querySelectorAll('select').forEach(input => input.addEventListener('input', updateImage));
window.addEventListener('paste', e => {
skinUpload.files = e.clipboardData.files;
skinUpload.dispatchEvent(new Event('change'));
});
async function updateImage() {
recursiveSetEnabled(document.getElementById('camera-position-group'), modeSelect.value == 'custom');
// Find all inputs
let inputs = document.querySelectorAll('input, select');
// Create an object to store the values
let values = {};
values.t = /* Current time in milliseconds */ new Date().getTime();
// Iterate over all inputs
for (let input of inputs) {
// Add the value to the object if it's not empty and not disabled
if (input.name && input.value && !input.disabled) {
values[input.name] = input.value;
}
}
let params = new URLSearchParams(values);
// Add the features
let excluded = [];
for (let feature of featuresGroup.querySelectorAll('input.feature')) {
if (!feature.checked) {
excluded.push(feature.value);
}
}
if (excluded.length > 0) params.append('no', excluded.join(','));
if (document.getElementById('back-chk').checked) {
params.append('back', '');
}
if (document.getElementById('deadmau5ears').checked) {
params.append('deadmau5ears', '');
}
if (document.getElementById('upsidedown').checked) {
params.append('upside_down', '');
}
const url = `https://nickac-pc.werewolf-scala.ts.net/temp/nmsr`;
if (uploadedSkin && !textureInput.value) {
// Use POST if a skin was uploaded
const formData = new FormData();
for (let name of params.keys()) {
formData.append(name, params.get(name));
}
formData.append('skin', uploadedSkin);
if (uploadedCape) formData.append('cape', uploadedCape);
// Request image and set it as the preview, or show an error
try {
const response = await fetch(`${url}/${modeSelect.value}`, {
method: 'POST',
body: formData
});
if (!response.ok) {
throw new Error(await response.text());
}
const imageBlob = await response.blob();
imagePreview.style.display = 'block';
imageError.style.display = 'none';
imagePreview.src = URL.createObjectURL(imageBlob);
} catch (error) {
console.error('Error loading image:', error);
imagePreview.style.display = 'none';
imageError.style.display = 'block';
imageError.textContent = error;
}
} else {
let resolvedTexture = await tryResolveName(textureInput.value);
let imageUrl = `${url}/${modeSelect.value}/${resolvedTexture}?${params.toString()}`;
imagePreview.src = imageUrl;
imagePreview.style.display = 'block';
imageError.style.display = 'none';
}
}
function recursiveSetEnabled(root, enabled) {
for (let child of root.children) {
if (child.children.length > 0) {
recursiveSetEnabled(child, enabled);
} else {
// Disable this input
child.disabled = !enabled;
}
}
}
async function tryResolveName(name) {
if (resolvedNames && resolvedNames[name]) return resolvedNames[name];
if (!validMinecraftName.test(name)) return name;
let response = await fetch(`https://corsjangapi.b-cdn.net/users/profiles/minecraft/${name}`);
if (!response.ok) return name;
let data = await response.json();
resolvedNames[name] = data.id;
return data.id;
}
function debounce(func, timeout = 300) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => { func.apply(this, args); }, timeout);
};
}
</script>
</body>
</html>