create-mud 2.0.0-next.12 → 2.0.0-next.13

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 (96) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/templates/phaser/.vscode/extensions.json +1 -1
  3. package/dist/templates/phaser/.vscode/settings.json +1 -4
  4. package/dist/templates/phaser/mprocs.yaml +7 -0
  5. package/dist/templates/phaser/package.json +2 -2
  6. package/dist/templates/phaser/packages/contracts/.env +3 -0
  7. package/dist/templates/phaser/packages/contracts/remappings.txt +3 -3
  8. package/dist/templates/phaser/packages/contracts/script/PostDeploy.s.sol +5 -0
  9. package/dist/templates/react/.vscode/extensions.json +1 -1
  10. package/dist/templates/react/.vscode/settings.json +1 -4
  11. package/dist/templates/react/mprocs.yaml +7 -0
  12. package/dist/templates/react/package.json +2 -2
  13. package/dist/templates/react/packages/client/package.json +0 -1
  14. package/dist/templates/react/packages/client/src/App.tsx +93 -17
  15. package/dist/templates/react/packages/client/src/index.tsx +0 -1
  16. package/dist/templates/react/packages/client/src/mud/createSystemCalls.ts +18 -15
  17. package/dist/templates/react/packages/client/src/mud/setup.ts +1 -4
  18. package/dist/templates/react/packages/client/src/mud/setupNetwork.ts +4 -9
  19. package/dist/templates/react/packages/contracts/.env +3 -0
  20. package/dist/templates/react/packages/contracts/mud.config.ts +6 -3
  21. package/dist/templates/react/packages/contracts/remappings.txt +3 -3
  22. package/dist/templates/react/packages/contracts/script/PostDeploy.s.sol +13 -4
  23. package/dist/templates/react/packages/contracts/src/codegen/index.sol +1 -1
  24. package/dist/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +556 -0
  25. package/dist/templates/react/packages/contracts/src/codegen/world/ITasksSystem.sol +18 -0
  26. package/dist/templates/react/packages/contracts/src/codegen/world/IWorld.sol +2 -2
  27. package/dist/templates/react/packages/contracts/src/systems/TasksSystem.sol +24 -0
  28. package/dist/templates/react/packages/contracts/test/TasksTest.t.sol +30 -0
  29. package/dist/templates/react/packages/contracts/worlds.json +1 -1
  30. package/dist/templates/react-ecs/.eslintrc +10 -0
  31. package/dist/templates/react-ecs/.gitattributes +3 -0
  32. package/dist/templates/react-ecs/.vscode/extensions.json +3 -0
  33. package/dist/templates/react-ecs/.vscode/settings.json +1 -0
  34. package/dist/templates/react-ecs/mprocs.yaml +7 -0
  35. package/dist/templates/react-ecs/package.json +27 -0
  36. package/dist/templates/react-ecs/packages/client/.env +1 -0
  37. package/dist/templates/react-ecs/packages/client/.eslintrc +7 -0
  38. package/dist/templates/react-ecs/packages/client/index.html +12 -0
  39. package/dist/templates/react-ecs/packages/client/package.json +38 -0
  40. package/dist/templates/react-ecs/packages/client/src/App.tsx +29 -0
  41. package/dist/templates/react-ecs/packages/client/src/MUDContext.tsx +21 -0
  42. package/dist/templates/react-ecs/packages/client/src/index.tsx +34 -0
  43. package/dist/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts +51 -0
  44. package/dist/templates/react-ecs/packages/client/src/mud/getNetworkConfig.ts +91 -0
  45. package/dist/templates/react-ecs/packages/client/src/mud/setup.ts +21 -0
  46. package/dist/templates/react-ecs/packages/client/src/mud/setupNetwork.ts +125 -0
  47. package/dist/templates/react-ecs/packages/client/src/mud/supportedChains.ts +20 -0
  48. package/dist/templates/react-ecs/packages/client/tsconfig.json +19 -0
  49. package/dist/templates/react-ecs/packages/client/vite.config.ts +17 -0
  50. package/dist/templates/react-ecs/packages/contracts/.env +11 -0
  51. package/dist/templates/react-ecs/packages/contracts/.prettierrc +8 -0
  52. package/dist/templates/react-ecs/packages/contracts/.solhint.json +12 -0
  53. package/dist/templates/react-ecs/packages/contracts/foundry.toml +26 -0
  54. package/dist/templates/react-ecs/packages/contracts/mud.config.ts +10 -0
  55. package/dist/templates/react-ecs/packages/contracts/package.json +36 -0
  56. package/dist/templates/react-ecs/packages/contracts/remappings.txt +3 -0
  57. package/dist/templates/react-ecs/packages/contracts/script/PostDeploy.s.sol +29 -0
  58. package/dist/templates/react-ecs/packages/contracts/src/codegen/index.sol +6 -0
  59. package/dist/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol +18 -0
  60. package/dist/templates/react-ecs/packages/contracts/tsconfig.json +13 -0
  61. package/dist/templates/react-ecs/packages/contracts/worlds.json +5 -0
  62. package/dist/templates/react-ecs/packages/contracts/worlds.json.d.ts +2 -0
  63. package/dist/templates/react-ecs/pnpm-workspace.yaml +2 -0
  64. package/dist/templates/threejs/.vscode/extensions.json +1 -1
  65. package/dist/templates/threejs/.vscode/settings.json +1 -4
  66. package/dist/templates/threejs/mprocs.yaml +7 -0
  67. package/dist/templates/threejs/package.json +2 -2
  68. package/dist/templates/threejs/packages/contracts/.env +3 -0
  69. package/dist/templates/threejs/packages/contracts/remappings.txt +3 -3
  70. package/dist/templates/vanilla/.vscode/extensions.json +1 -1
  71. package/dist/templates/vanilla/.vscode/settings.json +1 -4
  72. package/dist/templates/vanilla/mprocs.yaml +7 -0
  73. package/dist/templates/vanilla/package.json +2 -2
  74. package/dist/templates/vanilla/packages/contracts/.env +3 -0
  75. package/dist/templates/vanilla/packages/contracts/remappings.txt +3 -3
  76. package/dist/templates/vanilla/packages/contracts/script/PostDeploy.s.sol +5 -0
  77. package/package.json +3 -2
  78. package/dist/templates/phaser/.gitignore +0 -1
  79. package/dist/templates/phaser/packages/art/.gitignore +0 -0
  80. package/dist/templates/phaser/packages/client/.gitignore +0 -3
  81. package/dist/templates/phaser/packages/contracts/.gitignore +0 -9
  82. package/dist/templates/react/.gitignore +0 -1
  83. package/dist/templates/react/packages/client/.gitignore +0 -3
  84. package/dist/templates/react/packages/contracts/.gitignore +0 -9
  85. package/dist/templates/threejs/.gitignore +0 -1
  86. package/dist/templates/threejs/packages/client/.gitignore +0 -3
  87. package/dist/templates/threejs/packages/contracts/.gitignore +0 -9
  88. package/dist/templates/vanilla/.gitignore +0 -1
  89. package/dist/templates/vanilla/packages/client/.gitignore +0 -3
  90. package/dist/templates/vanilla/packages/contracts/.gitignore +0 -9
  91. /package/dist/templates/{react → react-ecs}/packages/client/src/mud/createClientComponents.ts +0 -0
  92. /package/dist/templates/{react → react-ecs}/packages/client/src/mud/world.ts +0 -0
  93. /package/dist/templates/{react → react-ecs}/packages/contracts/src/codegen/tables/Counter.sol +0 -0
  94. /package/dist/templates/{react → react-ecs}/packages/contracts/src/codegen/world/IIncrementSystem.sol +0 -0
  95. /package/dist/templates/{react → react-ecs}/packages/contracts/src/systems/IncrementSystem.sol +0 -0
  96. /package/dist/templates/{react → react-ecs}/packages/contracts/test/CounterTest.t.sol +0 -0
package/dist/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var t=require("create-create-app"),s=require("path");var e={name:"create-mud",version:"2.0.0-next.12",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 && ./scripts/copy-templates.sh",clean:"pnpm run clean:js","clean:js":"rimraf dist",dev:"tsup --watch",prepublishOnly:"npm run clean && npm run build",test:"pnpm run test:vanilla && pnpm run test:react && pnpm run test:phaser && pnpm run test:threejs","test:ci":"pnpm run test","test:phaser":"dist/cli.js test-project --template phaser && rimraf test-project","test:react":"dist/cli.js test-project --template react && rimraf test-project","test:threejs":"dist/cli.js test-project --template threejs && rimraf test-project","test:vanilla":"dist/cli.js test-project --template vanilla && rimraf test-project"},dependencies:{"create-create-app":"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63"},devDependencies:{"@types/node":"^18.15.11",tsup:"^6.7.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"},gitHead:"914a1e0ae4a573d685841ca2ea921435057deb8f"};var i=(0,s.resolve)(__dirname,"..","dist","templates");(0,t.create)("create-mud",{templateRoot:i,defaultTemplate:"vanilla",defaultPackageManager:"pnpm",promptForDescription:!1,promptForAuthor:!1,promptForEmail:!1,promptForLicense:!1,promptForTemplate:!0,caveat:({answers:r,packageManager:a})=>`Done! Play in the MUD with \`cd ${r.name}\` and \`${a} run dev\``,extra:{"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:e.version}}});
2
+ "use strict";var t=require("create-create-app"),s=require("path");var e={name:"create-mud",version:"2.0.0-next.13",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 && ./scripts/copy-templates.sh",clean:"pnpm run clean:js","clean:js":"rimraf 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 && rimraf test-project","test:react":"dist/cli.js test-project --template react && rimraf test-project","test:react-ecs":"dist/cli.js test-project --template react-ecs && rimraf test-project","test:threejs":"dist/cli.js test-project --template threejs && rimraf test-project","test:vanilla":"dist/cli.js test-project --template vanilla && rimraf test-project"},dependencies:{"create-create-app":"git+https://github.com/holic/create-create-app#74376c59b48a04aabbe94d9cacfe9cb1cecccd63"},devDependencies:{"@types/node":"^18.15.11",tsup:"^6.7.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"},gitHead:"914a1e0ae4a573d685841ca2ea921435057deb8f"};var c=(0,s.resolve)(__dirname,"..","dist","templates");(0,t.create)("create-mud",{templateRoot:c,defaultTemplate:"vanilla",defaultPackageManager:"pnpm",promptForDescription:!1,promptForAuthor:!1,promptForEmail:!1,promptForLicense:!1,promptForTemplate:!0,caveat:({answers:r,packageManager:a})=>`Done! Play in the MUD with \`cd ${r.name}\` and \`${a} run dev\``,extra:{"mud-version":{type:"input",describe:"The version of MUD packages to use, defaults to latest",default:e.version}}});
@@ -1,3 +1,3 @@
1
1
  {
2
- "recommendations": ["JuanBlanco.solidity"]
2
+ "recommendations": ["NomicFoundation.hardhat-solidity"]
3
3
  }
@@ -1,4 +1 @@
1
- {
2
- "solidity.monoRepoSupport": true,
3
- "solidity.compileUsingRemoteVersion": "v0.8.21+commit.d9974bed"
4
- }
1
+ {}
@@ -0,0 +1,7 @@
1
+ procs:
2
+ contracts:
3
+ cwd: packages/contracts
4
+ shell: pnpm run dev
5
+ client:
6
+ cwd: packages/client
7
+ shell: pnpm run dev
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "scripts": {
5
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\"",
6
+ "dev": "mprocs",
7
7
  "dev:client": "pnpm --filter 'client' run dev",
8
8
  "dev:contracts": "pnpm --filter 'contracts' dev",
9
9
  "foundry:up": "curl -L https://foundry.paradigm.xyz | bash && bash $HOME/.foundry/bin/foundryup",
@@ -15,8 +15,8 @@
15
15
  "@latticexyz/cli": "{{mud-version}}",
16
16
  "@typescript-eslint/eslint-plugin": "5.46.1",
17
17
  "@typescript-eslint/parser": "5.46.1",
18
- "concurrently": "^8.0.1",
19
18
  "eslint": "8.29.0",
19
+ "mprocs": "^0.6.4",
20
20
  "rimraf": "^3.0.2",
21
21
  "typescript": "5.1.6"
22
22
  },
@@ -4,5 +4,8 @@
4
4
  # your deployment enviroment, but we're including this here for ease of local
5
5
  # development. Please do not commit changes to this file!
6
6
  #
7
+ # Enable debug logs for MUD CLI
8
+ DEBUG=mud:*
9
+ #
7
10
  # Anvil default private key:
8
11
  PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
@@ -1,3 +1,3 @@
1
- ds-test/=./node_modules/ds-test/src/
2
- forge-std/=./node_modules/forge-std/src/
3
- @latticexyz/=./node_modules/@latticexyz/
1
+ ds-test/=node_modules/ds-test/src/
2
+ forge-std/=node_modules/forge-std/src/
3
+ @latticexyz/=node_modules/@latticexyz/
@@ -3,10 +3,15 @@ pragma solidity >=0.8.21;
3
3
 
4
4
  import { Script } from "forge-std/Script.sol";
5
5
  import { console } from "forge-std/console.sol";
6
+ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
7
+
6
8
  import { IWorld } from "../src/codegen/world/IWorld.sol";
7
9
 
8
10
  contract PostDeploy is Script {
9
11
  function run(address worldAddress) external {
12
+ // Specify a store so that you can use tables directly in PostDeploy
13
+ StoreSwitch.setStoreAddress(worldAddress);
14
+
10
15
  // Load the private key from the `PRIVATE_KEY` environment variable (in .env)
11
16
  uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
12
17
 
@@ -1,3 +1,3 @@
1
1
  {
2
- "recommendations": ["JuanBlanco.solidity"]
2
+ "recommendations": ["NomicFoundation.hardhat-solidity"]
3
3
  }
@@ -1,4 +1 @@
1
- {
2
- "solidity.monoRepoSupport": true,
3
- "solidity.compileUsingRemoteVersion": "v0.8.21+commit.d9974bed"
4
- }
1
+ {}
@@ -0,0 +1,7 @@
1
+ procs:
2
+ contracts:
3
+ cwd: packages/contracts
4
+ shell: pnpm run dev
5
+ client:
6
+ cwd: packages/client
7
+ shell: pnpm run dev
@@ -3,7 +3,7 @@
3
3
  "private": true,
4
4
  "scripts": {
5
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\"",
6
+ "dev": "mprocs",
7
7
  "dev:client": "pnpm --filter 'client' run dev",
8
8
  "dev:contracts": "pnpm --filter 'contracts' dev",
9
9
  "foundry:up": "curl -L https://foundry.paradigm.xyz | bash && bash $HOME/.foundry/bin/foundryup",
@@ -15,8 +15,8 @@
15
15
  "@latticexyz/cli": "{{mud-version}}",
16
16
  "@typescript-eslint/eslint-plugin": "5.46.1",
17
17
  "@typescript-eslint/parser": "5.46.1",
18
- "concurrently": "^8.0.1",
19
18
  "eslint": "8.29.0",
19
+ "mprocs": "^0.6.4",
20
20
  "rimraf": "^3.0.2",
21
21
  "typescript": "5.1.6"
22
22
  },
@@ -14,7 +14,6 @@
14
14
  "@latticexyz/common": "{{mud-version}}",
15
15
  "@latticexyz/dev-tools": "{{mud-version}}",
16
16
  "@latticexyz/react": "{{mud-version}}",
17
- "@latticexyz/recs": "{{mud-version}}",
18
17
  "@latticexyz/schema-type": "{{mud-version}}",
19
18
  "@latticexyz/services": "{{mud-version}}",
20
19
  "@latticexyz/store-sync": "{{mud-version}}",
@@ -1,29 +1,105 @@
1
- import { useComponentValue } from "@latticexyz/react";
2
1
  import { useMUD } from "./MUDContext";
3
- import { singletonEntity } from "@latticexyz/store-sync/recs";
2
+
3
+ const styleUnset = { all: "unset" } as const;
4
4
 
5
5
  export const App = () => {
6
6
  const {
7
- components: { Counter },
8
- systemCalls: { increment },
7
+ network: { tables, useStore },
8
+ systemCalls: { addTask, toggleTask, deleteTask },
9
9
  } = useMUD();
10
10
 
11
- const counter = useComponentValue(Counter, singletonEntity);
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
+ });
12
16
 
13
17
  return (
14
18
  <>
15
- <div>
16
- Counter: <span>{counter?.value ?? "??"}</span>
17
- </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>
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.key);
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.key);
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>
27
103
  </>
28
104
  );
29
105
  };
@@ -28,7 +28,6 @@ setup().then(async (result) => {
28
28
  worldAddress: result.network.worldContract.address,
29
29
  worldAbi: result.network.worldContract.abi,
30
30
  write$: result.network.write$,
31
- recsWorld: result.network.world,
32
31
  });
33
32
  }
34
33
  });
@@ -3,10 +3,8 @@
3
3
  * for changes in the World state (using the System contracts).
4
4
  */
5
5
 
6
- import { getComponentValue } from "@latticexyz/recs";
7
- import { ClientComponents } from "./createClientComponents";
6
+ import { Hex } from "viem";
8
7
  import { SetupNetworkResult } from "./setupNetwork";
9
- import { singletonEntity } from "@latticexyz/store-sync/recs";
10
8
 
11
9
  export type SystemCalls = ReturnType<typeof createSystemCalls>;
12
10
 
@@ -30,22 +28,27 @@ export function createSystemCalls(
30
28
  * syncToRecs
31
29
  * (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
32
30
  */
33
- { worldContract, waitForTransaction }: SetupNetworkResult,
34
- { Counter }: ClientComponents
31
+ { tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult
35
32
  ) {
36
- const increment = async () => {
37
- /*
38
- * Because IncrementSystem
39
- * (https://mud.dev/templates/typescript/contracts#incrementsystemsol)
40
- * is in the root namespace, `.increment` can be called directly
41
- * on the World contract.
42
- */
43
- const tx = await worldContract.write.increment();
33
+ const addTask = async (label: string) => {
34
+ const tx = await worldContract.write.addTask([label]);
35
+ await waitForTransaction(tx);
36
+ };
37
+
38
+ const toggleTask = async (key: Hex) => {
39
+ const isComplete = (useStore.getState().getValue(tables.Tasks, { key })?.completedAt ?? 0n) > 0n;
40
+ const tx = isComplete ? await worldContract.write.resetTask([key]) : await worldContract.write.completeTask([key]);
41
+ await waitForTransaction(tx);
42
+ };
43
+
44
+ const deleteTask = async (key: Hex) => {
45
+ const tx = await worldContract.write.deleteTask([key]);
44
46
  await waitForTransaction(tx);
45
- return getComponentValue(Counter, singletonEntity);
46
47
  };
47
48
 
48
49
  return {
49
- increment,
50
+ addTask,
51
+ toggleTask,
52
+ deleteTask,
50
53
  };
51
54
  }
@@ -2,7 +2,6 @@
2
2
  * This file sets up all the definitions required for a MUD client.
3
3
  */
4
4
 
5
- import { createClientComponents } from "./createClientComponents";
6
5
  import { createSystemCalls } from "./createSystemCalls";
7
6
  import { setupNetwork } from "./setupNetwork";
8
7
 
@@ -10,12 +9,10 @@ export type SetupResult = Awaited<ReturnType<typeof setup>>;
10
9
 
11
10
  export async function setup() {
12
11
  const network = await setupNetwork();
13
- const components = createClientComponents(network);
14
- const systemCalls = createSystemCalls(network, components);
12
+ const systemCalls = createSystemCalls(network);
15
13
 
16
14
  return {
17
15
  network,
18
- components,
19
16
  systemCalls,
20
17
  };
21
18
  }
@@ -5,13 +5,10 @@
5
5
  */
6
6
  import { createPublicClient, fallback, webSocket, http, createWalletClient, Hex, parseEther, ClientConfig } from "viem";
7
7
  import { createFaucetService } from "@latticexyz/services/faucet";
8
- import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
9
-
8
+ import { syncToZustand } from "@latticexyz/store-sync/zustand";
10
9
  import { getNetworkConfig } from "./getNetworkConfig";
11
- import { world } from "./world";
12
10
  import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
13
11
  import { createBurnerAccount, getContract, transportObserver, ContractWrite } from "@latticexyz/common";
14
-
15
12
  import { Subject, share } from "rxjs";
16
13
 
17
14
  /*
@@ -74,8 +71,7 @@ export async function setupNetwork() {
74
71
  * to the viem publicClient to make RPC calls to fetch MUD
75
72
  * events from the chain.
76
73
  */
77
- const { components, latestBlock$, storedBlockLogs$, waitForTransaction } = await syncToRecs({
78
- world,
74
+ const { tables, useStore, latestBlock$, storedBlockLogs$, waitForTransaction } = await syncToZustand({
79
75
  config: mudConfig,
80
76
  address: networkConfig.worldAddress as Hex,
81
77
  publicClient,
@@ -111,9 +107,8 @@ export async function setupNetwork() {
111
107
  }
112
108
 
113
109
  return {
114
- world,
115
- components,
116
- playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }),
110
+ tables,
111
+ useStore,
117
112
  publicClient,
118
113
  walletClient: burnerWalletClient,
119
114
  latestBlock$,
@@ -4,5 +4,8 @@
4
4
  # your deployment enviroment, but we're including this here for ease of local
5
5
  # development. Please do not commit changes to this file!
6
6
  #
7
+ # Enable debug logs for MUD CLI
8
+ DEBUG=mud:*
9
+ #
7
10
  # Anvil default private key:
8
11
  PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
@@ -2,9 +2,12 @@ import { mudConfig } from "@latticexyz/world/register";
2
2
 
3
3
  export default mudConfig({
4
4
  tables: {
5
- Counter: {
6
- keySchema: {},
7
- valueSchema: "uint32",
5
+ Tasks: {
6
+ valueSchema: {
7
+ createdAt: "uint256",
8
+ completedAt: "uint256",
9
+ description: "string",
10
+ },
8
11
  },
9
12
  },
10
13
  });
@@ -1,3 +1,3 @@
1
- ds-test/=./node_modules/ds-test/src/
2
- forge-std/=./node_modules/forge-std/src/
3
- @latticexyz/=./node_modules/@latticexyz/
1
+ ds-test/=node_modules/ds-test/src/
2
+ forge-std/=node_modules/forge-std/src/
3
+ @latticexyz/=node_modules/@latticexyz/
@@ -3,21 +3,30 @@ pragma solidity >=0.8.21;
3
3
 
4
4
  import { Script } from "forge-std/Script.sol";
5
5
  import { console } from "forge-std/console.sol";
6
+ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
7
+
6
8
  import { IWorld } from "../src/codegen/world/IWorld.sol";
9
+ import { Tasks, TasksData } from "../src/codegen/index.sol";
7
10
 
8
11
  contract PostDeploy is Script {
9
12
  function run(address worldAddress) external {
13
+ // Specify a store so that you can use tables directly in PostDeploy
14
+ StoreSwitch.setStoreAddress(worldAddress);
15
+
10
16
  // Load the private key from the `PRIVATE_KEY` environment variable (in .env)
11
17
  uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
12
18
 
13
19
  // Start broadcasting transactions from the deployer account
14
20
  vm.startBroadcast(deployerPrivateKey);
15
21
 
16
- // ------------------ EXAMPLES ------------------
22
+ // We can set table records directly
23
+ Tasks.set("1", TasksData({ description: "Walk the dog", createdAt: block.timestamp, completedAt: 0 }));
24
+
25
+ // Or we can call our own systems
26
+ IWorld(worldAddress).addTask("Take out the trash");
17
27
 
18
- // Call increment on the world via the registered function selector
19
- uint32 newValue = IWorld(worldAddress).increment();
20
- console.log("Increment via IWorld:", newValue);
28
+ bytes32 key = IWorld(worldAddress).addTask("Do the dishes");
29
+ IWorld(worldAddress).completeTask(key);
21
30
 
22
31
  vm.stopBroadcast();
23
32
  }
@@ -3,4 +3,4 @@ pragma solidity >=0.8.21;
3
3
 
4
4
  /* Autogenerated file. Do not edit manually. */
5
5
 
6
- import { Counter, CounterTableId } from "./tables/Counter.sol";
6
+ import { Tasks, TasksData, TasksTableId } from "./tables/Tasks.sol";