create-mud 2.0.0-alpha.1.21 → 2.0.0-alpha.1.211
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/README.md +1 -1
- package/dist/cli.js +1 -1
- package/dist/templates/{minimal/packages/client → phaser}/.eslintrc +1 -3
- package/dist/templates/phaser/package.json +28 -0
- package/dist/templates/phaser/packages/art/.gitignore +0 -0
- package/dist/templates/phaser/packages/art/README.md +33 -0
- package/dist/templates/phaser/packages/art/config-sprites.json +21 -0
- package/dist/templates/phaser/packages/art/package.json +27 -0
- package/dist/templates/phaser/packages/art/scripts/cli.mjs +190 -0
- package/dist/templates/phaser/packages/art/scripts/export-tiled-types.ts +292 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/0.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/1.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/2.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/3.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/4.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/attack/5.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/death/0.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/death/1.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/death/2.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/idle/0.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/idle/1.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/idle/2.png +0 -0
- package/dist/templates/phaser/packages/art/sprites/golem/idle/3.png +0 -0
- package/dist/templates/phaser/packages/art/tilesets/images/world.png +0 -0
- package/dist/templates/phaser/packages/art/tilesets/world.tsx +19 -0
- package/dist/templates/phaser/packages/client/.env +1 -0
- package/dist/templates/phaser/packages/client/.eslintrc +7 -0
- package/dist/templates/phaser/packages/client/index.html +39 -0
- package/dist/templates/phaser/packages/client/package.json +48 -0
- package/dist/templates/phaser/packages/client/public/assets/atlases/atlas.json +292 -0
- package/dist/templates/phaser/packages/client/public/assets/atlases/atlas.png +0 -0
- package/dist/templates/phaser/packages/client/public/assets/tilesets/world.png +0 -0
- package/dist/templates/phaser/packages/client/src/artTypes/world.ts +9 -0
- package/dist/templates/phaser/packages/client/src/index.tsx +11 -0
- package/dist/templates/phaser/packages/client/src/layers/network/createNetworkLayer.ts +24 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/configurePhaser.ts +91 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/constants.ts +22 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/createPhaserLayer.ts +33 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/systems/createCamera.ts +13 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/systems/createMapSystem.ts +32 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/systems/index.ts +1 -0
- package/dist/templates/phaser/packages/client/src/layers/phaser/systems/registerSystems.ts +8 -0
- package/dist/templates/phaser/packages/client/src/mud/contractComponents.ts +24 -0
- package/dist/templates/phaser/packages/client/src/mud/createClientComponents.ts +10 -0
- package/dist/templates/phaser/packages/client/src/mud/createSystemCalls.ts +21 -0
- package/dist/templates/phaser/packages/client/src/mud/getNetworkConfig.ts +53 -0
- package/dist/templates/phaser/packages/client/src/mud/setup.ts +16 -0
- package/dist/templates/phaser/packages/client/src/mud/setupNetwork.ts +102 -0
- package/dist/templates/phaser/packages/client/src/mud/supportedChains.ts +5 -0
- package/dist/templates/phaser/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/phaser/packages/client/src/store.ts +38 -0
- package/dist/templates/phaser/packages/client/src/ui/App.tsx +23 -0
- package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/BootScreen.tsx +42 -0
- package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/LoadingBar.tsx +21 -0
- package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/LoadingScreen.tsx +52 -0
- package/dist/templates/phaser/packages/client/src/ui/LoadingScreen/index.ts +1 -0
- package/dist/templates/phaser/packages/client/src/ui/PhaserLayer.tsx +20 -0
- package/dist/templates/phaser/packages/client/src/ui/UIRoot.tsx +20 -0
- package/dist/templates/phaser/packages/client/src/ui/Wrapper.tsx +5 -0
- package/dist/templates/phaser/packages/client/src/ui/hooks/useNetworkLayer.tsx +17 -0
- package/dist/templates/phaser/packages/client/src/ui/hooks/usePhaserLayer.tsx +87 -0
- package/dist/templates/phaser/packages/client/src/ui/hooks/usePromiseValue.ts +24 -0
- package/dist/templates/phaser/packages/client/src/ui/theme/ClickWrapper.tsx +18 -0
- package/dist/templates/phaser/packages/client/src/ui/theme/SpriteImage.tsx +52 -0
- package/dist/templates/{minimal → phaser}/packages/client/tsconfig.json +3 -4
- package/dist/templates/phaser/packages/client/vite.config.ts +15 -0
- package/dist/templates/phaser/packages/contracts/.env +8 -0
- package/dist/templates/{minimal → phaser}/packages/contracts/.gitignore +3 -2
- package/dist/templates/{minimal → phaser}/packages/contracts/.solhint.json +2 -1
- package/dist/templates/phaser/packages/contracts/foundry.toml +22 -0
- package/dist/templates/phaser/packages/contracts/mud.config.ts +10 -0
- package/dist/templates/phaser/packages/contracts/package.json +45 -0
- package/dist/templates/phaser/packages/contracts/remappings.txt +3 -0
- package/dist/templates/phaser/packages/contracts/script/PostDeploy.s.sol +17 -0
- package/dist/templates/phaser/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/phaser/packages/contracts/src/codegen/tables/Counter.sol +120 -0
- package/dist/templates/phaser/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
- package/dist/templates/phaser/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/phaser/packages/contracts/src/systems/IncrementSystem.sol +14 -0
- package/dist/templates/phaser/packages/contracts/test/CounterTest.t.sol +38 -0
- package/dist/templates/phaser/packages/contracts/tsconfig.json +13 -0
- package/dist/templates/phaser/packages/contracts/worlds.json +5 -0
- package/dist/templates/react/.eslintrc +10 -0
- package/dist/templates/react/package.json +13 -3
- package/dist/templates/react/packages/client/.env +1 -0
- package/dist/templates/react/packages/client/.eslintrc +2 -12
- package/dist/templates/react/packages/client/package.json +18 -21
- package/dist/templates/react/packages/client/src/App.tsx +11 -13
- package/dist/templates/react/packages/client/src/MUDContext.tsx +21 -0
- package/dist/templates/react/packages/client/src/index.tsx +12 -31
- package/dist/templates/react/packages/client/src/mud/contractComponents.ts +24 -0
- package/dist/templates/react/packages/client/src/mud/createClientComponents.ts +10 -0
- package/dist/templates/react/packages/client/src/mud/createSystemCalls.ts +21 -0
- package/dist/templates/react/packages/client/src/mud/getNetworkConfig.ts +53 -0
- package/dist/templates/react/packages/client/src/mud/setup.ts +16 -0
- package/dist/templates/react/packages/client/src/mud/setupNetwork.ts +102 -0
- package/dist/templates/react/packages/client/src/mud/supportedChains.ts +5 -0
- package/dist/templates/react/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/react/packages/client/tsconfig.json +0 -3
- package/dist/templates/react/packages/client/vite.config.ts +3 -0
- package/dist/templates/react/packages/contracts/.env +8 -0
- package/dist/templates/react/packages/contracts/.gitignore +3 -2
- package/dist/templates/react/packages/contracts/.solhint.json +2 -1
- package/dist/templates/react/packages/contracts/foundry.toml +13 -2
- package/dist/templates/react/packages/contracts/mud.config.ts +10 -0
- package/dist/templates/react/packages/contracts/package.json +25 -20
- package/dist/templates/react/packages/contracts/remappings.txt +3 -9
- package/dist/templates/react/packages/contracts/script/PostDeploy.s.sol +24 -0
- package/dist/templates/react/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/react/packages/contracts/src/codegen/tables/Counter.sol +120 -0
- package/dist/templates/react/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
- package/dist/templates/react/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/react/packages/contracts/src/systems/IncrementSystem.sol +7 -15
- package/dist/templates/react/packages/contracts/test/CounterTest.t.sol +38 -0
- package/dist/templates/react/packages/contracts/tsconfig.json +9 -8
- package/dist/templates/react/packages/contracts/worlds.json +5 -0
- package/dist/templates/threejs/.eslintrc +10 -0
- package/dist/templates/threejs/.gitignore +1 -0
- package/dist/templates/threejs/.vscode/extensions.json +3 -0
- package/dist/templates/threejs/.vscode/settings.json +3 -0
- package/dist/templates/threejs/package.json +28 -0
- package/dist/templates/threejs/packages/client/.env +1 -0
- package/dist/templates/threejs/packages/client/.eslintrc +7 -0
- package/dist/templates/threejs/packages/client/.gitignore +3 -0
- package/dist/templates/threejs/packages/client/index.html +12 -0
- package/dist/templates/threejs/packages/client/package.json +41 -0
- package/dist/templates/threejs/packages/client/src/App.tsx +81 -0
- package/dist/templates/threejs/packages/client/src/MUDContext.tsx +21 -0
- package/dist/templates/threejs/packages/client/src/index.tsx +19 -0
- package/dist/templates/threejs/packages/client/src/mud/contractComponents.ts +26 -0
- package/dist/templates/threejs/packages/client/src/mud/createClientComponents.ts +10 -0
- package/dist/templates/threejs/packages/client/src/mud/createSystemCalls.ts +15 -0
- package/dist/templates/threejs/packages/client/src/mud/getNetworkConfig.ts +53 -0
- package/dist/templates/threejs/packages/client/src/mud/setup.ts +16 -0
- package/dist/templates/threejs/packages/client/src/mud/setupNetwork.ts +102 -0
- package/dist/templates/threejs/packages/client/src/mud/supportedChains.ts +5 -0
- package/dist/templates/threejs/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/threejs/packages/client/src/useKeyboardMovement.ts +60 -0
- package/dist/templates/threejs/packages/client/tsconfig.json +19 -0
- package/dist/templates/threejs/packages/client/vite.config.ts +15 -0
- package/dist/templates/threejs/packages/contracts/.env +8 -0
- package/dist/templates/threejs/packages/contracts/.gitignore +11 -0
- package/dist/templates/threejs/packages/contracts/.prettierrc +8 -0
- package/dist/templates/threejs/packages/contracts/.solhint.json +12 -0
- package/dist/templates/threejs/packages/contracts/foundry.toml +22 -0
- package/dist/templates/threejs/packages/contracts/mud.config.ts +13 -0
- package/dist/templates/threejs/packages/contracts/package.json +45 -0
- package/dist/templates/threejs/packages/contracts/remappings.txt +3 -0
- package/dist/templates/threejs/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/threejs/packages/contracts/src/codegen/tables/Position.sol +263 -0
- package/dist/templates/threejs/packages/contracts/src/codegen/world/IMoveSystem.sol +8 -0
- package/dist/templates/threejs/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/threejs/packages/contracts/src/systems/MoveSystem.sol +25 -0
- package/dist/templates/threejs/packages/contracts/tsconfig.json +13 -0
- package/dist/templates/threejs/packages/contracts/worlds.json +5 -0
- package/dist/templates/threejs/pnpm-workspace.yaml +2 -0
- package/dist/templates/vanilla/.eslintrc +10 -0
- package/dist/templates/vanilla/.gitignore +1 -0
- package/dist/templates/vanilla/.vscode/extensions.json +3 -0
- package/dist/templates/vanilla/.vscode/settings.json +3 -0
- package/dist/templates/vanilla/package.json +28 -0
- package/dist/templates/vanilla/packages/client/.env +1 -0
- package/dist/templates/vanilla/packages/client/.gitignore +3 -0
- package/dist/templates/vanilla/packages/client/package.json +32 -0
- package/dist/templates/vanilla/packages/client/src/index.ts +22 -0
- package/dist/templates/vanilla/packages/client/src/mud/contractComponents.ts +24 -0
- package/dist/templates/vanilla/packages/client/src/mud/createClientComponents.ts +10 -0
- package/dist/templates/vanilla/packages/client/src/mud/createSystemCalls.ts +21 -0
- package/dist/templates/vanilla/packages/client/src/mud/getNetworkConfig.ts +53 -0
- package/dist/templates/vanilla/packages/client/src/mud/setup.ts +16 -0
- package/dist/templates/vanilla/packages/client/src/mud/setupNetwork.ts +102 -0
- package/dist/templates/vanilla/packages/client/src/mud/supportedChains.ts +5 -0
- package/dist/templates/vanilla/packages/client/src/mud/world.ts +3 -0
- package/dist/templates/vanilla/packages/client/tsconfig.json +18 -0
- package/dist/templates/{minimal → vanilla}/packages/client/vite.config.ts +3 -0
- package/dist/templates/vanilla/packages/contracts/.env +8 -0
- package/dist/templates/vanilla/packages/contracts/.gitignore +11 -0
- package/dist/templates/vanilla/packages/contracts/.prettierrc +8 -0
- package/dist/templates/vanilla/packages/contracts/.solhint.json +12 -0
- package/dist/templates/vanilla/packages/contracts/foundry.toml +22 -0
- package/dist/templates/vanilla/packages/contracts/mud.config.ts +10 -0
- package/dist/templates/vanilla/packages/contracts/package.json +45 -0
- package/dist/templates/vanilla/packages/contracts/remappings.txt +3 -0
- package/dist/templates/vanilla/packages/contracts/script/PostDeploy.s.sol +24 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/Tables.sol +6 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/tables/Counter.sol +120 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/world/IIncrementSystem.sol +8 -0
- package/dist/templates/vanilla/packages/contracts/src/codegen/world/IWorld.sol +16 -0
- package/dist/templates/vanilla/packages/contracts/src/systems/IncrementSystem.sol +14 -0
- package/dist/templates/vanilla/packages/contracts/test/CounterTest.t.sol +38 -0
- package/dist/templates/vanilla/packages/contracts/tsconfig.json +13 -0
- package/dist/templates/vanilla/packages/contracts/worlds.json +5 -0
- package/dist/templates/vanilla/pnpm-workspace.yaml +2 -0
- package/package.json +14 -11
- package/dist/templates/minimal/package.json +0 -18
- package/dist/templates/minimal/packages/client/package.json +0 -37
- package/dist/templates/minimal/packages/client/src/config.ts +0 -22
- package/dist/templates/minimal/packages/client/src/index.ts +0 -37
- package/dist/templates/minimal/packages/contracts/chainSpec.json +0 -5
- package/dist/templates/minimal/packages/contracts/deploy.json +0 -4
- package/dist/templates/minimal/packages/contracts/exports.sh +0 -22
- package/dist/templates/minimal/packages/contracts/foundry.toml +0 -11
- package/dist/templates/minimal/packages/contracts/package.json +0 -40
- package/dist/templates/minimal/packages/contracts/remappings.txt +0 -9
- package/dist/templates/minimal/packages/contracts/src/components/CounterComponent.sol +0 -9
- package/dist/templates/minimal/packages/contracts/src/libraries/LibMath.sol +0 -10
- package/dist/templates/minimal/packages/contracts/src/systems/IncrementSystem.sol +0 -22
- package/dist/templates/minimal/packages/contracts/src/systems/README.md +0 -7
- package/dist/templates/minimal/packages/contracts/src/test/Deploy.sol +0 -19
- package/dist/templates/minimal/packages/contracts/src/test/Deploy.t.sol +0 -14
- package/dist/templates/minimal/packages/contracts/src/test/LibDeploy.sol +0 -22
- package/dist/templates/minimal/packages/contracts/tsconfig.json +0 -12
- package/dist/templates/react/packages/client/src/config.ts +0 -22
- package/dist/templates/react/packages/contracts/chainSpec.json +0 -5
- package/dist/templates/react/packages/contracts/deploy.json +0 -4
- package/dist/templates/react/packages/contracts/exports.sh +0 -22
- package/dist/templates/react/packages/contracts/src/components/CounterComponent.sol +0 -9
- package/dist/templates/react/packages/contracts/src/libraries/LibMath.sol +0 -10
- package/dist/templates/react/packages/contracts/src/systems/README.md +0 -7
- package/dist/templates/react/packages/contracts/src/test/Deploy.sol +0 -19
- package/dist/templates/react/packages/contracts/src/test/Deploy.t.sol +0 -14
- package/dist/templates/react/packages/contracts/src/test/LibDeploy.sol +0 -22
- /package/dist/templates/{minimal → phaser}/.gitignore +0 -0
- /package/dist/templates/{minimal → phaser}/.vscode/extensions.json +0 -0
- /package/dist/templates/{minimal → phaser}/.vscode/settings.json +0 -0
- /package/dist/templates/{minimal → phaser}/packages/client/.gitignore +0 -0
- /package/dist/templates/{minimal → phaser}/packages/contracts/.prettierrc +0 -0
- /package/dist/templates/{minimal → phaser}/pnpm-workspace.yaml +0 -0
- /package/dist/templates/{minimal → vanilla}/packages/client/index.html +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "contracts",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "forge clean && forge build",
|
|
8
|
+
"deploy": "pnpm run initialize && mud deploy",
|
|
9
|
+
"deploy:hackathon": "pnpm run initialize && mud deploy --profile=hackathon-testnet",
|
|
10
|
+
"deploy:testnet": "pnpm run initialize && mud deploy --profile=lattice-testnet",
|
|
11
|
+
"dev": "pnpm mud dev-contracts --tsgenOutput ../client/src/mud",
|
|
12
|
+
"initialize": "pnpm run tablegen && pnpm run worldgen && pnpm run build && pnpm run worldtypes && pnpm run tsgen",
|
|
13
|
+
"lint": "pnpm run prettier && pnpm run solhint",
|
|
14
|
+
"prettier": "prettier --write 'src/**/*.sol'",
|
|
15
|
+
"solhint": "solhint --config ./.solhint.json 'src/**/*.sol' --fix",
|
|
16
|
+
"tablegen": "mud tablegen",
|
|
17
|
+
"test": "tsc --noEmit && mud test",
|
|
18
|
+
"tsgen": "mud tsgen --configPath mud.config.ts --out ../client/src/mud",
|
|
19
|
+
"worldgen": "mud worldgen",
|
|
20
|
+
"worldtypes": "rimraf types && typechain --target=ethers-v5 out/IWorld.sol/IWorld.json"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@ethersproject/abi": "^5.7.0",
|
|
24
|
+
"@ethersproject/bytes": "^5.7.0",
|
|
25
|
+
"@ethersproject/providers": "^5.7.2",
|
|
26
|
+
"@latticexyz/cli": "{{mud-version}}",
|
|
27
|
+
"@latticexyz/schema-type": "{{mud-version}}",
|
|
28
|
+
"@latticexyz/std-contracts": "{{mud-version}}",
|
|
29
|
+
"@latticexyz/store": "{{mud-version}}",
|
|
30
|
+
"@latticexyz/world": "{{mud-version}}",
|
|
31
|
+
"ethers": "^5.7.2"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@typechain/ethers-v5": "^10.2.0",
|
|
35
|
+
"@types/node": "^18.15.11",
|
|
36
|
+
"ds-test": "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084",
|
|
37
|
+
"forge-std": "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3",
|
|
38
|
+
"prettier": "^2.6.2",
|
|
39
|
+
"prettier-plugin-solidity": "^1.0.0-beta.19",
|
|
40
|
+
"solhint": "^3.3.7",
|
|
41
|
+
"solhint-config-mud": "{{mud-version}}",
|
|
42
|
+
"solhint-plugin-mud": "{{mud-version}}",
|
|
43
|
+
"typechain": "^8.1.1"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.0;
|
|
3
|
+
|
|
4
|
+
/* Autogenerated file. Do not edit manually. */
|
|
5
|
+
|
|
6
|
+
// Import schema type
|
|
7
|
+
import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol";
|
|
8
|
+
|
|
9
|
+
// Import store internals
|
|
10
|
+
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
|
11
|
+
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
|
12
|
+
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
|
|
13
|
+
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
|
14
|
+
import { Memory } from "@latticexyz/store/src/Memory.sol";
|
|
15
|
+
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
|
|
16
|
+
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
|
17
|
+
import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol";
|
|
18
|
+
import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol";
|
|
19
|
+
|
|
20
|
+
bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Position")));
|
|
21
|
+
bytes32 constant PositionTableId = _tableId;
|
|
22
|
+
|
|
23
|
+
struct PositionData {
|
|
24
|
+
int32 x;
|
|
25
|
+
int32 y;
|
|
26
|
+
int32 z;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
library Position {
|
|
30
|
+
/** Get the table's schema */
|
|
31
|
+
function getSchema() internal pure returns (Schema) {
|
|
32
|
+
SchemaType[] memory _schema = new SchemaType[](3);
|
|
33
|
+
_schema[0] = SchemaType.INT32;
|
|
34
|
+
_schema[1] = SchemaType.INT32;
|
|
35
|
+
_schema[2] = SchemaType.INT32;
|
|
36
|
+
|
|
37
|
+
return SchemaLib.encode(_schema);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getKeySchema() internal pure returns (Schema) {
|
|
41
|
+
SchemaType[] memory _schema = new SchemaType[](1);
|
|
42
|
+
_schema[0] = SchemaType.BYTES32;
|
|
43
|
+
|
|
44
|
+
return SchemaLib.encode(_schema);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Get the table's metadata */
|
|
48
|
+
function getMetadata() internal pure returns (string memory, string[] memory) {
|
|
49
|
+
string[] memory _fieldNames = new string[](3);
|
|
50
|
+
_fieldNames[0] = "x";
|
|
51
|
+
_fieldNames[1] = "y";
|
|
52
|
+
_fieldNames[2] = "z";
|
|
53
|
+
return ("Position", _fieldNames);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Register the table's schema */
|
|
57
|
+
function registerSchema() internal {
|
|
58
|
+
StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema());
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Register the table's schema (using the specified store) */
|
|
62
|
+
function registerSchema(IStore _store) internal {
|
|
63
|
+
_store.registerSchema(_tableId, getSchema(), getKeySchema());
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Set the table's metadata */
|
|
67
|
+
function setMetadata() internal {
|
|
68
|
+
(string memory _tableName, string[] memory _fieldNames) = getMetadata();
|
|
69
|
+
StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Set the table's metadata (using the specified store) */
|
|
73
|
+
function setMetadata(IStore _store) internal {
|
|
74
|
+
(string memory _tableName, string[] memory _fieldNames) = getMetadata();
|
|
75
|
+
_store.setMetadata(_tableId, _tableName, _fieldNames);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Get x */
|
|
79
|
+
function getX(bytes32 key) internal view returns (int32 x) {
|
|
80
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
81
|
+
_keyTuple[0] = bytes32((key));
|
|
82
|
+
|
|
83
|
+
bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 0);
|
|
84
|
+
return (int32(uint32(Bytes.slice4(_blob, 0))));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Get x (using the specified store) */
|
|
88
|
+
function getX(IStore _store, bytes32 key) internal view returns (int32 x) {
|
|
89
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
90
|
+
_keyTuple[0] = bytes32((key));
|
|
91
|
+
|
|
92
|
+
bytes memory _blob = _store.getField(_tableId, _keyTuple, 0);
|
|
93
|
+
return (int32(uint32(Bytes.slice4(_blob, 0))));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Set x */
|
|
97
|
+
function setX(bytes32 key, int32 x) internal {
|
|
98
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
99
|
+
_keyTuple[0] = bytes32((key));
|
|
100
|
+
|
|
101
|
+
StoreSwitch.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Set x (using the specified store) */
|
|
105
|
+
function setX(IStore _store, bytes32 key, int32 x) internal {
|
|
106
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
107
|
+
_keyTuple[0] = bytes32((key));
|
|
108
|
+
|
|
109
|
+
_store.setField(_tableId, _keyTuple, 0, abi.encodePacked((x)));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Get y */
|
|
113
|
+
function getY(bytes32 key) internal view returns (int32 y) {
|
|
114
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
115
|
+
_keyTuple[0] = bytes32((key));
|
|
116
|
+
|
|
117
|
+
bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 1);
|
|
118
|
+
return (int32(uint32(Bytes.slice4(_blob, 0))));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Get y (using the specified store) */
|
|
122
|
+
function getY(IStore _store, bytes32 key) internal view returns (int32 y) {
|
|
123
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
124
|
+
_keyTuple[0] = bytes32((key));
|
|
125
|
+
|
|
126
|
+
bytes memory _blob = _store.getField(_tableId, _keyTuple, 1);
|
|
127
|
+
return (int32(uint32(Bytes.slice4(_blob, 0))));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Set y */
|
|
131
|
+
function setY(bytes32 key, int32 y) internal {
|
|
132
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
133
|
+
_keyTuple[0] = bytes32((key));
|
|
134
|
+
|
|
135
|
+
StoreSwitch.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Set y (using the specified store) */
|
|
139
|
+
function setY(IStore _store, bytes32 key, int32 y) internal {
|
|
140
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
141
|
+
_keyTuple[0] = bytes32((key));
|
|
142
|
+
|
|
143
|
+
_store.setField(_tableId, _keyTuple, 1, abi.encodePacked((y)));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Get z */
|
|
147
|
+
function getZ(bytes32 key) internal view returns (int32 z) {
|
|
148
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
149
|
+
_keyTuple[0] = bytes32((key));
|
|
150
|
+
|
|
151
|
+
bytes memory _blob = StoreSwitch.getField(_tableId, _keyTuple, 2);
|
|
152
|
+
return (int32(uint32(Bytes.slice4(_blob, 0))));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Get z (using the specified store) */
|
|
156
|
+
function getZ(IStore _store, bytes32 key) internal view returns (int32 z) {
|
|
157
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
158
|
+
_keyTuple[0] = bytes32((key));
|
|
159
|
+
|
|
160
|
+
bytes memory _blob = _store.getField(_tableId, _keyTuple, 2);
|
|
161
|
+
return (int32(uint32(Bytes.slice4(_blob, 0))));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Set z */
|
|
165
|
+
function setZ(bytes32 key, int32 z) internal {
|
|
166
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
167
|
+
_keyTuple[0] = bytes32((key));
|
|
168
|
+
|
|
169
|
+
StoreSwitch.setField(_tableId, _keyTuple, 2, abi.encodePacked((z)));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Set z (using the specified store) */
|
|
173
|
+
function setZ(IStore _store, bytes32 key, int32 z) internal {
|
|
174
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
175
|
+
_keyTuple[0] = bytes32((key));
|
|
176
|
+
|
|
177
|
+
_store.setField(_tableId, _keyTuple, 2, abi.encodePacked((z)));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Get the full data */
|
|
181
|
+
function get(bytes32 key) internal view returns (PositionData memory _table) {
|
|
182
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
183
|
+
_keyTuple[0] = bytes32((key));
|
|
184
|
+
|
|
185
|
+
bytes memory _blob = StoreSwitch.getRecord(_tableId, _keyTuple, getSchema());
|
|
186
|
+
return decode(_blob);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Get the full data (using the specified store) */
|
|
190
|
+
function get(IStore _store, bytes32 key) internal view returns (PositionData memory _table) {
|
|
191
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
192
|
+
_keyTuple[0] = bytes32((key));
|
|
193
|
+
|
|
194
|
+
bytes memory _blob = _store.getRecord(_tableId, _keyTuple, getSchema());
|
|
195
|
+
return decode(_blob);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Set the full data using individual values */
|
|
199
|
+
function set(bytes32 key, int32 x, int32 y, int32 z) internal {
|
|
200
|
+
bytes memory _data = encode(x, y, z);
|
|
201
|
+
|
|
202
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
203
|
+
_keyTuple[0] = bytes32((key));
|
|
204
|
+
|
|
205
|
+
StoreSwitch.setRecord(_tableId, _keyTuple, _data);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Set the full data using individual values (using the specified store) */
|
|
209
|
+
function set(IStore _store, bytes32 key, int32 x, int32 y, int32 z) internal {
|
|
210
|
+
bytes memory _data = encode(x, y, z);
|
|
211
|
+
|
|
212
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
213
|
+
_keyTuple[0] = bytes32((key));
|
|
214
|
+
|
|
215
|
+
_store.setRecord(_tableId, _keyTuple, _data);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Set the full data using the data struct */
|
|
219
|
+
function set(bytes32 key, PositionData memory _table) internal {
|
|
220
|
+
set(key, _table.x, _table.y, _table.z);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Set the full data using the data struct (using the specified store) */
|
|
224
|
+
function set(IStore _store, bytes32 key, PositionData memory _table) internal {
|
|
225
|
+
set(_store, key, _table.x, _table.y, _table.z);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Decode the tightly packed blob using this table's schema */
|
|
229
|
+
function decode(bytes memory _blob) internal pure returns (PositionData memory _table) {
|
|
230
|
+
_table.x = (int32(uint32(Bytes.slice4(_blob, 0))));
|
|
231
|
+
|
|
232
|
+
_table.y = (int32(uint32(Bytes.slice4(_blob, 4))));
|
|
233
|
+
|
|
234
|
+
_table.z = (int32(uint32(Bytes.slice4(_blob, 8))));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Tightly pack full data using this table's schema */
|
|
238
|
+
function encode(int32 x, int32 y, int32 z) internal view returns (bytes memory) {
|
|
239
|
+
return abi.encodePacked(x, y, z);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Encode keys as a bytes32 array using this table's schema */
|
|
243
|
+
function encodeKeyTuple(bytes32 key) internal pure returns (bytes32[] memory _keyTuple) {
|
|
244
|
+
_keyTuple = new bytes32[](1);
|
|
245
|
+
_keyTuple[0] = bytes32((key));
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/* Delete all data for given keys */
|
|
249
|
+
function deleteRecord(bytes32 key) internal {
|
|
250
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
251
|
+
_keyTuple[0] = bytes32((key));
|
|
252
|
+
|
|
253
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/* Delete all data for given keys (using the specified store) */
|
|
257
|
+
function deleteRecord(IStore _store, bytes32 key) internal {
|
|
258
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
259
|
+
_keyTuple[0] = bytes32((key));
|
|
260
|
+
|
|
261
|
+
_store.deleteRecord(_tableId, _keyTuple);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.0;
|
|
3
|
+
|
|
4
|
+
/* Autogenerated file. Do not edit manually. */
|
|
5
|
+
|
|
6
|
+
import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol";
|
|
7
|
+
|
|
8
|
+
import { IMoveSystem } from "./IMoveSystem.sol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The IWorld interface includes all systems dynamically added to the World
|
|
12
|
+
* during the deploy process.
|
|
13
|
+
*/
|
|
14
|
+
interface IWorld is IBaseWorld, IMoveSystem {
|
|
15
|
+
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.0;
|
|
3
|
+
import { System } from "@latticexyz/world/src/System.sol";
|
|
4
|
+
import { Position, PositionData } from "../codegen/Tables.sol";
|
|
5
|
+
|
|
6
|
+
function distance(PositionData memory a, PositionData memory b) pure returns (int32) {
|
|
7
|
+
int32 deltaX = a.x > b.x ? a.x - b.x : b.x - a.x;
|
|
8
|
+
int32 deltaY = a.y > b.y ? a.y - b.y : b.y - a.y;
|
|
9
|
+
int32 deltaZ = a.z > b.z ? a.z - b.z : b.z - a.z;
|
|
10
|
+
|
|
11
|
+
return deltaX + deltaY + deltaZ;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
contract MoveSystem is System {
|
|
15
|
+
function move(int32 x, int32 y, int32 z) public {
|
|
16
|
+
bytes32 entityId = bytes32(uint256(uint160((_msgSender()))));
|
|
17
|
+
|
|
18
|
+
PositionData memory position = Position.get(entityId);
|
|
19
|
+
PositionData memory newPosition = PositionData(x, y, z);
|
|
20
|
+
|
|
21
|
+
require(distance(position, newPosition) == 1, "can only move to adjacent spaces");
|
|
22
|
+
|
|
23
|
+
Position.set(entityId, newPosition);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Visit https://aka.ms/tsconfig.json for all config options
|
|
2
|
+
{
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "ES2020",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"moduleResolution": "node"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node_modules
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mud-template-vanilla",
|
|
3
|
+
"private": true,
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "pnpm recursive run build",
|
|
6
|
+
"dev": "concurrently -n contracts,client -c cyan,magenta \"cd packages/contracts && pnpm run dev\" \"cd packages/client && pnpm run dev\"",
|
|
7
|
+
"dev:client": "pnpm --filter 'client' run dev",
|
|
8
|
+
"dev:contracts": "pnpm --filter 'contracts' dev",
|
|
9
|
+
"foundry:up": "curl -L https://foundry.paradigm.xyz | bash && bash $HOME/.foundry/bin/foundryup",
|
|
10
|
+
"initialize": "pnpm recursive run initialize",
|
|
11
|
+
"mud:up": "pnpm recursive exec mud set-version -v canary && pnpm install",
|
|
12
|
+
"prepare": "(forge --version || pnpm foundry:up)",
|
|
13
|
+
"test": "pnpm recursive run test"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@latticexyz/cli": "{{mud-version}}",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "5.46.1",
|
|
18
|
+
"@typescript-eslint/parser": "5.46.1",
|
|
19
|
+
"concurrently": "^8.0.1",
|
|
20
|
+
"eslint": "8.29.0",
|
|
21
|
+
"rimraf": "^3.0.2",
|
|
22
|
+
"typescript": "^4.9.5"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": "18.x",
|
|
26
|
+
"pnpm": "8.x"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
VITE_CHAIN_ID=31337
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "client",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"dev": "wait-port localhost:8545 && vite",
|
|
10
|
+
"initialize": "pnpm build",
|
|
11
|
+
"preview": "vite preview",
|
|
12
|
+
"test": "tsc --noEmit"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@ethersproject/providers": "^5.7.2",
|
|
16
|
+
"@latticexyz/common": "{{mud-version}}",
|
|
17
|
+
"@latticexyz/dev-tools": "{{mud-version}}",
|
|
18
|
+
"@latticexyz/network": "{{mud-version}}",
|
|
19
|
+
"@latticexyz/recs": "{{mud-version}}",
|
|
20
|
+
"@latticexyz/schema-type": "{{mud-version}}",
|
|
21
|
+
"@latticexyz/std-client": "{{mud-version}}",
|
|
22
|
+
"@latticexyz/utils": "{{mud-version}}",
|
|
23
|
+
"@latticexyz/world": "{{mud-version}}",
|
|
24
|
+
"@wagmi/chains": "^0.2.22",
|
|
25
|
+
"contracts": "workspace:*",
|
|
26
|
+
"ethers": "^5.7.2"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"vite": "^4.2.1",
|
|
30
|
+
"wait-port": "^1.0.4"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { mount as mountDevTools } from "@latticexyz/dev-tools";
|
|
2
|
+
import { setup } from "./mud/setup";
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
components,
|
|
6
|
+
systemCalls: { increment },
|
|
7
|
+
} = await setup();
|
|
8
|
+
|
|
9
|
+
// Components expose a stream that triggers when the component is updated.
|
|
10
|
+
components.Counter.update$.subscribe((update) => {
|
|
11
|
+
const [nextValue, prevValue] = update.value;
|
|
12
|
+
console.log("Counter updated", update, { nextValue, prevValue });
|
|
13
|
+
document.getElementById("counter")!.innerHTML = String(nextValue?.value ?? "unset");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// Just for demonstration purposes: we create a global function that can be
|
|
17
|
+
// called to invoke the Increment system contract via the world. (See IncrementSystem.sol.)
|
|
18
|
+
(window as any).increment = async () => {
|
|
19
|
+
console.log("new counter value:", await increment());
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
mountDevTools();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* Autogenerated file. Do not edit manually. */
|
|
2
|
+
|
|
3
|
+
import { TableId } from "@latticexyz/utils";
|
|
4
|
+
import { defineComponent, Type as RecsType, World } from "@latticexyz/recs";
|
|
5
|
+
|
|
6
|
+
export function defineContractComponents(world: World) {
|
|
7
|
+
return {
|
|
8
|
+
Counter: (() => {
|
|
9
|
+
const tableId = new TableId("", "Counter");
|
|
10
|
+
return defineComponent(
|
|
11
|
+
world,
|
|
12
|
+
{
|
|
13
|
+
value: RecsType.Number,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
metadata: {
|
|
17
|
+
contractId: tableId.toHexString(),
|
|
18
|
+
tableId: tableId.toString(),
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
})(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { SetupNetworkResult } from "./setupNetwork";
|
|
2
|
+
|
|
3
|
+
export type ClientComponents = ReturnType<typeof createClientComponents>;
|
|
4
|
+
|
|
5
|
+
export function createClientComponents({ components }: SetupNetworkResult) {
|
|
6
|
+
return {
|
|
7
|
+
...components,
|
|
8
|
+
// add your client components or overrides here
|
|
9
|
+
};
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getComponentValue } from "@latticexyz/recs";
|
|
2
|
+
import { awaitStreamValue } from "@latticexyz/utils";
|
|
3
|
+
import { ClientComponents } from "./createClientComponents";
|
|
4
|
+
import { SetupNetworkResult } from "./setupNetwork";
|
|
5
|
+
|
|
6
|
+
export type SystemCalls = ReturnType<typeof createSystemCalls>;
|
|
7
|
+
|
|
8
|
+
export function createSystemCalls(
|
|
9
|
+
{ worldSend, txReduced$, singletonEntity }: SetupNetworkResult,
|
|
10
|
+
{ Counter }: ClientComponents
|
|
11
|
+
) {
|
|
12
|
+
const increment = async () => {
|
|
13
|
+
const tx = await worldSend("increment", []);
|
|
14
|
+
await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash);
|
|
15
|
+
return getComponentValue(Counter, singletonEntity);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
increment,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { SetupContractConfig, getBurnerWallet } from "@latticexyz/std-client";
|
|
2
|
+
import worldsJson from "contracts/worlds.json";
|
|
3
|
+
import { supportedChains } from "./supportedChains";
|
|
4
|
+
|
|
5
|
+
const worlds = worldsJson as Partial<Record<string, { address: string; blockNumber?: number }>>;
|
|
6
|
+
|
|
7
|
+
type NetworkConfig = SetupContractConfig & {
|
|
8
|
+
privateKey: string;
|
|
9
|
+
faucetServiceUrl?: string;
|
|
10
|
+
snapSync?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export async function getNetworkConfig(): Promise<NetworkConfig> {
|
|
14
|
+
const params = new URLSearchParams(window.location.search);
|
|
15
|
+
|
|
16
|
+
const chainId = Number(params.get("chainId") || import.meta.env.VITE_CHAIN_ID || 31337);
|
|
17
|
+
const chainIndex = supportedChains.findIndex((c) => c.id === chainId);
|
|
18
|
+
const chain = supportedChains[chainIndex];
|
|
19
|
+
if (!chain) {
|
|
20
|
+
throw new Error(`Chain ${chainId} not found`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const world = worlds[chain.id.toString()];
|
|
24
|
+
const worldAddress = params.get("worldAddress") || world?.address;
|
|
25
|
+
if (!worldAddress) {
|
|
26
|
+
throw new Error(`No world address found for chain ${chainId}. Did you run \`mud deploy\`?`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const initialBlockNumber = params.has("initialBlockNumber")
|
|
30
|
+
? Number(params.get("initialBlockNumber"))
|
|
31
|
+
: world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
clock: {
|
|
35
|
+
period: 1000,
|
|
36
|
+
initialTime: 0,
|
|
37
|
+
syncInterval: 5000,
|
|
38
|
+
},
|
|
39
|
+
provider: {
|
|
40
|
+
chainId,
|
|
41
|
+
jsonRpcUrl: params.get("rpc") ?? chain.rpcUrls.default.http[0],
|
|
42
|
+
wsRpcUrl: params.get("wsRpc") ?? chain.rpcUrls.default.webSocket?.[0],
|
|
43
|
+
},
|
|
44
|
+
privateKey: getBurnerWallet().value,
|
|
45
|
+
chainId,
|
|
46
|
+
modeUrl: params.get("mode") ?? chain.modeUrl,
|
|
47
|
+
faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
|
|
48
|
+
worldAddress,
|
|
49
|
+
initialBlockNumber,
|
|
50
|
+
snapSync: params.get("snapSync") === "true",
|
|
51
|
+
disableCache: params.get("cache") === "false",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createClientComponents } from "./createClientComponents";
|
|
2
|
+
import { createSystemCalls } from "./createSystemCalls";
|
|
3
|
+
import { setupNetwork } from "./setupNetwork";
|
|
4
|
+
|
|
5
|
+
export type SetupResult = Awaited<ReturnType<typeof setup>>;
|
|
6
|
+
|
|
7
|
+
export async function setup() {
|
|
8
|
+
const network = await setupNetwork();
|
|
9
|
+
const components = createClientComponents(network);
|
|
10
|
+
const systemCalls = createSystemCalls(network, components);
|
|
11
|
+
return {
|
|
12
|
+
network,
|
|
13
|
+
components,
|
|
14
|
+
systemCalls,
|
|
15
|
+
};
|
|
16
|
+
}
|