Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
2D で会話中は移動できないようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
calmery committed Feb 26, 2021
1 parent c7d66e2 commit f70a6d1
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/components/Exhibition/2d/Morning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export const Exhibition2dMorning: React.FC = () => {
>(null);
const [wokeUp, setWorkUp] = useState(false);
const [sleep, setSleep] = useState(false);
const isInteracting = !wokeUp || !!scenarios || sleep;

useEffect(() => {
(async () => {
Expand All @@ -182,15 +183,22 @@ export const Exhibition2dMorning: React.FC = () => {
})();
}, []);

const handleKeydown = useCallback(({ key }: KeyboardEvent) => {
const isLeft = key === "a" || key === "ArrowLeft";
const isRight = key === "d" || key === "ArrowRight";
const handleKeydown = useCallback(
({ key }: KeyboardEvent) => {
if (isInteracting) {
return;
}

if (isLeft) setDirection("left");
if (isRight) setDirection("right");
const isLeft = key === "a" || key === "ArrowLeft";
const isRight = key === "d" || key === "ArrowRight";

setIsMoving(isLeft || isRight);
}, []);
if (isLeft) setDirection("left");
if (isRight) setDirection("right");

setIsMoving(isLeft || isRight);
},
[isInteracting]
);

const handleKeyup = useCallback(({ key }: KeyboardEvent) => {
if (
Expand All @@ -204,7 +212,7 @@ export const Exhibition2dMorning: React.FC = () => {
}, []);

const handleMove = useCallback(() => {
if (sleep || !wokeUp) {
if (isInteracting) {
return;
}

Expand Down Expand Up @@ -343,8 +351,6 @@ export const Exhibition2dMorning: React.FC = () => {

// Render

const isInteracting = !wokeUp || !!scenarios || sleep;

return (
<div
className={classnames("bg-black h-full w-full", {
Expand Down

0 comments on commit f70a6d1

Please sign in to comment.