create-mud 2.2.17-6e19b86633174dbbf98eb1a2b4446ef6f0b22ab7 → 2.2.17-78e9ed1294db2e924bd295734f3738bdd2786242

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 (119) 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/mprocs.yaml +1 -9
  5. package/templates/react/packages/client/index.html +2 -2
  6. package/templates/react/packages/client/package.json +9 -17
  7. package/templates/react/packages/client/src/App.tsx +100 -41
  8. package/templates/react/packages/client/src/MUDContext.tsx +21 -0
  9. package/templates/react/packages/client/src/index.tsx +32 -17
  10. package/templates/react/packages/client/src/mud/createSystemCalls.ts +56 -0
  11. package/templates/react/packages/client/src/mud/getNetworkConfig.ts +76 -0
  12. package/templates/react/packages/client/src/mud/setup.ts +18 -0
  13. package/templates/react/packages/client/src/mud/setupNetwork.ts +101 -0
  14. package/templates/react/packages/client/src/mud/supportedChains.ts +20 -0
  15. package/templates/react/packages/client/tsconfig.json +1 -1
  16. package/templates/react/packages/client/vite.config.ts +7 -2
  17. package/templates/react/packages/contracts/.env +1 -1
  18. package/templates/react/packages/contracts/mud.config.ts +8 -6
  19. package/templates/react/packages/contracts/package.json +0 -1
  20. package/templates/react/packages/contracts/script/PostDeploy.s.sol +9 -1
  21. package/templates/react/packages/contracts/src/codegen/index.sol +1 -1
  22. package/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +522 -0
  23. package/templates/{react-ecs/packages/contracts/src/codegen/world/IMoveSystem.sol → react/packages/contracts/src/codegen/world/ITasksSystem.sol} +9 -6
  24. package/templates/react/packages/contracts/src/codegen/world/IWorld.sol +2 -2
  25. package/templates/react/packages/contracts/src/systems/TasksSystem.sol +24 -0
  26. package/templates/react/packages/contracts/test/TasksTest.t.sol +30 -0
  27. package/templates/react/packages/contracts/worlds.json +1 -1
  28. package/templates/react-ecs/mprocs.yaml +1 -9
  29. package/templates/react-ecs/package.json +2 -1
  30. package/templates/react-ecs/packages/client/index.html +2 -2
  31. package/templates/react-ecs/packages/client/package.json +9 -16
  32. package/templates/react-ecs/packages/client/src/App.tsx +21 -66
  33. package/templates/react-ecs/packages/client/src/MUDContext.tsx +21 -0
  34. package/templates/react-ecs/packages/client/src/index.tsx +32 -17
  35. package/templates/react-ecs/packages/client/src/mud/createClientComponents.ts +21 -0
  36. package/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts +51 -0
  37. package/templates/react-ecs/packages/client/src/mud/getNetworkConfig.ts +77 -0
  38. package/templates/react-ecs/packages/client/src/mud/setup.ts +21 -0
  39. package/templates/react-ecs/packages/client/src/mud/setupNetwork.ts +106 -0
  40. package/templates/react-ecs/packages/client/src/mud/supportedChains.ts +20 -0
  41. package/templates/react-ecs/packages/client/src/mud/world.ts +3 -0
  42. package/templates/react-ecs/packages/client/tsconfig.json +1 -1
  43. package/templates/react-ecs/packages/client/vite.config.ts +7 -2
  44. package/templates/react-ecs/packages/contracts/.env +1 -1
  45. package/templates/react-ecs/packages/contracts/mud.config.ts +6 -11
  46. package/templates/react-ecs/packages/contracts/package.json +0 -1
  47. package/templates/react-ecs/packages/contracts/script/PostDeploy.s.sol +5 -1
  48. package/templates/react-ecs/packages/contracts/src/codegen/index.sol +1 -3
  49. package/templates/react-ecs/packages/contracts/src/codegen/tables/{EntityCount.sol → Counter.sol} +35 -35
  50. package/templates/{react/packages/contracts/src/codegen/world/IMoveSystem.sol → react-ecs/packages/contracts/src/codegen/world/IIncrementSystem.sol} +3 -5
  51. package/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol +2 -3
  52. package/templates/react-ecs/packages/contracts/src/systems/IncrementSystem.sol +14 -0
  53. package/templates/react-ecs/packages/contracts/test/CounterTest.t.sol +31 -0
  54. package/templates/react-ecs/packages/contracts/worlds.json +1 -1
  55. package/templates/phaser/.gitignore_ +0 -7
  56. package/templates/phaser/packages/art/.gitignore_ +0 -0
  57. package/templates/phaser/packages/client/.gitignore_ +0 -3
  58. package/templates/phaser/packages/contracts/.gitignore_ +0 -9
  59. package/templates/react/.gitignore_ +0 -16
  60. package/templates/react/packages/client/.gitignore_ +0 -1
  61. package/templates/react/packages/client/postcss.config.cjs +0 -6
  62. package/templates/react/packages/client/src/Providers.tsx +0 -35
  63. package/templates/react/packages/client/src/common.ts +0 -26
  64. package/templates/react/packages/client/src/game/GameMap.tsx +0 -102
  65. package/templates/react/packages/client/src/game/useKeyboardMovement.ts +0 -26
  66. package/templates/react/packages/client/src/mud/Explorer.tsx +0 -32
  67. package/templates/react/packages/client/src/mud/Synced.tsx +0 -14
  68. package/templates/react/packages/client/src/mud/stash.ts +0 -4
  69. package/templates/react/packages/client/src/mud/useSyncStatus.ts +0 -21
  70. package/templates/react/packages/client/src/mud/useWorldContract.ts +0 -44
  71. package/templates/react/packages/client/src/ui/AsyncButton.tsx +0 -41
  72. package/templates/react/packages/client/src/ui/ErrorFallback.tsx +0 -58
  73. package/templates/react/packages/client/src/ui/icons/ArrowDownIcon.tsx +0 -22
  74. package/templates/react/packages/client/src/ui/icons/MUDIcon.tsx +0 -25
  75. package/templates/react/packages/client/src/wagmiConfig.ts +0 -49
  76. package/templates/react/packages/client/tailwind.config.ts +0 -10
  77. package/templates/react/packages/contracts/.gitignore_ +0 -13
  78. package/templates/react/packages/contracts/out/IWorld.sol/IWorld.abi.json +0 -2021
  79. package/templates/react/packages/contracts/src/MoveSystem.sol +0 -26
  80. package/templates/react/packages/contracts/src/codegen/common.sol +0 -11
  81. package/templates/react/packages/contracts/src/codegen/tables/Position.sol +0 -318
  82. package/templates/react/packages/contracts/test/MoveTest.t.sol +0 -25
  83. package/templates/react/packages/contracts/test/WorldTest.t.sol +0 -16
  84. package/templates/react-ecs/.gitignore_ +0 -16
  85. package/templates/react-ecs/packages/client/.gitignore_ +0 -1
  86. package/templates/react-ecs/packages/client/postcss.config.cjs +0 -6
  87. package/templates/react-ecs/packages/client/src/Providers.tsx +0 -29
  88. package/templates/react-ecs/packages/client/src/common.ts +0 -27
  89. package/templates/react-ecs/packages/client/src/game/GameMap.tsx +0 -112
  90. package/templates/react-ecs/packages/client/src/game/useKeyboardMovement.ts +0 -26
  91. package/templates/react-ecs/packages/client/src/mud/Explorer.tsx +0 -32
  92. package/templates/react-ecs/packages/client/src/mud/Synced.tsx +0 -14
  93. package/templates/react-ecs/packages/client/src/mud/recs.ts +0 -6
  94. package/templates/react-ecs/packages/client/src/mud/useSyncStatus.ts +0 -17
  95. package/templates/react-ecs/packages/client/src/mud/useWorldContract.ts +0 -44
  96. package/templates/react-ecs/packages/client/src/ui/AsyncButton.tsx +0 -41
  97. package/templates/react-ecs/packages/client/src/ui/ErrorFallback.tsx +0 -58
  98. package/templates/react-ecs/packages/client/src/ui/icons/ArrowDownIcon.tsx +0 -22
  99. package/templates/react-ecs/packages/client/src/ui/icons/MUDIcon.tsx +0 -25
  100. package/templates/react-ecs/packages/client/src/wagmiConfig.ts +0 -49
  101. package/templates/react-ecs/packages/client/tailwind.config.ts +0 -10
  102. package/templates/react-ecs/packages/contracts/.gitignore_ +0 -13
  103. package/templates/react-ecs/packages/contracts/out/IWorld.sol/IWorld.abi.json +0 -2039
  104. package/templates/react-ecs/packages/contracts/src/Entity.sol +0 -20
  105. package/templates/react-ecs/packages/contracts/src/MoveSystem.sol +0 -30
  106. package/templates/react-ecs/packages/contracts/src/SpawnSystem.sol +0 -18
  107. package/templates/react-ecs/packages/contracts/src/codegen/common.sol +0 -11
  108. package/templates/react-ecs/packages/contracts/src/codegen/tables/Owner.sol +0 -202
  109. package/templates/react-ecs/packages/contracts/src/codegen/tables/Position.sol +0 -321
  110. package/templates/react-ecs/packages/contracts/src/codegen/world/ISpawnSystem.sol +0 -15
  111. package/templates/react-ecs/packages/contracts/src/createEntity.sol +0 -11
  112. package/templates/react-ecs/packages/contracts/test/MoveTest.t.sol +0 -39
  113. package/templates/react-ecs/packages/contracts/test/WorldTest.t.sol +0 -16
  114. package/templates/threejs/.gitignore_ +0 -7
  115. package/templates/threejs/packages/client/.gitignore_ +0 -3
  116. package/templates/threejs/packages/contracts/.gitignore_ +0 -9
  117. package/templates/vanilla/.gitignore_ +0 -7
  118. package/templates/vanilla/packages/client/.gitignore_ +0 -3
  119. package/templates/vanilla/packages/contracts/.gitignore_ +0 -9
@@ -2,17 +2,12 @@ import { defineWorld } from "@latticexyz/world";
2
2
 
3
3
  export default defineWorld({
4
4
  namespace: "app",
5
- userTypes: {
6
- Entity: { type: "bytes32", filePath: "./src/Entity.sol" },
7
- },
8
- enums: {
9
- Direction: ["North", "East", "South", "West"],
10
- },
11
5
  tables: {
12
- // singletons
13
- EntityCount: { schema: { count: "uint256" }, key: [] },
14
- // components
15
- Owner: { id: "Entity", owner: "address" },
16
- Position: { id: "Entity", x: "int32", y: "int32" },
6
+ Counter: {
7
+ schema: {
8
+ value: "uint32",
9
+ },
10
+ key: [],
11
+ },
17
12
  },
18
13
  });
@@ -17,7 +17,6 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@latticexyz/cli": "{{mud-version}}",
20
- "@latticexyz/entrykit": "{{mud-version}}",
21
20
  "@latticexyz/schema-type": "{{mud-version}}",
22
21
  "@latticexyz/store": "{{mud-version}}",
23
22
  "@latticexyz/world": "{{mud-version}}",
@@ -18,7 +18,11 @@ contract PostDeploy is Script {
18
18
  // Start broadcasting transactions from the deployer account
19
19
  vm.startBroadcast(deployerPrivateKey);
20
20
 
21
- // TODO
21
+ // ------------------ EXAMPLES ------------------
22
+
23
+ // Call increment on the world via the registered function selector
24
+ uint32 newValue = IWorld(worldAddress).app__increment();
25
+ console.log("Increment via IWorld:", newValue);
22
26
 
23
27
  vm.stopBroadcast();
24
28
  }
@@ -3,6 +3,4 @@ pragma solidity >=0.8.24;
3
3
 
4
4
  /* Autogenerated file. Do not edit manually. */
5
5
 
6
- import { EntityCount } from "./tables/EntityCount.sol";
7
- import { Owner } from "./tables/Owner.sol";
8
- import { Position, PositionData } from "./tables/Position.sol";
6
+ import { Counter } from "./tables/Counter.sol";
@@ -16,17 +16,17 @@ import { Schema } from "@latticexyz/store/src/Schema.sol";
16
16
  import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol";
17
17
  import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
18
18
 
19
- library EntityCount {
20
- // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "app", name: "EntityCount", typeId: RESOURCE_TABLE });`
21
- ResourceId constant _tableId = ResourceId.wrap(0x74626170700000000000000000000000456e74697479436f756e740000000000);
19
+ library Counter {
20
+ // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "app", name: "Counter", typeId: RESOURCE_TABLE });`
21
+ ResourceId constant _tableId = ResourceId.wrap(0x74626170700000000000000000000000436f756e746572000000000000000000);
22
22
 
23
23
  FieldLayout constant _fieldLayout =
24
- FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000);
24
+ FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000);
25
25
 
26
26
  // Hex-encoded key schema of ()
27
27
  Schema constant _keySchema = Schema.wrap(0x0000000000000000000000000000000000000000000000000000000000000000);
28
- // Hex-encoded value schema of (uint256)
29
- Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000);
28
+ // Hex-encoded value schema of (uint32)
29
+ Schema constant _valueSchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000);
30
30
 
31
31
  /**
32
32
  * @notice Get the table's key field names.
@@ -42,7 +42,7 @@ library EntityCount {
42
42
  */
43
43
  function getFieldNames() internal pure returns (string[] memory fieldNames) {
44
44
  fieldNames = new string[](1);
45
- fieldNames[0] = "count";
45
+ fieldNames[0] = "value";
46
46
  }
47
47
 
48
48
  /**
@@ -60,79 +60,79 @@ library EntityCount {
60
60
  }
61
61
 
62
62
  /**
63
- * @notice Get count.
63
+ * @notice Get value.
64
64
  */
65
- function getCount() internal view returns (uint256 count) {
65
+ function getValue() internal view returns (uint32 value) {
66
66
  bytes32[] memory _keyTuple = new bytes32[](0);
67
67
 
68
68
  bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
69
- return (uint256(bytes32(_blob)));
69
+ return (uint32(bytes4(_blob)));
70
70
  }
71
71
 
72
72
  /**
73
- * @notice Get count.
73
+ * @notice Get value.
74
74
  */
75
- function _getCount() internal view returns (uint256 count) {
75
+ function _getValue() internal view returns (uint32 value) {
76
76
  bytes32[] memory _keyTuple = new bytes32[](0);
77
77
 
78
78
  bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
79
- return (uint256(bytes32(_blob)));
79
+ return (uint32(bytes4(_blob)));
80
80
  }
81
81
 
82
82
  /**
83
- * @notice Get count.
83
+ * @notice Get value.
84
84
  */
85
- function get() internal view returns (uint256 count) {
85
+ function get() internal view returns (uint32 value) {
86
86
  bytes32[] memory _keyTuple = new bytes32[](0);
87
87
 
88
88
  bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
89
- return (uint256(bytes32(_blob)));
89
+ return (uint32(bytes4(_blob)));
90
90
  }
91
91
 
92
92
  /**
93
- * @notice Get count.
93
+ * @notice Get value.
94
94
  */
95
- function _get() internal view returns (uint256 count) {
95
+ function _get() internal view returns (uint32 value) {
96
96
  bytes32[] memory _keyTuple = new bytes32[](0);
97
97
 
98
98
  bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
99
- return (uint256(bytes32(_blob)));
99
+ return (uint32(bytes4(_blob)));
100
100
  }
101
101
 
102
102
  /**
103
- * @notice Set count.
103
+ * @notice Set value.
104
104
  */
105
- function setCount(uint256 count) internal {
105
+ function setValue(uint32 value) internal {
106
106
  bytes32[] memory _keyTuple = new bytes32[](0);
107
107
 
108
- StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((count)), _fieldLayout);
108
+ StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
109
109
  }
110
110
 
111
111
  /**
112
- * @notice Set count.
112
+ * @notice Set value.
113
113
  */
114
- function _setCount(uint256 count) internal {
114
+ function _setValue(uint32 value) internal {
115
115
  bytes32[] memory _keyTuple = new bytes32[](0);
116
116
 
117
- StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((count)), _fieldLayout);
117
+ StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
118
118
  }
119
119
 
120
120
  /**
121
- * @notice Set count.
121
+ * @notice Set value.
122
122
  */
123
- function set(uint256 count) internal {
123
+ function set(uint32 value) internal {
124
124
  bytes32[] memory _keyTuple = new bytes32[](0);
125
125
 
126
- StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((count)), _fieldLayout);
126
+ StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
127
127
  }
128
128
 
129
129
  /**
130
- * @notice Set count.
130
+ * @notice Set value.
131
131
  */
132
- function _set(uint256 count) internal {
132
+ function _set(uint32 value) internal {
133
133
  bytes32[] memory _keyTuple = new bytes32[](0);
134
134
 
135
- StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((count)), _fieldLayout);
135
+ StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
136
136
  }
137
137
 
138
138
  /**
@@ -157,8 +157,8 @@ library EntityCount {
157
157
  * @notice Tightly pack static (fixed length) data using this table's schema.
158
158
  * @return The static data, encoded into a sequence of bytes.
159
159
  */
160
- function encodeStatic(uint256 count) internal pure returns (bytes memory) {
161
- return abi.encodePacked(count);
160
+ function encodeStatic(uint32 value) internal pure returns (bytes memory) {
161
+ return abi.encodePacked(value);
162
162
  }
163
163
 
164
164
  /**
@@ -167,8 +167,8 @@ library EntityCount {
167
167
  * @return The lengths of the dynamic fields (packed into a single bytes32 value).
168
168
  * @return The dynamic (variable length) data, encoded into a sequence of bytes.
169
169
  */
170
- function encode(uint256 count) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
171
- bytes memory _staticData = encodeStatic(count);
170
+ function encode(uint32 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
171
+ bytes memory _staticData = encodeStatic(value);
172
172
 
173
173
  EncodedLengths _encodedLengths;
174
174
  bytes memory _dynamicData;
@@ -3,13 +3,11 @@ pragma solidity >=0.8.24;
3
3
 
4
4
  /* Autogenerated file. Do not edit manually. */
5
5
 
6
- import { Direction } from "../common.sol";
7
-
8
6
  /**
9
- * @title IMoveSystem
7
+ * @title IIncrementSystem
10
8
  * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
11
9
  * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually.
12
10
  */
13
- interface IMoveSystem {
14
- function app__move(Direction direction) external;
11
+ interface IIncrementSystem {
12
+ function app__increment() external returns (uint32);
15
13
  }
@@ -4,8 +4,7 @@ pragma solidity >=0.8.24;
4
4
  /* Autogenerated file. Do not edit manually. */
5
5
 
6
6
  import { IBaseWorld } from "@latticexyz/world/src/codegen/interfaces/IBaseWorld.sol";
7
- import { IMoveSystem } from "./IMoveSystem.sol";
8
- import { ISpawnSystem } from "./ISpawnSystem.sol";
7
+ import { IIncrementSystem } from "./IIncrementSystem.sol";
9
8
 
10
9
  /**
11
10
  * @title IWorld
@@ -14,4 +13,4 @@ import { ISpawnSystem } from "./ISpawnSystem.sol";
14
13
  * that are dynamically registered in the World during deployment.
15
14
  * @dev This is an autogenerated file; do not edit manually.
16
15
  */
17
- interface IWorld is IBaseWorld, IMoveSystem, ISpawnSystem {}
16
+ interface IWorld is IBaseWorld, IIncrementSystem {}
@@ -0,0 +1,14 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.24;
3
+
4
+ import { System } from "@latticexyz/world/src/System.sol";
5
+ import { Counter } from "../codegen/index.sol";
6
+
7
+ contract IncrementSystem is System {
8
+ function increment() public returns (uint32) {
9
+ uint32 counter = Counter.get();
10
+ uint32 newValue = counter + 1;
11
+ Counter.set(newValue);
12
+ return newValue;
13
+ }
14
+ }
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.24;
3
+
4
+ import "forge-std/Test.sol";
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 { Counter } from "../src/codegen/index.sol";
10
+
11
+ contract CounterTest is MudTest {
12
+ function testWorldExists() public {
13
+ uint256 codeSize;
14
+ address addr = worldAddress;
15
+ assembly {
16
+ codeSize := extcodesize(addr)
17
+ }
18
+ assertTrue(codeSize > 0);
19
+ }
20
+
21
+ function testCounter() public {
22
+ // Expect the counter to be 1 because it was incremented in the PostDeploy script.
23
+ uint32 counter = Counter.get();
24
+ assertEq(counter, 1);
25
+
26
+ // Expect the counter to be 2 after calling increment.
27
+ IWorld(worldAddress).app__increment();
28
+ counter = Counter.get();
29
+ assertEq(counter, 2);
30
+ }
31
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "31337": {
3
- "address": "0xfdf868ea710ffd8cd33b829c5aff79edd15ecd5f"
3
+ "address": "0x8d8b6b8414e1e3dcfd4168561b9be6bd3bf6ec4b"
4
4
  }
5
5
  }
@@ -1,7 +0,0 @@
1
- node_modules
2
-
3
- # mud artifacts
4
- .mud
5
- # sqlite indexer data
6
- *.db
7
- *.db-journal
File without changes
@@ -1,3 +0,0 @@
1
- node_modules
2
- dist
3
- .DS_Store
@@ -1,9 +0,0 @@
1
- out/
2
- cache/
3
- node_modules/
4
- bindings/
5
- artifacts/
6
- broadcast/
7
-
8
- # Ignore MUD deploy artifacts
9
- deploys/**/*.json
@@ -1,16 +0,0 @@
1
- .DS_Store
2
- logs
3
- *.log
4
-
5
- node_modules
6
-
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
@@ -1 +0,0 @@
1
- dist
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- plugins: {
3
- tailwindcss: {},
4
- autoprefixer: {},
5
- },
6
- };
@@ -1,35 +0,0 @@
1
- import { WagmiProvider } from "wagmi";
2
- import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
3
- import { ReactNode } from "react";
4
- import { createSyncAdapter } from "@latticexyz/store-sync/internal";
5
- import { SyncProvider } from "@latticexyz/store-sync/react";
6
- import { stash } from "./mud/stash";
7
- import { defineConfig, EntryKitProvider } from "@latticexyz/entrykit/internal";
8
- import { wagmiConfig } from "./wagmiConfig";
9
- import { chainId, getWorldAddress, startBlock } from "./common";
10
-
11
- const queryClient = new QueryClient();
12
-
13
- export type Props = {
14
- children: ReactNode;
15
- };
16
-
17
- export function Providers({ children }: Props) {
18
- const worldAddress = getWorldAddress();
19
- return (
20
- <WagmiProvider config={wagmiConfig}>
21
- <QueryClientProvider client={queryClient}>
22
- <EntryKitProvider config={defineConfig({ chainId, worldAddress })}>
23
- <SyncProvider
24
- chainId={chainId}
25
- address={worldAddress}
26
- startBlock={startBlock}
27
- adapter={createSyncAdapter({ stash })}
28
- >
29
- {children}
30
- </SyncProvider>
31
- </EntryKitProvider>
32
- </QueryClientProvider>
33
- </WagmiProvider>
34
- );
35
- }
@@ -1,26 +0,0 @@
1
- import mudConfig from "contracts/mud.config";
2
- import { chains } from "./wagmiConfig";
3
- import { Chain } 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 Direction = (typeof mudConfig.enums.Direction)[number];
12
-
13
- export function getWorldAddress() {
14
- if (!worldAddress) {
15
- throw new Error("No world address configured. Is the world still deploying?");
16
- }
17
- return worldAddress;
18
- }
19
-
20
- export function getChain(): Chain {
21
- const chain = chains.find((c) => c.id === chainId);
22
- if (!chain) {
23
- throw new Error(`No chain configured for chain ID ${chainId}.`);
24
- }
25
- return chain;
26
- }
@@ -1,102 +0,0 @@
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 } from "../common";
7
- import mudConfig from "contracts/mud.config";
8
- import { AsyncButton } from "../ui/AsyncButton";
9
- import { useAccountModal } from "@latticexyz/entrykit/internal";
10
-
11
- export type Props = {
12
- readonly players?: readonly {
13
- readonly player: Address;
14
- readonly x: number;
15
- readonly y: number;
16
- }[];
17
-
18
- readonly onMove?: (direction: Direction) => Promise<void>;
19
- };
20
-
21
- const size = 40;
22
- const scale = 100 / size;
23
-
24
- function getColorAngle(seed: Hex) {
25
- return Number(hexToBigInt(keccak256(seed)) % 360n);
26
- }
27
-
28
- const rotateClassName = {
29
- North: "rotate-0",
30
- East: "rotate-90",
31
- South: "rotate-180",
32
- West: "-rotate-90",
33
- } as const satisfies Record<Direction, `${"" | "-"}rotate-${number}`>;
34
-
35
- export function GameMap({ players = [], onMove }: Props) {
36
- const { openAccountModal } = useAccountModal();
37
- const { address: userAddress } = useAccount();
38
- const currentPlayer = players.find((player) => player.player.toLowerCase() === userAddress?.toLowerCase());
39
- useKeyboardMovement(onMove);
40
- return (
41
- <div className="aspect-square w-full max-w-[40rem]">
42
- <div className="relative w-full h-full border-8 border-black/10">
43
- {onMove
44
- ? mudConfig.enums.Direction.map((direction) => (
45
- <button
46
- key={direction}
47
- title={`Move ${direction.toLowerCase()}`}
48
- className={twMerge(
49
- "outline-0 absolute inset-0 cursor-pointer grid p-4",
50
- rotateClassName[direction],
51
- "transition bg-gradient-to-t from-transparent via-transparent to-blue-50 text-blue-400 opacity-0 hover:opacity-40 active:opacity-100",
52
- )}
53
- style={{ clipPath: "polygon(0% 0%, 100% 0%, 50% 50%)" }}
54
- onClick={() => onMove(direction)}
55
- >
56
- <ArrowDownIcon className="rotate-180 text-4xl self-start justify-self-center" />
57
- </button>
58
- ))
59
- : null}
60
-
61
- {players.map((player) => (
62
- <div
63
- key={player.player}
64
- className="absolute bg-current"
65
- style={{
66
- color: `hwb(${getColorAngle(player.player)} 40% 20%)`,
67
- width: `${scale}%`,
68
- height: `${scale}%`,
69
- left: `${((((player.x + size / 2) % size) + size) % size) * scale}%`,
70
- top: `${((size - ((player.y + size / 2) % size)) % size) * scale}%`,
71
- }}
72
- title={serialize(player, null, 2)}
73
- >
74
- {player === currentPlayer ? <div className="w-full h-full bg-current animate-ping opacity-50" /> : null}
75
- </div>
76
- ))}
77
-
78
- {!currentPlayer ? (
79
- onMove ? (
80
- <div className="absolute inset-0 grid place-items-center">
81
- <AsyncButton
82
- 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"
83
- onClick={() => onMove("North")}
84
- >
85
- Spawn<span className="hidden group-aria-busy:inline">ing…</span>
86
- </AsyncButton>
87
- </div>
88
- ) : (
89
- <div className="absolute inset-0 grid place-items-center">
90
- <button
91
- 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"
92
- onClick={openAccountModal}
93
- >
94
- Sign in to play
95
- </button>
96
- </div>
97
- )
98
- ) : null}
99
- </div>
100
- </div>
101
- );
102
- }
@@ -1,26 +0,0 @@
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,32 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
1
- import { ReactNode } from "react";
2
- import { useSyncStatus } from "./useSyncStatus";
3
- import { TableRecord } from "@latticexyz/stash/internal";
4
- import { SyncProgress } from "@latticexyz/store-sync/internal";
5
-
6
- export type Props = {
7
- children: ReactNode;
8
- fallback?: (props: TableRecord<typeof SyncProgress>) => ReactNode;
9
- };
10
-
11
- export function Synced({ children, fallback }: Props) {
12
- const status = useSyncStatus();
13
- return status.isLive ? children : fallback?.(status);
14
- }
@@ -1,4 +0,0 @@
1
- import { createStash } from "@latticexyz/stash/internal";
2
- import config from "contracts/mud.config";
3
-
4
- export const stash = createStash(config);
@@ -1,21 +0,0 @@
1
- import { stash } from "./stash";
2
- import { initialProgress, SyncProgress } from "@latticexyz/store-sync/internal";
3
- import { SyncStep } from "@latticexyz/store-sync";
4
- import { useMemo } from "react";
5
- import { useRecord } from "@latticexyz/stash/react";
6
-
7
- export function useSyncStatus() {
8
- const progress = useRecord({
9
- stash,
10
- table: SyncProgress,
11
- key: {},
12
- defaultValue: initialProgress,
13
- });
14
- return useMemo(
15
- () => ({
16
- ...progress,
17
- isLive: progress.step === SyncStep.LIVE,
18
- }),
19
- [progress],
20
- );
21
- }