create-mud 2.2.15-7482a5ae322f26278722081838b6103ce6d264e6 → 2.2.15-7fa68f6717ecd3fc2c734ca31c842c1242175cbe

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 (46) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/cli.js.map +1 -1
  3. package/dist/templates/react/gitignore +5 -14
  4. package/dist/templates/react/mprocs.yaml +1 -9
  5. package/dist/templates/react/package.json +4 -28
  6. package/dist/templates/react/packages/client/gitignore +2 -0
  7. package/dist/templates/react/packages/client/package.json +12 -21
  8. package/dist/templates/react/packages/client/src/App.tsx +100 -38
  9. package/dist/templates/react/packages/client/src/MUDContext.tsx +21 -0
  10. package/dist/templates/react/packages/client/src/index.tsx +31 -17
  11. package/dist/templates/react/packages/client/src/mud/createSystemCalls.ts +56 -0
  12. package/dist/templates/react/packages/client/src/mud/getNetworkConfig.ts +76 -0
  13. package/dist/templates/react/packages/client/src/mud/setup.ts +18 -0
  14. package/dist/templates/react/packages/client/src/mud/setupNetwork.ts +101 -0
  15. package/dist/templates/react/packages/client/src/mud/supportedChains.ts +20 -0
  16. package/dist/templates/react/packages/client/vite.config.ts +6 -0
  17. package/dist/templates/react/packages/contracts/gitignore +8 -12
  18. package/dist/templates/react/packages/contracts/mud.config.ts +8 -13
  19. package/dist/templates/react/packages/contracts/package.json +7 -8
  20. package/dist/templates/react/packages/contracts/script/PostDeploy.s.sol +9 -1
  21. package/dist/templates/react/packages/contracts/src/codegen/index.sol +1 -1
  22. package/dist/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +522 -0
  23. package/dist/templates/react/packages/contracts/src/codegen/world/{IMoveSystem.sol → ITasksSystem.sol} +9 -5
  24. package/dist/templates/react/packages/contracts/src/codegen/world/IWorld.sol +2 -2
  25. package/dist/templates/react/packages/contracts/src/systems/TasksSystem.sol +24 -0
  26. package/dist/templates/react/packages/contracts/test/TasksTest.t.sol +30 -0
  27. package/dist/templates/react/packages/contracts/worlds.json +1 -1
  28. package/package.json +1 -1
  29. package/dist/templates/react/packages/client/postcss.config.cjs +0 -6
  30. package/dist/templates/react/packages/client/src/GameMap.tsx +0 -78
  31. package/dist/templates/react/packages/client/src/Providers.tsx +0 -44
  32. package/dist/templates/react/packages/client/src/common.ts +0 -6
  33. package/dist/templates/react/packages/client/src/mud/Explorer.tsx +0 -32
  34. package/dist/templates/react/packages/client/src/mud/getWorldDeploy.ts +0 -23
  35. package/dist/templates/react/packages/client/src/mud/stash.ts +0 -4
  36. package/dist/templates/react/packages/client/src/mud/useSyncProgress.ts +0 -21
  37. package/dist/templates/react/packages/client/src/mud/useWorldContract.ts +0 -45
  38. package/dist/templates/react/packages/client/src/ui/icons/ArrowDownIcon.tsx +0 -22
  39. package/dist/templates/react/packages/client/src/ui/icons/MUDIcon.tsx +0 -25
  40. package/dist/templates/react/packages/client/src/useKeyboardMovement.ts +0 -26
  41. package/dist/templates/react/packages/client/src/wagmiConfig.ts +0 -49
  42. package/dist/templates/react/packages/client/tailwind.config.ts +0 -10
  43. package/dist/templates/react/packages/contracts/out/IWorld.sol/IWorld.abi.json +0 -2021
  44. package/dist/templates/react/packages/contracts/src/MoveSystem.sol +0 -26
  45. package/dist/templates/react/packages/contracts/src/codegen/common.sol +0 -11
  46. package/dist/templates/react/packages/contracts/src/codegen/tables/Position.sol +0 -318
package/dist/cli.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- var l=Object.create;var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var h=(e,t,s,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of m(t))!u.call(e,r)&&r!==s&&a(e,r,{get:()=>t[r],enumerable:!(p=o(t,r))||p.enumerable});return e};var j=(e,t,s)=>(s=e!=null?l(d(e)):{},h(t||!e||!e.__esModule?a(s,"default",{value:e,enumerable:!0}):s,e));var i=require("create-create-app"),n=j(require("path"));var c={name:"create-mud",version:"2.2.15-7482a5ae322f26278722081838b6103ce6d264e6",description:"Create a new MUD project",license:"MIT",author:"Lattice <mud@lattice.xyz>",bin:"dist/cli.js",files:["dist"],scripts:{build:"pnpm run build:js","build:js":"tsup && tsx ./scripts/copy-templates.ts",clean:"pnpm run clean:js","clean:js":"shx rm -rf dist",dev:"tsup --watch",prepublishOnly:"npm run clean && npm run build",test:"pnpm run test:vanilla && pnpm run test:react && pnpm run test:react-ecs && pnpm run test:phaser && pnpm run test:threejs","test:ci":"pnpm run test","test:phaser":"dist/cli.js test-project --template phaser && shx rm -rf test-project","test:react":"dist/cli.js test-project --template react && shx rm -rf test-project","test:react-ecs":"dist/cli.js test-project --template react-ecs && shx rm -rf test-project","test:threejs":"dist/cli.js test-project --template threejs && shx rm -rf test-project","test:vanilla":"dist/cli.js test-project --template vanilla && shx rm -rf test-project"},dependencies:{"create-create-app":"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63"},devDependencies:{"@types/node":"^18.15.11",execa:"^7.0.0",tsup:"^6.7.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"}};var b=n.default.resolve(__dirname,"..","dist","templates");(0,i.create)("create-mud",{templateRoot:b,defaultTemplate:"vanilla",defaultPackageManager:"pnpm",promptForDescription:!1,promptForAuthor:!1,promptForEmail:!1,promptForLicense:!1,promptForTemplate:!0,caveat:({answers:e,packageManager:t})=>`Done! Play in the MUD with \`cd ${e.name}\` and \`${t} run dev\``,extra:{"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:c.version}}});
2
+ var l=Object.create;var a=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var d=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var h=(e,t,s,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of m(t))!u.call(e,r)&&r!==s&&a(e,r,{get:()=>t[r],enumerable:!(p=o(t,r))||p.enumerable});return e};var j=(e,t,s)=>(s=e!=null?l(d(e)):{},h(t||!e||!e.__esModule?a(s,"default",{value:e,enumerable:!0}):s,e));var i=require("create-create-app"),n=j(require("path"));var c={name:"create-mud",version:"2.2.15-7fa68f6717ecd3fc2c734ca31c842c1242175cbe",description:"Create a new MUD project",license:"MIT",author:"Lattice <mud@lattice.xyz>",bin:"dist/cli.js",files:["dist"],scripts:{build:"pnpm run build:js","build:js":"tsup && tsx ./scripts/copy-templates.ts",clean:"pnpm run clean:js","clean:js":"shx rm -rf dist",dev:"tsup --watch",prepublishOnly:"npm run clean && npm run build",test:"pnpm run test:vanilla && pnpm run test:react && pnpm run test:react-ecs && pnpm run test:phaser && pnpm run test:threejs","test:ci":"pnpm run test","test:phaser":"dist/cli.js test-project --template phaser && shx rm -rf test-project","test:react":"dist/cli.js test-project --template react && shx rm -rf test-project","test:react-ecs":"dist/cli.js test-project --template react-ecs && shx rm -rf test-project","test:threejs":"dist/cli.js test-project --template threejs && shx rm -rf test-project","test:vanilla":"dist/cli.js test-project --template vanilla && shx rm -rf test-project"},dependencies:{"create-create-app":"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63"},devDependencies:{"@types/node":"^18.15.11",execa:"^7.0.0",tsup:"^6.7.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"}};var b=n.default.resolve(__dirname,"..","dist","templates");(0,i.create)("create-mud",{templateRoot:b,defaultTemplate:"vanilla",defaultPackageManager:"pnpm",promptForDescription:!1,promptForAuthor:!1,promptForEmail:!1,promptForLicense:!1,promptForTemplate:!0,caveat:({answers:e,packageManager:t})=>`Done! Play in the MUD with \`cd ${e.name}\` and \`${t} run dev\``,extra:{"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:c.version}}});
3
3
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts","../package.json"],"sourcesContent":["#!/usr/bin/env node\nimport { create } from \"create-create-app\";\nimport path from \"node:path\";\nimport packageJson from \"../package.json\";\n\nconst templateRoot = path.resolve(__dirname, \"..\", \"dist\", \"templates\");\n\n// See https://github.com/uetchy/create-create-app/blob/master/README.md for other options.\ncreate(\"create-mud\", {\n templateRoot,\n defaultTemplate: \"vanilla\",\n // templates use pnpm workspaces, so default to that for now\n // not sure if it's worth trying to support multiple kinds of package managers for monorepos, given the tooling is so different\n defaultPackageManager: \"pnpm\",\n promptForDescription: false,\n promptForAuthor: false,\n promptForEmail: false,\n promptForLicense: false,\n promptForTemplate: true,\n caveat: ({ answers, packageManager }) =>\n `Done! Play in the MUD with \\`cd ${answers.name}\\` and \\`${packageManager} run dev\\``,\n extra: {\n \"mud-version\": {\n type: \"input\",\n describe: \"The version of MUD packages to use, defaults to latest\",\n default: packageJson.version,\n },\n },\n});\n","{\n \"name\": \"create-mud\",\n \"version\": \"2.2.15-7482a5ae322f26278722081838b6103ce6d264e6\",\n \"description\": \"Create a new MUD project\",\n \"license\": \"MIT\",\n \"author\": \"Lattice <mud@lattice.xyz>\",\n \"bin\": \"dist/cli.js\",\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"build\": \"pnpm run build:js\",\n \"build:js\": \"tsup && tsx ./scripts/copy-templates.ts\",\n \"clean\": \"pnpm run clean:js\",\n \"clean:js\": \"shx rm -rf dist\",\n \"dev\": \"tsup --watch\",\n \"prepublishOnly\": \"npm run clean && npm run build\",\n \"test\": \"pnpm run test:vanilla && pnpm run test:react && pnpm run test:react-ecs && pnpm run test:phaser && pnpm run test:threejs\",\n \"test:ci\": \"pnpm run test\",\n \"test:phaser\": \"dist/cli.js test-project --template phaser && shx rm -rf test-project\",\n \"test:react\": \"dist/cli.js test-project --template react && shx rm -rf test-project\",\n \"test:react-ecs\": \"dist/cli.js test-project --template react-ecs && shx rm -rf test-project\",\n \"test:threejs\": \"dist/cli.js test-project --template threejs && shx rm -rf test-project\",\n \"test:vanilla\": \"dist/cli.js test-project --template vanilla && shx rm -rf test-project\"\n },\n \"dependencies\": {\n \"create-create-app\": \"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^18.15.11\",\n \"execa\": \"^7.0.0\",\n \"tsup\": \"^6.7.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org\"\n }\n}\n"],"mappings":";2cACA,IAAAA,EAAuB,6BACvBC,EAAiB,mBCFjB,IAAAC,EAAA,CACE,KAAQ,aACR,QAAW,kDACX,YAAe,2BACf,QAAW,MACX,OAAU,4BACV,IAAO,cACP,MAAS,CACP,MACF,EACA,QAAW,CACT,MAAS,oBACT,WAAY,0CACZ,MAAS,oBACT,WAAY,kBACZ,IAAO,eACP,eAAkB,iCAClB,KAAQ,2HACR,UAAW,gBACX,cAAe,wEACf,aAAc,uEACd,iBAAkB,2EAClB,eAAgB,yEAChB,eAAgB,wEAClB,EACA,aAAgB,CACd,oBAAqB,yFACvB,EACA,gBAAmB,CACjB,cAAe,YACf,MAAS,SACT,KAAQ,QACV,EACA,cAAiB,CACf,OAAU,SACV,SAAY,4BACd,CACF,EDhCA,IAAMC,EAAe,EAAAC,QAAK,QAAQ,UAAW,KAAM,OAAQ,WAAW,KAGtE,UAAO,aAAc,CACnB,aAAAD,EACA,gBAAiB,UAGjB,sBAAuB,OACvB,qBAAsB,GACtB,gBAAiB,GACjB,eAAgB,GAChB,iBAAkB,GAClB,kBAAmB,GACnB,OAAQ,CAAC,CAAE,QAAAE,EAAS,eAAAC,CAAe,IACjC,mCAAmCD,EAAQ,gBAAgBC,cAC7D,MAAO,CACL,cAAe,CACb,KAAM,QACN,SAAU,yDACV,QAASC,EAAY,OACvB,CACF,CACF,CAAC","names":["import_create_create_app","import_node_path","package_default","templateRoot","path","answers","packageManager","package_default"]}
1
+ {"version":3,"sources":["../src/cli.ts","../package.json"],"sourcesContent":["#!/usr/bin/env node\nimport { create } from \"create-create-app\";\nimport path from \"node:path\";\nimport packageJson from \"../package.json\";\n\nconst templateRoot = path.resolve(__dirname, \"..\", \"dist\", \"templates\");\n\n// See https://github.com/uetchy/create-create-app/blob/master/README.md for other options.\ncreate(\"create-mud\", {\n templateRoot,\n defaultTemplate: \"vanilla\",\n // templates use pnpm workspaces, so default to that for now\n // not sure if it's worth trying to support multiple kinds of package managers for monorepos, given the tooling is so different\n defaultPackageManager: \"pnpm\",\n promptForDescription: false,\n promptForAuthor: false,\n promptForEmail: false,\n promptForLicense: false,\n promptForTemplate: true,\n caveat: ({ answers, packageManager }) =>\n `Done! Play in the MUD with \\`cd ${answers.name}\\` and \\`${packageManager} run dev\\``,\n extra: {\n \"mud-version\": {\n type: \"input\",\n describe: \"The version of MUD packages to use, defaults to latest\",\n default: packageJson.version,\n },\n },\n});\n","{\n \"name\": \"create-mud\",\n \"version\": \"2.2.15-7fa68f6717ecd3fc2c734ca31c842c1242175cbe\",\n \"description\": \"Create a new MUD project\",\n \"license\": \"MIT\",\n \"author\": \"Lattice <mud@lattice.xyz>\",\n \"bin\": \"dist/cli.js\",\n \"files\": [\n \"dist\"\n ],\n \"scripts\": {\n \"build\": \"pnpm run build:js\",\n \"build:js\": \"tsup && tsx ./scripts/copy-templates.ts\",\n \"clean\": \"pnpm run clean:js\",\n \"clean:js\": \"shx rm -rf dist\",\n \"dev\": \"tsup --watch\",\n \"prepublishOnly\": \"npm run clean && npm run build\",\n \"test\": \"pnpm run test:vanilla && pnpm run test:react && pnpm run test:react-ecs && pnpm run test:phaser && pnpm run test:threejs\",\n \"test:ci\": \"pnpm run test\",\n \"test:phaser\": \"dist/cli.js test-project --template phaser && shx rm -rf test-project\",\n \"test:react\": \"dist/cli.js test-project --template react && shx rm -rf test-project\",\n \"test:react-ecs\": \"dist/cli.js test-project --template react-ecs && shx rm -rf test-project\",\n \"test:threejs\": \"dist/cli.js test-project --template threejs && shx rm -rf test-project\",\n \"test:vanilla\": \"dist/cli.js test-project --template vanilla && shx rm -rf test-project\"\n },\n \"dependencies\": {\n \"create-create-app\": \"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^18.15.11\",\n \"execa\": \"^7.0.0\",\n \"tsup\": \"^6.7.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org\"\n }\n}\n"],"mappings":";2cACA,IAAAA,EAAuB,6BACvBC,EAAiB,mBCFjB,IAAAC,EAAA,CACE,KAAQ,aACR,QAAW,kDACX,YAAe,2BACf,QAAW,MACX,OAAU,4BACV,IAAO,cACP,MAAS,CACP,MACF,EACA,QAAW,CACT,MAAS,oBACT,WAAY,0CACZ,MAAS,oBACT,WAAY,kBACZ,IAAO,eACP,eAAkB,iCAClB,KAAQ,2HACR,UAAW,gBACX,cAAe,wEACf,aAAc,uEACd,iBAAkB,2EAClB,eAAgB,yEAChB,eAAgB,wEAClB,EACA,aAAgB,CACd,oBAAqB,yFACvB,EACA,gBAAmB,CACjB,cAAe,YACf,MAAS,SACT,KAAQ,QACV,EACA,cAAiB,CACf,OAAU,SACV,SAAY,4BACd,CACF,EDhCA,IAAMC,EAAe,EAAAC,QAAK,QAAQ,UAAW,KAAM,OAAQ,WAAW,KAGtE,UAAO,aAAc,CACnB,aAAAD,EACA,gBAAiB,UAGjB,sBAAuB,OACvB,qBAAsB,GACtB,gBAAiB,GACjB,eAAgB,GAChB,iBAAkB,GAClB,kBAAmB,GACnB,OAAQ,CAAC,CAAE,QAAAE,EAAS,eAAAC,CAAe,IACjC,mCAAmCD,EAAQ,gBAAgBC,cAC7D,MAAO,CACL,cAAe,CACb,KAAM,QACN,SAAU,yDACV,QAASC,EAAY,OACvB,CACF,CACF,CAAC","names":["import_create_create_app","import_node_path","package_default","templateRoot","path","answers","packageManager","package_default"]}
@@ -1,16 +1,7 @@
1
- .DS_Store
2
- logs
3
- *.log
4
-
5
1
  node_modules
6
2
 
7
- .env.*
8
-
9
- # foundry
10
- cache
11
- broadcast
12
- out/*
13
- !out/IWorld.sol
14
- out/IWorld.sol/*
15
- !out/IWorld.sol/IWorld.abi.json
16
- !out/IWorld.sol/IWorld.abi.d.json.ts
3
+ # mud artifacts
4
+ .mud
5
+ # sqlite indexer data
6
+ *.db
7
+ *.db-journal
@@ -1,4 +1,3 @@
1
- scrollback: 10000
2
1
  procs:
3
2
  client:
4
3
  cwd: packages/client
@@ -6,16 +5,9 @@ procs:
6
5
  contracts:
7
6
  cwd: packages/contracts
8
7
  shell: pnpm mud dev-contracts --rpc http://127.0.0.1:8545
9
- deploy-prereqs:
10
- cwd: packages/contracts
11
- shell: pnpm deploy-local-prereqs
12
- env:
13
- DEBUG: "mud:*"
14
- # Anvil default account (0x70997970C51812dc3A010C7d01b50e0d17dc79C8)
15
- PRIVATE_KEY: "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
16
8
  anvil:
17
9
  cwd: packages/contracts
18
- shell: anvil --block-time 2
10
+ shell: anvil --base-fee 0 --block-time 2
19
11
  explorer:
20
12
  cwd: packages/contracts
21
13
  shell: pnpm explorer
@@ -12,10 +12,10 @@
12
12
  "test": "pnpm recursive run test"
13
13
  },
14
14
  "devDependencies": {
15
- "@latticexyz/cli": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
16
- "@latticexyz/common": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
17
- "@latticexyz/explorer": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
18
- "@latticexyz/store-indexer": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
15
+ "@latticexyz/cli": "{{mud-version}}",
16
+ "@latticexyz/common": "{{mud-version}}",
17
+ "@latticexyz/explorer": "{{mud-version}}",
18
+ "@latticexyz/store-indexer": "{{mud-version}}",
19
19
  "@types/debug": "4.1.7",
20
20
  "@typescript-eslint/eslint-plugin": "7.1.1",
21
21
  "@typescript-eslint/parser": "7.1.1",
@@ -27,29 +27,5 @@
27
27
  "engines": {
28
28
  "node": "^18",
29
29
  "pnpm": "^8 || ^9"
30
- },
31
- "pnpm": {
32
- "overrides": {
33
- "@latticexyz/abi-ts": "{{mud-version}}",
34
- "@latticexyz/block-logs-stream": "{{mud-version}}",
35
- "@latticexyz/cli": "{{mud-version}}",
36
- "@latticexyz/common": "{{mud-version}}",
37
- "@latticexyz/config": "{{mud-version}}",
38
- "@latticexyz/entrykit": "{{mud-version}}",
39
- "@latticexyz/explorer": "{{mud-version}}",
40
- "@latticexyz/gas-report": "{{mud-version}}",
41
- "@latticexyz/paymaster": "{{mud-version}}",
42
- "@latticexyz/protocol-parser": "{{mud-version}}",
43
- "@latticexyz/recs": "{{mud-version}}",
44
- "@latticexyz/schema-type": "{{mud-version}}",
45
- "@latticexyz/stash": "{{mud-version}}",
46
- "@latticexyz/store": "{{mud-version}}",
47
- "@latticexyz/store-indexer": "{{mud-version}}",
48
- "@latticexyz/store-sync": "{{mud-version}}",
49
- "@latticexyz/utils": "{{mud-version}}",
50
- "@latticexyz/world": "{{mud-version}}",
51
- "@latticexyz/world-module-metadata": "{{mud-version}}",
52
- "@latticexyz/world-modules": "{{mud-version}}"
53
- }
54
30
  }
55
31
  }
@@ -1 +1,3 @@
1
+ node_modules
1
2
  dist
3
+ .DS_Store
@@ -11,34 +11,25 @@
11
11
  "test": "tsc --noEmit"
12
12
  },
13
13
  "dependencies": {
14
- "@latticexyz/common": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
15
- "@latticexyz/entrykit": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
16
- "@latticexyz/explorer": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
17
- "@latticexyz/react": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
18
- "@latticexyz/schema-type": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
19
- "@latticexyz/stash": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
20
- "@latticexyz/store-sync": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
21
- "@latticexyz/utils": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
22
- "@latticexyz/world": "2.2.15-f9de085862ac62ce15fe3b7743916cfd631592ea",
23
- "@tanstack/react-query": "^5.63.0",
14
+ "@latticexyz/common": "{{mud-version}}",
15
+ "@latticexyz/dev-tools": "{{mud-version}}",
16
+ "@latticexyz/react": "{{mud-version}}",
17
+ "@latticexyz/schema-type": "{{mud-version}}",
18
+ "@latticexyz/store-sync": "{{mud-version}}",
19
+ "@latticexyz/utils": "{{mud-version}}",
20
+ "@latticexyz/world": "{{mud-version}}",
24
21
  "contracts": "workspace:*",
25
- "fast-deep-equal": "^3.1.3",
26
- "react": "18.2.0",
27
- "react-dom": "18.2.0",
22
+ "react": "^18.2.0",
23
+ "react-dom": "^18.2.0",
28
24
  "rxjs": "7.5.5",
29
- "tailwind-merge": "^2.6.0",
30
- "viem": "2.21.19",
31
- "wagmi": "2.12.11"
25
+ "viem": "2.21.19"
32
26
  },
33
27
  "devDependencies": {
34
- "@types/react": "18.2.0",
35
- "@types/react-dom": "18.2.0",
28
+ "@types/react": "18.2.22",
29
+ "@types/react-dom": "18.2.7",
36
30
  "@vitejs/plugin-react": "^3.1.0",
37
- "autoprefixer": "^10.4.20",
38
31
  "eslint-plugin-react": "7.31.11",
39
32
  "eslint-plugin-react-hooks": "4.6.0",
40
- "postcss": "^8.4.49",
41
- "tailwindcss": "^3.4.17",
42
33
  "vite": "^4.2.1",
43
34
  "wait-port": "^1.0.4"
44
35
  }
@@ -1,43 +1,105 @@
1
- import { stash } from "./mud/stash";
2
- import { useSyncProgress } from "./mud/useSyncProgress";
3
- import { useRecords } from "@latticexyz/stash/react";
4
- import { AccountButton } from "@latticexyz/entrykit/internal";
5
- import { Direction } from "./common";
6
- import mudConfig from "contracts/mud.config";
7
- import { useMemo } from "react";
8
- import { GameMap } from "./GameMap";
9
- import { useWorldContract } from "./mud/useWorldContract";
10
-
11
- export function App() {
12
- const { isLive, message, percentage } = useSyncProgress();
13
-
14
- const players = useRecords({ stash, table: mudConfig.tables.app__Position });
15
-
16
- const worldContract = useWorldContract();
17
- const onMove = useMemo(
18
- () =>
19
- worldContract
20
- ? async (direction: Direction) => {
21
- await worldContract.write.app__move([mudConfig.enums.Direction.indexOf(direction)]);
22
- }
23
- : undefined,
24
- [worldContract],
25
- );
1
+ import { useMUD } from "./MUDContext";
2
+
3
+ const styleUnset = { all: "unset" } as const;
4
+
5
+ export const App = () => {
6
+ const {
7
+ network: { tables, useStore },
8
+ systemCalls: { addTask, toggleTask, deleteTask },
9
+ } = useMUD();
10
+
11
+ const tasks = useStore((state) => {
12
+ const records = Object.values(state.getRecords(tables.Tasks));
13
+ records.sort((a, b) => Number(a.value.createdAt - b.value.createdAt));
14
+ return records;
15
+ });
26
16
 
27
17
  return (
28
18
  <>
29
- <div className="fixed inset-0 grid place-items-center p-4">
30
- {isLive ? (
31
- <GameMap players={players} onMove={onMove} />
32
- ) : (
33
- <div className="tabular-nums">
34
- {message} ({percentage.toFixed(1)}%)…
35
- </div>
36
- )}
37
- </div>
38
- <div className="fixed top-2 right-2">
39
- <AccountButton />
40
- </div>
19
+ <table>
20
+ <tbody>
21
+ {tasks.map((task) => (
22
+ <tr key={task.id}>
23
+ <td align="right">
24
+ <input
25
+ type="checkbox"
26
+ checked={task.value.completedAt > 0n}
27
+ title={task.value.completedAt === 0n ? "Mark task as completed" : "Mark task as incomplete"}
28
+ onChange={async (event) => {
29
+ event.preventDefault();
30
+ const checkbox = event.currentTarget;
31
+
32
+ checkbox.disabled = true;
33
+ try {
34
+ await toggleTask(task.key.id);
35
+ } finally {
36
+ checkbox.disabled = false;
37
+ }
38
+ }}
39
+ />
40
+ </td>
41
+ <td>{task.value.completedAt > 0n ? <s>{task.value.description}</s> : <>{task.value.description}</>}</td>
42
+ <td align="right">
43
+ <button
44
+ type="button"
45
+ title="Delete task"
46
+ style={styleUnset}
47
+ onClick={async (event) => {
48
+ event.preventDefault();
49
+ if (!window.confirm("Are you sure you want to delete this task?")) return;
50
+
51
+ const button = event.currentTarget;
52
+ button.disabled = true;
53
+ try {
54
+ await deleteTask(task.key.id);
55
+ } finally {
56
+ button.disabled = false;
57
+ }
58
+ }}
59
+ >
60
+ &times;
61
+ </button>
62
+ </td>
63
+ </tr>
64
+ ))}
65
+ </tbody>
66
+ <tfoot>
67
+ <tr>
68
+ <td>
69
+ <input type="checkbox" disabled />
70
+ </td>
71
+ <td colSpan={2}>
72
+ <form
73
+ onSubmit={async (event) => {
74
+ event.preventDefault();
75
+ const form = event.currentTarget;
76
+ const fieldset = form.querySelector("fieldset");
77
+ if (!(fieldset instanceof HTMLFieldSetElement)) return;
78
+
79
+ const formData = new FormData(form);
80
+ const desc = formData.get("description");
81
+ if (typeof desc !== "string") return;
82
+
83
+ fieldset.disabled = true;
84
+ try {
85
+ await addTask(desc);
86
+ form.reset();
87
+ } finally {
88
+ fieldset.disabled = false;
89
+ }
90
+ }}
91
+ >
92
+ <fieldset style={styleUnset}>
93
+ <input type="text" name="description" />{" "}
94
+ <button type="submit" title="Add task">
95
+ Add
96
+ </button>
97
+ </fieldset>
98
+ </form>
99
+ </td>
100
+ </tr>
101
+ </tfoot>
102
+ </table>
41
103
  </>
42
104
  );
43
- }
105
+ };
@@ -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
+ };
@@ -1,20 +1,34 @@
1
- import "tailwindcss/tailwind.css";
2
- import { StrictMode } from "react";
3
- import { createRoot } from "react-dom/client";
4
- import { getWorldDeploy } from "./mud/getWorldDeploy";
5
- import { Providers } from "./Providers";
1
+ import ReactDOM from "react-dom/client";
6
2
  import { App } from "./App";
7
- import { chainId } from "./common";
8
- import { Explorer } from "./mud/Explorer";
3
+ import { setup } from "./mud/setup";
4
+ import { MUDProvider } from "./MUDContext";
5
+ import mudConfig from "contracts/mud.config";
6
+
7
+ const rootElement = document.getElementById("react-root");
8
+ if (!rootElement) throw new Error("React root not found");
9
+ const root = ReactDOM.createRoot(rootElement);
9
10
 
10
11
  // TODO: figure out if we actually want this to be async or if we should render something else in the meantime
11
- getWorldDeploy(chainId).then((worldDeploy) =>
12
- createRoot(document.getElementById("react-root")!).render(
13
- <StrictMode>
14
- <Providers worldDeploy={worldDeploy}>
15
- <App />
16
- <Explorer />
17
- </Providers>
18
- </StrictMode>,
19
- ),
20
- );
12
+ setup().then(async (result) => {
13
+ root.render(
14
+ <MUDProvider value={result}>
15
+ <App />
16
+ </MUDProvider>,
17
+ );
18
+
19
+ // https://vitejs.dev/guide/env-and-mode.html
20
+ if (import.meta.env.DEV) {
21
+ const { mount: mountDevTools } = await import("@latticexyz/dev-tools");
22
+ mountDevTools({
23
+ config: mudConfig,
24
+ publicClient: result.network.publicClient,
25
+ walletClient: result.network.walletClient,
26
+ latestBlock$: result.network.latestBlock$,
27
+ storedBlockLogs$: result.network.storedBlockLogs$,
28
+ worldAddress: result.network.worldContract.address,
29
+ worldAbi: result.network.worldContract.abi,
30
+ write$: result.network.write$,
31
+ useStore: result.network.useStore,
32
+ });
33
+ }
34
+ });
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Create the system calls that the client can use to ask
3
+ * for changes in the World state (using the System contracts).
4
+ */
5
+
6
+ import { Hex } from "viem";
7
+ import { SetupNetworkResult } from "./setupNetwork";
8
+
9
+ export type SystemCalls = ReturnType<typeof createSystemCalls>;
10
+
11
+ export function createSystemCalls(
12
+ /*
13
+ * The parameter list informs TypeScript that:
14
+ *
15
+ * - The first parameter is expected to be a
16
+ * SetupNetworkResult, as defined in setupNetwork.ts
17
+ *
18
+ * Out of this parameter, we only care about two fields:
19
+ * - worldContract (which comes from getContract, see
20
+ * https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L63-L69).
21
+ *
22
+ * - waitForTransaction (which comes from syncToRecs, see
23
+ * https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
24
+ *
25
+ * - From the second parameter, which is a ClientComponent,
26
+ * we only care about Counter. This parameter comes to use
27
+ * through createClientComponents.ts, but it originates in
28
+ * syncToRecs
29
+ * (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
30
+ */
31
+ { tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult,
32
+ ) {
33
+ const addTask = async (label: string) => {
34
+ const tx = await worldContract.write.app__addTask([label]);
35
+ await waitForTransaction(tx);
36
+ };
37
+
38
+ const toggleTask = async (id: Hex) => {
39
+ const isComplete = (useStore.getState().getValue(tables.Tasks, { id })?.completedAt ?? 0n) > 0n;
40
+ const tx = isComplete
41
+ ? await worldContract.write.app__resetTask([id])
42
+ : await worldContract.write.app__completeTask([id]);
43
+ await waitForTransaction(tx);
44
+ };
45
+
46
+ const deleteTask = async (id: Hex) => {
47
+ const tx = await worldContract.write.app__deleteTask([id]);
48
+ await waitForTransaction(tx);
49
+ };
50
+
51
+ return {
52
+ addTask,
53
+ toggleTask,
54
+ deleteTask,
55
+ };
56
+ }
@@ -0,0 +1,76 @@
1
+ /*
2
+ * Network specific configuration for the client.
3
+ * By default connect to the anvil test network.
4
+ *
5
+ */
6
+
7
+ /*
8
+ * By default the template just creates a temporary wallet
9
+ * (called a burner wallet).
10
+ */
11
+ import { getBurnerPrivateKey } from "@latticexyz/common";
12
+
13
+ /*
14
+ * Import the addresses of the World, possibly on multiple chains,
15
+ * from packages/contracts/worlds.json. When the contracts package
16
+ * deploys a new `World`, it updates this file.
17
+ */
18
+ import worlds from "contracts/worlds.json";
19
+
20
+ /*
21
+ * The supported chains.
22
+ */
23
+ import { supportedChains } from "./supportedChains";
24
+
25
+ export async function getNetworkConfig() {
26
+ const params = new URLSearchParams(window.location.search);
27
+
28
+ /*
29
+ * The chain ID is the first item available from this list:
30
+ * 1. chainId query parameter
31
+ * 2. chainid query parameter
32
+ * 3. The VITE_CHAIN_ID environment variable set when the
33
+ * vite dev server was started or client was built
34
+ * 4. The default, 31337 (anvil)
35
+ */
36
+ const chainId = Number(params.get("chainId") || params.get("chainid") || import.meta.env.VITE_CHAIN_ID || 31337);
37
+
38
+ /*
39
+ * Find the chain (unless it isn't in the list of supported chains).
40
+ */
41
+ const chainIndex = supportedChains.findIndex((c) => c.id === chainId);
42
+ const chain = supportedChains[chainIndex];
43
+ if (!chain) {
44
+ throw new Error(`Chain ${chainId} not found`);
45
+ }
46
+
47
+ /*
48
+ * Get the address of the World. If you want to use a
49
+ * different address than the one in worlds.json,
50
+ * provide it as worldAddress in the query string.
51
+ */
52
+ const world = worlds[chain.id.toString()];
53
+ const worldAddress = params.get("worldAddress") || world?.address;
54
+ if (!worldAddress) {
55
+ throw new Error(`No world address found for chain ${chainId}. Did you run \`mud deploy\`?`);
56
+ }
57
+
58
+ /*
59
+ * MUD clients use events to synchronize the database, meaning
60
+ * they need to look as far back as when the World was started.
61
+ * The block number for the World start can be specified either
62
+ * on the URL (as initialBlockNumber) or in the worlds.json
63
+ * file. If neither has it, it starts at the first block, zero.
64
+ */
65
+ const initialBlockNumber = params.has("initialBlockNumber")
66
+ ? Number(params.get("initialBlockNumber"))
67
+ : world?.blockNumber ?? 0n;
68
+
69
+ return {
70
+ privateKey: getBurnerPrivateKey(),
71
+ chainId,
72
+ chain,
73
+ worldAddress,
74
+ initialBlockNumber,
75
+ };
76
+ }
@@ -0,0 +1,18 @@
1
+ /*
2
+ * This file sets up all the definitions required for a MUD client.
3
+ */
4
+
5
+ import { createSystemCalls } from "./createSystemCalls";
6
+ import { setupNetwork } from "./setupNetwork";
7
+
8
+ export type SetupResult = Awaited<ReturnType<typeof setup>>;
9
+
10
+ export async function setup() {
11
+ const network = await setupNetwork();
12
+ const systemCalls = createSystemCalls(network);
13
+
14
+ return {
15
+ network,
16
+ systemCalls,
17
+ };
18
+ }
@@ -0,0 +1,101 @@
1
+ /*
2
+ * The MUD client code is built on top of viem
3
+ * (https://viem.sh/docs/getting-started.html).
4
+ * This line imports the functions we need from it.
5
+ */
6
+ import {
7
+ createPublicClient,
8
+ fallback,
9
+ webSocket,
10
+ http,
11
+ createWalletClient,
12
+ Hex,
13
+ ClientConfig,
14
+ getContract,
15
+ } from "viem";
16
+ import { syncToZustand } from "@latticexyz/store-sync/zustand";
17
+ import { getNetworkConfig } from "./getNetworkConfig";
18
+ import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
19
+ import { createBurnerAccount, transportObserver, ContractWrite } from "@latticexyz/common";
20
+ import { transactionQueue, writeObserver } from "@latticexyz/common/actions";
21
+ import { Subject, share } from "rxjs";
22
+
23
+ /*
24
+ * Import our MUD config, which includes strong types for
25
+ * our tables and other config options. We use this to generate
26
+ * things like RECS components and get back strong types for them.
27
+ *
28
+ * See https://mud.dev/templates/typescript/contracts#mudconfigts
29
+ * for the source of this information.
30
+ */
31
+ import mudConfig from "contracts/mud.config";
32
+
33
+ export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;
34
+
35
+ export async function setupNetwork() {
36
+ const networkConfig = await getNetworkConfig();
37
+
38
+ /*
39
+ * Create a viem public (read only) client
40
+ * (https://viem.sh/docs/clients/public.html)
41
+ */
42
+ const clientOptions = {
43
+ chain: networkConfig.chain,
44
+ transport: transportObserver(fallback([webSocket(), http()])),
45
+ pollingInterval: 1000,
46
+ } as const satisfies ClientConfig;
47
+
48
+ const publicClient = createPublicClient(clientOptions);
49
+
50
+ /*
51
+ * Create an observable for contract writes that we can
52
+ * pass into MUD dev tools for transaction observability.
53
+ */
54
+ const write$ = new Subject<ContractWrite>();
55
+
56
+ /*
57
+ * Create a temporary wallet and a viem client for it
58
+ * (see https://viem.sh/docs/clients/wallet.html).
59
+ */
60
+ const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex);
61
+ const burnerWalletClient = createWalletClient({
62
+ ...clientOptions,
63
+ account: burnerAccount,
64
+ })
65
+ .extend(transactionQueue())
66
+ .extend(writeObserver({ onWrite: (write) => write$.next(write) }));
67
+
68
+ /*
69
+ * Create an object for communicating with the deployed World.
70
+ */
71
+ const worldContract = getContract({
72
+ address: networkConfig.worldAddress as Hex,
73
+ abi: IWorldAbi,
74
+ client: { public: publicClient, wallet: burnerWalletClient },
75
+ });
76
+
77
+ /*
78
+ * Sync on-chain state into RECS and keeps our client in sync.
79
+ * Uses the MUD indexer if available, otherwise falls back
80
+ * to the viem publicClient to make RPC calls to fetch MUD
81
+ * events from the chain.
82
+ */
83
+ const { tables, useStore, latestBlock$, storedBlockLogs$, waitForTransaction } = await syncToZustand({
84
+ config: mudConfig,
85
+ address: networkConfig.worldAddress as Hex,
86
+ publicClient,
87
+ startBlock: BigInt(networkConfig.initialBlockNumber),
88
+ });
89
+
90
+ return {
91
+ tables,
92
+ useStore,
93
+ publicClient,
94
+ walletClient: burnerWalletClient,
95
+ latestBlock$,
96
+ storedBlockLogs$,
97
+ waitForTransaction,
98
+ worldContract,
99
+ write$: write$.asObservable().pipe(share()),
100
+ };
101
+ }