Skip to content

Commit

Permalink
Merge pull request #231 from dojoengine/feat/state
Browse files Browse the repository at this point in the history
fix: docs and example
  • Loading branch information
ponderingdemocritus committed Jul 2, 2024
2 parents c3e260d + eb28675 commit f73e08c
Show file tree
Hide file tree
Showing 26 changed files with 80 additions and 52 deletions.
2 changes: 1 addition & 1 deletion examples/dojo-starter
4 changes: 3 additions & 1 deletion examples/react/react-app/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
## React-app
## Dojo React Vite App

[book](https://book.dojoengine.org/)
2 changes: 0 additions & 2 deletions examples/react/react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ function App() {
const moves = useComponentValue(Moves, entityId);
const directions = useComponentValue(DirectionsAvailable, entityId);

console.log("directions", directions);

const handleRestoreBurners = async () => {
try {
await account?.applyFromClipboard();
Expand Down
1 change: 0 additions & 1 deletion examples/react/react-app/src/assets/react.svg

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-app/src/dojo/generated/generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-app/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
6 changes: 2 additions & 4 deletions examples/react/react-phaser-example/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
## Phaser
## Dojo Phaser React App

### Instructions

When running `components` script to generate a component file, make sure to replace already given **World address** with the World Address you get after running `sozo migrate`.
[book](https://book.dojoengine.org/)
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../utils";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-pwa-app/src/dojo/generated/generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-pwa-app/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-threejs/src/dojo/generated/generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/react/react-threejs/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/react/starknet-react-app/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* Autogenerated file. Do not edit manually. */
/*
* Autogenerated file. Do not edit manually.
* Generated using @dojoengine/core
* Command: npx @dojoengine/core <MANIFEST_LOCATION> <OUTPUT_PATH> <RPC_URL> <WORLD_ADDRESS>
*/

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

Expand Down
2 changes: 0 additions & 2 deletions examples/vue/vue-app/src/dojo/generated/generated.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { Account, AccountInterface } from "starknet";
import { DojoProvider } from "@dojoengine/core";
import { Direction } from "../../utils";
Expand Down
2 changes: 0 additions & 2 deletions examples/vue/vue-app/src/dojo/generated/world.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Autogenerated file. Do not edit manually. */

import { createWorld } from "@dojoengine/recs";

export const world = createWorld();
26 changes: 26 additions & 0 deletions packages/state/src/recs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import {
import { Client } from "@dojoengine/torii-client";
import { convertValues } from "../utils";

/**
* Fetches and synchronizes entities with their components.
* @param client - The client instance for API communication.
* @param components - An array of component definitions.
* @param entities - An array of entities to synchronize.
* @param limit - The maximum number of entities to fetch per request (default: 100).
* @returns A promise that resolves when synchronization is complete.
*/
export const getSyncEntities = async <S extends Schema>(
client: Client,
components: Component<S, Metadata, undefined>[],
Expand All @@ -19,6 +27,12 @@ export const getSyncEntities = async <S extends Schema>(
return await syncEntities(client, components, entities);
};

/**
* Fetches all entities and their components from the client.
* @param client - The client instance for API communication.
* @param components - An array of component definitions.
* @param limit - The maximum number of entities to fetch per request (default: 100).
*/
export const getEntities = async <S extends Schema>(
client: Client,
components: Component<S, Metadata, undefined>[],
Expand All @@ -40,6 +54,13 @@ export const getEntities = async <S extends Schema>(
}
};

/**
* Sets up a subscription to sync entity updates.
* @param client - The client instance for API communication.
* @param components - An array of component definitions.
* @param entities - An array of entities to watch for updates.
* @returns A promise that resolves with the subscription handler.
*/
export const syncEntities = async <S extends Schema>(
client: Client,
components: Component<S, Metadata, undefined>[],
Expand All @@ -50,6 +71,11 @@ export const syncEntities = async <S extends Schema>(
});
};

/**
* Updates the components of entities in the local state.
* @param entities - An array of entities with their updated component data.
* @param components - An array of component definitions.
*/
export const setEntities = async <S extends Schema>(
entities: any[],
components: Component<S, Metadata, undefined>[]
Expand Down
2 changes: 1 addition & 1 deletion packages/torii-wasm/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -ex

# # Clone the repository
git clone https://github.com/dojoengine/dojo.c dojo.c
git clone --depth 1 --branch v0.7.0 https://github.com/dojoengine/dojo.c dojo.c
cd dojo.c

set -ex
Expand Down
29 changes: 17 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Dojo.js is the official JavaScript SDK for interacting with Dojo worlds. It is c

Bootstrap a dojo world like so. You will need [dojo](https://github.com/dojoengine/dojo) installed.

```console
```bash
npx @dojoengine/create-dojo
```

Expand All @@ -34,7 +34,7 @@ npx @dojoengine/create-dojo

From the repository root, run the following to install all the necessary package dependencies:

```console
```bash
pnpm i
```

Expand All @@ -44,21 +44,21 @@ pnpm i

To build all packages, from the root directory, run:

```console
```bash
pnpm run build
```

To watch for changes on all packages in parallel, from the root directory, run:

```console
```bash
pnpm run build-watch
```

#### Dojo starter:

To install dojo-starter submodule (which allows interactions with the examples), run:

```console
```bash
git submodule update --init --recursive
```

Expand All @@ -68,7 +68,7 @@ git submodule update --init --recursive

If you have issues on WSL, install package first then run command:

```console
```bash
npm i @dojoengine/create-dojo -g
npx @dojoengine/create-dojo
```
Expand All @@ -79,22 +79,27 @@ To run the examples that have the linked packages, follow the steps below:

**Terminal 1**: Set up the dojo starter with specific configurations.

```console
```bash
cd examples/dojo-starter
katana --disable-fee --block-time 1000
katana --disable-fee --allowed-origins "*"
```

**Terminal 2**: Build and migrate the dojo starter.

```console
```bash
cd examples/dojo-starter

# Build and migrate
sozo build
sozo migrate
sozo migrate apply

# Run Torii
torii --world 0xb4079627ebab1cd3cf9fd075dda1ad2454a7a448bf659591f259efa2519b18 --allowed-origins "*"
```

**Terminal 3**: Start the React app.
**Terminal 3**: Start the App

```console
```bash
cd examples/<package>
pnpm install
pnpm run dev
Expand Down

0 comments on commit f73e08c

Please sign in to comment.