@plupin/character 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anime-face.d.ts +42 -0
- package/dist/anime-face.js +14 -0
- package/dist/blob.d.ts +32 -0
- package/dist/blob.js +18 -0
- package/dist/body-presets.d.ts +85 -0
- package/dist/canvas.d.ts +79 -0
- package/dist/canvas.js +315 -0
- package/dist/chunk-09c5tps4.js +337 -0
- package/dist/chunk-60p135hw.js +103 -0
- package/dist/chunk-aa5nstet.js +39 -0
- package/dist/chunk-dpb0rnw9.js +37 -0
- package/dist/chunk-g1c0wdcj.js +825 -0
- package/dist/chunk-kber92gm.js +415 -0
- package/dist/chunk-sa2r1cxz.js +342 -0
- package/dist/chunk-yd5zzkkg.js +313 -0
- package/dist/clip-bake.d.ts +48 -0
- package/dist/clip-bake.js +132 -0
- package/dist/clips.d.ts +40 -0
- package/dist/dress.d.ts +4 -0
- package/dist/emote.d.ts +25 -0
- package/dist/faces.d.ts +10 -0
- package/dist/faces.js +12 -0
- package/dist/gaze.d.ts +81 -0
- package/dist/gaze.js +113 -0
- package/dist/hair3d.d.ts +3 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +176 -0
- package/dist/listing.d.ts +195 -0
- package/dist/listing.js +763 -0
- package/dist/named-faces.d.ts +22 -0
- package/dist/platform-body-data.d.ts +9 -0
- package/dist/platform-body.d.ts +91 -0
- package/dist/plup2d.d.ts +29 -0
- package/dist/plup3d.d.ts +121 -0
- package/dist/png.d.ts +78 -0
- package/dist/pose.d.ts +49 -0
- package/dist/pose.js +18 -0
- package/dist/proportions.d.ts +31 -0
- package/dist/ragdoll.d.ts +51 -0
- package/dist/resolution.d.ts +21 -0
- package/dist/rig.d.ts +29 -0
- package/dist/skin-map.d.ts +155 -0
- package/dist/skin-map.js +55 -0
- package/dist/skin-native.d.ts +301 -0
- package/dist/skin.d.ts +35 -0
- package/dist/texture.d.ts +8 -0
- package/dist/three.d.ts +25 -0
- package/dist/three.js +2302 -0
- package/dist/wear3d.d.ts +99 -0
- package/dist/wearables.d.ts +203 -0
- package/dist/wearables.js +26 -0
- package/package.json +78 -4
- package/README.md +0 -3
package/dist/listing.js
ADDED
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BODY_SCALE_LIMITS,
|
|
3
|
+
CLASSIC_HEIGHT,
|
|
4
|
+
CLASSIC_TORSO,
|
|
5
|
+
CLASSIC_WIDTH,
|
|
6
|
+
NATIVE_HEAD,
|
|
7
|
+
NATIVE_SHEET_CAPS,
|
|
8
|
+
NATIVE_TORSO,
|
|
9
|
+
clampBodyScale
|
|
10
|
+
} from "./chunk-sa2r1cxz.js";
|
|
11
|
+
import {
|
|
12
|
+
CLIPS
|
|
13
|
+
} from "./chunk-g1c0wdcj.js";
|
|
14
|
+
import {
|
|
15
|
+
FACE_STAMP_PALETTE,
|
|
16
|
+
NAMED_FACES,
|
|
17
|
+
NAMED_FACE_STAMPS,
|
|
18
|
+
isNamedFace
|
|
19
|
+
} from "./chunk-aa5nstet.js";
|
|
20
|
+
|
|
21
|
+
// src/png.ts
|
|
22
|
+
import { unzlibSync, zlibSync } from "fflate";
|
|
23
|
+
var MAX_PIXELS = 4000000;
|
|
24
|
+
var SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
25
|
+
var CHANNELS = { 0: 1, 2: 3, 4: 2, 6: 4 };
|
|
26
|
+
var readUint32 = (bytes, at) => ((bytes[at] ?? 0) << 24 | (bytes[at + 1] ?? 0) << 16 | (bytes[at + 2] ?? 0) << 8 | (bytes[at + 3] ?? 0)) >>> 0;
|
|
27
|
+
var isPng = (bytes) => bytes.length >= 8 && SIGNATURE.every((byte, index) => bytes[index] === byte);
|
|
28
|
+
function* chunks(bytes) {
|
|
29
|
+
let at = 8;
|
|
30
|
+
while (at + 8 <= bytes.length) {
|
|
31
|
+
const length = readUint32(bytes, at);
|
|
32
|
+
const type = String.fromCharCode(bytes[at + 4] ?? 0, bytes[at + 5] ?? 0, bytes[at + 6] ?? 0, bytes[at + 7] ?? 0);
|
|
33
|
+
const start = at + 8;
|
|
34
|
+
const end = start + length;
|
|
35
|
+
if (end + 4 > bytes.length)
|
|
36
|
+
return;
|
|
37
|
+
yield { type, data: bytes.subarray(start, end) };
|
|
38
|
+
at = end + 4;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function parseHeader(bytes) {
|
|
42
|
+
if (!isPng(bytes))
|
|
43
|
+
return { ok: false, reason: "not_png" };
|
|
44
|
+
const first = chunks(bytes).next();
|
|
45
|
+
if (first.done)
|
|
46
|
+
return { ok: false, reason: "truncated" };
|
|
47
|
+
const chunk = first.value;
|
|
48
|
+
if (chunk.type !== "IHDR" || chunk.data.length !== 13)
|
|
49
|
+
return { ok: false, reason: "bad_header" };
|
|
50
|
+
const header = {
|
|
51
|
+
width: readUint32(chunk.data, 0),
|
|
52
|
+
height: readUint32(chunk.data, 4),
|
|
53
|
+
bitDepth: chunk.data[8] ?? 0,
|
|
54
|
+
colorType: chunk.data[9] ?? 0,
|
|
55
|
+
interlaced: (chunk.data[12] ?? 0) === 1
|
|
56
|
+
};
|
|
57
|
+
if (header.width === 0 || header.height === 0)
|
|
58
|
+
return { ok: false, reason: "bad_header" };
|
|
59
|
+
if (header.width * header.height > MAX_PIXELS)
|
|
60
|
+
return { ok: false, reason: "too_large" };
|
|
61
|
+
return { ok: true, header };
|
|
62
|
+
}
|
|
63
|
+
function readPngHeader(bytes) {
|
|
64
|
+
const parsed = parseHeader(bytes);
|
|
65
|
+
if (!parsed.ok)
|
|
66
|
+
return parsed;
|
|
67
|
+
const { header } = parsed;
|
|
68
|
+
if (header.bitDepth !== 8)
|
|
69
|
+
return { ok: false, reason: "unsupported_format" };
|
|
70
|
+
if (header.colorType !== 2 && header.colorType !== 6)
|
|
71
|
+
return { ok: false, reason: "unsupported_format" };
|
|
72
|
+
if (header.interlaced)
|
|
73
|
+
return { ok: false, reason: "interlaced" };
|
|
74
|
+
for (const chunk of chunks(bytes)) {
|
|
75
|
+
if (chunk.type === "PLTE")
|
|
76
|
+
return { ok: false, reason: "unsupported_format" };
|
|
77
|
+
}
|
|
78
|
+
return { ok: true, header };
|
|
79
|
+
}
|
|
80
|
+
var paeth = (left, up, upLeft) => {
|
|
81
|
+
const estimate = left + up - upLeft;
|
|
82
|
+
const toLeft = Math.abs(estimate - left);
|
|
83
|
+
const toUp = Math.abs(estimate - up);
|
|
84
|
+
const toUpLeft = Math.abs(estimate - upLeft);
|
|
85
|
+
if (toLeft <= toUp && toLeft <= toUpLeft)
|
|
86
|
+
return left;
|
|
87
|
+
return toUp <= toUpLeft ? up : upLeft;
|
|
88
|
+
};
|
|
89
|
+
function unfilter(raw, width, height, channels) {
|
|
90
|
+
const stride = width * channels;
|
|
91
|
+
const out = new Uint8Array(stride * height);
|
|
92
|
+
for (let row = 0;row < height; row++) {
|
|
93
|
+
const filter = raw[row * (stride + 1)];
|
|
94
|
+
const start = row * (stride + 1) + 1;
|
|
95
|
+
const target = row * stride;
|
|
96
|
+
const prior = target - stride;
|
|
97
|
+
for (let index = 0;index < stride; index++) {
|
|
98
|
+
const value = raw[start + index] ?? 0;
|
|
99
|
+
const left = index >= channels ? out[target + index - channels] ?? 0 : 0;
|
|
100
|
+
const up = row > 0 ? out[prior + index] ?? 0 : 0;
|
|
101
|
+
const upLeft = row > 0 && index >= channels ? out[prior + index - channels] ?? 0 : 0;
|
|
102
|
+
let restored = value;
|
|
103
|
+
if (filter === 1)
|
|
104
|
+
restored = value + left;
|
|
105
|
+
else if (filter === 2)
|
|
106
|
+
restored = value + up;
|
|
107
|
+
else if (filter === 3)
|
|
108
|
+
restored = value + Math.floor((left + up) / 2);
|
|
109
|
+
else if (filter === 4)
|
|
110
|
+
restored = value + paeth(left, up, upLeft);
|
|
111
|
+
else if (filter !== 0)
|
|
112
|
+
return null;
|
|
113
|
+
out[target + index] = restored & 255;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
function decodePng(bytes) {
|
|
119
|
+
const header = readPngHeader(bytes);
|
|
120
|
+
if (!header.ok)
|
|
121
|
+
return header;
|
|
122
|
+
const { width, height, colorType } = header.header;
|
|
123
|
+
const channels = CHANNELS[colorType] ?? 0;
|
|
124
|
+
if (!channels)
|
|
125
|
+
return { ok: false, reason: "unsupported_format" };
|
|
126
|
+
const parts = [];
|
|
127
|
+
let sawEnd = false;
|
|
128
|
+
for (const chunk of chunks(bytes)) {
|
|
129
|
+
if (chunk.type === "IDAT")
|
|
130
|
+
parts.push(chunk.data);
|
|
131
|
+
if (chunk.type === "IEND") {
|
|
132
|
+
sawEnd = true;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (parts.length === 0 || !sawEnd)
|
|
137
|
+
return { ok: false, reason: "truncated" };
|
|
138
|
+
const compressed = new Uint8Array(parts.reduce((total, part) => total + part.length, 0));
|
|
139
|
+
let offset = 0;
|
|
140
|
+
for (const part of parts) {
|
|
141
|
+
compressed.set(part, offset);
|
|
142
|
+
offset += part.length;
|
|
143
|
+
}
|
|
144
|
+
let raw;
|
|
145
|
+
try {
|
|
146
|
+
raw = unzlibSync(compressed);
|
|
147
|
+
} catch {
|
|
148
|
+
return { ok: false, reason: "corrupt" };
|
|
149
|
+
}
|
|
150
|
+
if (raw.length < (width * channels + 1) * height)
|
|
151
|
+
return { ok: false, reason: "corrupt" };
|
|
152
|
+
const pixels = unfilter(raw, width, height, channels);
|
|
153
|
+
if (!pixels)
|
|
154
|
+
return { ok: false, reason: "corrupt" };
|
|
155
|
+
const data = new Uint8Array(width * height * 4);
|
|
156
|
+
for (let index = 0;index < width * height; index++) {
|
|
157
|
+
const source = index * channels;
|
|
158
|
+
data[index * 4] = pixels[source] ?? 0;
|
|
159
|
+
data[index * 4 + 1] = pixels[source + 1] ?? 0;
|
|
160
|
+
data[index * 4 + 2] = pixels[source + 2] ?? 0;
|
|
161
|
+
data[index * 4 + 3] = channels === 4 ? pixels[source + 3] ?? 255 : 255;
|
|
162
|
+
}
|
|
163
|
+
return { ok: true, image: { width, height, data } };
|
|
164
|
+
}
|
|
165
|
+
var BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
166
|
+
function decodeBase64(value) {
|
|
167
|
+
if (value.length === 0 || value.length % 4 !== 0)
|
|
168
|
+
return null;
|
|
169
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(value))
|
|
170
|
+
return null;
|
|
171
|
+
const padding = value.endsWith("==") ? 2 : value.endsWith("=") ? 1 : 0;
|
|
172
|
+
const bytes = new Uint8Array(value.length / 4 * 3 - padding);
|
|
173
|
+
let written = 0;
|
|
174
|
+
for (let at = 0;at < value.length; at += 4) {
|
|
175
|
+
const codes = [0, 1, 2, 3].map((offset) => {
|
|
176
|
+
const character = value[at + offset] ?? "=";
|
|
177
|
+
return character === "=" ? 0 : BASE64.indexOf(character);
|
|
178
|
+
});
|
|
179
|
+
if (codes.some((code) => code < 0))
|
|
180
|
+
return null;
|
|
181
|
+
const [a = 0, b = 0, c = 0, d = 0] = codes;
|
|
182
|
+
const triple = a << 18 | b << 12 | c << 6 | d;
|
|
183
|
+
if (written < bytes.length)
|
|
184
|
+
bytes[written++] = triple >> 16 & 255;
|
|
185
|
+
if (written < bytes.length)
|
|
186
|
+
bytes[written++] = triple >> 8 & 255;
|
|
187
|
+
if (written < bytes.length)
|
|
188
|
+
bytes[written++] = triple & 255;
|
|
189
|
+
}
|
|
190
|
+
return bytes;
|
|
191
|
+
}
|
|
192
|
+
var CRC_TABLE = (() => {
|
|
193
|
+
const table = new Uint32Array(256);
|
|
194
|
+
for (let index = 0;index < 256; index++) {
|
|
195
|
+
let value = index;
|
|
196
|
+
for (let bit = 0;bit < 8; bit++)
|
|
197
|
+
value = value & 1 ? 3988292384 ^ value >>> 1 : value >>> 1;
|
|
198
|
+
table[index] = value >>> 0;
|
|
199
|
+
}
|
|
200
|
+
return table;
|
|
201
|
+
})();
|
|
202
|
+
|
|
203
|
+
// src/listing.ts
|
|
204
|
+
var LISTABLE_SLOTS = ["outfit", "hair", "accessory", "emote"];
|
|
205
|
+
var EMOTE_KEYS = ["glyph", "face", "clip", "faceStamp", "anim"];
|
|
206
|
+
var ANIM_KEYS = ["fps", "loop", "bones", "frames"];
|
|
207
|
+
var ANIM_CAPS = {
|
|
208
|
+
maxFps: 30,
|
|
209
|
+
maxFrames: 240,
|
|
210
|
+
maxSeconds: 8,
|
|
211
|
+
maxRotation: 3.2,
|
|
212
|
+
minLift: 0,
|
|
213
|
+
maxLift: 3,
|
|
214
|
+
maxBytes: 32 * 1024
|
|
215
|
+
};
|
|
216
|
+
var ANIM_BONES = ["head", "torso", "armL", "armR", "legL", "legR"];
|
|
217
|
+
var COLOR_KEYS = ["color"];
|
|
218
|
+
var SHEET_KEYS = ["sheet", "layer"];
|
|
219
|
+
var VARIANT_KEYS = ["variant", "parts", "scale"];
|
|
220
|
+
var SPRITE_KEYS = ["sprite"];
|
|
221
|
+
var ITEM_ASSET_KINDS = {
|
|
222
|
+
color: "color",
|
|
223
|
+
sheet: "sheet",
|
|
224
|
+
bodyVariant: "variant",
|
|
225
|
+
accessory: "sprite"
|
|
226
|
+
};
|
|
227
|
+
var LISTING_ASSET_CAPS = {
|
|
228
|
+
sheet: { width: CLASSIC_WIDTH, height: CLASSIC_HEIGHT, maxBytes: 160 * 1024 },
|
|
229
|
+
bodyVariant: {
|
|
230
|
+
width: NATIVE_SHEET_CAPS.width,
|
|
231
|
+
height: NATIVE_SHEET_CAPS.height,
|
|
232
|
+
maxBytes: NATIVE_SHEET_CAPS.maxBytes
|
|
233
|
+
},
|
|
234
|
+
accessory: { maxWidth: 64, maxHeight: 64, maxBytes: 8 * 1024 }
|
|
235
|
+
};
|
|
236
|
+
var VARIANT_PARTS = ["torso", "head", "armL", "armR", "legL", "legR"];
|
|
237
|
+
var VARIANT_FACES = ["front", "back", "left", "right", "up", "down"];
|
|
238
|
+
var FACE_STAMP_ROWS = 4;
|
|
239
|
+
var FACE_STAMP_COLUMNS = 8;
|
|
240
|
+
var MAX_GLYPH_CHARACTERS = 20;
|
|
241
|
+
var COLOR_PATTERN = /^#[0-9a-f]{6}$/i;
|
|
242
|
+
var PNG_DATA_URL = "data:image/png;base64,";
|
|
243
|
+
var FACE_PALETTE_KEYS = Object.keys(FACE_STAMP_PALETTE);
|
|
244
|
+
|
|
245
|
+
class Refusal extends Error {
|
|
246
|
+
}
|
|
247
|
+
function refuse(message) {
|
|
248
|
+
throw new Refusal(message);
|
|
249
|
+
}
|
|
250
|
+
function asObject(value) {
|
|
251
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
252
|
+
refuse("assetConfig must be an object: the composition the editor produced.");
|
|
253
|
+
return value;
|
|
254
|
+
}
|
|
255
|
+
function refuseUnknownKeys(record, allowed, kind) {
|
|
256
|
+
for (const key of Object.keys(record)) {
|
|
257
|
+
if (!allowed.includes(key))
|
|
258
|
+
refuse(`assetConfig.${key} is not part of an ${kind} manifest. Allowed: ${allowed.join(", ")}.`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function readGlyph(value) {
|
|
262
|
+
if (typeof value !== "string")
|
|
263
|
+
refuse('assetConfig.glyph must be the kaomoji text, for example "(≧▽≦)".');
|
|
264
|
+
const glyph = value.trim();
|
|
265
|
+
const characters = [...glyph];
|
|
266
|
+
if (characters.length === 0 || characters.length > MAX_GLYPH_CHARACTERS)
|
|
267
|
+
refuse(`assetConfig.glyph must be 1 to ${MAX_GLYPH_CHARACTERS} characters; this one is ${characters.length}.`);
|
|
268
|
+
for (const character of characters) {
|
|
269
|
+
const code = character.codePointAt(0) ?? 0;
|
|
270
|
+
if (code < 32 || code === 127)
|
|
271
|
+
refuse("assetConfig.glyph must stay on one line: no control characters.");
|
|
272
|
+
}
|
|
273
|
+
return glyph;
|
|
274
|
+
}
|
|
275
|
+
function readFace(value) {
|
|
276
|
+
if (typeof value !== "string" || !value)
|
|
277
|
+
refuse(`assetConfig.face must name a face. Choose one of: ${NAMED_FACES.join(", ")}.`);
|
|
278
|
+
if (!isNamedFace(value))
|
|
279
|
+
refuse(`assetConfig.face "${value}" is not a named face. Choose one of: ${NAMED_FACES.join(", ")}, or draw your own with faceStamp.`);
|
|
280
|
+
return value;
|
|
281
|
+
}
|
|
282
|
+
function readClip(value) {
|
|
283
|
+
if (typeof value !== "string" || !Object.hasOwn(CLIPS, value))
|
|
284
|
+
refuse(`assetConfig.clip must be one the rig plays: ${Object.keys(CLIPS).join(", ")}${typeof value === "string" ? `. "${value}" is not one.` : "."}`);
|
|
285
|
+
return value;
|
|
286
|
+
}
|
|
287
|
+
function readFaceStamp(value) {
|
|
288
|
+
if (!Array.isArray(value) || value.length !== FACE_STAMP_ROWS)
|
|
289
|
+
refuse(`assetConfig.faceStamp must be ${FACE_STAMP_ROWS} rows of ${FACE_STAMP_COLUMNS} characters: one row per pixel row.`);
|
|
290
|
+
return value.map((row, index) => {
|
|
291
|
+
if (typeof row !== "string")
|
|
292
|
+
refuse(`assetConfig.faceStamp[${index}] must be a string of ${FACE_STAMP_COLUMNS} keys.`);
|
|
293
|
+
const characters = [...row];
|
|
294
|
+
if (characters.length !== FACE_STAMP_COLUMNS)
|
|
295
|
+
refuse(`assetConfig.faceStamp[${index}] has ${characters.length} characters; a face row is ${FACE_STAMP_COLUMNS}.`);
|
|
296
|
+
for (const [column, key] of characters.entries()) {
|
|
297
|
+
if (key !== "." && !FACE_PALETTE_KEYS.includes(key))
|
|
298
|
+
refuse(`assetConfig.faceStamp[${index}][${column}] is "${key}". Use "." for transparent or one of: ${FACE_PALETTE_KEYS.join(", ")}.`);
|
|
299
|
+
}
|
|
300
|
+
return characters.join("");
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
function readColor(value) {
|
|
304
|
+
if (typeof value !== "string" || !COLOR_PATTERN.test(value))
|
|
305
|
+
refuse('assetConfig.color must be a hex colour such as "#8a5ad8".');
|
|
306
|
+
return value.toLowerCase();
|
|
307
|
+
}
|
|
308
|
+
async function readImage(field, value, maxBytes) {
|
|
309
|
+
if (typeof value !== "string" || !value.startsWith(PNG_DATA_URL))
|
|
310
|
+
refuse(`${field} must be a data:image/png;base64, URL carrying the PNG bytes.`);
|
|
311
|
+
const base64 = value.slice(PNG_DATA_URL.length);
|
|
312
|
+
const bytes = decodeBase64(base64);
|
|
313
|
+
if (!bytes)
|
|
314
|
+
refuse(`${field} is not valid base64.`);
|
|
315
|
+
const header = readPngHeader(bytes);
|
|
316
|
+
if (!header.ok) {
|
|
317
|
+
if (header.reason === "not_png")
|
|
318
|
+
refuse(`${field} must be a PNG file: these bytes are not one.`);
|
|
319
|
+
if (header.reason === "unsupported_format")
|
|
320
|
+
refuse(`${field} must be a PNG-24 file (8-bit truecolour or truecolour+alpha, no palette): re-export it as PNG-24.`);
|
|
321
|
+
if (header.reason === "interlaced")
|
|
322
|
+
refuse(`${field} must be a non-interlaced PNG: re-export it without Adam7.`);
|
|
323
|
+
if (header.reason === "too_large")
|
|
324
|
+
refuse(`${field} is larger than any listing image may be: re-export it at the template size.`);
|
|
325
|
+
refuse(`${field} could not be read as a PNG: re-export it as PNG-24.`);
|
|
326
|
+
}
|
|
327
|
+
if (bytes.length > maxBytes)
|
|
328
|
+
refuse(`${field} must be ${maxBytes / 1024} KiB at most; these bytes are ${Math.ceil(bytes.length / 1024)} KiB.`);
|
|
329
|
+
const decoded = decodePng(bytes);
|
|
330
|
+
if (!decoded.ok)
|
|
331
|
+
refuse(`${field} could not be decoded as a PNG: re-export it as PNG-24.`);
|
|
332
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
333
|
+
return {
|
|
334
|
+
url: value,
|
|
335
|
+
digest: [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join(""),
|
|
336
|
+
image: decoded.image
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function readLayer(value) {
|
|
340
|
+
if (value !== "shirt" && value !== "pants")
|
|
341
|
+
refuse('assetConfig.layer must be "shirt" or "pants": which classic template the sheet is.');
|
|
342
|
+
return value;
|
|
343
|
+
}
|
|
344
|
+
function readVariantParts(value) {
|
|
345
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
346
|
+
refuse('assetConfig.parts must list at least one part, for example [{"part":"armL","faces":["front","left","right"]}].');
|
|
347
|
+
const seen = new Set;
|
|
348
|
+
return value.map((entry, index) => {
|
|
349
|
+
const field = `assetConfig.parts[${index}]`;
|
|
350
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
351
|
+
refuse(`${field} must be an object with part and faces.`);
|
|
352
|
+
const record = entry;
|
|
353
|
+
for (const key of Object.keys(record)) {
|
|
354
|
+
if (key !== "part" && key !== "faces")
|
|
355
|
+
refuse(`${field}.${key} is not part of a part entry. Allowed: part, faces.`);
|
|
356
|
+
}
|
|
357
|
+
const part = record.part;
|
|
358
|
+
if (typeof part !== "string" || !VARIANT_PARTS.includes(part))
|
|
359
|
+
refuse(`${field}.part ${typeof part === "string" ? `"${part}"` : "must be a name"}: choose one of ${VARIANT_PARTS.join(", ")}.`);
|
|
360
|
+
if (seen.has(part))
|
|
361
|
+
refuse(`${field}.part repeats "${part}": list each part once.`);
|
|
362
|
+
seen.add(part);
|
|
363
|
+
const faces = record.faces;
|
|
364
|
+
if (!Array.isArray(faces) || faces.length === 0)
|
|
365
|
+
refuse(`${field}.faces must list one or more of: ${VARIANT_FACES.join(", ")}.`);
|
|
366
|
+
const normalised = [];
|
|
367
|
+
for (const face of faces) {
|
|
368
|
+
if (typeof face !== "string" || !VARIANT_FACES.includes(face))
|
|
369
|
+
refuse(`${field}.faces has ${typeof face === "string" ? `"${face}"` : "a value that is not a name"}: allowed faces are ${VARIANT_FACES.join(", ")}.`);
|
|
370
|
+
if (!normalised.includes(face))
|
|
371
|
+
normalised.push(face);
|
|
372
|
+
}
|
|
373
|
+
return { part, faces: normalised };
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
var WIDTH_KNOBS = ["torso", "armL", "armR", "legL", "legR"];
|
|
377
|
+
function readKnob(field, value, limit) {
|
|
378
|
+
if (value === undefined)
|
|
379
|
+
return;
|
|
380
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
381
|
+
refuse(`${field} must be a number between ${limit.min} and ${limit.max}.`);
|
|
382
|
+
if (value < limit.min || value > limit.max)
|
|
383
|
+
refuse(`${field} must be between ${limit.min} and ${limit.max}; this one is ${value}.`);
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
386
|
+
function readScale(value) {
|
|
387
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
388
|
+
refuse("assetConfig.scale must be an object of stature, width and head: the proportion profile.");
|
|
389
|
+
const record = value;
|
|
390
|
+
for (const key of Object.keys(record)) {
|
|
391
|
+
if (!["stature", "width", "head"].includes(key))
|
|
392
|
+
refuse(`assetConfig.scale.${key} is not a scale knob. Allowed: stature, width, head.`);
|
|
393
|
+
}
|
|
394
|
+
const width = {};
|
|
395
|
+
if (record.width !== undefined) {
|
|
396
|
+
if (!record.width || typeof record.width !== "object" || Array.isArray(record.width))
|
|
397
|
+
refuse('assetConfig.scale.width must be an object of body parts, for example { "armL": 1.2 }.');
|
|
398
|
+
for (const [part, knob] of Object.entries(record.width)) {
|
|
399
|
+
if (!WIDTH_KNOBS.includes(part))
|
|
400
|
+
refuse(`assetConfig.scale.width.${part} is not a body part with a width. Allowed: ${WIDTH_KNOBS.join(", ")}.`);
|
|
401
|
+
const read = readKnob(`assetConfig.scale.width.${part}`, knob, BODY_SCALE_LIMITS.width);
|
|
402
|
+
if (read !== undefined)
|
|
403
|
+
width[part] = read;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
stature: readKnob("assetConfig.scale.stature", record.stature, BODY_SCALE_LIMITS.stature) ?? 1,
|
|
408
|
+
width,
|
|
409
|
+
head: readKnob("assetConfig.scale.head", record.head, BODY_SCALE_LIMITS.head) ?? 1
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
function readSlotFor(kind, slot, allowed) {
|
|
413
|
+
if (!allowed.includes(slot))
|
|
414
|
+
refuse(`A ${kind} is worn on the ${allowed.join(" or ")} slot, not ${slot}.`);
|
|
415
|
+
}
|
|
416
|
+
async function readSheet(record, slot) {
|
|
417
|
+
readSlotFor("sheet", slot, ["outfit"]);
|
|
418
|
+
refuseUnknownKeys(record, SHEET_KEYS, "sheet item");
|
|
419
|
+
const layer = readLayer(record.layer);
|
|
420
|
+
const caps = LISTING_ASSET_CAPS.sheet;
|
|
421
|
+
const image = await readImage("assetConfig.sheet", record.sheet, caps.maxBytes);
|
|
422
|
+
if (image.image.width !== caps.width || image.image.height !== caps.height)
|
|
423
|
+
refuse(`assetConfig.sheet must be the classic ${caps.width}x${caps.height} template; this one is ${image.image.width}x${image.image.height}.`);
|
|
424
|
+
return { assetConfig: { sheet: image.url, layer }, assets: [image.digest] };
|
|
425
|
+
}
|
|
426
|
+
async function readVariant(record, slot) {
|
|
427
|
+
readSlotFor("bodyVariant", slot, ["outfit"]);
|
|
428
|
+
refuseUnknownKeys(record, VARIANT_KEYS, "body-variant item");
|
|
429
|
+
const parts = readVariantParts(record.parts);
|
|
430
|
+
const scale = record.scale === undefined ? undefined : readScale(record.scale);
|
|
431
|
+
const caps = LISTING_ASSET_CAPS.bodyVariant;
|
|
432
|
+
const image = await readImage("assetConfig.variant", record.variant, caps.maxBytes);
|
|
433
|
+
if (image.image.width !== caps.width || image.image.height !== caps.height)
|
|
434
|
+
refuse(`assetConfig.variant must be the Plupin-native ${caps.width}x${caps.height} grid; this one is ${image.image.width}x${image.image.height}.`);
|
|
435
|
+
const assetConfig = {
|
|
436
|
+
variant: image.url,
|
|
437
|
+
parts,
|
|
438
|
+
...scale ? { scale } : {}
|
|
439
|
+
};
|
|
440
|
+
return { assetConfig, assets: [image.digest] };
|
|
441
|
+
}
|
|
442
|
+
async function readSprite(record, slot) {
|
|
443
|
+
readSlotFor("sprite", slot, ["hair", "accessory"]);
|
|
444
|
+
refuseUnknownKeys(record, SPRITE_KEYS, "sprite item");
|
|
445
|
+
const caps = LISTING_ASSET_CAPS.accessory;
|
|
446
|
+
const image = await readImage("assetConfig.sprite", record.sprite, caps.maxBytes);
|
|
447
|
+
if (image.image.width > caps.maxWidth || image.image.height > caps.maxHeight)
|
|
448
|
+
refuse(`assetConfig.sprite must be at most ${caps.maxWidth}x${caps.maxHeight}; this one is ${image.image.width}x${image.image.height}.`);
|
|
449
|
+
return { assetConfig: { sprite: image.url }, assets: [image.digest] };
|
|
450
|
+
}
|
|
451
|
+
async function faceStampDigest(rows) {
|
|
452
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`plupin-face-v1
|
|
453
|
+
${rows.join(`
|
|
454
|
+
`)}`));
|
|
455
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
456
|
+
}
|
|
457
|
+
async function animDigest(anim) {
|
|
458
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`plupin-anim-v1
|
|
459
|
+
${JSON.stringify(anim)}`));
|
|
460
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
461
|
+
}
|
|
462
|
+
function readAnim(value) {
|
|
463
|
+
const record = asObject(value);
|
|
464
|
+
refuseUnknownKeys(record, ANIM_KEYS, "assetConfig.anim");
|
|
465
|
+
const { fps, loop, bones, frames } = record;
|
|
466
|
+
if (!Number.isInteger(fps) || fps < 1 || fps > ANIM_CAPS.maxFps)
|
|
467
|
+
refuse(`assetConfig.anim.fps must be a whole number from 1 to ${ANIM_CAPS.maxFps}.`);
|
|
468
|
+
if (typeof loop !== "boolean")
|
|
469
|
+
refuse("assetConfig.anim.loop must be true or false.");
|
|
470
|
+
if (!Array.isArray(bones) || bones.length < 1 || bones.length > ANIM_BONES.length)
|
|
471
|
+
refuse(`assetConfig.anim.bones must list 1 to ${ANIM_BONES.length} of: ${ANIM_BONES.join(", ")}.`);
|
|
472
|
+
bones.forEach((bone, index) => {
|
|
473
|
+
if (!ANIM_BONES.includes(bone))
|
|
474
|
+
refuse(`assetConfig.anim.bones[${index}] "${String(bone)}" is not a bone. Choose from: ${ANIM_BONES.join(", ")}.`);
|
|
475
|
+
});
|
|
476
|
+
if (new Set(bones).size !== bones.length)
|
|
477
|
+
refuse("assetConfig.anim.bones lists a bone twice.");
|
|
478
|
+
if (!Array.isArray(frames) || frames.length < 1)
|
|
479
|
+
refuse("assetConfig.anim.frames must be a list with at least one frame.");
|
|
480
|
+
if (frames.length > ANIM_CAPS.maxFrames)
|
|
481
|
+
refuse(`assetConfig.anim.frames has ${frames.length} frames; the most is ${ANIM_CAPS.maxFrames}.`);
|
|
482
|
+
const seconds = frames.length / fps;
|
|
483
|
+
if (seconds > ANIM_CAPS.maxSeconds)
|
|
484
|
+
refuse(`assetConfig.anim runs ${seconds.toFixed(1)} s; the longest is ${ANIM_CAPS.maxSeconds} s. Lower the frame count or raise fps.`);
|
|
485
|
+
const width = bones.length * 3 + 1;
|
|
486
|
+
const checked = frames.map((frame, row) => {
|
|
487
|
+
if (!Array.isArray(frame) || frame.length !== width)
|
|
488
|
+
refuse(`assetConfig.anim.frames[${row}] must hold ${width} numbers: x, y, z for each of ${bones.length} bone(s), then lift.`);
|
|
489
|
+
return frame.map((entry, column) => {
|
|
490
|
+
if (typeof entry !== "number" || !Number.isFinite(entry))
|
|
491
|
+
refuse(`assetConfig.anim.frames[${row}][${column}] must be a finite number.`);
|
|
492
|
+
const lift = column === width - 1;
|
|
493
|
+
const [low, high] = lift ? [ANIM_CAPS.minLift, ANIM_CAPS.maxLift] : [-ANIM_CAPS.maxRotation, ANIM_CAPS.maxRotation];
|
|
494
|
+
if (entry < low || entry > high)
|
|
495
|
+
refuse(`assetConfig.anim.frames[${row}][${column}] is ${entry}; ${lift ? "lift" : "a rotation"} must stay within ${low} to ${high}.`);
|
|
496
|
+
return Math.round(entry * 1000) / 1000;
|
|
497
|
+
});
|
|
498
|
+
});
|
|
499
|
+
const anim = {
|
|
500
|
+
fps,
|
|
501
|
+
loop,
|
|
502
|
+
bones,
|
|
503
|
+
frames: checked
|
|
504
|
+
};
|
|
505
|
+
if (JSON.stringify(anim).length > ANIM_CAPS.maxBytes)
|
|
506
|
+
refuse(`assetConfig.anim is larger than ${ANIM_CAPS.maxBytes / 1024} KB. Fewer frames or a lower fps.`);
|
|
507
|
+
return anim;
|
|
508
|
+
}
|
|
509
|
+
async function readEmote(record) {
|
|
510
|
+
refuseUnknownKeys(record, EMOTE_KEYS, "emote");
|
|
511
|
+
const glyph = readGlyph(record.glyph);
|
|
512
|
+
const anim = record.anim === undefined ? undefined : readAnim(record.anim);
|
|
513
|
+
const clip = record.clip === undefined && anim ? "idle" : readClip(record.clip);
|
|
514
|
+
const faceStamp = record.faceStamp === undefined ? undefined : readFaceStamp(record.faceStamp);
|
|
515
|
+
const face = record.face === undefined && faceStamp ? undefined : readFace(record.face);
|
|
516
|
+
const assetConfig = { glyph, clip, ...face ? { face } : {} };
|
|
517
|
+
if (faceStamp)
|
|
518
|
+
assetConfig.faceStamp = faceStamp;
|
|
519
|
+
if (anim)
|
|
520
|
+
assetConfig.anim = anim;
|
|
521
|
+
return {
|
|
522
|
+
assetConfig,
|
|
523
|
+
assets: [
|
|
524
|
+
...faceStamp ? [await faceStampDigest(faceStamp)] : [],
|
|
525
|
+
...anim ? [await animDigest(anim)] : []
|
|
526
|
+
]
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
var ITEM_FORMS = ["color", "sheet", "variant", "sprite"];
|
|
530
|
+
function readItem(record, slot) {
|
|
531
|
+
const present = ITEM_FORMS.filter((form2) => record[form2] !== undefined);
|
|
532
|
+
if (present.length === 0)
|
|
533
|
+
refuse("assetConfig needs one of: color (a hex colour), sheet (a classic 585x559 shirt or pants PNG), variant (a Plupin-native body-variant sheet) or sprite (an accessory PNG).");
|
|
534
|
+
if (present.length > 1)
|
|
535
|
+
throw new Refusal(`assetConfig mixes ${present.join(" and ")}: an item manifest carries one form.`);
|
|
536
|
+
const form = present[0];
|
|
537
|
+
if (form === "color") {
|
|
538
|
+
refuseUnknownKeys(record, COLOR_KEYS, "item");
|
|
539
|
+
return Promise.resolve({ assetConfig: { color: readColor(record.color) }, assets: [] });
|
|
540
|
+
}
|
|
541
|
+
if (form === "sheet")
|
|
542
|
+
return readSheet(record, slot);
|
|
543
|
+
if (form === "variant")
|
|
544
|
+
return readVariant(record, slot);
|
|
545
|
+
return readSprite(record, slot);
|
|
546
|
+
}
|
|
547
|
+
async function checkListingManifest(input) {
|
|
548
|
+
if (!LISTABLE_SLOTS.includes(input.slot))
|
|
549
|
+
return { ok: false, message: `Only ${LISTABLE_SLOTS.join(", ")} can be listed.` };
|
|
550
|
+
try {
|
|
551
|
+
const record = asObject(input.assetConfig);
|
|
552
|
+
return {
|
|
553
|
+
ok: true,
|
|
554
|
+
manifest: input.slot === "emote" ? await readEmote(record) : await readItem(record, input.slot)
|
|
555
|
+
};
|
|
556
|
+
} catch (error) {
|
|
557
|
+
if (error instanceof Refusal)
|
|
558
|
+
return { ok: false, message: error.message };
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
function starterManifest(input) {
|
|
563
|
+
const slot = input.slot ?? "emote";
|
|
564
|
+
return {
|
|
565
|
+
id: input.id,
|
|
566
|
+
slot,
|
|
567
|
+
name: input.name,
|
|
568
|
+
sigmaPrice: input.sigmaPrice ?? 0,
|
|
569
|
+
assetConfig: slot === "emote" ? {
|
|
570
|
+
glyph: input.glyph ?? "(≧▽≦)",
|
|
571
|
+
face: input.face ?? "teriak",
|
|
572
|
+
clip: input.clip ?? "jump"
|
|
573
|
+
} : { color: input.color ?? "#8a5ad8" }
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
var GRID = 24;
|
|
577
|
+
var SCALE = 8;
|
|
578
|
+
var INK = "#161923";
|
|
579
|
+
var SKIN = "#f0b184";
|
|
580
|
+
var BODY = "#2f6fed";
|
|
581
|
+
var NEUTRAL = "#8b93a8";
|
|
582
|
+
var NEUTRAL_FACE = [".e....e.", "........", "...mm...", "........"];
|
|
583
|
+
function paint(pixels, x, y, width, height, colour) {
|
|
584
|
+
for (let row = y;row < y + height; row++) {
|
|
585
|
+
for (let column = x;column < x + width; column++)
|
|
586
|
+
pixels.set(`${column},${row}`, colour);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
function stamp(rows, left, top, pixels) {
|
|
590
|
+
for (const [row, line] of rows.entries()) {
|
|
591
|
+
for (const [column, key] of [...line].entries()) {
|
|
592
|
+
const colour = FACE_STAMP_PALETTE[key];
|
|
593
|
+
if (colour)
|
|
594
|
+
pixels.set(`${left + column},${top + row}`, colour);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function drawnFace(assetConfig) {
|
|
599
|
+
const value = assetConfig.faceStamp;
|
|
600
|
+
if (!Array.isArray(value) || value.length !== 4)
|
|
601
|
+
return null;
|
|
602
|
+
return value.every((row) => typeof row === "string") ? value : null;
|
|
603
|
+
}
|
|
604
|
+
function namedFace(assetConfig) {
|
|
605
|
+
const face = assetConfig.face;
|
|
606
|
+
if (typeof face !== "string")
|
|
607
|
+
return null;
|
|
608
|
+
const rows = NAMED_FACE_STAMPS[face];
|
|
609
|
+
return rows ?? null;
|
|
610
|
+
}
|
|
611
|
+
function escapeXml(value) {
|
|
612
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
613
|
+
}
|
|
614
|
+
function asRecord(value) {
|
|
615
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
616
|
+
}
|
|
617
|
+
function itemAssetKindOf(assetConfig) {
|
|
618
|
+
const record = asRecord(assetConfig);
|
|
619
|
+
for (const kind of Object.keys(ITEM_ASSET_KINDS)) {
|
|
620
|
+
if (typeof record[ITEM_ASSET_KINDS[kind]] === "string")
|
|
621
|
+
return kind;
|
|
622
|
+
}
|
|
623
|
+
return null;
|
|
624
|
+
}
|
|
625
|
+
function manifestImage(record, field) {
|
|
626
|
+
const value = record[field];
|
|
627
|
+
if (typeof value !== "string" || !value.startsWith(PNG_DATA_URL))
|
|
628
|
+
return null;
|
|
629
|
+
const bytes = decodeBase64(value.slice(PNG_DATA_URL.length));
|
|
630
|
+
if (!bytes)
|
|
631
|
+
return null;
|
|
632
|
+
const decoded = decodePng(bytes);
|
|
633
|
+
return decoded.ok ? decoded.image : null;
|
|
634
|
+
}
|
|
635
|
+
var BODY_TORSO_BOX = { x: 6, y: 14, w: 12, h: 8 };
|
|
636
|
+
var BODY_HEAD_BOX = { x: 8, y: 5, w: 8, h: 9 };
|
|
637
|
+
function bodyBoxes(scale) {
|
|
638
|
+
const torsoWidth = Math.max(2, Math.round(BODY_TORSO_BOX.w * scale.stature * (scale.width.torso ?? 1)));
|
|
639
|
+
const torsoHeight = Math.max(2, Math.round(BODY_TORSO_BOX.h * scale.stature));
|
|
640
|
+
const torso = {
|
|
641
|
+
x: 12 - Math.floor(torsoWidth / 2),
|
|
642
|
+
y: 22 - torsoHeight,
|
|
643
|
+
w: torsoWidth,
|
|
644
|
+
h: torsoHeight
|
|
645
|
+
};
|
|
646
|
+
const headSide = Math.max(2, Math.round(BODY_HEAD_BOX.w * scale.stature * scale.head));
|
|
647
|
+
const headHeight = Math.max(2, Math.round(BODY_HEAD_BOX.h * scale.stature * scale.head));
|
|
648
|
+
const head = {
|
|
649
|
+
x: 12 - Math.floor(headSide / 2),
|
|
650
|
+
y: torso.y - headHeight,
|
|
651
|
+
w: headSide,
|
|
652
|
+
h: headHeight
|
|
653
|
+
};
|
|
654
|
+
return { torso, head };
|
|
655
|
+
}
|
|
656
|
+
var hexColour = (image, at) => `#${[0, 1, 2].map((offset) => (image.data[at + offset] ?? 0).toString(16).padStart(2, "0")).join("")}`;
|
|
657
|
+
function sampleInto(pixels, image, source, dest) {
|
|
658
|
+
if (dest.w <= 0 || dest.h <= 0)
|
|
659
|
+
return;
|
|
660
|
+
for (let y = dest.y;y < dest.y + dest.h; y++) {
|
|
661
|
+
if (y < 0 || y >= GRID)
|
|
662
|
+
continue;
|
|
663
|
+
for (let x = dest.x;x < dest.x + dest.w; x++) {
|
|
664
|
+
if (x < 0 || x >= GRID)
|
|
665
|
+
continue;
|
|
666
|
+
const u = (x - dest.x + 0.5) / dest.w;
|
|
667
|
+
const v = (y - dest.y + 0.5) / dest.h;
|
|
668
|
+
const sx = Math.min(source.x + source.w - 1, Math.max(source.x, Math.floor(source.x + u * source.w)));
|
|
669
|
+
const sy = Math.min(source.y + source.h - 1, Math.max(source.y, Math.floor(source.y + v * source.h)));
|
|
670
|
+
if (sx >= image.width || sy >= image.height)
|
|
671
|
+
continue;
|
|
672
|
+
const at = (sy * image.width + sx) * 4;
|
|
673
|
+
if ((image.data[at + 3] ?? 255) < 128)
|
|
674
|
+
continue;
|
|
675
|
+
pixels.set(`${x},${y}`, hexColour(image, at));
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function paintArtItem(pixels, assetConfig, kind, slot) {
|
|
680
|
+
const scale = clampBodyScale(assetConfig.scale && typeof assetConfig.scale === "object" ? assetConfig.scale : undefined);
|
|
681
|
+
const { torso, head } = bodyBoxes(scale);
|
|
682
|
+
paint(pixels, torso.x, torso.y, torso.w, torso.h, SKIN);
|
|
683
|
+
paint(pixels, head.x, head.y, head.w, head.h, SKIN);
|
|
684
|
+
if (kind === "bodyVariant") {
|
|
685
|
+
const image = manifestImage(assetConfig, "variant");
|
|
686
|
+
if (image) {
|
|
687
|
+
sampleInto(pixels, image, NATIVE_TORSO.front, torso);
|
|
688
|
+
sampleInto(pixels, image, NATIVE_HEAD.front, head);
|
|
689
|
+
}
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (kind === "sheet") {
|
|
693
|
+
const image = manifestImage(assetConfig, "sheet");
|
|
694
|
+
if (image)
|
|
695
|
+
sampleInto(pixels, image, CLASSIC_TORSO.front, torso);
|
|
696
|
+
} else {
|
|
697
|
+
const image = manifestImage(assetConfig, "sprite");
|
|
698
|
+
if (image) {
|
|
699
|
+
const band = slot === "hair" ? { x: head.x, y: head.y, w: head.w, h: Math.max(1, Math.floor(head.h * 0.45)) } : { x: torso.x, y: torso.y, w: torso.w, h: Math.max(1, Math.floor(torso.h * 0.5)) };
|
|
700
|
+
sampleInto(pixels, image, { x: 0, y: 0, w: image.width, h: image.height }, band);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const face = drawnFace(assetConfig) ?? namedFace(assetConfig) ?? NEUTRAL_FACE;
|
|
704
|
+
stamp(face, head.x, head.y + Math.max(0, Math.floor((head.h - FACE_STAMP_ROWS) / 2)), pixels);
|
|
705
|
+
}
|
|
706
|
+
function renderListingPreview(input) {
|
|
707
|
+
const assetConfig = asRecord(input.assetConfig);
|
|
708
|
+
const kind = itemAssetKindOf(assetConfig);
|
|
709
|
+
const colour = typeof assetConfig.color === "string" && COLOR_PATTERN.test(assetConfig.color) ? assetConfig.color.toLowerCase() : BODY;
|
|
710
|
+
const pixels = new Map;
|
|
711
|
+
if (kind === "sheet" || kind === "bodyVariant" || kind === "accessory") {
|
|
712
|
+
paintArtItem(pixels, assetConfig, kind, input.slot === "hat" ? "hair" : input.slot);
|
|
713
|
+
} else {
|
|
714
|
+
paint(pixels, 5, 17, 14, 4, input.slot === "emote" ? BODY : colour);
|
|
715
|
+
paint(pixels, 7, 4, 10, 12, SKIN);
|
|
716
|
+
paint(pixels, 7, 3, 10, 1, INK);
|
|
717
|
+
paint(pixels, 7, 16, 10, 1, INK);
|
|
718
|
+
paint(pixels, 6, 4, 1, 12, INK);
|
|
719
|
+
paint(pixels, 17, 4, 1, 12, INK);
|
|
720
|
+
const face = drawnFace(assetConfig) ?? namedFace(assetConfig) ?? NEUTRAL_FACE;
|
|
721
|
+
stamp(face, 8, 8, pixels);
|
|
722
|
+
if (input.slot === "hair")
|
|
723
|
+
paint(pixels, 7, 3, 10, 3, colour);
|
|
724
|
+
if (input.slot === "accessory")
|
|
725
|
+
paint(pixels, 7, 13, 10, 1, colour);
|
|
726
|
+
if (input.slot === "outfit")
|
|
727
|
+
paint(pixels, 5, 20, 14, 1, NEUTRAL);
|
|
728
|
+
}
|
|
729
|
+
const rects = [];
|
|
730
|
+
for (let y = 0;y < GRID; y++) {
|
|
731
|
+
for (let x = 0;x < GRID; x++) {
|
|
732
|
+
const painted = pixels.get(`${x},${y}`);
|
|
733
|
+
if (painted)
|
|
734
|
+
rects.push(`<rect x="${x}" y="${y}" width="1" height="1" fill="${painted}"/>`);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
let overlay = "";
|
|
738
|
+
const glyph = assetConfig.glyph;
|
|
739
|
+
if (input.slot === "emote" && typeof glyph === "string" && glyph.trim()) {
|
|
740
|
+
const text = glyph.trim();
|
|
741
|
+
const size = Math.min(3.6, (GRID - 4) / Math.max(4, [...text].length));
|
|
742
|
+
overlay = `<text x="${GRID / 2}" y="${GRID - 1}" text-anchor="middle" font-family="monospace" font-size="${size.toFixed(2)}" fill="#ffffff" stroke="${INK}" stroke-width="0.4">${escapeXml(text)}</text>`;
|
|
743
|
+
}
|
|
744
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${GRID} ${GRID}" width="${GRID * SCALE}" height="${GRID * SCALE}" shape-rendering="crispEdges" role="img" aria-label="${escapeXml(input.name)}"><title>${escapeXml(input.name)}</title>${rects.join("")}${overlay}</svg>`;
|
|
745
|
+
}
|
|
746
|
+
function previewDataUrl(svg) {
|
|
747
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
|
|
748
|
+
}
|
|
749
|
+
export {
|
|
750
|
+
starterManifest,
|
|
751
|
+
renderListingPreview,
|
|
752
|
+
previewDataUrl,
|
|
753
|
+
itemAssetKindOf,
|
|
754
|
+
faceStampDigest,
|
|
755
|
+
checkListingManifest,
|
|
756
|
+
animDigest,
|
|
757
|
+
VARIANT_PARTS,
|
|
758
|
+
VARIANT_FACES,
|
|
759
|
+
LISTING_ASSET_CAPS,
|
|
760
|
+
LISTABLE_SLOTS,
|
|
761
|
+
ITEM_ASSET_KINDS,
|
|
762
|
+
ANIM_CAPS
|
|
763
|
+
};
|