create-mud 2.0.0-alpha.1.21 → 2.0.0-alpha.1.211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/README.md +1 -1
  2. package/dist/cli.js +1 -1
  3. package/dist/templates/{minimal/packages/client → phaser}/.eslintrc +1 -3
  4. package/dist/templates/phaser/package.json +28 -0
  5. package/dist/templates/phaser/packages/art/.gitignore +0 -0
  6. package/dist/templates/phaser/packages/art/README.md +33 -0
  7. package/dist/templates/phaser/packages/art/config-sprites.json +21 -0
  8. package/dist/templates/phaser/packages/art/package.json +27 -0
  9. package/dist/templates/phaser/packages/art/scripts/cli.mjs +190 -0
  10. package/dist/templates/phaser/packages/art/scripts/export-tiled-types.ts +292 -0
  11. package/dist/templates/phaser/packages/art/sprites/golem/attack/0.png +0 -0
  12. package/dist/templates/phaser/packages/art/sprites/golem/attack/1.png +0 -0
  13. package/dist/templates/phaser/packages/art/sprites/golem/attack/2.png +0 -0
  14. package/dist/templates/phaser/packages/art/sprites/golem/attack/3.png +0 -0
  15. package/dist/templates/phaser/packages/art/sprites/golem/attack/4.png +0 -0
  16. package/dist/templates/phaser/packages/art/sprites/golem/attack/5.png +0 -0
  17. package/dist/templates/phaser/packages/art/sprites/golem/death/0.png +0 -0
  18. package/dist/templates/phaser/packages/art/sprites/golem/death/1.png +0 -0
  19. package/dist/templates/phaser/packages/art/sprites/golem/death/2.png +0 -0
  20. package/dist/templates/phaser/packages/art/sprites/golem/idle/0.png +0 -0
  21. package/dist/templates/phaser/packages/art/sprites/golem/idle/1.png +0 -0
  22. package/dist/templates/phaser/packages/art/sprites/golem/idle/2.png +0 -0
  23. package/dist/templates/phaser/packages/art/sprites/golem/idle/3.png +0 -0
  24. package/dist/templates/phaser/packages/art/tilesets/images/world.png +0 -0
  25. package/dist/templates/phaser/packages/art/tilesets/world.tsx +19 -0
  26. package/dist/templates/phaser/packages/client/.env +1 -0
  27. package/dist/templates/phaser/packages/client/.eslintrc +7 -0
  28. package/dist/templates/phaser/packages/client/index.html +39 -0
  29. package/dist/templates/phaser/packages/client/package.json +48 -0
  30. package/dist/templates/phaser/packages/client/public/assets/atlases/atlas.json +292 -0
  31. package/dist/templates/phaser/packages/client/public/assets/atlases/atlas.png +0 -0
  32. package/dist/templates/phaser/packages/client/public/assets/tilesets/world.png +0 -0
  33. package/dist/templates/phaser/packages/client/src/artTypes/world.ts +9 -0
  34. package/dist/templates/phaser/packages/client/src/index.tsx +11 -0
  35. package/dist/templates/phaser/packages/client/src/layers/network/createNetworkLayer.ts +24 -0
  36. package/dist/templates/phaser/packages/client/src/layers/phaser/configurePhaser.ts +91 -0
  37. package/dist/templates/phaser/packages/client/src/layers/phaser/constants.ts +22 -0
  38. package/dist/templates/phaser/packages/client/src/layers/phaser/createPhaserLayer.ts +33 -0
  39. package/dist/templates/phaser/packages/client/src/layers/phaser/systems/createCamera.ts +13 -0
  40. package/dist/templates/phaser/packages/client/src/layers/phaser/systems/createMapSystem.ts +32 -0
  41. package/dist/templates/phaser/packages/client/src/layers/phaser/systems/index.ts +1 -0
  42. package/dist/templates/phaser/packages/client/src/layers/phaser/systems/registerSystems.ts +8 -0
  43. package/dist/templates/phaser/packages/client/src/mud/contractComponents.ts +24 -0
  44. package/dist/templates/phaser/packages/client/src/mud/createClientComponents.ts +10 -0
  45. package/dist/templates/phaser/packages/client/src/mud/createSystemCalls.ts +21 -0
  46. package/dist/templates/phaser/packages/client/src/mud/getNetworkConfig.ts +53 -0
  47. package/dist/templates/phaser/packages/client/src/mud/setup.ts +16 -0
  48. package/dist/templates/phaser/packages/client/src/mud/setupNetwork.ts +102 -0
  49. package/dist/templates/phaser/packages/client/src/mud/supportedChains.ts +5 -0
  50. package/dist/templates/phaser/packages/client/src/mud/world.ts +3 -0
  51. package/dist/templates/phaser/packages/client/src/store.ts +38 -0
  52. package/dist/templates/phaser/packages/client/src/ui/App.tsx +23 -0
  53. package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/BootScreen.tsx +42 -0
  54. package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/LoadingBar.tsx +21 -0
  55. package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/LoadingScreen.tsx +52 -0
  56. package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/index.ts +1 -0
  57. package/dist/templates/phaser/packages/client/src/ui/PhaserLayer.tsx +20 -0
  58. package/dist/templates/phaser/packages/client/src/ui/UIRoot.tsx +20 -0
  59. package/dist/templates/phaser/packages/client/src/ui/Wrapper.tsx +5 -0
  60. package/dist/templates/phaser/packages/client/src/ui/hooks/useNetworkLayer.tsx +17 -0
  61. package/dist/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx +87 -0
  62. package/dist/templates/phaser/packages/client/src/ui/hooks/usePromiseValue.ts +24 -0
  63. package/dist/templates/phaser/packages/client/src/ui/theme/ClickWrapper.tsx +18 -0
  64. package/dist/templates/phaser/packages/client/src/ui/theme/SpriteImage.tsx +52 -0
  65. package/dist/templates/{minimal → phaser}/packages/client/tsconfig.json +3 -4
  66. package/dist/templates/phaser/packages/client/vite.config.ts +15 -0
  67. package/dist/templates/phaser/packages/contracts/.env +8 -0
  68. package/dist/templates/{minimal → phaser}/packages/contracts/.gitignore +3 -2
  69. package/dist/templates/{minimal → phaser}/packages/contracts/.solhint.json +2 -1
  70. package/dist/templates/phaser/packages/contracts/foundry.toml +22 -0
  71. package/dist/templates/phaser/packages/contracts/mud.config.ts +10 -0
  72. package/dist/templates/phaser/packages/contracts/package.json +45 -0
  73. package/dist/templates/phaser/packages/contracts/remappings.txt +3 -0
  74. package/dist/templates/phaser/packages/contracts/script/PostDeploy.s.sol +17 -0
  75. package/dist/templates/phaser/packages/contracts/src/codegen/Tables.sol +6 -0
  76. package/dist/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +120 -0
  77. package/dist/templates/phaser/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
  78. package/dist/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol +16 -0
  79. package/dist/templates/phaser/packages/contracts/src/systems/IncrementSystem.sol +14 -0
  80. package/dist/templates/phaser/packages/contracts/test/CounterTest.t.sol +38 -0
  81. package/dist/templates/phaser/packages/contracts/tsconfig.json +13 -0
  82. package/dist/templates/phaser/packages/contracts/worlds.json +5 -0
  83. package/dist/templates/react/.eslintrc +10 -0
  84. package/dist/templates/react/package.json +13 -3
  85. package/dist/templates/react/packages/client/.env +1 -0
  86. package/dist/templates/react/packages/client/.eslintrc +2 -12
  87. package/dist/templates/react/packages/client/package.json +18 -21
  88. package/dist/templates/react/packages/client/src/App.tsx +11 -13
  89. package/dist/templates/react/packages/client/src/MUDContext.tsx +21 -0
  90. package/dist/templates/react/packages/client/src/index.tsx +12 -31
  91. package/dist/templates/react/packages/client/src/mud/contractComponents.ts +24 -0
  92. package/dist/templates/react/packages/client/src/mud/createClientComponents.ts +10 -0
  93. package/dist/templates/react/packages/client/src/mud/createSystemCalls.ts +21 -0
  94. package/dist/templates/react/packages/client/src/mud/getNetworkConfig.ts +53 -0
  95. package/dist/templates/react/packages/client/src/mud/setup.ts +16 -0
  96. package/dist/templates/react/packages/client/src/mud/setupNetwork.ts +102 -0
  97. package/dist/templates/react/packages/client/src/mud/supportedChains.ts +5 -0
  98. package/dist/templates/react/packages/client/src/mud/world.ts +3 -0
  99. package/dist/templates/react/packages/client/tsconfig.json +0 -3
  100. package/dist/templates/react/packages/client/vite.config.ts +3 -0
  101. package/dist/templates/react/packages/contracts/.env +8 -0
  102. package/dist/templates/react/packages/contracts/.gitignore +3 -2
  103. package/dist/templates/react/packages/contracts/.solhint.json +2 -1
  104. package/dist/templates/react/packages/contracts/foundry.toml +13 -2
  105. package/dist/templates/react/packages/contracts/mud.config.ts +10 -0
  106. package/dist/templates/react/packages/contracts/package.json +25 -20
  107. package/dist/templates/react/packages/contracts/remappings.txt +3 -9
  108. package/dist/templates/react/packages/contracts/script/PostDeploy.s.sol +24 -0
  109. package/dist/templates/react/packages/contracts/src/codegen/Tables.sol +6 -0
  110. package/dist/templates/react/packages/contracts/src/codegen/tables/Counter.sol +120 -0
  111. package/dist/templates/react/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
  112. package/dist/templates/react/packages/contracts/src/codegen/world/IWorld.sol +16 -0
  113. package/dist/templates/react/packages/contracts/src/systems/IncrementSystem.sol +7 -15
  114. package/dist/templates/react/packages/contracts/test/CounterTest.t.sol +38 -0
  115. package/dist/templates/react/packages/contracts/tsconfig.json +9 -8
  116. package/dist/templates/react/packages/contracts/worlds.json +5 -0
  117. package/dist/templates/threejs/.eslintrc +10 -0
  118. package/dist/templates/threejs/.gitignore +1 -0
  119. package/dist/templates/threejs/.vscode/extensions.json +3 -0
  120. package/dist/templates/threejs/.vscode/settings.json +3 -0
  121. package/dist/templates/threejs/package.json +28 -0
  122. package/dist/templates/threejs/packages/client/.env +1 -0
  123. package/dist/templates/threejs/packages/client/.eslintrc +7 -0
  124. package/dist/templates/threejs/packages/client/.gitignore +3 -0
  125. package/dist/templates/threejs/packages/client/index.html +12 -0
  126. package/dist/templates/threejs/packages/client/package.json +41 -0
  127. package/dist/templates/threejs/packages/client/src/App.tsx +81 -0
  128. package/dist/templates/threejs/packages/client/src/MUDContext.tsx +21 -0
  129. package/dist/templates/threejs/packages/client/src/index.tsx +19 -0
  130. package/dist/templates/threejs/packages/client/src/mud/contractComponents.ts +26 -0
  131. package/dist/templates/threejs/packages/client/src/mud/createClientComponents.ts +10 -0
  132. package/dist/templates/threejs/packages/client/src/mud/createSystemCalls.ts +15 -0
  133. package/dist/templates/threejs/packages/client/src/mud/getNetworkConfig.ts +53 -0
  134. package/dist/templates/threejs/packages/client/src/mud/setup.ts +16 -0
  135. package/dist/templates/threejs/packages/client/src/mud/setupNetwork.ts +102 -0
  136. package/dist/templates/threejs/packages/client/src/mud/supportedChains.ts +5 -0
  137. package/dist/templates/threejs/packages/client/src/mud/world.ts +3 -0
  138. package/dist/templates/threejs/packages/client/src/useKeyboardMovement.ts +60 -0
  139. package/dist/templates/threejs/packages/client/tsconfig.json +19 -0
  140. package/dist/templates/threejs/packages/client/vite.config.ts +15 -0
  141. package/dist/templates/threejs/packages/contracts/.env +8 -0
  142. package/dist/templates/threejs/packages/contracts/.gitignore +11 -0
  143. package/dist/templates/threejs/packages/contracts/.prettierrc +8 -0
  144. package/dist/templates/threejs/packages/contracts/.solhint.json +12 -0
  145. package/dist/templates/threejs/packages/contracts/foundry.toml +22 -0
  146. package/dist/templates/threejs/packages/contracts/mud.config.ts +13 -0
  147. package/dist/templates/threejs/packages/contracts/package.json +45 -0
  148. package/dist/templates/threejs/packages/contracts/remappings.txt +3 -0
  149. package/dist/templates/threejs/packages/contracts/src/codegen/Tables.sol +6 -0
  150. package/dist/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +263 -0
  151. package/dist/templates/threejs/packages/contracts/src/codegen/world/IMoveSystem.sol +8 -0
  152. package/dist/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol +16 -0
  153. package/dist/templates/threejs/packages/contracts/src/systems/MoveSystem.sol +25 -0
  154. package/dist/templates/threejs/packages/contracts/tsconfig.json +13 -0
  155. package/dist/templates/threejs/packages/contracts/worlds.json +5 -0
  156. package/dist/templates/threejs/pnpm-workspace.yaml +2 -0
  157. package/dist/templates/vanilla/.eslintrc +10 -0
  158. package/dist/templates/vanilla/.gitignore +1 -0
  159. package/dist/templates/vanilla/.vscode/extensions.json +3 -0
  160. package/dist/templates/vanilla/.vscode/settings.json +3 -0
  161. package/dist/templates/vanilla/package.json +28 -0
  162. package/dist/templates/vanilla/packages/client/.env +1 -0
  163. package/dist/templates/vanilla/packages/client/.gitignore +3 -0
  164. package/dist/templates/vanilla/packages/client/package.json +32 -0
  165. package/dist/templates/vanilla/packages/client/src/index.ts +22 -0
  166. package/dist/templates/vanilla/packages/client/src/mud/contractComponents.ts +24 -0
  167. package/dist/templates/vanilla/packages/client/src/mud/createClientComponents.ts +10 -0
  168. package/dist/templates/vanilla/packages/client/src/mud/createSystemCalls.ts +21 -0
  169. package/dist/templates/vanilla/packages/client/src/mud/getNetworkConfig.ts +53 -0
  170. package/dist/templates/vanilla/packages/client/src/mud/setup.ts +16 -0
  171. package/dist/templates/vanilla/packages/client/src/mud/setupNetwork.ts +102 -0
  172. package/dist/templates/vanilla/packages/client/src/mud/supportedChains.ts +5 -0
  173. package/dist/templates/vanilla/packages/client/src/mud/world.ts +3 -0
  174. package/dist/templates/vanilla/packages/client/tsconfig.json +18 -0
  175. package/dist/templates/{minimal → vanilla}/packages/client/vite.config.ts +3 -0
  176. package/dist/templates/vanilla/packages/contracts/.env +8 -0
  177. package/dist/templates/vanilla/packages/contracts/.gitignore +11 -0
  178. package/dist/templates/vanilla/packages/contracts/.prettierrc +8 -0
  179. package/dist/templates/vanilla/packages/contracts/.solhint.json +12 -0
  180. package/dist/templates/vanilla/packages/contracts/foundry.toml +22 -0
  181. package/dist/templates/vanilla/packages/contracts/mud.config.ts +10 -0
  182. package/dist/templates/vanilla/packages/contracts/package.json +45 -0
  183. package/dist/templates/vanilla/packages/contracts/remappings.txt +3 -0
  184. package/dist/templates/vanilla/packages/contracts/script/PostDeploy.s.sol +24 -0
  185. package/dist/templates/vanilla/packages/contracts/src/codegen/Tables.sol +6 -0
  186. package/dist/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +120 -0
  187. package/dist/templates/vanilla/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
  188. package/dist/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol +16 -0
  189. package/dist/templates/vanilla/packages/contracts/src/systems/IncrementSystem.sol +14 -0
  190. package/dist/templates/vanilla/packages/contracts/test/CounterTest.t.sol +38 -0
  191. package/dist/templates/vanilla/packages/contracts/tsconfig.json +13 -0
  192. package/dist/templates/vanilla/packages/contracts/worlds.json +5 -0
  193. package/dist/templates/vanilla/pnpm-workspace.yaml +2 -0
  194. package/package.json +14 -11
  195. package/dist/templates/minimal/package.json +0 -18
  196. package/dist/templates/minimal/packages/client/package.json +0 -37
  197. package/dist/templates/minimal/packages/client/src/config.ts +0 -22
  198. package/dist/templates/minimal/packages/client/src/index.ts +0 -37
  199. package/dist/templates/minimal/packages/contracts/chainSpec.json +0 -5
  200. package/dist/templates/minimal/packages/contracts/deploy.json +0 -4
  201. package/dist/templates/minimal/packages/contracts/exports.sh +0 -22
  202. package/dist/templates/minimal/packages/contracts/foundry.toml +0 -11
  203. package/dist/templates/minimal/packages/contracts/package.json +0 -40
  204. package/dist/templates/minimal/packages/contracts/remappings.txt +0 -9
  205. package/dist/templates/minimal/packages/contracts/src/components/CounterComponent.sol +0 -9
  206. package/dist/templates/minimal/packages/contracts/src/libraries/LibMath.sol +0 -10
  207. package/dist/templates/minimal/packages/contracts/src/systems/IncrementSystem.sol +0 -22
  208. package/dist/templates/minimal/packages/contracts/src/systems/README.md +0 -7
  209. package/dist/templates/minimal/packages/contracts/src/test/Deploy.sol +0 -19
  210. package/dist/templates/minimal/packages/contracts/src/test/Deploy.t.sol +0 -14
  211. package/dist/templates/minimal/packages/contracts/src/test/LibDeploy.sol +0 -22
  212. package/dist/templates/minimal/packages/contracts/tsconfig.json +0 -12
  213. package/dist/templates/react/packages/client/src/config.ts +0 -22
  214. package/dist/templates/react/packages/contracts/chainSpec.json +0 -5
  215. package/dist/templates/react/packages/contracts/deploy.json +0 -4
  216. package/dist/templates/react/packages/contracts/exports.sh +0 -22
  217. package/dist/templates/react/packages/contracts/src/components/CounterComponent.sol +0 -9
  218. package/dist/templates/react/packages/contracts/src/libraries/LibMath.sol +0 -10
  219. package/dist/templates/react/packages/contracts/src/systems/README.md +0 -7
  220. package/dist/templates/react/packages/contracts/src/test/Deploy.sol +0 -19
  221. package/dist/templates/react/packages/contracts/src/test/Deploy.t.sol +0 -14
  222. package/dist/templates/react/packages/contracts/src/test/LibDeploy.sol +0 -22
  223. /package/dist/templates/{minimal → phaser}/.gitignore +0 -0
  224. /package/dist/templates/{minimal → phaser}/.vscode/extensions.json +0 -0
  225. /package/dist/templates/{minimal → phaser}/.vscode/settings.json +0 -0
  226. /package/dist/templates/{minimal → phaser}/packages/client/.gitignore +0 -0
  227. /package/dist/templates/{minimal → phaser}/packages/contracts/.prettierrc +0 -0
  228. /package/dist/templates/{minimal → phaser}/pnpm-workspace.yaml +0 -0
  229. /package/dist/templates/{minimal → vanilla}/packages/client/index.html +0 -0
@@ -0,0 +1 @@
1
+ node_modules
@@ -0,0 +1,3 @@
1
+ {
2
+ "recommendations": ["JuanBlanco.solidity"]
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "solidity.monoRepoSupport": true
3
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "mud-template-threejs",
3
+ "private": true,
4
+ "scripts": {
5
+ "build": "pnpm recursive run build",
6
+ "dev": "concurrently -n contracts,client -c cyan,magenta \"cd packages/contracts && pnpm run dev\" \"cd packages/client && pnpm run dev\"",
7
+ "dev:client": "pnpm --filter 'client' run dev",
8
+ "dev:contracts": "pnpm --filter 'contracts' dev",
9
+ "foundry:up": "curl -L https://foundry.paradigm.xyz | bash && bash $HOME/.foundry/bin/foundryup",
10
+ "initialize": "pnpm recursive run initialize",
11
+ "mud:up": "pnpm recursive exec mud set-version -v canary && pnpm install",
12
+ "prepare": "(forge --version || pnpm foundry:up)",
13
+ "test": "pnpm recursive run test"
14
+ },
15
+ "devDependencies": {
16
+ "@latticexyz/cli": "{{mud-version}}",
17
+ "@typescript-eslint/eslint-plugin": "5.46.1",
18
+ "@typescript-eslint/parser": "5.46.1",
19
+ "concurrently": "^8.0.1",
20
+ "eslint": "8.29.0",
21
+ "rimraf": "^3.0.2",
22
+ "typescript": "^4.9.5"
23
+ },
24
+ "engines": {
25
+ "node": "18.x",
26
+ "pnpm": "8.x"
27
+ }
28
+ }
@@ -0,0 +1 @@
1
+ VITE_CHAIN_ID=31337
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": ["../../.eslintrc", "plugin:react/recommended", "plugin:react-hooks/recommended"],
3
+ "plugins": ["react", "react-hooks"],
4
+ "rules": {
5
+ "react/react-in-jsx-scope": "off"
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ dist
3
+ .DS_Store
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>a minimal MUD client</title>
7
+ </head>
8
+ <body>
9
+ <div id="react-root"></div>
10
+ <script type="module" src="/src/index.tsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "client",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "scripts": {
8
+ "build": "vite build",
9
+ "dev": "wait-port localhost:8545 && vite",
10
+ "initialize": "pnpm build",
11
+ "preview": "vite preview",
12
+ "test": "tsc --noEmit"
13
+ },
14
+ "dependencies": {
15
+ "@ethersproject/providers": "^5.7.2",
16
+ "@latticexyz/common": "{{mud-version}}",
17
+ "@latticexyz/dev-tools": "{{mud-version}}",
18
+ "@latticexyz/network": "{{mud-version}}",
19
+ "@latticexyz/react": "{{mud-version}}",
20
+ "@latticexyz/recs": "{{mud-version}}",
21
+ "@latticexyz/schema-type": "{{mud-version}}",
22
+ "@latticexyz/std-client": "{{mud-version}}",
23
+ "@latticexyz/utils": "{{mud-version}}",
24
+ "@latticexyz/world": "{{mud-version}}",
25
+ "@react-three/fiber": "^8.12.0",
26
+ "@wagmi/chains": "^0.2.22",
27
+ "contracts": "workspace:*",
28
+ "ethers": "^5.7.2",
29
+ "react": "^18.2.0",
30
+ "react-dom": "^18.2.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/react": "^18.2.6",
34
+ "@types/react-dom": "^18.2.4",
35
+ "@vitejs/plugin-react": "^3.1.0",
36
+ "eslint-plugin-react": "7.31.11",
37
+ "eslint-plugin-react-hooks": "4.6.0",
38
+ "vite": "^4.2.1",
39
+ "wait-port": "^1.0.4"
40
+ }
41
+ }
@@ -0,0 +1,81 @@
1
+ import React from "react";
2
+ import { Canvas, Color, ThreeElements, useThree } from "@react-three/fiber";
3
+ import { useComponentValue, useEntityQuery } from "@latticexyz/react";
4
+ import { getComponentValueStrict, Has } from "@latticexyz/recs";
5
+ import { useMUD } from "./MUDContext";
6
+ import { useKeyboardMovement } from "./useKeyboardMovement";
7
+
8
+ const Plane = (props: ThreeElements["mesh"]) => {
9
+ return (
10
+ <mesh {...props}>
11
+ {/* eslint-disable-next-line react/no-unknown-property */}
12
+ <boxGeometry args={[10, 5, 10]} />
13
+ <meshStandardMaterial color="green" />
14
+ </mesh>
15
+ );
16
+ };
17
+
18
+ const Player = (props: ThreeElements["mesh"] & { color: Color }) => {
19
+ return (
20
+ <mesh {...props}>
21
+ {/* eslint-disable-next-line react/no-unknown-property */}
22
+ <boxGeometry args={[1, 2, 1]} />
23
+ <meshStandardMaterial color={props.color} />
24
+ </mesh>
25
+ );
26
+ };
27
+
28
+ const Scene = () => {
29
+ const {
30
+ components: { Position },
31
+ network: { playerEntity },
32
+ } = useMUD();
33
+
34
+ useKeyboardMovement();
35
+
36
+ const playerPosition = useComponentValue(Position, playerEntity);
37
+ const players = useEntityQuery([Has(Position)]).map((entity) => {
38
+ const position = getComponentValueStrict(Position, entity);
39
+ return {
40
+ entity,
41
+ position,
42
+ };
43
+ });
44
+
45
+ useThree(({ camera }) => {
46
+ if (playerPosition) {
47
+ camera.position.set(playerPosition.x - 5, playerPosition.y + 5, playerPosition.z + 5);
48
+ } else {
49
+ camera.position.set(-5, 5, 5);
50
+ }
51
+ camera.rotation.order = "YXZ";
52
+ camera.rotation.y = -Math.PI / 4;
53
+ camera.rotation.x = Math.atan(-1 / Math.sqrt(2));
54
+ });
55
+
56
+ return (
57
+ <group>
58
+ <ambientLight />
59
+ {/* eslint-disable-next-line react/no-unknown-property */}
60
+ <pointLight position={[10, 10, 10]} />
61
+ <Plane position={[0, -5, 0]} />
62
+ {players.map((p, i) => (
63
+ <Player
64
+ key={i}
65
+ color={Math.floor(parseInt(p.entity) * 123456) % 16777215}
66
+ position={[p.position.x, p.position.y, p.position.z]}
67
+ />
68
+ ))}
69
+ </group>
70
+ );
71
+ };
72
+
73
+ const styles = { height: "100vh" };
74
+
75
+ export const App = () => {
76
+ return (
77
+ <Canvas style={styles}>
78
+ <Scene />
79
+ </Canvas>
80
+ );
81
+ };
@@ -0,0 +1,21 @@
1
+ import { createContext, ReactNode, useContext } from "react";
2
+ import { SetupResult } from "./mud/setup";
3
+
4
+ const MUDContext = createContext<SetupResult | null>(null);
5
+
6
+ type Props = {
7
+ children: ReactNode;
8
+ value: SetupResult;
9
+ };
10
+
11
+ export const MUDProvider = ({ children, value }: Props) => {
12
+ const currentValue = useContext(MUDContext);
13
+ if (currentValue) throw new Error("MUDProvider can only be used once");
14
+ return <MUDContext.Provider value={value}>{children}</MUDContext.Provider>;
15
+ };
16
+
17
+ export const useMUD = () => {
18
+ const value = useContext(MUDContext);
19
+ if (!value) throw new Error("Must be used within a MUDProvider");
20
+ return value;
21
+ };
@@ -0,0 +1,19 @@
1
+ import ReactDOM from "react-dom/client";
2
+ import { mount as mountDevTools } from "@latticexyz/dev-tools";
3
+ import { App } from "./App";
4
+ import { setup } from "./mud/setup";
5
+ import { MUDProvider } from "./MUDContext";
6
+
7
+ const rootElement = document.getElementById("react-root");
8
+ if (!rootElement) throw new Error("React root not found");
9
+ const root = ReactDOM.createRoot(rootElement);
10
+
11
+ // TODO: figure out if we actually want this to be async or if we should render something else in the meantime
12
+ setup().then((result) => {
13
+ root.render(
14
+ <MUDProvider value={result}>
15
+ <App />
16
+ </MUDProvider>
17
+ );
18
+ mountDevTools();
19
+ });
@@ -0,0 +1,26 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+
3
+ import { TableId } from "@latticexyz/utils";
4
+ import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";
5
+
6
+ export function defineContractComponents(world: World) {
7
+ return {
8
+ Position: (() => {
9
+ const tableId = new TableId("", "Position");
10
+ return defineComponent(
11
+ world,
12
+ {
13
+ x: RecsType.Number,
14
+ y: RecsType.Number,
15
+ z: RecsType.Number,
16
+ },
17
+ {
18
+ metadata: {
19
+ contractId: tableId.toHexString(),
20
+ tableId: tableId.toString(),
21
+ },
22
+ }
23
+ );
24
+ })(),
25
+ };
26
+ }
@@ -0,0 +1,10 @@
1
+ import { SetupNetworkResult } from "./setupNetwork";
2
+
3
+ export type ClientComponents = ReturnType<typeof createClientComponents>;
4
+
5
+ export function createClientComponents({ components }: SetupNetworkResult) {
6
+ return {
7
+ ...components,
8
+ // add your client components or overrides here
9
+ };
10
+ }
@@ -0,0 +1,15 @@
1
+ import { awaitStreamValue } from "@latticexyz/utils";
2
+ import { SetupNetworkResult } from "./setupNetwork";
3
+
4
+ export type SystemCalls = ReturnType<typeof createSystemCalls>;
5
+
6
+ export function createSystemCalls({ worldSend, txReduced$ }: SetupNetworkResult) {
7
+ const move = async (x: number, y: number, z: number) => {
8
+ const tx = await worldSend("move", [x, y, z]);
9
+ await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash);
10
+ };
11
+
12
+ return {
13
+ move,
14
+ };
15
+ }
@@ -0,0 +1,53 @@
1
+ import { SetupContractConfig, getBurnerWallet } from "@latticexyz/std-client";
2
+ import worldsJson from "contracts/worlds.json";
3
+ import { supportedChains } from "./supportedChains";
4
+
5
+ const worlds = worldsJson as Partial<Record<string, { address: string; blockNumber?: number }>>;
6
+
7
+ type NetworkConfig = SetupContractConfig & {
8
+ privateKey: string;
9
+ faucetServiceUrl?: string;
10
+ snapSync?: boolean;
11
+ };
12
+
13
+ export async function getNetworkConfig(): Promise<NetworkConfig> {
14
+ const params = new URLSearchParams(window.location.search);
15
+
16
+ const chainId = Number(params.get("chainId") || import.meta.env.VITE_CHAIN_ID || 31337);
17
+ const chainIndex = supportedChains.findIndex((c) => c.id === chainId);
18
+ const chain = supportedChains[chainIndex];
19
+ if (!chain) {
20
+ throw new Error(`Chain ${chainId} not found`);
21
+ }
22
+
23
+ const world = worlds[chain.id.toString()];
24
+ const worldAddress = params.get("worldAddress") || world?.address;
25
+ if (!worldAddress) {
26
+ throw new Error(`No world address found for chain ${chainId}. Did you run \`mud deploy\`?`);
27
+ }
28
+
29
+ const initialBlockNumber = params.has("initialBlockNumber")
30
+ ? Number(params.get("initialBlockNumber"))
31
+ : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC
32
+
33
+ return {
34
+ clock: {
35
+ period: 1000,
36
+ initialTime: 0,
37
+ syncInterval: 5000,
38
+ },
39
+ provider: {
40
+ chainId,
41
+ jsonRpcUrl: params.get("rpc") ?? chain.rpcUrls.default.http[0],
42
+ wsRpcUrl: params.get("wsRpc") ?? chain.rpcUrls.default.webSocket?.[0],
43
+ },
44
+ privateKey: getBurnerWallet().value,
45
+ chainId,
46
+ modeUrl: params.get("mode") ?? chain.modeUrl,
47
+ faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
48
+ worldAddress,
49
+ initialBlockNumber,
50
+ snapSync: params.get("snapSync") === "true",
51
+ disableCache: params.get("cache") === "false",
52
+ };
53
+ }
@@ -0,0 +1,16 @@
1
+ import { createClientComponents } from "./createClientComponents";
2
+ import { createSystemCalls } from "./createSystemCalls";
3
+ import { setupNetwork } from "./setupNetwork";
4
+
5
+ export type SetupResult = Awaited<ReturnType<typeof setup>>;
6
+
7
+ export async function setup() {
8
+ const network = await setupNetwork();
9
+ const components = createClientComponents(network);
10
+ const systemCalls = createSystemCalls(network);
11
+ return {
12
+ network,
13
+ components,
14
+ systemCalls,
15
+ };
16
+ }
@@ -0,0 +1,102 @@
1
+ import { setupMUDV2Network } from "@latticexyz/std-client";
2
+ import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network";
3
+ import { getNetworkConfig } from "./getNetworkConfig";
4
+ import { defineContractComponents } from "./contractComponents";
5
+ import { world } from "./world";
6
+ import { Contract, Signer, utils } from "ethers";
7
+ import { JsonRpcProvider } from "@ethersproject/providers";
8
+ import { IWorld__factory } from "contracts/types/ethers-contracts/factories/IWorld__factory";
9
+ import { getTableIds } from "@latticexyz/utils";
10
+ import storeConfig from "contracts/mud.config";
11
+
12
+ export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;
13
+
14
+ export async function setupNetwork() {
15
+ const contractComponents = defineContractComponents(world);
16
+ const networkConfig = await getNetworkConfig();
17
+ const result = await setupMUDV2Network<typeof contractComponents, typeof storeConfig>({
18
+ networkConfig,
19
+ world,
20
+ contractComponents,
21
+ syncThread: "main",
22
+ storeConfig,
23
+ worldAbi: IWorld__factory.abi,
24
+ });
25
+
26
+ // Request drip from faucet
27
+ const signer = result.network.signer.get();
28
+ if (networkConfig.faucetServiceUrl && signer) {
29
+ const address = await signer.getAddress();
30
+ console.info("[Dev Faucet]: Player address -> ", address);
31
+
32
+ const faucet = createFaucetService(networkConfig.faucetServiceUrl);
33
+
34
+ const requestDrip = async () => {
35
+ const balance = await signer.getBalance();
36
+ console.info(`[Dev Faucet]: Player balance -> ${balance}`);
37
+ const lowBalance = balance?.lte(utils.parseEther("1"));
38
+ if (lowBalance) {
39
+ console.info("[Dev Faucet]: Balance is low, dripping funds to player");
40
+ // Double drip
41
+ await faucet.dripDev({ address });
42
+ await faucet.dripDev({ address });
43
+ }
44
+ };
45
+
46
+ requestDrip();
47
+ // Request a drip every 20 seconds
48
+ setInterval(requestDrip, 20000);
49
+ }
50
+
51
+ const provider = result.network.providers.get().json;
52
+ const signerOrProvider = signer ?? provider;
53
+ // Create a World contract instance
54
+ const worldContract = IWorld__factory.connect(networkConfig.worldAddress, signerOrProvider);
55
+
56
+ if (networkConfig.snapSync) {
57
+ const currentBlockNumber = await provider.getBlockNumber();
58
+ const tableRecords = await getSnapSyncRecords(
59
+ networkConfig.worldAddress,
60
+ getTableIds(storeConfig),
61
+ currentBlockNumber,
62
+ signerOrProvider
63
+ );
64
+
65
+ console.log(`Syncing ${tableRecords.length} records`);
66
+ result.startSync(tableRecords, currentBlockNumber);
67
+ } else {
68
+ result.startSync();
69
+ }
70
+
71
+ // Create a fast tx executor
72
+ const fastTxExecutor =
73
+ signer?.provider instanceof JsonRpcProvider
74
+ ? await createFastTxExecutor(signer as Signer & { provider: JsonRpcProvider })
75
+ : null;
76
+
77
+ // TODO: infer this from fastTxExecute signature?
78
+ type BoundFastTxExecuteFn<C extends Contract> = <F extends keyof C>(
79
+ func: F,
80
+ args: Parameters<C[F]>,
81
+ options?: {
82
+ retryCount?: number;
83
+ }
84
+ ) => Promise<ReturnType<C[F]>>;
85
+
86
+ function bindFastTxExecute<C extends Contract>(contract: C): BoundFastTxExecuteFn<C> {
87
+ return async function (...args) {
88
+ if (!fastTxExecutor) {
89
+ throw new Error("no signer");
90
+ }
91
+ const { tx } = await fastTxExecutor.fastTxExecute(contract, ...args);
92
+ return await tx;
93
+ };
94
+ }
95
+
96
+ return {
97
+ ...result,
98
+ worldContract,
99
+ worldSend: bindFastTxExecute(worldContract),
100
+ fastTxExecutor,
101
+ };
102
+ }
@@ -0,0 +1,5 @@
1
+ import { MUDChain, latticeTestnet } from "@latticexyz/common/chains";
2
+ import { foundry } from "@wagmi/chains";
3
+
4
+ // If you are deploying to chains other than anvil or Lattice testnet, add them here
5
+ export const supportedChains: MUDChain[] = [foundry, latticeTestnet];
@@ -0,0 +1,3 @@
1
+ import { createWorld } from "@latticexyz/recs";
2
+
3
+ export const world = createWorld();
@@ -0,0 +1,60 @@
1
+ import { getComponentValue } from "@latticexyz/recs";
2
+ import { useEffect } from "react";
3
+ import { useMUD } from "./MUDContext";
4
+
5
+ export const useKeyboardMovement = () => {
6
+ const {
7
+ components: { Position },
8
+ network: {
9
+ worldSend,
10
+ network: { signer },
11
+ playerEntity,
12
+ },
13
+ } = useMUD();
14
+
15
+ useEffect(() => {
16
+ const moveTo = async (x: number, y: number, z: number) => {
17
+ const s = signer.get();
18
+ if (!s) throw new Error("No signer");
19
+
20
+ const txResult = await worldSend("move", [x, y, z]);
21
+ await txResult.wait();
22
+ };
23
+
24
+ const moveBy = async (deltaX: number, deltaY: number, deltaZ: number) => {
25
+ if (playerEntity) {
26
+ const playerPosition = getComponentValue(Position, playerEntity);
27
+
28
+ if (playerPosition) {
29
+ await moveTo(playerPosition.x + deltaX, playerPosition.y + deltaY, playerPosition.z + deltaZ);
30
+ } else {
31
+ await moveTo(deltaX, deltaY, deltaZ);
32
+ }
33
+ }
34
+ };
35
+
36
+ const listener = (e: KeyboardEvent) => {
37
+ if (e.key === "ArrowUp") {
38
+ moveBy(1, 0, 0);
39
+ }
40
+ if (e.key === "ArrowDown") {
41
+ moveBy(-1, 0, 0);
42
+ }
43
+ if (e.key === "ArrowLeft") {
44
+ moveBy(0, 0, -1);
45
+ }
46
+ if (e.key === "ArrowRight") {
47
+ moveBy(0, 0, 1);
48
+ }
49
+ if (e.key === " ") {
50
+ moveBy(0, 1, 0);
51
+ }
52
+ if (e.ctrlKey) {
53
+ moveBy(0, -1, 0);
54
+ }
55
+ };
56
+
57
+ window.addEventListener("keydown", listener);
58
+ return () => window.removeEventListener("keydown", listener);
59
+ }, [Position, playerEntity, signer, worldSend]);
60
+ };
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "types": ["vite/client"],
4
+ "target": "ESNext",
5
+ "useDefineForClassFields": true,
6
+ "module": "ESNext",
7
+ "lib": ["ESNext", "DOM"],
8
+ "moduleResolution": "Node",
9
+ "strict": true,
10
+ "resolveJsonModule": true,
11
+ "isolatedModules": true,
12
+ "esModuleInterop": true,
13
+ "noEmit": true,
14
+ "skipLibCheck": true,
15
+ "jsx": "react-jsx",
16
+ "jsxImportSource": "react"
17
+ },
18
+ "include": ["src"]
19
+ }
@@ -0,0 +1,15 @@
1
+ import { defineConfig } from "vite";
2
+ import react from "@vitejs/plugin-react";
3
+
4
+ export default defineConfig({
5
+ plugins: [react()],
6
+ server: {
7
+ port: 3000,
8
+ fs: {
9
+ strict: false,
10
+ },
11
+ },
12
+ build: {
13
+ target: "es2022",
14
+ },
15
+ });
@@ -0,0 +1,8 @@
1
+ # This .env file is for demonstration purposes only.
2
+ #
3
+ # This should usually be excluded via .gitignore and the env vars attached to
4
+ # your deployment enviroment, but we're including this here for ease of local
5
+ # development. Please do not commit changes to this file!
6
+ #
7
+ # Anvil default private key:
8
+ PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
@@ -0,0 +1,11 @@
1
+ out/
2
+ cache/
3
+ node_modules/
4
+ bindings/
5
+ artifacts/
6
+ abi/
7
+ types/
8
+ broadcast/
9
+
10
+ # Ignore MUD deploy artifacts
11
+ deploys/**/*.json
@@ -0,0 +1,8 @@
1
+ {
2
+ "plugins": ["prettier-plugin-solidity"],
3
+ "printWidth": 120,
4
+ "semi": true,
5
+ "tabWidth": 2,
6
+ "useTabs": false,
7
+ "bracketSpacing": true
8
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": ["solhint:recommended", "mud"],
3
+ "plugins": ["mud"],
4
+ "rules": {
5
+ "compiler-version": ["error", ">=0.8.0"],
6
+ "avoid-low-level-calls": "off",
7
+ "no-inline-assembly": "off",
8
+ "func-visibility": ["warn", { "ignoreConstructors": true }],
9
+ "no-empty-blocks": "off",
10
+ "no-complex-fallback": "off"
11
+ }
12
+ }
@@ -0,0 +1,22 @@
1
+ [profile.default]
2
+ solc_version = "0.8.13"
3
+ ffi = false
4
+ fuzz_runs = 256
5
+ optimizer = true
6
+ optimizer_runs = 3000
7
+ verbosity = 2
8
+ src = "src"
9
+ test = "test"
10
+ out = "out"
11
+ allow_paths = ["../../node_modules", "../../../../packages"]
12
+ extra_output_files = [
13
+ "abi",
14
+ "evm.bytecode"
15
+ ]
16
+ fs_permissions = [{ access = "read", path = "./"}]
17
+
18
+ [profile.lattice-testnet]
19
+ eth_rpc_url = "https://follower.testnet-chain.linfra.xyz"
20
+
21
+ [profile.hackathon-testnet]
22
+ eth_rpc_url = "https://lattice-goerli-sequencer.optimism.io"
@@ -0,0 +1,13 @@
1
+ import { mudConfig } from "@latticexyz/world/register";
2
+
3
+ export default mudConfig({
4
+ tables: {
5
+ Position: {
6
+ schema: {
7
+ x: "int32",
8
+ y: "int32",
9
+ z: "int32",
10
+ },
11
+ },
12
+ },
13
+ });