-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
ResourceSelector
with ResourceId
and `…
…WorldResourceId` (#1544) Co-authored-by: Kevin Ingersoll <[email protected]> Co-authored-by: dk1a <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
"@latticexyz/world": patch | ||
"@latticexyz/store": patch | ||
--- | ||
|
||
The `ResourceType` table is removed. | ||
It was previously used to store the resource type for each resource ID in a `World`. This is no longer necessary as the [resource type is now encoded in the resource ID](https://github.com/latticexyz/mud/pull/1544). | ||
|
||
To still be able to determine whether a given resource ID exists, a `ResourceIds` table has been added. | ||
The previous `ResourceType` table was part of `World` and missed tables that were registered directly via `StoreCore.registerTable` instead of via `World.registerTable` (e.g. when a table was registered as part of a root module). | ||
This problem is solved by the new table `ResourceIds` being part of `Store`. | ||
|
||
`StoreCore`'s `hasTable` function was removed in favor of using `ResourceIds.getExists(tableId)` directly. | ||
|
||
```diff | ||
- import { ResourceType } from "@latticexyz/world/src/tables/ResourceType.sol"; | ||
- import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; | ||
+ import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol"; | ||
|
||
- bool tableExists = StoreCore.hasTable(tableId); | ||
+ bool tableExists = ResourceIds.getExists(tableId); | ||
|
||
- bool systemExists = ResourceType.get(systemId) != Resource.NONE; | ||
+ bool systemExists = ResourceIds.getExists(systemId); | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
"@latticexyz/world": major | ||
--- | ||
|
||
All `World` methods acting on namespaces as resources have been updated to use `ResourceId namespaceId` as parameter instead of `bytes14 namespace`. | ||
The reason for this change is to make it clearer when a namespace is used as resource, as opposed to being part of another resource's ID. | ||
|
||
```diff | ||
+ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||
|
||
IBaseWorld { | ||
- function registerNamespace(bytes14 namespace) external; | ||
+ function registerNamespace(ResourceId namespaceId) external; | ||
|
||
- function transferOwnership(bytes14 namespace, address newOwner) external; | ||
+ function transferOwnership(ResourceId namespaceId, address newOwner) external; | ||
|
||
- function transferBalanceToNamespace(bytes14 fromNamespace, bytes14 toNamespace, uint256 amount) external; | ||
+ function transferBalanceToNamespace(ResourceId fromNamespaceId, ResourceId toNamespaceId, uint256 amount) external; | ||
|
||
- function transferBalanceToAddress(bytes14 fromNamespace, address toAddress, uint256 amount) external; | ||
+ function transferBalanceToAddress(ResourceId fromNamespaceId, address toAddress, uint256 amount) external; | ||
} | ||
|
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
"@latticexyz/cli": major | ||
"@latticexyz/common": major | ||
"@latticexyz/config": major | ||
"@latticexyz/store": major | ||
--- | ||
|
||
- `ResourceSelector` is replaced with `ResourceId`, `ResourceIdLib`, `ResourceIdInstance`, `WorldResourceIdLib` and `WorldResourceIdInstance`. | ||
|
||
Previously a "resource selector" was a `bytes32` value with the first 16 bytes reserved for the resource's namespace, and the last 16 bytes reserved for the resource's name. | ||
Now a "resource ID" is a `bytes32` value with the first 2 bytes reserved for the resource type, the next 14 bytes reserved for the resource's namespace, and the last 16 bytes reserved for the resource's name. | ||
|
||
Previously `ResouceSelector` was a library and the resource selector type was a plain `bytes32`. | ||
Now `ResourceId` is a user type, and the functionality is implemented in the `ResourceIdInstance` (for type) and `WorldResourceIdInstance` (for namespace and name) libraries. | ||
We split the logic into two libraries, because `Store` now also uses `ResourceId` and needs to be aware of resource types, but not of namespaces/names. | ||
|
||
```diff | ||
- import { ResourceSelector } from "@latticexyz/world/src/ResourceSelector.sol"; | ||
+ import { ResourceId, ResourceIdInstance } from "@latticexyz/store/src/ResourceId.sol"; | ||
+ import { WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol"; | ||
+ import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol"; | ||
|
||
- bytes32 systemId = ResourceSelector.from("namespace", "name"); | ||
+ ResourceId systemId = WorldResourceIdLib.encode(RESOURCE_SYSTEM, "namespace", "name"); | ||
|
||
- using ResourceSelector for bytes32; | ||
+ using WorldResourceIdInstance for ResourceId; | ||
+ using ResourceIdInstance for ResourceId; | ||
|
||
systemId.getName(); | ||
systemId.getNamespace(); | ||
+ systemId.getType(); | ||
|
||
``` | ||
|
||
- All `Store` and `World` methods now use the `ResourceId` type for `tableId`, `systemId`, `moduleId` and `namespaceId`. | ||
All mentions of `resourceSelector` were renamed to `resourceId` or the more specific type (e.g. `tableId`, `systemId`) | ||
|
||
```diff | ||
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||
|
||
IStore { | ||
function setRecord( | ||
- bytes32 tableId, | ||
+ ResourceId tableId, | ||
bytes32[] calldata keyTuple, | ||
bytes calldata staticData, | ||
PackedCounter encodedLengths, | ||
bytes calldata dynamicData, | ||
FieldLayout fieldLayout | ||
) external; | ||
|
||
// Same for all other methods | ||
} | ||
``` | ||
|
||
```diff | ||
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||
|
||
IBaseWorld { | ||
function callFrom( | ||
address delegator, | ||
- bytes32 resourceSelector, | ||
+ ResourceId systemId, | ||
bytes memory callData | ||
) external payable returns (bytes memory); | ||
|
||
// Same for all other methods | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
dist | ||
**/.next | ||
.next | ||
templates/phaser/packages/art | ||
CODEOWNERS | ||
out |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.