Skip to content

Commit e83bfde

Browse files
feat: examples
1 parent 4effc6b commit e83bfde

File tree

9 files changed

+221
-101
lines changed

9 files changed

+221
-101
lines changed

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ import "./App.css";
22
import { useComponentValue, useQuerySync } from "@dojoengine/react";
33
import { Entity } from "@dojoengine/recs";
44
import { useEffect, useState } from "react";
5-
import { Direction } from "./utils";
65
import { getEntityIdFromKeys } from "@dojoengine/utils";
76
import { useDojo } from "./dojo/useDojo";
7+
import { Direction } from "./dojo/typescript/models.gen";
8+
9+
enum DirectionEnum {
10+
None = "0",
11+
Left = "Left",
12+
Right = "Right",
13+
Up = "Up",
14+
Down = "Down",
15+
}
816

917
function App() {
1018
const {
@@ -139,7 +147,9 @@ function App() {
139147
<button
140148
onClick={() =>
141149
position && position.vec.y > 0
142-
? move(account.account, Direction.Up)
150+
? move(account.account, {
151+
type: DirectionEnum.Up,
152+
})
143153
: console.log("Reach the borders of the world.")
144154
}
145155
>
@@ -150,21 +160,27 @@ function App() {
150160
<button
151161
onClick={() =>
152162
position && position.vec.x > 0
153-
? move(account.account, Direction.Left)
163+
? move(account.account, {
164+
type: DirectionEnum.Left,
165+
})
154166
: console.log("Reach the borders of the world.")
155167
}
156168
>
157169
Move Left
158170
</button>
159171
<button
160-
onClick={() => move(account.account, Direction.Right)}
172+
onClick={() =>
173+
move(account.account, { type: DirectionEnum.Right })
174+
}
161175
>
162176
Move Right
163177
</button>
164178
</div>
165179
<div>
166180
<button
167-
onClick={() => move(account.account, Direction.Down)}
181+
onClick={() =>
182+
move(account.account, { type: DirectionEnum.Down })
183+
}
168184
>
169185
Move Down
170186
</button>

examples/clients/react/react-app/src/dojo/createSystemCalls.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
} from "@dojoengine/recs";
1010
import { uuid } from "@latticexyz/utils";
1111
import { ClientComponents } from "./createClientComponents";
12-
import { Direction, updatePositionWithDirection } from "../utils";
1312
import { getEntityIdFromKeys } from "@dojoengine/utils";
1413
import type { IWorld } from "./typescript/contracts.gen";
14+
import { Direction } from "./typescript/models.gen";
1515

1616
export type SystemCalls = ReturnType<typeof createSystemCalls>;
1717

@@ -81,34 +81,10 @@ export function createSystemCalls(
8181
BigInt(account.address),
8282
]) as Entity;
8383

84-
// Update the state before the transaction
85-
// const positionId = uuid();
86-
// Position.addOverride(positionId, {
87-
// entity: entityId,
88-
// value: {
89-
// player: BigInt(entityId),
90-
// vec: updatePositionWithDirection(
91-
// direction,
92-
// getComponentValue(Position, entityId) as any
93-
// ).vec,
94-
// },
95-
// });
96-
97-
// // Update the state before the transaction
98-
// const movesId = uuid();
99-
// Moves.addOverride(movesId, {
100-
// entity: entityId,
101-
// value: {
102-
// player: BigInt(entityId),
103-
// remaining:
104-
// (getComponentValue(Moves, entityId)?.remaining || 0) - 1,
105-
// },
106-
// });
107-
10884
try {
10985
await client.actions.move({
11086
account,
111-
direction: { type: "Left" },
87+
direction,
11288
});
11389

11490
// Wait for the indexer to update the entity
Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +0,0 @@
1-
export enum Direction {
2-
Left = 1,
3-
Right = 2,
4-
Up = 3,
5-
Down = 4,
6-
}
7-
8-
export function updatePositionWithDirection(
9-
direction: Direction,
10-
value: { vec: { x: number; y: number } }
11-
) {
12-
switch (direction) {
13-
case Direction.Left:
14-
value.vec.x--;
15-
break;
16-
case Direction.Right:
17-
value.vec.x++;
18-
break;
19-
case Direction.Up:
20-
value.vec.y--;
21-
break;
22-
case Direction.Down:
23-
value.vec.y++;
24-
break;
25-
default:
26-
throw new Error("Invalid direction provided");
27-
}
28-
return value;
29-
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ function App() {
2828
Moves: {
2929
$: {
3030
where: {
31-
can_move: { $is: true },
32-
last_direction: { $is: "Down" },
31+
player: {
32+
$is: "0x3628a39cc6bd2347e79967e9458ac41ab65bac6949f2aa311b311aff0d7334d",
33+
},
3334
},
3435
},
3536
},

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ interface Position {
1919
}
2020

2121
enum Direction {
22-
None,
23-
Left,
24-
Right,
25-
Up,
26-
Down,
22+
None = "0",
23+
Left = "1",
24+
Right = "2",
25+
Up = "3",
26+
Down = "4",
2727
}
2828

2929
interface Vec2 {

packages/sdk/package.json

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@dojoengine/sdk",
33
"version": "1.0.0-alpha.11",
4-
"description": "Dojo SDK for interacting with the Dojo engine.",
4+
"description": "Dojo SDK for interacting with the Dojo provable game engine.",
55
"author": "Dojo Team",
66
"license": "MIT",
77
"main": "dist/index.js",
@@ -10,26 +10,52 @@
1010
"build": "tsup --dts-resolve",
1111
"test": "vitest run --config ./vitest.config.ts",
1212
"coverage": "vitest run --coverage",
13-
"lint": "eslint . --ext .ts,.tsx"
13+
"lint": "eslint . --ext .ts,.tsx",
14+
"dev": "vite",
15+
"format": "prettier --write ."
1416
},
1517
"exports": {
1618
".": {
1719
"import": "./dist/index.js",
1820
"types": "./dist/index.d.ts"
19-
}
21+
},
22+
"./package.json": "./package.json"
2023
},
2124
"devDependencies": {
2225
"@vitest/coverage-v8": "^1.3.0",
2326
"tsup": "^8.0.1",
2427
"typescript": "^5.5.4",
25-
"vitest": "^1.6.0"
28+
"vitest": "^1.6.0",
29+
"eslint": "^8.30.0",
30+
"prettier": "^2.7.1",
31+
"vite": "^3.2.3"
2632
},
2733
"peerDependencies": {
2834
"starknet": "6.11.0"
2935
},
3036
"dependencies": {
3137
"@dojoengine/torii-client": "workspace:*",
3238
"vite-plugin-wasm": "^3.3.0",
33-
"zustand": "^4.5.2"
39+
"zustand": "^4.5.2",
40+
"axios": "^0.27.2",
41+
"lodash": "^4.17.21"
42+
},
43+
"repository": {
44+
"type": "git",
45+
"url": "https://github.com/dojoengine/sdk.git"
46+
},
47+
"bugs": {
48+
"url": "https://github.com/dojoengine/sdk/issues"
49+
},
50+
"homepage": "https://github.com/dojoengine/sdk#readme",
51+
"keywords": [
52+
"dojo",
53+
"sdk",
54+
"engine",
55+
"typescript",
56+
"torii"
57+
],
58+
"engines": {
59+
"node": ">=14.0.0"
3460
}
3561
}

0 commit comments

Comments
 (0)