create-mud 2.2.17-5aa8a3ad00aa591f9c3a60526b045257dc8a0bb5 → 2.2.17-78e9ed1294db2e924bd295734f3738bdd2786242
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/templates/react/mprocs.yaml +1 -9
- package/templates/react/packages/client/index.html +2 -2
- package/templates/react/packages/client/package.json +9 -17
- package/templates/react/packages/client/src/App.tsx +100 -41
- package/templates/react/packages/client/src/MUDContext.tsx +21 -0
- package/templates/react/packages/client/src/index.tsx +32 -17
- package/templates/react/packages/client/src/mud/createSystemCalls.ts +56 -0
- package/templates/react/packages/client/src/mud/getNetworkConfig.ts +76 -0
- package/templates/react/packages/client/src/mud/setup.ts +18 -0
- package/templates/react/packages/client/src/mud/setupNetwork.ts +101 -0
- package/templates/react/packages/client/src/mud/supportedChains.ts +20 -0
- package/templates/react/packages/client/tsconfig.json +1 -1
- package/templates/react/packages/client/vite.config.ts +7 -2
- package/templates/react/packages/contracts/.env +1 -1
- package/templates/react/packages/contracts/mud.config.ts +8 -6
- package/templates/react/packages/contracts/package.json +0 -1
- package/templates/react/packages/contracts/script/PostDeploy.s.sol +9 -1
- package/templates/react/packages/contracts/src/codegen/index.sol +1 -1
- package/templates/react/packages/contracts/src/codegen/tables/Tasks.sol +522 -0
- package/templates/{react-ecs/packages/contracts/src/codegen/world/IMoveSystem.sol → react/packages/contracts/src/codegen/world/ITasksSystem.sol} +9 -6
- package/templates/react/packages/contracts/src/codegen/world/IWorld.sol +2 -2
- package/templates/react/packages/contracts/src/systems/TasksSystem.sol +24 -0
- package/templates/react/packages/contracts/test/TasksTest.t.sol +30 -0
- package/templates/react/packages/contracts/worlds.json +1 -1
- 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/packages/contracts/src/codegen/world/IMoveSystem.sol → react-ecs/packages/contracts/src/codegen/world/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/client/postcss.config.cjs +0 -6
- package/templates/react/packages/client/src/Providers.tsx +0 -35
- package/templates/react/packages/client/src/common.ts +0 -26
- package/templates/react/packages/client/src/game/GameMap.tsx +0 -102
- package/templates/react/packages/client/src/game/useKeyboardMovement.ts +0 -26
- package/templates/react/packages/client/src/mud/Explorer.tsx +0 -32
- package/templates/react/packages/client/src/mud/Synced.tsx +0 -14
- package/templates/react/packages/client/src/mud/stash.ts +0 -4
- package/templates/react/packages/client/src/mud/useSyncStatus.ts +0 -21
- package/templates/react/packages/client/src/mud/useWorldContract.ts +0 -44
- package/templates/react/packages/client/src/ui/AsyncButton.tsx +0 -41
- package/templates/react/packages/client/src/ui/ErrorFallback.tsx +0 -58
- package/templates/react/packages/client/src/ui/icons/ArrowDownIcon.tsx +0 -22
- package/templates/react/packages/client/src/ui/icons/MUDIcon.tsx +0 -25
- package/templates/react/packages/client/src/wagmiConfig.ts +0 -49
- package/templates/react/packages/client/tailwind.config.ts +0 -10
- package/templates/react/packages/contracts/.gitignore_ +0 -13
- package/templates/react/packages/contracts/out/IWorld.sol/IWorld.abi.json +0 -2021
- package/templates/react/packages/contracts/src/MoveSystem.sol +0 -26
- package/templates/react/packages/contracts/src/codegen/common.sol +0 -11
- package/templates/react/packages/contracts/src/codegen/tables/Position.sol +0 -318
- package/templates/react/packages/contracts/test/MoveTest.t.sol +0 -25
- package/templates/react/packages/contracts/test/WorldTest.t.sol +0 -16
- 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/ISpawnSystem.sol +0 -15
- 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
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
type Entity is bytes32;
|
|
5
|
-
|
|
6
|
-
using EntityInstance for Entity global;
|
|
7
|
-
|
|
8
|
-
library EntityInstance {
|
|
9
|
-
function unwrap(Entity entity) internal pure returns (bytes32) {
|
|
10
|
-
return Entity.unwrap(entity);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function equals(Entity a, Entity b) internal pure returns (bool) {
|
|
14
|
-
return Entity.unwrap(a) == Entity.unwrap(b);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function isEmpty(Entity entity) internal pure returns (bool) {
|
|
18
|
-
return Entity.unwrap(entity) == 0;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
import { System } from "@latticexyz/world/src/System.sol";
|
|
5
|
-
|
|
6
|
-
import { Direction } from "./codegen/common.sol";
|
|
7
|
-
import { Owner } from "./codegen/tables/Owner.sol";
|
|
8
|
-
import { Position, PositionData } from "./codegen/tables/Position.sol";
|
|
9
|
-
import { Entity } from "./Entity.sol";
|
|
10
|
-
|
|
11
|
-
contract MoveSystem is System {
|
|
12
|
-
function move(Entity entity, Direction direction) public {
|
|
13
|
-
address owner = Owner.get(entity);
|
|
14
|
-
require(owner == _msgSender(), "You cannot move this entity.");
|
|
15
|
-
|
|
16
|
-
PositionData memory position = Position.get(entity);
|
|
17
|
-
|
|
18
|
-
if (direction == Direction.North) {
|
|
19
|
-
position.y += 1;
|
|
20
|
-
} else if (direction == Direction.East) {
|
|
21
|
-
position.x += 1;
|
|
22
|
-
} else if (direction == Direction.South) {
|
|
23
|
-
position.y -= 1;
|
|
24
|
-
} else if (direction == Direction.West) {
|
|
25
|
-
position.x -= 1;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
Position.set(entity, position);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
import { System } from "@latticexyz/world/src/System.sol";
|
|
5
|
-
|
|
6
|
-
import { Direction } from "./codegen/common.sol";
|
|
7
|
-
import { Owner } from "./codegen/tables/Owner.sol";
|
|
8
|
-
import { Position } from "./codegen/tables/Position.sol";
|
|
9
|
-
import { Entity } from "./Entity.sol";
|
|
10
|
-
import { createEntity } from "./createEntity.sol";
|
|
11
|
-
|
|
12
|
-
contract SpawnSystem is System {
|
|
13
|
-
function spawn() public returns (Entity entity) {
|
|
14
|
-
entity = createEntity();
|
|
15
|
-
Owner.set(entity, _msgSender());
|
|
16
|
-
Position.set(entity, 0, 0);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
/* Autogenerated file. Do not edit manually. */
|
|
5
|
-
|
|
6
|
-
// Import store internals
|
|
7
|
-
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
|
8
|
-
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
|
9
|
-
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
|
|
10
|
-
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
|
11
|
-
import { Memory } from "@latticexyz/store/src/Memory.sol";
|
|
12
|
-
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
|
|
13
|
-
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
|
14
|
-
import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol";
|
|
15
|
-
import { Schema } from "@latticexyz/store/src/Schema.sol";
|
|
16
|
-
import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol";
|
|
17
|
-
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
|
18
|
-
|
|
19
|
-
// Import user types
|
|
20
|
-
import { Entity } from "../../Entity.sol";
|
|
21
|
-
|
|
22
|
-
library Owner {
|
|
23
|
-
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "app", name: "Owner", typeId: RESOURCE_TABLE });`
|
|
24
|
-
ResourceId constant _tableId = ResourceId.wrap(0x746261707000000000000000000000004f776e65720000000000000000000000);
|
|
25
|
-
|
|
26
|
-
FieldLayout constant _fieldLayout =
|
|
27
|
-
FieldLayout.wrap(0x0014010014000000000000000000000000000000000000000000000000000000);
|
|
28
|
-
|
|
29
|
-
// Hex-encoded key schema of (bytes32)
|
|
30
|
-
Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000);
|
|
31
|
-
// Hex-encoded value schema of (address)
|
|
32
|
-
Schema constant _valueSchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000);
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @notice Get the table's key field names.
|
|
36
|
-
* @return keyNames An array of strings with the names of key fields.
|
|
37
|
-
*/
|
|
38
|
-
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
|
39
|
-
keyNames = new string[](1);
|
|
40
|
-
keyNames[0] = "id";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @notice Get the table's value field names.
|
|
45
|
-
* @return fieldNames An array of strings with the names of value fields.
|
|
46
|
-
*/
|
|
47
|
-
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
|
48
|
-
fieldNames = new string[](1);
|
|
49
|
-
fieldNames[0] = "owner";
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @notice Register the table with its config.
|
|
54
|
-
*/
|
|
55
|
-
function register() internal {
|
|
56
|
-
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @notice Register the table with its config.
|
|
61
|
-
*/
|
|
62
|
-
function _register() internal {
|
|
63
|
-
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @notice Get owner.
|
|
68
|
-
*/
|
|
69
|
-
function getOwner(Entity id) internal view returns (address owner) {
|
|
70
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
71
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
72
|
-
|
|
73
|
-
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
74
|
-
return (address(bytes20(_blob)));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @notice Get owner.
|
|
79
|
-
*/
|
|
80
|
-
function _getOwner(Entity id) internal view returns (address owner) {
|
|
81
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
82
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
83
|
-
|
|
84
|
-
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
85
|
-
return (address(bytes20(_blob)));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @notice Get owner.
|
|
90
|
-
*/
|
|
91
|
-
function get(Entity id) internal view returns (address owner) {
|
|
92
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
93
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
94
|
-
|
|
95
|
-
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
96
|
-
return (address(bytes20(_blob)));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @notice Get owner.
|
|
101
|
-
*/
|
|
102
|
-
function _get(Entity id) internal view returns (address owner) {
|
|
103
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
104
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
105
|
-
|
|
106
|
-
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
107
|
-
return (address(bytes20(_blob)));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* @notice Set owner.
|
|
112
|
-
*/
|
|
113
|
-
function setOwner(Entity id, address owner) internal {
|
|
114
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
115
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
116
|
-
|
|
117
|
-
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @notice Set owner.
|
|
122
|
-
*/
|
|
123
|
-
function _setOwner(Entity id, address owner) internal {
|
|
124
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
125
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
126
|
-
|
|
127
|
-
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @notice Set owner.
|
|
132
|
-
*/
|
|
133
|
-
function set(Entity id, address owner) internal {
|
|
134
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
135
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
136
|
-
|
|
137
|
-
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* @notice Set owner.
|
|
142
|
-
*/
|
|
143
|
-
function _set(Entity id, address owner) internal {
|
|
144
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
145
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
146
|
-
|
|
147
|
-
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((owner)), _fieldLayout);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* @notice Delete all data for given keys.
|
|
152
|
-
*/
|
|
153
|
-
function deleteRecord(Entity id) internal {
|
|
154
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
155
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
156
|
-
|
|
157
|
-
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @notice Delete all data for given keys.
|
|
162
|
-
*/
|
|
163
|
-
function _deleteRecord(Entity id) internal {
|
|
164
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
165
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
166
|
-
|
|
167
|
-
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @notice Tightly pack static (fixed length) data using this table's schema.
|
|
172
|
-
* @return The static data, encoded into a sequence of bytes.
|
|
173
|
-
*/
|
|
174
|
-
function encodeStatic(address owner) internal pure returns (bytes memory) {
|
|
175
|
-
return abi.encodePacked(owner);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* @notice Encode all of a record's fields.
|
|
180
|
-
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
|
181
|
-
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
|
182
|
-
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
|
183
|
-
*/
|
|
184
|
-
function encode(address owner) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
|
185
|
-
bytes memory _staticData = encodeStatic(owner);
|
|
186
|
-
|
|
187
|
-
EncodedLengths _encodedLengths;
|
|
188
|
-
bytes memory _dynamicData;
|
|
189
|
-
|
|
190
|
-
return (_staticData, _encodedLengths, _dynamicData);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* @notice Encode keys as a bytes32 array using this table's field layout.
|
|
195
|
-
*/
|
|
196
|
-
function encodeKeyTuple(Entity id) internal pure returns (bytes32[] memory) {
|
|
197
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
198
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
199
|
-
|
|
200
|
-
return _keyTuple;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
/* Autogenerated file. Do not edit manually. */
|
|
5
|
-
|
|
6
|
-
// Import store internals
|
|
7
|
-
import { IStore } from "@latticexyz/store/src/IStore.sol";
|
|
8
|
-
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
|
9
|
-
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
|
|
10
|
-
import { Bytes } from "@latticexyz/store/src/Bytes.sol";
|
|
11
|
-
import { Memory } from "@latticexyz/store/src/Memory.sol";
|
|
12
|
-
import { SliceLib } from "@latticexyz/store/src/Slice.sol";
|
|
13
|
-
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
|
|
14
|
-
import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol";
|
|
15
|
-
import { Schema } from "@latticexyz/store/src/Schema.sol";
|
|
16
|
-
import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol";
|
|
17
|
-
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";
|
|
18
|
-
|
|
19
|
-
// Import user types
|
|
20
|
-
import { Entity } from "../../Entity.sol";
|
|
21
|
-
|
|
22
|
-
struct PositionData {
|
|
23
|
-
int32 x;
|
|
24
|
-
int32 y;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
library Position {
|
|
28
|
-
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "app", name: "Position", typeId: RESOURCE_TABLE });`
|
|
29
|
-
ResourceId constant _tableId = ResourceId.wrap(0x74626170700000000000000000000000506f736974696f6e0000000000000000);
|
|
30
|
-
|
|
31
|
-
FieldLayout constant _fieldLayout =
|
|
32
|
-
FieldLayout.wrap(0x0008020004040000000000000000000000000000000000000000000000000000);
|
|
33
|
-
|
|
34
|
-
// Hex-encoded key schema of (bytes32)
|
|
35
|
-
Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000);
|
|
36
|
-
// Hex-encoded value schema of (int32, int32)
|
|
37
|
-
Schema constant _valueSchema = Schema.wrap(0x0008020023230000000000000000000000000000000000000000000000000000);
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @notice Get the table's key field names.
|
|
41
|
-
* @return keyNames An array of strings with the names of key fields.
|
|
42
|
-
*/
|
|
43
|
-
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
|
44
|
-
keyNames = new string[](1);
|
|
45
|
-
keyNames[0] = "id";
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @notice Get the table's value field names.
|
|
50
|
-
* @return fieldNames An array of strings with the names of value fields.
|
|
51
|
-
*/
|
|
52
|
-
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
|
53
|
-
fieldNames = new string[](2);
|
|
54
|
-
fieldNames[0] = "x";
|
|
55
|
-
fieldNames[1] = "y";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @notice Register the table with its config.
|
|
60
|
-
*/
|
|
61
|
-
function register() internal {
|
|
62
|
-
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @notice Register the table with its config.
|
|
67
|
-
*/
|
|
68
|
-
function _register() internal {
|
|
69
|
-
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @notice Get x.
|
|
74
|
-
*/
|
|
75
|
-
function getX(Entity id) internal view returns (int32 x) {
|
|
76
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
77
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
78
|
-
|
|
79
|
-
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
80
|
-
return (int32(uint32(bytes4(_blob))));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @notice Get x.
|
|
85
|
-
*/
|
|
86
|
-
function _getX(Entity id) internal view returns (int32 x) {
|
|
87
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
88
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
89
|
-
|
|
90
|
-
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
91
|
-
return (int32(uint32(bytes4(_blob))));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @notice Set x.
|
|
96
|
-
*/
|
|
97
|
-
function setX(Entity id, int32 x) internal {
|
|
98
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
99
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
100
|
-
|
|
101
|
-
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @notice Set x.
|
|
106
|
-
*/
|
|
107
|
-
function _setX(Entity id, int32 x) internal {
|
|
108
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
109
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
110
|
-
|
|
111
|
-
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((x)), _fieldLayout);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* @notice Get y.
|
|
116
|
-
*/
|
|
117
|
-
function getY(Entity id) internal view returns (int32 y) {
|
|
118
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
119
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
120
|
-
|
|
121
|
-
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout);
|
|
122
|
-
return (int32(uint32(bytes4(_blob))));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @notice Get y.
|
|
127
|
-
*/
|
|
128
|
-
function _getY(Entity id) internal view returns (int32 y) {
|
|
129
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
130
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
131
|
-
|
|
132
|
-
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout);
|
|
133
|
-
return (int32(uint32(bytes4(_blob))));
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* @notice Set y.
|
|
138
|
-
*/
|
|
139
|
-
function setY(Entity id, int32 y) internal {
|
|
140
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
141
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
142
|
-
|
|
143
|
-
StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @notice Set y.
|
|
148
|
-
*/
|
|
149
|
-
function _setY(Entity id, int32 y) internal {
|
|
150
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
151
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
152
|
-
|
|
153
|
-
StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((y)), _fieldLayout);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* @notice Get the full data.
|
|
158
|
-
*/
|
|
159
|
-
function get(Entity id) internal view returns (PositionData memory _table) {
|
|
160
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
161
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
162
|
-
|
|
163
|
-
(bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord(
|
|
164
|
-
_tableId,
|
|
165
|
-
_keyTuple,
|
|
166
|
-
_fieldLayout
|
|
167
|
-
);
|
|
168
|
-
return decode(_staticData, _encodedLengths, _dynamicData);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* @notice Get the full data.
|
|
173
|
-
*/
|
|
174
|
-
function _get(Entity id) internal view returns (PositionData memory _table) {
|
|
175
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
176
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
177
|
-
|
|
178
|
-
(bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord(
|
|
179
|
-
_tableId,
|
|
180
|
-
_keyTuple,
|
|
181
|
-
_fieldLayout
|
|
182
|
-
);
|
|
183
|
-
return decode(_staticData, _encodedLengths, _dynamicData);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* @notice Set the full data using individual values.
|
|
188
|
-
*/
|
|
189
|
-
function set(Entity id, int32 x, int32 y) internal {
|
|
190
|
-
bytes memory _staticData = encodeStatic(x, y);
|
|
191
|
-
|
|
192
|
-
EncodedLengths _encodedLengths;
|
|
193
|
-
bytes memory _dynamicData;
|
|
194
|
-
|
|
195
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
196
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
197
|
-
|
|
198
|
-
StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* @notice Set the full data using individual values.
|
|
203
|
-
*/
|
|
204
|
-
function _set(Entity id, int32 x, int32 y) internal {
|
|
205
|
-
bytes memory _staticData = encodeStatic(x, y);
|
|
206
|
-
|
|
207
|
-
EncodedLengths _encodedLengths;
|
|
208
|
-
bytes memory _dynamicData;
|
|
209
|
-
|
|
210
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
211
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
212
|
-
|
|
213
|
-
StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* @notice Set the full data using the data struct.
|
|
218
|
-
*/
|
|
219
|
-
function set(Entity id, PositionData memory _table) internal {
|
|
220
|
-
bytes memory _staticData = encodeStatic(_table.x, _table.y);
|
|
221
|
-
|
|
222
|
-
EncodedLengths _encodedLengths;
|
|
223
|
-
bytes memory _dynamicData;
|
|
224
|
-
|
|
225
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
226
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
227
|
-
|
|
228
|
-
StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* @notice Set the full data using the data struct.
|
|
233
|
-
*/
|
|
234
|
-
function _set(Entity id, PositionData memory _table) internal {
|
|
235
|
-
bytes memory _staticData = encodeStatic(_table.x, _table.y);
|
|
236
|
-
|
|
237
|
-
EncodedLengths _encodedLengths;
|
|
238
|
-
bytes memory _dynamicData;
|
|
239
|
-
|
|
240
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
241
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
242
|
-
|
|
243
|
-
StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* @notice Decode the tightly packed blob of static data using this table's field layout.
|
|
248
|
-
*/
|
|
249
|
-
function decodeStatic(bytes memory _blob) internal pure returns (int32 x, int32 y) {
|
|
250
|
-
x = (int32(uint32(Bytes.getBytes4(_blob, 0))));
|
|
251
|
-
|
|
252
|
-
y = (int32(uint32(Bytes.getBytes4(_blob, 4))));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* @notice Decode the tightly packed blobs using this table's field layout.
|
|
257
|
-
* @param _staticData Tightly packed static fields.
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*/
|
|
261
|
-
function decode(
|
|
262
|
-
bytes memory _staticData,
|
|
263
|
-
EncodedLengths,
|
|
264
|
-
bytes memory
|
|
265
|
-
) internal pure returns (PositionData memory _table) {
|
|
266
|
-
(_table.x, _table.y) = decodeStatic(_staticData);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* @notice Delete all data for given keys.
|
|
271
|
-
*/
|
|
272
|
-
function deleteRecord(Entity id) internal {
|
|
273
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
274
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
275
|
-
|
|
276
|
-
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* @notice Delete all data for given keys.
|
|
281
|
-
*/
|
|
282
|
-
function _deleteRecord(Entity id) internal {
|
|
283
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
284
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
285
|
-
|
|
286
|
-
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* @notice Tightly pack static (fixed length) data using this table's schema.
|
|
291
|
-
* @return The static data, encoded into a sequence of bytes.
|
|
292
|
-
*/
|
|
293
|
-
function encodeStatic(int32 x, int32 y) internal pure returns (bytes memory) {
|
|
294
|
-
return abi.encodePacked(x, y);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* @notice Encode all of a record's fields.
|
|
299
|
-
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
|
300
|
-
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
|
301
|
-
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
|
302
|
-
*/
|
|
303
|
-
function encode(int32 x, int32 y) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
|
304
|
-
bytes memory _staticData = encodeStatic(x, y);
|
|
305
|
-
|
|
306
|
-
EncodedLengths _encodedLengths;
|
|
307
|
-
bytes memory _dynamicData;
|
|
308
|
-
|
|
309
|
-
return (_staticData, _encodedLengths, _dynamicData);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* @notice Encode keys as a bytes32 array using this table's field layout.
|
|
314
|
-
*/
|
|
315
|
-
function encodeKeyTuple(Entity id) internal pure returns (bytes32[] memory) {
|
|
316
|
-
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
317
|
-
_keyTuple[0] = Entity.unwrap(id);
|
|
318
|
-
|
|
319
|
-
return _keyTuple;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
/* Autogenerated file. Do not edit manually. */
|
|
5
|
-
|
|
6
|
-
import { Entity } from "../../Entity.sol";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @title ISpawnSystem
|
|
10
|
-
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
|
|
11
|
-
* @dev This interface is automatically generated from the corresponding system contract. Do not edit manually.
|
|
12
|
-
*/
|
|
13
|
-
interface ISpawnSystem {
|
|
14
|
-
function app__spawn() external returns (Entity entity);
|
|
15
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
import { Entity } from "./Entity.sol";
|
|
5
|
-
import { EntityCount } from "./codegen/tables/EntityCount.sol";
|
|
6
|
-
|
|
7
|
-
function createEntity() returns (Entity entity) {
|
|
8
|
-
uint256 next = EntityCount.get() + 1;
|
|
9
|
-
EntityCount.set(next);
|
|
10
|
-
return Entity.wrap(bytes32(next));
|
|
11
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
import "forge-std/Test.sol";
|
|
5
|
-
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
|
|
6
|
-
|
|
7
|
-
import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
8
|
-
import { Owner } from "../src/codegen/tables/Owner.sol";
|
|
9
|
-
import { Position, PositionData } from "../src/codegen/tables/Position.sol";
|
|
10
|
-
import { Direction } from "../src/codegen/common.sol";
|
|
11
|
-
import { Entity } from "../src/Entity.sol";
|
|
12
|
-
|
|
13
|
-
contract MoveTest is MudTest {
|
|
14
|
-
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
|
|
15
|
-
address deployer = vm.addr(deployerPrivateKey);
|
|
16
|
-
|
|
17
|
-
address alice = vm.addr(uint256(keccak256("alice")));
|
|
18
|
-
address bob = vm.addr(uint256(keccak256("bob")));
|
|
19
|
-
|
|
20
|
-
function testMove() public {
|
|
21
|
-
Entity entity = Entity.wrap(keccak256("entity"));
|
|
22
|
-
vm.prank(deployer);
|
|
23
|
-
Owner.set(entity, alice);
|
|
24
|
-
|
|
25
|
-
PositionData memory position = Position.get(entity);
|
|
26
|
-
assertEq(position.x, 0);
|
|
27
|
-
assertEq(position.y, 0);
|
|
28
|
-
|
|
29
|
-
vm.prank(alice);
|
|
30
|
-
IWorld(worldAddress).app__move(entity, Direction.North);
|
|
31
|
-
position = Position.get(entity);
|
|
32
|
-
assertEq(position.x, 0);
|
|
33
|
-
assertEq(position.y, 1);
|
|
34
|
-
|
|
35
|
-
vm.prank(bob);
|
|
36
|
-
vm.expectRevert("You cannot move this entity.");
|
|
37
|
-
IWorld(worldAddress).app__move(entity, Direction.North);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
pragma solidity >=0.8.24;
|
|
3
|
-
|
|
4
|
-
import "forge-std/Test.sol";
|
|
5
|
-
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
|
|
6
|
-
|
|
7
|
-
contract WorldTest is MudTest {
|
|
8
|
-
function testWorldDeployed() public {
|
|
9
|
-
uint256 codeSize;
|
|
10
|
-
address addr = worldAddress;
|
|
11
|
-
assembly {
|
|
12
|
-
codeSize := extcodesize(addr)
|
|
13
|
-
}
|
|
14
|
-
assertTrue(codeSize > 0);
|
|
15
|
-
}
|
|
16
|
-
}
|