create-mud 2.2.17-ce0e08e6fdf17a061e41a062a2684a592ec15f2f → 2.2.17-d5f4e1e44bbc260ff21dacdfab0e0f8389e9f304
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/packages/client/src/mud/Synced.tsx +1 -1
- package/templates/react/packages/contracts/.env +1 -1
- package/templates/react/packages/contracts/mud.config.ts +7 -0
- package/templates/react/packages/contracts/test/MoveTest.t.sol +2 -0
- package/templates/react/packages/contracts/test/WorldTest.t.sol +5 -0
- package/templates/react-ecs/mprocs.yaml +1 -9
- package/templates/react-ecs/package.json +2 -1
- package/templates/react-ecs/packages/client/index.html +2 -2
- package/templates/react-ecs/packages/client/package.json +9 -16
- package/templates/react-ecs/packages/client/src/App.tsx +21 -66
- package/templates/react-ecs/packages/client/src/MUDContext.tsx +21 -0
- package/templates/react-ecs/packages/client/src/index.tsx +32 -17
- package/templates/react-ecs/packages/client/src/mud/createClientComponents.ts +21 -0
- package/templates/react-ecs/packages/client/src/mud/createSystemCalls.ts +51 -0
- package/templates/react-ecs/packages/client/src/mud/getNetworkConfig.ts +77 -0
- package/templates/react-ecs/packages/client/src/mud/setup.ts +21 -0
- package/templates/react-ecs/packages/client/src/mud/setupNetwork.ts +106 -0
- package/templates/react-ecs/packages/client/src/mud/supportedChains.ts +20 -0
- package/templates/react-ecs/packages/client/src/mud/world.ts +3 -0
- package/templates/react-ecs/packages/client/tsconfig.json +1 -1
- package/templates/react-ecs/packages/client/vite.config.ts +7 -2
- package/templates/react-ecs/packages/contracts/.env +1 -1
- package/templates/react-ecs/packages/contracts/mud.config.ts +6 -11
- package/templates/react-ecs/packages/contracts/package.json +0 -1
- package/templates/react-ecs/packages/contracts/script/PostDeploy.s.sol +5 -1
- package/templates/react-ecs/packages/contracts/src/codegen/index.sol +1 -3
- package/templates/react-ecs/packages/contracts/src/codegen/tables/{EntityCount.sol → Counter.sol} +35 -35
- package/templates/react-ecs/packages/contracts/src/codegen/world/{ISpawnSystem.sol → IIncrementSystem.sol} +3 -5
- package/templates/react-ecs/packages/contracts/src/codegen/world/IWorld.sol +2 -3
- package/templates/react-ecs/packages/contracts/src/systems/IncrementSystem.sol +14 -0
- package/templates/react-ecs/packages/contracts/test/CounterTest.t.sol +31 -0
- package/templates/react-ecs/packages/contracts/worlds.json +1 -1
- package/templates/phaser/.gitignore_ +0 -7
- package/templates/phaser/packages/art/.gitignore_ +0 -0
- package/templates/phaser/packages/client/.gitignore_ +0 -3
- package/templates/phaser/packages/contracts/.gitignore_ +0 -9
- package/templates/react/.gitignore_ +0 -16
- package/templates/react/packages/client/.gitignore_ +0 -1
- package/templates/react/packages/contracts/.gitignore_ +0 -13
- package/templates/react-ecs/.gitignore_ +0 -16
- package/templates/react-ecs/packages/client/.gitignore_ +0 -1
- package/templates/react-ecs/packages/client/postcss.config.cjs +0 -6
- package/templates/react-ecs/packages/client/src/Providers.tsx +0 -29
- package/templates/react-ecs/packages/client/src/common.ts +0 -27
- package/templates/react-ecs/packages/client/src/game/GameMap.tsx +0 -112
- package/templates/react-ecs/packages/client/src/game/useKeyboardMovement.ts +0 -26
- package/templates/react-ecs/packages/client/src/mud/Explorer.tsx +0 -32
- package/templates/react-ecs/packages/client/src/mud/Synced.tsx +0 -14
- package/templates/react-ecs/packages/client/src/mud/recs.ts +0 -6
- package/templates/react-ecs/packages/client/src/mud/useSyncStatus.ts +0 -17
- package/templates/react-ecs/packages/client/src/mud/useWorldContract.ts +0 -44
- package/templates/react-ecs/packages/client/src/ui/AsyncButton.tsx +0 -41
- package/templates/react-ecs/packages/client/src/ui/ErrorFallback.tsx +0 -58
- package/templates/react-ecs/packages/client/src/ui/icons/ArrowDownIcon.tsx +0 -22
- package/templates/react-ecs/packages/client/src/ui/icons/MUDIcon.tsx +0 -25
- package/templates/react-ecs/packages/client/src/wagmiConfig.ts +0 -49
- package/templates/react-ecs/packages/client/tailwind.config.ts +0 -10
- package/templates/react-ecs/packages/contracts/.gitignore_ +0 -13
- package/templates/react-ecs/packages/contracts/out/IWorld.sol/IWorld.abi.json +0 -2039
- package/templates/react-ecs/packages/contracts/src/Entity.sol +0 -20
- package/templates/react-ecs/packages/contracts/src/MoveSystem.sol +0 -30
- package/templates/react-ecs/packages/contracts/src/SpawnSystem.sol +0 -18
- package/templates/react-ecs/packages/contracts/src/codegen/common.sol +0 -11
- package/templates/react-ecs/packages/contracts/src/codegen/tables/Owner.sol +0 -202
- package/templates/react-ecs/packages/contracts/src/codegen/tables/Position.sol +0 -321
- package/templates/react-ecs/packages/contracts/src/codegen/world/IMoveSystem.sol +0 -16
- package/templates/react-ecs/packages/contracts/src/createEntity.sol +0 -11
- package/templates/react-ecs/packages/contracts/test/MoveTest.t.sol +0 -39
- package/templates/react-ecs/packages/contracts/test/WorldTest.t.sol +0 -16
- package/templates/threejs/.gitignore_ +0 -7
- package/templates/threejs/packages/client/.gitignore_ +0 -3
- package/templates/threejs/packages/contracts/.gitignore_ +0 -9
- package/templates/vanilla/.gitignore_ +0 -7
- package/templates/vanilla/packages/client/.gitignore_ +0 -3
- package/templates/vanilla/packages/contracts/.gitignore_ +0 -9
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MUD client code is built on top of viem
|
|
3
|
+
* (https://viem.sh/docs/getting-started.html).
|
|
4
|
+
* This line imports the functions we need from it.
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
createPublicClient,
|
|
8
|
+
fallback,
|
|
9
|
+
webSocket,
|
|
10
|
+
http,
|
|
11
|
+
createWalletClient,
|
|
12
|
+
Hex,
|
|
13
|
+
ClientConfig,
|
|
14
|
+
getContract,
|
|
15
|
+
} from "viem";
|
|
16
|
+
import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
|
|
17
|
+
|
|
18
|
+
import { getNetworkConfig } from "./getNetworkConfig";
|
|
19
|
+
import { world } from "./world";
|
|
20
|
+
import IWorldAbi from "contracts/out/IWorld.sol/IWorld.abi.json";
|
|
21
|
+
import { createBurnerAccount, transportObserver, ContractWrite } from "@latticexyz/common";
|
|
22
|
+
import { transactionQueue, writeObserver } from "@latticexyz/common/actions";
|
|
23
|
+
|
|
24
|
+
import { Subject, share } from "rxjs";
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* Import our MUD config, which includes strong types for
|
|
28
|
+
* our tables and other config options. We use this to generate
|
|
29
|
+
* things like RECS components and get back strong types for them.
|
|
30
|
+
*
|
|
31
|
+
* See https://mud.dev/templates/typescript/contracts#mudconfigts
|
|
32
|
+
* for the source of this information.
|
|
33
|
+
*/
|
|
34
|
+
import mudConfig from "contracts/mud.config";
|
|
35
|
+
|
|
36
|
+
export type SetupNetworkResult = Awaited<ReturnType<typeof setupNetwork>>;
|
|
37
|
+
|
|
38
|
+
export async function setupNetwork() {
|
|
39
|
+
const networkConfig = await getNetworkConfig();
|
|
40
|
+
|
|
41
|
+
/*
|
|
42
|
+
* Create a viem public (read only) client
|
|
43
|
+
* (https://viem.sh/docs/clients/public.html)
|
|
44
|
+
*/
|
|
45
|
+
const clientOptions = {
|
|
46
|
+
chain: networkConfig.chain,
|
|
47
|
+
transport: transportObserver(fallback([webSocket(), http()])),
|
|
48
|
+
pollingInterval: 1000,
|
|
49
|
+
} as const satisfies ClientConfig;
|
|
50
|
+
|
|
51
|
+
const publicClient = createPublicClient(clientOptions);
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* Create an observable for contract writes that we can
|
|
55
|
+
* pass into MUD dev tools for transaction observability.
|
|
56
|
+
*/
|
|
57
|
+
const write$ = new Subject<ContractWrite>();
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
* Create a temporary wallet and a viem client for it
|
|
61
|
+
* (see https://viem.sh/docs/clients/wallet.html).
|
|
62
|
+
*/
|
|
63
|
+
const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex);
|
|
64
|
+
const burnerWalletClient = createWalletClient({
|
|
65
|
+
...clientOptions,
|
|
66
|
+
account: burnerAccount,
|
|
67
|
+
})
|
|
68
|
+
.extend(transactionQueue())
|
|
69
|
+
.extend(writeObserver({ onWrite: (write) => write$.next(write) }));
|
|
70
|
+
|
|
71
|
+
/*
|
|
72
|
+
* Create an object for communicating with the deployed World.
|
|
73
|
+
*/
|
|
74
|
+
const worldContract = getContract({
|
|
75
|
+
address: networkConfig.worldAddress as Hex,
|
|
76
|
+
abi: IWorldAbi,
|
|
77
|
+
client: { public: publicClient, wallet: burnerWalletClient },
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
* Sync on-chain state into RECS and keeps our client in sync.
|
|
82
|
+
* Uses the MUD indexer if available, otherwise falls back
|
|
83
|
+
* to the viem publicClient to make RPC calls to fetch MUD
|
|
84
|
+
* events from the chain.
|
|
85
|
+
*/
|
|
86
|
+
const { components, latestBlock$, storedBlockLogs$, waitForTransaction } = await syncToRecs({
|
|
87
|
+
world,
|
|
88
|
+
config: mudConfig,
|
|
89
|
+
address: networkConfig.worldAddress as Hex,
|
|
90
|
+
publicClient,
|
|
91
|
+
startBlock: BigInt(networkConfig.initialBlockNumber),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
world,
|
|
96
|
+
components,
|
|
97
|
+
playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }),
|
|
98
|
+
publicClient,
|
|
99
|
+
walletClient: burnerWalletClient,
|
|
100
|
+
latestBlock$,
|
|
101
|
+
storedBlockLogs$,
|
|
102
|
+
waitForTransaction,
|
|
103
|
+
worldContract,
|
|
104
|
+
write$: write$.asObservable().pipe(share()),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The supported chains.
|
|
3
|
+
* By default, there are only two chains here:
|
|
4
|
+
*
|
|
5
|
+
* - mudFoundry, the chain running on anvil that pnpm dev
|
|
6
|
+
* starts by default. It is similar to the viem anvil chain
|
|
7
|
+
* (see https://viem.sh/docs/clients/test.html), but with the
|
|
8
|
+
* basefee set to zero to avoid transaction fees.
|
|
9
|
+
* - Redstone, our production blockchain (https://redstone.xyz/)
|
|
10
|
+
* - Garnet, our test blockchain (https://garnetchain.com/))
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { MUDChain, mudFoundry, redstone, garnet } from "@latticexyz/common/chains";
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* See https://mud.dev/guides/hello-world/add-chain-client
|
|
18
|
+
* for instructions on how to add networks.
|
|
19
|
+
*/
|
|
20
|
+
export const supportedChains: MUDChain[] = [mudFoundry, redstone, garnet];
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { defineConfig } from "vite";
|
|
2
2
|
import react from "@vitejs/plugin-react";
|
|
3
|
-
import { mud } from "vite-plugin-mud";
|
|
4
3
|
|
|
5
4
|
export default defineConfig({
|
|
6
|
-
plugins: [react()
|
|
5
|
+
plugins: [react()],
|
|
6
|
+
server: {
|
|
7
|
+
port: 3000,
|
|
8
|
+
fs: {
|
|
9
|
+
strict: false,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
7
12
|
build: {
|
|
8
13
|
target: "es2022",
|
|
9
14
|
minify: true,
|
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
Counter: {
|
|
7
|
+
schema: {
|
|
8
|
+
value: "uint32",
|
|
9
|
+
},
|
|
10
|
+
key: [],
|
|
11
|
+
},
|
|
17
12
|
},
|
|
18
13
|
});
|
|
@@ -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
|
-
//
|
|
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 {
|
|
7
|
-
import { Owner } from "./tables/Owner.sol";
|
|
8
|
-
import { Position, PositionData } from "./tables/Position.sol";
|
|
6
|
+
import { Counter } from "./tables/Counter.sol";
|
package/templates/react-ecs/packages/contracts/src/codegen/tables/{EntityCount.sol → Counter.sol}
RENAMED
|
@@ -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
|
|
20
|
-
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "app", name: "
|
|
21
|
-
ResourceId constant _tableId = ResourceId.wrap(
|
|
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(
|
|
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 (
|
|
29
|
-
Schema constant _valueSchema = Schema.wrap(
|
|
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] = "
|
|
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
|
|
63
|
+
* @notice Get value.
|
|
64
64
|
*/
|
|
65
|
-
function
|
|
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 (
|
|
69
|
+
return (uint32(bytes4(_blob)));
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* @notice Get
|
|
73
|
+
* @notice Get value.
|
|
74
74
|
*/
|
|
75
|
-
function
|
|
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 (
|
|
79
|
+
return (uint32(bytes4(_blob)));
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
* @notice Get
|
|
83
|
+
* @notice Get value.
|
|
84
84
|
*/
|
|
85
|
-
function get() internal view returns (
|
|
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 (
|
|
89
|
+
return (uint32(bytes4(_blob)));
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
|
-
* @notice Get
|
|
93
|
+
* @notice Get value.
|
|
94
94
|
*/
|
|
95
|
-
function _get() internal view returns (
|
|
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 (
|
|
99
|
+
return (uint32(bytes4(_blob)));
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
* @notice Set
|
|
103
|
+
* @notice Set value.
|
|
104
104
|
*/
|
|
105
|
-
function
|
|
105
|
+
function setValue(uint32 value) internal {
|
|
106
106
|
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
107
107
|
|
|
108
|
-
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((
|
|
108
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
* @notice Set
|
|
112
|
+
* @notice Set value.
|
|
113
113
|
*/
|
|
114
|
-
function
|
|
114
|
+
function _setValue(uint32 value) internal {
|
|
115
115
|
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
116
116
|
|
|
117
|
-
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((
|
|
117
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
|
-
* @notice Set
|
|
121
|
+
* @notice Set value.
|
|
122
122
|
*/
|
|
123
|
-
function set(
|
|
123
|
+
function set(uint32 value) internal {
|
|
124
124
|
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
125
125
|
|
|
126
|
-
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((
|
|
126
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
|
-
* @notice Set
|
|
130
|
+
* @notice Set value.
|
|
131
131
|
*/
|
|
132
|
-
function _set(
|
|
132
|
+
function _set(uint32 value) internal {
|
|
133
133
|
bytes32[] memory _keyTuple = new bytes32[](0);
|
|
134
134
|
|
|
135
|
-
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((
|
|
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(
|
|
161
|
-
return abi.encodePacked(
|
|
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(
|
|
171
|
-
bytes memory _staticData = encodeStatic(
|
|
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 { Entity } from "../../Entity.sol";
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
|
-
* @title
|
|
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
|
|
14
|
-
function
|
|
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 {
|
|
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,
|
|
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
|
+
}
|
|
File without changes
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dist
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dist
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { WagmiProvider } from "wagmi";
|
|
2
|
-
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
|
|
3
|
-
import { ReactNode } from "react";
|
|
4
|
-
import { SyncProvider } from "@latticexyz/store-sync/react";
|
|
5
|
-
import { defineConfig, EntryKitProvider } from "@latticexyz/entrykit/internal";
|
|
6
|
-
import { wagmiConfig } from "./wagmiConfig";
|
|
7
|
-
import { chainId, getWorldAddress, startBlock } from "./common";
|
|
8
|
-
import { syncAdapter } from "./mud/recs";
|
|
9
|
-
|
|
10
|
-
const queryClient = new QueryClient();
|
|
11
|
-
|
|
12
|
-
export type Props = {
|
|
13
|
-
children: ReactNode;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export function Providers({ children }: Props) {
|
|
17
|
-
const worldAddress = getWorldAddress();
|
|
18
|
-
return (
|
|
19
|
-
<WagmiProvider config={wagmiConfig}>
|
|
20
|
-
<QueryClientProvider client={queryClient}>
|
|
21
|
-
<EntryKitProvider config={defineConfig({ chainId, worldAddress })}>
|
|
22
|
-
<SyncProvider chainId={chainId} address={worldAddress} startBlock={startBlock} adapter={syncAdapter}>
|
|
23
|
-
{children}
|
|
24
|
-
</SyncProvider>
|
|
25
|
-
</EntryKitProvider>
|
|
26
|
-
</QueryClientProvider>
|
|
27
|
-
</WagmiProvider>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import mudConfig from "contracts/mud.config";
|
|
2
|
-
import { chains } from "./wagmiConfig";
|
|
3
|
-
import { Chain, Hex } from "viem";
|
|
4
|
-
|
|
5
|
-
export const chainId = import.meta.env.CHAIN_ID;
|
|
6
|
-
export const worldAddress = import.meta.env.WORLD_ADDRESS;
|
|
7
|
-
export const startBlock = import.meta.env.START_BLOCK;
|
|
8
|
-
|
|
9
|
-
export const url = new URL(window.location.href);
|
|
10
|
-
|
|
11
|
-
export type Entity = Hex;
|
|
12
|
-
export type Direction = (typeof mudConfig.enums.Direction)[number];
|
|
13
|
-
|
|
14
|
-
export function getWorldAddress() {
|
|
15
|
-
if (!worldAddress) {
|
|
16
|
-
throw new Error("No world address configured. Is the world still deploying?");
|
|
17
|
-
}
|
|
18
|
-
return worldAddress;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function getChain(): Chain {
|
|
22
|
-
const chain = chains.find((c) => c.id === chainId);
|
|
23
|
-
if (!chain) {
|
|
24
|
-
throw new Error(`No chain configured for chain ID ${chainId}.`);
|
|
25
|
-
}
|
|
26
|
-
return chain;
|
|
27
|
-
}
|