This repository was archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmatrix.js
More file actions
266 lines (224 loc) · 8.1 KB
/
Copy pathmatrix.js
File metadata and controls
266 lines (224 loc) · 8.1 KB
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
// Validation collections
//Once again, credit to the JN team
//POSE_CODES = []
EYEBROW_CODES = []
BACKARMS_CODES = []
ARMS_CODES = []
ARMS2_CODES = []
//HAIR_CODES = []
EYE_CODES = []
MOUTH_CODES = []
BLUSH_CODES = []
TEAR_CODES = []
// When an option is selected, this forces an update of the corresponding image tag's src to show the correct sprite
function ul(layer) {
var text = $("#" + layer + "_control :selected").text()
if (text === "(none)")
{
// We use Date here to ensure images aren't cached by spoofing a request for the newest ver.
$("#" + layer + "_layer").attr("src", "./img/etc/empty.png" + "?" + new Date())
}
else
{
// We use Date here to ensure images aren't cached by spoofing a request for the newest ver.
$("#" + layer + "_layer").attr("src", "./img/" + layer + "/" + text + ".png" + "?" + new Date())
}
// Update the sprite code displayed to the user
usc()
}
// This generates the sprite code for the currently selected sprite combination seen by the user
function usc() {
var code = $("#eyebrows_control :selected").val()
+ $("#backarms_control :selected").val()
+ $("#arms_control :selected").val()
+ $("#arms2_control :selected").val()
//+ $("#hair_control :selected").val()
+ $("#eyes_control :selected").val()
+ $("#mouth_control :selected").val()
+ $("#blush_control :selected").val()
+ $("#tears_control :selected").val()
$("#sprite_code").text(code)
}
function get_from_sprite_code(spritecode){
// Get the two main portions of the spritecode
baseCode = spritecode.slice(0, 6);
if (baseCode.length == 0) {
return
}
else if (baseCode.length < 6) {
update_sprite_code_status(false, "Invalid spritecode: spritecodes must be 6+ characters")
return
}
optionalCode = spritecode.slice(6);
// Get base subportions
//pose = baseCode[0]
eyebrows = baseCode[0]
backarms = baseCode[1]
arms = baseCode[2]
arms2 = baseCode[3]
//hair = baseCode[4]
eyes = baseCode[4]
mouth = baseCode[5]
//blush = baseCode[7]
//tears = baseCode[8]
// Validate base subportions
if (!EYEBROW_CODES.includes(eyebrows)){
update_sprite_code_status(false, "Invalid spritecode: undefined eyebrows " + eyebrows)
return
}
if (!BACKARMS_CODES.includes(backarms)){
update_sprite_code_status(false, "Invalid spritecode: undefined backarms " + backarms)
return
}
if (!ARMS_CODES.includes(arms)){
update_sprite_code_status(false, "Invalid spritecode: undefined arms " + arms)
return
}
if (!ARMS2_CODES.includes(arms2)){
update_sprite_code_status(false, "Invalid spritecode: undefined arms2 " + arms2)
return
}
//if (!HAIR_CODES.includes(hair)){
// update_sprite_code_status(false, "Invalid spritecode: undefined hair " + hair)
// return
//}
if (!EYE_CODES.includes(eyes)){
update_sprite_code_status(false, "Invalid spritecode: undefined eyes " + eyes)
return
}
if (!MOUTH_CODES.includes(mouth)){
update_sprite_code_status(false, "Invalid spritecode: undefined mouth " + mouth)
return
}
blush = null
tears = null
//emote = null
// Get, validate optional subportions
while (optionalCode) {
if (BLUSH_CODES.includes(optionalCode[0])) {
blush = optionalCode[0]
optionalCode = optionalCode.slice(1)
}
else {
if (TEAR_CODES.includes(optionalCode.slice(0,2))) {
tears = optionalCode.slice(0,2)
optionalCode = optionalCode.slice(2)
}
else {
update_sprite_code_status(false, "Invalid optional expression subcode " + optionalCode + ". (All optional parts must follow mandatory ones)")
return
}
}
}
// Finally update the visuals
//$("#pose_control option[value='" + pose + "']").prop("selected", true)
$("#eyebrows_control option[value='" + eyebrows + "']").prop("selected", true)
$("#backarms_control option[value='" + backarms + "']").prop("selected", true)
$("#arms_control option[value='" + arms + "']").prop("selected", true)
$("#arms2_control option[value='" + arms2 + "']").prop("selected", true)
//$("#hair_control option[value='" + hair + "']").prop("selected", true)
$("#eyes_control option[value='" + eyes + "']").prop("selected", true)
$("#mouth_control option[value='" + mouth + "']").prop("selected", true)
if (blush !== null) {
$("#blush_control option[value='" + blush + "']").prop("selected", true)
}
else {
$("#blush_control option[value='']").prop("selected", true)
}
if (tears !== null) {
$("#tears_control option[value='" + tears + "']").prop("selected", true)
}
else {
$("#tears_control option[value='']").prop("selected", true)
}
//if (emote !== null) {
// $("#emote_control option[value='" + emote + "']").prop("selected", true)
//}
//update_layer("pose")
ul("eyebrows")
ul("backarms")
ul("arms")
ul("arms2")
//ul("hair")
ul("eyes")
ul("mouth")
ul("blush")
ul("tears")
update_sprite_code_status(true)
//update_layer("emote")
}
// Copies the currently displayed sprite code to the clipboard
function cc(object) {
object.innerHTML = "[copied!]"
navigator.clipboard.writeText($("#sprite_code").text())
setTimeout(() => {
object.innerHTML = "[copy]"
}, 250);
}
// Reset everything by reloading the page
function reset_canvas(){
location.reload()
}
function update_sprite_code_status(isValid, hint="Invalid sprite code.") {
if (isValid) {
$("#sprite_code_status").attr("src", "./img/spritecode_status/valid.png?" + new Date())
$("#sprite_code_status").attr("title", "Valid spritecode!")
}
else {
$("#sprite_code_status").attr("src", "./img/spritecode_status/invalid.png?" + new Date())
$("#sprite_code_status").attr("title", hint)
}
}
// When the page loads, show the sprite code for the default sprite combination
$(document).ready(function() {
usc()
document.getElementById("input_code").addEventListener(
"keyup",
function() {
get_from_sprite_code($("#input_code").val())
}
)
document.getElementById("input_code").addEventListener(
"paste",
function() {
get_from_sprite_code($("#input_code").val())
}
)
// Add map values for input spritecode checks based on select options
// Compulsary code subportions
//$.each($("#pose_control option"), function(index, value) {
// POSE_CODES.push(value.value)
//});
$.each($("#eyebrows_control option"), function(index, value) {
EYEBROW_CODES.push(value.value)
});
$.each($("#backarms_control option"), function(index, value) {
BACKARMS_CODES.push(value.value)
});
$.each($("#arms_control option"), function(index, value) {
ARMS_CODES.push(value.value)
});
$.each($("#arms2_control option"), function(index, value) {
ARMS2_CODES.push(value.value)
});
//$.each($("#hair_control option"), function(index, value) {
// HAIR_CODES.push(value.value)
//});
$.each($("#eyes_control option"), function(index, value) {
EYE_CODES.push(value.value)
});
$.each($("#mouth_control option"), function(index, value) {
MOUTH_CODES.push(value.value)
});
// Optional code subportions
$.each($("#blush_control option"), function(index, value) {
if (value.value) {
BLUSH_CODES.push(value.value)
}
});
$.each($("#tears_control option"), function(index, value) {
if (value.value) {
TEAR_CODES.push(value.value)
}
});
});