-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
538 lines (493 loc) · 15.6 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
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<!DOCTYPE HTML>
<html>
<head>
<!--meta name="theme-color" content=""-->
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<meta name="viewport"
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<title>ShadowSkin</title>
</head>
<noscript>
<mark style="font-size:60px;color:red;">请使用带JavaScript的浏览器!</mark>
</noscript>
<body onload="load_()//}catch(err){alert(err)}">
<!--script src="debugger.js"></script-->
<script src="hframe.js" defer></script>
<script src="mobs.js"></script>
<script src="pic.js"></script>
<script src="effect.js"></script>
<style>
html,
body {
height: 100%;
margin: 0;
/*background:aliceblue;*/
}
canvas,
img {
image-rendering: pixelated;
image-rendering: crisp-edges;
}
#GUI {
display: flex;
flex-flow: column nowrap;
height: 100%;
width: 100%;
overflow: hidden;
}
#headbar {
flex: 8 0px;
text-align: center;
background: greenyellow;
box-shadow: 0px 2px 20px -3px silver;
border-bottom: 2px solid silver;
background: yellowgreen;
text-align: center;
font-size: 2em;
font-weight: bold;
color: white;
text-shadow: 0px 0px 10px grey;
line-height: 8vh;
}
jsjsks {
border: 3px solid black;
}
#toolbar {
flex: 4 0px;
width: 100%;
display: flex;
text-align: center;
padding: 0.5em;
}
#toolbar>a {
/*border-right:0.3em solid yellowgreen;*/
flex: 1 1 0;
color: yellowgreen;
}
#ctnr {
flex: 100 0px;
overflow-y: scroll;
padding: 2vh 2vw;
display: flex;
flex-flow: row wrap;
justify-content: center;
align-content: flex-start;
}
#ctnr::after {
content: '';
flex: auto;
}
s-skin {
border-radius: 15px 15px;
box-shadow: 0px 5px 50px -10px silver;
background: white;
display: inline-flex;
flex-direction: column;
justify-content: stretch;
height: 30%;
overflow: hidden;
margin: 1.5% 1.5%;
flex: 0 0 30%;
}
s-skin img {
margin: auto;
image-rendering: pixelated;
display: block;
height: 150%;
box-sizing: border-box;
}
[dd=head] {
width: 100%;
overflow: hidden;
white-space: nowrap;
flex: 3 0px;
}
[dd=name] {
line-height: 2em;
flex: 1 0px;
font-size: 1.3em;
background: yellowgreen;
width: 100%;
text-align: center;
color: white;
font-weight: bold;
text-overflow: ellipsis;
}
h-frame {
background: white;
}
/*加载页面*/
#loading {
width: 100%;
height: 100%;
z-index: 2;
background-color: white;
position: fixed;
animation-duration: .4s;
}
#loading>* {
position: absolute;
font-size: larger;
font-weight: lighter;
color: dimgray;
}
#loading>:first-child {
left: 10%;
top: 35%;
}
#loading>:nth-child(2) {
right: 10%;
top: 45%;
}
#loading>:last-child {
width: 100%;
top: 80%;
display: inline-block;
text-align: center;
color: black;
font-weight: normal;
}
@keyframes loading_hide {
to {
opacity: 0;
transform: scale(2, 2);
}
}
#version {
position: absolute;
bottom: 5px;
right: 5px;
color: yellowgreen;
}
#version::before {
content: 'v';
}
</style>
<script>
//测试可用
window.addEventListener("load", () => {
try {
let m = [
customElements,
HFrame,
window.postMessage,
localStorage
]
for (let i of m) {
if (!i) {
alert("浏览器兼容性不足,无法正常使用,请换浏览器!");
break;
}
}
} catch (err) {
alert("浏览器兼容性不足,无法正常使用,请换浏览器!"
+ "错误信息\n" + err);
}
})
</script>
<script>
let ALARMED;
let SKINS = [];
let ALARM_WHEN_QUIT = false;
window.onbeforeunload = (e) => {
if (!ALARM_WHEN_QUIT) {
return;
}
return "确实要退出吗?你的工作不会被自动保存"
}
class Skin extends HTMLElement {
constructor(obj, temporary) {
super();
if (!temporary) {
SKINS.push(this);
}
/*this._obj=obj;
this._model=obj.model;
this._texture_=obj.texture;
this._name=obj.name;*/
this.innerHTML = `
<div dd="head">
<img dd="headimg">
</div>
<div dd="name"></div>`
let id;
function rnd() {
return String(Math.random()).slice(8);
}
this.editor = {
modes: {},
pen: {}
}
this.setSkin(obj);
this.addEventListener("click", () => {
view(this);
});
}
loadPicture() {
let cvs = document.createElement("canvas");
let ctx = cvs.getContext("2d");
let img = new Image();
img.src = this.texture;
img.onload = () => {
cvs.width = 16;
cvs.height = 32;
let mo = mobs[this.model];
for (let i in mo) {
let {
size,
uv: [u0, u1],
origin: [o1, o2],
inflate: inf
} = mo[i];
let [x, y, z] = size;
o2 += size[1];
let p = [z + u0, z + u1, x, y];
ctx.drawImage(
img, p[0], p[1],
p[2], p[3], 8 + o1,
35 - o2, p[2], p[3]
);
};
this.querySelector("[dd=headimg]").src = cvs.toDataURL();
}
}
set name(v) {
this.info.name = this._name = v;
this.querySelector("[dd=name]").innerText = this.name;
}
get name() {
return this._name;
}
set texture(v) {
this.info.texture = this._texture = v;
this.loadPicture();
}
get texture() {
return this._texture;
}
set model(v) {
this.info.model = this._model = v;
this.loadPicture();
}
get model() {
return this._model;
}
getInfo() {
return this.info;
}
setSkin(o) {
this.info = o;
this.name = o.name;
this.texture = o.texture;
this.model = o.model;
}
}
try {
customElements.define("s-skin", Skin);
//customElements.whenDefined("s-skin").then(load_);
} catch (err) { alert(err) }
function ide(n) {
return document.getElementById(n);
}
//处理本地数据
function handleData(fn, alarm) {
if (localStorage) {
let q = localStorage.getItem("powerskin");
try {
q = JSON.parse(q);
} catch (e) {
q = [];
}
q = fn(q) || q;
localStorage.setItem("powerskin", JSON.stringify(q));
return true;
}
if (alarm || !ALARMED) {
alert("您的浏览器不支持localStorage,强烈建议" +
"升级浏览器,否则您的一切工作在刷新后将丢失!");
ALARMED = true;
}
return false;
}
function saveData() {
handleData(() => {
return SKINS.map(e => {
let a = e.getInfo();
return a;
});
})
}
function view(e) {
let vw = ide("viewer");
vw.fullScreen = true;
ALARM_WHEN_QUIT = true;
let obj = e.info;
vw.send(obj);
//保存皮肤
function recv(d) {
d = d.detail;
switch (d.event) {
case "close":
if (d.save) {
save(d.save);
}
close();
break;
case "save":
save(d.save);
break;
case "copy":
let info = Object.assign({}, e.getInfo());
info.name = d.name;
setSkin(info, true);
break;
case "delete":
SKINS.forEach((el, i) => {
if (e == el) {
SKINS.splice(i, 1);
ide("ctnr").removeChild(e);
saveData();
close();
}
})
break;
}
function save(obj) {
e.setSkin(d.save);
SKINS.forEach((ele, i) => {
if (ele == e) {
SKINS.splice(i, 1);
SKINS.unshift(e);
}
});
let ctnr = ide("ctnr");
ctnr.insertBefore(e, ctnr.firstChild);
saveData();
}
function close() {
//某些浏览器在弹出对话框后太快关闭会有bug
setTimeout(function () {
viewer.fullScreen = false;
vw.removeEventListener("msg", recv);
ALARM_WHEN_QUIT = false;
}, 100);
}
}
vw.addEventListener("msg", recv);
}
function load_() {
/*for(let i=0;i<15;i++){
let name=(Math.random()*(10**15)).toString(36).slice(0,8);
setSkin({name:name});
}*/
{
let loading = document.getElementById("loading");
Effect(loading);
loading.hide();
}
try {
if (b64sk.raw.creeper) setSkin({
name: "creeper",
texture: b64sk.raw.creeper,
model: "alex"
});
setSkin({
name: "alex",
texture: b64sk.raw.alex,
model: "alex"
});
setSkin({
name: "steve",
texture: b64sk.raw.steve,
model: "steve"
});
handleData((m) => {
for (let i in m) {
let n = setSkin(m[i]);
SKINS.push(n)
}
});
} catch (err) { alert(err.stack) }
}
function importSkin() {
let fi = ide("loadSkin");
fi.click();
fi.onchange = () => {
let fr = new FileReader();
let isproj = fi.value.split(".").pop() == "json";
if (isproj) {
fr.onload = () => {
let obj = JSON.parse(fr.result);
let n = setSkin(obj);
SKINS.push(n);
saveData();
}
fr.readAsText(fi.files[0])
} else {
fr.onload = () => {
let name = (function () {
let n = fi.value;
n = n.split("\\").pop();
let y = n.split(".");
if (y.length >= 2) n = y[y.length - 2];
return n.slice(-10);
})();
setSkin({
name: name,
texture: fr.result,
model: "steve"
}, true);
fi.value = null;
}
fr.readAsDataURL(fi.files[0]);
fr.onerror = (ev) => {
alert("哎唷,读取失败啦!\n" + ev)
}
}
}
}
function createSkin() {
let n = prompt("请输入新皮肤名字", "New skin");
if (!n) return;
setSkin({
name: n,
model: "steve",
texture: b64sk.raw.dummy
}, true)
}
function setSkin(obj, save) {
let n = new Skin(obj, !save);
let ctnr = ide("ctnr");
if (save) {
ctnr.insertBefore(n, ctnr.firstElementChild);
} else {
ctnr.appendChild(n);
}
if (save) {
saveData();
}
return n;
}
</script>
<div id="loading">
<span>耐心和持久胜过激烈和狂热</span>
<span>---拉·封丹(法)</span>
<span>加载中,请稍后...</span>
</div>
<div id="version">2.1.0</div>
<h-frame id="viewer" style="display:none;background:white;" src="viewer2.html"></h-frame>
<div id="GUI">
<div id="headbar">ShadowSkin</div>
<div id="toolbar">
<a onclick="importSkin()">导入</a>
<a href="tutorial.html" target="_blank" style="text-shadow:0 0 2px #fafac3;">使用手册</a>
<a target="_blank" href="https://github.com/Fancyflame/ShadowSkin">github</a>
<a onclick="createSkin()">新建</a>
</div>
<div id="ctnr"></div>
</div>
<div style="display:none">
<input type="file" id="loadSkin">
</div>
</body>
</html>