From a33fcc4488c43312226664f82f53a004ddb0512a Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Sat, 15 Jun 2024 19:43:32 +1000 Subject: [PATCH 1/2] fix: bool state bug --- .github/workflows/ci.yaml | 2 +- examples/dojo-starter | 2 +- examples/react/react-app/package.json | 2 +- examples/react/react-app/src/App.tsx | 2 + .../src/dojo/generated/contractComponents.ts | 93 +++++++++---------- packages/state/src/recs/index.ts | 2 - packages/state/src/utils/index.ts | 1 + 7 files changed, 48 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8868075d..d482af42 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,7 +20,7 @@ jobs: run: git submodule update --init --recursive - run: curl -L https://install.dojoengine.org | bash - - run: /home/runner/.config/.dojo/bin/dojoup -v v0.7.0-alpha.5 + - run: /home/runner/.config/.dojo/bin/dojoup -v v0.7.0 - run: | cd examples/dojo-starter /home/runner/.config/.dojo/bin/sozo build diff --git a/examples/dojo-starter b/examples/dojo-starter index 358f66bc..fdab8d6b 160000 --- a/examples/dojo-starter +++ b/examples/dojo-starter @@ -1 +1 @@ -Subproject commit 358f66bcfaf5c7e83305666f7975428ba8af256d +Subproject commit fdab8d6bfcc19976448f01e5322a194e568bc48d diff --git a/examples/react/react-app/package.json b/examples/react/react-app/package.json index 7f86d2cd..189c38f3 100644 --- a/examples/react/react-app/package.json +++ b/examples/react/react-app/package.json @@ -8,7 +8,7 @@ "build": "tsc && vite build", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", - "create-components": "npx @dojoengine/core ../../dojo-starter/manifests/dev/manifest.json src/dojo/generated/contractComponents.ts http://localhost:5050 0x559e9e223d83b6a3121ba33b1339323a3bdf4c7c302078fb3e755fddc68a2fb" + "create-components": "npx @dojoengine/core ../../dojo-starter/manifests/dev/manifest.json src/dojo/generated/contractComponents.ts http://localhost:5050 0xb4079627ebab1cd3cf9fd075dda1ad2454a7a448bf659591f259efa2519b18" }, "dependencies": { "@dojoengine/core": "workspace:*", diff --git a/examples/react/react-app/src/App.tsx b/examples/react/react-app/src/App.tsx index 309a2587..b5210422 100644 --- a/examples/react/react-app/src/App.tsx +++ b/examples/react/react-app/src/App.tsx @@ -30,6 +30,8 @@ function App() { const moves = useComponentValue(Moves, entityId); const directions = useComponentValue(DirectionsAvailable, entityId); + console.log(moves); + const handleRestoreBurners = async () => { try { await account?.applyFromClipboard(); diff --git a/examples/react/react-app/src/dojo/generated/contractComponents.ts b/examples/react/react-app/src/dojo/generated/contractComponents.ts index fd453e3e..b8a7def3 100644 --- a/examples/react/react-app/src/dojo/generated/contractComponents.ts +++ b/examples/react/react-app/src/dojo/generated/contractComponents.ts @@ -2,57 +2,48 @@ import { defineComponent, Type as RecsType, World } from "@dojoengine/recs"; -export type ContractComponents = Awaited< - ReturnType ->; +export type ContractComponents = Awaited>; export function defineContractComponents(world: World) { - return { - DirectionsAvailable: (() => { - return defineComponent( - world, - { player: RecsType.BigInt, directions: RecsType.StringArray }, - { - metadata: { - name: "DirectionsAvailable", - types: ["contractaddress"], - customTypes: [], - }, - } - ); - })(), - Moves: (() => { - return defineComponent( - world, - { - player: RecsType.BigInt, - remaining: RecsType.Number, - last_direction: RecsType.Number, - }, - { - metadata: { - name: "Moves", - types: ["contractaddress", "u8", "enum"], - customTypes: ["Direction"], - }, - } - ); - })(), - Position: (() => { - return defineComponent( - world, - { - player: RecsType.BigInt, - vec: { x: RecsType.Number, y: RecsType.Number }, - }, - { - metadata: { - name: "Position", - types: ["contractaddress", "u32", "u32"], - customTypes: ["Vec2"], - }, - } - ); - })(), - }; + return { + DirectionsAvailable: (() => { + return defineComponent( + world, + { player: RecsType.BigInt, directions: RecsType.StringArray }, + { + metadata: { + name: "DirectionsAvailable", + types: ["contractaddress"], + customTypes: [], + }, + } + ); + })(), + Moves: (() => { + return defineComponent( + world, + { player: RecsType.BigInt, remaining: RecsType.Number, last_direction: RecsType.Number, can_move: RecsType.Boolean }, + { + metadata: { + name: "Moves", + types: ["contractaddress","u8","enum","bool"], + customTypes: ["Direction"], + }, + } + ); + })(), + Position: (() => { + return defineComponent( + world, + { player: RecsType.BigInt, vec: { x: RecsType.Number, y: RecsType.Number } }, + { + metadata: { + name: "Position", + types: ["contractaddress","u32","u32"], + customTypes: ["Vec2"], + }, + } + ); + })(), + }; } diff --git a/packages/state/src/recs/index.ts b/packages/state/src/recs/index.ts index bba129ac..01b61b64 100644 --- a/packages/state/src/recs/index.ts +++ b/packages/state/src/recs/index.ts @@ -30,8 +30,6 @@ export const getEntities = async ( while (continueFetching) { const entities = await client.getAllEntities(limit, cursor); - console.log("load entities", entities); - setEntities(entities, components); if (Object.keys(entities).length < limit) { diff --git a/packages/state/src/utils/index.ts b/packages/state/src/utils/index.ts index f3320857..a47005cd 100644 --- a/packages/state/src/utils/index.ts +++ b/packages/state/src/utils/index.ts @@ -35,6 +35,7 @@ export function convertValues(schema: Schema, values: any) { case RecsType.String: case RecsType.BigInt: + case RecsType.Boolean: case RecsType.Number: acc[key] = value.value; break; From 2a5fbab07af9604f1d7ebadc4c3c2678ec89115b Mon Sep 17 00:00:00 2001 From: ponderingdemocritus Date: Sat, 15 Jun 2024 19:44:51 +1000 Subject: [PATCH 2/2] fix: bump submodule --- examples/dojo-starter | 2 +- .../src/dojo/generated/contractComponents.ts | 94 ++++++++++--------- 2 files changed, 53 insertions(+), 43 deletions(-) diff --git a/examples/dojo-starter b/examples/dojo-starter index fdab8d6b..26403c65 160000 --- a/examples/dojo-starter +++ b/examples/dojo-starter @@ -1 +1 @@ -Subproject commit fdab8d6bfcc19976448f01e5322a194e568bc48d +Subproject commit 26403c656d26c14cdb06194842c4b87c9bcaf20d diff --git a/examples/react/react-app/src/dojo/generated/contractComponents.ts b/examples/react/react-app/src/dojo/generated/contractComponents.ts index b8a7def3..9592e0f1 100644 --- a/examples/react/react-app/src/dojo/generated/contractComponents.ts +++ b/examples/react/react-app/src/dojo/generated/contractComponents.ts @@ -2,48 +2,58 @@ import { defineComponent, Type as RecsType, World } from "@dojoengine/recs"; -export type ContractComponents = Awaited>; +export type ContractComponents = Awaited< + ReturnType +>; export function defineContractComponents(world: World) { - return { - DirectionsAvailable: (() => { - return defineComponent( - world, - { player: RecsType.BigInt, directions: RecsType.StringArray }, - { - metadata: { - name: "DirectionsAvailable", - types: ["contractaddress"], - customTypes: [], - }, - } - ); - })(), - Moves: (() => { - return defineComponent( - world, - { player: RecsType.BigInt, remaining: RecsType.Number, last_direction: RecsType.Number, can_move: RecsType.Boolean }, - { - metadata: { - name: "Moves", - types: ["contractaddress","u8","enum","bool"], - customTypes: ["Direction"], - }, - } - ); - })(), - Position: (() => { - return defineComponent( - world, - { player: RecsType.BigInt, vec: { x: RecsType.Number, y: RecsType.Number } }, - { - metadata: { - name: "Position", - types: ["contractaddress","u32","u32"], - customTypes: ["Vec2"], - }, - } - ); - })(), - }; + return { + DirectionsAvailable: (() => { + return defineComponent( + world, + { player: RecsType.BigInt, directions: RecsType.StringArray }, + { + metadata: { + name: "DirectionsAvailable", + types: ["contractaddress"], + customTypes: [], + }, + } + ); + })(), + Moves: (() => { + return defineComponent( + world, + { + player: RecsType.BigInt, + remaining: RecsType.Number, + last_direction: RecsType.Number, + can_move: RecsType.Boolean, + }, + { + metadata: { + name: "Moves", + types: ["contractaddress", "u8", "enum", "bool"], + customTypes: ["Direction"], + }, + } + ); + })(), + Position: (() => { + return defineComponent( + world, + { + player: RecsType.BigInt, + vec: { x: RecsType.Number, y: RecsType.Number }, + }, + { + metadata: { + name: "Position", + types: ["contractaddress", "u32", "u32"], + customTypes: ["Vec2"], + }, + } + ); + })(), + }; }