Skip to content

Commit a8dc7c1

Browse files
feat: add example, fix clauses, enable namespaces
1 parent 82465cb commit a8dc7c1

39 files changed

+2068
-899
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# React + TypeScript + Vite
2+
3+
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4+
5+
Currently, two official plugins are available:
6+
7+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9+
10+
## Expanding the ESLint configuration
11+
12+
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13+
14+
- Configure the top-level `parserOptions` property like this:
15+
16+
```js
17+
export default tseslint.config({
18+
languageOptions: {
19+
// other options...
20+
parserOptions: {
21+
project: ["./tsconfig.node.json", "./tsconfig.app.json"],
22+
tsconfigRootDir: import.meta.dirname,
23+
},
24+
},
25+
});
26+
```
27+
28+
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
29+
- Optionally add `...tseslint.configs.stylisticTypeChecked`
30+
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:
31+
32+
```js
33+
// eslint.config.js
34+
import react from "eslint-plugin-react";
35+
36+
export default tseslint.config({
37+
// Set the react version
38+
settings: { react: { version: "18.3" } },
39+
plugins: {
40+
// Add the react plugin
41+
react,
42+
},
43+
rules: {
44+
// other rules...
45+
// Enable its recommended rules
46+
...react.configs.recommended.rules,
47+
...react.configs["jsx-runtime"].rules,
48+
},
49+
});
50+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import manifest from "../../../dojo/dojo-starter/manifests/dev/deployment/manifest.json";
2+
3+
import { createDojoConfig } from "@dojoengine/core";
4+
5+
export const dojoConfig = createDojoConfig({
6+
manifest,
7+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import js from "@eslint/js";
2+
import globals from "globals";
3+
import reactHooks from "eslint-plugin-react-hooks";
4+
import reactRefresh from "eslint-plugin-react-refresh";
5+
import tseslint from "typescript-eslint";
6+
7+
export default tseslint.config(
8+
{ ignores: ["dist"] },
9+
{
10+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
11+
files: ["**/*.{ts,tsx}"],
12+
languageOptions: {
13+
ecmaVersion: 2020,
14+
globals: globals.browser,
15+
},
16+
plugins: {
17+
"react-hooks": reactHooks,
18+
"react-refresh": reactRefresh,
19+
},
20+
rules: {
21+
...reactHooks.configs.recommended.rules,
22+
"react-refresh/only-export-components": [
23+
"warn",
24+
{ allowConstantExport: true },
25+
],
26+
},
27+
}
28+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "react-sdk",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "tsc -b && vite build",
9+
"lint": "eslint .",
10+
"preview": "vite preview"
11+
},
12+
"dependencies": {
13+
"@dojoengine/core": "1.0.0-alpha.12",
14+
"@dojoengine/sdk": "workspace:*",
15+
"@dojoengine/torii-wasm": "1.0.0-alpha.12",
16+
"react": "^18.3.1",
17+
"react-dom": "^18.3.1",
18+
"vite-plugin-top-level-await": "^1.4.4",
19+
"vite-plugin-wasm": "^3.3.0"
20+
},
21+
"devDependencies": {
22+
"@eslint/js": "^9.9.0",
23+
"@types/react": "^18.3.3",
24+
"@types/react-dom": "^18.3.0",
25+
"@vitejs/plugin-react": "^4.3.1",
26+
"eslint": "^9.9.0",
27+
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
28+
"eslint-plugin-react-refresh": "^0.4.9",
29+
"globals": "^15.9.0",
30+
"typescript": "^5.5.3",
31+
"typescript-eslint": "^8.0.1",
32+
"vite": "^5.4.1"
33+
}
34+
}
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#root {
2+
max-width: 1280px;
3+
margin: 0 auto;
4+
padding: 2rem;
5+
text-align: center;
6+
}
7+
8+
.logo {
9+
height: 6em;
10+
padding: 1.5em;
11+
will-change: filter;
12+
transition: filter 300ms;
13+
}
14+
.logo:hover {
15+
filter: drop-shadow(0 0 2em #646cffaa);
16+
}
17+
.logo.react:hover {
18+
filter: drop-shadow(0 0 2em #61dafbaa);
19+
}
20+
21+
@keyframes logo-spin {
22+
from {
23+
transform: rotate(0deg);
24+
}
25+
to {
26+
transform: rotate(360deg);
27+
}
28+
}
29+
30+
@media (prefers-reduced-motion: no-preference) {
31+
a:nth-of-type(2) .logo {
32+
animation: logo-spin infinite 20s linear;
33+
}
34+
}
35+
36+
.card {
37+
padding: 2em;
38+
}
39+
40+
.read-the-docs {
41+
color: #888;
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import { useEffect, useState } from "react";
2+
import reactLogo from "./assets/react.svg";
3+
import viteLogo from "/vite.svg";
4+
import "./App.css";
5+
import { init } from "@dojoengine/sdk";
6+
7+
import { dojoConfig } from "../dojoConfig.ts";
8+
import { Subscription } from "@dojoengine/torii-wasm";
9+
10+
interface Moves {
11+
player: string;
12+
remaining: number;
13+
last_direction: Direction;
14+
can_move: boolean;
15+
}
16+
17+
interface DirectionsAvailable {
18+
player: string;
19+
directions: Direction[];
20+
}
21+
22+
interface Position {
23+
player: string;
24+
vec: Vec2;
25+
}
26+
27+
enum Direction {
28+
None,
29+
Left,
30+
Right,
31+
Up,
32+
Down,
33+
}
34+
35+
interface Vec2 {
36+
x: number;
37+
y: number;
38+
}
39+
40+
type Schema = {
41+
dojo_starter: {
42+
moves: Moves;
43+
directionsAvailable: DirectionsAvailable;
44+
position: Position;
45+
};
46+
};
47+
48+
const db = await init<Schema>({
49+
rpcUrl: dojoConfig.rpcUrl,
50+
toriiUrl: dojoConfig.toriiUrl,
51+
relayUrl: dojoConfig.relayUrl,
52+
worldAddress:
53+
"0x5d475a9221f6cbf1a016b12400a01b9a89935069aecd57e9876fcb2a7bb29da",
54+
});
55+
56+
function App() {
57+
// useEffect(() => {
58+
// let unsubscribe: Subscription | undefined;
59+
60+
// const subscribe = async () => {
61+
// try {
62+
// unsubscribe = await db.subscribeQuery(
63+
// {
64+
// moves: {},
65+
// },
66+
// (resp) => {
67+
// if (resp.error) {
68+
// console.error(
69+
// "Error querying moves:",
70+
// resp.error.message
71+
// );
72+
// return;
73+
// }
74+
// if (resp.data) {
75+
// console.log("Moves for player 123:", resp.data);
76+
// }
77+
// },
78+
// { logging: true }
79+
// );
80+
// } catch (error) {
81+
// console.error("Subscription error:", error);
82+
// }
83+
// };
84+
85+
// subscribe();
86+
87+
// return () => {
88+
// if (unsubscribe) {
89+
// unsubscribe.cancel();
90+
// console.log("Unsubscribed from moves query");
91+
// }
92+
// };
93+
// }, []);
94+
95+
useEffect(() => {
96+
const fetchEntities = async () => {
97+
try {
98+
const entities = await db.getEntities(
99+
{
100+
dojo_starter: {
101+
moves: {
102+
$: {
103+
where: {
104+
remaining: {
105+
$eq: 97,
106+
},
107+
},
108+
},
109+
},
110+
},
111+
},
112+
(resp) => {
113+
if (resp.error) {
114+
console.error(
115+
"Error querying completed important tasks:",
116+
resp.error.message
117+
);
118+
return;
119+
}
120+
if (resp.data) {
121+
console.log(
122+
"Completed important tasks:",
123+
resp.data
124+
);
125+
}
126+
}
127+
);
128+
console.log("Queried entities:", entities.dojo_starter);
129+
} catch (error) {
130+
console.error("Error querying entities:", error);
131+
}
132+
};
133+
134+
fetchEntities();
135+
}, []);
136+
return <></>;
137+
}
138+
139+
export default App;
Loading

0 commit comments

Comments
 (0)