create-mud 2.2.17-78e9ed1294db2e924bd295734f3738bdd2786242 → 2.2.17-86f455c0a09d5d8af64d030669ebf30ffa71420b
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.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/templates/react/mprocs.yaml +9 -1
- package/templates/react/packages/client/index.html +2 -2
- package/templates/react/packages/client/package.json +17 -9
- package/templates/react/packages/client/postcss.config.cjs +6 -0
- package/templates/react/packages/client/src/App.tsx +41 -100
- package/templates/react/packages/client/src/Providers.tsx +35 -0
- package/templates/react/packages/client/src/common.ts +26 -0
- package/templates/react/packages/client/src/game/GameMap.tsx +102 -0
- package/templates/react/packages/client/src/game/useKeyboardMovement.ts +26 -0
- package/templates/react/packages/client/src/index.tsx +17 -32
- package/templates/react/packages/client/src/mud/Explorer.tsx +32 -0
- package/templates/react/packages/client/src/mud/Synced.tsx +14 -0
- package/templates/react/packages/client/src/mud/stash.ts +4 -0
- package/templates/react/packages/client/src/mud/useSyncStatus.ts +21 -0
- package/templates/react/packages/client/src/mud/useWorldContract.ts +44 -0
- package/templates/react/packages/client/src/ui/AsyncButton.tsx +41 -0
- package/templates/react/packages/client/src/ui/ErrorFallback.tsx +58 -0
- package/templates/react/packages/client/src/ui/icons/ArrowDownIcon.tsx +22 -0
- package/templates/react/packages/client/src/ui/icons/MUDIcon.tsx +25 -0
- package/templates/react/packages/client/src/wagmiConfig.ts +49 -0
- package/templates/react/packages/client/tailwind.config.ts +10 -0
- package/templates/react/packages/client/tsconfig.json +1 -1
- package/templates/react/packages/client/vite.config.ts +2 -7
- package/templates/react/packages/contracts/.env +1 -1
- package/templates/react/packages/contracts/mud.config.ts +13 -8
- package/templates/react/packages/contracts/out/IWorld.sol/IWorld.abi.json +2021 -0
- package/templates/react/packages/contracts/package.json +1 -0
- package/templates/react/packages/contracts/script/PostDeploy.s.sol +1 -9
- package/templates/react/packages/contracts/src/MoveSystem.sol +26 -0
- package/templates/react/packages/contracts/src/codegen/common.sol +11 -0
- package/templates/react/packages/contracts/src/codegen/index.sol +1 -1
- package/templates/react/packages/contracts/src/codegen/tables/Position.sol +318 -0
- package/templates/{react-ecs/packages/contracts/src/codegen/world/IIncrementSystem.sol → react/packages/contracts/src/codegen/world/IMoveSystem.sol} +5 -3
- package/templates/react/packages/contracts/src/codegen/world/IWorld.sol +2 -2
- package/templates/react/packages/contracts/test/MoveTest.t.sol +25 -0
- package/templates/react/packages/contracts/test/WorldTest.t.sol +16 -0
- package/templates/react/packages/contracts/worlds.json +1 -1
- package/templates/react-ecs/mprocs.yaml +9 -1
- package/templates/react-ecs/package.json +1 -2
- package/templates/react-ecs/packages/client/index.html +2 -2
- package/templates/react-ecs/packages/client/package.json +16 -9
- package/templates/react-ecs/packages/client/postcss.config.cjs +6 -0
- package/templates/react-ecs/packages/client/src/App.tsx +66 -21
- package/templates/react-ecs/packages/client/src/Providers.tsx +29 -0
- package/templates/react-ecs/packages/client/src/common.ts +27 -0
- package/templates/react-ecs/packages/client/src/game/GameMap.tsx +112 -0
- package/templates/react-ecs/packages/client/src/game/useKeyboardMovement.ts +26 -0
- package/templates/react-ecs/packages/client/src/index.tsx +17 -32
- package/templates/react-ecs/packages/client/src/mud/Explorer.tsx +32 -0
- package/templates/react-ecs/packages/client/src/mud/Synced.tsx +14 -0
- package/templates/react-ecs/packages/client/src/mud/recs.ts +6 -0
- package/templates/react-ecs/packages/client/src/mud/useSyncStatus.ts +17 -0
- package/templates/react-ecs/packages/client/src/mud/useWorldContract.ts +44 -0
- package/templates/react-ecs/packages/client/src/ui/AsyncButton.tsx +41 -0
- package/templates/react-ecs/packages/client/src/ui/ErrorFallback.tsx +58 -0
- package/templates/react-ecs/packages/client/src/ui/icons/ArrowDownIcon.tsx +22 -0
- package/templates/react-ecs/packages/client/src/ui/icons/MUDIcon.tsx +25 -0
- package/templates/react-ecs/packages/client/src/wagmiConfig.ts +49 -0
- package/templates/react-ecs/packages/client/tailwind.config.ts +10 -0
- package/templates/react-ecs/packages/client/tsconfig.json +1 -1
- package/templates/react-ecs/packages/client/vite.config.ts +2 -7
- package/templates/react-ecs/packages/contracts/.env +1 -1
- package/templates/react-ecs/packages/contracts/mud.config.ts +18 -6
- package/templates/react-ecs/packages/contracts/out/IWorld.sol/IWorld.abi.json +2039 -0
- package/templates/react-ecs/packages/contracts/package.json +1 -0
- package/templates/react-ecs/packages/contracts/script/PostDeploy.s.sol +1 -5
- package/templates/react-ecs/packages/contracts/src/Entity.sol +20 -0
- package/templates/react-ecs/packages/contracts/src/MoveSystem.sol +30 -0
- package/templates/react-ecs/packages/contracts/src/SpawnSystem.sol +18 -0
- package/templates/react-ecs/packages/contracts/src/codegen/common.sol +11 -0
- package/templates/react-ecs/packages/contracts/src/codegen/index.sol +3 -1
- package/templates/react-ecs/packages/contracts/src/codegen/tables/{Counter.sol → EntityCount.sol} +35 -35
- package/templates/react-ecs/packages/contracts/src/codegen/tables/Owner.sol +202 -0
- package/templates/react-ecs/packages/contracts/src/codegen/tables/Position.sol +321 -0
- package/templates/{react/packages/contracts/src/codegen/world/ITasksSystem.sol → react-ecs/packages/contracts/src/codegen/world/IMoveSystem.sol} +6 -9
- package/templates/react-ecs/packages/contracts/src/codegen/world/ISpawnSystem.sol +15 -0
- package/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol +3 -2
- package/templates/react-ecs/packages/contracts/src/createEntity.sol +11 -0
- package/templates/react-ecs/packages/contracts/test/MoveTest.t.sol +39 -0
- package/templates/react-ecs/packages/contracts/test/WorldTest.t.sol +16 -0
- package/templates/react-ecs/packages/contracts/worlds.json +1 -1
- package/templates/react/packages/client/src/MUDContext.tsx +0 -21
- package/templates/react/packages/client/src/mud/createSystemCalls.ts +0 -56
- package/templates/react/packages/client/src/mud/getNetworkConfig.ts +0 -76
- package/templates/react/packages/client/src/mud/setup.ts +0 -18
- package/templates/react/packages/client/src/mud/setupNetwork.ts +0 -101
- package/templates/react/packages/client/src/mud/supportedChains.ts +0 -20
- package/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +0 -522
- package/templates/react/packages/contracts/src/systems/TasksSystem.sol +0 -24
- package/templates/react/packages/contracts/test/TasksTest.t.sol +0 -30
- package/templates/react-ecs/packages/client/src/MUDContext.tsx +0 -21
- package/templates/react-ecs/packages/client/src/mud/createClientComponents.ts +0 -21
- package/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts +0 -51
- package/templates/react-ecs/packages/client/src/mud/getNetworkConfig.ts +0 -77
- package/templates/react-ecs/packages/client/src/mud/setup.ts +0 -21
- package/templates/react-ecs/packages/client/src/mud/setupNetwork.ts +0 -106
- package/templates/react-ecs/packages/client/src/mud/supportedChains.ts +0 -20
- package/templates/react-ecs/packages/client/src/mud/world.ts +0 -3
- package/templates/react-ecs/packages/contracts/src/systems/IncrementSystem.sol +0 -14
- package/templates/react-ecs/packages/contracts/test/CounterTest.t.sol +0 -31
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.24;
|
|
3
|
+
|
|
4
|
+
/* Autogenerated file. Do not edit manually. */
|
|
5
|
+
|
|
6
|
+
// Import store internals
|
|
7
|
+
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
|
8
|
+
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
|
9
|
+
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
|
|
10
|
+
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
|
11
|
+
import { Memory } from "@latticexyz/store/src/Memory.sol";
|
|
12
|
+
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
|
|
13
|
+
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
|
14
|
+
import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol";
|
|
15
|
+
import { Schema } from "@latticexyz/store/src/Schema.sol";
|
|
16
|
+
import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol";
|
|
17
|
+
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
|
18
|
+
|
|
19
|
+
// Import user types
|
|
20
|
+
import { Entity } from "../../Entity.sol";
|
|
21
|
+
|
|
22
|
+
struct PositionData {
|
|
23
|
+
int32 x;
|
|
24
|
+
int32 y;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
library Position {
|
|
28
|
+
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "app", name: "Position", typeId: RESOURCE_TABLE });`
|
|
29
|
+
ResourceId constant _tableId = ResourceId.wrap(0x74626170700000000000000000000000506f736974696f6e0000000000000000);
|
|
30
|
+
|
|
31
|
+
FieldLayout constant _fieldLayout =
|
|
32
|
+
FieldLayout.wrap(0x0008020004040000000000000000000000000000000000000000000000000000);
|
|
33
|
+
|
|
34
|
+
// Hex-encoded key schema of (bytes32)
|
|
35
|
+
Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000);
|
|
36
|
+
// Hex-encoded value schema of (int32, int32)
|
|
37
|
+
Schema constant _valueSchema = Schema.wrap(0x0008020023230000000000000000000000000000000000000000000000000000);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @notice Get the table's key field names.
|
|
41
|
+
* @return keyNames An array of strings with the names of key fields.
|
|
42
|
+
*/
|
|
43
|
+
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
|
44
|
+
keyNames = new string[](1);
|
|
45
|
+
keyNames[0] = "id";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @notice Get the table's value field names.
|
|
50
|
+
* @return fieldNames An array of strings with the names of value fields.
|
|
51
|
+
*/
|
|
52
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
|
53
|
+
fieldNames = new string[](2);
|
|
54
|
+
fieldNames[0] = "x";
|
|
55
|
+
fieldNames[1] = "y";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @notice Register the table with its config.
|
|
60
|
+
*/
|
|
61
|
+
function register() internal {
|
|
62
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @notice Register the table with its config.
|
|
67
|
+
*/
|
|
68
|
+
function _register() internal {
|
|
69
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @notice Get x.
|
|
74
|
+
*/
|
|
75
|
+
function getX(Entity id) internal view returns (int32 x) {
|
|
76
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
77
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
78
|
+
|
|
79
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
80
|
+
return (int32(uint32(bytes4(_blob))));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @notice Get x.
|
|
85
|
+
*/
|
|
86
|
+
function _getX(Entity id) internal view returns (int32 x) {
|
|
87
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
88
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
89
|
+
|
|
90
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
91
|
+
return (int32(uint32(bytes4(_blob))));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @notice Set x.
|
|
96
|
+
*/
|
|
97
|
+
function setX(Entity id, int32 x) internal {
|
|
98
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
99
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
100
|
+
|
|
101
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @notice Set x.
|
|
106
|
+
*/
|
|
107
|
+
function _setX(Entity id, int32 x) internal {
|
|
108
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
109
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
110
|
+
|
|
111
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @notice Get y.
|
|
116
|
+
*/
|
|
117
|
+
function getY(Entity id) internal view returns (int32 y) {
|
|
118
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
119
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
120
|
+
|
|
121
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout);
|
|
122
|
+
return (int32(uint32(bytes4(_blob))));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @notice Get y.
|
|
127
|
+
*/
|
|
128
|
+
function _getY(Entity id) internal view returns (int32 y) {
|
|
129
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
130
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
131
|
+
|
|
132
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout);
|
|
133
|
+
return (int32(uint32(bytes4(_blob))));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @notice Set y.
|
|
138
|
+
*/
|
|
139
|
+
function setY(Entity id, int32 y) internal {
|
|
140
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
141
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
142
|
+
|
|
143
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @notice Set y.
|
|
148
|
+
*/
|
|
149
|
+
function _setY(Entity id, int32 y) internal {
|
|
150
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
151
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
152
|
+
|
|
153
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @notice Get the full data.
|
|
158
|
+
*/
|
|
159
|
+
function get(Entity id) internal view returns (PositionData memory _table) {
|
|
160
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
161
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
162
|
+
|
|
163
|
+
(bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord(
|
|
164
|
+
_tableId,
|
|
165
|
+
_keyTuple,
|
|
166
|
+
_fieldLayout
|
|
167
|
+
);
|
|
168
|
+
return decode(_staticData, _encodedLengths, _dynamicData);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @notice Get the full data.
|
|
173
|
+
*/
|
|
174
|
+
function _get(Entity id) internal view returns (PositionData memory _table) {
|
|
175
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
176
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
177
|
+
|
|
178
|
+
(bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord(
|
|
179
|
+
_tableId,
|
|
180
|
+
_keyTuple,
|
|
181
|
+
_fieldLayout
|
|
182
|
+
);
|
|
183
|
+
return decode(_staticData, _encodedLengths, _dynamicData);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* @notice Set the full data using individual values.
|
|
188
|
+
*/
|
|
189
|
+
function set(Entity id, int32 x, int32 y) internal {
|
|
190
|
+
bytes memory _staticData = encodeStatic(x, y);
|
|
191
|
+
|
|
192
|
+
EncodedLengths _encodedLengths;
|
|
193
|
+
bytes memory _dynamicData;
|
|
194
|
+
|
|
195
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
196
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
197
|
+
|
|
198
|
+
StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @notice Set the full data using individual values.
|
|
203
|
+
*/
|
|
204
|
+
function _set(Entity id, int32 x, int32 y) internal {
|
|
205
|
+
bytes memory _staticData = encodeStatic(x, y);
|
|
206
|
+
|
|
207
|
+
EncodedLengths _encodedLengths;
|
|
208
|
+
bytes memory _dynamicData;
|
|
209
|
+
|
|
210
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
211
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
212
|
+
|
|
213
|
+
StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @notice Set the full data using the data struct.
|
|
218
|
+
*/
|
|
219
|
+
function set(Entity id, PositionData memory _table) internal {
|
|
220
|
+
bytes memory _staticData = encodeStatic(_table.x, _table.y);
|
|
221
|
+
|
|
222
|
+
EncodedLengths _encodedLengths;
|
|
223
|
+
bytes memory _dynamicData;
|
|
224
|
+
|
|
225
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
226
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
227
|
+
|
|
228
|
+
StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* @notice Set the full data using the data struct.
|
|
233
|
+
*/
|
|
234
|
+
function _set(Entity id, PositionData memory _table) internal {
|
|
235
|
+
bytes memory _staticData = encodeStatic(_table.x, _table.y);
|
|
236
|
+
|
|
237
|
+
EncodedLengths _encodedLengths;
|
|
238
|
+
bytes memory _dynamicData;
|
|
239
|
+
|
|
240
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
241
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
242
|
+
|
|
243
|
+
StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @notice Decode the tightly packed blob of static data using this table's field layout.
|
|
248
|
+
*/
|
|
249
|
+
function decodeStatic(bytes memory _blob) internal pure returns (int32 x, int32 y) {
|
|
250
|
+
x = (int32(uint32(Bytes.getBytes4(_blob, 0))));
|
|
251
|
+
|
|
252
|
+
y = (int32(uint32(Bytes.getBytes4(_blob, 4))));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* @notice Decode the tightly packed blobs using this table's field layout.
|
|
257
|
+
* @param _staticData Tightly packed static fields.
|
|
258
|
+
*
|
|
259
|
+
*
|
|
260
|
+
*/
|
|
261
|
+
function decode(
|
|
262
|
+
bytes memory _staticData,
|
|
263
|
+
EncodedLengths,
|
|
264
|
+
bytes memory
|
|
265
|
+
) internal pure returns (PositionData memory _table) {
|
|
266
|
+
(_table.x, _table.y) = decodeStatic(_staticData);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @notice Delete all data for given keys.
|
|
271
|
+
*/
|
|
272
|
+
function deleteRecord(Entity id) internal {
|
|
273
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
274
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
275
|
+
|
|
276
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* @notice Delete all data for given keys.
|
|
281
|
+
*/
|
|
282
|
+
function _deleteRecord(Entity id) internal {
|
|
283
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
284
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
285
|
+
|
|
286
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @notice Tightly pack static (fixed length) data using this table's schema.
|
|
291
|
+
* @return The static data, encoded into a sequence of bytes.
|
|
292
|
+
*/
|
|
293
|
+
function encodeStatic(int32 x, int32 y) internal pure returns (bytes memory) {
|
|
294
|
+
return abi.encodePacked(x, y);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @notice Encode all of a record's fields.
|
|
299
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
|
300
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
|
301
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
|
302
|
+
*/
|
|
303
|
+
function encode(int32 x, int32 y) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
|
304
|
+
bytes memory _staticData = encodeStatic(x, y);
|
|
305
|
+
|
|
306
|
+
EncodedLengths _encodedLengths;
|
|
307
|
+
bytes memory _dynamicData;
|
|
308
|
+
|
|
309
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
|
314
|
+
*/
|
|
315
|
+
function encodeKeyTuple(Entity id) internal pure returns (bytes32[] memory) {
|
|
316
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
317
|
+
_keyTuple[0] = Entity.unwrap(id);
|
|
318
|
+
|
|
319
|
+
return _keyTuple;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
@@ -3,17 +3,14 @@ pragma solidity >=0.8.24;
|
|
|
3
3
|
|
|
4
4
|
/* Autogenerated file. Do not edit manually. */
|
|
5
5
|
|
|
6
|
+
import { Entity } from "../../Entity.sol";
|
|
7
|
+
import { Direction } from "../common.sol";
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
|
-
* @title
|
|
10
|
+
* @title IMoveSystem
|
|
8
11
|
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
|
|
9
12
|
* @dev This interface is automatically generated from the corresponding system contract. Do not edit manually.
|
|
10
13
|
*/
|
|
11
|
-
interface
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
function app__completeTask(bytes32 id) external;
|
|
15
|
-
|
|
16
|
-
function app__resetTask(bytes32 id) external;
|
|
17
|
-
|
|
18
|
-
function app__deleteTask(bytes32 id) external;
|
|
14
|
+
interface IMoveSystem {
|
|
15
|
+
function app__move(Entity entity, Direction direction) external;
|
|
19
16
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.24;
|
|
3
|
+
|
|
4
|
+
/* Autogenerated file. Do not edit manually. */
|
|
5
|
+
|
|
6
|
+
import { Entity } from "../../Entity.sol";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @title ISpawnSystem
|
|
10
|
+
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
|
|
11
|
+
* @dev This interface is automatically generated from the corresponding system contract. Do not edit manually.
|
|
12
|
+
*/
|
|
13
|
+
interface ISpawnSystem {
|
|
14
|
+
function app__spawn() external returns (Entity entity);
|
|
15
|
+
}
|
|
@@ -4,7 +4,8 @@ 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 {
|
|
7
|
+
import { IMoveSystem } from "./IMoveSystem.sol";
|
|
8
|
+
import { ISpawnSystem } from "./ISpawnSystem.sol";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @title IWorld
|
|
@@ -13,4 +14,4 @@ import { IIncrementSystem } from "./IIncrementSystem.sol";
|
|
|
13
14
|
* that are dynamically registered in the World during deployment.
|
|
14
15
|
* @dev This is an autogenerated file; do not edit manually.
|
|
15
16
|
*/
|
|
16
|
-
interface IWorld is IBaseWorld,
|
|
17
|
+
interface IWorld is IBaseWorld, IMoveSystem, ISpawnSystem {}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.24;
|
|
3
|
+
|
|
4
|
+
import { Entity } from "./Entity.sol";
|
|
5
|
+
import { EntityCount } from "./codegen/tables/EntityCount.sol";
|
|
6
|
+
|
|
7
|
+
function createEntity() returns (Entity entity) {
|
|
8
|
+
uint256 next = EntityCount.get() + 1;
|
|
9
|
+
EntityCount.set(next);
|
|
10
|
+
return Entity.wrap(bytes32(next));
|
|
11
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
|
|
7
|
+
import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
8
|
+
import { Owner } from "../src/codegen/tables/Owner.sol";
|
|
9
|
+
import { Position, PositionData } from "../src/codegen/tables/Position.sol";
|
|
10
|
+
import { Direction } from "../src/codegen/common.sol";
|
|
11
|
+
import { Entity } from "../src/Entity.sol";
|
|
12
|
+
|
|
13
|
+
contract MoveTest is MudTest {
|
|
14
|
+
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
|
|
15
|
+
address deployer = vm.addr(deployerPrivateKey);
|
|
16
|
+
|
|
17
|
+
address alice = vm.addr(uint256(keccak256("alice")));
|
|
18
|
+
address bob = vm.addr(uint256(keccak256("bob")));
|
|
19
|
+
|
|
20
|
+
function testMove() public {
|
|
21
|
+
Entity entity = Entity.wrap(keccak256("entity"));
|
|
22
|
+
vm.prank(deployer);
|
|
23
|
+
Owner.set(entity, alice);
|
|
24
|
+
|
|
25
|
+
PositionData memory position = Position.get(entity);
|
|
26
|
+
assertEq(position.x, 0);
|
|
27
|
+
assertEq(position.y, 0);
|
|
28
|
+
|
|
29
|
+
vm.prank(alice);
|
|
30
|
+
IWorld(worldAddress).app__move(entity, Direction.North);
|
|
31
|
+
position = Position.get(entity);
|
|
32
|
+
assertEq(position.x, 0);
|
|
33
|
+
assertEq(position.y, 1);
|
|
34
|
+
|
|
35
|
+
vm.prank(bob);
|
|
36
|
+
vm.expectRevert("You cannot move this entity.");
|
|
37
|
+
IWorld(worldAddress).app__move(entity, Direction.North);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
|
|
7
|
+
contract WorldTest is MudTest {
|
|
8
|
+
function testWorldDeployed() public {
|
|
9
|
+
uint256 codeSize;
|
|
10
|
+
address addr = worldAddress;
|
|
11
|
+
assembly {
|
|
12
|
+
codeSize := extcodesize(addr)
|
|
13
|
+
}
|
|
14
|
+
assertTrue(codeSize > 0);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { createContext, ReactNode, useContext } from "react";
|
|
2
|
-
import { SetupResult } from "./mud/setup";
|
|
3
|
-
|
|
4
|
-
const MUDContext = createContext<SetupResult | null>(null);
|
|
5
|
-
|
|
6
|
-
type Props = {
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
value: SetupResult;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const MUDProvider = ({ children, value }: Props) => {
|
|
12
|
-
const currentValue = useContext(MUDContext);
|
|
13
|
-
if (currentValue) throw new Error("MUDProvider can only be used once");
|
|
14
|
-
return <MUDContext.Provider value={value}>{children}</MUDContext.Provider>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const useMUD = () => {
|
|
18
|
-
const value = useContext(MUDContext);
|
|
19
|
-
if (!value) throw new Error("Must be used within a MUDProvider");
|
|
20
|
-
return value;
|
|
21
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Create the system calls that the client can use to ask
|
|
3
|
-
* for changes in the World state (using the System contracts).
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { Hex } from "viem";
|
|
7
|
-
import { SetupNetworkResult } from "./setupNetwork";
|
|
8
|
-
|
|
9
|
-
export type SystemCalls = ReturnType<typeof createSystemCalls>;
|
|
10
|
-
|
|
11
|
-
export function createSystemCalls(
|
|
12
|
-
/*
|
|
13
|
-
* The parameter list informs TypeScript that:
|
|
14
|
-
*
|
|
15
|
-
* - The first parameter is expected to be a
|
|
16
|
-
* SetupNetworkResult, as defined in setupNetwork.ts
|
|
17
|
-
*
|
|
18
|
-
* Out of this parameter, we only care about two fields:
|
|
19
|
-
* - worldContract (which comes from getContract, see
|
|
20
|
-
* https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L63-L69).
|
|
21
|
-
*
|
|
22
|
-
* - waitForTransaction (which comes from syncToRecs, see
|
|
23
|
-
* https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
24
|
-
*
|
|
25
|
-
* - From the second parameter, which is a ClientComponent,
|
|
26
|
-
* we only care about Counter. This parameter comes to use
|
|
27
|
-
* through createClientComponents.ts, but it originates in
|
|
28
|
-
* syncToRecs
|
|
29
|
-
* (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
30
|
-
*/
|
|
31
|
-
{ tables, useStore, worldContract, waitForTransaction }: SetupNetworkResult,
|
|
32
|
-
) {
|
|
33
|
-
const addTask = async (label: string) => {
|
|
34
|
-
const tx = await worldContract.write.app__addTask([label]);
|
|
35
|
-
await waitForTransaction(tx);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const toggleTask = async (id: Hex) => {
|
|
39
|
-
const isComplete = (useStore.getState().getValue(tables.Tasks, { id })?.completedAt ?? 0n) > 0n;
|
|
40
|
-
const tx = isComplete
|
|
41
|
-
? await worldContract.write.app__resetTask([id])
|
|
42
|
-
: await worldContract.write.app__completeTask([id]);
|
|
43
|
-
await waitForTransaction(tx);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const deleteTask = async (id: Hex) => {
|
|
47
|
-
const tx = await worldContract.write.app__deleteTask([id]);
|
|
48
|
-
await waitForTransaction(tx);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
addTask,
|
|
53
|
-
toggleTask,
|
|
54
|
-
deleteTask,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Network specific configuration for the client.
|
|
3
|
-
* By default connect to the anvil test network.
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
* By default the template just creates a temporary wallet
|
|
9
|
-
* (called a burner wallet).
|
|
10
|
-
*/
|
|
11
|
-
import { getBurnerPrivateKey } from "@latticexyz/common";
|
|
12
|
-
|
|
13
|
-
/*
|
|
14
|
-
* Import the addresses of the World, possibly on multiple chains,
|
|
15
|
-
* from packages/contracts/worlds.json. When the contracts package
|
|
16
|
-
* deploys a new `World`, it updates this file.
|
|
17
|
-
*/
|
|
18
|
-
import worlds from "contracts/worlds.json";
|
|
19
|
-
|
|
20
|
-
/*
|
|
21
|
-
* The supported chains.
|
|
22
|
-
*/
|
|
23
|
-
import { supportedChains } from "./supportedChains";
|
|
24
|
-
|
|
25
|
-
export async function getNetworkConfig() {
|
|
26
|
-
const params = new URLSearchParams(window.location.search);
|
|
27
|
-
|
|
28
|
-
/*
|
|
29
|
-
* The chain ID is the first item available from this list:
|
|
30
|
-
* 1. chainId query parameter
|
|
31
|
-
* 2. chainid query parameter
|
|
32
|
-
* 3. The VITE_CHAIN_ID environment variable set when the
|
|
33
|
-
* vite dev server was started or client was built
|
|
34
|
-
* 4. The default, 31337 (anvil)
|
|
35
|
-
*/
|
|
36
|
-
const chainId = Number(params.get("chainId") || params.get("chainid") || import.meta.env.VITE_CHAIN_ID || 31337);
|
|
37
|
-
|
|
38
|
-
/*
|
|
39
|
-
* Find the chain (unless it isn't in the list of supported chains).
|
|
40
|
-
*/
|
|
41
|
-
const chainIndex = supportedChains.findIndex((c) => c.id === chainId);
|
|
42
|
-
const chain = supportedChains[chainIndex];
|
|
43
|
-
if (!chain) {
|
|
44
|
-
throw new Error(`Chain ${chainId} not found`);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/*
|
|
48
|
-
* Get the address of the World. If you want to use a
|
|
49
|
-
* different address than the one in worlds.json,
|
|
50
|
-
* provide it as worldAddress in the query string.
|
|
51
|
-
*/
|
|
52
|
-
const world = worlds[chain.id.toString()];
|
|
53
|
-
const worldAddress = params.get("worldAddress") || world?.address;
|
|
54
|
-
if (!worldAddress) {
|
|
55
|
-
throw new Error(`No world address found for chain ${chainId}. Did you run \`mud deploy\`?`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/*
|
|
59
|
-
* MUD clients use events to synchronize the database, meaning
|
|
60
|
-
* they need to look as far back as when the World was started.
|
|
61
|
-
* The block number for the World start can be specified either
|
|
62
|
-
* on the URL (as initialBlockNumber) or in the worlds.json
|
|
63
|
-
* file. If neither has it, it starts at the first block, zero.
|
|
64
|
-
*/
|
|
65
|
-
const initialBlockNumber = params.has("initialBlockNumber")
|
|
66
|
-
? Number(params.get("initialBlockNumber"))
|
|
67
|
-
: world?.blockNumber ?? 0n;
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
privateKey: getBurnerPrivateKey(),
|
|
71
|
-
chainId,
|
|
72
|
-
chain,
|
|
73
|
-
worldAddress,
|
|
74
|
-
initialBlockNumber,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This file sets up all the definitions required for a MUD client.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { createSystemCalls } from "./createSystemCalls";
|
|
6
|
-
import { setupNetwork } from "./setupNetwork";
|
|
7
|
-
|
|
8
|
-
export type SetupResult = Awaited<ReturnType<typeof setup>>;
|
|
9
|
-
|
|
10
|
-
export async function setup() {
|
|
11
|
-
const network = await setupNetwork();
|
|
12
|
-
const systemCalls = createSystemCalls(network);
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
network,
|
|
16
|
-
systemCalls,
|
|
17
|
-
};
|
|
18
|
-
}
|