Skip to content

Commit

Permalink
refactor: move table ID and field layout constants into table library (
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Feb 28, 2024
1 parent 53d227c commit 4423604
Show file tree
Hide file tree
Showing 102 changed files with 427 additions and 1,037 deletions.
21 changes: 21 additions & 0 deletions .changeset/few-berries-tickle.md
@@ -0,0 +1,21 @@
---
"create-mud": patch
"@latticexyz/cli": major
"@latticexyz/common": major
"@latticexyz/store": patch
"@latticexyz/world": patch
"@latticexyz/world-modules": patch
---

Moved table ID and field layout constants in code-generated table libraries from the file level into the library, for clearer access and cleaner imports.

```diff
-import { SomeTable, SomeTableTableId } from "./codegen/tables/SomeTable.sol";
+import { SomeTable } from "./codegen/tables/SomeTable.sol";

-console.log(SomeTableTableId);
+console.log(SomeTable._tableId);

-console.log(SomeTable.getFieldLayout());
+console.log(SomeTable._fieldLayout);
```
12 changes: 6 additions & 6 deletions e2e/packages/contracts/src/codegen/index.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions e2e/packages/contracts/src/codegen/tables/Multi.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions e2e/packages/contracts/src/codegen/tables/Number.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions e2e/packages/contracts/src/codegen/tables/NumberList.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions e2e/packages/contracts/src/codegen/tables/Position.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions e2e/packages/contracts/src/codegen/tables/StaticArray.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions e2e/packages/contracts/src/codegen/tables/Vector.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions e2e/packages/contracts/src/systems/NumberListSystem.sol
Expand Up @@ -4,7 +4,7 @@ pragma solidity >=0.8.24;
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol";
import { System } from "@latticexyz/world/src/System.sol";
import { NumberList, NumberListTableId } from "../codegen/index.sol";
import { NumberList } from "../codegen/index.sol";

contract NumberListSystem is System {
function set(uint32[] memory list) public {
Expand All @@ -22,7 +22,7 @@ contract NumberListSystem is System {
}

bytes32[] memory emptyKey;
StoreSwitch.pushToDynamicField(NumberListTableId, emptyKey, 0, EncodeArray.encode(list));
StoreSwitch.pushToDynamicField(NumberList._tableId, emptyKey, 0, EncodeArray.encode(list));
}

function pop() public {
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal/packages/contracts/script/PostDeploy.s.sol
Expand Up @@ -7,7 +7,7 @@ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";
import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";

import { MessageTable, MessageTableTableId } from "../src/codegen/index.sol";
import { MessageTable } from "../src/codegen/index.sol";
import { IWorld } from "../src/codegen/world/IWorld.sol";
import { ChatNamespacedSystem } from "../src/systems/ChatNamespacedSystem.sol";

Expand Down Expand Up @@ -36,7 +36,7 @@ contract PostDeploy is Script {
IWorld(worldAddress).registerFunctionSelector(systemId, "sendMessage(string)");

// Grant this system access to MessageTable
IWorld(worldAddress).grantAccess(MessageTableTableId, address(chatNamespacedSystem));
IWorld(worldAddress).grantAccess(MessageTable._tableId, address(chatNamespacedSystem));

// ------------------ EXAMPLES ------------------

Expand Down
6 changes: 3 additions & 3 deletions examples/minimal/packages/contracts/src/codegen/index.sol

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.

4 changes: 2 additions & 2 deletions examples/minimal/packages/contracts/test/ChatNamespaced.t.sol
Expand Up @@ -7,7 +7,7 @@ import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswith
import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";
import { MessageTable, MessageTableTableId } from "../src/codegen/index.sol";
import { MessageTable } from "../src/codegen/index.sol";
import { IChatNamespacedSystem } from "../src/interfaces/IChatNamespacedSystem.sol";

contract ChatNamespacedTest is MudTest {
Expand All @@ -16,7 +16,7 @@ contract ChatNamespacedTest is MudTest {
string memory value = "test";
vm.expectEmit(true, true, true, true);
emit StoreCore.Store_SetRecord(
MessageTableTableId,
MessageTable._tableId,
keyTuple,
new bytes(0),
MessageTable.encodeLengths(value),
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal/packages/contracts/test/CounterTest.t.sol
Expand Up @@ -6,7 +6,7 @@ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";
import { CounterTable, CounterTableTableId } from "../src/codegen/index.sol";
import { CounterTable } from "../src/codegen/index.sol";

contract CounterTest is MudTest {
function testWorldExists() public {
Expand All @@ -32,7 +32,7 @@ contract CounterTest is MudTest {
// TODO: re-enable the KeysWithValueModule in mud.config.ts once it supports singleton keys
// function testKeysWithValue() public {
// uint32 counter = CounterTable.get();
// bytes32[] memory keysWithValue = getKeysWithValue(CounterTableTableId, CounterTable.encode(counter));
// bytes32[] memory keysWithValue = getKeysWithValue(CounterTable._tableId, CounterTable.encode(counter));
// assertEq(keysWithValue.length, 1);
// }
}
2 changes: 1 addition & 1 deletion examples/minimal/packages/contracts/test/StructTest.t.sol
Expand Up @@ -6,7 +6,7 @@ import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
import { getKeysWithValue } from "@latticexyz/world-modules/src/modules/keyswithvalue/getKeysWithValue.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";
import { CounterTable, CounterTableTableId } from "../src/codegen/index.sol";
import { CounterTable } from "../src/codegen/index.sol";
import { BytesStruct, StringStruct } from "../src/systems/structs.sol";

contract StructTest is MudTest {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4423604

Please sign in to comment.