create-mud 2.0.0-next.11 → 2.0.0-next.12
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/templates/phaser/packages/client/src/mud/createSystemCalls.ts +7 -5
- package/dist/templates/phaser/packages/client/src/mud/setupNetwork.ts +1 -1
- package/dist/templates/phaser/packages/contracts/package.json +2 -2
- package/dist/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +0 -54
- package/dist/templates/phaser/packages/contracts/test/CounterTest.t.sol +3 -10
- package/dist/templates/react/packages/client/src/mud/createSystemCalls.ts +7 -5
- package/dist/templates/react/packages/client/src/mud/setupNetwork.ts +1 -1
- package/dist/templates/react/packages/contracts/package.json +2 -2
- package/dist/templates/react/packages/contracts/src/codegen/tables/Counter.sol +0 -54
- package/dist/templates/react/packages/contracts/test/CounterTest.t.sol +3 -10
- package/dist/templates/threejs/packages/client/src/mud/createSystemCalls.ts +7 -5
- package/dist/templates/threejs/packages/client/src/mud/setupNetwork.ts +1 -1
- package/dist/templates/threejs/packages/contracts/package.json +2 -2
- package/dist/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +0 -125
- package/dist/templates/vanilla/packages/client/src/mud/createSystemCalls.ts +7 -6
- package/dist/templates/vanilla/packages/client/src/mud/setupNetwork.ts +1 -1
- package/dist/templates/vanilla/packages/contracts/package.json +2 -2
- package/dist/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +0 -54
- package/dist/templates/vanilla/packages/contracts/test/CounterTest.t.sol +3 -10
- package/package.json +1 -1
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.
|
|
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}}});
|
|
@@ -23,16 +23,18 @@ export function createSystemCalls(
|
|
|
23
23
|
* - The first parameter is expected to be a
|
|
24
24
|
* SetupNetworkResult, as defined in setupNetwork.ts
|
|
25
25
|
*
|
|
26
|
-
*
|
|
26
|
+
* Out of this parameter, we only care about two fields:
|
|
27
27
|
* - worldContract (which comes from getContract, see
|
|
28
|
-
* https://github.com/latticexyz/mud/blob/
|
|
28
|
+
* https://github.com/latticexyz/mud/blob/main/templates/phaser/packages/client/src/mud/setupNetwork.ts#L61-L67).
|
|
29
|
+
*
|
|
29
30
|
* - waitForTransaction (which comes from syncToRecs, see
|
|
30
|
-
* https://github.com/latticexyz/mud/blob/
|
|
31
|
+
* https://github.com/latticexyz/mud/blob/main/templates/phaser/packages/client/src/mud/setupNetwork.ts#L75-L81).
|
|
31
32
|
*
|
|
32
33
|
* - From the second parameter, which is a ClientComponent,
|
|
33
34
|
* we only care about Counter. This parameter comes to use
|
|
34
35
|
* through createClientComponents.ts, but it originates in
|
|
35
|
-
* syncToRecs
|
|
36
|
+
* syncToRecs
|
|
37
|
+
* (https://github.com/latticexyz/mud/blob/main/templates/phaser/packages/client/src/mud/setupNetwork.ts#L75-L81).
|
|
36
38
|
*/
|
|
37
39
|
{ worldContract, waitForTransaction }: SetupNetworkResult,
|
|
38
40
|
{ Counter }: ClientComponents
|
|
@@ -40,7 +42,7 @@ export function createSystemCalls(
|
|
|
40
42
|
const increment = async () => {
|
|
41
43
|
/*
|
|
42
44
|
* Because IncrementSystem
|
|
43
|
-
* (https://mud.dev/
|
|
45
|
+
* (https://mud.dev/templates/typescript/contracts#incrementsystemsol)
|
|
44
46
|
* is in the root namespace, `.increment` can be called directly
|
|
45
47
|
* on the World contract.
|
|
46
48
|
*/
|
|
@@ -17,7 +17,7 @@ import { Subject, share } from "rxjs";
|
|
|
17
17
|
* our tables and other config options. We use this to generate
|
|
18
18
|
* things like RECS components and get back strong types for them.
|
|
19
19
|
*
|
|
20
|
-
* See https://mud.dev/
|
|
20
|
+
* See https://mud.dev/templates/typescript/contracts#mudconfigts
|
|
21
21
|
* for the source of this information.
|
|
22
22
|
*/
|
|
23
23
|
import mudConfig from "contracts/mud.config";
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
|
|
8
|
-
"build:abi": "forge
|
|
9
|
-
"build:abi-ts": "mud abi-ts
|
|
8
|
+
"build:abi": "forge build",
|
|
9
|
+
"build:abi-ts": "mud abi-ts",
|
|
10
10
|
"build:mud": "rimraf src/codegen && mud tablegen && mud worldgen",
|
|
11
11
|
"deploy:local": "pnpm run build && mud deploy",
|
|
12
12
|
"deploy:testnet": "pnpm run build && mud deploy --profile=lattice-testnet",
|
|
@@ -90,13 +90,6 @@ library Counter {
|
|
|
90
90
|
StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
/**
|
|
94
|
-
* @notice Register the table with its config (using the specified store).
|
|
95
|
-
*/
|
|
96
|
-
function register(IStore _store) internal {
|
|
97
|
-
_store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
|
|
98
|
-
}
|
|
99
|
-
|
|
100
93
|
/**
|
|
101
94
|
* @notice Get value.
|
|
102
95
|
*/
|
|
@@ -117,16 +110,6 @@ library Counter {
|
|
|
117
110
|
return (uint32(bytes4(_blob)));
|
|
118
111
|
}
|
|
119
112
|
|
|
120
|
-
/**
|
|
121
|
-
* @notice Get value (using the specified store).
|
|
122
|
-
*/
|
|
123
|
-
function getValue(IStore _store) internal view returns (uint32 value) {
|
|
124
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
125
|
-
|
|
126
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
127
|
-
return (uint32(bytes4(_blob)));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
113
|
/**
|
|
131
114
|
* @notice Get value.
|
|
132
115
|
*/
|
|
@@ -147,16 +130,6 @@ library Counter {
|
|
|
147
130
|
return (uint32(bytes4(_blob)));
|
|
148
131
|
}
|
|
149
132
|
|
|
150
|
-
/**
|
|
151
|
-
* @notice Get value (using the specified store).
|
|
152
|
-
*/
|
|
153
|
-
function get(IStore _store) internal view returns (uint32 value) {
|
|
154
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
155
|
-
|
|
156
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
157
|
-
return (uint32(bytes4(_blob)));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
133
|
/**
|
|
161
134
|
* @notice Set value.
|
|
162
135
|
*/
|
|
@@ -175,15 +148,6 @@ library Counter {
|
|
|
175
148
|
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
176
149
|
}
|
|
177
150
|
|
|
178
|
-
/**
|
|
179
|
-
* @notice Set value (using the specified store).
|
|
180
|
-
*/
|
|
181
|
-
function setValue(IStore _store, uint32 value) internal {
|
|
182
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
183
|
-
|
|
184
|
-
_store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
151
|
/**
|
|
188
152
|
* @notice Set value.
|
|
189
153
|
*/
|
|
@@ -202,15 +166,6 @@ library Counter {
|
|
|
202
166
|
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
203
167
|
}
|
|
204
168
|
|
|
205
|
-
/**
|
|
206
|
-
* @notice Set value (using the specified store).
|
|
207
|
-
*/
|
|
208
|
-
function set(IStore _store, uint32 value) internal {
|
|
209
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
210
|
-
|
|
211
|
-
_store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
169
|
/**
|
|
215
170
|
* @notice Delete all data for given keys.
|
|
216
171
|
*/
|
|
@@ -229,15 +184,6 @@ library Counter {
|
|
|
229
184
|
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
|
230
185
|
}
|
|
231
186
|
|
|
232
|
-
/**
|
|
233
|
-
* @notice Delete all data for given keys (using the specified store).
|
|
234
|
-
*/
|
|
235
|
-
function deleteRecord(IStore _store) internal {
|
|
236
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
237
|
-
|
|
238
|
-
_store.deleteRecord(_tableId, _keyTuple);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
187
|
/**
|
|
242
188
|
* @notice Tightly pack static (fixed length) data using this table's schema.
|
|
243
189
|
* @return The static data, encoded into a sequence of bytes.
|
|
@@ -9,13 +9,6 @@ import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
|
9
9
|
import { Counter, CounterTableId } from "../src/codegen/index.sol";
|
|
10
10
|
|
|
11
11
|
contract CounterTest is MudTest {
|
|
12
|
-
IWorld public world;
|
|
13
|
-
|
|
14
|
-
function setUp() public override {
|
|
15
|
-
super.setUp();
|
|
16
|
-
world = IWorld(worldAddress);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
function testWorldExists() public {
|
|
20
13
|
uint256 codeSize;
|
|
21
14
|
address addr = worldAddress;
|
|
@@ -27,12 +20,12 @@ contract CounterTest is MudTest {
|
|
|
27
20
|
|
|
28
21
|
function testCounter() public {
|
|
29
22
|
// Expect the counter to be 1 because it was incremented in the PostDeploy script.
|
|
30
|
-
uint32 counter = Counter.get(
|
|
23
|
+
uint32 counter = Counter.get();
|
|
31
24
|
assertEq(counter, 1);
|
|
32
25
|
|
|
33
26
|
// Expect the counter to be 2 after calling increment.
|
|
34
|
-
|
|
35
|
-
counter = Counter.get(
|
|
27
|
+
IWorld(worldAddress).increment();
|
|
28
|
+
counter = Counter.get();
|
|
36
29
|
assertEq(counter, 2);
|
|
37
30
|
}
|
|
38
31
|
}
|
|
@@ -17,16 +17,18 @@ export function createSystemCalls(
|
|
|
17
17
|
* - The first parameter is expected to be a
|
|
18
18
|
* SetupNetworkResult, as defined in setupNetwork.ts
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* Out of this parameter, we only care about two fields:
|
|
21
21
|
* - worldContract (which comes from getContract, see
|
|
22
|
-
* https://github.com/latticexyz/mud/blob/
|
|
22
|
+
* https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L63-L69).
|
|
23
|
+
*
|
|
23
24
|
* - waitForTransaction (which comes from syncToRecs, see
|
|
24
|
-
* https://github.com/latticexyz/mud/blob/
|
|
25
|
+
* https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
25
26
|
*
|
|
26
27
|
* - From the second parameter, which is a ClientComponent,
|
|
27
28
|
* we only care about Counter. This parameter comes to use
|
|
28
29
|
* through createClientComponents.ts, but it originates in
|
|
29
|
-
* syncToRecs
|
|
30
|
+
* syncToRecs
|
|
31
|
+
* (https://github.com/latticexyz/mud/blob/main/templates/react/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
30
32
|
*/
|
|
31
33
|
{ worldContract, waitForTransaction }: SetupNetworkResult,
|
|
32
34
|
{ Counter }: ClientComponents
|
|
@@ -34,7 +36,7 @@ export function createSystemCalls(
|
|
|
34
36
|
const increment = async () => {
|
|
35
37
|
/*
|
|
36
38
|
* Because IncrementSystem
|
|
37
|
-
* (https://mud.dev/
|
|
39
|
+
* (https://mud.dev/templates/typescript/contracts#incrementsystemsol)
|
|
38
40
|
* is in the root namespace, `.increment` can be called directly
|
|
39
41
|
* on the World contract.
|
|
40
42
|
*/
|
|
@@ -19,7 +19,7 @@ import { Subject, share } from "rxjs";
|
|
|
19
19
|
* our tables and other config options. We use this to generate
|
|
20
20
|
* things like RECS components and get back strong types for them.
|
|
21
21
|
*
|
|
22
|
-
* See https://mud.dev/
|
|
22
|
+
* See https://mud.dev/templates/typescript/contracts#mudconfigts
|
|
23
23
|
* for the source of this information.
|
|
24
24
|
*/
|
|
25
25
|
import mudConfig from "contracts/mud.config";
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
|
|
8
|
-
"build:abi": "forge
|
|
9
|
-
"build:abi-ts": "mud abi-ts
|
|
8
|
+
"build:abi": "forge build",
|
|
9
|
+
"build:abi-ts": "mud abi-ts",
|
|
10
10
|
"build:mud": "rimraf src/codegen && mud tablegen && mud worldgen",
|
|
11
11
|
"deploy:local": "pnpm run build && mud deploy",
|
|
12
12
|
"deploy:testnet": "pnpm run build && mud deploy --profile=lattice-testnet",
|
|
@@ -90,13 +90,6 @@ library Counter {
|
|
|
90
90
|
StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
/**
|
|
94
|
-
* @notice Register the table with its config (using the specified store).
|
|
95
|
-
*/
|
|
96
|
-
function register(IStore _store) internal {
|
|
97
|
-
_store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
|
|
98
|
-
}
|
|
99
|
-
|
|
100
93
|
/**
|
|
101
94
|
* @notice Get value.
|
|
102
95
|
*/
|
|
@@ -117,16 +110,6 @@ library Counter {
|
|
|
117
110
|
return (uint32(bytes4(_blob)));
|
|
118
111
|
}
|
|
119
112
|
|
|
120
|
-
/**
|
|
121
|
-
* @notice Get value (using the specified store).
|
|
122
|
-
*/
|
|
123
|
-
function getValue(IStore _store) internal view returns (uint32 value) {
|
|
124
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
125
|
-
|
|
126
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
127
|
-
return (uint32(bytes4(_blob)));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
113
|
/**
|
|
131
114
|
* @notice Get value.
|
|
132
115
|
*/
|
|
@@ -147,16 +130,6 @@ library Counter {
|
|
|
147
130
|
return (uint32(bytes4(_blob)));
|
|
148
131
|
}
|
|
149
132
|
|
|
150
|
-
/**
|
|
151
|
-
* @notice Get value (using the specified store).
|
|
152
|
-
*/
|
|
153
|
-
function get(IStore _store) internal view returns (uint32 value) {
|
|
154
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
155
|
-
|
|
156
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
157
|
-
return (uint32(bytes4(_blob)));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
133
|
/**
|
|
161
134
|
* @notice Set value.
|
|
162
135
|
*/
|
|
@@ -175,15 +148,6 @@ library Counter {
|
|
|
175
148
|
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
176
149
|
}
|
|
177
150
|
|
|
178
|
-
/**
|
|
179
|
-
* @notice Set value (using the specified store).
|
|
180
|
-
*/
|
|
181
|
-
function setValue(IStore _store, uint32 value) internal {
|
|
182
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
183
|
-
|
|
184
|
-
_store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
151
|
/**
|
|
188
152
|
* @notice Set value.
|
|
189
153
|
*/
|
|
@@ -202,15 +166,6 @@ library Counter {
|
|
|
202
166
|
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
203
167
|
}
|
|
204
168
|
|
|
205
|
-
/**
|
|
206
|
-
* @notice Set value (using the specified store).
|
|
207
|
-
*/
|
|
208
|
-
function set(IStore _store, uint32 value) internal {
|
|
209
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
210
|
-
|
|
211
|
-
_store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
169
|
/**
|
|
215
170
|
* @notice Delete all data for given keys.
|
|
216
171
|
*/
|
|
@@ -229,15 +184,6 @@ library Counter {
|
|
|
229
184
|
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
|
230
185
|
}
|
|
231
186
|
|
|
232
|
-
/**
|
|
233
|
-
* @notice Delete all data for given keys (using the specified store).
|
|
234
|
-
*/
|
|
235
|
-
function deleteRecord(IStore _store) internal {
|
|
236
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
237
|
-
|
|
238
|
-
_store.deleteRecord(_tableId, _keyTuple);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
187
|
/**
|
|
242
188
|
* @notice Tightly pack static (fixed length) data using this table's schema.
|
|
243
189
|
* @return The static data, encoded into a sequence of bytes.
|
|
@@ -9,13 +9,6 @@ import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
|
9
9
|
import { Counter, CounterTableId } from "../src/codegen/index.sol";
|
|
10
10
|
|
|
11
11
|
contract CounterTest is MudTest {
|
|
12
|
-
IWorld public world;
|
|
13
|
-
|
|
14
|
-
function setUp() public override {
|
|
15
|
-
super.setUp();
|
|
16
|
-
world = IWorld(worldAddress);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
function testWorldExists() public {
|
|
20
13
|
uint256 codeSize;
|
|
21
14
|
address addr = worldAddress;
|
|
@@ -27,12 +20,12 @@ contract CounterTest is MudTest {
|
|
|
27
20
|
|
|
28
21
|
function testCounter() public {
|
|
29
22
|
// Expect the counter to be 1 because it was incremented in the PostDeploy script.
|
|
30
|
-
uint32 counter = Counter.get(
|
|
23
|
+
uint32 counter = Counter.get();
|
|
31
24
|
assertEq(counter, 1);
|
|
32
25
|
|
|
33
26
|
// Expect the counter to be 2 after calling increment.
|
|
34
|
-
|
|
35
|
-
counter = Counter.get(
|
|
27
|
+
IWorld(worldAddress).increment();
|
|
28
|
+
counter = Counter.get();
|
|
36
29
|
assertEq(counter, 2);
|
|
37
30
|
}
|
|
38
31
|
}
|
|
@@ -16,16 +16,18 @@ export function createSystemCalls(
|
|
|
16
16
|
* - The first parameter is expected to be a
|
|
17
17
|
* SetupNetworkResult, as defined in setupNetwork.ts
|
|
18
18
|
*
|
|
19
|
-
*
|
|
19
|
+
* Out of this parameter, we only care about two fields:
|
|
20
20
|
* - worldContract (which comes from getContract, see
|
|
21
|
-
* https://github.com/latticexyz/mud/blob/
|
|
21
|
+
* https://github.com/latticexyz/mud/blob/main/templates/threejs/packages/client/src/mud/setupNetwork.ts#L61-L67).
|
|
22
|
+
*
|
|
22
23
|
* - waitForTransaction (which comes from syncToRecs, see
|
|
23
|
-
* https://github.com/latticexyz/mud/blob/
|
|
24
|
+
* https://github.com/latticexyz/mud/blob/main/templates/threejs/packages/client/src/mud/setupNetwork.ts#L75-L81).
|
|
24
25
|
*
|
|
25
26
|
* - From the second parameter, which is a ClientComponent,
|
|
26
|
-
* we only care about
|
|
27
|
+
* we only care about Counter. This parameter comes to use
|
|
27
28
|
* through createClientComponents.ts, but it originates in
|
|
28
|
-
* syncToRecs
|
|
29
|
+
* syncToRecs
|
|
30
|
+
* (https://github.com/latticexyz/mud/blob/main/templates/threejs/packages/client/src/mud/setupNetwork.ts#L75-L81).
|
|
29
31
|
*/
|
|
30
32
|
{ worldContract, waitForTransaction, playerEntity }: SetupNetworkResult,
|
|
31
33
|
{ Position }: ClientComponents
|
|
@@ -17,7 +17,7 @@ import { Subject, share } from "rxjs";
|
|
|
17
17
|
* our tables and other config options. We use this to generate
|
|
18
18
|
* things like RECS components and get back strong types for them.
|
|
19
19
|
*
|
|
20
|
-
* See https://github.com/latticexyz/mud/blob/
|
|
20
|
+
* See https://github.com/latticexyz/mud/blob/main/templates/threejs/packages/contracts/mud.config.ts
|
|
21
21
|
* for the source of this information.
|
|
22
22
|
*/
|
|
23
23
|
import mudConfig from "contracts/mud.config";
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
|
|
8
|
-
"build:abi": "forge
|
|
9
|
-
"build:abi-ts": "mud abi-ts
|
|
8
|
+
"build:abi": "forge build",
|
|
9
|
+
"build:abi-ts": "mud abi-ts",
|
|
10
10
|
"build:mud": "rimraf src/codegen && mud tablegen && mud worldgen",
|
|
11
11
|
"deploy:local": "pnpm run build && mud deploy",
|
|
12
12
|
"deploy:testnet": "pnpm run build && mud deploy --profile=lattice-testnet",
|
|
@@ -102,13 +102,6 @@ library Position {
|
|
|
102
102
|
StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
/**
|
|
106
|
-
* @notice Register the table with its config (using the specified store).
|
|
107
|
-
*/
|
|
108
|
-
function register(IStore _store) internal {
|
|
109
|
-
_store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
|
|
110
|
-
}
|
|
111
|
-
|
|
112
105
|
/**
|
|
113
106
|
* @notice Get x.
|
|
114
107
|
*/
|
|
@@ -131,17 +124,6 @@ library Position {
|
|
|
131
124
|
return (int32(uint32(bytes4(_blob))));
|
|
132
125
|
}
|
|
133
126
|
|
|
134
|
-
/**
|
|
135
|
-
* @notice Get x (using the specified store).
|
|
136
|
-
*/
|
|
137
|
-
function getX(IStore _store, bytes32 key) internal view returns (int32 x) {
|
|
138
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
139
|
-
_keyTuple[0] = key;
|
|
140
|
-
|
|
141
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
142
|
-
return (int32(uint32(bytes4(_blob))));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
127
|
/**
|
|
146
128
|
* @notice Set x.
|
|
147
129
|
*/
|
|
@@ -162,16 +144,6 @@ library Position {
|
|
|
162
144
|
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout);
|
|
163
145
|
}
|
|
164
146
|
|
|
165
|
-
/**
|
|
166
|
-
* @notice Set x (using the specified store).
|
|
167
|
-
*/
|
|
168
|
-
function setX(IStore _store, bytes32 key, int32 x) internal {
|
|
169
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
170
|
-
_keyTuple[0] = key;
|
|
171
|
-
|
|
172
|
-
_store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
147
|
/**
|
|
176
148
|
* @notice Get y.
|
|
177
149
|
*/
|
|
@@ -194,17 +166,6 @@ library Position {
|
|
|
194
166
|
return (int32(uint32(bytes4(_blob))));
|
|
195
167
|
}
|
|
196
168
|
|
|
197
|
-
/**
|
|
198
|
-
* @notice Get y (using the specified store).
|
|
199
|
-
*/
|
|
200
|
-
function getY(IStore _store, bytes32 key) internal view returns (int32 y) {
|
|
201
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
202
|
-
_keyTuple[0] = key;
|
|
203
|
-
|
|
204
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout);
|
|
205
|
-
return (int32(uint32(bytes4(_blob))));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
169
|
/**
|
|
209
170
|
* @notice Set y.
|
|
210
171
|
*/
|
|
@@ -225,16 +186,6 @@ library Position {
|
|
|
225
186
|
StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout);
|
|
226
187
|
}
|
|
227
188
|
|
|
228
|
-
/**
|
|
229
|
-
* @notice Set y (using the specified store).
|
|
230
|
-
*/
|
|
231
|
-
function setY(IStore _store, bytes32 key, int32 y) internal {
|
|
232
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
233
|
-
_keyTuple[0] = key;
|
|
234
|
-
|
|
235
|
-
_store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
189
|
/**
|
|
239
190
|
* @notice Get z.
|
|
240
191
|
*/
|
|
@@ -257,17 +208,6 @@ library Position {
|
|
|
257
208
|
return (int32(uint32(bytes4(_blob))));
|
|
258
209
|
}
|
|
259
210
|
|
|
260
|
-
/**
|
|
261
|
-
* @notice Get z (using the specified store).
|
|
262
|
-
*/
|
|
263
|
-
function getZ(IStore _store, bytes32 key) internal view returns (int32 z) {
|
|
264
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
265
|
-
_keyTuple[0] = key;
|
|
266
|
-
|
|
267
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout);
|
|
268
|
-
return (int32(uint32(bytes4(_blob))));
|
|
269
|
-
}
|
|
270
|
-
|
|
271
211
|
/**
|
|
272
212
|
* @notice Set z.
|
|
273
213
|
*/
|
|
@@ -288,16 +228,6 @@ library Position {
|
|
|
288
228
|
StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((z)), _fieldLayout);
|
|
289
229
|
}
|
|
290
230
|
|
|
291
|
-
/**
|
|
292
|
-
* @notice Set z (using the specified store).
|
|
293
|
-
*/
|
|
294
|
-
function setZ(IStore _store, bytes32 key, int32 z) internal {
|
|
295
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
296
|
-
_keyTuple[0] = key;
|
|
297
|
-
|
|
298
|
-
_store.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((z)), _fieldLayout);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
231
|
/**
|
|
302
232
|
* @notice Get the full data.
|
|
303
233
|
*/
|
|
@@ -328,21 +258,6 @@ library Position {
|
|
|
328
258
|
return decode(_staticData, _encodedLengths, _dynamicData);
|
|
329
259
|
}
|
|
330
260
|
|
|
331
|
-
/**
|
|
332
|
-
* @notice Get the full data (using the specified store).
|
|
333
|
-
*/
|
|
334
|
-
function get(IStore _store, bytes32 key) internal view returns (PositionData memory _table) {
|
|
335
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
336
|
-
_keyTuple[0] = key;
|
|
337
|
-
|
|
338
|
-
(bytes memory _staticData, PackedCounter _encodedLengths, bytes memory _dynamicData) = _store.getRecord(
|
|
339
|
-
_tableId,
|
|
340
|
-
_keyTuple,
|
|
341
|
-
_fieldLayout
|
|
342
|
-
);
|
|
343
|
-
return decode(_staticData, _encodedLengths, _dynamicData);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
261
|
/**
|
|
347
262
|
* @notice Set the full data using individual values.
|
|
348
263
|
*/
|
|
@@ -373,21 +288,6 @@ library Position {
|
|
|
373
288
|
StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
|
|
374
289
|
}
|
|
375
290
|
|
|
376
|
-
/**
|
|
377
|
-
* @notice Set the full data using individual values (using the specified store).
|
|
378
|
-
*/
|
|
379
|
-
function set(IStore _store, bytes32 key, int32 x, int32 y, int32 z) internal {
|
|
380
|
-
bytes memory _staticData = encodeStatic(x, y, z);
|
|
381
|
-
|
|
382
|
-
PackedCounter _encodedLengths;
|
|
383
|
-
bytes memory _dynamicData;
|
|
384
|
-
|
|
385
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
386
|
-
_keyTuple[0] = key;
|
|
387
|
-
|
|
388
|
-
_store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
291
|
/**
|
|
392
292
|
* @notice Set the full data using the data struct.
|
|
393
293
|
*/
|
|
@@ -418,21 +318,6 @@ library Position {
|
|
|
418
318
|
StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
|
|
419
319
|
}
|
|
420
320
|
|
|
421
|
-
/**
|
|
422
|
-
* @notice Set the full data using the data struct (using the specified store).
|
|
423
|
-
*/
|
|
424
|
-
function set(IStore _store, bytes32 key, PositionData memory _table) internal {
|
|
425
|
-
bytes memory _staticData = encodeStatic(_table.x, _table.y, _table.z);
|
|
426
|
-
|
|
427
|
-
PackedCounter _encodedLengths;
|
|
428
|
-
bytes memory _dynamicData;
|
|
429
|
-
|
|
430
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
431
|
-
_keyTuple[0] = key;
|
|
432
|
-
|
|
433
|
-
_store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
|
|
434
|
-
}
|
|
435
|
-
|
|
436
321
|
/**
|
|
437
322
|
* @notice Decode the tightly packed blob of static data using this table's field layout.
|
|
438
323
|
*/
|
|
@@ -478,16 +363,6 @@ library Position {
|
|
|
478
363
|
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
|
479
364
|
}
|
|
480
365
|
|
|
481
|
-
/**
|
|
482
|
-
* @notice Delete all data for given keys (using the specified store).
|
|
483
|
-
*/
|
|
484
|
-
function deleteRecord(IStore _store, bytes32 key) internal {
|
|
485
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
486
|
-
_keyTuple[0] = key;
|
|
487
|
-
|
|
488
|
-
_store.deleteRecord(_tableId, _keyTuple);
|
|
489
|
-
}
|
|
490
|
-
|
|
491
366
|
/**
|
|
492
367
|
* @notice Tightly pack static (fixed length) data using this table's schema.
|
|
493
368
|
* @return The static data, encoded into a sequence of bytes.
|
|
@@ -17,17 +17,18 @@ export function createSystemCalls(
|
|
|
17
17
|
* - The first parameter is expected to be a
|
|
18
18
|
* SetupNetworkResult, as defined in setupNetwork.ts
|
|
19
19
|
*
|
|
20
|
-
*
|
|
20
|
+
* Out of this parameter, we only care about two fields:
|
|
21
21
|
* - worldContract (which comes from getContract, see
|
|
22
|
-
* https://github.com/latticexyz/mud/blob/
|
|
22
|
+
* https://github.com/latticexyz/mud/blob/main/templates/vanilla/packages/client/src/mud/setupNetwork.ts#L63-L69).
|
|
23
|
+
*
|
|
23
24
|
* - waitForTransaction (which comes from syncToRecs, see
|
|
24
|
-
* https://github.com/latticexyz/mud/blob/
|
|
25
|
+
* https://github.com/latticexyz/mud/blob/main/templates/vanilla/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
25
26
|
*
|
|
26
27
|
* - From the second parameter, which is a ClientComponent,
|
|
27
28
|
* we only care about Counter. This parameter comes to use
|
|
28
29
|
* through createClientComponents.ts, but it originates in
|
|
29
|
-
* syncToRecs
|
|
30
|
-
(https://github.com/latticexyz/mud/blob/
|
|
30
|
+
* syncToRecs
|
|
31
|
+
* (https://github.com/latticexyz/mud/blob/main/templates/vanilla/packages/client/src/mud/setupNetwork.ts#L77-L83).
|
|
31
32
|
*/
|
|
32
33
|
{ worldContract, waitForTransaction }: SetupNetworkResult,
|
|
33
34
|
{ Counter }: ClientComponents
|
|
@@ -35,7 +36,7 @@ export function createSystemCalls(
|
|
|
35
36
|
const increment = async () => {
|
|
36
37
|
/*
|
|
37
38
|
* Because IncrementSystem
|
|
38
|
-
* (https://mud.dev/
|
|
39
|
+
* (https://mud.dev/templates/typescript/contracts#incrementsystemsol)
|
|
39
40
|
* is in the root namespace, `.increment` can be called directly
|
|
40
41
|
* on the World contract.
|
|
41
42
|
*/
|
|
@@ -19,7 +19,7 @@ import { Subject, share } from "rxjs";
|
|
|
19
19
|
* our tables and other config options. We use this to generate
|
|
20
20
|
* things like RECS components and get back strong types for them.
|
|
21
21
|
*
|
|
22
|
-
* See https://mud.dev/
|
|
22
|
+
* See https://mud.dev/templates/typescript/contracts#mudconfigts
|
|
23
23
|
* for the source of this information.
|
|
24
24
|
*/
|
|
25
25
|
import mudConfig from "contracts/mud.config";
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
|
|
8
|
-
"build:abi": "forge
|
|
9
|
-
"build:abi-ts": "mud abi-ts
|
|
8
|
+
"build:abi": "forge build",
|
|
9
|
+
"build:abi-ts": "mud abi-ts",
|
|
10
10
|
"build:mud": "rimraf src/codegen && mud tablegen && mud worldgen",
|
|
11
11
|
"deploy:local": "pnpm run build && mud deploy",
|
|
12
12
|
"deploy:testnet": "pnpm run build && mud deploy --profile=lattice-testnet",
|
|
@@ -90,13 +90,6 @@ library Counter {
|
|
|
90
90
|
StoreCore.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
/**
|
|
94
|
-
* @notice Register the table with its config (using the specified store).
|
|
95
|
-
*/
|
|
96
|
-
function register(IStore _store) internal {
|
|
97
|
-
_store.registerTable(_tableId, _fieldLayout, getKeySchema(), getValueSchema(), getKeyNames(), getFieldNames());
|
|
98
|
-
}
|
|
99
|
-
|
|
100
93
|
/**
|
|
101
94
|
* @notice Get value.
|
|
102
95
|
*/
|
|
@@ -117,16 +110,6 @@ library Counter {
|
|
|
117
110
|
return (uint32(bytes4(_blob)));
|
|
118
111
|
}
|
|
119
112
|
|
|
120
|
-
/**
|
|
121
|
-
* @notice Get value (using the specified store).
|
|
122
|
-
*/
|
|
123
|
-
function getValue(IStore _store) internal view returns (uint32 value) {
|
|
124
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
125
|
-
|
|
126
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
127
|
-
return (uint32(bytes4(_blob)));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
113
|
/**
|
|
131
114
|
* @notice Get value.
|
|
132
115
|
*/
|
|
@@ -147,16 +130,6 @@ library Counter {
|
|
|
147
130
|
return (uint32(bytes4(_blob)));
|
|
148
131
|
}
|
|
149
132
|
|
|
150
|
-
/**
|
|
151
|
-
* @notice Get value (using the specified store).
|
|
152
|
-
*/
|
|
153
|
-
function get(IStore _store) internal view returns (uint32 value) {
|
|
154
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
155
|
-
|
|
156
|
-
bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
157
|
-
return (uint32(bytes4(_blob)));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
133
|
/**
|
|
161
134
|
* @notice Set value.
|
|
162
135
|
*/
|
|
@@ -175,15 +148,6 @@ library Counter {
|
|
|
175
148
|
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
176
149
|
}
|
|
177
150
|
|
|
178
|
-
/**
|
|
179
|
-
* @notice Set value (using the specified store).
|
|
180
|
-
*/
|
|
181
|
-
function setValue(IStore _store, uint32 value) internal {
|
|
182
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
183
|
-
|
|
184
|
-
_store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
151
|
/**
|
|
188
152
|
* @notice Set value.
|
|
189
153
|
*/
|
|
@@ -202,15 +166,6 @@ library Counter {
|
|
|
202
166
|
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
203
167
|
}
|
|
204
168
|
|
|
205
|
-
/**
|
|
206
|
-
* @notice Set value (using the specified store).
|
|
207
|
-
*/
|
|
208
|
-
function set(IStore _store, uint32 value) internal {
|
|
209
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
210
|
-
|
|
211
|
-
_store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
169
|
/**
|
|
215
170
|
* @notice Delete all data for given keys.
|
|
216
171
|
*/
|
|
@@ -229,15 +184,6 @@ library Counter {
|
|
|
229
184
|
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
|
230
185
|
}
|
|
231
186
|
|
|
232
|
-
/**
|
|
233
|
-
* @notice Delete all data for given keys (using the specified store).
|
|
234
|
-
*/
|
|
235
|
-
function deleteRecord(IStore _store) internal {
|
|
236
|
-
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
237
|
-
|
|
238
|
-
_store.deleteRecord(_tableId, _keyTuple);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
187
|
/**
|
|
242
188
|
* @notice Tightly pack static (fixed length) data using this table's schema.
|
|
243
189
|
* @return The static data, encoded into a sequence of bytes.
|
|
@@ -9,13 +9,6 @@ import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
|
9
9
|
import { Counter, CounterTableId } from "../src/codegen/index.sol";
|
|
10
10
|
|
|
11
11
|
contract CounterTest is MudTest {
|
|
12
|
-
IWorld public world;
|
|
13
|
-
|
|
14
|
-
function setUp() public override {
|
|
15
|
-
super.setUp();
|
|
16
|
-
world = IWorld(worldAddress);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
function testWorldExists() public {
|
|
20
13
|
uint256 codeSize;
|
|
21
14
|
address addr = worldAddress;
|
|
@@ -27,12 +20,12 @@ contract CounterTest is MudTest {
|
|
|
27
20
|
|
|
28
21
|
function testCounter() public {
|
|
29
22
|
// Expect the counter to be 1 because it was incremented in the PostDeploy script.
|
|
30
|
-
uint32 counter = Counter.get(
|
|
23
|
+
uint32 counter = Counter.get();
|
|
31
24
|
assertEq(counter, 1);
|
|
32
25
|
|
|
33
26
|
// Expect the counter to be 2 after calling increment.
|
|
34
|
-
|
|
35
|
-
counter = Counter.get(
|
|
27
|
+
IWorld(worldAddress).increment();
|
|
28
|
+
counter = Counter.get();
|
|
36
29
|
assertEq(counter, 2);
|
|
37
30
|
}
|
|
38
31
|
}
|