Skip to content

Commit

Permalink
add phaser example
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Nov 7, 2023
1 parent b3b3b59 commit b6e9332
Show file tree
Hide file tree
Showing 52 changed files with 1,542 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
Binary file removed examples/react-app/bun.lockb
Binary file not shown.
7 changes: 7 additions & 0 deletions examples/react-phaser-example/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VITE_PUBLIC_ETH_CONTRACT_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
VITE_PUBLIC_ACCOUNT_CLASS_HASH=0x04d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f
VITE_PUBLIC_MASTER_ADDRESS=0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973
VITE_PUBLIC_MASTER_PRIVATE_KEY=0x1800000000300000180000000000030000000000003006001800006600
VITE_PUBLIC_WORLD_ADDRESS=0x534692277764b04cfc469858891b825c799d1da550d2509fdd5be2f32abdaa0
VITE_PUBLIC_NODE_URL=http://localhost:5050
VITE_PUBLIC_TORII=http://localhost:8080
14 changes: 14 additions & 0 deletions examples/react-phaser-example/.eslintrc.cjs
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',
},
}
24 changes: 24 additions & 0 deletions examples/react-phaser-example/.gitignore
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?
21 changes: 21 additions & 0 deletions examples/react-phaser-example/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 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.
15 changes: 15 additions & 0 deletions examples/react-phaser-example/codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
schema: 'http://localhost:8080',
documents: 'src/**/*.graphql',
generates: {
'src/generated/graphql.ts': {
plugins: ['typescript', 'typescript-operations', 'typescript-graphql-request'],
config: {
rawRequest: true
},
},
},
};
export default config;
13 changes: 13 additions & 0 deletions examples/react-phaser-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
55 changes: 55 additions & 0 deletions examples/react-phaser-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "react-phaser-example",
"private": true,
"version": "0.1.0",
"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",
"codegen": "graphql-codegen",
"components": "npx @dojoengine/core ../dojo-starter/target/dev/manifest.json src/dojo/contractComponents.ts http://localhost:5050 0x534692277764b04cfc469858891b825c799d1da550d2509fdd5be2f32abdaa0"
},
"dependencies": {
"@dojoengine/core": "link:dojo-packages/packages/core",
"@dojoengine/create-burner": "link:dojo-packages/packages/create-burner",
"@dojoengine/torii-client": "link:dojo-packages/packages/torii-client",
"@dojoengine/utils": "link:dojo-packages/packages/utils",
"@dojoengine/react": "link:dojo-packages/packages/react",
"@dojoengine/recs": "0.1.35",
"@latticexyz/utils": "^2.0.0-next.11",
"@latticexyz/phaserx": "^2.0.0-next.11",
"ethers": "^5.7.2",
"events": "^3.3.0",
"graphql": "^16.7.1",
"graphql-request": "^6.1.0",
"mobx": "^6.9.0",
"phaser": "3.60.0-beta.14",
"proxy-deep": "^3.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rxjs": "^7.8.1",
"simplex-noise": "^4.0.1",
"starknet": "^5.19.5",
"styled-components": "^6.0.7",
"zustand": "^4.4.1"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-graphql-request": "^5.0.0",
"@graphql-codegen/typescript-operations": "^4.0.1",
"@types/node": "^20.4.8",
"@types/react": "^18.0.37",
"@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.0.2",
"vite": "^4.3.9"
}
}
1 change: 1 addition & 0 deletions examples/react-phaser-example/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions examples/react-phaser-example/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Dojo create-phaser-app

The pattern here is inherited from mud.dev and is a simple example of how to use the dojo engine with create-phaser-app.

### Steps to Execute the Example

Firstly, clone the [dojo-starter](https://github.com/dojoengine/dojo-starter) project and follow the given instructions to ensure it's functioning correctly. This step is crucial as this client displays data obtained from the project.

Subsequently, clone this project and execute the following commands in the terminal:

```console
yarn

yarn generate

yarn dev
```

### Notes

This is just a simple example of how to setup a project, but in by no means is the only way.
Empty file.
28 changes: 28 additions & 0 deletions examples/react-phaser-example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import "./App.css";
import { useEffect } from "react";
import { useNetworkLayer } from "./hooks/useNetworkLayer";
import { PhaserLayer } from "./phaser/phaserLayer";
import { store } from "./store/store";
import { UI } from "./ui";

function App() {
const networkLayer = useNetworkLayer();

useEffect(() => {
if (!networkLayer) return;

console.log("Setting network layer");

store.setState({ networkLayer });
}, [networkLayer]);

return (
<div>
<PhaserLayer networkLayer={networkLayer} />

<UI />
</div>
);
}

export default App;
9 changes: 9 additions & 0 deletions examples/react-phaser-example/src/artTypes/world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// GENERATED CODE - DO NOT MODIFY BY HAND

export enum Tileset {
Grass = 0,
Mountains = 1,
Forest = 2,
}
export enum TileAnimationKey { }
export const TileAnimations: { [key in TileAnimationKey]: number[] } = {};
103 changes: 103 additions & 0 deletions examples/react-phaser-example/src/assets/atlases/atlas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"meta": {
"app": "",
"version": "1.0.0"
},
"textures": [
{
"image": "atlas.png?timestamp=1678825051140",
"format": "RGBA8888",
"size": {
"w": 2048,
"h": 2048
},
"scale": 1,
"frames": [
{
"filename": "sprites/soldier/idle/0.png",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 32,
"h": 32
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 32,
"h": 32
},
"frame": {
"x": 0,
"y": 0,
"w": 32,
"h": 32
}
},
{
"filename": "sprites/soldier/idle/1.png",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 32,
"h": 32
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 32,
"h": 32
},
"frame": {
"x": 32,
"y": 0,
"w": 32,
"h": 32
}
},
{
"filename": "sprites/soldier/idle/2.png",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 32,
"h": 32
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 32,
"h": 32
},
"frame": {
"x": 0,
"y": 32,
"w": 32,
"h": 32
}
},
{
"filename": "sprites/soldier/idle/3.png",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 32,
"h": 32
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 32,
"h": 32
},
"frame": {
"x": 32,
"y": 32,
"w": 32,
"h": 32
}
}
]
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/react-phaser-example/src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions examples/react-phaser-example/src/dojo/contractComponents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Autogenerated file. Do not edit manually. */

import { defineComponent, Type as RecsType, World } from "@dojoengine/recs";

export function defineContractComponents(world: World) {
return {
Moves: (() => {
return defineComponent(
world,
{
player: RecsType.BigInt,
remaining: RecsType.Number,
last_direction: RecsType.Number,
},
{
metadata: {
name: "Moves",
types: ["Direction"],
},
}
);
})(),
Position: (() => {
return defineComponent(
world,
{
player: RecsType.BigInt,
vec: { x: RecsType.Number, y: RecsType.Number },
},
{
metadata: {
name: "Position",
types: ["Vec2"],
},
}
);
})(),
};
}
13 changes: 13 additions & 0 deletions examples/react-phaser-example/src/dojo/createClientComponents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { overridableComponent } from "@dojoengine/recs";
import { SetupNetworkResult } from "./setupNetwork";


export type ClientComponents = ReturnType<typeof createClientComponents>;

export function createClientComponents({ contractComponents }: SetupNetworkResult) {
return {
...contractComponents,
Position: overridableComponent(contractComponents.Position),
Moves: overridableComponent(contractComponents.Moves),
};
}
Loading

0 comments on commit b6e9332

Please sign in to comment.