Skip to content

Commit

Permalink
handle go to next phase
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheelax committed Nov 19, 2024
1 parent 141c55a commit 18fa9c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
16 changes: 7 additions & 9 deletions client/src/ui/components/Tutorial/GameBoardTutorial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface GameBoardProps {
isIntermission: boolean;
};
onBlockSelect?: (block: Block) => void;
onUpdateState: (intermission: boolean) => void;
}

const GameBoardTutorial: React.FC<GameBoardProps> = ({
Expand All @@ -39,6 +40,7 @@ const GameBoardTutorial: React.FC<GameBoardProps> = ({
totemCount,
tutorialProps,
onBlockSelect,
onUpdateState,
}) => {
const isMdOrLarger = useMediaQuery({ query: "(min-width: 768px)" });
const ROWS = 10;
Expand All @@ -56,6 +58,10 @@ const GameBoardTutorial: React.FC<GameBoardProps> = ({
const [score, setScore] = useState<number | undefined>(0);
const [isIntermission, setIsIntermission] = useState(false);

const updateValue = () => {
onUpdateState(true);
};

useEffect(() => {
// Every time the initial grid changes, we erase the optimistic data
// and set the data to the one returned by the contract
Expand Down Expand Up @@ -100,11 +106,6 @@ const GameBoardTutorial: React.FC<GameBoardProps> = ({
}
};

const updateValue = (intermission: boolean) => {
setScore((score ?? 0) + 15);
setIsIntermission(intermission);
};

const handleBonusWaveTx = useCallback(async (rowIndex: number) => {
setIsTxProcessing(true);
try {
Expand Down Expand Up @@ -257,10 +258,7 @@ const GameBoardTutorial: React.FC<GameBoardProps> = ({
tutorialStep={tutorialProps?.step ?? 0}
intermission={tutorialProps?.isIntermission}
tutorialTargetBlock={tutorialProps?.targetBlock ?? null}
onUpdate={(intermission: boolean) => {
// Ignore the intermission parameter since we only care about score updates
setOptimisticScore((prev) => (prev ?? 0) + 1);
}}
onUpdate={updateValue}
ref={setBonus}
/>
</div>
Expand Down
5 changes: 5 additions & 0 deletions client/src/ui/components/Tutorial/Tutorial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ const Tutorial: React.FC<TutorialProps> = ({ showGrid, endTutorial }) => {
[tutorialStep],
);

const handleUpdateState = (intermission: boolean) => {
setIsIntermission(intermission);
};

const tutorialTargetBlock = useMemo(() => {
switch (tutorialStep) {
case 1:
Expand Down Expand Up @@ -143,6 +147,7 @@ const Tutorial: React.FC<TutorialProps> = ({ showGrid, endTutorial }) => {
targetBlock: tutorialTargetBlock,
isIntermission,
}}
onUpdateState={handleUpdateState}
/>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion client/src/ui/components/Tutorial/TutorialGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ const TutorialGrid: React.FC<GridProps> = forwardRef(

const isHighlighted = (block: Block) => {
if (!tutorialTargetBlock) return false;

if (intermission) return false;
if (tutorialTargetBlock.type === "row") {
return block.y === tutorialTargetBlock.y;
} else {
Expand Down Expand Up @@ -385,6 +385,7 @@ const TutorialGrid: React.FC<GridProps> = forwardRef(
setBlocks(updatedBlocks);
setIsMoving(true);
setGameState(newGravityState);
onUpdate(true);
} else {
setGameState(newStateOnComplete);
}
Expand Down

0 comments on commit 18fa9c7

Please sign in to comment.