-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
169 lines (164 loc) · 5.18 KB
/
app.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
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
function getFormat(type)
{
if (type == null || type == "") type = "application/unknown";
let result = {}
result.mimeType = type;
type = type.split("/")[0];
switch(type) {
case "image":
result.type = "i";
break;
case "text":
result.type = "t";
break;
case "audio":
result.type = "a";
break;
default:
result.type = "b"; //binary
}
return result;
}
function openView() {
document.getElementById("settings").style.left = 0;
}
function closeView() {
document.getElementById("settings").style.left = "-400px";
}
function skinList()
{
let same;
let skin = document.getElementById("skin").value;
let select = document.getElementById("skin");
select.innerHTML = '';
let el = document.createElement("option");
for (const [key, value] of Object.entries(DALFC.skin.skins)) {
let el = document.createElement("option");
el.textContent = value;
el.value = value;
if (value == skin) same = true
select.appendChild(el);
}
if (same) document.getElementById("skin").value = skin;
}
function animationList()
{
let same;
let anim = document.getElementById("animation").value;
let select = document.getElementById("animation");
select.innerHTML = '';
let el = document.createElement("option");
for (const [key, value] of Object.entries(DALFC.animation.animations)) {
let el = document.createElement("option");
el.textContent = value;
el.value = value;
if (value == anim) same = true
select.appendChild(el);
}
if (same) document.getElementById("animation").value = anim;
}
function screenshot()
{
let cv = document.getElementsByTagName("canvas")[0];
let imgSave = window.open();
imgSave.document.body.style.backgroundColor = "#7F7F7F";
imgSave.document.body.style.margin = "0px";
imgSave.document.body.innerHTML = '<img src="' + cv.toDataURL("png") + '">';
}
function setPosition()
{
let px = parseInt(document.querySelector('input[name="positionX"]').value,10);
let py = parseInt(document.querySelector('input[name="positionY"]').value,10);
DALFC.skeleton.setPosition(px, py);
}
function setZoomDelta()
{
DALFC.user.setZoomDelta(parseFloat(document.querySelector('input[name="zoomDelta"]').value,10));
}
function setZoom()
{
DALFC.user.setZoom(parseFloat(document.querySelector('input[name="zoom"]').value / 10,10));
}
function setScale()
{
DALFC.skeleton.setScale(parseFloat(document.querySelector('input[name="scale"]').value,10));
}
function setMix()
{
DALFC.state.setDefaultMix(parseFloat(document.querySelector('input[name="mix"]').value / 10,10));
document.getElementById("MixValue").innerHTML = document.querySelector('input[name="mix"]').value / 10;
}
function resetMix()
{
DALFC.state.setDefaultMix(0);
document.querySelector('input[name="mix"]').value = 0;
document.getElementById("MixValue").innerHTML = "0.0";
}
function setSpeed()
{
DALFC.animation.setSpeed(parseFloat(document.querySelector('input[name="speed"]').value / 10,10));
document.getElementById("SpeedValue").innerHTML = document.querySelector('input[name="speed"]').value /10;
}
function resetSpeed()
{
DALFC.animation.setSpeed(1);
document.querySelector('input[name="speed"]').value = 10;
document.getElementById("SpeedValue").innerHTML = "1.0";
}
function setSkin()
{
DALFC.skin.setSkin(document.getElementById("skin").value);
//console.log(document.getElementById("skin").value);
}
function setAnimation()
{
DALFC.skeleton.setToSetupPose();
DALFC.animation.setAnimation(document.getElementById("animation").value);
//console.log(document.getElementById("animation").value);
}
function resetSkel()
{
DALFC.user.resetSkel();
updatePosition(DALFC.skeleton.getPositionX(), DALFC.skeleton.getPositionY());
document.querySelectorAll('input[name=bones]')[0].checked = false;
document.querySelectorAll('input[name=regions]')[0].checked = false;
document.querySelectorAll('input[name=bounds]')[0].checked = false;
document.querySelectorAll('input[name=meshhull]')[0].checked = false;
document.querySelectorAll('input[name=meshtriangles]')[0].checked = false;
document.querySelectorAll('input[name=PMA]')[0].checked = false;
document.querySelectorAll('input[name=flipX]')[0].checked = false;
document.querySelectorAll('input[name=flipY]')[0].checked = false;
document.querySelectorAll('input[name=pause]')[0].checked = false;
document.querySelectorAll('input[name=loop]')[0].checked = true;
document.querySelector('input[name="scale"]').value = 1;
resetMix();
resetSpeed();
}
function resetUser()
{
DALFC.user.setZoom(1);
DALFC.user.backgroundColor(0,0,0,0);
document.querySelector('input[name="zoom"]').value = 10;
document.querySelector('input[name="zoomDelta"]').value = 0.25;
}
const pickr = Pickr.create({
el: '.color',
theme: 'nano', // or 'monolith', or 'nano'
swatches: [],
components: {
// Main components
preview: true,
opacity: true,
hue: true,
// Input / output Options
interaction: {
input: true,
save: true
}
}
});
pickr.on('change', (color) => {
//console.log('change', color.toRGBA());
let c = color.toRGBA();
DALFC.user.backgroundColor(c[0] / 255, c[1] / 255, c[2] / 255, c[3]);
})