2020-05-02 15:41:02 -07:00
|
|
|
import React from "react";
|
2020-05-02 17:22:46 -07:00
|
|
|
import gql from "graphql-tag";
|
2020-07-31 23:10:34 -07:00
|
|
|
import { useQuery } from "@apollo/client";
|
2021-01-03 19:11:46 -08:00
|
|
|
import { ClassNames } from "@emotion/react";
|
2020-05-02 15:41:02 -07:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Button,
|
|
|
|
Flex,
|
|
|
|
Popover,
|
|
|
|
PopoverArrow,
|
|
|
|
PopoverContent,
|
|
|
|
PopoverTrigger,
|
2020-07-31 23:31:51 -07:00
|
|
|
Portal,
|
2020-05-02 22:04:20 -07:00
|
|
|
VisuallyHidden,
|
2020-08-12 00:37:31 -07:00
|
|
|
useColorModeValue,
|
2020-05-02 15:41:02 -07:00
|
|
|
useTheme,
|
2020-12-25 09:08:33 -08:00
|
|
|
} from "@chakra-ui/react";
|
2021-01-21 14:34:55 -08:00
|
|
|
import { loadable } from "../util";
|
2020-05-02 15:41:02 -07:00
|
|
|
|
2020-07-22 21:29:57 -07:00
|
|
|
import {
|
|
|
|
getVisibleLayers,
|
|
|
|
petAppearanceFragment,
|
|
|
|
} from "../components/useOutfitAppearance";
|
|
|
|
import { OutfitLayers } from "../components/OutfitPreview";
|
2020-08-26 18:43:54 -07:00
|
|
|
import SupportOnly from "./support/SupportOnly";
|
2020-08-29 14:49:37 -07:00
|
|
|
import useSupport from "./support/useSupport";
|
2020-08-28 22:58:39 -07:00
|
|
|
import { useLocalStorage } from "../util";
|
2020-05-02 15:41:02 -07:00
|
|
|
|
2020-05-02 16:03:23 -07:00
|
|
|
// From https://twemoji.twitter.com/, thank you!
|
2021-01-03 19:49:08 -08:00
|
|
|
import twemojiSmile from "../images/twemoji/smile.svg";
|
|
|
|
import twemojiCry from "../images/twemoji/cry.svg";
|
|
|
|
import twemojiSick from "../images/twemoji/sick.svg";
|
|
|
|
import twemojiSunglasses from "../images/twemoji/sunglasses.svg";
|
|
|
|
import twemojiQuestion from "../images/twemoji/question.svg";
|
|
|
|
import twemojiMasc from "../images/twemoji/masc.svg";
|
|
|
|
import twemojiFem from "../images/twemoji/fem.svg";
|
2020-05-02 16:03:23 -07:00
|
|
|
|
2020-08-26 18:43:54 -07:00
|
|
|
const PosePickerSupport = loadable(() => import("./support/PosePickerSupport"));
|
|
|
|
|
|
|
|
const PosePickerSupportSwitch = loadable(() =>
|
|
|
|
import("./support/PosePickerSupport").then((m) => m.PosePickerSupportSwitch)
|
|
|
|
);
|
|
|
|
|
2020-08-04 23:58:52 -07:00
|
|
|
/**
|
|
|
|
* PosePicker shows the pet poses available on the current species/color, and
|
|
|
|
* lets the user choose which want they want!
|
|
|
|
*
|
|
|
|
* NOTE: This component is memoized with React.memo. It's relatively expensive
|
|
|
|
* to re-render on every outfit change - the contents update even if the
|
|
|
|
* popover is closed! This makes wearing/unwearing items noticeably
|
|
|
|
* slower on lower-power devices.
|
|
|
|
*
|
|
|
|
* So, instead of using `outfitState` like most components, we specify
|
|
|
|
* exactly which props we need, so that `React.memo` can see the changes
|
|
|
|
* that matter, and skip updates that don't.
|
|
|
|
*/
|
2020-05-02 22:20:17 -07:00
|
|
|
function PosePicker({
|
2020-08-04 23:58:52 -07:00
|
|
|
speciesId,
|
|
|
|
colorId,
|
|
|
|
pose,
|
2020-08-28 22:58:39 -07:00
|
|
|
appearanceId,
|
2020-05-02 22:20:17 -07:00
|
|
|
dispatchToOutfit,
|
|
|
|
onLockFocus,
|
|
|
|
onUnlockFocus,
|
|
|
|
}) {
|
2020-05-02 15:41:02 -07:00
|
|
|
const theme = useTheme();
|
2020-08-31 01:32:25 -07:00
|
|
|
const initialFocusRef = React.useRef();
|
2020-08-12 00:35:11 -07:00
|
|
|
const { loading, error, poseInfos } = usePoses(speciesId, colorId, pose);
|
2020-08-28 22:58:39 -07:00
|
|
|
const [isInSupportMode, setIsInSupportMode] = useLocalStorage(
|
|
|
|
"DTIPosePickerIsInSupportMode",
|
|
|
|
false
|
|
|
|
);
|
2020-08-29 14:49:37 -07:00
|
|
|
const { isSupportUser } = useSupport();
|
2020-05-02 22:04:20 -07:00
|
|
|
|
2020-08-29 14:19:43 -07:00
|
|
|
// Resize the Popover when we toggle support mode, because it probably will
|
|
|
|
// affect the content size.
|
|
|
|
React.useLayoutEffect(() => {
|
|
|
|
// HACK: To trigger a Popover resize, we simulate a window resize event,
|
|
|
|
// because Popover listens for window resizes to reposition itself.
|
|
|
|
// I've also filed an issue requesting an official API!
|
|
|
|
// https://github.com/chakra-ui/chakra-ui/issues/1853
|
|
|
|
window.dispatchEvent(new Event("resize"));
|
|
|
|
}, [isInSupportMode]);
|
|
|
|
|
2020-05-02 17:22:46 -07:00
|
|
|
if (loading) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a low-stakes enough control, where enough pairs don't have data
|
|
|
|
// anyway, that I think I want to just not draw attention to failures.
|
|
|
|
if (error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's only one pose anyway, don't bother showing a picker!
|
2020-08-29 14:49:37 -07:00
|
|
|
// (Unless we're Support, in which case we want the ability to pop it open to
|
|
|
|
// inspect and label the Unknown poses!)
|
2020-05-23 12:47:06 -07:00
|
|
|
const numAvailablePoses = Object.values(poseInfos).filter(
|
|
|
|
(p) => p.isAvailable
|
|
|
|
).length;
|
2020-08-29 14:49:37 -07:00
|
|
|
if (numAvailablePoses <= 1 && !isSupportUser) {
|
2020-05-02 17:22:46 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-05-02 22:20:17 -07:00
|
|
|
const onChange = (e) => {
|
2020-05-23 12:47:06 -07:00
|
|
|
dispatchToOutfit({ type: "setPose", pose: e.target.value });
|
2020-05-02 22:20:17 -07:00
|
|
|
};
|
|
|
|
|
2020-05-02 15:41:02 -07:00
|
|
|
return (
|
2021-01-04 21:51:54 -08:00
|
|
|
<Popover
|
|
|
|
placement="bottom-end"
|
|
|
|
returnFocusOnClose
|
|
|
|
onOpen={onLockFocus}
|
|
|
|
onClose={onUnlockFocus}
|
|
|
|
initialFocusRef={initialFocusRef}
|
|
|
|
>
|
|
|
|
{({ isOpen }) => (
|
|
|
|
<ClassNames>
|
|
|
|
{({ css, cx }) => (
|
2021-01-03 19:11:46 -08:00
|
|
|
<>
|
|
|
|
<PopoverTrigger>
|
|
|
|
<Button
|
|
|
|
variant="unstyled"
|
|
|
|
boxShadow="md"
|
|
|
|
d="flex"
|
|
|
|
alignItems="center"
|
|
|
|
justifyContent="center"
|
|
|
|
_focus={{ borderColor: "gray.50" }}
|
|
|
|
_hover={{ borderColor: "gray.50" }}
|
|
|
|
outline="initial"
|
|
|
|
className={cx(
|
|
|
|
css`
|
|
|
|
border: 1px solid transparent !important;
|
|
|
|
transition: border-color 0.2s !important;
|
2020-05-02 15:41:02 -07:00
|
|
|
|
2021-01-03 19:11:46 -08:00
|
|
|
&:focus,
|
|
|
|
&:hover,
|
|
|
|
&.is-open {
|
|
|
|
border-color: ${theme.colors.gray["50"]} !important;
|
|
|
|
}
|
2020-05-02 16:03:23 -07:00
|
|
|
|
2021-01-03 19:11:46 -08:00
|
|
|
&.is-open {
|
|
|
|
border-width: 2px !important;
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
isOpen && "is-open"
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<EmojiImage src={getIcon(pose)} alt="Choose a pose" />
|
|
|
|
</Button>
|
|
|
|
</PopoverTrigger>
|
|
|
|
<Portal>
|
|
|
|
<PopoverContent>
|
|
|
|
<Box p="4" position="relative">
|
|
|
|
{isInSupportMode ? (
|
|
|
|
<PosePickerSupport
|
|
|
|
speciesId={speciesId}
|
|
|
|
colorId={colorId}
|
|
|
|
pose={pose}
|
|
|
|
appearanceId={appearanceId}
|
|
|
|
initialFocusRef={initialFocusRef}
|
|
|
|
dispatchToOutfit={dispatchToOutfit}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<PosePickerTable
|
|
|
|
poseInfos={poseInfos}
|
|
|
|
onChange={onChange}
|
|
|
|
initialFocusRef={initialFocusRef}
|
|
|
|
/>
|
|
|
|
{numAvailablePoses <= 1 && (
|
|
|
|
<SupportOnly>
|
|
|
|
<Box
|
|
|
|
fontSize="xs"
|
|
|
|
fontStyle="italic"
|
|
|
|
textAlign="center"
|
|
|
|
opacity="0.7"
|
|
|
|
marginTop="2"
|
|
|
|
>
|
|
|
|
The empty picker is hidden for most users!
|
|
|
|
<br />
|
|
|
|
You can see it because you're a Support user.
|
|
|
|
</Box>
|
|
|
|
</SupportOnly>
|
|
|
|
)}
|
|
|
|
</>
|
2020-08-29 14:49:37 -07:00
|
|
|
)}
|
2021-01-03 19:11:46 -08:00
|
|
|
<SupportOnly>
|
|
|
|
<Box position="absolute" top="5" left="3">
|
|
|
|
<PosePickerSupportSwitch
|
|
|
|
isChecked={isInSupportMode}
|
|
|
|
onChange={(e) => setIsInSupportMode(e.target.checked)}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</SupportOnly>
|
2020-08-26 18:43:54 -07:00
|
|
|
</Box>
|
2021-01-03 19:11:46 -08:00
|
|
|
<PopoverArrow />
|
|
|
|
</PopoverContent>
|
|
|
|
</Portal>
|
|
|
|
</>
|
|
|
|
)}
|
2021-01-04 21:51:54 -08:00
|
|
|
</ClassNames>
|
2020-05-02 15:41:02 -07:00
|
|
|
)}
|
2021-01-04 21:51:54 -08:00
|
|
|
</Popover>
|
2020-05-02 15:41:02 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-31 01:32:25 -07:00
|
|
|
function PosePickerTable({ poseInfos, onChange, initialFocusRef }) {
|
2020-08-26 18:43:54 -07:00
|
|
|
return (
|
2020-08-31 20:26:15 -07:00
|
|
|
<Box display="flex" flexDirection="column" alignItems="center">
|
|
|
|
<table width="100%">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th />
|
|
|
|
<Cell as="th">
|
|
|
|
<EmojiImage src={twemojiSmile} alt="Happy" />
|
|
|
|
</Cell>
|
|
|
|
<Cell as="th">
|
|
|
|
<EmojiImage src={twemojiCry} alt="Sad" />
|
|
|
|
</Cell>
|
|
|
|
<Cell as="th">
|
|
|
|
<EmojiImage src={twemojiSick} alt="Sick" />
|
|
|
|
</Cell>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<Cell as="th">
|
|
|
|
<EmojiImage src={twemojiMasc} alt="Masculine" />
|
|
|
|
</Cell>
|
|
|
|
<Cell as="td">
|
|
|
|
<PoseOption
|
|
|
|
poseInfo={poseInfos.happyMasc}
|
|
|
|
onChange={onChange}
|
|
|
|
inputRef={poseInfos.happyMasc.isSelected && initialFocusRef}
|
|
|
|
/>
|
|
|
|
</Cell>
|
|
|
|
<Cell as="td">
|
|
|
|
<PoseOption
|
|
|
|
poseInfo={poseInfos.sadMasc}
|
|
|
|
onChange={onChange}
|
|
|
|
inputRef={poseInfos.sadMasc.isSelected && initialFocusRef}
|
|
|
|
/>
|
|
|
|
</Cell>
|
|
|
|
<Cell as="td">
|
|
|
|
<PoseOption
|
|
|
|
poseInfo={poseInfos.sickMasc}
|
|
|
|
onChange={onChange}
|
|
|
|
inputRef={poseInfos.sickMasc.isSelected && initialFocusRef}
|
|
|
|
/>
|
|
|
|
</Cell>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<Cell as="th">
|
|
|
|
<EmojiImage src={twemojiFem} alt="Feminine" />
|
|
|
|
</Cell>
|
|
|
|
<Cell as="td">
|
|
|
|
<PoseOption
|
|
|
|
poseInfo={poseInfos.happyFem}
|
|
|
|
onChange={onChange}
|
|
|
|
inputRef={poseInfos.happyFem.isSelected && initialFocusRef}
|
|
|
|
/>
|
|
|
|
</Cell>
|
|
|
|
<Cell as="td">
|
|
|
|
<PoseOption
|
|
|
|
poseInfo={poseInfos.sadFem}
|
|
|
|
onChange={onChange}
|
|
|
|
inputRef={poseInfos.sadFem.isSelected && initialFocusRef}
|
|
|
|
/>
|
|
|
|
</Cell>
|
|
|
|
<Cell as="td">
|
|
|
|
<PoseOption
|
|
|
|
poseInfo={poseInfos.sickFem}
|
|
|
|
onChange={onChange}
|
|
|
|
inputRef={poseInfos.sickFem.isSelected && initialFocusRef}
|
|
|
|
/>
|
|
|
|
</Cell>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
{poseInfos.unconverted.isAvailable && (
|
|
|
|
<PoseOption
|
|
|
|
poseInfo={poseInfos.unconverted}
|
|
|
|
onChange={onChange}
|
|
|
|
inputRef={poseInfos.unconverted.isSelected && initialFocusRef}
|
|
|
|
size="sm"
|
|
|
|
label="Unconverted"
|
|
|
|
marginTop="2"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
2020-08-26 18:43:54 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-02 16:03:23 -07:00
|
|
|
function Cell({ children, as }) {
|
|
|
|
const Tag = as;
|
2020-05-02 15:41:02 -07:00
|
|
|
return (
|
2020-05-02 16:03:23 -07:00
|
|
|
<Tag>
|
2020-05-02 15:41:02 -07:00
|
|
|
<Flex justify="center" p="1">
|
|
|
|
{children}
|
|
|
|
</Flex>
|
2020-05-02 16:03:23 -07:00
|
|
|
</Tag>
|
2020-05-02 15:41:02 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-02 22:04:20 -07:00
|
|
|
const EMOTION_STRINGS = {
|
2020-08-12 00:32:10 -07:00
|
|
|
HAPPY_MASC: "Happy",
|
|
|
|
HAPPY_FEM: "Happy",
|
|
|
|
SAD_MASC: "Sad",
|
|
|
|
SAD_FEM: "Sad",
|
|
|
|
SICK_MASC: "Sick",
|
|
|
|
SICK_FEM: "Sick",
|
2020-05-02 22:04:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
const GENDER_PRESENTATION_STRINGS = {
|
2020-08-12 00:32:10 -07:00
|
|
|
HAPPY_MASC: "Masculine",
|
|
|
|
SAD_MASC: "Masculine",
|
|
|
|
SICK_MASC: "Masculine",
|
|
|
|
HAPPY_FEM: "Feminine",
|
|
|
|
SAD_FEM: "Feminine",
|
|
|
|
SICK_FEM: "Feminine",
|
2020-05-02 22:04:20 -07:00
|
|
|
};
|
|
|
|
|
2020-08-31 20:26:15 -07:00
|
|
|
function PoseOption({
|
|
|
|
poseInfo,
|
|
|
|
onChange,
|
|
|
|
inputRef,
|
2020-08-31 23:08:03 -07:00
|
|
|
size = "md",
|
2020-08-31 20:26:15 -07:00
|
|
|
label,
|
|
|
|
...otherProps
|
|
|
|
}) {
|
2020-05-02 22:04:20 -07:00
|
|
|
const theme = useTheme();
|
2020-08-12 00:32:10 -07:00
|
|
|
const genderPresentationStr = GENDER_PRESENTATION_STRINGS[poseInfo.pose];
|
|
|
|
const emotionStr = EMOTION_STRINGS[poseInfo.pose];
|
2020-05-02 22:04:20 -07:00
|
|
|
|
2020-08-31 20:26:15 -07:00
|
|
|
let poseName =
|
|
|
|
poseInfo.pose === "UNCONVERTED"
|
|
|
|
? "Unconverted"
|
|
|
|
: `${emotionStr} and ${genderPresentationStr}`;
|
2020-05-23 12:47:06 -07:00
|
|
|
if (!poseInfo.isAvailable) {
|
2020-08-31 20:26:15 -07:00
|
|
|
poseName += ` (not modeled yet)`;
|
2020-05-02 22:59:30 -07:00
|
|
|
}
|
|
|
|
|
2020-08-12 00:37:31 -07:00
|
|
|
const borderColor = useColorModeValue(
|
|
|
|
theme.colors.green["600"],
|
|
|
|
theme.colors.green["300"]
|
|
|
|
);
|
|
|
|
|
2020-05-02 15:41:02 -07:00
|
|
|
return (
|
2021-01-03 19:11:46 -08:00
|
|
|
<ClassNames>
|
|
|
|
{({ css, cx }) => (
|
2020-05-02 22:04:20 -07:00
|
|
|
<Box
|
2021-01-03 19:11:46 -08:00
|
|
|
as="label"
|
|
|
|
cursor="pointer"
|
|
|
|
display="flex"
|
|
|
|
alignItems="center"
|
|
|
|
borderColor={poseInfo.isSelected ? borderColor : "gray.400"}
|
|
|
|
boxShadow={label ? "md" : "none"}
|
|
|
|
borderWidth={label ? "1px" : "0"}
|
|
|
|
borderRadius={label ? "full" : "0"}
|
|
|
|
paddingRight={label ? "3" : "0"}
|
|
|
|
onClick={(e) => {
|
|
|
|
// HACK: We need the timeout to beat the popover's focus stealing!
|
|
|
|
const input = e.currentTarget.querySelector("input");
|
|
|
|
setTimeout(() => input.focus(), 0);
|
|
|
|
}}
|
|
|
|
{...otherProps}
|
|
|
|
>
|
|
|
|
<VisuallyHidden
|
|
|
|
as="input"
|
|
|
|
type="radio"
|
|
|
|
aria-label={poseName}
|
|
|
|
name="pose"
|
|
|
|
value={poseInfo.pose}
|
|
|
|
checked={poseInfo.isSelected}
|
|
|
|
disabled={!poseInfo.isAvailable}
|
|
|
|
onChange={onChange}
|
|
|
|
ref={inputRef || null}
|
|
|
|
/>
|
|
|
|
<Box
|
|
|
|
aria-hidden
|
|
|
|
borderRadius="full"
|
|
|
|
boxShadow="md"
|
|
|
|
overflow="hidden"
|
|
|
|
width={size === "sm" ? "30px" : "50px"}
|
|
|
|
height={size === "sm" ? "30px" : "50px"}
|
|
|
|
title={
|
|
|
|
poseInfo.isAvailable
|
|
|
|
? // A lil debug output, so that we can quickly identify glitched
|
|
|
|
// PetStates and manually mark them as glitched!
|
|
|
|
window.location.hostname.includes("localhost") &&
|
|
|
|
`#${poseInfo.id}`
|
|
|
|
: "Not modeled yet"
|
|
|
|
}
|
|
|
|
position="relative"
|
|
|
|
className={css`
|
|
|
|
transform: scale(0.8);
|
|
|
|
opacity: 0.8;
|
|
|
|
transition: all 0.2s;
|
2020-05-02 22:04:20 -07:00
|
|
|
|
2021-01-03 19:11:46 -08:00
|
|
|
input:checked + & {
|
|
|
|
transform: scale(1);
|
|
|
|
opacity: 1;
|
2020-05-02 22:59:30 -07:00
|
|
|
}
|
2021-01-03 19:11:46 -08:00
|
|
|
`}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
borderRadius="full"
|
|
|
|
position="absolute"
|
|
|
|
top="0"
|
|
|
|
bottom="0"
|
|
|
|
left="0"
|
|
|
|
right="0"
|
|
|
|
zIndex="2"
|
|
|
|
className={cx(
|
|
|
|
css`
|
|
|
|
border: 0px solid ${borderColor};
|
|
|
|
transition: border-width 0.2s;
|
2020-05-02 22:04:20 -07:00
|
|
|
|
2021-01-03 19:11:46 -08:00
|
|
|
&.not-available {
|
|
|
|
border-color: ${theme.colors.gray["500"]};
|
|
|
|
border-width: 1px;
|
|
|
|
}
|
2020-05-02 22:59:30 -07:00
|
|
|
|
2021-01-03 19:11:46 -08:00
|
|
|
input:checked + * & {
|
|
|
|
border-width: 1px;
|
|
|
|
}
|
|
|
|
|
|
|
|
input:focus + * & {
|
|
|
|
border-width: 3px;
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
!poseInfo.isAvailable && "not-available"
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{poseInfo.isAvailable ? (
|
|
|
|
<Box
|
|
|
|
width="100%"
|
|
|
|
height="100%"
|
|
|
|
transform={getTransform(poseInfo)}
|
|
|
|
>
|
|
|
|
<OutfitLayers visibleLayers={getVisibleLayers(poseInfo, [])} />
|
|
|
|
</Box>
|
|
|
|
) : (
|
|
|
|
<Flex align="center" justify="center" width="100%" height="100%">
|
|
|
|
<EmojiImage src={twemojiQuestion} boxSize="24px" />
|
|
|
|
</Flex>
|
|
|
|
)}
|
2020-05-02 22:59:30 -07:00
|
|
|
</Box>
|
2021-01-03 19:11:46 -08:00
|
|
|
{label && (
|
|
|
|
<Box
|
|
|
|
marginLeft="2"
|
|
|
|
fontSize="xs"
|
|
|
|
fontWeight={poseInfo.isSelected ? "bold" : "normal"}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</Box>
|
|
|
|
)}
|
2020-08-31 20:26:15 -07:00
|
|
|
</Box>
|
|
|
|
)}
|
2021-01-03 19:11:46 -08:00
|
|
|
</ClassNames>
|
2020-05-02 15:41:02 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-31 20:26:15 -07:00
|
|
|
function EmojiImage({ src, alt, boxSize = "16px" }) {
|
|
|
|
return <img src={src} alt={alt} width={boxSize} height={boxSize} />;
|
2020-05-02 16:03:23 -07:00
|
|
|
}
|
|
|
|
|
2020-08-04 23:58:52 -07:00
|
|
|
function usePoses(speciesId, colorId, selectedPose) {
|
2020-05-02 17:22:46 -07:00
|
|
|
const { loading, error, data } = useQuery(
|
|
|
|
gql`
|
|
|
|
query PosePicker($speciesId: ID!, $colorId: ID!) {
|
2020-08-27 21:26:24 -07:00
|
|
|
happyMasc: petAppearance(
|
|
|
|
speciesId: $speciesId
|
|
|
|
colorId: $colorId
|
|
|
|
pose: HAPPY_MASC
|
|
|
|
) {
|
|
|
|
...PetAppearanceForPosePicker
|
|
|
|
}
|
|
|
|
sadMasc: petAppearance(
|
|
|
|
speciesId: $speciesId
|
|
|
|
colorId: $colorId
|
|
|
|
pose: SAD_MASC
|
|
|
|
) {
|
|
|
|
...PetAppearanceForPosePicker
|
|
|
|
}
|
|
|
|
sickMasc: petAppearance(
|
|
|
|
speciesId: $speciesId
|
|
|
|
colorId: $colorId
|
|
|
|
pose: SICK_MASC
|
|
|
|
) {
|
|
|
|
...PetAppearanceForPosePicker
|
|
|
|
}
|
|
|
|
happyFem: petAppearance(
|
|
|
|
speciesId: $speciesId
|
|
|
|
colorId: $colorId
|
|
|
|
pose: HAPPY_FEM
|
|
|
|
) {
|
|
|
|
...PetAppearanceForPosePicker
|
|
|
|
}
|
|
|
|
sadFem: petAppearance(
|
|
|
|
speciesId: $speciesId
|
|
|
|
colorId: $colorId
|
|
|
|
pose: SAD_FEM
|
|
|
|
) {
|
|
|
|
...PetAppearanceForPosePicker
|
|
|
|
}
|
|
|
|
sickFem: petAppearance(
|
|
|
|
speciesId: $speciesId
|
|
|
|
colorId: $colorId
|
|
|
|
pose: SICK_FEM
|
|
|
|
) {
|
|
|
|
...PetAppearanceForPosePicker
|
2020-05-02 17:22:46 -07:00
|
|
|
}
|
2020-08-31 20:26:15 -07:00
|
|
|
unconverted: petAppearance(
|
|
|
|
speciesId: $speciesId
|
|
|
|
colorId: $colorId
|
|
|
|
pose: UNCONVERTED
|
|
|
|
) {
|
|
|
|
...PetAppearanceForPosePicker
|
|
|
|
}
|
2020-05-02 17:22:46 -07:00
|
|
|
}
|
2020-08-27 21:26:24 -07:00
|
|
|
|
|
|
|
fragment PetAppearanceForPosePicker on PetAppearance {
|
|
|
|
id
|
|
|
|
bodyId
|
|
|
|
pose
|
|
|
|
...PetAppearanceForOutfitPreview
|
|
|
|
}
|
2020-05-02 17:22:46 -07:00
|
|
|
${petAppearanceFragment}
|
|
|
|
`,
|
|
|
|
{ variables: { speciesId, colorId } }
|
|
|
|
);
|
|
|
|
|
2020-05-23 12:47:06 -07:00
|
|
|
const poseInfos = {
|
2020-08-27 21:26:24 -07:00
|
|
|
happyMasc: {
|
|
|
|
...data?.happyMasc,
|
2020-08-31 20:26:15 -07:00
|
|
|
pose: "HAPPY_MASC",
|
2020-08-27 21:26:24 -07:00
|
|
|
isAvailable: Boolean(data?.happyMasc),
|
|
|
|
isSelected: selectedPose === "HAPPY_MASC",
|
|
|
|
},
|
|
|
|
sadMasc: {
|
|
|
|
...data?.sadMasc,
|
2020-08-31 20:26:15 -07:00
|
|
|
pose: "SAD_MASC",
|
2020-08-27 21:26:24 -07:00
|
|
|
isAvailable: Boolean(data?.sadMasc),
|
|
|
|
isSelected: selectedPose === "SAD_MASC",
|
|
|
|
},
|
|
|
|
sickMasc: {
|
|
|
|
...data?.sickMasc,
|
2020-08-31 20:26:15 -07:00
|
|
|
pose: "SICK_MASC",
|
2020-08-27 21:26:24 -07:00
|
|
|
isAvailable: Boolean(data?.sickMasc),
|
|
|
|
isSelected: selectedPose === "SICK_MASC",
|
|
|
|
},
|
|
|
|
happyFem: {
|
|
|
|
...data?.happyFem,
|
2020-08-31 20:26:15 -07:00
|
|
|
pose: "HAPPY_FEM",
|
2020-08-27 21:26:24 -07:00
|
|
|
isAvailable: Boolean(data?.happyFem),
|
|
|
|
isSelected: selectedPose === "HAPPY_FEM",
|
|
|
|
},
|
|
|
|
sadFem: {
|
|
|
|
...data?.sadFem,
|
2020-08-31 20:26:15 -07:00
|
|
|
pose: "SAD_FEM",
|
2020-08-27 21:26:24 -07:00
|
|
|
isAvailable: Boolean(data?.sadFem),
|
|
|
|
isSelected: selectedPose === "SAD_FEM",
|
|
|
|
},
|
|
|
|
sickFem: {
|
|
|
|
...data?.sickFem,
|
2020-08-31 20:26:15 -07:00
|
|
|
pose: "SICK_FEM",
|
2020-08-27 21:26:24 -07:00
|
|
|
isAvailable: Boolean(data?.sickFem),
|
|
|
|
isSelected: selectedPose === "SICK_FEM",
|
|
|
|
},
|
2020-08-31 20:26:15 -07:00
|
|
|
unconverted: {
|
|
|
|
...data?.unconverted,
|
|
|
|
pose: "UNCONVERTED",
|
|
|
|
isAvailable: Boolean(data?.unconverted),
|
|
|
|
isSelected: selectedPose === "UNCONVERTED",
|
|
|
|
},
|
2020-05-02 17:22:46 -07:00
|
|
|
};
|
|
|
|
|
2020-05-23 12:47:06 -07:00
|
|
|
return { loading, error, poseInfos };
|
|
|
|
}
|
|
|
|
|
2020-08-31 20:26:15 -07:00
|
|
|
function getIcon(pose) {
|
2020-05-23 12:47:06 -07:00
|
|
|
if (["HAPPY_MASC", "HAPPY_FEM"].includes(pose)) {
|
2020-08-31 20:26:15 -07:00
|
|
|
return twemojiSmile;
|
2020-05-23 12:47:06 -07:00
|
|
|
} else if (["SAD_MASC", "SAD_FEM"].includes(pose)) {
|
2020-08-31 20:26:15 -07:00
|
|
|
return twemojiCry;
|
2020-05-23 12:47:06 -07:00
|
|
|
} else if (["SICK_MASC", "SICK_FEM"].includes(pose)) {
|
2020-08-31 20:26:15 -07:00
|
|
|
return twemojiSick;
|
|
|
|
} else if (pose === "UNCONVERTED") {
|
|
|
|
return twemojiSunglasses;
|
2020-05-23 12:47:06 -07:00
|
|
|
} else {
|
2020-08-31 20:26:15 -07:00
|
|
|
return twemojiQuestion;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTransform(poseInfo) {
|
|
|
|
const { pose, bodyId } = poseInfo;
|
|
|
|
if (pose === "UNCONVERTED") {
|
|
|
|
return transformsByBodyId.default;
|
|
|
|
}
|
|
|
|
if (bodyId in transformsByBodyId) {
|
|
|
|
return transformsByBodyId[bodyId];
|
2020-05-23 12:47:06 -07:00
|
|
|
}
|
2020-08-31 20:26:15 -07:00
|
|
|
return transformsByBodyId.default;
|
2020-05-02 17:22:46 -07:00
|
|
|
}
|
|
|
|
|
2020-05-03 12:55:37 -07:00
|
|
|
const transformsByBodyId = {
|
|
|
|
"93": "translate(-5px, 10px) scale(2.8)",
|
|
|
|
"106": "translate(-8px, 8px) scale(2.9)",
|
|
|
|
"47": "translate(-1px, 17px) scale(3)",
|
|
|
|
"84": "translate(-21px, 22px) scale(3.2)",
|
|
|
|
"146": "translate(2px, 15px) scale(3.3)",
|
|
|
|
"250": "translate(-14px, 28px) scale(3.4)",
|
|
|
|
"212": "translate(-4px, 8px) scale(2.9)",
|
|
|
|
"74": "translate(-26px, 30px) scale(3.0)",
|
|
|
|
"94": "translate(-4px, 8px) scale(3.1)",
|
|
|
|
"132": "translate(-14px, 18px) scale(3.0)",
|
|
|
|
"56": "translate(-7px, 24px) scale(2.9)",
|
|
|
|
"90": "translate(-16px, 20px) scale(3.5)",
|
|
|
|
"136": "translate(-11px, 18px) scale(3.0)",
|
|
|
|
"138": "translate(-14px, 26px) scale(3.5)",
|
|
|
|
"166": "translate(-13px, 24px) scale(3.1)",
|
|
|
|
"119": "translate(-6px, 29px) scale(3.1)",
|
|
|
|
"126": "translate(3px, 13px) scale(3.1)",
|
|
|
|
"67": "translate(2px, 27px) scale(3.4)",
|
|
|
|
"163": "translate(-7px, 16px) scale(3.1)",
|
|
|
|
"147": "translate(-2px, 15px) scale(3.0)",
|
|
|
|
"80": "translate(-2px, -17px) scale(3.0)",
|
|
|
|
"117": "translate(-14px, 16px) scale(3.6)",
|
|
|
|
"201": "translate(-16px, 16px) scale(3.2)",
|
|
|
|
"51": "translate(-2px, 6px) scale(3.2)",
|
|
|
|
"208": "translate(-3px, 6px) scale(3.7)",
|
|
|
|
"196": "translate(-7px, 19px) scale(5.2)",
|
|
|
|
"143": "translate(-16px, 20px) scale(3.5)",
|
|
|
|
"150": "translate(-3px, 24px) scale(3.2)",
|
|
|
|
"175": "translate(-9px, 15px) scale(3.4)",
|
|
|
|
"173": "translate(3px, 57px) scale(4.4)",
|
|
|
|
"199": "translate(-28px, 35px) scale(3.8)",
|
|
|
|
"52": "translate(-8px, 33px) scale(3.5)",
|
|
|
|
"109": "translate(-8px, -6px) scale(3.2)",
|
|
|
|
"134": "translate(-14px, 14px) scale(3.1)",
|
|
|
|
"95": "translate(-12px, 0px) scale(3.4)",
|
|
|
|
"96": "translate(6px, 23px) scale(3.3)",
|
|
|
|
"154": "translate(-20px, 25px) scale(3.6)",
|
|
|
|
"55": "translate(-16px, 28px) scale(4.0)",
|
|
|
|
"76": "translate(-8px, 11px) scale(3.0)",
|
|
|
|
"156": "translate(2px, 12px) scale(3.5)",
|
|
|
|
"78": "translate(-3px, 18px) scale(3.0)",
|
|
|
|
"191": "translate(-18px, 46px) scale(4.4)",
|
|
|
|
"187": "translate(-6px, 22px) scale(3.2)",
|
|
|
|
"46": "translate(-2px, 19px) scale(3.4)",
|
|
|
|
"178": "translate(-11px, 32px) scale(3.3)",
|
|
|
|
"100": "translate(-13px, 23px) scale(3.3)",
|
|
|
|
"130": "translate(-14px, 4px) scale(3.1)",
|
|
|
|
"188": "translate(-9px, 24px) scale(3.5)",
|
|
|
|
"257": "translate(-14px, 25px) scale(3.4)",
|
|
|
|
"206": "translate(-7px, 4px) scale(3.6)",
|
|
|
|
"101": "translate(-13px, 16px) scale(3.2)",
|
|
|
|
"68": "translate(-2px, 13px) scale(3.2)",
|
|
|
|
"182": "translate(-6px, 4px) scale(3.1)",
|
|
|
|
"180": "translate(-15px, 22px) scale(3.6)",
|
|
|
|
"306": "translate(1px, 14px) scale(3.1)",
|
2020-05-02 21:04:54 -07:00
|
|
|
default: "scale(2.5)",
|
|
|
|
};
|
|
|
|
|
2020-08-04 23:58:52 -07:00
|
|
|
export default React.memo(PosePicker);
|