@7ots/cli 0.1.17 → 0.1.36
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/.env.example +14 -0
- package/README.md +11 -0
- package/brand/logos/base.svg +1 -0
- package/brand/logos/clawpump.png +0 -0
- package/brand/logos/conductors.svg +1 -0
- package/brand/logos/notlogin.svg +12 -0
- package/brand/logos/pumpfun.png +0 -0
- package/brand/logos/solana.png +0 -0
- package/brand/logos/spawnerbot.svg +1 -0
- package/brand/logos/virtuals.png +0 -0
- package/cli/7ots.mjs +61 -1
- package/cli/lib/account.mjs +23 -3
- package/cli/lib/assistant.mjs +92 -14
- package/cli/lib/brain.mjs +84 -11
- package/cli/lib/card-shot.mjs +1 -1
- package/cli/lib/config.mjs +14 -3
- package/cli/lib/desktop-sync.mjs +177 -0
- package/cli/lib/i18n.mjs +9 -0
- package/cli/lib/inferences.mjs +19 -2
- package/cli/lib/integrations.mjs +98 -13
- package/cli/lib/mcp.mjs +1 -1
- package/cli/lib/open.mjs +3 -1
- package/cli/lib/pet-server.mjs +352 -41
- package/cli/lib/prompts.mjs +1 -1
- package/cli/lib/screen.mjs +1 -1
- package/cli/lib/senses/gestures.mjs +121 -0
- package/cli/lib/senses/index.mjs +490 -0
- package/cli/lib/senses/rules.mjs +159 -0
- package/cli/lib/senses/sources/activity.mjs +95 -0
- package/cli/lib/senses/sources/calendar.mjs +75 -0
- package/cli/lib/senses/sources/index.mjs +17 -0
- package/cli/lib/senses/sources/mail.mjs +48 -0
- package/cli/lib/senses/sources/system.mjs +39 -0
- package/cli/lib/senses/util.mjs +41 -0
- package/cli/lib/senses/vendor.mjs +78 -0
- package/cli/lib/stt-local.py +16 -8
- package/cli/lib/stt.mjs +53 -6
- package/cli/lib/tooluse.mjs +56 -0
- package/cli/lib/tts-local.mjs +2 -2
- package/cli/lib/vm.mjs +2 -2
- package/cli/lib/wake-local.py +109 -0
- package/cli/lib/wake.mjs +102 -0
- package/cli/pet/electron/main.cjs +190 -8
- package/cli/pet/pet.html +153 -34
- package/cli/pet/senses.html +342 -0
- package/cli/pet/settings.html +815 -74
- package/dist/7ots.esm.js +373 -146
- package/dist/7ots.esm.js.map +4 -4
- package/dist/7ots.iife.js +373 -146
- package/dist/7ots.iife.js.map +4 -4
- package/llms.txt +27 -0
- package/package.json +5 -2
- package/server/channels/apuchat.mjs +18 -4
- package/server/errors.mjs +90 -0
- package/server/notify.mjs +78 -0
- package/server/server.mjs +84 -14
- package/server/settings.mjs +3 -0
- package/server/site.mjs +401 -0
- package/server/tts.mjs +29 -5
- package/src/avatar/AvatarStage.js +2 -2
- package/src/avatar/three.js +3 -2
- package/src/character/AvatarEditor.js +2 -1
- package/src/character/Character.js +38 -5
- package/src/character/TradingCard.js +2 -0
- package/src/character/beat.js +64 -2
- package/src/character/mods/orc.js +8 -1
- package/src/character/mods.js +104 -10
- package/src/character/motion.js +252 -1
- package/src/character/parts.js +40 -38
- package/src/character/styles.js +40 -38
- package/src/character3d/Character3D.js +26 -5
- package/src/character3d/body.js +14 -12
- package/src/character3d/export.js +693 -0
- package/src/character3d/fx.js +13 -0
- package/src/character3d/index.js +2 -0
- package/src/character3d/materials.js +106 -10
- package/src/character3d/room-themes.js +1184 -0
- package/src/character3d/room.js +487 -0
- package/src/character3d/stage.js +14 -2
- package/src/creator/StepCreator.js +316 -0
- package/src/i18n/index.js +3 -3
- package/src/i18n/messages/character.js +352 -4
- package/src/i18n/messages/creator.js +138 -0
- package/src/i18n/messages/identity.js +89 -1
- package/src/i18n/messages/platform.js +270 -4
- package/src/i18n/messages/server.js +443 -1
- package/src/i18n/messages/widget.js +233 -0
- package/src/identity/random.js +14 -2
- package/src/identity/schema.js +2 -1
- package/src/index.js +9 -2
- package/src/voice/tags.js +22 -0
- package/server/platform/apuchat.mjs +0 -266
- package/server/platform/auth.mjs +0 -319
- package/server/platform/connect.mjs +0 -387
- package/server/platform/crypto.mjs +0 -80
- package/server/platform/db.mjs +0 -275
- package/server/platform/device.mjs +0 -222
- package/server/platform/integrations.mjs +0 -169
- package/server/platform/look.mjs +0 -20
- package/server/platform/mods.mjs +0 -222
- package/server/platform/orquesta.mjs +0 -577
- package/server/platform/profile.mjs +0 -161
- package/server/platform/routes.mjs +0 -542
- package/server/platform/runtime.mjs +0 -242
- package/server/platform/sites.mjs +0 -146
- package/server/platform/store.mjs +0 -456
- package/server/platform/vm.mjs +0 -1057
package/src/character/beat.js
CHANGED
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
* hype electrónica de cuatro en el piso funk bajo sincopado y guitarra rítmica
|
|
8
8
|
* chip 8 bits (cuadradas y triangular) trap 808 largo, hats con redobles
|
|
9
9
|
* entrance público que ruge, dos golpes con pirotecnia y un riff de rock (entradas tipo lucha libre)
|
|
10
|
+
* phonk (farmeo de aura) cowbell 808 en menor, 808 saturado que se desliza, hats en tresillo, medio tiempo
|
|
11
|
+
* montagem (farmeo de aura) funk brasileño: tamborzão, cowbell distorsionado repitiendo el riff
|
|
10
12
|
*
|
|
11
13
|
* playBeat(style, { ms, volume }) → { stop(), done: Promise, analyser } (solo en el navegador).
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
import { DANCE_BPM } from './motion.js';
|
|
15
17
|
|
|
16
|
-
export const BEAT_STYLES = ['hype', 'funk', 'chip', 'trap', 'entrance'];
|
|
18
|
+
export const BEAT_STYLES = ['hype', 'funk', 'chip', 'trap', 'entrance', 'phonk', 'montagem'];
|
|
17
19
|
|
|
18
20
|
const hz = (m) => 440 * 2 ** ((m - 69) / 12);
|
|
19
21
|
let shared = null;
|
|
@@ -61,6 +63,19 @@ function filt(ctx, type, f, q, dest) {
|
|
|
61
63
|
b.connect(dest);
|
|
62
64
|
return b;
|
|
63
65
|
}
|
|
66
|
+
/** Saturación (tanh) que se reusa por contexto y cantidad. */
|
|
67
|
+
function drive(ctx, amt, dest) {
|
|
68
|
+
const key = `__drive${amt}`;
|
|
69
|
+
if (!ctx[key]) {
|
|
70
|
+
const c = new Float32Array(1024);
|
|
71
|
+
for (let i = 0; i < c.length; i++) c[i] = Math.tanh(((i / c.length) * 2 - 1) * amt);
|
|
72
|
+
ctx[key] = c;
|
|
73
|
+
}
|
|
74
|
+
const ws = ctx.createWaveShaper();
|
|
75
|
+
ws.curve = ctx[key];
|
|
76
|
+
ws.connect(dest);
|
|
77
|
+
return ws;
|
|
78
|
+
}
|
|
64
79
|
const I = {
|
|
65
80
|
kick(ctx, out, t, v = 1, low = 45) {
|
|
66
81
|
const g = env(ctx, out, t, 0.9 * v, 0.003, 0.32);
|
|
@@ -125,6 +140,18 @@ const I = {
|
|
|
125
140
|
o.frequency.linearRampToValueAtTime(o.frequency.value * 1.3, s + 0.3);
|
|
126
141
|
}
|
|
127
142
|
},
|
|
143
|
+
// el cowbell de la 808: dos cuadradas desafinadas (≈ 540 y 800 Hz en el original), aquí afinado a la nota
|
|
144
|
+
cowbell(ctx, out, t, m, dur, v = 1, dist = 0) {
|
|
145
|
+
const g = env(ctx, out, t, 0.16 * v, 0.002, dur);
|
|
146
|
+
const bp = filt(ctx, 'bandpass', hz(m) * 1.8, 1.4, dist ? drive(ctx, dist, g) : g);
|
|
147
|
+
for (const k of [1, 1.48]) osc(ctx, 'square', hz(m) * k, t, dur, bp);
|
|
148
|
+
},
|
|
149
|
+
// 808 largo y saturado, con glide desde otra nota
|
|
150
|
+
bass808(ctx, out, t, m, dur, v = 1, from = null) {
|
|
151
|
+
const g = env(ctx, out, t, 0.5 * v, 0.004, dur);
|
|
152
|
+
const o = osc(ctx, 'sine', hz(from ?? m), t, dur, drive(ctx, 3.5, filt(ctx, 'lowpass', 900, 0.7, g)));
|
|
153
|
+
if (from != null) o.frequency.exponentialRampToValueAtTime(hz(m), t + 0.14);
|
|
154
|
+
},
|
|
128
155
|
boom(ctx, out, t, v = 1) {
|
|
129
156
|
I.kick(ctx, out, t, 1.2 * v, 30);
|
|
130
157
|
noise(ctx, t, 1.4, filt(ctx, 'lowpass', 900, 0.5, env(ctx, out, t, 0.5 * v, 0.005, 1.3)));
|
|
@@ -184,6 +211,39 @@ const STYLES = {
|
|
|
184
211
|
if (i === 0 && bar % 2 === 0) I.chord(ctx, out, t, [r + 12, r + 15, r + 19], sd * 30, 0.7, 'triangle');
|
|
185
212
|
},
|
|
186
213
|
},
|
|
214
|
+
// farmeo de aura: phonk de drift en medio tiempo (caja en el 3), el riff de cowbell va cambiando por compás
|
|
215
|
+
phonk: {
|
|
216
|
+
roots: [49, 49, 45, 47], // do#, do#, la, si (menor)
|
|
217
|
+
riff: [
|
|
218
|
+
[12, null, 12, null, 15, null, 12, null, 19, null, 17, 15, null, 12, null, null],
|
|
219
|
+
[12, null, 12, null, 15, null, 12, null, 10, null, 12, null, 7, null, null, null],
|
|
220
|
+
],
|
|
221
|
+
step(ctx, out, t, i, bar, sd) {
|
|
222
|
+
const r = this.roots[bar % 4];
|
|
223
|
+
if (on('x......xx.x.....', i)) (I.kick(ctx, out, t, 1.1, 40), I.bass808(ctx, out, t, r - 24, sd * (i === 0 ? 6 : 3), 1, i === 10 ? r - 19 : null));
|
|
224
|
+
if (i === 8) (I.clap(ctx, out, t, 1.2), I.snare(ctx, out, t, 0.6));
|
|
225
|
+
// hats en tresillo de corchea, más fuertes a contratiempo
|
|
226
|
+
if (i % 4 === 0) for (let k = 0; k < 3; k++) I.hat(ctx, out, t + (k * sd * 4) / 3, k === 1 ? 0.55 : 0.3);
|
|
227
|
+
const n = this.riff[bar % 2][i];
|
|
228
|
+
if (n != null) I.cowbell(ctx, out, t, r + n, sd * 1.6, 1);
|
|
229
|
+
if (i === 0 && bar % 4 === 0) I.chord(ctx, out, t, [r + 12, r + 15, r + 19], sd * 60, 0.45, 'triangle'); // colchón oscuro
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
// farmeo de aura: montagem (funk brasileño), tamborzão y el cowbell distorsionado repitiendo el mismo riff
|
|
233
|
+
montagem: {
|
|
234
|
+
roots: [50, 50, 53, 48],
|
|
235
|
+
riff: [0, null, 0, 3, null, 0, null, 7, null, 5, 3, null, 0, null, 3, null],
|
|
236
|
+
step(ctx, out, t, i, bar, sd) {
|
|
237
|
+
const r = this.roots[bar % 4];
|
|
238
|
+
if (on('x..x..x...x..x..', i)) I.kick(ctx, out, t, 1.15, 42); // tamborzão
|
|
239
|
+
if (on('x.....x...x.....', i)) I.bass808(ctx, out, t, r - 24, sd * 2.5, 0.8);
|
|
240
|
+
if (i === 4 || i === 12) I.clap(ctx, out, t, 1.1);
|
|
241
|
+
if (on('..x...x...x.x..x', i)) I.snare(ctx, out, t, 0.35);
|
|
242
|
+
if (i % 2) I.hat(ctx, out, t, 0.3);
|
|
243
|
+
const n = this.riff[i];
|
|
244
|
+
if (n != null) I.cowbell(ctx, out, t, r + 24 + n, sd * 1.2, 1.1, 4);
|
|
245
|
+
},
|
|
246
|
+
},
|
|
187
247
|
entrance: {
|
|
188
248
|
intro: 2.2, // s de público y golpes antes del riff
|
|
189
249
|
start(ctx, out, t) {
|
|
@@ -207,7 +267,7 @@ const STYLES = {
|
|
|
207
267
|
* Toca un estilo durante `ms`. Devuelve { stop(), done, analyser } o null sin Web Audio.
|
|
208
268
|
* `volume` 0..1. El primer paso cae en el instante en que se llama (con el gesto de baile).
|
|
209
269
|
*/
|
|
210
|
-
export function playBeat(style, { ms = 6000, volume = 0.5, bpm = DANCE_BPM, ctx = null } = {}) {
|
|
270
|
+
export function playBeat(style, { ms = 6000, volume = 0.5, bpm = DANCE_BPM, ctx = null, out = null } = {}) {
|
|
211
271
|
const AC = globalThis.AudioContext || globalThis.webkitAudioContext;
|
|
212
272
|
if (!AC) return null;
|
|
213
273
|
ctx ||= shared ||= new AC();
|
|
@@ -220,6 +280,8 @@ export function playBeat(style, { ms = 6000, volume = 0.5, bpm = DANCE_BPM, ctx
|
|
|
220
280
|
const analyser = ctx.createAnalyser();
|
|
221
281
|
analyser.fftSize = 256;
|
|
222
282
|
master.connect(comp).connect(analyser).connect(ctx.destination);
|
|
283
|
+
// out: otro destino además de los parlantes (p. ej. un MediaStreamDestination para grabar un clip)
|
|
284
|
+
if (out) analyser.connect(out);
|
|
223
285
|
const sd = 60 / bpm / 4; // un paso = semicorchea
|
|
224
286
|
const t0 = ctx.currentTime + 0.05;
|
|
225
287
|
const end = t0 + ms / 1000;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Mod de ejemplo: orco (piel verde, cejas fruncidas, colmillos y orejas puntiagudas).
|
|
1
|
+
// Mod de ejemplo: orco (piel verde, cejas fruncidas, mandíbula ancha, frente baja, colmillos y orejas puntiagudas).
|
|
2
2
|
// Los glb salen de scripts/mod-glb.mjs (orc-tusks, orc-ears).
|
|
3
3
|
export default {
|
|
4
4
|
"id": "orc",
|
|
@@ -28,9 +28,15 @@ export default {
|
|
|
28
28
|
"type": "none"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
+
"face": {
|
|
32
|
+
"jaw": 0.45,
|
|
33
|
+
"forehead": -0.35,
|
|
34
|
+
"width": 0.1
|
|
35
|
+
},
|
|
31
36
|
"parts": [
|
|
32
37
|
{
|
|
33
38
|
"id": "tusks",
|
|
39
|
+
"slot": "face",
|
|
34
40
|
"anchor": "mouth",
|
|
35
41
|
"layer": "front",
|
|
36
42
|
"svg": "<path d=\"M8 3Q11 -5 16 -13Q18.5 -4 14 5Z\" fill=\"{color}\" stroke=\"{line}\" stroke-width=\"1.6\" stroke-linejoin=\"round\"/><path d=\"M12 0Q14 -6 16 -10\" stroke=\"#fff\" stroke-width=\"1.4\" stroke-linecap=\"round\" fill=\"none\" opacity=\".55\"/><g transform=\"scale(-1 1)\"><path d=\"M8 3Q11 -5 16 -13Q18.5 -4 14 5Z\" fill=\"{color}\" stroke=\"{line}\" stroke-width=\"1.6\" stroke-linejoin=\"round\"/><path d=\"M12 0Q14 -6 16 -10\" stroke=\"#fff\" stroke-width=\"1.4\" stroke-linecap=\"round\" fill=\"none\" opacity=\".55\"/></g>",
|
|
@@ -47,6 +53,7 @@ export default {
|
|
|
47
53
|
},
|
|
48
54
|
{
|
|
49
55
|
"id": "ears",
|
|
56
|
+
"slot": "none",
|
|
50
57
|
"anchor": "eyes",
|
|
51
58
|
"layer": "back",
|
|
52
59
|
"svg": "<path d=\"M42 -12L86 -28L48 12Z\" fill=\"{body}\" stroke=\"{line}\" stroke-width=\"2.5\" stroke-linejoin=\"round\"/><path d=\"M52 -7L76 -20L53 4Z\" fill=\"{bodyDark}\" opacity=\".75\"/><g transform=\"scale(-1 1)\"><path d=\"M42 -12L86 -28L48 12Z\" fill=\"{body}\" stroke=\"{line}\" stroke-width=\"2.5\" stroke-linejoin=\"round\"/><path d=\"M52 -7L76 -20L53 4Z\" fill=\"{bodyDark}\" opacity=\".75\"/></g>",
|
package/src/character/mods.js
CHANGED
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
* {
|
|
6
6
|
* id: 'orc', v: 1, name: { es: 'Orco', en: 'Orc' }, by: '7ots',
|
|
7
7
|
* character: { body: { color: '#7aa64a' }, brows: { type: 'angled' }, accessories: [{ id: 'horns' }] },
|
|
8
|
+
* face: { jaw: 0.5, forehead: -0.3 }, // rasgos relativos a la cara del ot (ver abajo)
|
|
9
|
+
* replaces: ['eyes'], // huecos que vacía aunque no traiga nada para ellos
|
|
8
10
|
* parts: [{
|
|
9
11
|
* id: 'tusks', anchor: 'mouth', layer: 'front',
|
|
12
|
+
* slot: 'face', // hueco que ocupa (ver abajo); sin él se deduce del ancla
|
|
10
13
|
* svg: '<path d="…" fill="{color}"/>', // 2D: coordenadas de un ot de 120 de ancho, origen en el ancla
|
|
11
14
|
* view: [-30, -20, 60, 30], // caja del dibujo (para el respaldo 3D en plano)
|
|
12
15
|
* glb: 'data:model/gltf-binary;base64,…' | 'https://…/tusks.glb', // 3D (opcional)
|
|
@@ -16,20 +19,47 @@
|
|
|
16
19
|
* }],
|
|
17
20
|
* }
|
|
18
21
|
*
|
|
22
|
+
* Huecos (MOD_SLOTS: los grupos de accesorios de parts.js más 'body'): head (sombreros, pelo,
|
|
23
|
+
* orejas…), eyes (gafas, antifaces), face (bigotes, barbas, narices, colmillos), neck, back, body
|
|
24
|
+
* (ropa sobre el cuerpo; no hay accesorios de catálogo ahí) y extra. Un mod REEMPLAZA lo que el ot
|
|
25
|
+
* (o un mod anterior) lleva en cada hueco que ocupa: el de sus piezas, el de los accesorios de
|
|
26
|
+
* catálogo de su `character.accessories` y los de `replaces` ('all' = todos). Así un mod con
|
|
27
|
+
* sombrero le quita al ot el suyo en vez de ponerle otro encima. Una pieza con slot 'none' se suma
|
|
28
|
+
* sin quitar nada. Las piezas sin `slot` (mods de antes) lo deducen de su ancla y su capa: delante,
|
|
29
|
+
* top → head, eyes → eyes, nose/mouth → face, neck → neck; detrás, top → head y neck/center/
|
|
30
|
+
* bottom/shoulder → back; lo demás, 'none'.
|
|
31
|
+
*
|
|
32
|
+
* `face`: cambios físicos relativos a la cara del ot, cada uno de -1 a 1 (0 = como está), para
|
|
33
|
+
* parecerse a quien imita sin dejar de ser ese ot. Deforman su silueta (y con ella el cuerpo 3D,
|
|
34
|
+
* que sale de los mismos puntos) y mueven ojos y boca:
|
|
35
|
+
* width, height cara más ancha/estrecha, más alta/baja (los pies se quedan en el suelo)
|
|
36
|
+
* jaw mandíbula: + ancha y cuadrada, − fina
|
|
37
|
+
* chin barbilla: + marcada hacia abajo, − plana
|
|
38
|
+
* forehead frente: + alta (despejada, con entradas), − baja
|
|
39
|
+
* cheekbones pómulos: + marcados, − hundidos
|
|
40
|
+
* eyeSize, eyeSpacing, eyeHeight, mouthSize, mouthHeight
|
|
41
|
+
* Los rasgos absolutos (tono de piel = body.color, forma = body.shape o body.points, tipo y color
|
|
42
|
+
* de ojos, cejas y boca, mejillas, textura) van en `character`; si el mod fija body.shape sin
|
|
43
|
+
* body.points, la silueta dibujada a mano del ot deja paso a esa forma.
|
|
44
|
+
*
|
|
19
45
|
* Un mod puede traer además un cuerpo completo (3D) que reemplaza al ot procedural:
|
|
20
46
|
* model: { url: 'https://…/muneco.vrm' | '/mods/<hash>.vrm' | data:glb, scale, y, rot }
|
|
21
47
|
* (VRM o GLB; ver src/character3d/model.js). En 2D se sigue viendo el ot con su parche.
|
|
22
48
|
*
|
|
23
|
-
* `character` es un parche de la ficha (normalizeCharacter lo sanea); sus `accessories`
|
|
24
|
-
*
|
|
25
|
-
* mismas unidades que el SVG (1 = 1 px de un ot de 120 de ancho) con y hacia arriba.
|
|
49
|
+
* `character` es un parche de la ficha (normalizeCharacter lo sanea); sus `accessories` ocupan el
|
|
50
|
+
* hueco de su grupo. En el SVG valen {color} {color2} {body} {bodyDark} {bodyLight} {line}. El glb
|
|
51
|
+
* usa las mismas unidades que el SVG (1 = 1 px de un ot de 120 de ancho) con y hacia arriba.
|
|
26
52
|
*
|
|
27
53
|
* Todo pasa por aquí antes de guardarse o pintarse: el SVG se reescribe con una lista cerrada de
|
|
28
54
|
* etiquetas y atributos (sin scripts, eventos, enlaces ni estilos) y el glb solo puede ser https o
|
|
29
55
|
* un data: de glb.
|
|
30
56
|
*/
|
|
31
57
|
|
|
58
|
+
import { ACCESSORIES, SHAPES } from './parts.js';
|
|
59
|
+
|
|
32
60
|
export const MOD_ANCHORS = ['top', 'eyes', 'nose', 'mouth', 'neck', 'center', 'bottom', 'shoulder'];
|
|
61
|
+
export const MOD_SLOTS = ['head', 'eyes', 'face', 'neck', 'back', 'body', 'extra'];
|
|
62
|
+
export const MOD_FACE = ['width', 'height', 'jaw', 'chin', 'forehead', 'cheekbones', 'eyeSize', 'eyeSpacing', 'eyeHeight', 'mouthSize', 'mouthHeight'];
|
|
33
63
|
export const MAX_MODS = 4;
|
|
34
64
|
const MAX_PARTS = 8;
|
|
35
65
|
const MAX_SVG = 20000;
|
|
@@ -125,21 +155,33 @@ const modelOf = (v) => {
|
|
|
125
155
|
const nameOf = (v) => {
|
|
126
156
|
if (isObj(v)) {
|
|
127
157
|
const o = {};
|
|
128
|
-
for (const k of ['en', 'es', 'pt']) if (v[k]) o[k] = str(v[k], 40);
|
|
158
|
+
for (const k of ['en', 'es', 'pt', 'zh', 'hi']) if (v[k]) o[k] = str(v[k], 40);
|
|
129
159
|
return Object.keys(o).length ? o : '';
|
|
130
160
|
}
|
|
131
161
|
return str(v, 40);
|
|
132
162
|
};
|
|
133
163
|
|
|
134
164
|
const PATCH_KEYS = ['body', 'eyes', 'brows', 'mouth', 'cheeks', 'finish', 'texture', 'outline', 'accessories'];
|
|
165
|
+
/** Hueco de cada accesorio de catálogo: su grupo. */
|
|
166
|
+
const GROUP = Object.fromEntries(ACCESSORIES.map((a) => [a.id, a.group]));
|
|
167
|
+
const ANCHOR_SLOT = {
|
|
168
|
+
front: { top: 'head', eyes: 'eyes', nose: 'face', mouth: 'face', neck: 'neck' },
|
|
169
|
+
// detrás del cuerpo no hay gafas ni bigotes (las orejas del orco van en 'eyes' por detrás)
|
|
170
|
+
back: { top: 'head', neck: 'back', center: 'back', bottom: 'back', shoulder: 'back' },
|
|
171
|
+
};
|
|
172
|
+
/** Hueco de una pieza: el que declara, o el de su ancla (mods de antes de los huecos). */
|
|
173
|
+
const slotOf = (slot, anchor, layer) => (slot === 'none' || MOD_SLOTS.includes(slot) ? slot : ANCHOR_SLOT[layer][anchor] || 'none');
|
|
135
174
|
|
|
136
175
|
function normalizePart(p, modId) {
|
|
137
176
|
if (!isObj(p) || !/^[a-z0-9-]{1,24}$/.test(String(p.id))) return null;
|
|
138
177
|
const view = Array.isArray(p.view) && p.view.length === 4 ? p.view.map((v, i) => num(v, 0, i < 2 ? -400 : 1, 400)) : [-60, -60, 120, 120];
|
|
178
|
+
const anchor = MOD_ANCHORS.includes(p.anchor) ? p.anchor : 'center';
|
|
179
|
+
const layer = p.layer === 'back' ? 'back' : 'front';
|
|
139
180
|
const part = {
|
|
140
181
|
id: p.id,
|
|
141
|
-
anchor
|
|
142
|
-
layer
|
|
182
|
+
anchor,
|
|
183
|
+
layer,
|
|
184
|
+
slot: slotOf(p.slot, anchor, layer),
|
|
143
185
|
svg: sanitizeSvg(p.svg, `m-${modId}-${p.id}`),
|
|
144
186
|
view,
|
|
145
187
|
glb: glbUrl(p.glb),
|
|
@@ -166,12 +208,17 @@ export function normalizeMod(m) {
|
|
|
166
208
|
const parts = (Array.isArray(m.parts) ? m.parts : []).slice(0, MAX_PARTS).map((p) => normalizePart(p, m.id)).filter(Boolean);
|
|
167
209
|
const seen = new Set();
|
|
168
210
|
const model = modelOf(m.model);
|
|
211
|
+
const face = {};
|
|
212
|
+
if (isObj(m.face)) for (const k of MOD_FACE) if (num(m.face[k], 0, -1, 1)) face[k] = Math.round(num(m.face[k], 0, -1, 1) * 100) / 100;
|
|
213
|
+
const replaces = Array.isArray(m.replaces) ? [...new Set(m.replaces.filter((x) => x === 'all' || MOD_SLOTS.includes(x)))] : [];
|
|
169
214
|
return {
|
|
170
215
|
id: m.id,
|
|
171
216
|
v: 1,
|
|
172
217
|
name: nameOf(m.name) || m.id,
|
|
173
218
|
...(m.by ? { by: str(m.by, 40) } : {}),
|
|
174
219
|
character,
|
|
220
|
+
...(Object.keys(face).length ? { face } : {}),
|
|
221
|
+
...(replaces.length ? { replaces } : {}),
|
|
175
222
|
parts: parts.filter((p) => !seen.has(p.id) && seen.add(p.id)),
|
|
176
223
|
...(model ? { model } : {}),
|
|
177
224
|
};
|
|
@@ -202,22 +249,69 @@ const merge = (a, b) => {
|
|
|
202
249
|
return o;
|
|
203
250
|
};
|
|
204
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Rasgos de `face` sobre una ficha ya normalizada: deforma su silueta (16 puntos simétricos) y
|
|
254
|
+
* mueve ojos y boca. Todo relativo a la caja del cuerpo, con los pies donde estaban.
|
|
255
|
+
*/
|
|
256
|
+
function applyFace(s, f) {
|
|
257
|
+
const pts = s.body.points || SHAPES.find((x) => x.id === s.body.shape)?.points || SHAPES[0].points;
|
|
258
|
+
const xs = pts.map((p) => p[0]);
|
|
259
|
+
const ys = pts.map((p) => p[1]);
|
|
260
|
+
const cx = (Math.min(...xs) + Math.max(...xs)) / 2;
|
|
261
|
+
const cy = (Math.min(...ys) + Math.max(...ys)) / 2;
|
|
262
|
+
const hw = (Math.max(...xs) - Math.min(...xs)) / 2 || 1;
|
|
263
|
+
const hh = (Math.max(...ys) - Math.min(...ys)) / 2 || 1;
|
|
264
|
+
const foot = Math.max(...ys);
|
|
265
|
+
const v = (k) => f[k] || 0;
|
|
266
|
+
const points = pts.map(([x, y]) => {
|
|
267
|
+
const u = (x - cx) / hw; // -1 izquierda … 1 derecha
|
|
268
|
+
const t = (y - cy) / hh; // -1 arriba … 1 abajo
|
|
269
|
+
const low = Math.max(0, t);
|
|
270
|
+
const up = Math.max(0, -t);
|
|
271
|
+
let sx = 1 + 0.22 * v('width');
|
|
272
|
+
sx *= 1 + 0.3 * v('jaw') * low ** 0.8; // mandíbula: la mitad de abajo
|
|
273
|
+
sx *= 1 + 0.16 * v('cheekbones') * Math.max(0, 1 - ((t + 0.1) / 0.75) ** 2); // pómulos: algo por encima del centro (suave: son 16 puntos)
|
|
274
|
+
let ny = y - hh * 0.18 * v('forehead') * up ** 2; // frente: sube la parte de arriba
|
|
275
|
+
ny += hh * 0.2 * v('chin') * Math.max(0, 1 - Math.abs(u) / 0.6) * low ** 2; // barbilla: solo el centro de abajo
|
|
276
|
+
ny = foot - (foot - ny) * (1 + 0.18 * v('height'));
|
|
277
|
+
return [cx + (x - cx) * sx, ny];
|
|
278
|
+
});
|
|
279
|
+
return {
|
|
280
|
+
...s,
|
|
281
|
+
body: { ...s.body, points },
|
|
282
|
+
eyes: { ...s.eyes, size: s.eyes.size * (1 + 0.35 * v('eyeSize')), spacing: s.eyes.spacing * (1 + 0.35 * v('eyeSpacing')), y: s.eyes.y - 14 * v('eyeHeight') },
|
|
283
|
+
mouth: { ...s.mouth, size: s.mouth.size * (1 + 0.35 * v('mouthSize')), y: s.mouth.y - 12 * v('mouthHeight') },
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
205
287
|
/**
|
|
206
288
|
* La ficha que se pinta: la base con los parches de sus mods (en orden) y sus piezas como
|
|
207
|
-
* accesorios `mod:<mod>/<pieza>`.
|
|
208
|
-
*
|
|
289
|
+
* accesorios `mod:<mod>/<pieza>`. Cada mod vacía antes los huecos que ocupa (MOD_SLOTS): lo que
|
|
290
|
+
* el ot o un mod anterior llevaba ahí se quita en vez de quedar debajo. `normalize` es
|
|
291
|
+
* normalizeCharacter (sin dependencia circular). La ficha devuelta lleva `_modParts` con los
|
|
292
|
+
* datos de esas piezas (los lee modPart).
|
|
209
293
|
*/
|
|
210
294
|
export function applyMods(spec, normalize) {
|
|
211
295
|
const mods = spec?.mods;
|
|
212
296
|
if (!Array.isArray(mods) || !mods.length) return spec;
|
|
213
297
|
let s = spec;
|
|
214
|
-
|
|
298
|
+
let extra = [];
|
|
215
299
|
const parts = {};
|
|
216
300
|
let model = null;
|
|
301
|
+
const slotIn = (a) => (a.id.startsWith('mod:') ? parts[a.id]?.slot : GROUP[a.id]);
|
|
217
302
|
for (const m of mods) {
|
|
218
303
|
if (m.model) model = m.model; // el último cuerpo completo manda
|
|
219
304
|
const { accessories, ...patch } = m.character || {};
|
|
220
|
-
|
|
305
|
+
const add = (Array.isArray(accessories) ? accessories : []).filter((a, i, l) => isObj(a) && GROUP[a.id] && l.findIndex((b) => b?.id === a.id) === i);
|
|
306
|
+
const slots = new Set(m.replaces || []);
|
|
307
|
+
for (const a of add) slots.add(GROUP[a.id]);
|
|
308
|
+
for (const p of m.parts) if (p.slot !== 'none') slots.add(p.slot);
|
|
309
|
+
const free = (a) => !slots.has('all') && !slots.has(slotIn(a));
|
|
310
|
+
// una forma nueva manda sobre la silueta dibujada a mano del ot (si el mod no trae la suya)
|
|
311
|
+
const base = isObj(patch.body) && patch.body.shape && !patch.body.points ? { ...s, body: { ...s.body, points: null } } : s;
|
|
312
|
+
s = normalize({ ...merge(base, patch), accessories: [...s.accessories.filter(free), ...add] });
|
|
313
|
+
if (m.face) s = normalize(applyFace(s, m.face));
|
|
314
|
+
extra = extra.filter(free);
|
|
221
315
|
for (const p of m.parts) {
|
|
222
316
|
const id = `mod:${m.id}/${p.id}`;
|
|
223
317
|
parts[id] = p;
|