import React from "react";
import {
Box,
Button,
Flex,
Heading,
Input,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalHeader,
ModalOverlay,
Select,
Tooltip,
Wrap,
WrapItem,
} from "@chakra-ui/react";
import { gql, useQuery } from "@apollo/client";
import {
itemAppearanceFragment,
petAppearanceFragment,
} from "../../components/useOutfitAppearance";
import HangerSpinner from "../../components/HangerSpinner";
import { ErrorMessage, useCommonStyles } from "../../util";
import ItemSupportAppearanceLayer from "./ItemSupportAppearanceLayer";
import { EditIcon } from "@chakra-ui/icons";
import cachedZones from "../../cached-data/zones.json";
function AllItemLayersSupportModal({ item, isOpen, onClose }) {
const { bodyBackground } = useCommonStyles();
return (
Layers on all pets:
{" "}
{item.name}
);
}
function BulkAddBodySpecificAssetsForm() {
const zones = [...cachedZones].sort((a, b) =>
`${a.label} (${a.id})`.localeCompare(`${b.label} (${b.id})`)
);
const [minAssetId, setMinAssetId] = React.useState(null);
const [selectedZoneId, setSelectedZoneId] = React.useState(zones[0].id);
return (
{
e.preventDefault();
alert("TODO!");
}}
>
When an item accidentally gets assigned to fit all bodies, this
tool can help you recover the original appearances, by assuming
the layer IDs are assigned to each species in alphabetical order.
This will only find layers that have already been modeled!
}
>
Bulk-add body-specific assets:
setMinAssetId(e.target.value || null)}
/>
–
setMinAssetId(e.target.value ? Number(e.target.value) - 53 : null)
}
/>
, assigned to
);
}
function AllItemLayersSupportModalContent({ item }) {
const { loading, error, data } = useQuery(
gql`
query AllItemLayersSupportModal($itemId: ID!) {
item(id: $itemId) {
id
allAppearances {
id
body {
id
representsAllBodies
canonicalAppearance {
id
species {
id
name
}
color {
id
name
isStandard
}
pose
...PetAppearanceForOutfitPreview
}
}
...ItemAppearanceForOutfitPreview
}
}
}
${itemAppearanceFragment}
${petAppearanceFragment}
`,
{ variables: { itemId: item.id } }
);
if (loading) {
return (
);
}
if (error) {
return {error.message};
}
const itemAppearances = [...(data.item?.allAppearances || [])].sort(
(a, b) => {
const aKey = getSortKeyForPetAppearance(a.body.canonicalAppearance);
const bKey = getSortKeyForPetAppearance(b.body.canonicalAppearance);
return aKey.localeCompare(bKey);
}
);
return (
{itemAppearances.map((itemAppearance) => (
))}
);
}
function ItemAppearanceCard({ item, itemAppearance }) {
const petAppearance = itemAppearance.body.canonicalAppearance;
const biologyLayers = petAppearance.layers;
const itemLayers = [...itemAppearance.layers].sort(
(a, b) => a.zone.depth - b.zone.depth
);
const { brightBackground } = useCommonStyles();
return (
{getBodyName(itemAppearance.body)}
{itemLayers.map((itemLayer) => (
))}
);
}
function getSortKeyForPetAppearance({ color, species }) {
// Sort standard colors first, then special colors by name, then by species
// within each color.
return `${color.isStandard ? "A" : "Z"}-${color.name}-${species.name}`;
}
function getBodyName(body) {
if (body.representsAllBodies) {
return "All bodies";
}
const { species, color } = body.canonicalAppearance;
const speciesName = capitalize(species.name);
const colorName = color.isStandard ? "Standard" : capitalize(color.name);
return `${colorName} ${speciesName}`;
}
function capitalize(str) {
return str[0].toUpperCase() + str.slice(1);
}
export default AllItemLayersSupportModal;