@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
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FACE_STAMP_PALETTE,
|
|
3
|
+
NAMED_FACE_STAMPS
|
|
4
|
+
} from "./chunk-aa5nstet.js";
|
|
5
|
+
|
|
6
|
+
// src/skin-map.ts
|
|
7
|
+
var BODY_WIDTH = 48;
|
|
8
|
+
var BODY_HEIGHT = 24;
|
|
9
|
+
var FACE_COLUMN = 20;
|
|
10
|
+
var FACE_ROW = 9;
|
|
11
|
+
var FACE_TYPES = ["dot", "sparkle", "sleepy", "derp", "anime"];
|
|
12
|
+
var EXPRESSIONS = [
|
|
13
|
+
"idle",
|
|
14
|
+
"blink",
|
|
15
|
+
"happy",
|
|
16
|
+
"surprised",
|
|
17
|
+
"sad",
|
|
18
|
+
"wee",
|
|
19
|
+
...Object.keys(NAMED_FACE_STAMPS)
|
|
20
|
+
];
|
|
21
|
+
function isNamedExpression(expression) {
|
|
22
|
+
return Object.hasOwn(NAMED_FACE_STAMPS, expression);
|
|
23
|
+
}
|
|
24
|
+
var SKIN_PALETTE = {
|
|
25
|
+
B: "#2f6fed",
|
|
26
|
+
L: "#6a96ff",
|
|
27
|
+
D: "#1f4fc0",
|
|
28
|
+
l: "#a9c4ff",
|
|
29
|
+
k: "#161923",
|
|
30
|
+
w: "#ffffff",
|
|
31
|
+
a: "#8b93a8",
|
|
32
|
+
r: "#e2574c",
|
|
33
|
+
o: "#e6a23c",
|
|
34
|
+
y: "#f2d24b",
|
|
35
|
+
g: "#3fae74",
|
|
36
|
+
c: "#4cc9e2",
|
|
37
|
+
v: "#8a5ad8",
|
|
38
|
+
p: "#f08aa8",
|
|
39
|
+
n: "#8a5a3c",
|
|
40
|
+
s: "#f0b184"
|
|
41
|
+
};
|
|
42
|
+
var PAINT_KEYS = Object.keys(SKIN_PALETTE);
|
|
43
|
+
var FACE_PALETTE = FACE_STAMP_PALETTE;
|
|
44
|
+
var SHARED_EYES = {
|
|
45
|
+
blink: ["........", ".ee..ee."],
|
|
46
|
+
happy: ["........", ".ee..ee."],
|
|
47
|
+
wide: [".ee..ee.", ".ee..ee."],
|
|
48
|
+
sad: ["........", ".ee..ee."]
|
|
49
|
+
};
|
|
50
|
+
var SHARED_MOUTHS = {
|
|
51
|
+
open: ["...mm...", "...tt..."],
|
|
52
|
+
o: ["...mm...", "...mm..."],
|
|
53
|
+
frown: ["...mm...", "..m..m.."]
|
|
54
|
+
};
|
|
55
|
+
var FACES = {
|
|
56
|
+
dot: {
|
|
57
|
+
eyes: { ...SHARED_EYES, open: [".ee..ee.", ".ee..ee."], blink: ["........", ".ee..ee."] },
|
|
58
|
+
mouth: { ...SHARED_MOUTHS, idle: ["...mm...", "........"] },
|
|
59
|
+
blush: true
|
|
60
|
+
},
|
|
61
|
+
sparkle: {
|
|
62
|
+
eyes: { ...SHARED_EYES, open: [".we..we.", ".ee..ee."] },
|
|
63
|
+
mouth: { ...SHARED_MOUTHS, idle: ["..m..m..", "...mm..."] },
|
|
64
|
+
blush: true
|
|
65
|
+
},
|
|
66
|
+
sleepy: {
|
|
67
|
+
eyes: { ...SHARED_EYES, open: ["........", ".ee..ee."], blink: ["........", ".ee..ee."] },
|
|
68
|
+
mouth: { ...SHARED_MOUTHS, idle: ["...m....", "........"] },
|
|
69
|
+
blush: true
|
|
70
|
+
},
|
|
71
|
+
derp: {
|
|
72
|
+
eyes: { ...SHARED_EYES, open: [".ee.....", ".ee..e.."] },
|
|
73
|
+
mouth: { ...SHARED_MOUTHS, idle: ["..mmmm..", "....t..."] },
|
|
74
|
+
blush: false
|
|
75
|
+
},
|
|
76
|
+
anime: {
|
|
77
|
+
eyes: { ...SHARED_EYES, open: [".we..we.", ".ee..ee."] },
|
|
78
|
+
mouth: { ...SHARED_MOUTHS, idle: ["..m..m..", "...mm..."] },
|
|
79
|
+
blush: true
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var EXPRESSION_PARTS = {
|
|
83
|
+
idle: { eyes: "open", mouth: "idle" },
|
|
84
|
+
blink: { eyes: "blink", mouth: "idle" },
|
|
85
|
+
happy: { eyes: "happy", mouth: "open" },
|
|
86
|
+
surprised: { eyes: "wide", mouth: "o" },
|
|
87
|
+
sad: { eyes: "sad", mouth: "frown" },
|
|
88
|
+
wee: { eyes: "happy", mouth: "o" }
|
|
89
|
+
};
|
|
90
|
+
function faceStamp(face, expression) {
|
|
91
|
+
if (isNamedExpression(expression))
|
|
92
|
+
return [...NAMED_FACE_STAMPS[expression]];
|
|
93
|
+
const definition = FACES[face] ?? FACES.dot;
|
|
94
|
+
const parts = EXPRESSION_PARTS[expression];
|
|
95
|
+
const [eyeTop, eyeBottom] = definition.eyes[parts.eyes];
|
|
96
|
+
const [mouthTop, mouthBottom] = definition.mouth[parts.mouth];
|
|
97
|
+
const blushRow = definition.blush ? "p......p" : "........";
|
|
98
|
+
const merged = Array.from(mouthTop, (pixel, i) => pixel === "." ? blushRow[i] ?? "." : pixel).join("");
|
|
99
|
+
return [eyeTop, eyeBottom, merged, mouthBottom];
|
|
100
|
+
}
|
|
101
|
+
function bodyPalette(outfitColor) {
|
|
102
|
+
if (!outfitColor || !/^#[0-9a-f]{6}$/i.test(outfitColor))
|
|
103
|
+
return { ...SKIN_PALETTE };
|
|
104
|
+
const channel = (offset) => Number.parseInt(outfitColor.slice(offset, offset + 2), 16);
|
|
105
|
+
const rgb = [channel(1), channel(3), channel(5)];
|
|
106
|
+
const toHex = (values) => `#${values.map((v) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0")).join("")}`;
|
|
107
|
+
return {
|
|
108
|
+
...SKIN_PALETTE,
|
|
109
|
+
B: toHex(rgb),
|
|
110
|
+
L: toHex(rgb.map((v) => v + (255 - v) * 0.32)),
|
|
111
|
+
D: toHex(rgb.map((v) => v * 0.7))
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function composeSkin(skin, expression, outfitColor, look = 0, lookY = 0, drawFace = true, faceScale = 1) {
|
|
115
|
+
const palette = bodyPalette(outfitColor);
|
|
116
|
+
const fallback = palette.B ?? "#2f6fed";
|
|
117
|
+
const pixels = Array.from({ length: BODY_HEIGHT }, (_, y) => Array.from({ length: BODY_WIDTH }, (_2, x) => palette[skin.body[y]?.[x] ?? ""] ?? fallback));
|
|
118
|
+
if (!drawFace)
|
|
119
|
+
return pixels;
|
|
120
|
+
const stamp = faceStamp(skin.face, expression);
|
|
121
|
+
const scale = Math.max(1, Math.floor(faceScale));
|
|
122
|
+
const originX = FACE_COLUMN + 4 - 4 * scale;
|
|
123
|
+
const originY = FACE_ROW + 2 - 2 * scale;
|
|
124
|
+
for (const dy of [2, 3, 0, 1]) {
|
|
125
|
+
const row = stamp[dy] ?? "";
|
|
126
|
+
const eyes = dy < 2;
|
|
127
|
+
const shift = eyes ? look : 0;
|
|
128
|
+
const rise = eyes ? Math.min(lookY, 0) : 0;
|
|
129
|
+
for (let dx = 0;dx < row.length; dx++) {
|
|
130
|
+
const color = FACE_PALETTE[row[dx] ?? "."];
|
|
131
|
+
if (!color)
|
|
132
|
+
continue;
|
|
133
|
+
for (let sy = 0;sy < scale; sy++) {
|
|
134
|
+
const target = pixels[originY + (dy + rise) * scale + sy];
|
|
135
|
+
if (!target)
|
|
136
|
+
continue;
|
|
137
|
+
for (let sx = 0;sx < scale; sx++) {
|
|
138
|
+
target[(originX + (dx + shift) * scale + sx + BODY_WIDTH) % BODY_WIDTH] = color;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return pixels;
|
|
144
|
+
}
|
|
145
|
+
function blankBody(key = "B") {
|
|
146
|
+
return Array.from({ length: BODY_HEIGHT }, () => key.repeat(BODY_WIDTH));
|
|
147
|
+
}
|
|
148
|
+
function defaultBody() {
|
|
149
|
+
const rows = blankBody("B");
|
|
150
|
+
const paint = (x, y, key) => {
|
|
151
|
+
const row = rows[y];
|
|
152
|
+
if (row)
|
|
153
|
+
rows[y] = row.slice(0, x) + key + row.slice(x + 1);
|
|
154
|
+
};
|
|
155
|
+
for (let x = 0;x < BODY_WIDTH; x++) {
|
|
156
|
+
for (const y of [0, 1, 2, 3])
|
|
157
|
+
paint(x, y, "L");
|
|
158
|
+
for (let y = 19;y < BODY_HEIGHT; y++)
|
|
159
|
+
paint(x, y, "D");
|
|
160
|
+
const fromFront = Math.abs(x - 24);
|
|
161
|
+
for (let y = 14;y < 20; y++) {
|
|
162
|
+
if (fromFront * fromFront + (y - 17) * (y - 17) * 4 < 90)
|
|
163
|
+
paint(x, y, "l");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const [x, y] of [
|
|
167
|
+
[15, 6],
|
|
168
|
+
[16, 6],
|
|
169
|
+
[14, 7]
|
|
170
|
+
])
|
|
171
|
+
paint(x, y, "l");
|
|
172
|
+
return rows;
|
|
173
|
+
}
|
|
174
|
+
var BUDDY_TINTS = ["#2f6fed", "#e2574c", "#3fae74", "#e6a23c", "#8a5ad8"];
|
|
175
|
+
var DEFAULT_BUDDY_SKIN = { face: "sparkle", body: defaultBody() };
|
|
176
|
+
function sanitizeSkin(value) {
|
|
177
|
+
const candidate = value;
|
|
178
|
+
const face = FACE_TYPES.includes(candidate?.face) ? candidate?.face : DEFAULT_BUDDY_SKIN.face;
|
|
179
|
+
const rows = Array.isArray(candidate?.body) ? candidate.body : [];
|
|
180
|
+
const body = Array.from({ length: BODY_HEIGHT }, (_, y) => {
|
|
181
|
+
const row = typeof rows[y] === "string" ? rows[y] : "";
|
|
182
|
+
return Array.from({ length: BODY_WIDTH }, (_2, x) => {
|
|
183
|
+
const key = row[x] ?? "";
|
|
184
|
+
return key in SKIN_PALETTE ? key : DEFAULT_BUDDY_SKIN.body[y]?.[x] ?? "B";
|
|
185
|
+
}).join("");
|
|
186
|
+
});
|
|
187
|
+
return { body, face };
|
|
188
|
+
}
|
|
189
|
+
var pick = (list) => list[Math.floor(Math.random() * list.length)];
|
|
190
|
+
function randomSkin() {
|
|
191
|
+
const tint = pick(BUDDY_TINTS);
|
|
192
|
+
const accent = pick(["w", "y", "p", "c", "k", "o"]);
|
|
193
|
+
const pattern = pick(["none", "belly", "stripes", "spots"]);
|
|
194
|
+
const body = DEFAULT_BUDDY_SKIN.body.map((row, y) => Array.from(row, (key, x) => {
|
|
195
|
+
if (pattern === "belly" && y >= 13 && y < 18 && x >= 18 && x < 30)
|
|
196
|
+
return accent;
|
|
197
|
+
if (pattern === "stripes" && y >= 6 && y < 18 && y % 4 === 0)
|
|
198
|
+
return accent;
|
|
199
|
+
if (pattern === "spots" && y >= 4 && y < 17 && (x * 7 + y * 13) % 23 === 0)
|
|
200
|
+
return accent;
|
|
201
|
+
return key;
|
|
202
|
+
}).join(""));
|
|
203
|
+
return {
|
|
204
|
+
skin: {
|
|
205
|
+
face: pick(FACE_TYPES),
|
|
206
|
+
body: body.slice(0, BODY_HEIGHT).map((r) => r.slice(0, BODY_WIDTH))
|
|
207
|
+
},
|
|
208
|
+
tint
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
var SKIN_DETAIL = 4;
|
|
212
|
+
function faceKeys(skin, expression, look = 0, lookY = 0, withEyes = true) {
|
|
213
|
+
const keys = new Map;
|
|
214
|
+
const stamp = faceStamp(skin.face, expression);
|
|
215
|
+
const originX = FACE_COLUMN;
|
|
216
|
+
const originY = FACE_ROW;
|
|
217
|
+
for (const dy of [2, 3, 0, 1]) {
|
|
218
|
+
const row = stamp[dy] ?? "";
|
|
219
|
+
const eyes = dy < 2;
|
|
220
|
+
if (eyes && !withEyes)
|
|
221
|
+
continue;
|
|
222
|
+
const shift = eyes ? look : 0;
|
|
223
|
+
const rise = eyes ? Math.min(lookY, 0) : 0;
|
|
224
|
+
for (let dx = 0;dx < row.length; dx++) {
|
|
225
|
+
const key = row[dx] ?? ".";
|
|
226
|
+
if (!FACE_PALETTE[key])
|
|
227
|
+
continue;
|
|
228
|
+
const x = (originX + dx + shift + BODY_WIDTH) % BODY_WIDTH;
|
|
229
|
+
keys.set(`${x},${originY + dy + rise}`, key);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return keys;
|
|
233
|
+
}
|
|
234
|
+
var CATCH_LIGHT = "#e8eefc";
|
|
235
|
+
function isCatchLight(key, neighbours) {
|
|
236
|
+
return key === "w" && neighbours.includes("e");
|
|
237
|
+
}
|
|
238
|
+
function paintSkinDetailed(context, pixels, body, keys, from = {
|
|
239
|
+
x: 0,
|
|
240
|
+
y: 0,
|
|
241
|
+
w: BODY_WIDTH,
|
|
242
|
+
h: BODY_HEIGHT
|
|
243
|
+
}, soften = (fill) => fill) {
|
|
244
|
+
const D = SKIN_DETAIL;
|
|
245
|
+
const at = (x, y) => keys.get(`${(x + BODY_WIDTH) % BODY_WIDTH},${y}`);
|
|
246
|
+
const isLight = (x, y) => y < FACE_ROW + 2 && isCatchLight(at(x, y), [at(x, y - 1), at(x, y + 1), at(x - 1, y), at(x + 1, y)]);
|
|
247
|
+
let lit = false;
|
|
248
|
+
for (const key of keys.keys()) {
|
|
249
|
+
const [x, y] = key.split(",").map(Number);
|
|
250
|
+
if (isLight(x, y))
|
|
251
|
+
lit = true;
|
|
252
|
+
}
|
|
253
|
+
const isEye = (x, y) => at(x, y) === "e" || isLight(x, y);
|
|
254
|
+
for (let j = 0;j < from.h; j++) {
|
|
255
|
+
for (let i = 0;i < from.w; i++) {
|
|
256
|
+
const x = (from.x + i + BODY_WIDTH) % BODY_WIDTH;
|
|
257
|
+
const y = from.y + j;
|
|
258
|
+
const key = keys.get(`${x},${y}`);
|
|
259
|
+
const under = body[y]?.[x] ?? "transparent";
|
|
260
|
+
context.fillStyle = soften(key ? under : pixels[y]?.[x] ?? "transparent");
|
|
261
|
+
context.fillRect(i * D, j * D, D, D);
|
|
262
|
+
if (!key)
|
|
263
|
+
continue;
|
|
264
|
+
const px = i * D;
|
|
265
|
+
const py = j * D;
|
|
266
|
+
const color = FACE_PALETTE[key] ?? "#000";
|
|
267
|
+
context.fillStyle = color;
|
|
268
|
+
if (key === "e" || isLight(x, y)) {
|
|
269
|
+
const up = isEye(x, y - 1);
|
|
270
|
+
const down = isEye(x, y + 1);
|
|
271
|
+
const left = isEye(x - 1, y);
|
|
272
|
+
const right = isEye(x + 1, y);
|
|
273
|
+
context.fillStyle = FACE_PALETTE.e ?? "#161923";
|
|
274
|
+
context.fillRect(px, py, D, D);
|
|
275
|
+
context.fillStyle = soften(under);
|
|
276
|
+
if (!up && !left)
|
|
277
|
+
context.fillRect(px, py, 1, 1);
|
|
278
|
+
if (!up && !right)
|
|
279
|
+
context.fillRect(px + D - 1, py, 1, 1);
|
|
280
|
+
if (!down && !left)
|
|
281
|
+
context.fillRect(px, py + D - 1, 1, 1);
|
|
282
|
+
if (!down && !right)
|
|
283
|
+
context.fillRect(px + D - 1, py + D - 1, 1, 1);
|
|
284
|
+
if (key !== "e") {
|
|
285
|
+
context.fillStyle = CATCH_LIGHT;
|
|
286
|
+
context.fillRect(px + 0.75, py + 0.75, D - 1.5, D - 1.5);
|
|
287
|
+
} else if (down && !up && !left && !lit) {
|
|
288
|
+
context.fillStyle = CATCH_LIGHT;
|
|
289
|
+
context.fillRect(px + 1, py + 1, 2, 2);
|
|
290
|
+
}
|
|
291
|
+
} else if (key === "m" || key === "t") {
|
|
292
|
+
const left = at(x - 1, y) === key || at(x - 1, y) === "m" || at(x - 1, y) === "t";
|
|
293
|
+
const right = at(x + 1, y) === key || at(x + 1, y) === "m" || at(x + 1, y) === "t";
|
|
294
|
+
const above = at(x, y - 1) === "m" || at(x, y - 1) === "t";
|
|
295
|
+
const below = at(x, y + 1) === "m" || at(x, y + 1) === "t";
|
|
296
|
+
const top = above ? 0 : 1;
|
|
297
|
+
context.fillRect(px + (left ? 0 : 1), py + top, D - (left ? 0 : 1) - (right ? 0 : 1), (below ? D : 3) - top);
|
|
298
|
+
} else if (key === "p") {
|
|
299
|
+
context.fillRect(px, py + 1, D, 2);
|
|
300
|
+
} else {
|
|
301
|
+
context.fillRect(px, py, D, D);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function paintEyesSmooth(context, skin, expression, offset, openness, from = {
|
|
307
|
+
x: 0,
|
|
308
|
+
y: 0,
|
|
309
|
+
w: BODY_WIDTH,
|
|
310
|
+
h: BODY_HEIGHT
|
|
311
|
+
}) {
|
|
312
|
+
const D = SKIN_DETAIL;
|
|
313
|
+
const stamp = faceStamp(skin.face, expression);
|
|
314
|
+
const cellAt = (dx, dy) => dy === 0 || dy === 1 ? stamp[dy]?.[dx] : undefined;
|
|
315
|
+
const lightAt = (dx, dy) => isCatchLight(cellAt(dx, dy), [
|
|
316
|
+
cellAt(dx, dy - 1),
|
|
317
|
+
cellAt(dx, dy + 1),
|
|
318
|
+
cellAt(dx - 1, dy),
|
|
319
|
+
cellAt(dx + 1, dy)
|
|
320
|
+
]);
|
|
321
|
+
const eyes = new Set;
|
|
322
|
+
const lights = [];
|
|
323
|
+
const others = [];
|
|
324
|
+
let bottom = Number.NEGATIVE_INFINITY;
|
|
325
|
+
for (const dy of [0, 1]) {
|
|
326
|
+
const row = stamp[dy] ?? "";
|
|
327
|
+
for (let dx = 0;dx < row.length; dx++) {
|
|
328
|
+
const key = row[dx] ?? ".";
|
|
329
|
+
if (key === "e" || lightAt(dx, dy)) {
|
|
330
|
+
eyes.add(`${dx},${dy}`);
|
|
331
|
+
if (key !== "e")
|
|
332
|
+
lights.push([dx, dy]);
|
|
333
|
+
bottom = Math.max(bottom, dy);
|
|
334
|
+
} else if (FACE_PALETTE[key]) {
|
|
335
|
+
others.push([dx, dy, key]);
|
|
336
|
+
bottom = Math.max(bottom, dy);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (eyes.size === 0 && others.length === 0)
|
|
341
|
+
return;
|
|
342
|
+
const has = (dx, dy) => eyes.has(`${dx},${dy}`);
|
|
343
|
+
const pivotY = (FACE_ROW + bottom + 1 - from.y) * D;
|
|
344
|
+
const open = Math.min(1, Math.max(0.06, openness));
|
|
345
|
+
context.save();
|
|
346
|
+
context.translate(offset.x * D, offset.y * D);
|
|
347
|
+
context.translate(0, pivotY);
|
|
348
|
+
context.scale(1, open);
|
|
349
|
+
context.translate(0, -pivotY);
|
|
350
|
+
const cellX = (dx) => (FACE_COLUMN + dx - from.x) * D;
|
|
351
|
+
const cellY = (dy) => (FACE_ROW + dy - from.y) * D;
|
|
352
|
+
for (const [dx, dy, key] of others) {
|
|
353
|
+
context.fillStyle = FACE_PALETTE[key] ?? "#000";
|
|
354
|
+
context.fillRect(cellX(dx), cellY(dy), D, D);
|
|
355
|
+
}
|
|
356
|
+
for (const key of eyes) {
|
|
357
|
+
const [dx, dy] = key.split(",").map(Number);
|
|
358
|
+
const px = cellX(dx);
|
|
359
|
+
const py = cellY(dy);
|
|
360
|
+
const up = has(dx, dy - 1);
|
|
361
|
+
const down = has(dx, dy + 1);
|
|
362
|
+
const left = has(dx - 1, dy);
|
|
363
|
+
const right = has(dx + 1, dy);
|
|
364
|
+
context.fillStyle = FACE_PALETTE.e ?? "#161923";
|
|
365
|
+
context.beginPath();
|
|
366
|
+
const r = Math.max(1, D / 2.4);
|
|
367
|
+
const x0 = px - (left ? 0.5 : 0);
|
|
368
|
+
const y0 = py - (up ? 0.5 : 0);
|
|
369
|
+
const x1 = px + D + (right ? 0.5 : 0);
|
|
370
|
+
const y1 = py + D + (down ? 0.5 : 0);
|
|
371
|
+
context.moveTo(x0 + (!up && !left ? r : 0), y0);
|
|
372
|
+
context.lineTo(x1 - (!up && !right ? r : 0), y0);
|
|
373
|
+
if (!up && !right)
|
|
374
|
+
context.arcTo(x1, y0, x1, y0 + r, r);
|
|
375
|
+
else
|
|
376
|
+
context.lineTo(x1, y0);
|
|
377
|
+
context.lineTo(x1, y1 - (!down && !right ? r : 0));
|
|
378
|
+
if (!down && !right)
|
|
379
|
+
context.arcTo(x1, y1, x1 - r, y1, r);
|
|
380
|
+
else
|
|
381
|
+
context.lineTo(x1, y1);
|
|
382
|
+
context.lineTo(x0 + (!down && !left ? r : 0), y1);
|
|
383
|
+
if (!down && !left)
|
|
384
|
+
context.arcTo(x0, y1, x0, y1 - r, r);
|
|
385
|
+
else
|
|
386
|
+
context.lineTo(x0, y1);
|
|
387
|
+
context.lineTo(x0, y0 + (!up && !left ? r : 0));
|
|
388
|
+
if (!up && !left)
|
|
389
|
+
context.arcTo(x0, y0, x0 + r, y0, r);
|
|
390
|
+
else
|
|
391
|
+
context.lineTo(x0, y0);
|
|
392
|
+
context.closePath();
|
|
393
|
+
context.fill();
|
|
394
|
+
if (lights.length === 0 && down && !up && !left) {
|
|
395
|
+
context.fillStyle = "rgba(232, 238, 252, 0.95)";
|
|
396
|
+
context.fillRect(px + 1, py + 1, 2, 2);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
context.fillStyle = "rgba(232, 238, 252, 0.95)";
|
|
400
|
+
for (const [dx, dy] of lights)
|
|
401
|
+
context.fillRect(cellX(dx) + 0.75, cellY(dy) + 0.75, D - 1.5, D - 1.5);
|
|
402
|
+
context.restore();
|
|
403
|
+
}
|
|
404
|
+
var BODY_SHAPES = {
|
|
405
|
+
plup: { x: 1, y: 1 },
|
|
406
|
+
tall: { x: 0.88, y: 1.25 },
|
|
407
|
+
wide: { x: 1.2, y: 0.85 },
|
|
408
|
+
mini: { x: 0.82, y: 0.82 },
|
|
409
|
+
bean: { x: 0.72, y: 1.35 }
|
|
410
|
+
};
|
|
411
|
+
function tintForName(name) {
|
|
412
|
+
return BUDDY_TINTS[[...name].reduce((h, c) => h * 31 + c.charCodeAt(0) >>> 0, 7) % BUDDY_TINTS.length];
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export { BODY_WIDTH, BODY_HEIGHT, FACE_COLUMN, FACE_ROW, FACE_TYPES, EXPRESSIONS, isNamedExpression, SKIN_PALETTE, PAINT_KEYS, FACE_PALETTE, FACES, faceStamp, bodyPalette, composeSkin, blankBody, BUDDY_TINTS, DEFAULT_BUDDY_SKIN, sanitizeSkin, randomSkin, SKIN_DETAIL, faceKeys, paintSkinDetailed, paintEyesSmooth, BODY_SHAPES, tintForName };
|