avatar to main merge
I have completed the character creation screen on the avatar branch and am preparing to merge it into main.
This commit is contained in:
37
lib/avatar-display.ts
Normal file
37
lib/avatar-display.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { LayerVariantState } from "@/lib/character/types";
|
||||
import { parseShopStyleItem, parseVariantId } from "@/lib/shop-catalog";
|
||||
|
||||
/** Apply equipped shop styles (variant ids like head-1) onto saved customization. */
|
||||
export function applyEquippedItemsToVariants(
|
||||
variants: LayerVariantState,
|
||||
equippedItems: string[],
|
||||
): LayerVariantState {
|
||||
const next = { ...variants };
|
||||
|
||||
for (const itemId of equippedItems) {
|
||||
const style = parseVariantId(itemId);
|
||||
|
||||
if (style) {
|
||||
next[style.layerId] = style.variantId;
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
export function applyEquippedShopRecordsToVariants(
|
||||
variants: LayerVariantState,
|
||||
equippedItems: Array<{ id: string; type: string }>,
|
||||
): LayerVariantState {
|
||||
const next = { ...variants };
|
||||
|
||||
for (const item of equippedItems) {
|
||||
const style = parseShopStyleItem(item.id, item.type);
|
||||
|
||||
if (style) {
|
||||
next[style.layerId] = style.variantId;
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
Reference in New Issue
Block a user