// SPDX-License-Identifier: MIT pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; // Import user types import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct SmartGateConfigData { ResourceId systemId; uint256 maxDistance; } library SmartGateConfig { // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "evefrontier", name: "SmartGateConfig", typeId: RESOURCE_TABLE });` ResourceId constant _tableId = ResourceId.wrap(0x746265766566726f6e74696572000000536d61727447617465436f6e66696700); FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0040020020200000000000000000000000000000000000000000000000000000); // Hex-encoded key schema of (uint256) Schema constant _keySchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); // Hex-encoded value schema of (bytes32, uint256) Schema constant _valueSchema = Schema.wrap(0x004002005f1f0000000000000000000000000000000000000000000000000000); /** * @notice Get the table's key field names. * @return keyNames An array of strings with the names of key fields. */ function getKeyNames() internal pure returns (string[] memory keyNames) { keyNames = new string[](1); keyNames[0] = "smartObjectId"; } /** * @notice Get the table's value field names. * @return fieldNames An array of strings with the names of value fields. */ function getFieldNames() internal pure returns (string[] memory fieldNames) { fieldNames = new string[](2); fieldNames[0] = "systemId"; fieldNames[1] = "maxDistance"; } /** * @notice Register the table with its config. */ function register() internal { StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Get systemId. */ function getSystemId(uint256 smartObjectId) internal view returns (ResourceId systemId) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return ResourceId.wrap(bytes32(_blob)); } /** * @notice Get systemId. */ function _getSystemId(uint256 smartObjectId) internal view returns (ResourceId systemId) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return ResourceId.wrap(bytes32(_blob)); } /** * @notice Set systemId. */ function setSystemId(uint256 smartObjectId, ResourceId systemId) internal { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); } /** * @notice Set systemId. */ function _setSystemId(uint256 smartObjectId, ResourceId systemId) internal { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(ResourceId.unwrap(systemId)), _fieldLayout); } /** * @notice Get maxDistance. */ function getMaxDistance(uint256 smartObjectId) internal view returns (uint256 maxDistance) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); return (uint256(bytes32(_blob))); } /** * @notice Get maxDistance. */ function _getMaxDistance(uint256 smartObjectId) internal view returns (uint256 maxDistance) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); return (uint256(bytes32(_blob))); } /** * @notice Set maxDistance. */ function setMaxDistance(uint256 smartObjectId, uint256 maxDistance) internal { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((maxDistance)), _fieldLayout); } /** * @notice Set maxDistance. */ function _setMaxDistance(uint256 smartObjectId, uint256 maxDistance) internal { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((maxDistance)), _fieldLayout); } /** * @notice Get the full data. */ function get(uint256 smartObjectId) internal view returns (SmartGateConfigData memory _table) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout ); return decode(_staticData, _encodedLengths, _dynamicData); } /** * @notice Get the full data. */ function _get(uint256 smartObjectId) internal view returns (SmartGateConfigData memory _table) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout ); return decode(_staticData, _encodedLengths, _dynamicData); } /** * @notice Set the full data using individual values. */ function set(uint256 smartObjectId, ResourceId systemId, uint256 maxDistance) internal { bytes memory _staticData = encodeStatic(systemId, maxDistance); EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); } /** * @notice Set the full data using individual values. */ function _set(uint256 smartObjectId, ResourceId systemId, uint256 maxDistance) internal { bytes memory _staticData = encodeStatic(systemId, maxDistance); EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** * @notice Set the full data using the data struct. */ function set(uint256 smartObjectId, SmartGateConfigData memory _table) internal { bytes memory _staticData = encodeStatic(_table.systemId, _table.maxDistance); EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); } /** * @notice Set the full data using the data struct. */ function _set(uint256 smartObjectId, SmartGateConfigData memory _table) internal { bytes memory _staticData = encodeStatic(_table.systemId, _table.maxDistance); EncodedLengths _encodedLengths; bytes memory _dynamicData; bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ function decodeStatic(bytes memory _blob) internal pure returns (ResourceId systemId, uint256 maxDistance) { systemId = ResourceId.wrap(Bytes.getBytes32(_blob, 0)); maxDistance = (uint256(Bytes.getBytes32(_blob, 32))); } /** * @notice Decode the tightly packed blobs using this table's field layout. * @param _staticData Tightly packed static fields. * * */ function decode( bytes memory _staticData, EncodedLengths, bytes memory ) internal pure returns (SmartGateConfigData memory _table) { (_table.systemId, _table.maxDistance) = decodeStatic(_staticData); } /** * @notice Delete all data for given keys. */ function deleteRecord(uint256 smartObjectId) internal { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreSwitch.deleteRecord(_tableId, _keyTuple); } /** * @notice Delete all data for given keys. */ function _deleteRecord(uint256 smartObjectId) internal { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. */ function encodeStatic(ResourceId systemId, uint256 maxDistance) internal pure returns (bytes memory) { return abi.encodePacked(systemId, maxDistance); } /** * @notice Encode all of a record's fields. * @return The static (fixed length) data, encoded into a sequence of bytes. * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ function encode( ResourceId systemId, uint256 maxDistance ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(systemId, maxDistance); EncodedLengths _encodedLengths; bytes memory _dynamicData; return (_staticData, _encodedLengths, _dynamicData); } /** * @notice Encode keys as a bytes32 array using this table's field layout. */ function encodeKeyTuple(uint256 smartObjectId) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](1); _keyTuple[0] = bytes32(uint256(smartObjectId)); return _keyTuple; } }