create-mud 2.2.17-d5f4e1e44bbc260ff21dacdfab0e0f8389e9f304 → 2.2.17-f1d5432fe2c9abb19fa378f790217e67d6dd8504

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 (61) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/cli.js.map +1 -1
  3. package/package.json +1 -1
  4. package/templates/react/packages/client/src/mud/Synced.tsx +1 -1
  5. package/templates/react/packages/contracts/.env +1 -1
  6. package/templates/react/packages/contracts/test/MoveTest.t.sol +0 -2
  7. package/templates/react/packages/contracts/test/WorldTest.t.sol +0 -5
  8. package/templates/react-ecs/mprocs.yaml +9 -1
  9. package/templates/react-ecs/package.json +1 -2
  10. package/templates/react-ecs/packages/client/index.html +2 -2
  11. package/templates/react-ecs/packages/client/package.json +16 -9
  12. package/templates/react-ecs/packages/client/postcss.config.cjs +6 -0
  13. package/templates/react-ecs/packages/client/src/App.tsx +66 -21
  14. package/templates/react-ecs/packages/client/src/Providers.tsx +29 -0
  15. package/templates/react-ecs/packages/client/src/common.ts +27 -0
  16. package/templates/react-ecs/packages/client/src/game/GameMap.tsx +112 -0
  17. package/templates/react-ecs/packages/client/src/game/useKeyboardMovement.ts +26 -0
  18. package/templates/react-ecs/packages/client/src/index.tsx +17 -32
  19. package/templates/react-ecs/packages/client/src/mud/Explorer.tsx +32 -0
  20. package/templates/react-ecs/packages/client/src/mud/Synced.tsx +14 -0
  21. package/templates/react-ecs/packages/client/src/mud/recs.ts +6 -0
  22. package/templates/react-ecs/packages/client/src/mud/useSyncStatus.ts +17 -0
  23. package/templates/react-ecs/packages/client/src/mud/useWorldContract.ts +44 -0
  24. package/templates/react-ecs/packages/client/src/ui/AsyncButton.tsx +41 -0
  25. package/templates/react-ecs/packages/client/src/ui/ErrorFallback.tsx +58 -0
  26. package/templates/react-ecs/packages/client/src/ui/icons/ArrowDownIcon.tsx +22 -0
  27. package/templates/react-ecs/packages/client/src/ui/icons/MUDIcon.tsx +25 -0
  28. package/templates/react-ecs/packages/client/src/wagmiConfig.ts +49 -0
  29. package/templates/react-ecs/packages/client/tailwind.config.ts +10 -0
  30. package/templates/react-ecs/packages/client/tsconfig.json +1 -1
  31. package/templates/react-ecs/packages/client/vite.config.ts +2 -7
  32. package/templates/react-ecs/packages/contracts/.env +1 -1
  33. package/templates/react-ecs/packages/contracts/mud.config.ts +18 -6
  34. package/templates/react-ecs/packages/contracts/out/IWorld.sol/IWorld.abi.json +2039 -0
  35. package/templates/react-ecs/packages/contracts/package.json +1 -0
  36. package/templates/react-ecs/packages/contracts/script/PostDeploy.s.sol +1 -5
  37. package/templates/react-ecs/packages/contracts/src/Entity.sol +20 -0
  38. package/templates/react-ecs/packages/contracts/src/MoveSystem.sol +30 -0
  39. package/templates/react-ecs/packages/contracts/src/SpawnSystem.sol +18 -0
  40. package/templates/react-ecs/packages/contracts/src/codegen/common.sol +11 -0
  41. package/templates/react-ecs/packages/contracts/src/codegen/index.sol +3 -1
  42. package/templates/react-ecs/packages/contracts/src/codegen/tables/{Counter.sol → EntityCount.sol} +35 -35
  43. package/templates/react-ecs/packages/contracts/src/codegen/tables/Owner.sol +202 -0
  44. package/templates/react-ecs/packages/contracts/src/codegen/tables/Position.sol +321 -0
  45. package/templates/react-ecs/packages/contracts/src/codegen/world/IMoveSystem.sol +16 -0
  46. package/templates/react-ecs/packages/contracts/src/codegen/world/{IIncrementSystem.sol → ISpawnSystem.sol} +5 -3
  47. package/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol +3 -2
  48. package/templates/react-ecs/packages/contracts/src/createEntity.sol +11 -0
  49. package/templates/react-ecs/packages/contracts/test/MoveTest.t.sol +39 -0
  50. package/templates/react-ecs/packages/contracts/test/WorldTest.t.sol +16 -0
  51. package/templates/react-ecs/packages/contracts/worlds.json +1 -1
  52. package/templates/react-ecs/packages/client/src/MUDContext.tsx +0 -21
  53. package/templates/react-ecs/packages/client/src/mud/createClientComponents.ts +0 -21
  54. package/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts +0 -51
  55. package/templates/react-ecs/packages/client/src/mud/getNetworkConfig.ts +0 -77
  56. package/templates/react-ecs/packages/client/src/mud/setup.ts +0 -21
  57. package/templates/react-ecs/packages/client/src/mud/setupNetwork.ts +0 -106
  58. package/templates/react-ecs/packages/client/src/mud/supportedChains.ts +0 -20
  59. package/templates/react-ecs/packages/client/src/mud/world.ts +0 -3
  60. package/templates/react-ecs/packages/contracts/src/systems/IncrementSystem.sol +0 -14
  61. package/templates/react-ecs/packages/contracts/test/CounterTest.t.sol +0 -31
package/dist/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- import r from"node:fs/promises";import t from"node:path";import{fileURLToPath as j}from"node:url";import h from"yargs-interactive";import y from"fast-glob";var c={name:"create-mud",version:"2.2.17-d5f4e1e44bbc260ff21dacdfab0e0f8389e9f304",description:"Create a new MUD project",license:"MIT",author:"Lattice <mud@lattice.xyz>",type:"module",bin:"bin/cli.js",files:["bin","dist","templates"],scripts:{build:"pnpm run build:js","build:js":"tsup && pnpm run copy-templates",clean:"pnpm run clean:js","clean:js":"shx rm -rf dist","copy-templates":"tsx ./scripts/copy-templates.ts",dev:"tsup --watch",prepublishOnly:"npm run clean && npm run build",test:"pnpm run copy-templates && pnpm vitest --run && 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":"bin/cli.js --name test-project --template phaser && pnpm --dir test-project install && shx rm -rf test-project","test:react":"bin/cli.js --name test-project --template react && pnpm --dir test-project install && shx rm -rf test-project","test:react-ecs":"bin/cli.js --name test-project --template react-ecs && pnpm --dir test-project install && shx rm -rf test-project","test:threejs":"bin/cli.js --name test-project --template threejs && pnpm --dir test-project install && shx rm -rf test-project","test:vanilla":"bin/cli.js --name test-project --template vanilla && pnpm --dir test-project install && shx rm -rf test-project"},dependencies:{"fast-glob":"^3.3.3","yargs-interactive":"^3.0.1"},devDependencies:{"@types/yargs-interactive":"^2.1.6",execa:"^7.0.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"}};var o=["react","react-ecs","phaser","threejs","vanilla"];import f from"node:fs/promises";async function m(e){try{return await f.access(e),!0}catch{return!1}}var b=j(import.meta.url),v=t.dirname(b);async function w(){h().usage("$0 [args]").interactive({interactive:{default:!0},name:{describe:"Name your project",type:"input"},template:{describe:"Pick a template",type:"list",choices:o},"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:c.version}}).then(async e=>{if(!e.name)throw new Error("No project name provided.");let s=t.join(process.cwd(),e.name);if(await m(s))throw new Error(`Target directory "${s}" already exists.`);let a=t.join(v,"..","templates",e.template),l=await y("**/*",{cwd:a,dot:!0});for(let p of l){let i=t.join(a,p),n=t.join(s,p);if(await r.mkdir(t.dirname(n),{recursive:!0}),/package\.json$/.test(i)){let u=await r.readFile(i,"utf-8");await r.writeFile(n,u.replaceAll(/{{mud-version}}/g,e.mudVersion),"utf-8")}else await r.copyFile(i,n)}console.log(`
1
+ import r from"node:fs/promises";import t from"node:path";import{fileURLToPath as j}from"node:url";import h from"yargs-interactive";import y from"fast-glob";var c={name:"create-mud",version:"2.2.17-f1d5432fe2c9abb19fa378f790217e67d6dd8504",description:"Create a new MUD project",license:"MIT",author:"Lattice <mud@lattice.xyz>",type:"module",bin:"bin/cli.js",files:["bin","dist","templates"],scripts:{build:"pnpm run build:js","build:js":"tsup && pnpm run copy-templates",clean:"pnpm run clean:js","clean:js":"shx rm -rf dist","copy-templates":"tsx ./scripts/copy-templates.ts",dev:"tsup --watch",prepublishOnly:"npm run clean && npm run build",test:"pnpm run copy-templates && pnpm vitest --run && 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":"bin/cli.js --name test-project --template phaser && pnpm --dir test-project install && shx rm -rf test-project","test:react":"bin/cli.js --name test-project --template react && pnpm --dir test-project install && shx rm -rf test-project","test:react-ecs":"bin/cli.js --name test-project --template react-ecs && pnpm --dir test-project install && shx rm -rf test-project","test:threejs":"bin/cli.js --name test-project --template threejs && pnpm --dir test-project install && shx rm -rf test-project","test:vanilla":"bin/cli.js --name test-project --template vanilla && pnpm --dir test-project install && shx rm -rf test-project"},dependencies:{"fast-glob":"^3.3.3","yargs-interactive":"^3.0.1"},devDependencies:{"@types/yargs-interactive":"^2.1.6",execa:"^7.0.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"}};var o=["react","react-ecs","phaser","threejs","vanilla"];import f from"node:fs/promises";async function m(e){try{return await f.access(e),!0}catch{return!1}}var b=j(import.meta.url),v=t.dirname(b);async function w(){h().usage("$0 [args]").interactive({interactive:{default:!0},name:{describe:"Name your project",type:"input"},template:{describe:"Pick a template",type:"list",choices:o},"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:c.version}}).then(async e=>{if(!e.name)throw new Error("No project name provided.");let s=t.join(process.cwd(),e.name);if(await m(s))throw new Error(`Target directory "${s}" already exists.`);let a=t.join(v,"..","templates",e.template),l=await y("**/*",{cwd:a,dot:!0});for(let p of l){let i=t.join(a,p),n=t.join(s,p);if(await r.mkdir(t.dirname(n),{recursive:!0}),/package\.json$/.test(i)){let u=await r.readFile(i,"utf-8");await r.writeFile(n,u.replaceAll(/{{mud-version}}/g,e.mudVersion),"utf-8")}else await r.copyFile(i,n)}console.log(`
2
2
  New project created! Run it with:
3
3
 
4
4
  cd ${e.name}
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/bin/cli.ts","../package.json","../src/common.ts","../src/exists.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport yargsInteractive from \"yargs-interactive\";\nimport glob from \"fast-glob\";\nimport packageJson from \"../../package.json\";\nimport { templates } from \"../common\";\nimport { exists } from \"../exists\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nasync function run() {\n yargsInteractive()\n .usage(\"$0 [args]\")\n .interactive({\n interactive: { default: true },\n name: {\n describe: \"Name your project\",\n type: \"input\",\n },\n template: {\n describe: \"Pick a template\",\n type: \"list\",\n choices: templates,\n },\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 .then(async (args) => {\n if (!args.name) throw new Error(\"No project name provided.\");\n\n const destDir = path.join(process.cwd(), args.name);\n if (await exists(destDir)) {\n throw new Error(`Target directory \"${destDir}\" already exists.`);\n }\n\n const sourceDir = path.join(__dirname, \"..\", \"templates\", args.template);\n const files = await glob(\"**/*\", { cwd: sourceDir, dot: true });\n\n for (const filename of files) {\n const sourceFile = path.join(sourceDir, filename);\n const destFile = path.join(destDir, filename);\n\n await fs.mkdir(path.dirname(destFile), { recursive: true });\n\n if (/package\\.json$/.test(sourceFile)) {\n const source = await fs.readFile(sourceFile, \"utf-8\");\n await fs.writeFile(destFile, source.replaceAll(/{{mud-version}}/g, args.mudVersion), \"utf-8\");\n } else {\n await fs.copyFile(sourceFile, destFile);\n }\n }\n\n console.log(`\nNew project created! Run it with:\n\n cd ${args.name}\n pnpm install\n pnpm dev\n\nHave fun! For more info, check the docs at https://mud.dev/\n`);\n });\n}\n\nrun();\n","{\n \"name\": \"create-mud\",\n \"version\": \"2.2.17-d5f4e1e44bbc260ff21dacdfab0e0f8389e9f304\",\n \"description\": \"Create a new MUD project\",\n \"license\": \"MIT\",\n \"author\": \"Lattice <mud@lattice.xyz>\",\n \"type\": \"module\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"build\": \"pnpm run build:js\",\n \"build:js\": \"tsup && pnpm run copy-templates\",\n \"clean\": \"pnpm run clean:js\",\n \"clean:js\": \"shx rm -rf dist\",\n \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\n \"dev\": \"tsup --watch\",\n \"prepublishOnly\": \"npm run clean && npm run build\",\n \"test\": \"pnpm run copy-templates && pnpm vitest --run && 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\": \"bin/cli.js --name test-project --template phaser && pnpm --dir test-project install && shx rm -rf test-project\",\n \"test:react\": \"bin/cli.js --name test-project --template react && pnpm --dir test-project install && shx rm -rf test-project\",\n \"test:react-ecs\": \"bin/cli.js --name test-project --template react-ecs && pnpm --dir test-project install && shx rm -rf test-project\",\n \"test:threejs\": \"bin/cli.js --name test-project --template threejs && pnpm --dir test-project install && shx rm -rf test-project\",\n \"test:vanilla\": \"bin/cli.js --name test-project --template vanilla && pnpm --dir test-project install && shx rm -rf test-project\"\n },\n \"dependencies\": {\n \"fast-glob\": \"^3.3.3\",\n \"yargs-interactive\": \"^3.0.1\"\n },\n \"devDependencies\": {\n \"@types/yargs-interactive\": \"^2.1.6\",\n \"execa\": \"^7.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org\"\n }\n}\n","// We define these here to keep them in the order we want to present in the CLI.\n// Tests will ensure this list stays up to date.\nexport const templates = [\"react\", \"react-ecs\", \"phaser\", \"threejs\", \"vanilla\"];\n","import fs from \"node:fs/promises\";\n\nexport async function exists(path: string) {\n try {\n await fs.access(path);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":"AAAA,OAAOA,MAAQ,mBACf,OAAOC,MAAU,YACjB,OAAS,iBAAAC,MAAqB,WAC9B,OAAOC,MAAsB,oBAC7B,OAAOC,MAAU,YCJjB,IAAAC,EAAA,CACE,KAAQ,aACR,QAAW,kDACX,YAAe,2BACf,QAAW,MACX,OAAU,4BACV,KAAQ,SACR,IAAO,aACP,MAAS,CACP,MACA,OACA,WACF,EACA,QAAW,CACT,MAAS,oBACT,WAAY,kCACZ,MAAS,oBACT,WAAY,kBACZ,iBAAkB,kCAClB,IAAO,eACP,eAAkB,iCAClB,KAAQ,2KACR,UAAW,gBACX,cAAe,iHACf,aAAc,gHACd,iBAAkB,oHAClB,eAAgB,kHAChB,eAAgB,iHAClB,EACA,aAAgB,CACd,YAAa,SACb,oBAAqB,QACvB,EACA,gBAAmB,CACjB,2BAA4B,SAC5B,MAAS,QACX,EACA,cAAiB,CACf,OAAU,SACV,SAAY,4BACd,CACF,ECvCO,IAAMC,EAAY,CAAC,QAAS,YAAa,SAAU,UAAW,SAAS,ECF9E,OAAOC,MAAQ,mBAEf,eAAsBC,EAAOC,EAAc,CACzC,GAAI,CACF,aAAMF,EAAG,OAAOE,CAAI,EACb,EACT,MAAQ,CACN,MAAO,EACT,CACF,CHAA,IAAMC,EAAaC,EAAc,YAAY,GAAG,EAC1CC,EAAYC,EAAK,QAAQH,CAAU,EAEzC,eAAeI,GAAM,CACnBC,EAAiB,EACd,MAAM,WAAW,EACjB,YAAY,CACX,YAAa,CAAE,QAAS,EAAK,EAC7B,KAAM,CACJ,SAAU,oBACV,KAAM,OACR,EACA,SAAU,CACR,SAAU,kBACV,KAAM,OACN,QAASC,CACX,EACA,cAAe,CACb,KAAM,QACN,SAAU,yDACV,QAASC,EAAY,OACvB,CACF,CAAC,EACA,KAAK,MAAOC,GAAS,CACpB,GAAI,CAACA,EAAK,KAAM,MAAM,IAAI,MAAM,2BAA2B,EAE3D,IAAMC,EAAUN,EAAK,KAAK,QAAQ,IAAI,EAAGK,EAAK,IAAI,EAClD,GAAI,MAAME,EAAOD,CAAO,EACtB,MAAM,IAAI,MAAM,qBAAqBA,CAAO,mBAAmB,EAGjE,IAAME,EAAYR,EAAK,KAAKD,EAAW,KAAM,YAAaM,EAAK,QAAQ,EACjEI,EAAQ,MAAMC,EAAK,OAAQ,CAAE,IAAKF,EAAW,IAAK,EAAK,CAAC,EAE9D,QAAWG,KAAYF,EAAO,CAC5B,IAAMG,EAAaZ,EAAK,KAAKQ,EAAWG,CAAQ,EAC1CE,EAAWb,EAAK,KAAKM,EAASK,CAAQ,EAI5C,GAFA,MAAMG,EAAG,MAAMd,EAAK,QAAQa,CAAQ,EAAG,CAAE,UAAW,EAAK,CAAC,EAEtD,iBAAiB,KAAKD,CAAU,EAAG,CACrC,IAAMG,EAAS,MAAMD,EAAG,SAASF,EAAY,OAAO,EACpD,MAAME,EAAG,UAAUD,EAAUE,EAAO,WAAW,mBAAoBV,EAAK,UAAU,EAAG,OAAO,CAC9F,MACE,MAAMS,EAAG,SAASF,EAAYC,CAAQ,CAE1C,CAEA,QAAQ,IAAI;AAAA;AAAA;AAAA,OAGXR,EAAK,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,CAKf,CACG,CAAC,CACL,CAEAJ,EAAI","names":["fs","path","fileURLToPath","yargsInteractive","glob","package_default","templates","fs","exists","path","__filename","fileURLToPath","__dirname","path","run","yargsInteractive","templates","package_default","args","destDir","exists","sourceDir","files","glob","filename","sourceFile","destFile","fs","source"]}
1
+ {"version":3,"sources":["../src/bin/cli.ts","../package.json","../src/common.ts","../src/exists.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport yargsInteractive from \"yargs-interactive\";\nimport glob from \"fast-glob\";\nimport packageJson from \"../../package.json\";\nimport { templates } from \"../common\";\nimport { exists } from \"../exists\";\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nasync function run() {\n yargsInteractive()\n .usage(\"$0 [args]\")\n .interactive({\n interactive: { default: true },\n name: {\n describe: \"Name your project\",\n type: \"input\",\n },\n template: {\n describe: \"Pick a template\",\n type: \"list\",\n choices: templates,\n },\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 .then(async (args) => {\n if (!args.name) throw new Error(\"No project name provided.\");\n\n const destDir = path.join(process.cwd(), args.name);\n if (await exists(destDir)) {\n throw new Error(`Target directory \"${destDir}\" already exists.`);\n }\n\n const sourceDir = path.join(__dirname, \"..\", \"templates\", args.template);\n const files = await glob(\"**/*\", { cwd: sourceDir, dot: true });\n\n for (const filename of files) {\n const sourceFile = path.join(sourceDir, filename);\n const destFile = path.join(destDir, filename);\n\n await fs.mkdir(path.dirname(destFile), { recursive: true });\n\n if (/package\\.json$/.test(sourceFile)) {\n const source = await fs.readFile(sourceFile, \"utf-8\");\n await fs.writeFile(destFile, source.replaceAll(/{{mud-version}}/g, args.mudVersion), \"utf-8\");\n } else {\n await fs.copyFile(sourceFile, destFile);\n }\n }\n\n console.log(`\nNew project created! Run it with:\n\n cd ${args.name}\n pnpm install\n pnpm dev\n\nHave fun! For more info, check the docs at https://mud.dev/\n`);\n });\n}\n\nrun();\n","{\n \"name\": \"create-mud\",\n \"version\": \"2.2.17-f1d5432fe2c9abb19fa378f790217e67d6dd8504\",\n \"description\": \"Create a new MUD project\",\n \"license\": \"MIT\",\n \"author\": \"Lattice <mud@lattice.xyz>\",\n \"type\": \"module\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"build\": \"pnpm run build:js\",\n \"build:js\": \"tsup && pnpm run copy-templates\",\n \"clean\": \"pnpm run clean:js\",\n \"clean:js\": \"shx rm -rf dist\",\n \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\n \"dev\": \"tsup --watch\",\n \"prepublishOnly\": \"npm run clean && npm run build\",\n \"test\": \"pnpm run copy-templates && pnpm vitest --run && 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\": \"bin/cli.js --name test-project --template phaser && pnpm --dir test-project install && shx rm -rf test-project\",\n \"test:react\": \"bin/cli.js --name test-project --template react && pnpm --dir test-project install && shx rm -rf test-project\",\n \"test:react-ecs\": \"bin/cli.js --name test-project --template react-ecs && pnpm --dir test-project install && shx rm -rf test-project\",\n \"test:threejs\": \"bin/cli.js --name test-project --template threejs && pnpm --dir test-project install && shx rm -rf test-project\",\n \"test:vanilla\": \"bin/cli.js --name test-project --template vanilla && pnpm --dir test-project install && shx rm -rf test-project\"\n },\n \"dependencies\": {\n \"fast-glob\": \"^3.3.3\",\n \"yargs-interactive\": \"^3.0.1\"\n },\n \"devDependencies\": {\n \"@types/yargs-interactive\": \"^2.1.6\",\n \"execa\": \"^7.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"registry\": \"https://registry.npmjs.org\"\n }\n}\n","// We define these here to keep them in the order we want to present in the CLI.\n// Tests will ensure this list stays up to date.\nexport const templates = [\"react\", \"react-ecs\", \"phaser\", \"threejs\", \"vanilla\"];\n","import fs from \"node:fs/promises\";\n\nexport async function exists(path: string) {\n try {\n await fs.access(path);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":"AAAA,OAAOA,MAAQ,mBACf,OAAOC,MAAU,YACjB,OAAS,iBAAAC,MAAqB,WAC9B,OAAOC,MAAsB,oBAC7B,OAAOC,MAAU,YCJjB,IAAAC,EAAA,CACE,KAAQ,aACR,QAAW,kDACX,YAAe,2BACf,QAAW,MACX,OAAU,4BACV,KAAQ,SACR,IAAO,aACP,MAAS,CACP,MACA,OACA,WACF,EACA,QAAW,CACT,MAAS,oBACT,WAAY,kCACZ,MAAS,oBACT,WAAY,kBACZ,iBAAkB,kCAClB,IAAO,eACP,eAAkB,iCAClB,KAAQ,2KACR,UAAW,gBACX,cAAe,iHACf,aAAc,gHACd,iBAAkB,oHAClB,eAAgB,kHAChB,eAAgB,iHAClB,EACA,aAAgB,CACd,YAAa,SACb,oBAAqB,QACvB,EACA,gBAAmB,CACjB,2BAA4B,SAC5B,MAAS,QACX,EACA,cAAiB,CACf,OAAU,SACV,SAAY,4BACd,CACF,ECvCO,IAAMC,EAAY,CAAC,QAAS,YAAa,SAAU,UAAW,SAAS,ECF9E,OAAOC,MAAQ,mBAEf,eAAsBC,EAAOC,EAAc,CACzC,GAAI,CACF,aAAMF,EAAG,OAAOE,CAAI,EACb,EACT,MAAQ,CACN,MAAO,EACT,CACF,CHAA,IAAMC,EAAaC,EAAc,YAAY,GAAG,EAC1CC,EAAYC,EAAK,QAAQH,CAAU,EAEzC,eAAeI,GAAM,CACnBC,EAAiB,EACd,MAAM,WAAW,EACjB,YAAY,CACX,YAAa,CAAE,QAAS,EAAK,EAC7B,KAAM,CACJ,SAAU,oBACV,KAAM,OACR,EACA,SAAU,CACR,SAAU,kBACV,KAAM,OACN,QAASC,CACX,EACA,cAAe,CACb,KAAM,QACN,SAAU,yDACV,QAASC,EAAY,OACvB,CACF,CAAC,EACA,KAAK,MAAOC,GAAS,CACpB,GAAI,CAACA,EAAK,KAAM,MAAM,IAAI,MAAM,2BAA2B,EAE3D,IAAMC,EAAUN,EAAK,KAAK,QAAQ,IAAI,EAAGK,EAAK,IAAI,EAClD,GAAI,MAAME,EAAOD,CAAO,EACtB,MAAM,IAAI,MAAM,qBAAqBA,CAAO,mBAAmB,EAGjE,IAAME,EAAYR,EAAK,KAAKD,EAAW,KAAM,YAAaM,EAAK,QAAQ,EACjEI,EAAQ,MAAMC,EAAK,OAAQ,CAAE,IAAKF,EAAW,IAAK,EAAK,CAAC,EAE9D,QAAWG,KAAYF,EAAO,CAC5B,IAAMG,EAAaZ,EAAK,KAAKQ,EAAWG,CAAQ,EAC1CE,EAAWb,EAAK,KAAKM,EAASK,CAAQ,EAI5C,GAFA,MAAMG,EAAG,MAAMd,EAAK,QAAQa,CAAQ,EAAG,CAAE,UAAW,EAAK,CAAC,EAEtD,iBAAiB,KAAKD,CAAU,EAAG,CACrC,IAAMG,EAAS,MAAMD,EAAG,SAASF,EAAY,OAAO,EACpD,MAAME,EAAG,UAAUD,EAAUE,EAAO,WAAW,mBAAoBV,EAAK,UAAU,EAAG,OAAO,CAC9F,MACE,MAAMS,EAAG,SAASF,EAAYC,CAAQ,CAE1C,CAEA,QAAQ,IAAI;AAAA;AAAA;AAAA,OAGXR,EAAK,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,CAKf,CACG,CAAC,CACL,CAEAJ,EAAI","names":["fs","path","fileURLToPath","yargsInteractive","glob","package_default","templates","fs","exists","path","__filename","fileURLToPath","__dirname","path","run","yargsInteractive","templates","package_default","args","destDir","exists","sourceDir","files","glob","filename","sourceFile","destFile","fs","source"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-mud",
3
- "version": "2.2.17-d5f4e1e44bbc260ff21dacdfab0e0f8389e9f304",
3
+ "version": "2.2.17-f1d5432fe2c9abb19fa378f790217e67d6dd8504",
4
4
  "description": "Create a new MUD project",
5
5
  "license": "MIT",
6
6
  "author": "Lattice <mud@lattice.xyz>",
@@ -1,7 +1,7 @@
1
1
  import { ReactNode } from "react";
2
2
  import { useSyncStatus } from "./useSyncStatus";
3
3
  import { TableRecord } from "@latticexyz/stash/internal";
4
- import { SyncProgress } from "@latticexyz/store-sync/stash/common";
4
+ import { SyncProgress } from "@latticexyz/store-sync/internal";
5
5
 
6
6
  export type Props = {
7
7
  children: ReactNode;
@@ -7,5 +7,5 @@
7
7
  # Enable debug logs for MUD CLI
8
8
  DEBUG=mud:*
9
9
  #
10
- # Anvil default private key:
10
+ # Anvil default private key
11
11
  PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
@@ -3,7 +3,6 @@ pragma solidity >=0.8.24;
3
3
 
4
4
  import "forge-std/Test.sol";
5
5
  import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
6
- import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol";
7
6
 
8
7
  import { IWorld } from "../src/codegen/world/IWorld.sol";
9
8
  import { Position, PositionData } from "../src/codegen/tables/Position.sol";
@@ -20,7 +19,6 @@ contract MoveTest is MudTest {
20
19
 
21
20
  IWorld(worldAddress).app__move(Direction.North);
22
21
  position = Position.get(alice);
23
-
24
22
  assertEq(position.x, 0);
25
23
  assertEq(position.y, 1);
26
24
  }
@@ -3,11 +3,6 @@ pragma solidity >=0.8.24;
3
3
 
4
4
  import "forge-std/Test.sol";
5
5
  import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
6
- import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol";
7
-
8
- import { IWorld } from "../src/codegen/world/IWorld.sol";
9
- import { Position, PositionData } from "../src/codegen/tables/Position.sol";
10
- import { Direction } from "../src/codegen/common.sol";
11
6
 
12
7
  contract WorldTest is MudTest {
13
8
  function testWorldDeployed() public {
@@ -1,3 +1,4 @@
1
+ scrollback: 10000
1
2
  procs:
2
3
  client:
3
4
  cwd: packages/client
@@ -5,9 +6,16 @@ procs:
5
6
  contracts:
6
7
  cwd: packages/contracts
7
8
  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"
8
16
  anvil:
9
17
  cwd: packages/contracts
10
- shell: anvil --base-fee 0 --block-time 2
18
+ shell: anvil --block-time 2
11
19
  explorer:
12
20
  cwd: packages/contracts
13
21
  shell: pnpm explorer
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "mud-template-react-ecs",
2
+ "name": "mud-template-react",
3
3
  "private": true,
4
4
  "scripts": {
5
5
  "build": "pnpm recursive run build",
@@ -17,7 +17,6 @@
17
17
  "@latticexyz/explorer": "{{mud-version}}",
18
18
  "@latticexyz/store-indexer": "{{mud-version}}",
19
19
  "@types/debug": "4.1.7",
20
- "@types/node": "^18",
21
20
  "@typescript-eslint/eslint-plugin": "7.1.1",
22
21
  "@typescript-eslint/parser": "7.1.1",
23
22
  "eslint": "8.57.0",
@@ -1,9 +1,9 @@
1
- <!DOCTYPE html>
1
+ <!doctype html>
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>a minimal MUD client</title>
6
+ <title>a MUD app</title>
7
7
  </head>
8
8
  <body>
9
9
  <div id="react-root"></div>
@@ -6,32 +6,39 @@
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "vite build",
9
- "dev": "wait-port localhost:8545 && vite",
9
+ "dev": "vite",
10
10
  "preview": "vite preview",
11
11
  "test": "tsc --noEmit"
12
12
  },
13
13
  "dependencies": {
14
14
  "@latticexyz/common": "{{mud-version}}",
15
- "@latticexyz/dev-tools": "{{mud-version}}",
15
+ "@latticexyz/entrykit": "{{mud-version}}",
16
+ "@latticexyz/explorer": "{{mud-version}}",
16
17
  "@latticexyz/react": "{{mud-version}}",
17
18
  "@latticexyz/recs": "{{mud-version}}",
18
19
  "@latticexyz/schema-type": "{{mud-version}}",
19
20
  "@latticexyz/store-sync": "{{mud-version}}",
20
21
  "@latticexyz/utils": "{{mud-version}}",
21
22
  "@latticexyz/world": "{{mud-version}}",
23
+ "@tanstack/react-query": "^5.63.0",
22
24
  "contracts": "workspace:*",
23
- "react": "^18.2.0",
24
- "react-dom": "^18.2.0",
25
- "rxjs": "7.5.5",
26
- "viem": "2.21.19"
25
+ "react": "18.2.0",
26
+ "react-dom": "18.2.0",
27
+ "react-error-boundary": "5.0.0",
28
+ "tailwind-merge": "^2.6.0",
29
+ "viem": "2.21.19",
30
+ "wagmi": "2.12.11"
27
31
  },
28
32
  "devDependencies": {
29
33
  "@types/react": "18.2.22",
30
34
  "@types/react-dom": "18.2.7",
31
- "@vitejs/plugin-react": "^3.1.0",
35
+ "@vitejs/plugin-react": "^4.3.4",
36
+ "autoprefixer": "^10.4.20",
32
37
  "eslint-plugin-react": "7.31.11",
33
38
  "eslint-plugin-react-hooks": "4.6.0",
34
- "vite": "^4.2.1",
35
- "wait-port": "^1.0.4"
39
+ "postcss": "^8.4.49",
40
+ "tailwindcss": "^3.4.17",
41
+ "vite": "^6.0.7",
42
+ "vite-plugin-mud": "{{mud-version}}"
36
43
  }
37
44
  }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ };
@@ -1,29 +1,74 @@
1
- import { useComponentValue } from "@latticexyz/react";
2
- import { useMUD } from "./MUDContext";
3
- import { singletonEntity } from "@latticexyz/store-sync/recs";
1
+ import { AccountButton } from "@latticexyz/entrykit/internal";
2
+ import { Direction, Entity } from "./common";
3
+ import mudConfig from "contracts/mud.config";
4
+ import { useMemo } from "react";
5
+ import { GameMap } from "./game/GameMap";
6
+ import { useWorldContract } from "./mud/useWorldContract";
7
+ import { Synced } from "./mud/Synced";
8
+ import { useSync } from "@latticexyz/store-sync/react";
9
+ import { components } from "./mud/recs";
10
+ import { useEntityQuery } from "@latticexyz/react";
11
+ import { Has, getComponentValueStrict } from "@latticexyz/recs";
12
+ import { Address } from "viem";
4
13
 
5
- export const App = () => {
6
- const {
7
- components: { Counter },
8
- systemCalls: { increment },
9
- } = useMUD();
14
+ export function App() {
15
+ const playerEntities = useEntityQuery([Has(components.Owner), Has(components.Position)]);
16
+ const players = useMemo(
17
+ () =>
18
+ playerEntities.map((entity) => {
19
+ const owner = getComponentValueStrict(components.Owner, entity);
20
+ const position = getComponentValueStrict(components.Position, entity);
21
+ return {
22
+ entity: entity as Entity,
23
+ owner: owner.owner as Address,
24
+ x: position.x,
25
+ y: position.y,
26
+ };
27
+ }),
28
+ [playerEntities],
29
+ );
30
+
31
+ const sync = useSync();
32
+ const worldContract = useWorldContract();
33
+
34
+ const onMove = useMemo(
35
+ () =>
36
+ sync.data && worldContract
37
+ ? async (entity: Entity, direction: Direction) => {
38
+ const tx = await worldContract.write.app__move([entity, mudConfig.enums.Direction.indexOf(direction)]);
39
+ await sync.data.waitForTransaction(tx);
40
+ }
41
+ : undefined,
42
+ [sync.data, worldContract],
43
+ );
10
44
 
11
- const counter = useComponentValue(Counter, singletonEntity);
45
+ const onSpawn = useMemo(
46
+ () =>
47
+ sync.data && worldContract
48
+ ? async () => {
49
+ const tx = await worldContract.write.app__spawn();
50
+ await sync.data.waitForTransaction(tx);
51
+ }
52
+ : undefined,
53
+ [sync.data, worldContract],
54
+ );
12
55
 
13
56
  return (
14
57
  <>
15
- <div>
16
- Counter: <span>{counter?.value ?? "??"}</span>
58
+ <div className="fixed inset-0 grid place-items-center p-4">
59
+ <Synced
60
+ fallback={({ message, percentage }) => (
61
+ <div className="tabular-nums">
62
+ {message} ({percentage.toFixed(1)}%)…
63
+ </div>
64
+ )}
65
+ >
66
+ <GameMap players={players} onMove={onMove} onSpawn={onSpawn} />
67
+ </Synced>
68
+ </div>
69
+ <div className="fixed top-2 right-2">
70
+ <AccountButton />
17
71
  </div>
18
- <button
19
- type="button"
20
- onClick={async (event) => {
21
- event.preventDefault();
22
- console.log("new counter value:", await increment());
23
- }}
24
- >
25
- Increment
26
- </button>
27
72
  </>
28
73
  );
29
- };
74
+ }
@@ -0,0 +1,29 @@
1
+ import { WagmiProvider } from "wagmi";
2
+ import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
3
+ import { ReactNode } from "react";
4
+ import { SyncProvider } from "@latticexyz/store-sync/react";
5
+ import { defineConfig, EntryKitProvider } from "@latticexyz/entrykit/internal";
6
+ import { wagmiConfig } from "./wagmiConfig";
7
+ import { chainId, getWorldAddress, startBlock } from "./common";
8
+ import { syncAdapter } from "./mud/recs";
9
+
10
+ const queryClient = new QueryClient();
11
+
12
+ export type Props = {
13
+ children: ReactNode;
14
+ };
15
+
16
+ export function Providers({ children }: Props) {
17
+ const worldAddress = getWorldAddress();
18
+ return (
19
+ <WagmiProvider config={wagmiConfig}>
20
+ <QueryClientProvider client={queryClient}>
21
+ <EntryKitProvider config={defineConfig({ chainId, worldAddress })}>
22
+ <SyncProvider chainId={chainId} address={worldAddress} startBlock={startBlock} adapter={syncAdapter}>
23
+ {children}
24
+ </SyncProvider>
25
+ </EntryKitProvider>
26
+ </QueryClientProvider>
27
+ </WagmiProvider>
28
+ );
29
+ }
@@ -0,0 +1,27 @@
1
+ import mudConfig from "contracts/mud.config";
2
+ import { chains } from "./wagmiConfig";
3
+ import { Chain, Hex } from "viem";
4
+
5
+ export const chainId = import.meta.env.CHAIN_ID;
6
+ export const worldAddress = import.meta.env.WORLD_ADDRESS;
7
+ export const startBlock = import.meta.env.START_BLOCK;
8
+
9
+ export const url = new URL(window.location.href);
10
+
11
+ export type Entity = Hex;
12
+ export type Direction = (typeof mudConfig.enums.Direction)[number];
13
+
14
+ export function getWorldAddress() {
15
+ if (!worldAddress) {
16
+ throw new Error("No world address configured. Is the world still deploying?");
17
+ }
18
+ return worldAddress;
19
+ }
20
+
21
+ export function getChain(): Chain {
22
+ const chain = chains.find((c) => c.id === chainId);
23
+ if (!chain) {
24
+ throw new Error(`No chain configured for chain ID ${chainId}.`);
25
+ }
26
+ return chain;
27
+ }
@@ -0,0 +1,112 @@
1
+ import { serialize, useAccount } from "wagmi";
2
+ import { useKeyboardMovement } from "./useKeyboardMovement";
3
+ import { Address, Hex, hexToBigInt, keccak256 } from "viem";
4
+ import { ArrowDownIcon } from "../ui/icons/ArrowDownIcon";
5
+ import { twMerge } from "tailwind-merge";
6
+ import { Direction, Entity } from "../common";
7
+ import mudConfig from "contracts/mud.config";
8
+ import { AsyncButton } from "../ui/AsyncButton";
9
+ import { useAccountModal } from "@latticexyz/entrykit/internal";
10
+ import { useMemo } from "react";
11
+
12
+ export type Props = {
13
+ readonly players?: {
14
+ readonly entity: Entity;
15
+ readonly owner: Address;
16
+ readonly x: number;
17
+ readonly y: number;
18
+ }[];
19
+ readonly onMove?: (entity: Entity, direction: Direction) => Promise<void>;
20
+ readonly onSpawn?: () => Promise<void>;
21
+ };
22
+
23
+ const size = 40;
24
+ const scale = 100 / size;
25
+
26
+ function getColorAngle(seed: Hex) {
27
+ return Number(hexToBigInt(keccak256(seed)) % 360n);
28
+ }
29
+
30
+ const rotateClassName = {
31
+ North: "rotate-0",
32
+ East: "rotate-90",
33
+ South: "rotate-180",
34
+ West: "-rotate-90",
35
+ } as const satisfies Record<Direction, `${"" | "-"}rotate-${number}`>;
36
+
37
+ export function GameMap({ players = [], onMove, onSpawn }: Props) {
38
+ const { openAccountModal } = useAccountModal();
39
+ const { address: userAddress } = useAccount();
40
+
41
+ const currentPlayer = players.find((player) => player.owner.toLowerCase() === userAddress?.toLowerCase());
42
+
43
+ useKeyboardMovement(
44
+ useMemo(
45
+ () => (onMove && currentPlayer ? (direction: Direction) => onMove(currentPlayer.entity, direction) : undefined),
46
+ [currentPlayer, onMove],
47
+ ),
48
+ );
49
+
50
+ return (
51
+ <div className="aspect-square w-full max-w-[40rem]">
52
+ <div className="relative w-full h-full border-8 border-black/10">
53
+ {currentPlayer && onMove
54
+ ? mudConfig.enums.Direction.map((direction) => (
55
+ <button
56
+ key={direction}
57
+ title={`Move ${direction.toLowerCase()}`}
58
+ className={twMerge(
59
+ "outline-0 absolute inset-0 cursor-pointer grid p-4",
60
+ rotateClassName[direction],
61
+ "transition bg-gradient-to-t from-transparent via-transparent to-blue-50 text-blue-400 opacity-0 hover:opacity-40 active:opacity-100",
62
+ )}
63
+ style={{ clipPath: "polygon(0% 0%, 100% 0%, 50% 50%)" }}
64
+ onClick={() => onMove(currentPlayer.entity, direction)}
65
+ >
66
+ <ArrowDownIcon className="rotate-180 text-4xl self-start justify-self-center" />
67
+ </button>
68
+ ))
69
+ : null}
70
+
71
+ {players.map((player) => (
72
+ <div
73
+ key={player.entity}
74
+ className="absolute bg-current"
75
+ style={{
76
+ color: `hwb(${getColorAngle(player.owner)} 40% 20%)`,
77
+ width: `${scale}%`,
78
+ height: `${scale}%`,
79
+ left: `${((((player.x + size / 2) % size) + size) % size) * scale}%`,
80
+ top: `${((size - ((player.y + size / 2) % size)) % size) * scale}%`,
81
+ }}
82
+ title={serialize(player, null, 2)}
83
+ >
84
+ {player === currentPlayer ? <div className="w-full h-full bg-current animate-ping opacity-50" /> : null}
85
+ </div>
86
+ ))}
87
+
88
+ {!currentPlayer ? (
89
+ onSpawn ? (
90
+ <div className="absolute inset-0 grid place-items-center">
91
+ <AsyncButton
92
+ className="group outline-0 p-4 border-4 border-green-400 transition ring-green-300 hover:ring-4 active:scale-95 rounded-lg text-lg font-medium aria-busy:pointer-events-none aria-busy:animate-pulse"
93
+ onClick={() => onSpawn()}
94
+ >
95
+ Spawn<span className="hidden group-aria-busy:inline">ing…</span>
96
+ </AsyncButton>
97
+ </div>
98
+ ) : (
99
+ <div className="absolute inset-0 grid place-items-center">
100
+ <button
101
+ className="group outline-0 p-4 border-4 border-green-400 transition ring-green-300 hover:ring-4 active:scale-95 rounded-lg text-lg font-medium aria-busy:pointer-events-none aria-busy:animate-pulse"
102
+ onClick={openAccountModal}
103
+ >
104
+ Sign in to play
105
+ </button>
106
+ </div>
107
+ )
108
+ ) : null}
109
+ </div>
110
+ </div>
111
+ );
112
+ }
@@ -0,0 +1,26 @@
1
+ import { useEffect } from "react";
2
+ import { Direction } from "../common";
3
+
4
+ const keys = new Map<KeyboardEvent["key"], Direction>([
5
+ ["ArrowUp", "North"],
6
+ ["ArrowRight", "East"],
7
+ ["ArrowDown", "South"],
8
+ ["ArrowLeft", "West"],
9
+ ]);
10
+
11
+ export const useKeyboardMovement = (move: undefined | ((direction: Direction) => void)) => {
12
+ useEffect(() => {
13
+ if (!move) return;
14
+
15
+ const listener = (event: KeyboardEvent) => {
16
+ const direction = keys.get(event.key);
17
+ if (direction == null) return;
18
+
19
+ event.preventDefault();
20
+ move(direction);
21
+ };
22
+
23
+ window.addEventListener("keydown", listener);
24
+ return () => window.removeEventListener("keydown", listener);
25
+ }, [move]);
26
+ };
@@ -1,34 +1,19 @@
1
- import ReactDOM from "react-dom/client";
1
+ import "tailwindcss/tailwind.css";
2
+ import { StrictMode } from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import { Providers } from "./Providers";
2
5
  import { App } from "./App";
3
- import { setup } from "./mud/setup";
4
- import { MUDProvider } from "./MUDContext";
5
- import mudConfig from "contracts/mud.config";
6
+ import { Explorer } from "./mud/Explorer";
7
+ import { ErrorBoundary } from "react-error-boundary";
8
+ import { ErrorFallback } from "./ui/ErrorFallback";
6
9
 
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(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
- recsWorld: result.network.world,
32
- });
33
- }
34
- });
10
+ createRoot(document.getElementById("react-root")!).render(
11
+ <StrictMode>
12
+ <ErrorBoundary FallbackComponent={ErrorFallback}>
13
+ <Providers>
14
+ <App />
15
+ <Explorer />
16
+ </Providers>
17
+ </ErrorBoundary>
18
+ </StrictMode>,
19
+ );
@@ -0,0 +1,32 @@
1
+ import { useState } from "react";
2
+ import { getChain, getWorldAddress } from "../common";
3
+ import { MUDIcon } from "../ui/icons/MUDIcon";
4
+
5
+ export function Explorer() {
6
+ const [open, setOpen] = useState(false);
7
+
8
+ const chain = getChain();
9
+ const worldAddress = getWorldAddress();
10
+
11
+ const explorerUrl = chain.blockExplorers?.worldsExplorer?.url;
12
+ if (!explorerUrl) return null;
13
+
14
+ return (
15
+ <div className="fixed bottom-0 inset-x-0 flex flex-col opacity-80 transition hover:opacity-100">
16
+ <button
17
+ type="button"
18
+ onClick={() => setOpen(!open)}
19
+ className="outline-none flex justify-end gap-2 p-2 font-medium leading-none text-black"
20
+ >
21
+ {open ? (
22
+ <>Close</>
23
+ ) : (
24
+ <>
25
+ Explore <MUDIcon className="text-orange-500" />
26
+ </>
27
+ )}
28
+ </button>
29
+ {open ? <iframe src={`${explorerUrl}/${worldAddress}`} className="bg-black h-[50vh]" /> : null}
30
+ </div>
31
+ );
32
+ }
@@ -0,0 +1,14 @@
1
+ import { ReactNode } from "react";
2
+ import { useSyncStatus } from "./useSyncStatus";
3
+ import { ComponentValue } from "@latticexyz/recs";
4
+ import { components } from "./recs";
5
+
6
+ export type Props = {
7
+ children: ReactNode;
8
+ fallback?: (props: ComponentValue<(typeof components)["SyncProgress"]["schema"]>) => ReactNode;
9
+ };
10
+
11
+ export function Synced({ children, fallback }: Props) {
12
+ const status = useSyncStatus();
13
+ return status.isLive ? children : fallback?.(status);
14
+ }
@@ -0,0 +1,6 @@
1
+ import { createWorld } from "@latticexyz/recs";
2
+ import { createSyncAdapter } from "@latticexyz/store-sync/recs";
3
+ import config from "contracts/mud.config";
4
+
5
+ export const world = createWorld();
6
+ export const { syncAdapter, components } = createSyncAdapter({ world, config });
@@ -0,0 +1,17 @@
1
+ import { initialProgress } from "@latticexyz/store-sync/internal";
2
+ import { SyncStep } from "@latticexyz/store-sync";
3
+ import { useMemo } from "react";
4
+ import { useComponentValue } from "@latticexyz/react";
5
+ import { singletonEntity } from "@latticexyz/store-sync/recs";
6
+ import { components } from "./recs";
7
+
8
+ export function useSyncStatus() {
9
+ const progress = useComponentValue(components.SyncProgress, singletonEntity, initialProgress);
10
+ return useMemo(
11
+ () => ({
12
+ ...progress,
13
+ isLive: progress.step === SyncStep.LIVE,
14
+ }),
15
+ [progress],
16
+ );
17
+ }