Add shop preview modal to try items on your pet before buying.

Preview overlays the item or room background on the current avatar without equipping.
This commit is contained in:
2026-05-24 04:45:35 -06:00
parent 4df8ea8d66
commit 69131ac8eb
3 changed files with 197 additions and 12 deletions

34
lib/shop-preview.ts Normal file
View File

@@ -0,0 +1,34 @@
import type { AvatarCustomization } from "@/lib/avatar-customization-storage";
import { parseVariantId, parseShopStyleItem, type ShopItemRecord } from "@/lib/shop-catalog";
import { normalizeRoomBackgroundId } from "@/lib/room-backgrounds";
/** Build a non-persisted avatar state showing how a shop item would look. */
export function buildShopItemPreviewCustomization(
base: AvatarCustomization,
item: ShopItemRecord,
): AvatarCustomization {
if (item.type === "room") {
return {
...base,
roomBackground: normalizeRoomBackgroundId(item.id),
};
}
const style = parseShopStyleItem(item.id, item.type);
if (!style) {
return base;
}
const nextEquipped = [
...base.equippedItems.filter((equippedId) => {
const equippedStyle = parseVariantId(equippedId);
return equippedStyle?.layerId !== style.layerId;
}),
item.id,
];
return {
...base,
equippedItems: nextEquipped,
};
}