@plupin/character 0.2.0 → 0.4.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 +70 -0
- package/dist/blob.js +46 -0
- package/dist/body-presets.d.ts +153 -0
- package/dist/canvas.js +27 -8
- package/dist/chunk-7ry0n8cw.js +1209 -0
- package/dist/{chunk-k5gwaq6t.js → chunk-ew73g2v7.js} +36 -3
- package/dist/chunk-ewkkvpte.js +448 -0
- package/dist/chunk-kf7f1tdx.js +207 -0
- package/dist/chunk-nx2wbkfn.js +421 -0
- package/dist/chunk-rqenm9tn.js +487 -0
- package/dist/chunk-vy9w8as2.js +196 -0
- package/dist/clips.d.ts +40 -0
- package/dist/dress.d.ts +4 -0
- package/dist/emote.d.ts +5 -3
- 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 +9 -2
- package/dist/index.js +46 -10
- package/dist/listing.d.ts +1 -1
- package/dist/listing.js +52 -16
- package/dist/platform-body-data.d.ts +9 -0
- package/dist/platform-body.d.ts +91 -0
- package/dist/plup3d.d.ts +43 -44
- package/dist/png.d.ts +23 -5
- package/dist/pose.d.ts +7 -1
- package/dist/pose.js +1 -1
- package/dist/proportions.d.ts +31 -0
- package/dist/ragdoll.d.ts +51 -0
- package/dist/resolution.d.ts +21 -0
- package/dist/skin-map.d.ts +156 -0
- package/dist/skin-map.js +57 -0
- package/dist/skin-native.d.ts +73 -6
- package/dist/texture.d.ts +8 -0
- package/dist/three.d.ts +11 -1
- package/dist/three.js +2820 -205
- package/dist/wear3d.d.ts +118 -0
- package/dist/wearables.d.ts +307 -0
- package/dist/wearables.js +26 -0
- package/package.json +21 -1
- package/dist/chunk-ae7gp5cc.js +0 -101
- package/dist/chunk-wpbgtn0y.js +0 -179
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// src/wearables.ts
|
|
2
|
+
var WEARABLES = {
|
|
3
|
+
"wolf-cut": {
|
|
4
|
+
slot: "hair",
|
|
5
|
+
name: "Wolf Cut",
|
|
6
|
+
rarity: "epic",
|
|
7
|
+
sigmaPrice: 120,
|
|
8
|
+
volume: 0.09,
|
|
9
|
+
view: -0.35
|
|
10
|
+
},
|
|
11
|
+
"curtain-ikemen": {
|
|
12
|
+
slot: "hair",
|
|
13
|
+
name: "Curtain Flow",
|
|
14
|
+
rarity: "rare",
|
|
15
|
+
sigmaPrice: 85,
|
|
16
|
+
volume: 0.08,
|
|
17
|
+
view: -0.25
|
|
18
|
+
},
|
|
19
|
+
"messy-fluff": {
|
|
20
|
+
slot: "hair",
|
|
21
|
+
name: "Messy Fluff",
|
|
22
|
+
rarity: "rare",
|
|
23
|
+
sigmaPrice: 80,
|
|
24
|
+
volume: 0.1,
|
|
25
|
+
view: -0.3
|
|
26
|
+
},
|
|
27
|
+
"silky-layers": {
|
|
28
|
+
slot: "hair",
|
|
29
|
+
name: "Silky Layers",
|
|
30
|
+
rarity: "epic",
|
|
31
|
+
sigmaPrice: 130,
|
|
32
|
+
volume: 0.07,
|
|
33
|
+
view: -0.45
|
|
34
|
+
},
|
|
35
|
+
"ojou-curls": {
|
|
36
|
+
slot: "hair",
|
|
37
|
+
name: "Ribbon Curls",
|
|
38
|
+
rarity: "epic",
|
|
39
|
+
sigmaPrice: 125,
|
|
40
|
+
volume: 0.08,
|
|
41
|
+
view: -0.35
|
|
42
|
+
},
|
|
43
|
+
"side-braid": {
|
|
44
|
+
slot: "hair",
|
|
45
|
+
name: "Side Braid",
|
|
46
|
+
rarity: "rare",
|
|
47
|
+
sigmaPrice: 90,
|
|
48
|
+
volume: 0.07,
|
|
49
|
+
view: -0.4
|
|
50
|
+
},
|
|
51
|
+
"fluffy-bob": {
|
|
52
|
+
slot: "hair",
|
|
53
|
+
name: "Fluffy Bob",
|
|
54
|
+
rarity: "common",
|
|
55
|
+
sigmaPrice: 40,
|
|
56
|
+
volume: 0.07
|
|
57
|
+
},
|
|
58
|
+
"twin-tails": { slot: "hair", name: "Twin Tails", rarity: "rare", sigmaPrice: 70, volume: 0.06 },
|
|
59
|
+
"spiky-hero": { slot: "hair", name: "Spiky Hero", rarity: "rare", sigmaPrice: 65, volume: 0.12 },
|
|
60
|
+
afro: { slot: "hair", name: "Afro", rarity: "rare", sigmaPrice: 60, volume: 0.2 },
|
|
61
|
+
"swoosh-quiff": {
|
|
62
|
+
slot: "hair",
|
|
63
|
+
name: "Swoosh Quiff",
|
|
64
|
+
rarity: "common",
|
|
65
|
+
sigmaPrice: 35,
|
|
66
|
+
volume: 0.08
|
|
67
|
+
},
|
|
68
|
+
"long-waves": {
|
|
69
|
+
slot: "hair",
|
|
70
|
+
name: "Long Waves",
|
|
71
|
+
rarity: "epic",
|
|
72
|
+
sigmaPrice: 110,
|
|
73
|
+
volume: 0.06,
|
|
74
|
+
view: -0.8
|
|
75
|
+
},
|
|
76
|
+
ponytail: {
|
|
77
|
+
slot: "hair",
|
|
78
|
+
name: "Ponytail",
|
|
79
|
+
rarity: "common",
|
|
80
|
+
sigmaPrice: 45,
|
|
81
|
+
volume: 0.06,
|
|
82
|
+
view: -1.1
|
|
83
|
+
},
|
|
84
|
+
mohawk: {
|
|
85
|
+
slot: "hair",
|
|
86
|
+
name: "Mohawk",
|
|
87
|
+
rarity: "rare",
|
|
88
|
+
sigmaPrice: 55,
|
|
89
|
+
volume: 0.14,
|
|
90
|
+
view: -0.8
|
|
91
|
+
},
|
|
92
|
+
"space-buns": { slot: "hair", name: "Space Buns", rarity: "rare", sigmaPrice: 60, volume: 0.07 },
|
|
93
|
+
"hime-cut": {
|
|
94
|
+
slot: "hair",
|
|
95
|
+
name: "Hime Cut",
|
|
96
|
+
rarity: "epic",
|
|
97
|
+
sigmaPrice: 120,
|
|
98
|
+
volume: 0.07,
|
|
99
|
+
view: -0.5
|
|
100
|
+
},
|
|
101
|
+
"bunny-ears": { slot: "hat", name: "Bunny Ears", rarity: "rare", sigmaPrice: 60 },
|
|
102
|
+
"cat-ears": { slot: "hat", name: "Cat Ears", rarity: "common", sigmaPrice: 45 },
|
|
103
|
+
"top-hat": { slot: "hat", name: "Top Hat", rarity: "rare", sigmaPrice: 70 },
|
|
104
|
+
crown: { slot: "hat", name: "Crown", rarity: "epic", sigmaPrice: 150 },
|
|
105
|
+
"party-hat": { slot: "hat", name: "Party Hat", rarity: "common", sigmaPrice: 35 },
|
|
106
|
+
halo: { slot: "hat", name: "Halo", rarity: "epic", sigmaPrice: 120 },
|
|
107
|
+
bow: { slot: "hat", name: "Bow", rarity: "common", sigmaPrice: 30 },
|
|
108
|
+
"ribbon-dress": {
|
|
109
|
+
slot: "accessory",
|
|
110
|
+
name: "Ribbon Dress",
|
|
111
|
+
rarity: "epic",
|
|
112
|
+
sigmaPrice: 135,
|
|
113
|
+
view: -0.35
|
|
114
|
+
},
|
|
115
|
+
"crop-hoodie": {
|
|
116
|
+
slot: "accessory",
|
|
117
|
+
name: "Cropped Hoodie",
|
|
118
|
+
rarity: "rare",
|
|
119
|
+
sigmaPrice: 85,
|
|
120
|
+
view: -0.3
|
|
121
|
+
},
|
|
122
|
+
"idol-set": {
|
|
123
|
+
slot: "accessory",
|
|
124
|
+
name: "Star Idol",
|
|
125
|
+
rarity: "epic",
|
|
126
|
+
sigmaPrice: 145,
|
|
127
|
+
view: -0.3
|
|
128
|
+
},
|
|
129
|
+
"street-jacket": {
|
|
130
|
+
slot: "accessory",
|
|
131
|
+
name: "Street Jacket",
|
|
132
|
+
rarity: "epic",
|
|
133
|
+
sigmaPrice: 130,
|
|
134
|
+
view: -0.35
|
|
135
|
+
},
|
|
136
|
+
"blazer-coat": {
|
|
137
|
+
slot: "accessory",
|
|
138
|
+
name: "Academy Blazer",
|
|
139
|
+
rarity: "rare",
|
|
140
|
+
sigmaPrice: 95,
|
|
141
|
+
view: -0.3
|
|
142
|
+
},
|
|
143
|
+
"brawler-vest": {
|
|
144
|
+
slot: "accessory",
|
|
145
|
+
name: "Brawler Tank",
|
|
146
|
+
rarity: "rare",
|
|
147
|
+
sigmaPrice: 75,
|
|
148
|
+
view: -0.3
|
|
149
|
+
},
|
|
150
|
+
"martial-gi": {
|
|
151
|
+
slot: "accessory",
|
|
152
|
+
name: "Fighter Gi",
|
|
153
|
+
rarity: "rare",
|
|
154
|
+
sigmaPrice: 90,
|
|
155
|
+
view: -0.35
|
|
156
|
+
},
|
|
157
|
+
"chibi-overalls": {
|
|
158
|
+
slot: "accessory",
|
|
159
|
+
name: "Chibi Overalls",
|
|
160
|
+
rarity: "rare",
|
|
161
|
+
sigmaPrice: 70,
|
|
162
|
+
view: -0.25
|
|
163
|
+
},
|
|
164
|
+
"pleated-skirt": { slot: "accessory", name: "Pleated Skirt", rarity: "common", sigmaPrice: 50 },
|
|
165
|
+
tuxedo: { slot: "accessory", name: "Tuxedo", rarity: "epic", sigmaPrice: 140 },
|
|
166
|
+
"hero-cape": { slot: "accessory", name: "Hero Cape", rarity: "rare", sigmaPrice: 90, view: 2.6 },
|
|
167
|
+
scarf: { slot: "accessory", name: "Scarf", rarity: "common", sigmaPrice: 40 },
|
|
168
|
+
sunglasses: { slot: "accessory", name: "Sunglasses", rarity: "rare", sigmaPrice: 65 }
|
|
169
|
+
};
|
|
170
|
+
var WEAR_KEYS = Object.keys(WEARABLES);
|
|
171
|
+
var PREFIX = "wear-";
|
|
172
|
+
var entry = (key) => WEARABLES[key];
|
|
173
|
+
var isWearKey = (value) => typeof value === "string" && Object.hasOwn(WEARABLES, value);
|
|
174
|
+
var isHairKey = (key) => entry(key).slot === "hair";
|
|
175
|
+
var hairVolume = (key) => entry(key).volume ?? 0;
|
|
176
|
+
var wearSlotOf = (key) => entry(key).slot;
|
|
177
|
+
function wearKeyOf(itemId) {
|
|
178
|
+
if (!itemId?.startsWith(PREFIX))
|
|
179
|
+
return null;
|
|
180
|
+
const key = itemId.slice(PREFIX.length);
|
|
181
|
+
return isWearKey(key) ? key : null;
|
|
182
|
+
}
|
|
183
|
+
var wearItemId = (key) => `${PREFIX}${key}`;
|
|
184
|
+
function wearKeysOf(itemIds) {
|
|
185
|
+
const keys = new Set;
|
|
186
|
+
for (const id of itemIds) {
|
|
187
|
+
const key = wearKeyOf(id);
|
|
188
|
+
if (key)
|
|
189
|
+
keys.add(key);
|
|
190
|
+
}
|
|
191
|
+
return WEAR_KEYS.filter((key) => keys.has(key));
|
|
192
|
+
}
|
|
193
|
+
function wearableItems() {
|
|
194
|
+
return WEAR_KEYS.map((key) => ({
|
|
195
|
+
id: wearItemId(key),
|
|
196
|
+
slot: entry(key).slot,
|
|
197
|
+
name: entry(key).name,
|
|
198
|
+
rarity: entry(key).rarity,
|
|
199
|
+
sigmaPrice: entry(key).sigmaPrice,
|
|
200
|
+
assetConfig: { wear: key }
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
function wearView(key) {
|
|
204
|
+
return key ? entry(key).view ?? -0.3 : -0.3;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export { WEARABLES, WEAR_KEYS, isWearKey, isHairKey, hairVolume, wearSlotOf, wearKeyOf, wearItemId, wearKeysOf, wearableItems, wearView };
|
|
@@ -0,0 +1,421 @@
|
|
|
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", "ikemen"];
|
|
12
|
+
var isHighResFace = (faceType) => faceType === "anime" || faceType === "ikemen";
|
|
13
|
+
var EXPRESSIONS = [
|
|
14
|
+
"idle",
|
|
15
|
+
"blink",
|
|
16
|
+
"happy",
|
|
17
|
+
"surprised",
|
|
18
|
+
"sad",
|
|
19
|
+
"wee",
|
|
20
|
+
...Object.keys(NAMED_FACE_STAMPS)
|
|
21
|
+
];
|
|
22
|
+
function isNamedExpression(expression) {
|
|
23
|
+
return Object.hasOwn(NAMED_FACE_STAMPS, expression);
|
|
24
|
+
}
|
|
25
|
+
var SKIN_PALETTE = {
|
|
26
|
+
B: "#2f6fed",
|
|
27
|
+
L: "#6a96ff",
|
|
28
|
+
D: "#1f4fc0",
|
|
29
|
+
l: "#a9c4ff",
|
|
30
|
+
k: "#161923",
|
|
31
|
+
w: "#ffffff",
|
|
32
|
+
a: "#8b93a8",
|
|
33
|
+
r: "#e2574c",
|
|
34
|
+
o: "#e6a23c",
|
|
35
|
+
y: "#f2d24b",
|
|
36
|
+
g: "#3fae74",
|
|
37
|
+
c: "#4cc9e2",
|
|
38
|
+
v: "#8a5ad8",
|
|
39
|
+
p: "#f08aa8",
|
|
40
|
+
n: "#8a5a3c",
|
|
41
|
+
s: "#f0b184"
|
|
42
|
+
};
|
|
43
|
+
var PAINT_KEYS = Object.keys(SKIN_PALETTE);
|
|
44
|
+
var FACE_PALETTE = FACE_STAMP_PALETTE;
|
|
45
|
+
var SHARED_EYES = {
|
|
46
|
+
blink: ["........", ".ee..ee."],
|
|
47
|
+
happy: ["........", ".ee..ee."],
|
|
48
|
+
wide: [".ee..ee.", ".ee..ee."],
|
|
49
|
+
sad: ["........", ".ee..ee."]
|
|
50
|
+
};
|
|
51
|
+
var SHARED_MOUTHS = {
|
|
52
|
+
open: ["...mm...", "...tt..."],
|
|
53
|
+
o: ["...mm...", "...mm..."],
|
|
54
|
+
frown: ["...mm...", "..m..m.."]
|
|
55
|
+
};
|
|
56
|
+
var FACES = {
|
|
57
|
+
dot: {
|
|
58
|
+
eyes: { ...SHARED_EYES, open: [".ee..ee.", ".ee..ee."], blink: ["........", ".ee..ee."] },
|
|
59
|
+
mouth: { ...SHARED_MOUTHS, idle: ["...mm...", "........"] },
|
|
60
|
+
blush: true
|
|
61
|
+
},
|
|
62
|
+
sparkle: {
|
|
63
|
+
eyes: { ...SHARED_EYES, open: [".we..we.", ".ee..ee."] },
|
|
64
|
+
mouth: { ...SHARED_MOUTHS, idle: ["..m..m..", "...mm..."] },
|
|
65
|
+
blush: true
|
|
66
|
+
},
|
|
67
|
+
sleepy: {
|
|
68
|
+
eyes: { ...SHARED_EYES, open: ["........", ".ee..ee."], blink: ["........", ".ee..ee."] },
|
|
69
|
+
mouth: { ...SHARED_MOUTHS, idle: ["...m....", "........"] },
|
|
70
|
+
blush: true
|
|
71
|
+
},
|
|
72
|
+
derp: {
|
|
73
|
+
eyes: { ...SHARED_EYES, open: [".ee.....", ".ee..e.."] },
|
|
74
|
+
mouth: { ...SHARED_MOUTHS, idle: ["..mmmm..", "....t..."] },
|
|
75
|
+
blush: false
|
|
76
|
+
},
|
|
77
|
+
anime: {
|
|
78
|
+
eyes: { ...SHARED_EYES, open: [".we..we.", ".ee..ee."] },
|
|
79
|
+
mouth: { ...SHARED_MOUTHS, idle: ["..m..m..", "...mm..."] },
|
|
80
|
+
blush: true
|
|
81
|
+
},
|
|
82
|
+
ikemen: {
|
|
83
|
+
eyes: { ...SHARED_EYES, open: [".we..we.", ".ee..ee."] },
|
|
84
|
+
mouth: { ...SHARED_MOUTHS, idle: ["...mm...", "........"] },
|
|
85
|
+
blush: false
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var EXPRESSION_PARTS = {
|
|
89
|
+
idle: { eyes: "open", mouth: "idle" },
|
|
90
|
+
blink: { eyes: "blink", mouth: "idle" },
|
|
91
|
+
happy: { eyes: "happy", mouth: "open" },
|
|
92
|
+
surprised: { eyes: "wide", mouth: "o" },
|
|
93
|
+
sad: { eyes: "sad", mouth: "frown" },
|
|
94
|
+
wee: { eyes: "happy", mouth: "o" }
|
|
95
|
+
};
|
|
96
|
+
function faceStamp(face, expression) {
|
|
97
|
+
if (isNamedExpression(expression))
|
|
98
|
+
return [...NAMED_FACE_STAMPS[expression]];
|
|
99
|
+
const definition = FACES[face] ?? FACES.dot;
|
|
100
|
+
const parts = EXPRESSION_PARTS[expression];
|
|
101
|
+
const [eyeTop, eyeBottom] = definition.eyes[parts.eyes];
|
|
102
|
+
const [mouthTop, mouthBottom] = definition.mouth[parts.mouth];
|
|
103
|
+
const blushRow = definition.blush ? "p......p" : "........";
|
|
104
|
+
const merged = Array.from(mouthTop, (pixel, i) => pixel === "." ? blushRow[i] ?? "." : pixel).join("");
|
|
105
|
+
return [eyeTop, eyeBottom, merged, mouthBottom];
|
|
106
|
+
}
|
|
107
|
+
function bodyPalette(outfitColor) {
|
|
108
|
+
if (!outfitColor || !/^#[0-9a-f]{6}$/i.test(outfitColor))
|
|
109
|
+
return { ...SKIN_PALETTE };
|
|
110
|
+
const channel = (offset) => Number.parseInt(outfitColor.slice(offset, offset + 2), 16);
|
|
111
|
+
const rgb = [channel(1), channel(3), channel(5)];
|
|
112
|
+
const toHex = (values) => `#${values.map((v) => Math.max(0, Math.min(255, Math.round(v))).toString(16).padStart(2, "0")).join("")}`;
|
|
113
|
+
return {
|
|
114
|
+
...SKIN_PALETTE,
|
|
115
|
+
B: toHex(rgb),
|
|
116
|
+
L: toHex(rgb.map((v) => v + (255 - v) * 0.32)),
|
|
117
|
+
D: toHex(rgb.map((v) => v * 0.7))
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function composeSkin(skin, expression, outfitColor, look = 0, lookY = 0, drawFace = true, faceScale = 1) {
|
|
121
|
+
const palette = bodyPalette(outfitColor);
|
|
122
|
+
const fallback = palette.B ?? "#2f6fed";
|
|
123
|
+
const pixels = Array.from({ length: BODY_HEIGHT }, (_, y) => Array.from({ length: BODY_WIDTH }, (_2, x) => palette[skin.body[y]?.[x] ?? ""] ?? fallback));
|
|
124
|
+
if (!drawFace)
|
|
125
|
+
return pixels;
|
|
126
|
+
const stamp = faceStamp(skin.face, expression);
|
|
127
|
+
const scale = Math.max(1, Math.floor(faceScale));
|
|
128
|
+
const originX = FACE_COLUMN + 4 - 4 * scale;
|
|
129
|
+
const originY = FACE_ROW + 2 - 2 * scale;
|
|
130
|
+
for (const dy of [2, 3, 0, 1]) {
|
|
131
|
+
const row = stamp[dy] ?? "";
|
|
132
|
+
const eyes = dy < 2;
|
|
133
|
+
const shift = eyes ? look : 0;
|
|
134
|
+
const rise = eyes ? Math.min(lookY, 0) : 0;
|
|
135
|
+
for (let dx = 0;dx < row.length; dx++) {
|
|
136
|
+
const color = FACE_PALETTE[row[dx] ?? "."];
|
|
137
|
+
if (!color)
|
|
138
|
+
continue;
|
|
139
|
+
for (let sy = 0;sy < scale; sy++) {
|
|
140
|
+
const target = pixels[originY + (dy + rise) * scale + sy];
|
|
141
|
+
if (!target)
|
|
142
|
+
continue;
|
|
143
|
+
for (let sx = 0;sx < scale; sx++) {
|
|
144
|
+
target[(originX + (dx + shift) * scale + sx + BODY_WIDTH) % BODY_WIDTH] = color;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return pixels;
|
|
150
|
+
}
|
|
151
|
+
function blankBody(key = "B") {
|
|
152
|
+
return Array.from({ length: BODY_HEIGHT }, () => key.repeat(BODY_WIDTH));
|
|
153
|
+
}
|
|
154
|
+
function defaultBody() {
|
|
155
|
+
const rows = blankBody("B");
|
|
156
|
+
const paint = (x, y, key) => {
|
|
157
|
+
const row = rows[y];
|
|
158
|
+
if (row)
|
|
159
|
+
rows[y] = row.slice(0, x) + key + row.slice(x + 1);
|
|
160
|
+
};
|
|
161
|
+
for (let x = 0;x < BODY_WIDTH; x++) {
|
|
162
|
+
for (const y of [0, 1, 2, 3])
|
|
163
|
+
paint(x, y, "L");
|
|
164
|
+
for (let y = 19;y < BODY_HEIGHT; y++)
|
|
165
|
+
paint(x, y, "D");
|
|
166
|
+
const fromFront = Math.abs(x - 24);
|
|
167
|
+
for (let y = 14;y < 20; y++) {
|
|
168
|
+
if (fromFront * fromFront + (y - 17) * (y - 17) * 4 < 90)
|
|
169
|
+
paint(x, y, "l");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
for (const [x, y] of [
|
|
173
|
+
[15, 6],
|
|
174
|
+
[16, 6],
|
|
175
|
+
[14, 7]
|
|
176
|
+
])
|
|
177
|
+
paint(x, y, "l");
|
|
178
|
+
return rows;
|
|
179
|
+
}
|
|
180
|
+
var BUDDY_TINTS = ["#2f6fed", "#e2574c", "#3fae74", "#e6a23c", "#8a5ad8"];
|
|
181
|
+
var DEFAULT_BUDDY_SKIN = { face: "sparkle", body: defaultBody() };
|
|
182
|
+
function sanitizeSkin(value) {
|
|
183
|
+
const candidate = value;
|
|
184
|
+
const face = FACE_TYPES.includes(candidate?.face) ? candidate?.face : DEFAULT_BUDDY_SKIN.face;
|
|
185
|
+
const rows = Array.isArray(candidate?.body) ? candidate.body : [];
|
|
186
|
+
const body = Array.from({ length: BODY_HEIGHT }, (_, y) => {
|
|
187
|
+
const row = typeof rows[y] === "string" ? rows[y] : "";
|
|
188
|
+
return Array.from({ length: BODY_WIDTH }, (_2, x) => {
|
|
189
|
+
const key = row[x] ?? "";
|
|
190
|
+
return key in SKIN_PALETTE ? key : DEFAULT_BUDDY_SKIN.body[y]?.[x] ?? "B";
|
|
191
|
+
}).join("");
|
|
192
|
+
});
|
|
193
|
+
return { body, face };
|
|
194
|
+
}
|
|
195
|
+
var pick = (list) => list[Math.floor(Math.random() * list.length)];
|
|
196
|
+
function randomSkin() {
|
|
197
|
+
const tint = pick(BUDDY_TINTS);
|
|
198
|
+
const accent = pick(["w", "y", "p", "c", "k", "o"]);
|
|
199
|
+
const pattern = pick(["none", "belly", "stripes", "spots"]);
|
|
200
|
+
const body = DEFAULT_BUDDY_SKIN.body.map((row, y) => Array.from(row, (key, x) => {
|
|
201
|
+
if (pattern === "belly" && y >= 13 && y < 18 && x >= 18 && x < 30)
|
|
202
|
+
return accent;
|
|
203
|
+
if (pattern === "stripes" && y >= 6 && y < 18 && y % 4 === 0)
|
|
204
|
+
return accent;
|
|
205
|
+
if (pattern === "spots" && y >= 4 && y < 17 && (x * 7 + y * 13) % 23 === 0)
|
|
206
|
+
return accent;
|
|
207
|
+
return key;
|
|
208
|
+
}).join(""));
|
|
209
|
+
return {
|
|
210
|
+
skin: {
|
|
211
|
+
face: pick(FACE_TYPES),
|
|
212
|
+
body: body.slice(0, BODY_HEIGHT).map((r) => r.slice(0, BODY_WIDTH))
|
|
213
|
+
},
|
|
214
|
+
tint
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
var SKIN_DETAIL = 4;
|
|
218
|
+
function faceKeys(skin, expression, look = 0, lookY = 0, withEyes = true) {
|
|
219
|
+
const keys = new Map;
|
|
220
|
+
const stamp = faceStamp(skin.face, expression);
|
|
221
|
+
const originX = FACE_COLUMN;
|
|
222
|
+
const originY = FACE_ROW;
|
|
223
|
+
for (const dy of [2, 3, 0, 1]) {
|
|
224
|
+
const row = stamp[dy] ?? "";
|
|
225
|
+
const eyes = dy < 2;
|
|
226
|
+
if (eyes && !withEyes)
|
|
227
|
+
continue;
|
|
228
|
+
const shift = eyes ? look : 0;
|
|
229
|
+
const rise = eyes ? Math.min(lookY, 0) : 0;
|
|
230
|
+
for (let dx = 0;dx < row.length; dx++) {
|
|
231
|
+
const key = row[dx] ?? ".";
|
|
232
|
+
if (!FACE_PALETTE[key])
|
|
233
|
+
continue;
|
|
234
|
+
const x = (originX + dx + shift + BODY_WIDTH) % BODY_WIDTH;
|
|
235
|
+
keys.set(`${x},${originY + dy + rise}`, key);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return keys;
|
|
239
|
+
}
|
|
240
|
+
var CATCH_LIGHT = "#e8eefc";
|
|
241
|
+
function isCatchLight(key, neighbours) {
|
|
242
|
+
return key === "w" && neighbours.includes("e");
|
|
243
|
+
}
|
|
244
|
+
function paintSkinDetailed(context, pixels, body, keys, from = {
|
|
245
|
+
x: 0,
|
|
246
|
+
y: 0,
|
|
247
|
+
w: BODY_WIDTH,
|
|
248
|
+
h: BODY_HEIGHT
|
|
249
|
+
}, soften = (fill) => fill) {
|
|
250
|
+
const D = SKIN_DETAIL;
|
|
251
|
+
const at = (x, y) => keys.get(`${(x + BODY_WIDTH) % BODY_WIDTH},${y}`);
|
|
252
|
+
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)]);
|
|
253
|
+
let lit = false;
|
|
254
|
+
for (const key of keys.keys()) {
|
|
255
|
+
const [x, y] = key.split(",").map(Number);
|
|
256
|
+
if (isLight(x, y))
|
|
257
|
+
lit = true;
|
|
258
|
+
}
|
|
259
|
+
const isEye = (x, y) => at(x, y) === "e" || isLight(x, y);
|
|
260
|
+
for (let j = 0;j < from.h; j++) {
|
|
261
|
+
for (let i = 0;i < from.w; i++) {
|
|
262
|
+
const x = (from.x + i + BODY_WIDTH) % BODY_WIDTH;
|
|
263
|
+
const y = from.y + j;
|
|
264
|
+
const key = keys.get(`${x},${y}`);
|
|
265
|
+
const under = body[y]?.[x] ?? "transparent";
|
|
266
|
+
context.fillStyle = soften(key ? under : pixels[y]?.[x] ?? "transparent");
|
|
267
|
+
context.fillRect(i * D, j * D, D, D);
|
|
268
|
+
if (!key)
|
|
269
|
+
continue;
|
|
270
|
+
const px = i * D;
|
|
271
|
+
const py = j * D;
|
|
272
|
+
const color = FACE_PALETTE[key] ?? "#000";
|
|
273
|
+
context.fillStyle = color;
|
|
274
|
+
if (key === "e" || isLight(x, y)) {
|
|
275
|
+
const up = isEye(x, y - 1);
|
|
276
|
+
const down = isEye(x, y + 1);
|
|
277
|
+
const left = isEye(x - 1, y);
|
|
278
|
+
const right = isEye(x + 1, y);
|
|
279
|
+
context.fillStyle = FACE_PALETTE.e ?? "#161923";
|
|
280
|
+
context.fillRect(px, py, D, D);
|
|
281
|
+
context.fillStyle = soften(under);
|
|
282
|
+
if (!up && !left)
|
|
283
|
+
context.fillRect(px, py, 1, 1);
|
|
284
|
+
if (!up && !right)
|
|
285
|
+
context.fillRect(px + D - 1, py, 1, 1);
|
|
286
|
+
if (!down && !left)
|
|
287
|
+
context.fillRect(px, py + D - 1, 1, 1);
|
|
288
|
+
if (!down && !right)
|
|
289
|
+
context.fillRect(px + D - 1, py + D - 1, 1, 1);
|
|
290
|
+
if (key !== "e") {
|
|
291
|
+
context.fillStyle = CATCH_LIGHT;
|
|
292
|
+
context.fillRect(px + 0.75, py + 0.75, D - 1.5, D - 1.5);
|
|
293
|
+
} else if (down && !up && !left && !lit) {
|
|
294
|
+
context.fillStyle = CATCH_LIGHT;
|
|
295
|
+
context.fillRect(px + 1, py + 1, 2, 2);
|
|
296
|
+
}
|
|
297
|
+
} else if (key === "m" || key === "t") {
|
|
298
|
+
const left = at(x - 1, y) === key || at(x - 1, y) === "m" || at(x - 1, y) === "t";
|
|
299
|
+
const right = at(x + 1, y) === key || at(x + 1, y) === "m" || at(x + 1, y) === "t";
|
|
300
|
+
const above = at(x, y - 1) === "m" || at(x, y - 1) === "t";
|
|
301
|
+
const below = at(x, y + 1) === "m" || at(x, y + 1) === "t";
|
|
302
|
+
const top = above ? 0 : 1;
|
|
303
|
+
context.fillRect(px + (left ? 0 : 1), py + top, D - (left ? 0 : 1) - (right ? 0 : 1), (below ? D : 3) - top);
|
|
304
|
+
} else if (key === "p") {
|
|
305
|
+
context.fillRect(px, py + 1, D, 2);
|
|
306
|
+
} else {
|
|
307
|
+
context.fillRect(px, py, D, D);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
function paintEyesSmooth(context, skin, expression, offset, openness, from = {
|
|
313
|
+
x: 0,
|
|
314
|
+
y: 0,
|
|
315
|
+
w: BODY_WIDTH,
|
|
316
|
+
h: BODY_HEIGHT
|
|
317
|
+
}) {
|
|
318
|
+
const D = SKIN_DETAIL;
|
|
319
|
+
const stamp = faceStamp(skin.face, expression);
|
|
320
|
+
const cellAt = (dx, dy) => dy === 0 || dy === 1 ? stamp[dy]?.[dx] : undefined;
|
|
321
|
+
const lightAt = (dx, dy) => isCatchLight(cellAt(dx, dy), [
|
|
322
|
+
cellAt(dx, dy - 1),
|
|
323
|
+
cellAt(dx, dy + 1),
|
|
324
|
+
cellAt(dx - 1, dy),
|
|
325
|
+
cellAt(dx + 1, dy)
|
|
326
|
+
]);
|
|
327
|
+
const eyes = new Set;
|
|
328
|
+
const lights = [];
|
|
329
|
+
const others = [];
|
|
330
|
+
let bottom = Number.NEGATIVE_INFINITY;
|
|
331
|
+
for (const dy of [0, 1]) {
|
|
332
|
+
const row = stamp[dy] ?? "";
|
|
333
|
+
for (let dx = 0;dx < row.length; dx++) {
|
|
334
|
+
const key = row[dx] ?? ".";
|
|
335
|
+
if (key === "e" || lightAt(dx, dy)) {
|
|
336
|
+
eyes.add(`${dx},${dy}`);
|
|
337
|
+
if (key !== "e")
|
|
338
|
+
lights.push([dx, dy]);
|
|
339
|
+
bottom = Math.max(bottom, dy);
|
|
340
|
+
} else if (FACE_PALETTE[key]) {
|
|
341
|
+
others.push([dx, dy, key]);
|
|
342
|
+
bottom = Math.max(bottom, dy);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (eyes.size === 0 && others.length === 0)
|
|
347
|
+
return;
|
|
348
|
+
const has = (dx, dy) => eyes.has(`${dx},${dy}`);
|
|
349
|
+
const pivotY = (FACE_ROW + bottom + 1 - from.y) * D;
|
|
350
|
+
const open = Math.min(1, Math.max(0.06, openness));
|
|
351
|
+
context.save();
|
|
352
|
+
context.translate(offset.x * D, offset.y * D);
|
|
353
|
+
context.translate(0, pivotY);
|
|
354
|
+
context.scale(1, open);
|
|
355
|
+
context.translate(0, -pivotY);
|
|
356
|
+
const cellX = (dx) => (FACE_COLUMN + dx - from.x) * D;
|
|
357
|
+
const cellY = (dy) => (FACE_ROW + dy - from.y) * D;
|
|
358
|
+
for (const [dx, dy, key] of others) {
|
|
359
|
+
context.fillStyle = FACE_PALETTE[key] ?? "#000";
|
|
360
|
+
context.fillRect(cellX(dx), cellY(dy), D, D);
|
|
361
|
+
}
|
|
362
|
+
for (const key of eyes) {
|
|
363
|
+
const [dx, dy] = key.split(",").map(Number);
|
|
364
|
+
const px = cellX(dx);
|
|
365
|
+
const py = cellY(dy);
|
|
366
|
+
const up = has(dx, dy - 1);
|
|
367
|
+
const down = has(dx, dy + 1);
|
|
368
|
+
const left = has(dx - 1, dy);
|
|
369
|
+
const right = has(dx + 1, dy);
|
|
370
|
+
context.fillStyle = FACE_PALETTE.e ?? "#161923";
|
|
371
|
+
context.beginPath();
|
|
372
|
+
const r = Math.max(1, D / 2.4);
|
|
373
|
+
const x0 = px - (left ? 0.5 : 0);
|
|
374
|
+
const y0 = py - (up ? 0.5 : 0);
|
|
375
|
+
const x1 = px + D + (right ? 0.5 : 0);
|
|
376
|
+
const y1 = py + D + (down ? 0.5 : 0);
|
|
377
|
+
context.moveTo(x0 + (!up && !left ? r : 0), y0);
|
|
378
|
+
context.lineTo(x1 - (!up && !right ? r : 0), y0);
|
|
379
|
+
if (!up && !right)
|
|
380
|
+
context.arcTo(x1, y0, x1, y0 + r, r);
|
|
381
|
+
else
|
|
382
|
+
context.lineTo(x1, y0);
|
|
383
|
+
context.lineTo(x1, y1 - (!down && !right ? r : 0));
|
|
384
|
+
if (!down && !right)
|
|
385
|
+
context.arcTo(x1, y1, x1 - r, y1, r);
|
|
386
|
+
else
|
|
387
|
+
context.lineTo(x1, y1);
|
|
388
|
+
context.lineTo(x0 + (!down && !left ? r : 0), y1);
|
|
389
|
+
if (!down && !left)
|
|
390
|
+
context.arcTo(x0, y1, x0, y1 - r, r);
|
|
391
|
+
else
|
|
392
|
+
context.lineTo(x0, y1);
|
|
393
|
+
context.lineTo(x0, y0 + (!up && !left ? r : 0));
|
|
394
|
+
if (!up && !left)
|
|
395
|
+
context.arcTo(x0, y0, x0 + r, y0, r);
|
|
396
|
+
else
|
|
397
|
+
context.lineTo(x0, y0);
|
|
398
|
+
context.closePath();
|
|
399
|
+
context.fill();
|
|
400
|
+
if (lights.length === 0 && down && !up && !left) {
|
|
401
|
+
context.fillStyle = "rgba(232, 238, 252, 0.95)";
|
|
402
|
+
context.fillRect(px + 1, py + 1, 2, 2);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
context.fillStyle = "rgba(232, 238, 252, 0.95)";
|
|
406
|
+
for (const [dx, dy] of lights)
|
|
407
|
+
context.fillRect(cellX(dx) + 0.75, cellY(dy) + 0.75, D - 1.5, D - 1.5);
|
|
408
|
+
context.restore();
|
|
409
|
+
}
|
|
410
|
+
var BODY_SHAPES = {
|
|
411
|
+
plup: { x: 1, y: 1 },
|
|
412
|
+
tall: { x: 0.88, y: 1.25 },
|
|
413
|
+
wide: { x: 1.2, y: 0.85 },
|
|
414
|
+
mini: { x: 0.82, y: 0.82 },
|
|
415
|
+
bean: { x: 0.72, y: 1.35 }
|
|
416
|
+
};
|
|
417
|
+
function tintForName(name) {
|
|
418
|
+
return BUDDY_TINTS[[...name].reduce((h, c) => h * 31 + c.charCodeAt(0) >>> 0, 7) % BUDDY_TINTS.length];
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
export { BODY_WIDTH, BODY_HEIGHT, FACE_COLUMN, FACE_ROW, FACE_TYPES, isHighResFace, 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 };
|