fix: 2048 modal bug
This commit is contained in:
@@ -141,7 +141,7 @@ const cellX = (col: number) => BORDER_SIZE + col * (TILE_SIZE + BORDER_SIZE);
|
|||||||
const cellY = (row: number) => BORDER_SIZE + row * (TILE_SIZE + BORDER_SIZE);
|
const cellY = (row: number) => BORDER_SIZE + row * (TILE_SIZE + BORDER_SIZE);
|
||||||
|
|
||||||
let tiles: VisualTile[] = [];
|
let tiles: VisualTile[] = [];
|
||||||
let animating = false;
|
let moveTimeline: gsap.core.Timeline | null = null;
|
||||||
|
|
||||||
const showRestartModal = () => {
|
const showRestartModal = () => {
|
||||||
confirmationModal.open({
|
confirmationModal.open({
|
||||||
@@ -415,14 +415,14 @@ if (board.every((r) => r.every((c) => c === 0))) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const slide = (rowDir: number, colDir: number) => {
|
const slide = (rowDir: number, colDir: number) => {
|
||||||
if (isDead() && !confirmationModal.isOpen) {
|
if (isDead()) {
|
||||||
showRestartModal();
|
showRestartModal();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (animating) {
|
if (moveTimeline) {
|
||||||
gsap.globalTimeline.clear();
|
moveTimeline.kill();
|
||||||
animating = false;
|
moveTimeline = null;
|
||||||
buildTilesFromBoard();
|
buildTilesFromBoard();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,14 +553,14 @@ const slide = (rowDir: number, colDir: number) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tiles = animTiles;
|
tiles = animTiles;
|
||||||
animating = true;
|
|
||||||
|
|
||||||
const tl = gsap.timeline({
|
const tl = gsap.timeline({
|
||||||
onComplete: () => {
|
onComplete: () => {
|
||||||
animating = false;
|
moveTimeline = null;
|
||||||
buildTilesFromBoard();
|
buildTilesFromBoard();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
moveTimeline = tl;
|
||||||
|
|
||||||
for (const { tile, toX, toY } of tweens) {
|
for (const { tile, toX, toY } of tweens) {
|
||||||
tl.to(tile, { x: toX, y: toY, duration: ANIM_DURATION, ease: "none" }, 0);
|
tl.to(tile, { x: toX, y: toY, duration: ANIM_DURATION, ease: "none" }, 0);
|
||||||
@@ -601,7 +601,7 @@ const slide = (rowDir: number, colDir: number) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
useKeyDown(({ key }) => {
|
useKeyDown(({ key }) => {
|
||||||
if (isAnimating.value) return;
|
if (isAnimating.value || confirmationModal.isOpen) return;
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "NDS_UP":
|
case "NDS_UP":
|
||||||
case "NDS_SWIPE_UP":
|
case "NDS_SWIPE_UP":
|
||||||
|
|||||||
Reference in New Issue
Block a user