Skip to content

Commit b373dd0

Browse files
feat: update examplee
1 parent f1b0d97 commit b373dd0

File tree

7 files changed

+3385
-3335
lines changed

7 files changed

+3385
-3335
lines changed

examples/clients/react/react-sdk/src/App.tsx

+20-11
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import { useEffect, useState } from "react";
22
import "./App.css";
33
import { ParsedEntity, init } from "@dojoengine/sdk";
44
import { dojoConfig } from "../dojoConfig.ts";
5-
import { Schema } from "./bindings.ts";
5+
import { Schema, schema } from "./bindings.ts";
66

7-
const db = await init<Schema>({
8-
rpcUrl: dojoConfig.rpcUrl,
9-
toriiUrl: dojoConfig.toriiUrl,
10-
relayUrl: dojoConfig.relayUrl,
11-
worldAddress:
12-
"0x5d475a9221f6cbf1a016b12400a01b9a89935069aecd57e9876fcb2a7bb29da",
13-
});
7+
const db = await init<Schema>(
8+
{
9+
rpcUrl: dojoConfig.rpcUrl,
10+
toriiUrl: dojoConfig.toriiUrl,
11+
relayUrl: dojoConfig.relayUrl,
12+
worldAddress:
13+
"0x5d475a9221f6cbf1a016b12400a01b9a89935069aecd57e9876fcb2a7bb29da",
14+
},
15+
schema
16+
);
1417

1518
function App() {
1619
const [entities, setEntities] = useState<ParsedEntity<Schema>[]>([]);
@@ -22,8 +25,11 @@ function App() {
2225
const subscription = await db.subscribeEntityQuery(
2326
{
2427
dojo_starter: {
25-
Position: [],
26-
Moves: ["player"],
28+
Moves: {
29+
$: {
30+
where: { remaining: { $is: 22 } },
31+
},
32+
},
2733
},
2834
},
2935
(response) => {
@@ -36,6 +42,7 @@ function App() {
3642
response.data &&
3743
response.data[0].entityId !== "0x0"
3844
) {
45+
console.log(response.data);
3946
setEntities((prevEntities) => {
4047
return prevEntities.map((entity) => {
4148
const newEntity = response.data?.find(
@@ -45,7 +52,8 @@ function App() {
4552
});
4653
});
4754
}
48-
}
55+
},
56+
{ logging: true }
4957
);
5058

5159
unsubscribe = () => subscription.cancel();
@@ -80,6 +88,7 @@ function App() {
8088
return;
8189
}
8290
if (resp.data) {
91+
console.log(resp.data);
8392
setEntities((prevEntities) => {
8493
const updatedEntities = [...prevEntities];
8594
resp.data?.forEach((newEntity) => {

examples/clients/react/react-sdk/src/bindings.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
interface Moves {
2+
fieldOrder: string[];
23
player: string;
34
remaining: number;
45
last_direction: Direction;
56
can_move: boolean;
67
}
78

89
interface DirectionsAvailable {
10+
fieldOrder: string[];
911
player: string;
1012
directions: Direction[];
1113
}
1214

1315
interface Position {
16+
fieldOrder: string[];
1417
player: string;
1518
vec: Vec2;
1619
}
@@ -36,5 +39,27 @@ type Schema = {
3639
};
3740
};
3841

42+
const schema: Schema = {
43+
dojo_starter: {
44+
Moves: {
45+
fieldOrder: ["player", "remaining", "last_direction", "can_move"],
46+
player: "",
47+
remaining: 0,
48+
last_direction: Direction.None,
49+
can_move: false,
50+
},
51+
DirectionsAvailable: {
52+
fieldOrder: ["player", "directions"],
53+
player: "",
54+
directions: [],
55+
},
56+
Position: {
57+
fieldOrder: ["player", "vec"],
58+
player: "",
59+
vec: { x: 0, y: 0 },
60+
},
61+
},
62+
};
63+
3964
export type { Schema, Moves, DirectionsAvailable, Position, Vec2 };
40-
export { Direction };
65+
export { Direction, schema };

0 commit comments

Comments
 (0)