-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
641 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
client/src/ui/components/Tutorial.tsx → ...t/src/ui/components/Tutorial/Tutorial.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React, { useEffect, useRef, useState } from "react"; | ||
import { GameState } from "@/enums/gameEnums"; | ||
import { Block } from "@/types/types"; | ||
|
||
interface BlockProps { | ||
block: Block; | ||
gridSize: number; | ||
isTxProcessing?: boolean; | ||
transitionDuration?: number; | ||
state?: GameState; | ||
handleMouseDown?: ( | ||
e: React.MouseEvent<HTMLDivElement>, | ||
block: BlockProps["block"], | ||
) => void; | ||
handleTouchStart?: ( | ||
e: React.TouchEvent<HTMLDivElement>, | ||
block: BlockProps["block"], | ||
) => void; | ||
onTransitionBlockStart?: () => void; | ||
onTransitionBlockEnd?: () => void; | ||
isHighlighted?: boolean; | ||
highlightType?: "block" | "row"; | ||
isClickable?: boolean; // If the block or row is clickable | ||
} | ||
|
||
const BlockContainer: React.FC<BlockProps> = ({ | ||
block, | ||
gridSize, | ||
transitionDuration = 100, | ||
isTxProcessing = false, | ||
state, | ||
handleMouseDown, | ||
handleTouchStart, | ||
onTransitionBlockStart, | ||
onTransitionBlockEnd, | ||
isHighlighted, | ||
highlightType = "block", | ||
isClickable, | ||
}) => { | ||
const ref = useRef<HTMLDivElement | null>(null); | ||
|
||
useEffect(() => { | ||
if (ref.current === null) return; | ||
|
||
const element = ref.current; // Capture the current value | ||
const onTransitionStart = () => { | ||
console.log("Transition started for block", block); | ||
onTransitionBlockStart && onTransitionBlockStart(); | ||
}; | ||
|
||
element.addEventListener("transitionstart", onTransitionStart); | ||
|
||
return () => { | ||
element.removeEventListener("transitionstart", onTransitionStart); | ||
}; | ||
}, [block, onTransitionBlockStart]); | ||
|
||
const handleTransitionEnd = () => { | ||
console.log("Transition ended for block", block); | ||
onTransitionBlockEnd && onTransitionBlockEnd(); | ||
}; | ||
|
||
// Determine the CSS class based on highlight status | ||
const highlightClass = isHighlighted | ||
? highlightType === "row" | ||
? "ring-2 ring-yellow-400 ring-opacity-50" // Subtle row highlight | ||
: "ring-4 ring-yellow-400 animate-pulse" // Prominent block highlight | ||
: ""; | ||
|
||
// Only make the block clickable if it's highlighted | ||
const isBlockClickable = isHighlighted && isClickable; | ||
|
||
return ( | ||
<div | ||
className={`block block-${block.width} ${isTxProcessing ? "cursor-wait" : ""} ${highlightClass} ${isBlockClickable ? "cursor-pointer" : ""}`} | ||
ref={ref} | ||
style={{ | ||
zIndex: isHighlighted ? 999 : "auto", | ||
position: "absolute", | ||
top: `${block.y * gridSize + 1}px`, | ||
left: `${block.x * gridSize + 1}px`, | ||
width: `${block.width * gridSize}px`, | ||
height: `${gridSize}px`, | ||
transition: | ||
state === GameState.GRAVITY || | ||
state === GameState.GRAVITY2 || | ||
state === GameState.GRAVITY_BONUS | ||
? `top ${transitionDuration / 1000}s linear` | ||
: "none", // No transition in other states | ||
color: "white", | ||
}} | ||
onMouseDown={(e) => { | ||
if (isBlockClickable && handleMouseDown) { | ||
handleMouseDown(e, block); // Allow clicking only if it's clickable | ||
} | ||
}} | ||
onTouchStart={(e) => { | ||
if (isBlockClickable && handleTouchStart) { | ||
handleTouchStart(e, block); // Allow touch only if it's clickable | ||
} | ||
}} | ||
onTransitionEnd={handleTransitionEnd} | ||
></div> | ||
); | ||
}; | ||
|
||
export default BlockContainer; |
Oops, something went wrong.