Skip to content

Commit ac99ffa

Browse files
fix: merge
2 parents 6eabbf4 + 6450e1a commit ac99ffa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+4127
-4033
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
run: git submodule update --init --recursive
2121

2222
- run: curl -L https://install.dojoengine.org | bash
23-
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.0.0-alpha.12
23+
- run: /home/runner/.config/.dojo/bin/dojoup -v v1.0.0-rc.0
2424
- run: |
2525
cd worlds/dojo-starter
2626
/home/runner/.config/.dojo/bin/sozo build

.github/workflows/docs.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "typedoc"
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
permissions:
8+
contents: read
9+
pages: write
10+
id-token: write
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: pnpm/action-setup@v2
18+
with:
19+
version: 8
20+
21+
- name: Install Protobuf Compiler
22+
run: sudo apt-get install -y protobuf-compiler
23+
24+
- name: Install dependencies
25+
run: pnpm install
26+
27+
- name: Build dependencies
28+
run: pnpm run build
29+
30+
- name: Build docs
31+
run: pnpm run docs
32+
33+
- uses: actions/upload-pages-artifact@v2
34+
with:
35+
path: ./docs
36+
deploy:
37+
runs-on: ubuntu-latest
38+
environment:
39+
name: githubs
40+
url: ${{ steps.deployment.outputs.page_url }}
41+
needs: build
42+
steps:
43+
- name: Deploy to GitHub Pages
44+
id: deployment
45+
# https://github.com/actions/deploy-pages
46+
uses: actions/deploy-pages@v2
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { createDojoConfig } from "@dojoengine/core";
2+
3+
import manifest from "../../worlds/dojo-starter/manifests/dev/deployment/manifest.json";
4+
5+
export const dojoConfig = createDojoConfig({
6+
manifest,
7+
});

examples/example-vite-react-app-recs/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ function App() {
1616
account,
1717
} = useDojo();
1818

19+
// sync the contract components to the local state
20+
// this fetches the entities from the world and updates the local state
1921
useQuerySync(toriiClient, contractComponents as any, []);
2022

2123
const [clipboardStatus, setClipboardStatus] = useState({

examples/example-vite-react-app-recs/src/dojo/setup.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DojoConfig, DojoProvider } from "@dojoengine/core";
22
import { BurnerManager } from "@dojoengine/create-burner";
3-
import { getSyncEvents } from "@dojoengine/state";
3+
import { getSyncEntities, getSyncEvents } from "@dojoengine/state";
44
import * as torii from "@dojoengine/torii-client";
55
import { Account, ArraySignatureType } from "starknet";
66

@@ -24,6 +24,15 @@ export async function setup({ ...config }: DojoConfig) {
2424
// Define contract components based on the world configuration
2525
const contractComponents = defineContractComponents(world);
2626

27+
const getSync = await getSyncEntities(
28+
toriiClient,
29+
contractComponents as any,
30+
undefined,
31+
[],
32+
3000,
33+
true
34+
);
35+
2736
// Create client-side components that mirror the contract components
2837
const clientComponents = createClientComponents({ contractComponents });
2938

@@ -79,5 +88,6 @@ export async function setup({ ...config }: DojoConfig) {
7988
burnerManager,
8089
toriiClient,
8190
eventSync,
91+
getSync,
8292
};
8393
}

examples/example-vite-react-sdk/src/App.tsx

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import { useEffect, useMemo } from "react";
22
import { SDK, createDojoStore } from "@dojoengine/sdk";
3-
import { Schema } from "./bindings.ts";
4-
5-
import { useDojo } from "./useDojo.tsx";
63
import { getEntityIdFromKeys } from "@dojoengine/utils";
74
import { addAddressPadding } from "starknet";
85

6+
import { Models, Schema } from "./bindings.ts";
7+
import { useDojo } from "./useDojo.tsx";
8+
import useModel from "./useModel.tsx";
9+
import { useSystemCalls } from "./useSystemCalls.ts";
10+
911
export const useDojoStore = createDojoStore<Schema>();
1012

11-
function App({ db }: { db: SDK<Schema> }) {
13+
function App({ sdk }: { sdk: SDK<Schema> }) {
1214
const {
1315
account,
1416
setup: { client },
1517
} = useDojo();
1618
const state = useDojoStore((state) => state);
1719
const entities = useDojoStore((state) => state.entities);
1820

21+
const { spawn } = useSystemCalls();
22+
1923
const entityId = useMemo(
2024
() => getEntityIdFromKeys([BigInt(account?.account.address)]),
2125
[account?.account.address]
@@ -25,7 +29,7 @@ function App({ db }: { db: SDK<Schema> }) {
2529
let unsubscribe: (() => void) | undefined;
2630

2731
const subscribe = async () => {
28-
const subscription = await db.subscribeEntityQuery(
32+
const subscription = await sdk.subscribeEntityQuery(
2933
{
3034
dojo_starter: {
3135
Moves: {
@@ -39,6 +43,17 @@ function App({ db }: { db: SDK<Schema> }) {
3943
},
4044
},
4145
},
46+
Position: {
47+
$: {
48+
where: {
49+
player: {
50+
$is: addAddressPadding(
51+
account.account.address
52+
),
53+
},
54+
},
55+
},
56+
},
4257
},
4358
},
4459
(response) => {
@@ -51,7 +66,8 @@ function App({ db }: { db: SDK<Schema> }) {
5166
response.data &&
5267
response.data[0].entityId !== "0x0"
5368
) {
54-
state.setEntities(response.data);
69+
console.log("subscribed", response.data[0]);
70+
state.updateEntity(response.data[0]);
5571
}
5672
},
5773
{ logging: true }
@@ -67,12 +83,12 @@ function App({ db }: { db: SDK<Schema> }) {
6783
unsubscribe();
6884
}
6985
};
70-
}, [db, account?.account.address]);
86+
}, [sdk, account?.account.address]);
7187

7288
useEffect(() => {
7389
const fetchEntities = async () => {
7490
try {
75-
await db.getEntities(
91+
await sdk.getEntities(
7692
{
7793
dojo_starter: {
7894
Moves: {
@@ -107,15 +123,10 @@ function App({ db }: { db: SDK<Schema> }) {
107123
};
108124

109125
fetchEntities();
110-
}, [db, account?.account.address]);
126+
}, [sdk, account?.account.address]);
111127

112-
const position = useMemo(() => {
113-
return entities[entityId]?.models?.dojo_starter.Position;
114-
}, [entities]);
115-
116-
const moves = useMemo(() => {
117-
return entities[entityId]?.models?.dojo_starter.Moves;
118-
}, [entities]);
128+
const moves = useModel(entityId, Models.Moves);
129+
const position = useModel(entityId, Models.Position);
119130

120131
return (
121132
<div className="bg-black min-h-screen w-full p-4 sm:p-8">
@@ -165,11 +176,7 @@ function App({ db }: { db: SDK<Schema> }) {
165176
<div className="col-start-2">
166177
<button
167178
className="h-12 w-12 bg-gray-600 rounded-full shadow-md active:shadow-inner active:bg-gray-500 focus:outline-none text-2xl font-bold text-gray-200"
168-
onClick={async () =>
169-
await client.actions.spawn({
170-
account: account.account,
171-
})
172-
}
179+
onClick={async () => await spawn()}
173180
>
174181
+
175182
</button>
@@ -217,28 +224,10 @@ function App({ db }: { db: SDK<Schema> }) {
217224
className={`${col} h-12 w-12 bg-gray-600 rounded-full shadow-md active:shadow-inner active:bg-gray-500 focus:outline-none text-2xl font-bold text-gray-200`}
218225
key={direction}
219226
onClick={async () => {
220-
const condition =
221-
(direction === "Up" &&
222-
position?.vec?.y !==
223-
undefined &&
224-
position.vec.y > 0) ||
225-
(direction === "Left" &&
226-
position?.vec?.x !==
227-
undefined &&
228-
position.vec.x > 0) ||
229-
direction === "Right" ||
230-
direction === "Down";
231-
232-
if (!condition) {
233-
console.log(
234-
"Reached the borders of the world."
235-
);
236-
} else {
237-
await client.actions.move({
238-
account: account.account,
239-
direction: { type: direction },
240-
});
241-
}
227+
await client.actions.move({
228+
account: account.account,
229+
direction: { type: direction },
230+
});
242231
}}
243232
>
244233
{label}

examples/example-vite-react-sdk/src/bindings.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ type Schema = {
3939
};
4040
};
4141

42+
enum Models {
43+
Moves = "dojo_starter-Moves",
44+
DirectionsAvailable = "dojo_starter-DirectionsAvailable",
45+
Position = "dojo_starter-Position",
46+
}
47+
4248
const schema: Schema = {
4349
dojo_starter: {
4450
Moves: {
@@ -62,4 +68,4 @@ const schema: Schema = {
6268
};
6369

6470
export type { Schema, Moves, DirectionsAvailable, Position, Vec2 };
65-
export { Direction, schema };
71+
export { Direction, schema, Models };

examples/example-vite-react-sdk/src/main.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { init } from "@dojoengine/sdk";
88
import { Schema, schema } from "./bindings.ts";
99
import { dojoConfig } from "../dojoConfig.ts";
1010
import { DojoContextProvider } from "./DojoContext.tsx";
11-
import { setupBurner } from "./setupBurner.tsx";
11+
import { setupBurnerManager } from "@dojoengine/create-burner";
1212

1313
async function main() {
14-
const db = await init<Schema>(
14+
const sdk = await init<Schema>(
1515
{
1616
client: {
1717
rpcUrl: dojoConfig.rpcUrl,
@@ -20,21 +20,21 @@ async function main() {
2020
worldAddress: dojoConfig.manifest.world.address,
2121
},
2222
domain: {
23-
name: "Example",
23+
name: "WORLD_NAME",
2424
version: "1.0",
25-
chainId: "your-chain-id",
25+
chainId: "KATANA",
2626
revision: "1",
2727
},
2828
},
2929
schema
3030
);
3131

32-
const burnerManager = await setupBurner(dojoConfig);
33-
3432
createRoot(document.getElementById("root")!).render(
3533
<StrictMode>
36-
<DojoContextProvider burnerManager={burnerManager}>
37-
<App db={db} />
34+
<DojoContextProvider
35+
burnerManager={await setupBurnerManager(dojoConfig)}
36+
>
37+
<App sdk={sdk} />
3838
</DojoContextProvider>
3939
</StrictMode>
4040
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { useDojoStore } from "./App";
2+
import { Schema } from "./bindings";
3+
4+
/**
5+
* Custom hook to retrieve a specific model for a given entityId within a specified namespace.
6+
*
7+
* @param entityId - The ID of the entity.
8+
* @param model - The model to retrieve, specified as a string in the format "namespace-modelName".
9+
* @returns The model structure if found, otherwise undefined.
10+
*/
11+
function useModel<N extends keyof Schema, M extends keyof Schema[N] & string>(
12+
entityId: string,
13+
model: `${N}-${M}`
14+
): Schema[N][M] | undefined {
15+
const [namespace, modelName] = model.split("-") as [N, M];
16+
17+
// Select only the specific model data for the given entityId
18+
const modelData = useDojoStore(
19+
(state) =>
20+
state.entities[entityId]?.models?.[namespace]?.[modelName] as
21+
| Schema[N][M]
22+
| undefined
23+
);
24+
25+
return modelData;
26+
}
27+
28+
export default useModel;

0 commit comments

Comments
 (0)