Skip to content

Commit

Permalink
chore: refac
Browse files Browse the repository at this point in the history
  • Loading branch information
0xibs committed Jan 1, 2025
1 parent 9f01c5a commit 9d0e35d
Show file tree
Hide file tree
Showing 9 changed files with 468 additions and 287 deletions.
6 changes: 3 additions & 3 deletions client/src/components/ControlWindows/GameAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { QueryBuilder } from "@dojoengine/sdk";
import { QueryBuilder, SDK } from "@dojoengine/sdk";

Check warning on line 1 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'QueryBuilder' is defined but never used

Check warning on line 1 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'QueryBuilder' is defined but never used
import { useAccount, useConnect } from "@starknet-react/core";

Check warning on line 2 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'useConnect' is defined but never used

Check warning on line 2 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'useConnect' is defined but never used
import { getEntityIdFromKeys } from "@dojoengine/utils";
import BigNumber from "bignumber.js";

Check warning on line 4 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'BigNumber' is defined but never used

Check warning on line 4 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'BigNumber' is defined but never used
Expand All @@ -11,7 +11,7 @@ import "../../styles/GameAccount.scss";
import useModel from "../../dojo/hooks/useModel";
import { getUsernameFromAddress } from "../../utils/helpers";

const ConnectWallet = ({ sdk }) => {
const ConnectWallet = ({ sdk }: { sdk: SDK<SchemaType> }) => {
const {
account,
setup: { client },
Expand Down Expand Up @@ -106,7 +106,7 @@ const ConnectWallet = ({ sdk }) => {
);
};

const GameAccount = ({ sdk }) => {
const GameAccount = ({ sdk }: { sdk: SDK<SchemaType> }) => {
const { address } = useAccount();

Check warning on line 110 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'address' is assigned a value but never used

Check warning on line 110 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'address' is assigned a value but never used
const [pagesStack, setPagesStack] = useState<string[]>(["MAIN_PAGE"]);

Check warning on line 111 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'setPagesStack' is assigned a value but never used

Check warning on line 111 in client/src/components/ControlWindows/GameAccount.tsx

View workflow job for this annotation

GitHub Actions / node

'setPagesStack' is assigned a value but never used

Expand Down
11 changes: 4 additions & 7 deletions client/src/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DiceTwo from "../svg/DiceTwo";
import DiceThree from "../svg/DiceThree";
import DiceFour from "../svg/DiceFour";
import { useDojo } from "../dojo/hooks/useDojo";
import * as models from "../dojo/typescript/models.gen.ts";
import * as models from "../dojo/typescript/models.gen";

const Menu = () => {
const { options } = useContext(GameContext);
Expand All @@ -26,13 +26,10 @@ const Menu = () => {
}

async function start() {
await client.GameActions.create(
await client.GameActions.createNewGame(
account.account,
models.GameMode.MultiPlayer,
"ibs",
0,
0,
0,
models.GameMode.SinglePlayer,
models.PlayerColor.Green,
2
);
}
Expand Down
33 changes: 25 additions & 8 deletions client/src/dojo/typescript/contracts.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import * as models from "./models.gen";

export function setupWorld(provider: DojoProvider) {

const GameActions_create = async (snAccount: Account | AccountInterface, gameMode: models.GameMode, playerGreen: BigNumberish, playerYellow: BigNumberish, playerBlue: BigNumberish, playerRed: BigNumberish, numberOfPlayers: BigNumberish) => {
const GameActions_createNewGame = async (snAccount: Account | AccountInterface, gameMode: models.GameMode, playerColor: models.PlayerColor, numberOfPlayers: BigNumberish) => {
try {
return await provider.execute(
snAccount,
{
contractName: "GameActions",
entrypoint: "create",
calldata: [gameMode, playerGreen, playerYellow, playerBlue, playerRed, numberOfPlayers],
entrypoint: "create_new_game",
calldata: [gameMode, playerColor, numberOfPlayers],
},
"starkludo",
);
Expand All @@ -20,14 +20,14 @@ export function setupWorld(provider: DojoProvider) {
}
};

const GameActions_start = async (snAccount: Account | AccountInterface) => {
const GameActions_startGame = async (snAccount: Account | AccountInterface, gameId: BigNumberish) => {
try {
return await provider.execute(
snAccount,
{
contractName: "GameActions",
entrypoint: "start",
calldata: [],
entrypoint: "start_game",
calldata: [gameId],
},
"starkludo",
);
Expand Down Expand Up @@ -128,6 +128,22 @@ export function setupWorld(provider: DojoProvider) {
}
};

const GameActions_createBotPlayer = async (snAccount: Account | AccountInterface, botColor: models.PlayerColor) => {
try {
return await provider.execute(
snAccount,
{
contractName: "GameActions",
entrypoint: "create_bot_player",
calldata: [botColor],
},
"starkludo",
);
} catch (error) {
console.error(error);
}
};

const GameActions_getUsernameFromAddress = async (address: string) => {
try {
return await provider.call("starkludo", {
Expand All @@ -154,14 +170,15 @@ export function setupWorld(provider: DojoProvider) {

return {
GameActions: {
create: GameActions_create,
start: GameActions_start,
createNewGame: GameActions_createNewGame,
startGame: GameActions_startGame,
join: GameActions_join,
move: GameActions_move,
roll: GameActions_roll,
getCurrentGameId: GameActions_getCurrentGameId,
createNewGameId: GameActions_createNewGameId,
createNewPlayer: GameActions_createNewPlayer,
createBotPlayer: GameActions_createBotPlayer,
getUsernameFromAddress: GameActions_getUsernameFromAddress,
getAddressFromUsername: GameActions_getAddressFromUsername,
},
Expand Down
Loading

0 comments on commit 9d0e35d

Please sign in to comment.