katachi-runtime 0.6.0 → 0.6.1
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/README.md +1 -1
- package/character.d.ts +5 -2
- package/index.js +38 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -276,7 +276,7 @@ interface HeadBlend {
|
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
interface Look {
|
|
279
|
-
outfit?: Record<string, string>; // { jbib: "5:a", hair: "12:a", p_head: "none" }
|
|
279
|
+
outfit?: Record<string, string>; // { jbib: "5:a", hair: "12:a", p_head: "none" }; a DLC pack's piece names its pack: "mp_m_freemode_01_mp_m_xmas/5:a"
|
|
280
280
|
head?: HeadBlend;
|
|
281
281
|
hair?: { color: Tone; highlight?: Tone };
|
|
282
282
|
overlays?: Partial<Record<OverlayName, Overlay>>; // eyebrows, facialHair, makeup, blush, lipstick, ageing...
|
package/character.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type Tone = string | readonly [number, number, number];
|
|
|
29
29
|
* form that fits a link or a command line with `Character.parseOutfit` and `Character.parseHead`.
|
|
30
30
|
*/
|
|
31
31
|
export interface Look {
|
|
32
|
-
/** Pieces by slot, as `index` or `index:variant`, or `none`: `{ jbib: "5:a", hair: "12:a", p_head: "none" }`. */
|
|
32
|
+
/** Pieces by slot, as `index`, `index:variant` or `pack/index:variant`, or `none`: `{ jbib: "5:a", hair: "12:a", p_head: "none" }`. */
|
|
33
33
|
outfit?: Record<string, string>;
|
|
34
34
|
head?: HeadBlend;
|
|
35
35
|
hair?: {
|
|
@@ -91,7 +91,10 @@ export declare class Character extends Model {
|
|
|
91
91
|
* the look has them, so nothing loads to be replaced.
|
|
92
92
|
*/
|
|
93
93
|
static load(name: string, entry: PedEntry, loader: ModelLoader, looks?: FreemodeEntry | null, look?: Look): Promise<Character>;
|
|
94
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Reads `slot=index[:variant],...` as an outfit, such as `jbib=5:a,hair=12:a,p_head=none`. A piece from a DLC pack
|
|
96
|
+
* names its pack, as `jbib=mp_m_freemode_01_mp_m_xmas/5:a`, since every pack numbers its pieces from 0.
|
|
97
|
+
*/
|
|
95
98
|
static parseOutfit(text: string): Record<string, string>;
|
|
96
99
|
/** Writes an outfit the way `parseOutfit` reads it. */
|
|
97
100
|
static formatOutfit(outfit: Record<string, string>): string;
|
package/index.js
CHANGED
|
@@ -1171,25 +1171,43 @@ var TOP_ARMS = {
|
|
|
1171
1171
|
mp_m_freemode_01: [0, 0, 2, 14, 14, 5, 14, 14, 8, 0, 14, 15, 12, 11, 12, 15],
|
|
1172
1172
|
mp_f_freemode_01: [0, 5, 2, 3, 4, 4, 5, 5, 5, 0, 5, 4, 12, 15, 14, 15]
|
|
1173
1173
|
};
|
|
1174
|
+
function readChoice(choice) {
|
|
1175
|
+
if (choice === "none")
|
|
1176
|
+
return { none: true, index: -1 };
|
|
1177
|
+
const [where, variant] = choice.split(":");
|
|
1178
|
+
const slash = where.lastIndexOf("/");
|
|
1179
|
+
return { none: false, collection: slash >= 0 ? where.slice(0, slash) : undefined, index: Number(where.slice(slash + 1)), variant: variant || undefined };
|
|
1180
|
+
}
|
|
1181
|
+
function choose(pieces, component, choice, own) {
|
|
1182
|
+
const matches = pieces.filter((piece) => piece.component === component && piece.index === choice.index && !piece.alternate);
|
|
1183
|
+
if (choice.collection)
|
|
1184
|
+
return matches.find((piece) => piece.collection === choice.collection);
|
|
1185
|
+
return matches.find((piece) => piece.collection === own) ?? matches[0];
|
|
1186
|
+
}
|
|
1187
|
+
function topArms(name, outfit) {
|
|
1188
|
+
if (!outfit.jbib)
|
|
1189
|
+
return;
|
|
1190
|
+
const top = readChoice(outfit.jbib);
|
|
1191
|
+
if (top.none || top.collection && top.collection !== name)
|
|
1192
|
+
return;
|
|
1193
|
+
return TOP_ARMS[name]?.[top.index];
|
|
1194
|
+
}
|
|
1174
1195
|
function warm(name, entry, loader, look) {
|
|
1175
|
-
const find = (component, index) => {
|
|
1176
|
-
const matches = entry.components.filter((piece) => piece.component === component && piece.index === index && !piece.alternate);
|
|
1177
|
-
return matches.find((piece) => piece.collection === name) ?? matches[0];
|
|
1178
|
-
};
|
|
1179
1196
|
const wanted = [];
|
|
1180
1197
|
const outfit = { ...look.outfit };
|
|
1181
|
-
const top =
|
|
1198
|
+
const top = topArms(name, outfit);
|
|
1182
1199
|
if (top !== undefined && outfit.uppr === undefined)
|
|
1183
1200
|
outfit.uppr = String(top);
|
|
1184
|
-
for (const [slot,
|
|
1185
|
-
const
|
|
1186
|
-
const
|
|
1201
|
+
for (const [slot, text] of Object.entries(outfit)) {
|
|
1202
|
+
const choice = readChoice(text);
|
|
1203
|
+
const prop = slot.startsWith("p_");
|
|
1204
|
+
const piece = choice.none ? undefined : choose(prop ? entry.props : entry.components, prop ? slot.slice(2) : slot, choice, name);
|
|
1187
1205
|
if (piece)
|
|
1188
|
-
wanted.push([piece, variant]);
|
|
1206
|
+
wanted.push([piece, choice.variant]);
|
|
1189
1207
|
}
|
|
1190
1208
|
if (look.head) {
|
|
1191
1209
|
for (const id of new Set([look.head.shapeFirst, look.head.shapeSecond, look.head.skinFirst, look.head.skinSecond])) {
|
|
1192
|
-
const piece =
|
|
1210
|
+
const piece = choose(entry.components, "head", { none: false, index: id }, name);
|
|
1193
1211
|
if (piece)
|
|
1194
1212
|
wanted.push([piece, undefined]);
|
|
1195
1213
|
}
|
|
@@ -1401,8 +1419,8 @@ class Character extends Model {
|
|
|
1401
1419
|
const outfit = {};
|
|
1402
1420
|
for (const part of text.split(",").map((item) => item.trim()).filter(Boolean)) {
|
|
1403
1421
|
const [slot, choice, extra] = part.split("=");
|
|
1404
|
-
if (!slot || !choice || extra !== undefined || !/^(none
|
|
1405
|
-
throw new Error(`An outfit takes slot=index[:variant] or slot=none, not ${part}`);
|
|
1422
|
+
if (!slot || !choice || extra !== undefined || !/^(none|([\w-]+\/)?\d+(:[a-z])?)$/.test(choice))
|
|
1423
|
+
throw new Error(`An outfit takes slot=[pack/]index[:variant] or slot=none, not ${part}`);
|
|
1406
1424
|
outfit[slot] = choice;
|
|
1407
1425
|
}
|
|
1408
1426
|
return outfit;
|
|
@@ -1655,15 +1673,14 @@ class Character extends Model {
|
|
|
1655
1673
|
async dress(look) {
|
|
1656
1674
|
const missing = [];
|
|
1657
1675
|
const outfit = this.outfitOf(look);
|
|
1658
|
-
const clothes = Promise.all(Object.entries(outfit).map(([slot,
|
|
1659
|
-
const
|
|
1676
|
+
const clothes = Promise.all(Object.entries(outfit).map(([slot, text]) => {
|
|
1677
|
+
const choice = readChoice(text);
|
|
1660
1678
|
const prop = slot.startsWith("p_");
|
|
1661
1679
|
const component = prop ? slot.slice(2) : slot;
|
|
1662
|
-
const
|
|
1663
|
-
const
|
|
1664
|
-
const piece = indexText === "none" ? null : matches.find((candidate) => candidate.collection === this.name) ?? matches[0];
|
|
1680
|
+
const piece = choice.none ? null : choose(prop ? this.entry.props : this.entry.components, component, choice, this.name);
|
|
1681
|
+
const variant = choice.variant;
|
|
1665
1682
|
if (piece === undefined || piece && variant && !(variant in piece.diffuse)) {
|
|
1666
|
-
missing.push(`${slot}=${
|
|
1683
|
+
missing.push(`${slot}=${text}`);
|
|
1667
1684
|
return;
|
|
1668
1685
|
}
|
|
1669
1686
|
return prop ? this.setProp(component, piece, variant) : this.setComponent(component, piece, variant);
|
|
@@ -1677,7 +1694,7 @@ class Character extends Model {
|
|
|
1677
1694
|
}
|
|
1678
1695
|
outfitOf(look) {
|
|
1679
1696
|
const outfit = { ...look.outfit };
|
|
1680
|
-
const top =
|
|
1697
|
+
const top = topArms(this.name, outfit);
|
|
1681
1698
|
if (top !== undefined && outfit.uppr === undefined)
|
|
1682
1699
|
outfit.uppr = String(top);
|
|
1683
1700
|
if (look.head)
|
|
@@ -1691,7 +1708,8 @@ class Character extends Model {
|
|
|
1691
1708
|
const original = this.defaults.get(slot);
|
|
1692
1709
|
if (worn?.piece === original?.piece && worn?.variant === original?.variant)
|
|
1693
1710
|
continue;
|
|
1694
|
-
|
|
1711
|
+
const pack = worn && worn.piece.collection !== this.name ? `${worn.piece.collection}/` : "";
|
|
1712
|
+
outfit[slot] = worn ? `${pack}${worn.piece.index}${worn.variant ? `:${worn.variant}` : ""}` : "none";
|
|
1695
1713
|
}
|
|
1696
1714
|
if (this.blend)
|
|
1697
1715
|
delete outfit.head;
|