forked from SunsetMkt/blue-archive-spine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
376 lines (345 loc) · 16.7 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
<title>Blue Archive Resource Viewer</title>
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<meta name="og:title" content="Blue Archive Spine Viewer" />
<meta property="og:url" content="https://respectz.github.io/blue-archive-spine/" />
<meta name="keywords" content="bluearchive" />
<meta name="description" content="Blue Archive Spine Viewer" />
<!-- Main CSS -->
<link rel="stylesheet" href="css/style.css">
<!-- PIXI -->
<script src="js/pixi.js"></script>
<script src="js/pixi-spine.js"></script>
<!-- UIkit CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/uikit.min.css" />
<!-- UIkit JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit-icons.min.js"></script>
<!-- Main -->
<script src="js/main.js"></script>
<!-- Utility -->
<script src="js/utility.js"></script>
<!-- Howler -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/howler.min.js"></script>
</head>
<body>
<nav class="uk-navbar-container uk-navbar-transparent" uk-navbar style="position: fixed">
<div class="uk-navbar-left">
<ul class="uk-navbar-nav uk-dotnav-vertical">
<li class="uk-active">
<button class="uk-button uk-button-default" type="button" uk-toggle="target: #sidebar-options"><span
uk-icon="cog"></span></button>
</li>
<li class="uk-active">
<button class="uk-button uk-button-default" type="button"
onclick="document.fullscreen?document.exitFullscreen():document.documentElement.requestFullscreen()"><span
uk-icon="expand"></span></button>
</li>
</ul>
</div>
</nav>
<div id="sidebar-options" uk-offcanvas>
<div class="uk-offcanvas-bar">
<button class="uk-offcanvas-close" type="button" uk-close></button>
<h3>Blue Archive Spines</h3>
<p>Select Model</p>
<select class="uk-select" id="optionModels">
</select>
<p>Select Animation</p>
<select class="uk-select" id="optionAnimations">
</select>
<p><label><input class="uk-checkbox" type="checkbox" id="optionLoop"> Loop</label></p>
<p><label><input class="uk-checkbox" type="checkbox" id="optionTalkSound"> Play Talk Sound</label></p>
<!-- Advanced Options -->
<ul uk-accordion>
<li>
<a class="uk-accordion-title" href="#">Advanced Options</a>
<div class="uk-accordion-content">
<div class="uk-grid-small" uk-grid>
<div class="uk-width-1-1">
<button class="uk-button uk-button-default" id="optionScaleFit">Fit Scale</button>
<button class="uk-button uk-button-default" id="optionScaleHalf">1/2 Scale</button>
</div>
<div class="uk-width-1-4 uk-margin">
<p>Size</p>
</div>
<div class="uk-width-3-4">
<input class="uk-input" type="number" step="1" id="optionWidth">
<input class="uk-input" type="number" step="1" id="optionHeight">
</div>
<div class="uk-width-1-4 uk-margin">
<p>Scale</p>
</div>
<div class="uk-width-3-4">
<input class="uk-input" type="number" min="0.01" step="0.01" id="optionScale">
</div>
<div class="uk-width-1-1">
<p><label><input class="uk-checkbox" type="checkbox" id="optionAutoPos" checked> Auto
Centerize</label></p>
</div>
<div class="uk-width-1-1">
<p>You can also move it by dragging.</p>
</div>
<div class="uk-width-1-4 uk-margin">
<p>X</p>
</div>
<div class="uk-width-3-4">
<input class="uk-input" type="number" min="0" step="1" id="optionX" disabled>
</div>
<div class="uk-width-1-4 uk-margin">
<p>Y</p>
</div>
<div class="uk-width-3-4">
<input class="uk-input" type="number" min="0" step="1" id="optionY" disabled>
</div>
</div>
</div>
</li>
</ul>
<!-- Export Animation -->
<ul uk-accordion>
<li>
<a class="uk-accordion-title" href="#">Export Animation</a>
<div class="uk-accordion-content">
<div class="uk-grid-small" uk-grid>
<div class="uk-width-1-4 uk-margin">
<p>FPS</p>
</div>
<div class="uk-width-3-4">
<input class="uk-input" type="number" min="1" step="1" id="optionFPS" value="60">
</div>
<div class="uk-width-1-1">
<p>File Type</p>
</div>
<div class="uk-width-1-1">
<select class="uk-select" id="optionExportType">
<option value="video/mp4">.mp4</option>
<option value="video/webm">.webm</option>
</select>
</div>
<div class="uk-width-1-1">
<button class="uk-button uk-button-default" id="optionExport">Export</button>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
<!-- Main Canvas -->
<div id="canvasWrapper">
<canvas id="screen"></canvas>
</div>
<!-- load it -->
<script>
let option = {
models: document.getElementById("optionModels"),
animations: document.getElementById("optionAnimations"),
loop: document.getElementById("optionLoop"),
talkSound: document.getElementById("optionTalkSound"),
scaleFit: document.getElementById("optionScaleFit"),
scaleHalf: document.getElementById("optionScaleHalf"),
width: document.getElementById("optionWidth"),
height: document.getElementById("optionHeight"),
scale: document.getElementById("optionScale"),
autoPos: document.getElementById("optionAutoPos"),
x: document.getElementById("optionX"),
y: document.getElementById("optionY"),
FPS: document.getElementById("optionFPS"),
export: document.getElementById("optionExport"),
exportType: document.getElementById("optionExportType")
}
async function main() {
// Init models
let dataModels = await fetch("./data/models.json").then(r => r.json())
for (var i in dataModels) {
let opt = document.createElement("option");
opt.value = dataModels[i];
opt.innerHTML = i;
option.models.appendChild(opt);
}
// Events
option.models.onchange = function () {
localStorage.setItem("blue-archive-res-model", this.value);
loadChar(this.value)
}
option.animations.onchange = function () {
playAnimation(this.value);
}
option.loop.onchange = function () {
localStorage.setItem("blue-archive-res-loop", this.checked);
playAnimation(option.animations.value);
}
option.height.onchange = option.width.onchange = function () {
updateCanvas(option.width.value, option.height.value)
}
option.talkSound.onchange = function () {
localStorage.setItem("blue-archive-res-talkSound", this.checked);
}
option.scaleFit.onclick = function () {
if (isCharacterLoaded)
char.scale.x = char.scale.y = option.scale.value = option.models.value.indexOf("_home") != -1 ? Math.max(app.renderer.height / char.spineData.height, app.renderer.width / char.spineData.width) : Math.min(app.renderer.height / char.spineData.height, app.renderer.width / char.spineData.width);
}
option.scaleHalf.onclick = function () {
if (isCharacterLoaded)
char.scale.x = char.scale.y = option.scale.value = 0.5;
}
option.scale.onchange = function () {
if (isCharacterLoaded)
char.scale.x = char.scale.y = option.scale.value;
}
option.autoPos.onchange = function () {
if (!isCharacterLoaded)
return;
if (this.checked) {
option.x.disabled = option.y.disabled = true;
option.x.value = char.x = window.innerWidth / 2;
option.y.value = char.y = window.innerHeight / 1;
} else {
option.x.disabled = option.y.disabled = false;
}
}
option.x.onchange = function (e) {
if (isCharacterLoaded)
char.x = this.value;
}
option.y.onchange = function () {
if (isCharacterLoaded)
char.y = this.value;
}
option.export.onclick = function () {
exportAnimation(FPS = parseInt(option.FPS.value))
}
// On window resize
window.onresize = function () {
width = window.innerWidth;
height = window.innerHeight;
//localStorage.setItem("blue-archive-res-width", width)
//localStorage.setItem("blue-archive-res-height", height)
option.width.value = canvasScreen.width = width;
option.height.value = canvasScreen.height = height;
if (option.autoPos) {
option.x.value = char.x = window.innerWidth / 2;
option.y.value = char.y = window.innerHeight / 1;
}
}
// Draggable Canvas
let canvasScreen = document.getElementById("screen")
let isDragging = false;
let nowMouseX, nowMouseY;
let lastMouseX, lastMouseY;
let canvasX, canvasY;
function updatePos() {
if (isDragging)
window.requestAnimationFrame(updatePos)
if (!isCharacterLoaded)
return;
if (!nowMouseX || !nowMouseY)
return;
if ((nowMouseX == lastMouseX) && (nowMouseY == lastMouseY))
return;
// console.log(nowMouseX, lastMouseX, nowMouseY, lastMouseY)
char.x = canvasX += parseInt(nowMouseX - lastMouseX)
char.y = canvasY += parseInt(nowMouseY - lastMouseY)
lastMouseX = nowMouseX
lastMouseY = nowMouseY
}
function handleMove(e) {
nowMouseX = e.clientX
nowMouseY = e.clientY
}
function handleTouch(e) {
handleMove(e.touches[0])
}
function handleMoveStart(e, type = "mousemove", func = handleMove) {
// console.log("start", e)
isDragging = true;
canvasX = char.x;
canvasY = char.y;
nowMouseX = lastMouseX = e.clientX
nowMouseY = lastMouseY = e.clientY
window.requestAnimationFrame(updatePos)
canvasScreen.addEventListener(type, func, { passive: true })
}
canvasScreen.onmousedown = handleMoveStart
canvasScreen.ontouchstart = function (e) {
handleMoveStart(e.touches[0], "touchmove", handleTouch)
}
function handleMoveEnd(e, type = "mousemove", func = handleMove) {
// console.log("end", e)
isDragging = false;
canvasScreen.removeEventListener(type, func)
option.x.value = canvasX
option.y.value = canvasY
}
canvasScreen.onmouseup = canvasScreen.onmouseout = handleMoveEnd
canvasScreen.ontouchend = function (e) {
handleMoveEnd(e.touches[0], "touchmove", handleTouch)
}
canvasScreen.onwheel = function (e) {
char.scale.x = char.scale.y = option.scale.value = (option.scale.value - e.deltaY / 10000)
}
//Load localStorage if exists
if (localStorage["blue-archive-res-model"]) {
option.models.value = localStorage["blue-archive-res-model"]
} else {
option.models.value = option.models.children[0].value;
}
if (localStorage["blue-archive-res-loop"])
option.loop.checked = localStorage["blue-archive-res-loop"]
if (localStorage["blue-archive-res-talkSound"])
option.talkSound.checked = localStorage["blue-archive-res-talkSound"]
// Start
async function updateCanvas(width, height) {
width = width ? width : window.innerWidth;
height = height ? height : window.innerHeight;
//localStorage.setItem("blue-archive-res-width", width)
//localStorage.setItem("blue-archive-res-height", height)
option.width.value = canvasScreen.width = width;
option.height.value = canvasScreen.height = height;
if (option.autoPos.checked && isCharacterLoaded) {
char.x = option.x.value = width / 2;
char.y = option.y.value = height / 1;
}
if (!app) {
audios = await fetch("./data/audio.json").then(r => r.json())
app = new PIXI.Application(
{
width: width,
height: height,
view: document.getElementById("screen")
}
);
}
}
await updateCanvas(localStorage.getItem("blue-archive-res-width"), localStorage.getItem("blue-archive-res-height"))
loadChar(option.models.value);
}
main()
</script>
<!-- Exporter -->
<script src="js/canvas-exporter.js"></script>
<!-- Modal Exporter -->
<div id="modal-exporter" class="uk-flex-top" uk-modal='{"bg-close": false, "esc-close": false}'>
<div class="uk-modal-dialog uk-modal-body uk-margin-auto-vertical" id="modal-exporter-content">
<div id="rendering">
<p>Rendering...</p>
<progress id="export-progress" class="uk-progress" value="0" max="100"></progress>
</div>
<div id="complete">
<p>Done !</p>
<div id="result">
</div>
<p class="uk-text-right">
<button class="uk-button uk-button-primary uk-modal-close" type="button">Close</button>
</p>
</div>
</div>
</div>
</body>
</html>