From 63b865ef7c1c3941327ea957480648329a87f60b Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 1 Aug 2020 01:35:27 -0700 Subject: [PATCH] start adding appearance layers support tool right now it just shows stuff. next step is to make them clickable to open tools for managing the layer! --- src/app/WardrobePage/Item.js | 1 + .../WardrobePage/support/ItemSupportDrawer.js | 75 +++++++++++++++++-- src/app/components/OutfitPreview.js | 13 +++- src/app/components/useOutfitAppearance.js | 16 ++-- 4 files changed, 87 insertions(+), 18 deletions(-) diff --git a/src/app/WardrobePage/Item.js b/src/app/WardrobePage/Item.js index c786f7a..f86a039 100644 --- a/src/app/WardrobePage/Item.js +++ b/src/app/WardrobePage/Item.js @@ -82,6 +82,7 @@ export function Item({ item, itemNameId, outfitState, dispatchToOutfit }) { setSupportDrawerIsOpen(false)} /> diff --git a/src/app/WardrobePage/support/ItemSupportDrawer.js b/src/app/WardrobePage/support/ItemSupportDrawer.js index c0c0c94..431a758 100644 --- a/src/app/WardrobePage/support/ItemSupportDrawer.js +++ b/src/app/WardrobePage/support/ItemSupportDrawer.js @@ -14,13 +14,17 @@ import { FormErrorMessage, FormHelperText, FormLabel, + HStack, Link, Select, Spinner, + Stack, useBreakpointValue, } from "@chakra-ui/core"; import { CheckCircleIcon, ExternalLinkIcon } from "@chakra-ui/icons"; +import { OutfitLayers } from "../../components/OutfitPreview"; +import useOutfitAppearance from "../../components/useOutfitAppearance"; import useSupportSecret from "./useSupportSecret"; /** @@ -29,7 +33,7 @@ import useSupportSecret from "./useSupportSecret"; * This component controls the drawer element. The actual content is imported * from another lazy-loaded component! */ -function ItemSupportDrawer({ item, isOpen, onClose }) { +function ItemSupportDrawer({ item, outfitState, isOpen, onClose }) { const placement = useBreakpointValue({ base: "bottom", lg: "right", @@ -53,17 +57,26 @@ function ItemSupportDrawer({ item, isOpen, onClose }) { blockScrollOnMount={false} > - + - + {item.name} Support - + - + + + + @@ -72,7 +85,7 @@ function ItemSupportDrawer({ item, isOpen, onClose }) { ); } -function SpecialColorFields({ item }) { +function ItemSupportSpecialColorFields({ item }) { const supportSecret = useSupportSecret(); const { loading: itemLoading, error: itemError, data: itemData } = useQuery( @@ -215,4 +228,54 @@ function SpecialColorFields({ item }) { ); } +function ItemSupportAppearanceFields({ item, outfitState }) { + const { speciesId, colorId, pose } = outfitState; + const { error, visibleLayers } = useOutfitAppearance({ + speciesId, + colorId, + pose, + wornItemIds: [item.id], + }); + + const biologyLayers = visibleLayers.filter((l) => l.source === "pet"); + const itemLayers = visibleLayers.filter((l) => l.source === "item"); + itemLayers.sort((a, b) => a.zone.depth - b.zone.depth); + + return ( + + Appearance layers + + {itemLayers.map((itemLayer) => ( + + ))} + + {error && {error.message}} + + ); +} + +function ItemSupportAppearanceLayer({ biologyLayers, itemLayer }) { + return ( + + + + + + {itemLayer.zone.label} + + Zone ID: {itemLayer.zone.id} + Layer ID: {itemLayer.id} + + ); +} + export default ItemSupportDrawer; diff --git a/src/app/components/OutfitPreview.js b/src/app/components/OutfitPreview.js index a234266..bf9f526 100644 --- a/src/app/components/OutfitPreview.js +++ b/src/app/components/OutfitPreview.js @@ -80,7 +80,13 @@ export function OutfitLayers({ }, []); return ( - + {placeholder && ( - + {children} diff --git a/src/app/components/useOutfitAppearance.js b/src/app/components/useOutfitAppearance.js index 8671b0f..8b4a34b 100644 --- a/src/app/components/useOutfitAppearance.js +++ b/src/app/components/useOutfitAppearance.js @@ -91,15 +91,12 @@ export function getVisibleLayers(petAppearance, itemAppearances) { const validItemAppearances = itemAppearances.filter((a) => a); - const allAppearances = [petAppearance, ...validItemAppearances]; - let allLayers = allAppearances.map((a) => a.layers).flat(); - - // Clean up our data a bit, by ensuring only one layer per zone. This - // shouldn't happen in theory, but sometimes our database doesn't clean up - // after itself correctly :( - allLayers = allLayers.filter((l, i) => { - return allLayers.findIndex((l2) => l2.zone.id === l.zone.id) === i; - }); + const petLayers = petAppearance.layers.map((l) => ({ ...l, source: "pet" })); + const itemLayers = validItemAppearances + .map((a) => a.layers) + .flat() + .map((l) => ({ ...l, source: "item" })); + let allLayers = [...petLayers, ...itemLayers]; const allRestrictedZoneIds = validItemAppearances .map((l) => l.restrictedZones) @@ -123,6 +120,7 @@ export const itemAppearanceFragment = gql` zone { id depth + label # HACK: This is for Support tools, but other views don't need it } }