Skip to content

Commit

Permalink
[๐ŸŽจ UI/UX] #222 ํ•œ ์ค„ ๊ณต๊ฒฉ ์™„๋ฃŒ ์‹œ toggle off
Browse files Browse the repository at this point in the history
  • Loading branch information
seungineer committed Jul 19, 2024
1 parent 0519df8 commit 371ca11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
3 changes: 3 additions & 0 deletions handtris/src/components/TetrisGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class TetrisGame {
toggleAttackEffect: boolean;
toggleAttackedEffect: boolean;
previousGreyRows: Set<number>;
isAddAttackToggleOn: boolean;

drawSquareCanvas: (
ctx: CanvasRenderingContext2D,
Expand Down Expand Up @@ -81,6 +82,7 @@ export class TetrisGame {
this.isFlipAttackToggleOn = false;
this.isDonutAttack = false;
this.isDonutAttackToggleOn = false;
this.isAddAttackToggleOn = false;
this.toggleAttackEffect = false;
this.toggleAttackedEffect = false;
this.isAddAttacked = false;
Expand Down Expand Up @@ -221,6 +223,7 @@ export class TetrisGame {
[...currentGreyRows].some(r => !this.previousGreyRows.has(r))
) {
this.toggleAttackEffect = true;
this.isAddAttackToggleOn = false;
} else {
this.toggleAttackEffect = false;
}
Expand Down
39 changes: 2 additions & 37 deletions handtris/src/components/TetrisPlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,6 @@ const Home: React.FC = () => {
const [isFlipping, setIsFlipping] = useState(false);
const [isNextBlockDonut, setIsNextBlockDonut] = useState(false);
const [showDonutWarning, setShowDonutWarning] = useState(false);
const [animationState, setAnimationState] = useState({
opacity: 1,
y: 0,
});
const [donutAttackToggle, setDonutAttackToggle] = useState(
tetrisGameRef.current?.isDonutAttackToggleOn
? "/image/DropPressed.png"
: "/image/DropDefault.png",
);
const fetchRoomPlayers = useCallback(async () => {
setIsLoading(true);
try {
Expand Down Expand Up @@ -623,6 +614,7 @@ const Home: React.FC = () => {
// console.log("newGauge: ", newGauge);
if (newGauge == 1 && tetrisGameRef.current) {
tetrisGameRef.current.isAddAttack = true;
tetrisGameRef.current.isAddAttackToggleOn = true;
} else if (newGauge == 2 && tetrisGameRef.current) {
tetrisGameRef.current.isFlipAttack = true;
} else if (newGauge == 3 && tetrisGameRef.current) {
Expand Down Expand Up @@ -921,33 +913,6 @@ const Home: React.FC = () => {
}
});

useEffect(() => {
let timeoutId: NodeJS.Timeout | undefined;

if (tetrisGameRef.current) {
const { isDonutAttackToggleOn, linesCleared } = tetrisGameRef.current;

if (!isDonutAttackToggleOn && linesCleared > 0) {
setAnimationState({ opacity: 0, y: -500 });

timeoutId = setTimeout(() => {
setAnimationState({ opacity: 1, y: 0 });
setDonutAttackToggle("/image/DropDefault.png");
}, 1000);
} else if (linesCleared > 0) {
setAnimationState({ opacity: 1, y: 0 });
setDonutAttackToggle("/image/DropPressed.png");
}
}

return () => {
if (timeoutId) clearTimeout(timeoutId);
};
}, [
tetrisGameRef.current?.isDonutAttackToggleOn,
tetrisGameRef.current?.linesCleared,
]);

const toggleShowFirstAttack = useCallback(() => {
setShowFirstAttack(true);
setTimeout(() => setShowFirstAttack(false), 500);
Expand Down Expand Up @@ -1049,7 +1014,7 @@ const Home: React.FC = () => {
{/* ์ฒซ ๋ฒˆ์งธ ์•„์ด์ฝ˜ */}
<ArrowUpNarrowWide
className={`border-2 absolute text-white rounded-lg
${gauge === 1 ? "bg-indigo-400" : "bg-black"}
${gauge === 1 && tetrisGameRef.current?.isAddAttackToggleOn ? "bg-indigo-400" : "bg-black"}
w-[40px] h-[40px]`}
style={{
left: "90%",
Expand Down

0 comments on commit 371ca11

Please sign in to comment.