@botharness/pixel-avatar 0.1.0 → 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/README.md +1 -0
- package/dist/index.d.ts +46 -6
- package/dist/index.js +1576 -1482
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,5 +18,6 @@ const svg = pixelAvatarSvg(recipe); // 32×32 viewBox, crisp edges, no ids or sc
|
|
|
18
18
|
- `AVATAR_PARTS`, `AVATAR_SWATCHES`, `AVATAR_PRESETS`, `DEFAULT_RECIPE`: everything an editor needs.
|
|
19
19
|
- `isPixelAvatarRecipe`, `canonicalRecipe`: validate and normalise saved recipes.
|
|
20
20
|
- `AVATAR_HAIR_PARTS`, `AVATAR_RANGES`, `detailedRecipe(recipe)`: optional finer controls. A recipe may carry `bangs`, `sideHair`, `backHair`, `spacing`, `height` and `hairLength`, all six or none; `detailedRecipe` derives them from the plain `hair` so an editor can start from what is on screen. Recipes without them render exactly as before.
|
|
21
|
+
- `AVATAR_SPECIES`, `AVATAR_SPECIES_SWATCHES`, `AVATAR_PIECE_COLORS`, `withSpecies(recipe, species)`: Avatar Species (`human`, `goblin`) on the same rig, as asset version 2. `withSpecies` keeps every choice, splits side hair into `sideHair` (left) and `rightSideHair`, and accepts optional `leftSideHairColor`/`rightSideHairColor`, where left and right are as seen on screen. Consumers built before version 2 reject these recipes with `isPixelAvatarRecipe` and can show a saved snapshot instead.
|
|
21
22
|
- `faceCells`, `pixelSymbolCells`, `symbolArtCells`: pixels for [`@botharness/pixel-morph`](../morph).
|
|
22
23
|
- `pixelAvatarSvg(recipe, { turns, classPrefix })`: optional pre-rendered head turns, and rig layer classes (`<prefix>-body`, `-head`, `-face`, `-gaze`, `-blink`) for CSS animation.
|
package/dist/index.d.ts
CHANGED
|
@@ -30,15 +30,48 @@ type AvatarRange = keyof typeof AVATAR_RANGES;
|
|
|
30
30
|
type AvatarPart = keyof typeof AVATAR_PARTS;
|
|
31
31
|
declare const AVATAR_COLORS: readonly ["skinColor", "hairColor", "eyeColor", "shirtColor"];
|
|
32
32
|
type AvatarColor = (typeof AVATAR_COLORS)[number];
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Avatar Species: a base on the pixel bust rig. Species share motion and anchors; each sets its
|
|
35
|
+
* own ears, face details and suggested body colors. A recipe with a species is asset version 2.
|
|
36
|
+
*/
|
|
37
|
+
declare const AVATAR_SPECIES: readonly ["human", "goblin"];
|
|
38
|
+
type AvatarSpecies = (typeof AVATAR_SPECIES)[number];
|
|
39
|
+
/** Optional per-piece hair colors (asset version 2); an absent piece uses `hairColor`. */
|
|
40
|
+
declare const AVATAR_PIECE_COLORS: readonly ["leftSideHairColor", "rightSideHairColor"];
|
|
41
|
+
type AvatarPieceColor = (typeof AVATAR_PIECE_COLORS)[number];
|
|
42
|
+
type BaseRecipe = {
|
|
34
43
|
schemaVersion: 1;
|
|
35
44
|
family: 'illustrated';
|
|
36
|
-
assetVersion: 1;
|
|
37
45
|
rigVersion: 1;
|
|
38
|
-
} & { [P in AvatarPart]: (typeof AVATAR_PARTS)[P][number] } & Record<AvatarColor, string
|
|
39
|
-
|
|
46
|
+
} & { [P in AvatarPart]: (typeof AVATAR_PARTS)[P][number] } & Record<AvatarColor, string>;
|
|
47
|
+
/** Asset version 1: optional split hair and geometry, all six or none. */
|
|
48
|
+
type PixelAvatarRecipeV1 = BaseRecipe & {
|
|
49
|
+
assetVersion: 1;
|
|
50
|
+
} & { [P in AvatarHairPart]?: (typeof AVATAR_PARTS)['hair'][number] } & { [P in AvatarRange]?: number } & {
|
|
51
|
+
species?: never;
|
|
52
|
+
rightSideHair?: never;
|
|
53
|
+
} & { [P in AvatarPieceColor]?: never };
|
|
54
|
+
/**
|
|
55
|
+
* Asset version 2: a species, the full split hair and geometry, a separate right side hair
|
|
56
|
+
* (`sideHair` is then the left side) and optional per-side hair colors.
|
|
57
|
+
*/
|
|
58
|
+
type PixelAvatarRecipeV2 = BaseRecipe & {
|
|
59
|
+
assetVersion: 2;
|
|
60
|
+
} & { [P in AvatarHairPart]: (typeof AVATAR_PARTS)['hair'][number] } & { [P in AvatarRange]: number } & {
|
|
61
|
+
species: AvatarSpecies;
|
|
62
|
+
rightSideHair: (typeof AVATAR_HAIR_PARTS)['sideHair'][number];
|
|
63
|
+
} & { [P in AvatarPieceColor]?: string };
|
|
64
|
+
type PixelAvatarRecipe = PixelAvatarRecipeV1 | PixelAvatarRecipeV2;
|
|
65
|
+
declare const DEFAULT_RECIPE: PixelAvatarRecipeV1;
|
|
40
66
|
declare function isPixelAvatarRecipe(value: unknown): value is PixelAvatarRecipe;
|
|
41
67
|
declare function canonicalRecipe(recipe: PixelAvatarRecipe): PixelAvatarRecipe;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the recipe as asset version 2 with the given species, keeping every other choice.
|
|
70
|
+
* Side hair splits into left (`sideHair`) and right (`rightSideHair`) pieces that start equal.
|
|
71
|
+
* When the skin color is one of the previous species' suggested colors, it moves to the new
|
|
72
|
+
* species' first suggestion; a custom color is kept.
|
|
73
|
+
*/
|
|
74
|
+
declare function withSpecies(recipe: PixelAvatarRecipe, species: AvatarSpecies): PixelAvatarRecipeV2;
|
|
42
75
|
declare function detailedRecipe(recipe: PixelAvatarRecipe): PixelAvatarRecipe;
|
|
43
76
|
declare const AVATAR_SWATCHES: Record<AvatarColor, readonly string[]>;
|
|
44
77
|
/**
|
|
@@ -48,15 +81,21 @@ declare const AVATAR_SWATCHES: Record<AvatarColor, readonly string[]>;
|
|
|
48
81
|
declare function createSeededRecipe(namespace: string): (seed: string) => PixelAvatarRecipe;
|
|
49
82
|
/** The same name always gives the same face (BotHarness's namespace). */
|
|
50
83
|
declare const seededRecipe: (seed: string) => PixelAvatarRecipe;
|
|
84
|
+
/** Suggested body colors per species; any color remains allowed. */
|
|
85
|
+
declare const AVATAR_SPECIES_SWATCHES: Record<AvatarSpecies, readonly string[]>;
|
|
51
86
|
declare const AVATAR_PRESETS: readonly PixelAvatarRecipe[];
|
|
52
87
|
//#endregion
|
|
53
88
|
//#region src/figure.d.ts
|
|
54
89
|
type Cell = string | undefined;
|
|
55
90
|
type Grid = Cell[][];
|
|
56
91
|
type PixelGrid = Grid;
|
|
92
|
+
type PixelMouthState = 'saved' | 'closed' | 'half-open' | 'open';
|
|
93
|
+
interface PixelFigureOptions {
|
|
94
|
+
mouthLayers?: boolean;
|
|
95
|
+
}
|
|
57
96
|
type Recipe = PixelAvatarRecipe;
|
|
58
97
|
declare function pixelTileColor(hair: string): string;
|
|
59
|
-
declare function pixelFigure(recipe: Recipe, yawDeg: number): {
|
|
98
|
+
declare function pixelFigure(recipe: Recipe, yawDeg: number, options?: PixelFigureOptions): {
|
|
60
99
|
tile: string;
|
|
61
100
|
body: string;
|
|
62
101
|
head: string;
|
|
@@ -70,6 +109,7 @@ declare function seededRandom(seed: string): () => number;
|
|
|
70
109
|
/** Head-turn offsets (degrees) the thinking animation cycles through. */
|
|
71
110
|
declare const AVATAR_TURNS: readonly [-14, -7, 7, 14];
|
|
72
111
|
interface PixelAvatarSvgOptions {
|
|
112
|
+
mouthLayers?: boolean;
|
|
73
113
|
/** Extra yaw offsets to pre-render as hidden `[data-avatar-turn]` layers. */
|
|
74
114
|
turns?: readonly number[];
|
|
75
115
|
/** Class prefix for the rig layers (`-body`, `-head`, `-face`, `-gaze`, `-blink`). */
|
|
@@ -110,5 +150,5 @@ declare function pixelSymbolCells(symbol: PixelSymbol, color: string): PixelCell
|
|
|
110
150
|
*/
|
|
111
151
|
declare function symbolArtCells(rows: readonly string[], color: string): PixelCell$1[];
|
|
112
152
|
//#endregion
|
|
113
|
-
export { AVATAR_COLORS, AVATAR_HAIR_PARTS, AVATAR_PARTS, AVATAR_PRESETS, AVATAR_RANGES, AVATAR_SWATCHES, AVATAR_TURNS, type AvatarColor, type AvatarHairPart, type AvatarPart, type AvatarRange, DEFAULT_RECIPE, PIXEL_SYMBOLS, type PixelAvatarRecipe, type PixelAvatarSvgOptions, type PixelCell, type PixelGrid, type PixelSymbol, canonicalRecipe, createSeededRecipe, detailedRecipe, faceCells, isPixelAvatarRecipe, pixelAvatarSvg, pixelFigure, pixelSymbolCells, pixelTileColor, seededRandom, seededRecipe, symbolArtCells };
|
|
153
|
+
export { AVATAR_COLORS, AVATAR_HAIR_PARTS, AVATAR_PARTS, AVATAR_PIECE_COLORS, AVATAR_PRESETS, AVATAR_RANGES, AVATAR_SPECIES, AVATAR_SPECIES_SWATCHES, AVATAR_SWATCHES, AVATAR_TURNS, type AvatarColor, type AvatarHairPart, type AvatarPart, type AvatarPieceColor, type AvatarRange, type AvatarSpecies, DEFAULT_RECIPE, PIXEL_SYMBOLS, type PixelAvatarRecipe, type PixelAvatarRecipeV1, type PixelAvatarRecipeV2, type PixelAvatarSvgOptions, type PixelCell, type PixelFigureOptions, type PixelGrid, type PixelMouthState, type PixelSymbol, canonicalRecipe, createSeededRecipe, detailedRecipe, faceCells, isPixelAvatarRecipe, pixelAvatarSvg, pixelFigure, pixelSymbolCells, pixelTileColor, seededRandom, seededRecipe, symbolArtCells, withSpecies };
|
|
114
154
|
//# sourceMappingURL=index.d.ts.map
|