-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c5aa5f
commit 5a26d4d
Showing
32 changed files
with
3,503 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
## Bare Bones Dojo world using only React State and torii client | ||
|
||
### 1. Build Contracts | ||
|
||
### 2. Generate Bindings | ||
|
||
Run from within the vite app | ||
|
||
``` | ||
sozo build --typescript --manifest-path ../../contracts/Scarb.toml --bindings-output ./src | ||
``` | ||
|
||
### 3. Run App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:react-hooks/recommended", | ||
], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { ecmaVersion: "latest", sourceType: "module" }, | ||
plugins: ["react-refresh"], | ||
rules: { | ||
"react-refresh/only-export-components": "warn", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Dojo | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "https://ui.shadcn.com/schema.json", | ||
"style": "default", | ||
"rsc": false, | ||
"tsx": true, | ||
"tailwind": { | ||
"config": "tailwind.config.js", | ||
"css": "src/index.css", | ||
"baseColor": "slate", | ||
"cssVariables": true, | ||
"prefix": "" | ||
}, | ||
"aliases": { | ||
"components": "@/components", | ||
"utils": "@/lib/utils" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import manifest from "../../contracts/manifests/dev/deployment/manifest.json"; | ||
|
||
import { createDojoConfig } from "@dojoengine/core"; | ||
|
||
export const dojoConfig = createDojoConfig({ | ||
manifest, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Dojo React Vite</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "react-example", | ||
"private": false, | ||
"version": "0.0.1", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@dojoengine/core": "1.0.0-alpha.6", | ||
"@dojoengine/create-burner": "1.0.0-alpha.6", | ||
"@dojoengine/react": "1.0.0-alpha.6", | ||
"@dojoengine/recs": "2.0.13", | ||
"@dojoengine/state": "1.0.0-alpha.6", | ||
"@dojoengine/torii-client": "1.0.0-alpha.6", | ||
"@dojoengine/utils": "1.0.0-alpha.6", | ||
"@latticexyz/react": "^2.0.12", | ||
"@latticexyz/utils": "^2.0.12", | ||
"@radix-ui/react-slot": "^1.1.0", | ||
"autoprefixer": "^10.4.20", | ||
"class-variance-authority": "^0.7.0", | ||
"clsx": "^2.1.1", | ||
"ethers": "^5.7.2", | ||
"lucide-react": "^0.429.0", | ||
"mobx": "^6.9.0", | ||
"postcss": "^8.4.41", | ||
"proxy-deep": "^3.1.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"rxjs": "^7.8.1", | ||
"starknet": "6.11.0", | ||
"tailwind-merge": "^2.5.2", | ||
"tailwindcss": "^3.4.10", | ||
"tailwindcss-animate": "^1.0.7", | ||
"vite-plugin-top-level-await": "^1.3.1", | ||
"vite-plugin-wasm": "^3.2.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.16.1", | ||
"@types/react": "^18.2.33", | ||
"@types/react-dom": "^18.0.11", | ||
"@typescript-eslint/eslint-plugin": "^5.59.0", | ||
"@typescript-eslint/parser": "^5.59.0", | ||
"@vitejs/plugin-react": "^4.0.0", | ||
"eslint": "^8.38.0", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.3.4", | ||
"typescript": "^5.5.4", | ||
"vite": "^5.4.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Dojo React Vite App | ||
|
||
[book](https://book.dojoengine.org/) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import "./App.css"; | ||
import { useComponentValue } from "@dojoengine/react"; | ||
import { Entity } from "@dojoengine/recs"; | ||
import { getEntityIdFromKeys } from "@dojoengine/utils"; | ||
import { useDojo } from "./dojo/useDojo"; | ||
import { Button } from "./components/ui/button"; | ||
import * as torii from "@dojoengine/torii-client"; | ||
|
||
function App() { | ||
const { | ||
setup: { | ||
clientComponents: { Dungeon, Player }, | ||
toriiClient, | ||
client, | ||
contractComponents, | ||
}, | ||
account: { account }, | ||
} = useDojo(); | ||
|
||
// entity id we are syncing | ||
const entityId = getEntityIdFromKeys([BigInt(account.address)]) as Entity; | ||
|
||
const player = useComponentValue(Player, entityId); | ||
|
||
console.log(player); | ||
|
||
return ( | ||
<> | ||
<div className="bg-black text-green-600 h-screen w-screen p-10"> | ||
<h4>RPG Starter</h4> | ||
<div className="mb-1"> | ||
<Button | ||
onClick={async () => { | ||
await client.actions.spawn({ | ||
account, | ||
name: BigInt(torii.cairoShortStringToFelt("Loaf")), | ||
role: 1, | ||
}); | ||
}} | ||
variant={"default"} | ||
> | ||
Spawn | ||
</Button> | ||
</div> | ||
|
||
<div className="grid grid-cols-2 gap-1"> | ||
<Button | ||
onClick={async () => { | ||
await client.actions.move({ | ||
account, | ||
direction: 1, // North | ||
}); | ||
}} | ||
variant={"outline"} | ||
> | ||
North | ||
</Button> | ||
<Button | ||
onClick={async () => { | ||
await client.actions.move({ | ||
account, | ||
direction: 2, // South | ||
}); | ||
}} | ||
variant={"outline"} | ||
> | ||
South | ||
</Button> | ||
<Button | ||
onClick={async () => { | ||
await client.actions.move({ | ||
account, | ||
direction: 3, // East | ||
}); | ||
}} | ||
variant={"outline"} | ||
> | ||
East | ||
</Button> | ||
<Button | ||
onClick={async () => { | ||
await client.actions.move({ | ||
account, | ||
direction: 4, // West | ||
}); | ||
}} | ||
variant={"outline"} | ||
> | ||
West | ||
</Button> | ||
</div> | ||
|
||
<div className="my-1"> | ||
{" "} | ||
<Button | ||
onClick={async () => { | ||
await client.actions.heal({ | ||
account, | ||
quantity: 1, | ||
}); | ||
}} | ||
variant={"secondary"} | ||
> | ||
Heal | ||
</Button> | ||
<Button | ||
onClick={async () => { | ||
await client.actions.attack({ | ||
account, | ||
}); | ||
}} | ||
variant={"destructive"} | ||
> | ||
Attack | ||
</Button> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from "react"; | ||
import { Slot } from "@radix-ui/react-slot"; | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
|
||
const buttonVariants = cva( | ||
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "bg-primary text-primary-foreground hover:bg-primary/90", | ||
destructive: | ||
"bg-destructive text-destructive-foreground hover:bg-destructive/90", | ||
outline: | ||
"border border-input bg-background hover:bg-accent hover:text-accent-foreground", | ||
secondary: | ||
"bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
ghost: "hover:bg-accent hover:text-accent-foreground", | ||
link: "text-primary underline-offset-4 hover:underline", | ||
}, | ||
size: { | ||
default: "h-10 px-4 py-2", | ||
sm: "h-9 rounded-md px-3", | ||
lg: "h-11 rounded-md px-8", | ||
icon: "h-10 w-10", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
size: "default", | ||
}, | ||
} | ||
); | ||
|
||
export interface ButtonProps | ||
extends React.ButtonHTMLAttributes<HTMLButtonElement>, | ||
VariantProps<typeof buttonVariants> { | ||
asChild?: boolean; | ||
} | ||
|
||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | ||
({ className, variant, size, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "button"; | ||
return ( | ||
<Comp | ||
className={cn(buttonVariants({ variant, size, className }))} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
} | ||
); | ||
Button.displayName = "Button"; | ||
|
||
export { Button, buttonVariants }; |
Oops, something went wrong.