create-mud 2.2.17-6e19b86633174dbbf98eb1a2b4446ef6f0b22ab7 → 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,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,13 +2,15 @@ import { defineWorld } from "@latticexyz/world";
|
|
|
2
2
|
|
|
3
3
|
export default defineWorld({
|
|
4
4
|
namespace: "app",
|
|
5
|
-
enums: {
|
|
6
|
-
Direction: ["North", "East", "South", "West"],
|
|
7
|
-
},
|
|
8
5
|
tables: {
|
|
9
|
-
|
|
10
|
-
schema: {
|
|
11
|
-
|
|
6
|
+
Tasks: {
|
|
7
|
+
schema: {
|
|
8
|
+
id: "bytes32",
|
|
9
|
+
createdAt: "uint256",
|
|
10
|
+
completedAt: "uint256",
|
|
11
|
+
description: "string",
|
|
12
|
+
},
|
|
13
|
+
key: ["id"],
|
|
12
14
|
},
|
|
13
15
|
},
|
|
14
16
|
});
|
|
@@ -6,6 +6,7 @@ import { console } from "forge-std/console.sol";
|
|
|
6
6
|
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
|
|
7
7
|
|
|
8
8
|
import { IWorld } from "../src/codegen/world/IWorld.sol";
|
|
9
|
+
import { Tasks, TasksData } from "../src/codegen/index.sol";
|
|
9
10
|
|
|
10
11
|
contract PostDeploy is Script {
|
|
11
12
|
function run(address worldAddress) external {
|
|
@@ -18,7 +19,14 @@ contract PostDeploy is Script {
|
|
|
18
19
|
// Start broadcasting transactions from the deployer account
|
|
19
20
|
vm.startBroadcast(deployerPrivateKey);
|
|
20
21
|
|
|
21
|
-
//
|
|
22
|
+
// We can set table records directly
|
|
23
|
+
Tasks.set("1", TasksData({ description: "Walk the dog", createdAt: block.timestamp, completedAt: 0 }));
|
|
24
|
+
|
|
25
|
+
// Or we can call our own systems
|
|
26
|
+
IWorld(worldAddress).app__addTask("Take out the trash");
|
|
27
|
+
|
|
28
|
+
bytes32 key = IWorld(worldAddress).app__addTask("Do the dishes");
|
|
29
|
+
IWorld(worldAddress).app__completeTask(key);
|
|
22
30
|
|
|
23
31
|
vm.stopBroadcast();
|
|
24
32
|
}
|
|
@@ -0,0 +1,522 @@
|
|
|
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
|
+
struct TasksData {
|
|
20
|
+
uint256 createdAt;
|
|
21
|
+
uint256 completedAt;
|
|
22
|
+
string description;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
library Tasks {
|
|
26
|
+
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "app", name: "Tasks", typeId: RESOURCE_TABLE });`
|
|
27
|
+
ResourceId constant _tableId = ResourceId.wrap(0x746261707000000000000000000000005461736b730000000000000000000000);
|
|
28
|
+
|
|
29
|
+
FieldLayout constant _fieldLayout =
|
|
30
|
+
FieldLayout.wrap(0x0040020120200000000000000000000000000000000000000000000000000000);
|
|
31
|
+
|
|
32
|
+
// Hex-encoded key schema of (bytes32)
|
|
33
|
+
Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000);
|
|
34
|
+
// Hex-encoded value schema of (uint256, uint256, string)
|
|
35
|
+
Schema constant _valueSchema = Schema.wrap(0x004002011f1fc500000000000000000000000000000000000000000000000000);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @notice Get the table's key field names.
|
|
39
|
+
* @return keyNames An array of strings with the names of key fields.
|
|
40
|
+
*/
|
|
41
|
+
function getKeyNames() internal pure returns (string[] memory keyNames) {
|
|
42
|
+
keyNames = new string[](1);
|
|
43
|
+
keyNames[0] = "id";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @notice Get the table's value field names.
|
|
48
|
+
* @return fieldNames An array of strings with the names of value fields.
|
|
49
|
+
*/
|
|
50
|
+
function getFieldNames() internal pure returns (string[] memory fieldNames) {
|
|
51
|
+
fieldNames = new string[](3);
|
|
52
|
+
fieldNames[0] = "createdAt";
|
|
53
|
+
fieldNames[1] = "completedAt";
|
|
54
|
+
fieldNames[2] = "description";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @notice Register the table with its config.
|
|
59
|
+
*/
|
|
60
|
+
function register() internal {
|
|
61
|
+
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @notice Register the table with its config.
|
|
66
|
+
*/
|
|
67
|
+
function _register() internal {
|
|
68
|
+
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @notice Get createdAt.
|
|
73
|
+
*/
|
|
74
|
+
function getCreatedAt(bytes32 id) internal view returns (uint256 createdAt) {
|
|
75
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
76
|
+
_keyTuple[0] = id;
|
|
77
|
+
|
|
78
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
79
|
+
return (uint256(bytes32(_blob)));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @notice Get createdAt.
|
|
84
|
+
*/
|
|
85
|
+
function _getCreatedAt(bytes32 id) internal view returns (uint256 createdAt) {
|
|
86
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
87
|
+
_keyTuple[0] = id;
|
|
88
|
+
|
|
89
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
|
|
90
|
+
return (uint256(bytes32(_blob)));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @notice Set createdAt.
|
|
95
|
+
*/
|
|
96
|
+
function setCreatedAt(bytes32 id, uint256 createdAt) internal {
|
|
97
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
98
|
+
_keyTuple[0] = id;
|
|
99
|
+
|
|
100
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((createdAt)), _fieldLayout);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @notice Set createdAt.
|
|
105
|
+
*/
|
|
106
|
+
function _setCreatedAt(bytes32 id, uint256 createdAt) internal {
|
|
107
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
108
|
+
_keyTuple[0] = id;
|
|
109
|
+
|
|
110
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((createdAt)), _fieldLayout);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @notice Get completedAt.
|
|
115
|
+
*/
|
|
116
|
+
function getCompletedAt(bytes32 id) internal view returns (uint256 completedAt) {
|
|
117
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
118
|
+
_keyTuple[0] = id;
|
|
119
|
+
|
|
120
|
+
bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout);
|
|
121
|
+
return (uint256(bytes32(_blob)));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @notice Get completedAt.
|
|
126
|
+
*/
|
|
127
|
+
function _getCompletedAt(bytes32 id) internal view returns (uint256 completedAt) {
|
|
128
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
129
|
+
_keyTuple[0] = id;
|
|
130
|
+
|
|
131
|
+
bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout);
|
|
132
|
+
return (uint256(bytes32(_blob)));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @notice Set completedAt.
|
|
137
|
+
*/
|
|
138
|
+
function setCompletedAt(bytes32 id, uint256 completedAt) internal {
|
|
139
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
140
|
+
_keyTuple[0] = id;
|
|
141
|
+
|
|
142
|
+
StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((completedAt)), _fieldLayout);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @notice Set completedAt.
|
|
147
|
+
*/
|
|
148
|
+
function _setCompletedAt(bytes32 id, uint256 completedAt) internal {
|
|
149
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
150
|
+
_keyTuple[0] = id;
|
|
151
|
+
|
|
152
|
+
StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((completedAt)), _fieldLayout);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @notice Get description.
|
|
157
|
+
*/
|
|
158
|
+
function getDescription(bytes32 id) internal view returns (string memory description) {
|
|
159
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
160
|
+
_keyTuple[0] = id;
|
|
161
|
+
|
|
162
|
+
bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0);
|
|
163
|
+
return (string(_blob));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @notice Get description.
|
|
168
|
+
*/
|
|
169
|
+
function _getDescription(bytes32 id) internal view returns (string memory description) {
|
|
170
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
171
|
+
_keyTuple[0] = id;
|
|
172
|
+
|
|
173
|
+
bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0);
|
|
174
|
+
return (string(_blob));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @notice Set description.
|
|
179
|
+
*/
|
|
180
|
+
function setDescription(bytes32 id, string memory description) internal {
|
|
181
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
182
|
+
_keyTuple[0] = id;
|
|
183
|
+
|
|
184
|
+
StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, bytes((description)));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @notice Set description.
|
|
189
|
+
*/
|
|
190
|
+
function _setDescription(bytes32 id, string memory description) internal {
|
|
191
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
192
|
+
_keyTuple[0] = id;
|
|
193
|
+
|
|
194
|
+
StoreCore.setDynamicField(_tableId, _keyTuple, 0, bytes((description)));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @notice Get the length of description.
|
|
199
|
+
*/
|
|
200
|
+
function lengthDescription(bytes32 id) internal view returns (uint256) {
|
|
201
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
202
|
+
_keyTuple[0] = id;
|
|
203
|
+
|
|
204
|
+
uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
|
205
|
+
unchecked {
|
|
206
|
+
return _byteLength / 1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @notice Get the length of description.
|
|
212
|
+
*/
|
|
213
|
+
function _lengthDescription(bytes32 id) internal view returns (uint256) {
|
|
214
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
215
|
+
_keyTuple[0] = id;
|
|
216
|
+
|
|
217
|
+
uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0);
|
|
218
|
+
unchecked {
|
|
219
|
+
return _byteLength / 1;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* @notice Get an item of description.
|
|
225
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
|
226
|
+
*/
|
|
227
|
+
function getItemDescription(bytes32 id, uint256 _index) internal view returns (string memory) {
|
|
228
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
229
|
+
_keyTuple[0] = id;
|
|
230
|
+
|
|
231
|
+
unchecked {
|
|
232
|
+
bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1);
|
|
233
|
+
return (string(_blob));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @notice Get an item of description.
|
|
239
|
+
* @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array.
|
|
240
|
+
*/
|
|
241
|
+
function _getItemDescription(bytes32 id, uint256 _index) internal view returns (string memory) {
|
|
242
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
243
|
+
_keyTuple[0] = id;
|
|
244
|
+
|
|
245
|
+
unchecked {
|
|
246
|
+
bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1);
|
|
247
|
+
return (string(_blob));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @notice Push a slice to description.
|
|
253
|
+
*/
|
|
254
|
+
function pushDescription(bytes32 id, string memory _slice) internal {
|
|
255
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
256
|
+
_keyTuple[0] = id;
|
|
257
|
+
|
|
258
|
+
StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice)));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* @notice Push a slice to description.
|
|
263
|
+
*/
|
|
264
|
+
function _pushDescription(bytes32 id, string memory _slice) internal {
|
|
265
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
266
|
+
_keyTuple[0] = id;
|
|
267
|
+
|
|
268
|
+
StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice)));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* @notice Pop a slice from description.
|
|
273
|
+
*/
|
|
274
|
+
function popDescription(bytes32 id) internal {
|
|
275
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
276
|
+
_keyTuple[0] = id;
|
|
277
|
+
|
|
278
|
+
StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 1);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @notice Pop a slice from description.
|
|
283
|
+
*/
|
|
284
|
+
function _popDescription(bytes32 id) internal {
|
|
285
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
286
|
+
_keyTuple[0] = id;
|
|
287
|
+
|
|
288
|
+
StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 1);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* @notice Update a slice of description at `_index`.
|
|
293
|
+
*/
|
|
294
|
+
function updateDescription(bytes32 id, uint256 _index, string memory _slice) internal {
|
|
295
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
296
|
+
_keyTuple[0] = id;
|
|
297
|
+
|
|
298
|
+
unchecked {
|
|
299
|
+
bytes memory _encoded = bytes((_slice));
|
|
300
|
+
StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* @notice Update a slice of description at `_index`.
|
|
306
|
+
*/
|
|
307
|
+
function _updateDescription(bytes32 id, uint256 _index, string memory _slice) internal {
|
|
308
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
309
|
+
_keyTuple[0] = id;
|
|
310
|
+
|
|
311
|
+
unchecked {
|
|
312
|
+
bytes memory _encoded = bytes((_slice));
|
|
313
|
+
StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* @notice Get the full data.
|
|
319
|
+
*/
|
|
320
|
+
function get(bytes32 id) internal view returns (TasksData memory _table) {
|
|
321
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
322
|
+
_keyTuple[0] = id;
|
|
323
|
+
|
|
324
|
+
(bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord(
|
|
325
|
+
_tableId,
|
|
326
|
+
_keyTuple,
|
|
327
|
+
_fieldLayout
|
|
328
|
+
);
|
|
329
|
+
return decode(_staticData, _encodedLengths, _dynamicData);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @notice Get the full data.
|
|
334
|
+
*/
|
|
335
|
+
function _get(bytes32 id) internal view returns (TasksData memory _table) {
|
|
336
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
337
|
+
_keyTuple[0] = id;
|
|
338
|
+
|
|
339
|
+
(bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord(
|
|
340
|
+
_tableId,
|
|
341
|
+
_keyTuple,
|
|
342
|
+
_fieldLayout
|
|
343
|
+
);
|
|
344
|
+
return decode(_staticData, _encodedLengths, _dynamicData);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* @notice Set the full data using individual values.
|
|
349
|
+
*/
|
|
350
|
+
function set(bytes32 id, uint256 createdAt, uint256 completedAt, string memory description) internal {
|
|
351
|
+
bytes memory _staticData = encodeStatic(createdAt, completedAt);
|
|
352
|
+
|
|
353
|
+
EncodedLengths _encodedLengths = encodeLengths(description);
|
|
354
|
+
bytes memory _dynamicData = encodeDynamic(description);
|
|
355
|
+
|
|
356
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
357
|
+
_keyTuple[0] = id;
|
|
358
|
+
|
|
359
|
+
StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* @notice Set the full data using individual values.
|
|
364
|
+
*/
|
|
365
|
+
function _set(bytes32 id, uint256 createdAt, uint256 completedAt, string memory description) internal {
|
|
366
|
+
bytes memory _staticData = encodeStatic(createdAt, completedAt);
|
|
367
|
+
|
|
368
|
+
EncodedLengths _encodedLengths = encodeLengths(description);
|
|
369
|
+
bytes memory _dynamicData = encodeDynamic(description);
|
|
370
|
+
|
|
371
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
372
|
+
_keyTuple[0] = id;
|
|
373
|
+
|
|
374
|
+
StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* @notice Set the full data using the data struct.
|
|
379
|
+
*/
|
|
380
|
+
function set(bytes32 id, TasksData memory _table) internal {
|
|
381
|
+
bytes memory _staticData = encodeStatic(_table.createdAt, _table.completedAt);
|
|
382
|
+
|
|
383
|
+
EncodedLengths _encodedLengths = encodeLengths(_table.description);
|
|
384
|
+
bytes memory _dynamicData = encodeDynamic(_table.description);
|
|
385
|
+
|
|
386
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
387
|
+
_keyTuple[0] = id;
|
|
388
|
+
|
|
389
|
+
StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* @notice Set the full data using the data struct.
|
|
394
|
+
*/
|
|
395
|
+
function _set(bytes32 id, TasksData memory _table) internal {
|
|
396
|
+
bytes memory _staticData = encodeStatic(_table.createdAt, _table.completedAt);
|
|
397
|
+
|
|
398
|
+
EncodedLengths _encodedLengths = encodeLengths(_table.description);
|
|
399
|
+
bytes memory _dynamicData = encodeDynamic(_table.description);
|
|
400
|
+
|
|
401
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
402
|
+
_keyTuple[0] = id;
|
|
403
|
+
|
|
404
|
+
StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* @notice Decode the tightly packed blob of static data using this table's field layout.
|
|
409
|
+
*/
|
|
410
|
+
function decodeStatic(bytes memory _blob) internal pure returns (uint256 createdAt, uint256 completedAt) {
|
|
411
|
+
createdAt = (uint256(Bytes.getBytes32(_blob, 0)));
|
|
412
|
+
|
|
413
|
+
completedAt = (uint256(Bytes.getBytes32(_blob, 32)));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* @notice Decode the tightly packed blob of dynamic data using the encoded lengths.
|
|
418
|
+
*/
|
|
419
|
+
function decodeDynamic(
|
|
420
|
+
EncodedLengths _encodedLengths,
|
|
421
|
+
bytes memory _blob
|
|
422
|
+
) internal pure returns (string memory description) {
|
|
423
|
+
uint256 _start;
|
|
424
|
+
uint256 _end;
|
|
425
|
+
unchecked {
|
|
426
|
+
_end = _encodedLengths.atIndex(0);
|
|
427
|
+
}
|
|
428
|
+
description = (string(SliceLib.getSubslice(_blob, _start, _end).toBytes()));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* @notice Decode the tightly packed blobs using this table's field layout.
|
|
433
|
+
* @param _staticData Tightly packed static fields.
|
|
434
|
+
* @param _encodedLengths Encoded lengths of dynamic fields.
|
|
435
|
+
* @param _dynamicData Tightly packed dynamic fields.
|
|
436
|
+
*/
|
|
437
|
+
function decode(
|
|
438
|
+
bytes memory _staticData,
|
|
439
|
+
EncodedLengths _encodedLengths,
|
|
440
|
+
bytes memory _dynamicData
|
|
441
|
+
) internal pure returns (TasksData memory _table) {
|
|
442
|
+
(_table.createdAt, _table.completedAt) = decodeStatic(_staticData);
|
|
443
|
+
|
|
444
|
+
(_table.description) = decodeDynamic(_encodedLengths, _dynamicData);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* @notice Delete all data for given keys.
|
|
449
|
+
*/
|
|
450
|
+
function deleteRecord(bytes32 id) internal {
|
|
451
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
452
|
+
_keyTuple[0] = id;
|
|
453
|
+
|
|
454
|
+
StoreSwitch.deleteRecord(_tableId, _keyTuple);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* @notice Delete all data for given keys.
|
|
459
|
+
*/
|
|
460
|
+
function _deleteRecord(bytes32 id) internal {
|
|
461
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
462
|
+
_keyTuple[0] = id;
|
|
463
|
+
|
|
464
|
+
StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* @notice Tightly pack static (fixed length) data using this table's schema.
|
|
469
|
+
* @return The static data, encoded into a sequence of bytes.
|
|
470
|
+
*/
|
|
471
|
+
function encodeStatic(uint256 createdAt, uint256 completedAt) internal pure returns (bytes memory) {
|
|
472
|
+
return abi.encodePacked(createdAt, completedAt);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* @notice Tightly pack dynamic data lengths using this table's schema.
|
|
477
|
+
* @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value).
|
|
478
|
+
*/
|
|
479
|
+
function encodeLengths(string memory description) internal pure returns (EncodedLengths _encodedLengths) {
|
|
480
|
+
// Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits
|
|
481
|
+
unchecked {
|
|
482
|
+
_encodedLengths = EncodedLengthsLib.pack(bytes(description).length);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* @notice Tightly pack dynamic (variable length) data using this table's schema.
|
|
488
|
+
* @return The dynamic data, encoded into a sequence of bytes.
|
|
489
|
+
*/
|
|
490
|
+
function encodeDynamic(string memory description) internal pure returns (bytes memory) {
|
|
491
|
+
return abi.encodePacked(bytes((description)));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* @notice Encode all of a record's fields.
|
|
496
|
+
* @return The static (fixed length) data, encoded into a sequence of bytes.
|
|
497
|
+
* @return The lengths of the dynamic fields (packed into a single bytes32 value).
|
|
498
|
+
* @return The dynamic (variable length) data, encoded into a sequence of bytes.
|
|
499
|
+
*/
|
|
500
|
+
function encode(
|
|
501
|
+
uint256 createdAt,
|
|
502
|
+
uint256 completedAt,
|
|
503
|
+
string memory description
|
|
504
|
+
) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
|
|
505
|
+
bytes memory _staticData = encodeStatic(createdAt, completedAt);
|
|
506
|
+
|
|
507
|
+
EncodedLengths _encodedLengths = encodeLengths(description);
|
|
508
|
+
bytes memory _dynamicData = encodeDynamic(description);
|
|
509
|
+
|
|
510
|
+
return (_staticData, _encodedLengths, _dynamicData);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* @notice Encode keys as a bytes32 array using this table's field layout.
|
|
515
|
+
*/
|
|
516
|
+
function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) {
|
|
517
|
+
bytes32[] memory _keyTuple = new bytes32[](1);
|
|
518
|
+
_keyTuple[0] = id;
|
|
519
|
+
|
|
520
|
+
return _keyTuple;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
@@ -3,14 +3,17 @@ pragma solidity >=0.8.24;
|
|
|
3
3
|
|
|
4
4
|
/* Autogenerated file. Do not edit manually. */
|
|
5
5
|
|
|
6
|
-
import { Entity } from "../../Entity.sol";
|
|
7
|
-
import { Direction } from "../common.sol";
|
|
8
|
-
|
|
9
6
|
/**
|
|
10
|
-
* @title
|
|
7
|
+
* @title ITasksSystem
|
|
11
8
|
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
|
|
12
9
|
* @dev This interface is automatically generated from the corresponding system contract. Do not edit manually.
|
|
13
10
|
*/
|
|
14
|
-
interface
|
|
15
|
-
function
|
|
11
|
+
interface ITasksSystem {
|
|
12
|
+
function app__addTask(string memory description) external returns (bytes32 id);
|
|
13
|
+
|
|
14
|
+
function app__completeTask(bytes32 id) external;
|
|
15
|
+
|
|
16
|
+
function app__resetTask(bytes32 id) external;
|
|
17
|
+
|
|
18
|
+
function app__deleteTask(bytes32 id) external;
|
|
16
19
|
}
|
|
@@ -4,7 +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 {
|
|
7
|
+
import { ITasksSystem } from "./ITasksSystem.sol";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @title IWorld
|
|
@@ -13,4 +13,4 @@ import { IMoveSystem } from "./IMoveSystem.sol";
|
|
|
13
13
|
* that are dynamically registered in the World during deployment.
|
|
14
14
|
* @dev This is an autogenerated file; do not edit manually.
|
|
15
15
|
*/
|
|
16
|
-
interface IWorld is IBaseWorld,
|
|
16
|
+
interface IWorld is IBaseWorld, ITasksSystem {}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.24;
|
|
3
|
+
|
|
4
|
+
import { System } from "@latticexyz/world/src/System.sol";
|
|
5
|
+
import { Tasks, TasksData } from "../codegen/index.sol";
|
|
6
|
+
|
|
7
|
+
contract TasksSystem is System {
|
|
8
|
+
function addTask(string memory description) public returns (bytes32 id) {
|
|
9
|
+
id = keccak256(abi.encode(block.prevrandao, _msgSender(), description));
|
|
10
|
+
Tasks.set(id, TasksData({ description: description, createdAt: block.timestamp, completedAt: 0 }));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function completeTask(bytes32 id) public {
|
|
14
|
+
Tasks.setCompletedAt(id, block.timestamp);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function resetTask(bytes32 id) public {
|
|
18
|
+
Tasks.setCompletedAt(id, 0);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function deleteTask(bytes32 id) public {
|
|
22
|
+
Tasks.deleteRecord(id);
|
|
23
|
+
}
|
|
24
|
+
}
|