Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat implement tutorials mode #63

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ca8de74
Merge branch 'main' of https://github.com/josephchimebuka/zkube
josephchimebuka Aug 27, 2024
d4322ef
updated packages
josephchimebuka Sep 13, 2024
d875643
added the tutorialsteps and tutorialgame
josephchimebuka Sep 15, 2024
238f6c7
feat: Add Tutorial mode and TutorialComponent
josephchimebuka Sep 16, 2024
16ea24d
added new changes
josephchimebuka Sep 18, 2024
63c13fc
Merge branch 'feat--implement-tutorial-mode' of https://github.com/jo…
josephchimebuka Sep 18, 2024
f5f379b
new chnages
josephchimebuka Sep 23, 2024
d4e7ec9
added the burner opton for as a connector for account
josephchimebuka Oct 6, 2024
70e7da4
Merge branch 'dev' of https://github.com/z-korp/zkube into dev
josephchimebuka Oct 6, 2024
4928deb
Merge branch 'dev' into feat--implement-tutorial-mode
josephchimebuka Oct 7, 2024
f9b4a1c
new changes
josephchimebuka Oct 7, 2024
c5fce30
added the welcome dialog for the tutorial
josephchimebuka Oct 9, 2024
480869f
increase board size
josephchimebuka Oct 10, 2024
e9bdb6d
added tutorial mode
josephchimebuka Nov 2, 2024
45a2426
refactor code
josephchimebuka Nov 5, 2024
9e1b671
refactored code
josephchimebuka Nov 5, 2024
54b7fab
fix: correct variable names in Tutorial and ensure proper rendering i…
josephchimebuka Nov 5, 2024
6dcde81
refactored code
josephchimebuka Nov 5, 2024
e1fced7
removed setTutorial prop
josephchimebuka Nov 5, 2024
62e57b6
Merge branch 'feat-implement-tutorials-mode' of https://github.com/jo…
josephchimebuka Nov 5, 2024
ec164cc
feat: enhance components to support tutorial functionality
josephchimebuka Nov 5, 2024
3939ae0
fix: update BonusType to BonusName in components and fix function nam…
josephchimebuka Nov 5, 2024
37cdb45
refactor: update BonusType references and clean up unused tutorial code
josephchimebuka Nov 6, 2024
fdd3536
feat: restore Tutorial mode functionality in ModeType and related met…
josephchimebuka Nov 6, 2024
4607305
refactor: Tutorial mode
josephchimebuka Nov 7, 2024
0f23ff2
Merge branch 'main' into feat-implement-tutorials-mode
Cheelax Nov 17, 2024
c4758e0
fix z index and merge
Cheelax Nov 17, 2024
ff5a371
Merge branch 'z-korp:main' into feat-implement-tutorials-mode
josephchimebuka Nov 20, 2024
77afdf8
coder rabbit requested changes
josephchimebuka Nov 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19,068 changes: 19,068 additions & 0 deletions client/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions client/src/dojo/game/models/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Game {
this.over = game.over ? true : false;
this.next_row = Packer.sized_unpack(
BigInt(game.next_row),
BigInt(BLOCK_BIT_COUNT),
BigInt(BLOCK_BIT_COUNT),
DEFAULT_GRID_WIDTH,
);
this.hammer = game.hammer_bonus;
Expand All @@ -78,7 +78,6 @@ export class Game {
this.combo_counter_in_tournament = game.combo_counter_in_tournament;
this.max_combo_in_tournament = game.max_combo_in_tournament;
this.tournament_id = game.tournament_id;

// Destructure blocks and colors bitmaps in to Rows and Blocks
this.blocksRaw = game.blocks;
this.blocks = Packer.sized_unpack(
Expand Down Expand Up @@ -106,6 +105,8 @@ export class Game {
});
}



public isOver(): boolean {
return this.over;
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/dojo/game/models/tournament.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class Tournament {
ids[modeType] = Math.floor(startOfPeriod / duration);
}

return ids;
return ids;
};

determineModeById = (id: number): ModeType => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/dojo/game/types/difficulty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export enum DifficultyType {
VeryEasy = "VeryEasy",
Easy = "Easy",
Medium = "Medium",
MediumHard = "MediumHard",
MediumHard = "MediumHard",
Hard = "Hard",
VeryHard = "VeryHard",
Expert = "Expert",
Expand Down
1 change: 1 addition & 0 deletions client/src/dojo/game/types/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ export class Mode {
return BigInt(FREE_MODE_PRICE);
}
}

}
6 changes: 6 additions & 0 deletions client/src/enums/bonusEnum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export enum BonusName {
WAVE,
TIKI,
HAMMER,
NONE,
}
josephchimebuka marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion client/src/hooks/useAccountCustom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Account } from "starknet";
type AccountType = "burner" | "controller";

// eslint-disable-next-line prefer-const
export let ACCOUNT_CONNECTOR: AccountType = "controller";
export let ACCOUNT_CONNECTOR: AccountType = "burner";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will break the game, revert plz


const useAccountCustom = () => {
const { account } = useAccount();
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/useGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ export const useGame = ({
}, [component]);

return { game, gameKey };
};
};
12 changes: 12 additions & 0 deletions client/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ body {
}
}

.highlight {
border: 3px solid #ffd700; /* gold border */
box-shadow: 0px 0px 10px 5px rgba(255, 215, 0, 0.7); /* glowing effect */
transition: all 0.3s ease-in-out;

/* Respect user preferences for reduced motion */
@media (prefers-reduced-motion: reduce) {
transition: none;
box-shadow: 0px 0px 5px 2px rgba(255, 215, 0, 0.7);
}
}

.wiggle {
animation: wiggle 0.2s ease-in-out infinite;
}
Expand Down
7 changes: 6 additions & 1 deletion client/src/ui/actions/Start.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ interface StartProps {
handleGameMode: () => void;
}

export const Start: React.FC<StartProps> = ({ mode, handleGameMode }) => {
export const Start: React.FC<StartProps> = ({
mode,
handleGameMode,
potentialWinnings,
remainingTime,
}) => {
Comment on lines +29 to +34
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update StartProps interface to match implementation.

The component implementation includes potentialWinnings and remainingTime props, but these are not defined in the StartProps interface. This TypeScript type mismatch could lead to runtime issues.

Apply this diff to fix the type definitions:

interface StartProps {
  mode: ModeType;
  handleGameMode: () => void;
+ potentialWinnings?: number;  // Optional since it might not always be required
+ remainingTime?: number;      // Optional since it might not always be required
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const Start: React.FC<StartProps> = ({
mode,
handleGameMode,
potentialWinnings,
remainingTime,
}) => {
interface StartProps {
mode: ModeType;
handleGameMode: () => void;
potentialWinnings?: number; // Optional since it might not always be required
remainingTime?: number; // Optional since it might not always be required
}
export const Start: React.FC<StartProps> = ({
mode,
handleGameMode,
potentialWinnings,
remainingTime,
}) => {

💡 Codebase verification

🛠️ Refactor suggestion

Props potentialWinnings and remainingTime are not used in the component

The review comment is correct. The code inspection reveals that while these props are destructured in the component's parameters, they are not utilized anywhere in the implementation. The props appear to be related to tournament functionality (based on their usage in Leaderboard components), suggesting they could provide valuable information to players about potential rewards and time constraints.

  • client/src/ui/actions/Start.tsx: Props are declared but not used in the component's JSX or logic
  • The props are used meaningfully in other components like Leaderboard and ContentTournament, indicating their importance for game information
🔗 Analysis chain

Consider utilizing the newly added props.

The props potentialWinnings and remainingTime are received but not used in the component. If these are intended for the tutorial mode implementation, they should be integrated into the UI to show potential rewards and time constraints.

Let's check if these props are used elsewhere in the codebase:

Consider displaying these values in the UI, for example:

  return (
    <Button
      disabled={isLoading || disabled}
      isLoading={isLoading}
      onClick={handleClick}
      className={`text-lg w-full transition-transform duration-300 ease-in-out hover:scale-105 ${!isMdOrLarger && "py-6 border-4 border-white rounded-none text-white bg-sky-900 shadow-lg font-sans font-bold "}`}
    >
-     Play !
+     {potentialWinnings ? `Play for ${potentialWinnings} credits!` : 'Play!'}
+     {remainingTime ? `(${remainingTime}s remaining)` : ''}
    </Button>
  );

Let me check the complete implementation of the Start component to verify if these props are truly unused.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potentialWinnings and remainingTime usage
rg -A 5 "potentialWinnings|remainingTime" 

Length of output: 4920


Script:

#!/bin/bash
# Get the complete implementation of Start.tsx
cat client/src/ui/actions/Start.tsx

Length of output: 4105

const {
setup: {
systemCalls: { start },
Expand Down
2 changes: 1 addition & 1 deletion client/src/ui/components/ContentTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Button } from "@/ui/elements/button";
const ContentTabs = () => {
const [selectedTab, setSelectedTab] = useState("weekly-quests");

return (
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Extras</Button>
Expand Down
36 changes: 35 additions & 1 deletion client/src/ui/components/DesktopHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,42 @@ import { useCallback, useState } from "react";
import LevelIndicator from "./LevelIndicator";
import SettingsDropDown from "./SettingsDropDown";
import { useNavigate } from "react-router-dom";
import TutorialModal from "./TutorialModal";
import { Controller } from "./Controller";

const DesktopHeader = () => {


interface DesktopHeaderProps {
onStartTutorial: () => void;
}
const DesktopHeader: React.FC<DesktopHeaderProps> = ({ onStartTutorial }) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unused state variables.

The states showGrid and showTutorialText are declared but never used in the component. Consider removing them if they're not needed, or implement their intended functionality.

  const [isTutorialOpen, setIsTutorialOpen] = useState(false);
- const [showGrid, setShowGrid] = useState(false);
- const [showTutorialText, setShowTutorialText] = useState(true);

Also applies to: 26-28

const { account } = useAccountCustom();
const { player } = usePlayer({ playerId: account?.address });

const [isOpen, setIsOpen] = useState(false);
const [isTutorialOpen, setIsTutorialOpen] = useState(false);
const [showGrid, setShowGrid] = useState(false);
const [showTutorialText, setShowTutorialText] = useState(true);


const handleTutorialOpen = () => {
setIsTutorialOpen(true);
};

const handleTutorialClose = () => {
setIsTutorialOpen(false);
};

const onClose = () => {
setIsOpen(false);
};

const handleStartTutorial = () => {
handleTutorialClose();
onStartTutorial();
};


const navigate = useNavigate();

const handleClick = useCallback(() => {
Expand All @@ -41,6 +65,16 @@ const DesktopHeader = () => {
Collective Chests
</Button>
<CollectiveTreasureChest isOpen={isOpen} onClose={onClose} />
<Button
variant="outline"
onClick={(e) => {
e.stopPropagation();
handleTutorialOpen();
}}
>
Tutorial
</Button>
<TutorialModal isOpen={isTutorialOpen} onClose={handleTutorialClose} onStartTutorial={handleStartTutorial}/>
</div>
<div className="flex flex-col gap-4 items-center md:flex-row">
{!!player && (
Expand Down
6 changes: 3 additions & 3 deletions client/src/ui/components/GameBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { GameBonus } from "../containers/GameBonus";
import { useMediaQuery } from "react-responsive";
import { Account } from "starknet";
import Grid from "./Grid";
import { transformDataContractIntoBlock } from "@/utils/gridUtils";
import { transformDataContratIntoBlock } from "@/utils/gridUtils";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix typo in function name transformDataContratIntoBlock

The function name appears to contain a typo ('Contrat' instead of 'Contract'). This should be corrected to maintain code clarity and prevent confusion.

-import { transformDataContratIntoBlock } from "@/utils/gridUtils";
+import { transformDataContractIntoBlock } from "@/utils/gridUtils";

Also update the usage:

-    return transformDataContratIntoBlock(initialGrid);
+    return transformDataContractIntoBlock(initialGrid);

Also applies to: 200-200, 204-204

import NextLine from "./NextLine";
import { Block } from "@/types/types";
import GameScores from "./GameScores";
Expand Down Expand Up @@ -197,11 +197,11 @@ const GameBoard: React.FC<GameBoardProps> = ({
}, [initialGrid]);

const memoizedInitialData = useMemo(() => {
return transformDataContractIntoBlock(initialGrid);
return transformDataContratIntoBlock(initialGrid);
}, [initialGrid]);

const memoizedNextLineData = useMemo(() => {
return transformDataContractIntoBlock([nextLine]);
return transformDataContratIntoBlock([nextLine]);
// initialGrid on purpose
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [initialGrid]);
Expand Down
Loading
Loading