Skip to content

Commit

Permalink
use system libs
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Feb 7, 2025
1 parent 35c5ac5 commit a681215
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 80 deletions.
69 changes: 0 additions & 69 deletions packages/world-module-metadata/src/DelegatorContext.sol

This file was deleted.

29 changes: 18 additions & 11 deletions packages/world-module-metadata/src/MetadataModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { ResourceId, WorldResourceIdLib, WorldResourceIdInstance } from "@lattic
import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol";
import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";
import { REGISTRATION_SYSTEM_ID } from "@latticexyz/world/src/modules/init/constants.sol";
import { worldRegistrationSystem } from "@latticexyz/world/src/codegen/systems/WorldRegistrationSystemLib.sol";
import { storeRegistrationSystem } from "@latticexyz/world/src/codegen/systems/StoreRegistrationSystemLib.sol";

import { MetadataSystem } from "./MetadataSystem.sol";
import { ResourceTag } from "./codegen/tables/ResourceTag.sol";
import { DelegatorContext, DelegatedRegistrationSystemLib } from "./DelegatorContext.sol";

/**
* @title MetadataModule
Expand All @@ -21,22 +22,19 @@ import { DelegatorContext, DelegatedRegistrationSystemLib } from "./DelegatorCon
*/
contract MetadataModule is Module {
using WorldResourceIdInstance for ResourceId;
using DelegatedRegistrationSystemLib for DelegatorContext;

MetadataSystem private immutable metadataSystem = new MetadataSystem();

function install(bytes memory args) public override {
DelegatorContext memory world = DelegatorContext(IBaseWorld(_world()), _msgSender());

ResourceId namespace = ResourceTag._tableId.getNamespaceId();
if (!ResourceIds.getExists(namespace)) {
world.registerNamespace(namespace);
worldRegistrationSystem.callFrom(_msgSender()).registerNamespace(namespace);
}
AccessControl.requireOwner(namespace, world.delegator);
AccessControl.requireOwner(namespace, _msgSender());

if (!ResourceIds.getExists(ResourceTag._tableId)) {
// TODO: add a `ResourceTag.getTableDef()` that returns a struct that can be used to register?
world.registerTable(
storeRegistrationSystem.callFrom(_msgSender()).registerTable(
ResourceTag._tableId,
ResourceTag._fieldLayout,
ResourceTag._keySchema,
Expand All @@ -53,10 +51,19 @@ contract MetadataModule is Module {
);
// TODO: add support for upgrading system and registering new function selectors
if (!ResourceIds.getExists(metadataSystemId)) {
world.registerSystem(metadataSystemId, metadataSystem, true);
world.registerFunctionSelector(metadataSystemId, "getResourceTag(bytes32,bytes32)");
world.registerFunctionSelector(metadataSystemId, "setResourceTag(bytes32,bytes32,bytes)");
world.registerFunctionSelector(metadataSystemId, "deleteResourceTag(bytes32,bytes32)");
worldRegistrationSystem.callFrom(_msgSender()).registerSystem(metadataSystemId, metadataSystem, true);
worldRegistrationSystem.callFrom(_msgSender()).registerFunctionSelector(
metadataSystemId,
"getResourceTag(bytes32,bytes32)"
);
worldRegistrationSystem.callFrom(_msgSender()).registerFunctionSelector(
metadataSystemId,
"setResourceTag(bytes32,bytes32,bytes)"
);
worldRegistrationSystem.callFrom(_msgSender()).registerFunctionSelector(
metadataSystemId,
"deleteResourceTag(bytes32,bytes32)"
);
}
}
}

0 comments on commit a681215

Please sign in to comment.