diff --git a/packages/experience/IWorld.abi.json b/packages/experience/IWorld.abi.json index 424cde0a..e8d92dcb 100644 --- a/packages/experience/IWorld.abi.json +++ b/packages/experience/IWorld.abi.json @@ -150,6 +150,41 @@ "outputs": [], "stateMutability": "nonpayable" }, + { + "type": "function", + "name": "experience__addQuest", + "inputs": [ + { + "name": "quest", + "type": "tuple", + "internalType": "struct QuestData", + "components": [ + { + "name": "unlockId", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "triggerId", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "nameId", + "type": "string", + "internalType": "string" + }, + { + "name": "displayName", + "type": "string", + "internalType": "string" + } + ] + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, { "type": "function", "name": "experience__deleteArea", diff --git a/packages/experience/IWorld.abi.json.d.ts b/packages/experience/IWorld.abi.json.d.ts index 4b6880b5..2ba445dc 100644 --- a/packages/experience/IWorld.abi.json.d.ts +++ b/packages/experience/IWorld.abi.json.d.ts @@ -150,6 +150,41 @@ declare const abi: [ "outputs": [], "stateMutability": "nonpayable" }, + { + "type": "function", + "name": "experience__addQuest", + "inputs": [ + { + "name": "quest", + "type": "tuple", + "internalType": "struct QuestData", + "components": [ + { + "name": "unlockId", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "triggerId", + "type": "bytes32", + "internalType": "bytes32" + }, + { + "name": "nameId", + "type": "string", + "internalType": "string" + }, + { + "name": "displayName", + "type": "string", + "internalType": "string" + } + ] + } + ], + "outputs": [], + "stateMutability": "nonpayable" + }, { "type": "function", "name": "experience__deleteArea", diff --git a/packages/experience/mud.config.ts b/packages/experience/mud.config.ts index 003f893f..3ac23c54 100644 --- a/packages/experience/mud.config.ts +++ b/packages/experience/mud.config.ts @@ -9,6 +9,12 @@ export default defineWorld({ ChipType: ["None", "Chest", "ForceField"], ShopType: ["None", "Buy", "Sell", "BuySell"], ShopTxType: ["None", "Buy", "Sell"], + BaseTriggerKind: ["None", "All", "Any", "Seq"], + LeafTriggerKind: ["None", "MapBeam", "Event", "ChallengeComplete", "Collect"], + NavigationAidKind: ["None", "Position", "Entity"], + EventKind: ["None", "ItemShop", "CloseModal", "ChainPlayerAction"], + BasePredicateKind: ["None", "Object"], + LeafPredicateKind: ["None", "Value"], }, namespace: "experience", tables: { @@ -276,5 +282,116 @@ export default defineWorld({ storeArgument: true, }, }, + Quest: { + schema: { + id: "bytes32", + unlockId: "bytes32", + triggerId: "bytes32", + nameId: "string", + displayName: "string", + }, + key: ["id"], + codegen: { + storeArgument: true, + }, + }, + BaseTrigger: { + schema: { + id: "bytes32", + kind: "BaseTriggerKind", + triggerIds: "bytes32[]", + }, + key: ["id"], + codegen: { + storeArgument: true, + }, + }, + LeafTrigger: { + schema: { + id: "bytes32", + kind: "LeafTriggerKind", + navigationAidKind: "NavigationAidKind", + navigationAidPosX: "int16", + navigationAidPosY: "int16", + navigationAidPosZ: "int16", + navigaitonAidEntity: "bytes32", + name: "string", + }, + key: ["id"], + codegen: { + storeArgument: true, + }, + }, + MapBeamTrigger: { + schema: { + id: "bytes32", + posX: "int16", + posZ: "int16", + allowDefaultNavigationAid: "bool", + }, + key: ["id"], + codegen: { + storeArgument: true, + }, + }, + ChallengeCompleteTrigger: { + schema: { + id: "bytes32", + challengeId: "bytes32", + }, + key: ["id"], + codegen: { + storeArgument: true, + }, + }, + CollectTrigger: { + schema: { + id: "bytes32", + objectTypeId: "bytes32", + count: "uint32", + }, + key: ["id"], + codegen: { + storeArgument: true, + }, + }, + EventTrigger: { + schema: { + id: "bytes32", + eventKind: "EventKind", + count: "uint32", + predicateId: "bytes32", + }, + key: ["id"], + codegen: { + storeArgument: true, + }, + }, + BasePredicate: { + schema: { + id: "bytes32", + kind: "BasePredicateKind", + fieldKeys: "bytes", // string[] + fieldPredicateIds: "bytes32[]", + }, + key: ["id"], + codegen: { + storeArgument: true, + }, + }, + LeafPredicate: { + schema: { + id: "bytes32", + kind: "LeafPredicateKind", + valueNum: "uint32", + valueBool: "bool", + valueId: "bytes32", + valueString: "string", + }, + key: ["id"], + codegen: { + storeArgument: true, + }, + }, }, }); diff --git a/packages/experience/src/codegen/common.sol b/packages/experience/src/codegen/common.sol index c9e5c96a..1f2f6396 100644 --- a/packages/experience/src/codegen/common.sol +++ b/packages/experience/src/codegen/common.sol @@ -20,3 +20,41 @@ enum ShopTxType { Buy, Sell } + +enum BaseTriggerKind { + None, + All, + Any, + Seq +} + +enum LeafTriggerKind { + None, + MapBeam, + Event, + ChallengeComplete, + Collect +} + +enum NavigationAidKind { + None, + Position, + Entity +} + +enum EventKind { + None, + ItemShop, + CloseModal, + ChainPlayerAction +} + +enum BasePredicateKind { + None, + Object +} + +enum LeafPredicateKind { + None, + Value +} diff --git a/packages/experience/src/codegen/index.sol b/packages/experience/src/codegen/index.sol index 0b0426ca..7a9bafae 100644 --- a/packages/experience/src/codegen/index.sol +++ b/packages/experience/src/codegen/index.sol @@ -24,3 +24,12 @@ import { Tokens } from "./tables/Tokens.sol"; import { NFTs } from "./tables/NFTs.sol"; import { TokenMetadata, TokenMetadataData } from "./tables/TokenMetadata.sol"; import { NFTMetadata, NFTMetadataData } from "./tables/NFTMetadata.sol"; +import { Quest, QuestData } from "./tables/Quest.sol"; +import { BaseTrigger, BaseTriggerData } from "./tables/BaseTrigger.sol"; +import { LeafTrigger, LeafTriggerData } from "./tables/LeafTrigger.sol"; +import { MapBeamTrigger, MapBeamTriggerData } from "./tables/MapBeamTrigger.sol"; +import { ChallengeCompleteTrigger } from "./tables/ChallengeCompleteTrigger.sol"; +import { CollectTrigger, CollectTriggerData } from "./tables/CollectTrigger.sol"; +import { EventTrigger, EventTriggerData } from "./tables/EventTrigger.sol"; +import { BasePredicate, BasePredicateData } from "./tables/BasePredicate.sol"; +import { LeafPredicate, LeafPredicateData } from "./tables/LeafPredicate.sol"; diff --git a/packages/experience/src/codegen/tables/BasePredicate.sol b/packages/experience/src/codegen/tables/BasePredicate.sol new file mode 100644 index 00000000..665c4c5f --- /dev/null +++ b/packages/experience/src/codegen/tables/BasePredicate.sol @@ -0,0 +1,916 @@ +// 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 { BasePredicateKind } from "./../common.sol"; + +struct BasePredicateData { + BasePredicateKind kind; + bytes fieldKeys; + bytes32[] fieldPredicateIds; +} + +library BasePredicate { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "experience", name: "BasePredicate", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462657870657269656e63650000000042617365507265646963617465000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0001010201000000000000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint8, bytes, bytes32[]) + Schema constant _valueSchema = Schema.wrap(0x0001010200c4c100000000000000000000000000000000000000000000000000); + + /** + * @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] = "id"; + } + + /** + * @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[](3); + fieldNames[0] = "kind"; + fieldNames[1] = "fieldKeys"; + fieldNames[2] = "fieldPredicateIds"; + } + + /** + * @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 Register the table with its config (using the specified store). + */ + function register(IStore _store) internal { + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get kind. + */ + function getKind(bytes32 id) internal view returns (BasePredicateKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return BasePredicateKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get kind. + */ + function _getKind(bytes32 id) internal view returns (BasePredicateKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return BasePredicateKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get kind (using the specified store). + */ + function getKind(IStore _store, bytes32 id) internal view returns (BasePredicateKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return BasePredicateKind(uint8(bytes1(_blob))); + } + + /** + * @notice Set kind. + */ + function setKind(bytes32 id, BasePredicateKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Set kind. + */ + function _setKind(bytes32 id, BasePredicateKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Set kind (using the specified store). + */ + function setKind(IStore _store, bytes32 id, BasePredicateKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Get fieldKeys. + */ + function getFieldKeys(bytes32 id) internal view returns (bytes memory fieldKeys) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (bytes(_blob)); + } + + /** + * @notice Get fieldKeys. + */ + function _getFieldKeys(bytes32 id) internal view returns (bytes memory fieldKeys) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (bytes(_blob)); + } + + /** + * @notice Get fieldKeys (using the specified store). + */ + function getFieldKeys(IStore _store, bytes32 id) internal view returns (bytes memory fieldKeys) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (bytes(_blob)); + } + + /** + * @notice Set fieldKeys. + */ + function setFieldKeys(bytes32 id, bytes memory fieldKeys) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, bytes((fieldKeys))); + } + + /** + * @notice Set fieldKeys. + */ + function _setFieldKeys(bytes32 id, bytes memory fieldKeys) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setDynamicField(_tableId, _keyTuple, 0, bytes((fieldKeys))); + } + + /** + * @notice Set fieldKeys (using the specified store). + */ + function setFieldKeys(IStore _store, bytes32 id, bytes memory fieldKeys) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setDynamicField(_tableId, _keyTuple, 0, bytes((fieldKeys))); + } + + /** + * @notice Get the length of fieldKeys. + */ + function lengthFieldKeys(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of fieldKeys. + */ + function _lengthFieldKeys(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of fieldKeys (using the specified store). + */ + function lengthFieldKeys(IStore _store, bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get an item of fieldKeys. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemFieldKeys(bytes32 id, uint256 _index) internal view returns (bytes memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (bytes(_blob)); + } + } + + /** + * @notice Get an item of fieldKeys. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function _getItemFieldKeys(bytes32 id, uint256 _index) internal view returns (bytes memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (bytes(_blob)); + } + } + + /** + * @notice Get an item of fieldKeys (using the specified store). + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemFieldKeys(IStore _store, bytes32 id, uint256 _index) internal view returns (bytes memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (bytes(_blob)); + } + } + + /** + * @notice Push a slice to fieldKeys. + */ + function pushFieldKeys(bytes32 id, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Push a slice to fieldKeys. + */ + function _pushFieldKeys(bytes32 id, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Push a slice to fieldKeys (using the specified store). + */ + function pushFieldKeys(IStore _store, bytes32 id, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Pop a slice from fieldKeys. + */ + function popFieldKeys(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Pop a slice from fieldKeys. + */ + function _popFieldKeys(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Pop a slice from fieldKeys (using the specified store). + */ + function popFieldKeys(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Update a slice of fieldKeys at `_index`. + */ + function updateFieldKeys(bytes32 id, uint256 _index, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of fieldKeys at `_index`. + */ + function _updateFieldKeys(bytes32 id, uint256 _index, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of fieldKeys (using the specified store) at `_index`. + */ + function updateFieldKeys(IStore _store, bytes32 id, uint256 _index, bytes memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Get fieldPredicateIds. + */ + function getFieldPredicateIds(bytes32 id) internal view returns (bytes32[] memory fieldPredicateIds) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get fieldPredicateIds. + */ + function _getFieldPredicateIds(bytes32 id) internal view returns (bytes32[] memory fieldPredicateIds) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 1); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get fieldPredicateIds (using the specified store). + */ + function getFieldPredicateIds(IStore _store, bytes32 id) internal view returns (bytes32[] memory fieldPredicateIds) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Set fieldPredicateIds. + */ + function setFieldPredicateIds(bytes32 id, bytes32[] memory fieldPredicateIds) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode((fieldPredicateIds))); + } + + /** + * @notice Set fieldPredicateIds. + */ + function _setFieldPredicateIds(bytes32 id, bytes32[] memory fieldPredicateIds) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode((fieldPredicateIds))); + } + + /** + * @notice Set fieldPredicateIds (using the specified store). + */ + function setFieldPredicateIds(IStore _store, bytes32 id, bytes32[] memory fieldPredicateIds) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setDynamicField(_tableId, _keyTuple, 1, EncodeArray.encode((fieldPredicateIds))); + } + + /** + * @notice Get the length of fieldPredicateIds. + */ + function lengthFieldPredicateIds(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 1); + unchecked { + return _byteLength / 32; + } + } + + /** + * @notice Get the length of fieldPredicateIds. + */ + function _lengthFieldPredicateIds(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 1); + unchecked { + return _byteLength / 32; + } + } + + /** + * @notice Get the length of fieldPredicateIds (using the specified store). + */ + function lengthFieldPredicateIds(IStore _store, bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 1); + unchecked { + return _byteLength / 32; + } + } + + /** + * @notice Get an item of fieldPredicateIds. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemFieldPredicateIds(bytes32 id, uint256 _index) internal view returns (bytes32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 32, (_index + 1) * 32); + return (bytes32(_blob)); + } + } + + /** + * @notice Get an item of fieldPredicateIds. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function _getItemFieldPredicateIds(bytes32 id, uint256 _index) internal view returns (bytes32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 32, (_index + 1) * 32); + return (bytes32(_blob)); + } + } + + /** + * @notice Get an item of fieldPredicateIds (using the specified store). + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemFieldPredicateIds(IStore _store, bytes32 id, uint256 _index) internal view returns (bytes32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 32, (_index + 1) * 32); + return (bytes32(_blob)); + } + } + + /** + * @notice Push an element to fieldPredicateIds. + */ + function pushFieldPredicateIds(bytes32 id, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 1, abi.encodePacked((_element))); + } + + /** + * @notice Push an element to fieldPredicateIds. + */ + function _pushFieldPredicateIds(bytes32 id, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.pushToDynamicField(_tableId, _keyTuple, 1, abi.encodePacked((_element))); + } + + /** + * @notice Push an element to fieldPredicateIds (using the specified store). + */ + function pushFieldPredicateIds(IStore _store, bytes32 id, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.pushToDynamicField(_tableId, _keyTuple, 1, abi.encodePacked((_element))); + } + + /** + * @notice Pop an element from fieldPredicateIds. + */ + function popFieldPredicateIds(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 1, 32); + } + + /** + * @notice Pop an element from fieldPredicateIds. + */ + function _popFieldPredicateIds(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.popFromDynamicField(_tableId, _keyTuple, 1, 32); + } + + /** + * @notice Pop an element from fieldPredicateIds (using the specified store). + */ + function popFieldPredicateIds(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.popFromDynamicField(_tableId, _keyTuple, 1, 32); + } + + /** + * @notice Update an element of fieldPredicateIds at `_index`. + */ + function updateFieldPredicateIds(bytes32 id, uint256 _index, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = abi.encodePacked((_element)); + StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 32), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update an element of fieldPredicateIds at `_index`. + */ + function _updateFieldPredicateIds(bytes32 id, uint256 _index, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = abi.encodePacked((_element)); + StoreCore.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 32), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update an element of fieldPredicateIds (using the specified store) at `_index`. + */ + function updateFieldPredicateIds(IStore _store, bytes32 id, uint256 _index, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = abi.encodePacked((_element)); + _store.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 32), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Get the full data. + */ + function get(bytes32 id) internal view returns (BasePredicateData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (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(bytes32 id) internal view returns (BasePredicateData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Get the full data (using the specified store). + */ + function get(IStore _store, bytes32 id) internal view returns (BasePredicateData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function set( + bytes32 id, + BasePredicateKind kind, + bytes memory fieldKeys, + bytes32[] memory fieldPredicateIds + ) internal { + bytes memory _staticData = encodeStatic(kind); + + EncodedLengths _encodedLengths = encodeLengths(fieldKeys, fieldPredicateIds); + bytes memory _dynamicData = encodeDynamic(fieldKeys, fieldPredicateIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function _set( + bytes32 id, + BasePredicateKind kind, + bytes memory fieldKeys, + bytes32[] memory fieldPredicateIds + ) internal { + bytes memory _staticData = encodeStatic(kind); + + EncodedLengths _encodedLengths = encodeLengths(fieldKeys, fieldPredicateIds); + bytes memory _dynamicData = encodeDynamic(fieldKeys, fieldPredicateIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using individual values (using the specified store). + */ + function set( + IStore _store, + bytes32 id, + BasePredicateKind kind, + bytes memory fieldKeys, + bytes32[] memory fieldPredicateIds + ) internal { + bytes memory _staticData = encodeStatic(kind); + + EncodedLengths _encodedLengths = encodeLengths(fieldKeys, fieldPredicateIds); + bytes memory _dynamicData = encodeDynamic(fieldKeys, fieldPredicateIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function set(bytes32 id, BasePredicateData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.kind); + + EncodedLengths _encodedLengths = encodeLengths(_table.fieldKeys, _table.fieldPredicateIds); + bytes memory _dynamicData = encodeDynamic(_table.fieldKeys, _table.fieldPredicateIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function _set(bytes32 id, BasePredicateData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.kind); + + EncodedLengths _encodedLengths = encodeLengths(_table.fieldKeys, _table.fieldPredicateIds); + bytes memory _dynamicData = encodeDynamic(_table.fieldKeys, _table.fieldPredicateIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using the data struct (using the specified store). + */ + function set(IStore _store, bytes32 id, BasePredicateData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.kind); + + EncodedLengths _encodedLengths = encodeLengths(_table.fieldKeys, _table.fieldPredicateIds); + bytes memory _dynamicData = encodeDynamic(_table.fieldKeys, _table.fieldPredicateIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Decode the tightly packed blob of static data using this table's field layout. + */ + function decodeStatic(bytes memory _blob) internal pure returns (BasePredicateKind kind) { + kind = BasePredicateKind(uint8(Bytes.getBytes1(_blob, 0))); + } + + /** + * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. + */ + function decodeDynamic( + EncodedLengths _encodedLengths, + bytes memory _blob + ) internal pure returns (bytes memory fieldKeys, bytes32[] memory fieldPredicateIds) { + uint256 _start; + uint256 _end; + unchecked { + _end = _encodedLengths.atIndex(0); + } + fieldKeys = (bytes(SliceLib.getSubslice(_blob, _start, _end).toBytes())); + + _start = _end; + unchecked { + _end += _encodedLengths.atIndex(1); + } + fieldPredicateIds = (SliceLib.getSubslice(_blob, _start, _end).decodeArray_bytes32()); + } + + /** + * @notice Decode the tightly packed blobs using this table's field layout. + * @param _staticData Tightly packed static fields. + * @param _encodedLengths Encoded lengths of dynamic fields. + * @param _dynamicData Tightly packed dynamic fields. + */ + function decode( + bytes memory _staticData, + EncodedLengths _encodedLengths, + bytes memory _dynamicData + ) internal pure returns (BasePredicateData memory _table) { + (_table.kind) = decodeStatic(_staticData); + + (_table.fieldKeys, _table.fieldPredicateIds) = decodeDynamic(_encodedLengths, _dynamicData); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Delete all data for given keys (using the specified store). + */ + function deleteRecord(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic(BasePredicateKind kind) internal pure returns (bytes memory) { + return abi.encodePacked(kind); + } + + /** + * @notice Tightly pack dynamic data lengths using this table's schema. + * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). + */ + function encodeLengths( + bytes memory fieldKeys, + bytes32[] memory fieldPredicateIds + ) internal pure returns (EncodedLengths _encodedLengths) { + // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits + unchecked { + _encodedLengths = EncodedLengthsLib.pack(bytes(fieldKeys).length, fieldPredicateIds.length * 32); + } + } + + /** + * @notice Tightly pack dynamic (variable length) data using this table's schema. + * @return The dynamic data, encoded into a sequence of bytes. + */ + function encodeDynamic( + bytes memory fieldKeys, + bytes32[] memory fieldPredicateIds + ) internal pure returns (bytes memory) { + return abi.encodePacked(bytes((fieldKeys)), EncodeArray.encode((fieldPredicateIds))); + } + + /** + * @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( + BasePredicateKind kind, + bytes memory fieldKeys, + bytes32[] memory fieldPredicateIds + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic(kind); + + EncodedLengths _encodedLengths = encodeLengths(fieldKeys, fieldPredicateIds); + bytes memory _dynamicData = encodeDynamic(fieldKeys, fieldPredicateIds); + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + return _keyTuple; + } +} diff --git a/packages/experience/src/codegen/tables/BaseTrigger.sol b/packages/experience/src/codegen/tables/BaseTrigger.sol new file mode 100644 index 00000000..a7e8529c --- /dev/null +++ b/packages/experience/src/codegen/tables/BaseTrigger.sol @@ -0,0 +1,642 @@ +// 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 { BaseTriggerKind } from "./../common.sol"; + +struct BaseTriggerData { + BaseTriggerKind kind; + bytes32[] triggerIds; +} + +library BaseTrigger { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "experience", name: "BaseTrigger", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462657870657269656e63650000000042617365547269676765720000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0001010101000000000000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint8, bytes32[]) + Schema constant _valueSchema = Schema.wrap(0x0001010100c10000000000000000000000000000000000000000000000000000); + + /** + * @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] = "id"; + } + + /** + * @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] = "kind"; + fieldNames[1] = "triggerIds"; + } + + /** + * @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 Register the table with its config (using the specified store). + */ + function register(IStore _store) internal { + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get kind. + */ + function getKind(bytes32 id) internal view returns (BaseTriggerKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return BaseTriggerKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get kind. + */ + function _getKind(bytes32 id) internal view returns (BaseTriggerKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return BaseTriggerKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get kind (using the specified store). + */ + function getKind(IStore _store, bytes32 id) internal view returns (BaseTriggerKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return BaseTriggerKind(uint8(bytes1(_blob))); + } + + /** + * @notice Set kind. + */ + function setKind(bytes32 id, BaseTriggerKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Set kind. + */ + function _setKind(bytes32 id, BaseTriggerKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Set kind (using the specified store). + */ + function setKind(IStore _store, bytes32 id, BaseTriggerKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Get triggerIds. + */ + function getTriggerIds(bytes32 id) internal view returns (bytes32[] memory triggerIds) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get triggerIds. + */ + function _getTriggerIds(bytes32 id) internal view returns (bytes32[] memory triggerIds) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Get triggerIds (using the specified store). + */ + function getTriggerIds(IStore _store, bytes32 id) internal view returns (bytes32[] memory triggerIds) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** + * @notice Set triggerIds. + */ + function setTriggerIds(bytes32 id, bytes32[] memory triggerIds) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((triggerIds))); + } + + /** + * @notice Set triggerIds. + */ + function _setTriggerIds(bytes32 id, bytes32[] memory triggerIds) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((triggerIds))); + } + + /** + * @notice Set triggerIds (using the specified store). + */ + function setTriggerIds(IStore _store, bytes32 id, bytes32[] memory triggerIds) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setDynamicField(_tableId, _keyTuple, 0, EncodeArray.encode((triggerIds))); + } + + /** + * @notice Get the length of triggerIds. + */ + function lengthTriggerIds(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 32; + } + } + + /** + * @notice Get the length of triggerIds. + */ + function _lengthTriggerIds(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 32; + } + } + + /** + * @notice Get the length of triggerIds (using the specified store). + */ + function lengthTriggerIds(IStore _store, bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 32; + } + } + + /** + * @notice Get an item of triggerIds. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemTriggerIds(bytes32 id, uint256 _index) internal view returns (bytes32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32); + return (bytes32(_blob)); + } + } + + /** + * @notice Get an item of triggerIds. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function _getItemTriggerIds(bytes32 id, uint256 _index) internal view returns (bytes32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32); + return (bytes32(_blob)); + } + } + + /** + * @notice Get an item of triggerIds (using the specified store). + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemTriggerIds(IStore _store, bytes32 id, uint256 _index) internal view returns (bytes32) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 32, (_index + 1) * 32); + return (bytes32(_blob)); + } + } + + /** + * @notice Push an element to triggerIds. + */ + function pushTriggerIds(bytes32 id, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + } + + /** + * @notice Push an element to triggerIds. + */ + function _pushTriggerIds(bytes32 id, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + } + + /** + * @notice Push an element to triggerIds (using the specified store). + */ + function pushTriggerIds(IStore _store, bytes32 id, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.pushToDynamicField(_tableId, _keyTuple, 0, abi.encodePacked((_element))); + } + + /** + * @notice Pop an element from triggerIds. + */ + function popTriggerIds(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 32); + } + + /** + * @notice Pop an element from triggerIds. + */ + function _popTriggerIds(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 32); + } + + /** + * @notice Pop an element from triggerIds (using the specified store). + */ + function popTriggerIds(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.popFromDynamicField(_tableId, _keyTuple, 0, 32); + } + + /** + * @notice Update an element of triggerIds at `_index`. + */ + function updateTriggerIds(bytes32 id, uint256 _index, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = abi.encodePacked((_element)); + StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update an element of triggerIds at `_index`. + */ + function _updateTriggerIds(bytes32 id, uint256 _index, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = abi.encodePacked((_element)); + StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update an element of triggerIds (using the specified store) at `_index`. + */ + function updateTriggerIds(IStore _store, bytes32 id, uint256 _index, bytes32 _element) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = abi.encodePacked((_element)); + _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 32), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Get the full data. + */ + function get(bytes32 id) internal view returns (BaseTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (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(bytes32 id) internal view returns (BaseTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Get the full data (using the specified store). + */ + function get(IStore _store, bytes32 id) internal view returns (BaseTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function set(bytes32 id, BaseTriggerKind kind, bytes32[] memory triggerIds) internal { + bytes memory _staticData = encodeStatic(kind); + + EncodedLengths _encodedLengths = encodeLengths(triggerIds); + bytes memory _dynamicData = encodeDynamic(triggerIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function _set(bytes32 id, BaseTriggerKind kind, bytes32[] memory triggerIds) internal { + bytes memory _staticData = encodeStatic(kind); + + EncodedLengths _encodedLengths = encodeLengths(triggerIds); + bytes memory _dynamicData = encodeDynamic(triggerIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using individual values (using the specified store). + */ + function set(IStore _store, bytes32 id, BaseTriggerKind kind, bytes32[] memory triggerIds) internal { + bytes memory _staticData = encodeStatic(kind); + + EncodedLengths _encodedLengths = encodeLengths(triggerIds); + bytes memory _dynamicData = encodeDynamic(triggerIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function set(bytes32 id, BaseTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.kind); + + EncodedLengths _encodedLengths = encodeLengths(_table.triggerIds); + bytes memory _dynamicData = encodeDynamic(_table.triggerIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function _set(bytes32 id, BaseTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.kind); + + EncodedLengths _encodedLengths = encodeLengths(_table.triggerIds); + bytes memory _dynamicData = encodeDynamic(_table.triggerIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using the data struct (using the specified store). + */ + function set(IStore _store, bytes32 id, BaseTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.kind); + + EncodedLengths _encodedLengths = encodeLengths(_table.triggerIds); + bytes memory _dynamicData = encodeDynamic(_table.triggerIds); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Decode the tightly packed blob of static data using this table's field layout. + */ + function decodeStatic(bytes memory _blob) internal pure returns (BaseTriggerKind kind) { + kind = BaseTriggerKind(uint8(Bytes.getBytes1(_blob, 0))); + } + + /** + * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. + */ + function decodeDynamic( + EncodedLengths _encodedLengths, + bytes memory _blob + ) internal pure returns (bytes32[] memory triggerIds) { + uint256 _start; + uint256 _end; + unchecked { + _end = _encodedLengths.atIndex(0); + } + triggerIds = (SliceLib.getSubslice(_blob, _start, _end).decodeArray_bytes32()); + } + + /** + * @notice Decode the tightly packed blobs using this table's field layout. + * @param _staticData Tightly packed static fields. + * @param _encodedLengths Encoded lengths of dynamic fields. + * @param _dynamicData Tightly packed dynamic fields. + */ + function decode( + bytes memory _staticData, + EncodedLengths _encodedLengths, + bytes memory _dynamicData + ) internal pure returns (BaseTriggerData memory _table) { + (_table.kind) = decodeStatic(_staticData); + + (_table.triggerIds) = decodeDynamic(_encodedLengths, _dynamicData); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Delete all data for given keys (using the specified store). + */ + function deleteRecord(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic(BaseTriggerKind kind) internal pure returns (bytes memory) { + return abi.encodePacked(kind); + } + + /** + * @notice Tightly pack dynamic data lengths using this table's schema. + * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). + */ + function encodeLengths(bytes32[] memory triggerIds) internal pure returns (EncodedLengths _encodedLengths) { + // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits + unchecked { + _encodedLengths = EncodedLengthsLib.pack(triggerIds.length * 32); + } + } + + /** + * @notice Tightly pack dynamic (variable length) data using this table's schema. + * @return The dynamic data, encoded into a sequence of bytes. + */ + function encodeDynamic(bytes32[] memory triggerIds) internal pure returns (bytes memory) { + return abi.encodePacked(EncodeArray.encode((triggerIds))); + } + + /** + * @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( + BaseTriggerKind kind, + bytes32[] memory triggerIds + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic(kind); + + EncodedLengths _encodedLengths = encodeLengths(triggerIds); + bytes memory _dynamicData = encodeDynamic(triggerIds); + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + return _keyTuple; + } +} diff --git a/packages/experience/src/codegen/tables/ChallengeCompleteTrigger.sol b/packages/experience/src/codegen/tables/ChallengeCompleteTrigger.sol new file mode 100644 index 00000000..e971b754 --- /dev/null +++ b/packages/experience/src/codegen/tables/ChallengeCompleteTrigger.sol @@ -0,0 +1,258 @@ +// 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"; + +library ChallengeCompleteTrigger { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "experience", name: "ChallengeComplet", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462657870657269656e6365000000004368616c6c656e6765436f6d706c6574); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32) + Schema constant _valueSchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + + /** + * @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] = "id"; + } + + /** + * @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[](1); + fieldNames[0] = "challengeId"; + } + + /** + * @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 Register the table with its config (using the specified store). + */ + function register(IStore _store) internal { + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get challengeId. + */ + function getChallengeId(bytes32 id) internal view returns (bytes32 challengeId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get challengeId. + */ + function _getChallengeId(bytes32 id) internal view returns (bytes32 challengeId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get challengeId (using the specified store). + */ + function getChallengeId(IStore _store, bytes32 id) internal view returns (bytes32 challengeId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get challengeId. + */ + function get(bytes32 id) internal view returns (bytes32 challengeId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get challengeId. + */ + function _get(bytes32 id) internal view returns (bytes32 challengeId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get challengeId (using the specified store). + */ + function get(IStore _store, bytes32 id) internal view returns (bytes32 challengeId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Set challengeId. + */ + function setChallengeId(bytes32 id, bytes32 challengeId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((challengeId)), _fieldLayout); + } + + /** + * @notice Set challengeId. + */ + function _setChallengeId(bytes32 id, bytes32 challengeId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((challengeId)), _fieldLayout); + } + + /** + * @notice Set challengeId (using the specified store). + */ + function setChallengeId(IStore _store, bytes32 id, bytes32 challengeId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((challengeId)), _fieldLayout); + } + + /** + * @notice Set challengeId. + */ + function set(bytes32 id, bytes32 challengeId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((challengeId)), _fieldLayout); + } + + /** + * @notice Set challengeId. + */ + function _set(bytes32 id, bytes32 challengeId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((challengeId)), _fieldLayout); + } + + /** + * @notice Set challengeId (using the specified store). + */ + function set(IStore _store, bytes32 id, bytes32 challengeId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((challengeId)), _fieldLayout); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Delete all data for given keys (using the specified store). + */ + function deleteRecord(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic(bytes32 challengeId) internal pure returns (bytes memory) { + return abi.encodePacked(challengeId); + } + + /** + * @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(bytes32 challengeId) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic(challengeId); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + return _keyTuple; + } +} diff --git a/packages/experience/src/codegen/tables/CollectTrigger.sol b/packages/experience/src/codegen/tables/CollectTrigger.sol new file mode 100644 index 00000000..61eaf247 --- /dev/null +++ b/packages/experience/src/codegen/tables/CollectTrigger.sol @@ -0,0 +1,425 @@ +// 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"; + +struct CollectTriggerData { + bytes32 objectTypeId; + uint32 count; +} + +library CollectTrigger { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "experience", name: "CollectTrigger", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462657870657269656e636500000000436f6c6c656374547269676765720000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0024020020040000000000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32, uint32) + Schema constant _valueSchema = Schema.wrap(0x002402005f030000000000000000000000000000000000000000000000000000); + + /** + * @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] = "id"; + } + + /** + * @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] = "objectTypeId"; + fieldNames[1] = "count"; + } + + /** + * @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 Register the table with its config (using the specified store). + */ + function register(IStore _store) internal { + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get objectTypeId. + */ + function getObjectTypeId(bytes32 id) internal view returns (bytes32 objectTypeId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get objectTypeId. + */ + function _getObjectTypeId(bytes32 id) internal view returns (bytes32 objectTypeId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get objectTypeId (using the specified store). + */ + function getObjectTypeId(IStore _store, bytes32 id) internal view returns (bytes32 objectTypeId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Set objectTypeId. + */ + function setObjectTypeId(bytes32 id, bytes32 objectTypeId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((objectTypeId)), _fieldLayout); + } + + /** + * @notice Set objectTypeId. + */ + function _setObjectTypeId(bytes32 id, bytes32 objectTypeId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((objectTypeId)), _fieldLayout); + } + + /** + * @notice Set objectTypeId (using the specified store). + */ + function setObjectTypeId(IStore _store, bytes32 id, bytes32 objectTypeId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((objectTypeId)), _fieldLayout); + } + + /** + * @notice Get count. + */ + function getCount(bytes32 id) internal view returns (uint32 count) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** + * @notice Get count. + */ + function _getCount(bytes32 id) internal view returns (uint32 count) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** + * @notice Get count (using the specified store). + */ + function getCount(IStore _store, bytes32 id) internal view returns (uint32 count) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** + * @notice Set count. + */ + function setCount(bytes32 id, uint32 count) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((count)), _fieldLayout); + } + + /** + * @notice Set count. + */ + function _setCount(bytes32 id, uint32 count) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((count)), _fieldLayout); + } + + /** + * @notice Set count (using the specified store). + */ + function setCount(IStore _store, bytes32 id, uint32 count) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((count)), _fieldLayout); + } + + /** + * @notice Get the full data. + */ + function get(bytes32 id) internal view returns (CollectTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (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(bytes32 id) internal view returns (CollectTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Get the full data (using the specified store). + */ + function get(IStore _store, bytes32 id) internal view returns (CollectTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function set(bytes32 id, bytes32 objectTypeId, uint32 count) internal { + bytes memory _staticData = encodeStatic(objectTypeId, count); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function _set(bytes32 id, bytes32 objectTypeId, uint32 count) internal { + bytes memory _staticData = encodeStatic(objectTypeId, count); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using individual values (using the specified store). + */ + function set(IStore _store, bytes32 id, bytes32 objectTypeId, uint32 count) internal { + bytes memory _staticData = encodeStatic(objectTypeId, count); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function set(bytes32 id, CollectTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.objectTypeId, _table.count); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function _set(bytes32 id, CollectTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.objectTypeId, _table.count); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using the data struct (using the specified store). + */ + function set(IStore _store, bytes32 id, CollectTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.objectTypeId, _table.count); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Decode the tightly packed blob of static data using this table's field layout. + */ + function decodeStatic(bytes memory _blob) internal pure returns (bytes32 objectTypeId, uint32 count) { + objectTypeId = (Bytes.getBytes32(_blob, 0)); + + count = (uint32(Bytes.getBytes4(_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 (CollectTriggerData memory _table) { + (_table.objectTypeId, _table.count) = decodeStatic(_staticData); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Delete all data for given keys (using the specified store). + */ + function deleteRecord(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic(bytes32 objectTypeId, uint32 count) internal pure returns (bytes memory) { + return abi.encodePacked(objectTypeId, count); + } + + /** + * @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( + bytes32 objectTypeId, + uint32 count + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic(objectTypeId, count); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + return _keyTuple; + } +} diff --git a/packages/experience/src/codegen/tables/EventTrigger.sol b/packages/experience/src/codegen/tables/EventTrigger.sol new file mode 100644 index 00000000..71f84585 --- /dev/null +++ b/packages/experience/src/codegen/tables/EventTrigger.sol @@ -0,0 +1,498 @@ +// 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 { EventKind } from "./../common.sol"; + +struct EventTriggerData { + EventKind eventKind; + uint32 count; + bytes32 predicateId; +} + +library EventTrigger { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "experience", name: "EventTrigger", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462657870657269656e6365000000004576656e745472696767657200000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0025030001042000000000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint8, uint32, bytes32) + Schema constant _valueSchema = Schema.wrap(0x0025030000035f00000000000000000000000000000000000000000000000000); + + /** + * @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] = "id"; + } + + /** + * @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[](3); + fieldNames[0] = "eventKind"; + fieldNames[1] = "count"; + fieldNames[2] = "predicateId"; + } + + /** + * @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 Register the table with its config (using the specified store). + */ + function register(IStore _store) internal { + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get eventKind. + */ + function getEventKind(bytes32 id) internal view returns (EventKind eventKind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return EventKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get eventKind. + */ + function _getEventKind(bytes32 id) internal view returns (EventKind eventKind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return EventKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get eventKind (using the specified store). + */ + function getEventKind(IStore _store, bytes32 id) internal view returns (EventKind eventKind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return EventKind(uint8(bytes1(_blob))); + } + + /** + * @notice Set eventKind. + */ + function setEventKind(bytes32 id, EventKind eventKind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(eventKind)), _fieldLayout); + } + + /** + * @notice Set eventKind. + */ + function _setEventKind(bytes32 id, EventKind eventKind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(eventKind)), _fieldLayout); + } + + /** + * @notice Set eventKind (using the specified store). + */ + function setEventKind(IStore _store, bytes32 id, EventKind eventKind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(eventKind)), _fieldLayout); + } + + /** + * @notice Get count. + */ + function getCount(bytes32 id) internal view returns (uint32 count) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** + * @notice Get count. + */ + function _getCount(bytes32 id) internal view returns (uint32 count) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** + * @notice Get count (using the specified store). + */ + function getCount(IStore _store, bytes32 id) internal view returns (uint32 count) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** + * @notice Set count. + */ + function setCount(bytes32 id, uint32 count) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((count)), _fieldLayout); + } + + /** + * @notice Set count. + */ + function _setCount(bytes32 id, uint32 count) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((count)), _fieldLayout); + } + + /** + * @notice Set count (using the specified store). + */ + function setCount(IStore _store, bytes32 id, uint32 count) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((count)), _fieldLayout); + } + + /** + * @notice Get predicateId. + */ + function getPredicateId(bytes32 id) internal view returns (bytes32 predicateId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get predicateId. + */ + function _getPredicateId(bytes32 id) internal view returns (bytes32 predicateId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get predicateId (using the specified store). + */ + function getPredicateId(IStore _store, bytes32 id) internal view returns (bytes32 predicateId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Set predicateId. + */ + function setPredicateId(bytes32 id, bytes32 predicateId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((predicateId)), _fieldLayout); + } + + /** + * @notice Set predicateId. + */ + function _setPredicateId(bytes32 id, bytes32 predicateId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((predicateId)), _fieldLayout); + } + + /** + * @notice Set predicateId (using the specified store). + */ + function setPredicateId(IStore _store, bytes32 id, bytes32 predicateId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((predicateId)), _fieldLayout); + } + + /** + * @notice Get the full data. + */ + function get(bytes32 id) internal view returns (EventTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (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(bytes32 id) internal view returns (EventTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Get the full data (using the specified store). + */ + function get(IStore _store, bytes32 id) internal view returns (EventTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function set(bytes32 id, EventKind eventKind, uint32 count, bytes32 predicateId) internal { + bytes memory _staticData = encodeStatic(eventKind, count, predicateId); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function _set(bytes32 id, EventKind eventKind, uint32 count, bytes32 predicateId) internal { + bytes memory _staticData = encodeStatic(eventKind, count, predicateId); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using individual values (using the specified store). + */ + function set(IStore _store, bytes32 id, EventKind eventKind, uint32 count, bytes32 predicateId) internal { + bytes memory _staticData = encodeStatic(eventKind, count, predicateId); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function set(bytes32 id, EventTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.eventKind, _table.count, _table.predicateId); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function _set(bytes32 id, EventTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.eventKind, _table.count, _table.predicateId); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using the data struct (using the specified store). + */ + function set(IStore _store, bytes32 id, EventTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.eventKind, _table.count, _table.predicateId); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Decode the tightly packed blob of static data using this table's field layout. + */ + function decodeStatic( + bytes memory _blob + ) internal pure returns (EventKind eventKind, uint32 count, bytes32 predicateId) { + eventKind = EventKind(uint8(Bytes.getBytes1(_blob, 0))); + + count = (uint32(Bytes.getBytes4(_blob, 1))); + + predicateId = (Bytes.getBytes32(_blob, 5)); + } + + /** + * @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 (EventTriggerData memory _table) { + (_table.eventKind, _table.count, _table.predicateId) = decodeStatic(_staticData); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Delete all data for given keys (using the specified store). + */ + function deleteRecord(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic(EventKind eventKind, uint32 count, bytes32 predicateId) internal pure returns (bytes memory) { + return abi.encodePacked(eventKind, count, predicateId); + } + + /** + * @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( + EventKind eventKind, + uint32 count, + bytes32 predicateId + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic(eventKind, count, predicateId); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + return _keyTuple; + } +} diff --git a/packages/experience/src/codegen/tables/LeafPredicate.sol b/packages/experience/src/codegen/tables/LeafPredicate.sol new file mode 100644 index 00000000..681dfc6e --- /dev/null +++ b/packages/experience/src/codegen/tables/LeafPredicate.sol @@ -0,0 +1,887 @@ +// 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 { LeafPredicateKind } from "./../common.sol"; + +struct LeafPredicateData { + LeafPredicateKind kind; + uint32 valueNum; + bool valueBool; + bytes32 valueId; + string valueString; +} + +library LeafPredicate { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "experience", name: "LeafPredicate", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462657870657269656e6365000000004c656166507265646963617465000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0026040101040120000000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint8, uint32, bool, bytes32, string) + Schema constant _valueSchema = Schema.wrap(0x002604010003605fc50000000000000000000000000000000000000000000000); + + /** + * @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] = "id"; + } + + /** + * @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[](5); + fieldNames[0] = "kind"; + fieldNames[1] = "valueNum"; + fieldNames[2] = "valueBool"; + fieldNames[3] = "valueId"; + fieldNames[4] = "valueString"; + } + + /** + * @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 Register the table with its config (using the specified store). + */ + function register(IStore _store) internal { + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get kind. + */ + function getKind(bytes32 id) internal view returns (LeafPredicateKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return LeafPredicateKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get kind. + */ + function _getKind(bytes32 id) internal view returns (LeafPredicateKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return LeafPredicateKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get kind (using the specified store). + */ + function getKind(IStore _store, bytes32 id) internal view returns (LeafPredicateKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return LeafPredicateKind(uint8(bytes1(_blob))); + } + + /** + * @notice Set kind. + */ + function setKind(bytes32 id, LeafPredicateKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Set kind. + */ + function _setKind(bytes32 id, LeafPredicateKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Set kind (using the specified store). + */ + function setKind(IStore _store, bytes32 id, LeafPredicateKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Get valueNum. + */ + function getValueNum(bytes32 id) internal view returns (uint32 valueNum) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** + * @notice Get valueNum. + */ + function _getValueNum(bytes32 id) internal view returns (uint32 valueNum) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** + * @notice Get valueNum (using the specified store). + */ + function getValueNum(IStore _store, bytes32 id) internal view returns (uint32 valueNum) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (uint32(bytes4(_blob))); + } + + /** + * @notice Set valueNum. + */ + function setValueNum(bytes32 id, uint32 valueNum) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((valueNum)), _fieldLayout); + } + + /** + * @notice Set valueNum. + */ + function _setValueNum(bytes32 id, uint32 valueNum) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((valueNum)), _fieldLayout); + } + + /** + * @notice Set valueNum (using the specified store). + */ + function setValueNum(IStore _store, bytes32 id, uint32 valueNum) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((valueNum)), _fieldLayout); + } + + /** + * @notice Get valueBool. + */ + function getValueBool(bytes32 id) internal view returns (bool valueBool) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** + * @notice Get valueBool. + */ + function _getValueBool(bytes32 id) internal view returns (bool valueBool) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** + * @notice Get valueBool (using the specified store). + */ + function getValueBool(IStore _store, bytes32 id) internal view returns (bool valueBool) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** + * @notice Set valueBool. + */ + function setValueBool(bytes32 id, bool valueBool) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((valueBool)), _fieldLayout); + } + + /** + * @notice Set valueBool. + */ + function _setValueBool(bytes32 id, bool valueBool) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((valueBool)), _fieldLayout); + } + + /** + * @notice Set valueBool (using the specified store). + */ + function setValueBool(IStore _store, bytes32 id, bool valueBool) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((valueBool)), _fieldLayout); + } + + /** + * @notice Get valueId. + */ + function getValueId(bytes32 id) internal view returns (bytes32 valueId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get valueId. + */ + function _getValueId(bytes32 id) internal view returns (bytes32 valueId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get valueId (using the specified store). + */ + function getValueId(IStore _store, bytes32 id) internal view returns (bytes32 valueId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Set valueId. + */ + function setValueId(bytes32 id, bytes32 valueId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((valueId)), _fieldLayout); + } + + /** + * @notice Set valueId. + */ + function _setValueId(bytes32 id, bytes32 valueId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((valueId)), _fieldLayout); + } + + /** + * @notice Set valueId (using the specified store). + */ + function setValueId(IStore _store, bytes32 id, bytes32 valueId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((valueId)), _fieldLayout); + } + + /** + * @notice Get valueString. + */ + function getValueString(bytes32 id) internal view returns (string memory valueString) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** + * @notice Get valueString. + */ + function _getValueString(bytes32 id) internal view returns (string memory valueString) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** + * @notice Get valueString (using the specified store). + */ + function getValueString(IStore _store, bytes32 id) internal view returns (string memory valueString) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** + * @notice Set valueString. + */ + function setValueString(bytes32 id, string memory valueString) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, bytes((valueString))); + } + + /** + * @notice Set valueString. + */ + function _setValueString(bytes32 id, string memory valueString) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setDynamicField(_tableId, _keyTuple, 0, bytes((valueString))); + } + + /** + * @notice Set valueString (using the specified store). + */ + function setValueString(IStore _store, bytes32 id, string memory valueString) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setDynamicField(_tableId, _keyTuple, 0, bytes((valueString))); + } + + /** + * @notice Get the length of valueString. + */ + function lengthValueString(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of valueString. + */ + function _lengthValueString(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of valueString (using the specified store). + */ + function lengthValueString(IStore _store, bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get an item of valueString. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemValueString(bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Get an item of valueString. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function _getItemValueString(bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Get an item of valueString (using the specified store). + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemValueString(IStore _store, bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Push a slice to valueString. + */ + function pushValueString(bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Push a slice to valueString. + */ + function _pushValueString(bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Push a slice to valueString (using the specified store). + */ + function pushValueString(IStore _store, bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Pop a slice from valueString. + */ + function popValueString(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Pop a slice from valueString. + */ + function _popValueString(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Pop a slice from valueString (using the specified store). + */ + function popValueString(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Update a slice of valueString at `_index`. + */ + function updateValueString(bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of valueString at `_index`. + */ + function _updateValueString(bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of valueString (using the specified store) at `_index`. + */ + function updateValueString(IStore _store, bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Get the full data. + */ + function get(bytes32 id) internal view returns (LeafPredicateData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (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(bytes32 id) internal view returns (LeafPredicateData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Get the full data (using the specified store). + */ + function get(IStore _store, bytes32 id) internal view returns (LeafPredicateData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function set( + bytes32 id, + LeafPredicateKind kind, + uint32 valueNum, + bool valueBool, + bytes32 valueId, + string memory valueString + ) internal { + bytes memory _staticData = encodeStatic(kind, valueNum, valueBool, valueId); + + EncodedLengths _encodedLengths = encodeLengths(valueString); + bytes memory _dynamicData = encodeDynamic(valueString); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function _set( + bytes32 id, + LeafPredicateKind kind, + uint32 valueNum, + bool valueBool, + bytes32 valueId, + string memory valueString + ) internal { + bytes memory _staticData = encodeStatic(kind, valueNum, valueBool, valueId); + + EncodedLengths _encodedLengths = encodeLengths(valueString); + bytes memory _dynamicData = encodeDynamic(valueString); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using individual values (using the specified store). + */ + function set( + IStore _store, + bytes32 id, + LeafPredicateKind kind, + uint32 valueNum, + bool valueBool, + bytes32 valueId, + string memory valueString + ) internal { + bytes memory _staticData = encodeStatic(kind, valueNum, valueBool, valueId); + + EncodedLengths _encodedLengths = encodeLengths(valueString); + bytes memory _dynamicData = encodeDynamic(valueString); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function set(bytes32 id, LeafPredicateData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.kind, _table.valueNum, _table.valueBool, _table.valueId); + + EncodedLengths _encodedLengths = encodeLengths(_table.valueString); + bytes memory _dynamicData = encodeDynamic(_table.valueString); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function _set(bytes32 id, LeafPredicateData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.kind, _table.valueNum, _table.valueBool, _table.valueId); + + EncodedLengths _encodedLengths = encodeLengths(_table.valueString); + bytes memory _dynamicData = encodeDynamic(_table.valueString); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using the data struct (using the specified store). + */ + function set(IStore _store, bytes32 id, LeafPredicateData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.kind, _table.valueNum, _table.valueBool, _table.valueId); + + EncodedLengths _encodedLengths = encodeLengths(_table.valueString); + bytes memory _dynamicData = encodeDynamic(_table.valueString); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Decode the tightly packed blob of static data using this table's field layout. + */ + function decodeStatic( + bytes memory _blob + ) internal pure returns (LeafPredicateKind kind, uint32 valueNum, bool valueBool, bytes32 valueId) { + kind = LeafPredicateKind(uint8(Bytes.getBytes1(_blob, 0))); + + valueNum = (uint32(Bytes.getBytes4(_blob, 1))); + + valueBool = (_toBool(uint8(Bytes.getBytes1(_blob, 5)))); + + valueId = (Bytes.getBytes32(_blob, 6)); + } + + /** + * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. + */ + function decodeDynamic( + EncodedLengths _encodedLengths, + bytes memory _blob + ) internal pure returns (string memory valueString) { + uint256 _start; + uint256 _end; + unchecked { + _end = _encodedLengths.atIndex(0); + } + valueString = (string(SliceLib.getSubslice(_blob, _start, _end).toBytes())); + } + + /** + * @notice Decode the tightly packed blobs using this table's field layout. + * @param _staticData Tightly packed static fields. + * @param _encodedLengths Encoded lengths of dynamic fields. + * @param _dynamicData Tightly packed dynamic fields. + */ + function decode( + bytes memory _staticData, + EncodedLengths _encodedLengths, + bytes memory _dynamicData + ) internal pure returns (LeafPredicateData memory _table) { + (_table.kind, _table.valueNum, _table.valueBool, _table.valueId) = decodeStatic(_staticData); + + (_table.valueString) = decodeDynamic(_encodedLengths, _dynamicData); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Delete all data for given keys (using the specified store). + */ + function deleteRecord(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic( + LeafPredicateKind kind, + uint32 valueNum, + bool valueBool, + bytes32 valueId + ) internal pure returns (bytes memory) { + return abi.encodePacked(kind, valueNum, valueBool, valueId); + } + + /** + * @notice Tightly pack dynamic data lengths using this table's schema. + * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). + */ + function encodeLengths(string memory valueString) internal pure returns (EncodedLengths _encodedLengths) { + // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits + unchecked { + _encodedLengths = EncodedLengthsLib.pack(bytes(valueString).length); + } + } + + /** + * @notice Tightly pack dynamic (variable length) data using this table's schema. + * @return The dynamic data, encoded into a sequence of bytes. + */ + function encodeDynamic(string memory valueString) internal pure returns (bytes memory) { + return abi.encodePacked(bytes((valueString))); + } + + /** + * @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( + LeafPredicateKind kind, + uint32 valueNum, + bool valueBool, + bytes32 valueId, + string memory valueString + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic(kind, valueNum, valueBool, valueId); + + EncodedLengths _encodedLengths = encodeLengths(valueString); + bytes memory _dynamicData = encodeDynamic(valueString); + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + return _keyTuple; + } +} + +/** + * @notice Cast a value to a bool. + * @dev Boolean values are encoded as uint8 (1 = true, 0 = false), but Solidity doesn't allow casting between uint8 and bool. + * @param value The uint8 value to convert. + * @return result The boolean value. + */ +function _toBool(uint8 value) pure returns (bool result) { + assembly { + result := value + } +} diff --git a/packages/experience/src/codegen/tables/LeafTrigger.sol b/packages/experience/src/codegen/tables/LeafTrigger.sol new file mode 100644 index 00000000..8f8c11dd --- /dev/null +++ b/packages/experience/src/codegen/tables/LeafTrigger.sol @@ -0,0 +1,1094 @@ +// 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 { LeafTriggerKind, NavigationAidKind } from "./../common.sol"; + +struct LeafTriggerData { + LeafTriggerKind kind; + NavigationAidKind navigationAidKind; + int16 navigationAidPosX; + int16 navigationAidPosY; + int16 navigationAidPosZ; + bytes32 navigaitonAidEntity; + string name; +} + +library LeafTrigger { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "experience", name: "LeafTrigger", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462657870657269656e6365000000004c656166547269676765720000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0028060101010202022000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint8, uint8, int16, int16, int16, bytes32, string) + Schema constant _valueSchema = Schema.wrap(0x0028060100002121215fc5000000000000000000000000000000000000000000); + + /** + * @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] = "id"; + } + + /** + * @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[](7); + fieldNames[0] = "kind"; + fieldNames[1] = "navigationAidKind"; + fieldNames[2] = "navigationAidPosX"; + fieldNames[3] = "navigationAidPosY"; + fieldNames[4] = "navigationAidPosZ"; + fieldNames[5] = "navigaitonAidEntity"; + fieldNames[6] = "name"; + } + + /** + * @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 Register the table with its config (using the specified store). + */ + function register(IStore _store) internal { + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get kind. + */ + function getKind(bytes32 id) internal view returns (LeafTriggerKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return LeafTriggerKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get kind. + */ + function _getKind(bytes32 id) internal view returns (LeafTriggerKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return LeafTriggerKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get kind (using the specified store). + */ + function getKind(IStore _store, bytes32 id) internal view returns (LeafTriggerKind kind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return LeafTriggerKind(uint8(bytes1(_blob))); + } + + /** + * @notice Set kind. + */ + function setKind(bytes32 id, LeafTriggerKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Set kind. + */ + function _setKind(bytes32 id, LeafTriggerKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Set kind (using the specified store). + */ + function setKind(IStore _store, bytes32 id, LeafTriggerKind kind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked(uint8(kind)), _fieldLayout); + } + + /** + * @notice Get navigationAidKind. + */ + function getNavigationAidKind(bytes32 id) internal view returns (NavigationAidKind navigationAidKind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return NavigationAidKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get navigationAidKind. + */ + function _getNavigationAidKind(bytes32 id) internal view returns (NavigationAidKind navigationAidKind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return NavigationAidKind(uint8(bytes1(_blob))); + } + + /** + * @notice Get navigationAidKind (using the specified store). + */ + function getNavigationAidKind(IStore _store, bytes32 id) internal view returns (NavigationAidKind navigationAidKind) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return NavigationAidKind(uint8(bytes1(_blob))); + } + + /** + * @notice Set navigationAidKind. + */ + function setNavigationAidKind(bytes32 id, NavigationAidKind navigationAidKind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked(uint8(navigationAidKind)), _fieldLayout); + } + + /** + * @notice Set navigationAidKind. + */ + function _setNavigationAidKind(bytes32 id, NavigationAidKind navigationAidKind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked(uint8(navigationAidKind)), _fieldLayout); + } + + /** + * @notice Set navigationAidKind (using the specified store). + */ + function setNavigationAidKind(IStore _store, bytes32 id, NavigationAidKind navigationAidKind) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked(uint8(navigationAidKind)), _fieldLayout); + } + + /** + * @notice Get navigationAidPosX. + */ + function getNavigationAidPosX(bytes32 id) internal view returns (int16 navigationAidPosX) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get navigationAidPosX. + */ + function _getNavigationAidPosX(bytes32 id) internal view returns (int16 navigationAidPosX) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get navigationAidPosX (using the specified store). + */ + function getNavigationAidPosX(IStore _store, bytes32 id) internal view returns (int16 navigationAidPosX) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Set navigationAidPosX. + */ + function setNavigationAidPosX(bytes32 id, int16 navigationAidPosX) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((navigationAidPosX)), _fieldLayout); + } + + /** + * @notice Set navigationAidPosX. + */ + function _setNavigationAidPosX(bytes32 id, int16 navigationAidPosX) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((navigationAidPosX)), _fieldLayout); + } + + /** + * @notice Set navigationAidPosX (using the specified store). + */ + function setNavigationAidPosX(IStore _store, bytes32 id, int16 navigationAidPosX) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((navigationAidPosX)), _fieldLayout); + } + + /** + * @notice Get navigationAidPosY. + */ + function getNavigationAidPosY(bytes32 id) internal view returns (int16 navigationAidPosY) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get navigationAidPosY. + */ + function _getNavigationAidPosY(bytes32 id) internal view returns (int16 navigationAidPosY) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get navigationAidPosY (using the specified store). + */ + function getNavigationAidPosY(IStore _store, bytes32 id) internal view returns (int16 navigationAidPosY) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Set navigationAidPosY. + */ + function setNavigationAidPosY(bytes32 id, int16 navigationAidPosY) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((navigationAidPosY)), _fieldLayout); + } + + /** + * @notice Set navigationAidPosY. + */ + function _setNavigationAidPosY(bytes32 id, int16 navigationAidPosY) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((navigationAidPosY)), _fieldLayout); + } + + /** + * @notice Set navigationAidPosY (using the specified store). + */ + function setNavigationAidPosY(IStore _store, bytes32 id, int16 navigationAidPosY) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((navigationAidPosY)), _fieldLayout); + } + + /** + * @notice Get navigationAidPosZ. + */ + function getNavigationAidPosZ(bytes32 id) internal view returns (int16 navigationAidPosZ) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get navigationAidPosZ. + */ + function _getNavigationAidPosZ(bytes32 id) internal view returns (int16 navigationAidPosZ) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get navigationAidPosZ (using the specified store). + */ + function getNavigationAidPosZ(IStore _store, bytes32 id) internal view returns (int16 navigationAidPosZ) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Set navigationAidPosZ. + */ + function setNavigationAidPosZ(bytes32 id, int16 navigationAidPosZ) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((navigationAidPosZ)), _fieldLayout); + } + + /** + * @notice Set navigationAidPosZ. + */ + function _setNavigationAidPosZ(bytes32 id, int16 navigationAidPosZ) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((navigationAidPosZ)), _fieldLayout); + } + + /** + * @notice Set navigationAidPosZ (using the specified store). + */ + function setNavigationAidPosZ(IStore _store, bytes32 id, int16 navigationAidPosZ) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((navigationAidPosZ)), _fieldLayout); + } + + /** + * @notice Get navigaitonAidEntity. + */ + function getNavigaitonAidEntity(bytes32 id) internal view returns (bytes32 navigaitonAidEntity) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 5, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get navigaitonAidEntity. + */ + function _getNavigaitonAidEntity(bytes32 id) internal view returns (bytes32 navigaitonAidEntity) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 5, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get navigaitonAidEntity (using the specified store). + */ + function getNavigaitonAidEntity(IStore _store, bytes32 id) internal view returns (bytes32 navigaitonAidEntity) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 5, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Set navigaitonAidEntity. + */ + function setNavigaitonAidEntity(bytes32 id, bytes32 navigaitonAidEntity) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 5, abi.encodePacked((navigaitonAidEntity)), _fieldLayout); + } + + /** + * @notice Set navigaitonAidEntity. + */ + function _setNavigaitonAidEntity(bytes32 id, bytes32 navigaitonAidEntity) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 5, abi.encodePacked((navigaitonAidEntity)), _fieldLayout); + } + + /** + * @notice Set navigaitonAidEntity (using the specified store). + */ + function setNavigaitonAidEntity(IStore _store, bytes32 id, bytes32 navigaitonAidEntity) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 5, abi.encodePacked((navigaitonAidEntity)), _fieldLayout); + } + + /** + * @notice Get name. + */ + function getName(bytes32 id) internal view returns (string memory name) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** + * @notice Get name. + */ + function _getName(bytes32 id) internal view returns (string memory name) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** + * @notice Get name (using the specified store). + */ + function getName(IStore _store, bytes32 id) internal view returns (string memory name) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** + * @notice Set name. + */ + function setName(bytes32 id, string memory name) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, bytes((name))); + } + + /** + * @notice Set name. + */ + function _setName(bytes32 id, string memory name) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setDynamicField(_tableId, _keyTuple, 0, bytes((name))); + } + + /** + * @notice Set name (using the specified store). + */ + function setName(IStore _store, bytes32 id, string memory name) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setDynamicField(_tableId, _keyTuple, 0, bytes((name))); + } + + /** + * @notice Get the length of name. + */ + function lengthName(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of name. + */ + function _lengthName(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of name (using the specified store). + */ + function lengthName(IStore _store, bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get an item of name. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemName(bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Get an item of name. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function _getItemName(bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Get an item of name (using the specified store). + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemName(IStore _store, bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Push a slice to name. + */ + function pushName(bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Push a slice to name. + */ + function _pushName(bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Push a slice to name (using the specified store). + */ + function pushName(IStore _store, bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Pop a slice from name. + */ + function popName(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Pop a slice from name. + */ + function _popName(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Pop a slice from name (using the specified store). + */ + function popName(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Update a slice of name at `_index`. + */ + function updateName(bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of name at `_index`. + */ + function _updateName(bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of name (using the specified store) at `_index`. + */ + function updateName(IStore _store, bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Get the full data. + */ + function get(bytes32 id) internal view returns (LeafTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (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(bytes32 id) internal view returns (LeafTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Get the full data (using the specified store). + */ + function get(IStore _store, bytes32 id) internal view returns (LeafTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function set( + bytes32 id, + LeafTriggerKind kind, + NavigationAidKind navigationAidKind, + int16 navigationAidPosX, + int16 navigationAidPosY, + int16 navigationAidPosZ, + bytes32 navigaitonAidEntity, + string memory name + ) internal { + bytes memory _staticData = encodeStatic( + kind, + navigationAidKind, + navigationAidPosX, + navigationAidPosY, + navigationAidPosZ, + navigaitonAidEntity + ); + + EncodedLengths _encodedLengths = encodeLengths(name); + bytes memory _dynamicData = encodeDynamic(name); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function _set( + bytes32 id, + LeafTriggerKind kind, + NavigationAidKind navigationAidKind, + int16 navigationAidPosX, + int16 navigationAidPosY, + int16 navigationAidPosZ, + bytes32 navigaitonAidEntity, + string memory name + ) internal { + bytes memory _staticData = encodeStatic( + kind, + navigationAidKind, + navigationAidPosX, + navigationAidPosY, + navigationAidPosZ, + navigaitonAidEntity + ); + + EncodedLengths _encodedLengths = encodeLengths(name); + bytes memory _dynamicData = encodeDynamic(name); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using individual values (using the specified store). + */ + function set( + IStore _store, + bytes32 id, + LeafTriggerKind kind, + NavigationAidKind navigationAidKind, + int16 navigationAidPosX, + int16 navigationAidPosY, + int16 navigationAidPosZ, + bytes32 navigaitonAidEntity, + string memory name + ) internal { + bytes memory _staticData = encodeStatic( + kind, + navigationAidKind, + navigationAidPosX, + navigationAidPosY, + navigationAidPosZ, + navigaitonAidEntity + ); + + EncodedLengths _encodedLengths = encodeLengths(name); + bytes memory _dynamicData = encodeDynamic(name); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function set(bytes32 id, LeafTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic( + _table.kind, + _table.navigationAidKind, + _table.navigationAidPosX, + _table.navigationAidPosY, + _table.navigationAidPosZ, + _table.navigaitonAidEntity + ); + + EncodedLengths _encodedLengths = encodeLengths(_table.name); + bytes memory _dynamicData = encodeDynamic(_table.name); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function _set(bytes32 id, LeafTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic( + _table.kind, + _table.navigationAidKind, + _table.navigationAidPosX, + _table.navigationAidPosY, + _table.navigationAidPosZ, + _table.navigaitonAidEntity + ); + + EncodedLengths _encodedLengths = encodeLengths(_table.name); + bytes memory _dynamicData = encodeDynamic(_table.name); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using the data struct (using the specified store). + */ + function set(IStore _store, bytes32 id, LeafTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic( + _table.kind, + _table.navigationAidKind, + _table.navigationAidPosX, + _table.navigationAidPosY, + _table.navigationAidPosZ, + _table.navigaitonAidEntity + ); + + EncodedLengths _encodedLengths = encodeLengths(_table.name); + bytes memory _dynamicData = encodeDynamic(_table.name); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Decode the tightly packed blob of static data using this table's field layout. + */ + function decodeStatic( + bytes memory _blob + ) + internal + pure + returns ( + LeafTriggerKind kind, + NavigationAidKind navigationAidKind, + int16 navigationAidPosX, + int16 navigationAidPosY, + int16 navigationAidPosZ, + bytes32 navigaitonAidEntity + ) + { + kind = LeafTriggerKind(uint8(Bytes.getBytes1(_blob, 0))); + + navigationAidKind = NavigationAidKind(uint8(Bytes.getBytes1(_blob, 1))); + + navigationAidPosX = (int16(uint16(Bytes.getBytes2(_blob, 2)))); + + navigationAidPosY = (int16(uint16(Bytes.getBytes2(_blob, 4)))); + + navigationAidPosZ = (int16(uint16(Bytes.getBytes2(_blob, 6)))); + + navigaitonAidEntity = (Bytes.getBytes32(_blob, 8)); + } + + /** + * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. + */ + function decodeDynamic( + EncodedLengths _encodedLengths, + bytes memory _blob + ) internal pure returns (string memory name) { + uint256 _start; + uint256 _end; + unchecked { + _end = _encodedLengths.atIndex(0); + } + name = (string(SliceLib.getSubslice(_blob, _start, _end).toBytes())); + } + + /** + * @notice Decode the tightly packed blobs using this table's field layout. + * @param _staticData Tightly packed static fields. + * @param _encodedLengths Encoded lengths of dynamic fields. + * @param _dynamicData Tightly packed dynamic fields. + */ + function decode( + bytes memory _staticData, + EncodedLengths _encodedLengths, + bytes memory _dynamicData + ) internal pure returns (LeafTriggerData memory _table) { + ( + _table.kind, + _table.navigationAidKind, + _table.navigationAidPosX, + _table.navigationAidPosY, + _table.navigationAidPosZ, + _table.navigaitonAidEntity + ) = decodeStatic(_staticData); + + (_table.name) = decodeDynamic(_encodedLengths, _dynamicData); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Delete all data for given keys (using the specified store). + */ + function deleteRecord(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic( + LeafTriggerKind kind, + NavigationAidKind navigationAidKind, + int16 navigationAidPosX, + int16 navigationAidPosY, + int16 navigationAidPosZ, + bytes32 navigaitonAidEntity + ) internal pure returns (bytes memory) { + return + abi.encodePacked( + kind, + navigationAidKind, + navigationAidPosX, + navigationAidPosY, + navigationAidPosZ, + navigaitonAidEntity + ); + } + + /** + * @notice Tightly pack dynamic data lengths using this table's schema. + * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). + */ + function encodeLengths(string memory name) internal pure returns (EncodedLengths _encodedLengths) { + // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits + unchecked { + _encodedLengths = EncodedLengthsLib.pack(bytes(name).length); + } + } + + /** + * @notice Tightly pack dynamic (variable length) data using this table's schema. + * @return The dynamic data, encoded into a sequence of bytes. + */ + function encodeDynamic(string memory name) internal pure returns (bytes memory) { + return abi.encodePacked(bytes((name))); + } + + /** + * @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( + LeafTriggerKind kind, + NavigationAidKind navigationAidKind, + int16 navigationAidPosX, + int16 navigationAidPosY, + int16 navigationAidPosZ, + bytes32 navigaitonAidEntity, + string memory name + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic( + kind, + navigationAidKind, + navigationAidPosX, + navigationAidPosY, + navigationAidPosZ, + navigaitonAidEntity + ); + + EncodedLengths _encodedLengths = encodeLengths(name); + bytes memory _dynamicData = encodeDynamic(name); + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + return _keyTuple; + } +} diff --git a/packages/experience/src/codegen/tables/MapBeamTrigger.sol b/packages/experience/src/codegen/tables/MapBeamTrigger.sol new file mode 100644 index 00000000..a894d9d7 --- /dev/null +++ b/packages/experience/src/codegen/tables/MapBeamTrigger.sol @@ -0,0 +1,510 @@ +// 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"; + +struct MapBeamTriggerData { + int16 posX; + int16 posZ; + bool allowDefaultNavigationAid; +} + +library MapBeamTrigger { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "experience", name: "MapBeamTrigger", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462657870657269656e6365000000004d61704265616d547269676765720000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0005030002020100000000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (int16, int16, bool) + Schema constant _valueSchema = Schema.wrap(0x0005030021216000000000000000000000000000000000000000000000000000); + + /** + * @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] = "id"; + } + + /** + * @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[](3); + fieldNames[0] = "posX"; + fieldNames[1] = "posZ"; + fieldNames[2] = "allowDefaultNavigationAid"; + } + + /** + * @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 Register the table with its config (using the specified store). + */ + function register(IStore _store) internal { + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get posX. + */ + function getPosX(bytes32 id) internal view returns (int16 posX) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get posX. + */ + function _getPosX(bytes32 id) internal view returns (int16 posX) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get posX (using the specified store). + */ + function getPosX(IStore _store, bytes32 id) internal view returns (int16 posX) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Set posX. + */ + function setPosX(bytes32 id, int16 posX) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((posX)), _fieldLayout); + } + + /** + * @notice Set posX. + */ + function _setPosX(bytes32 id, int16 posX) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((posX)), _fieldLayout); + } + + /** + * @notice Set posX (using the specified store). + */ + function setPosX(IStore _store, bytes32 id, int16 posX) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((posX)), _fieldLayout); + } + + /** + * @notice Get posZ. + */ + function getPosZ(bytes32 id) internal view returns (int16 posZ) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get posZ. + */ + function _getPosZ(bytes32 id) internal view returns (int16 posZ) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Get posZ (using the specified store). + */ + function getPosZ(IStore _store, bytes32 id) internal view returns (int16 posZ) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (int16(uint16(bytes2(_blob)))); + } + + /** + * @notice Set posZ. + */ + function setPosZ(bytes32 id, int16 posZ) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((posZ)), _fieldLayout); + } + + /** + * @notice Set posZ. + */ + function _setPosZ(bytes32 id, int16 posZ) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((posZ)), _fieldLayout); + } + + /** + * @notice Set posZ (using the specified store). + */ + function setPosZ(IStore _store, bytes32 id, int16 posZ) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((posZ)), _fieldLayout); + } + + /** + * @notice Get allowDefaultNavigationAid. + */ + function getAllowDefaultNavigationAid(bytes32 id) internal view returns (bool allowDefaultNavigationAid) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** + * @notice Get allowDefaultNavigationAid. + */ + function _getAllowDefaultNavigationAid(bytes32 id) internal view returns (bool allowDefaultNavigationAid) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** + * @notice Get allowDefaultNavigationAid (using the specified store). + */ + function getAllowDefaultNavigationAid( + IStore _store, + bytes32 id + ) internal view returns (bool allowDefaultNavigationAid) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); + return (_toBool(uint8(bytes1(_blob)))); + } + + /** + * @notice Set allowDefaultNavigationAid. + */ + function setAllowDefaultNavigationAid(bytes32 id, bool allowDefaultNavigationAid) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((allowDefaultNavigationAid)), _fieldLayout); + } + + /** + * @notice Set allowDefaultNavigationAid. + */ + function _setAllowDefaultNavigationAid(bytes32 id, bool allowDefaultNavigationAid) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((allowDefaultNavigationAid)), _fieldLayout); + } + + /** + * @notice Set allowDefaultNavigationAid (using the specified store). + */ + function setAllowDefaultNavigationAid(IStore _store, bytes32 id, bool allowDefaultNavigationAid) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((allowDefaultNavigationAid)), _fieldLayout); + } + + /** + * @notice Get the full data. + */ + function get(bytes32 id) internal view returns (MapBeamTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (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(bytes32 id) internal view returns (MapBeamTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Get the full data (using the specified store). + */ + function get(IStore _store, bytes32 id) internal view returns (MapBeamTriggerData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function set(bytes32 id, int16 posX, int16 posZ, bool allowDefaultNavigationAid) internal { + bytes memory _staticData = encodeStatic(posX, posZ, allowDefaultNavigationAid); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function _set(bytes32 id, int16 posX, int16 posZ, bool allowDefaultNavigationAid) internal { + bytes memory _staticData = encodeStatic(posX, posZ, allowDefaultNavigationAid); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using individual values (using the specified store). + */ + function set(IStore _store, bytes32 id, int16 posX, int16 posZ, bool allowDefaultNavigationAid) internal { + bytes memory _staticData = encodeStatic(posX, posZ, allowDefaultNavigationAid); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function set(bytes32 id, MapBeamTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.posX, _table.posZ, _table.allowDefaultNavigationAid); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function _set(bytes32 id, MapBeamTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.posX, _table.posZ, _table.allowDefaultNavigationAid); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using the data struct (using the specified store). + */ + function set(IStore _store, bytes32 id, MapBeamTriggerData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.posX, _table.posZ, _table.allowDefaultNavigationAid); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Decode the tightly packed blob of static data using this table's field layout. + */ + function decodeStatic( + bytes memory _blob + ) internal pure returns (int16 posX, int16 posZ, bool allowDefaultNavigationAid) { + posX = (int16(uint16(Bytes.getBytes2(_blob, 0)))); + + posZ = (int16(uint16(Bytes.getBytes2(_blob, 2)))); + + allowDefaultNavigationAid = (_toBool(uint8(Bytes.getBytes1(_blob, 4)))); + } + + /** + * @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 (MapBeamTriggerData memory _table) { + (_table.posX, _table.posZ, _table.allowDefaultNavigationAid) = decodeStatic(_staticData); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Delete all data for given keys (using the specified store). + */ + function deleteRecord(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic(int16 posX, int16 posZ, bool allowDefaultNavigationAid) internal pure returns (bytes memory) { + return abi.encodePacked(posX, posZ, allowDefaultNavigationAid); + } + + /** + * @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( + int16 posX, + int16 posZ, + bool allowDefaultNavigationAid + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic(posX, posZ, allowDefaultNavigationAid); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + return _keyTuple; + } +} + +/** + * @notice Cast a value to a bool. + * @dev Boolean values are encoded as uint8 (1 = true, 0 = false), but Solidity doesn't allow casting between uint8 and bool. + * @param value The uint8 value to convert. + * @return result The boolean value. + */ +function _toBool(uint8 value) pure returns (bool result) { + assembly { + result := value + } +} diff --git a/packages/experience/src/codegen/tables/Quest.sol b/packages/experience/src/codegen/tables/Quest.sol new file mode 100644 index 00000000..83c3c52b --- /dev/null +++ b/packages/experience/src/codegen/tables/Quest.sol @@ -0,0 +1,981 @@ +// 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"; + +struct QuestData { + bytes32 unlockId; + bytes32 triggerId; + string nameId; + string displayName; +} + +library Quest { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "experience", name: "Quest", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462657870657269656e63650000000051756573740000000000000000000000); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0040020220200000000000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (bytes32) + Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (bytes32, bytes32, string, string) + Schema constant _valueSchema = Schema.wrap(0x004002025f5fc5c5000000000000000000000000000000000000000000000000); + + /** + * @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] = "id"; + } + + /** + * @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[](4); + fieldNames[0] = "unlockId"; + fieldNames[1] = "triggerId"; + fieldNames[2] = "nameId"; + fieldNames[3] = "displayName"; + } + + /** + * @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 Register the table with its config (using the specified store). + */ + function register(IStore _store) internal { + _store.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get unlockId. + */ + function getUnlockId(bytes32 id) internal view returns (bytes32 unlockId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get unlockId. + */ + function _getUnlockId(bytes32 id) internal view returns (bytes32 unlockId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get unlockId (using the specified store). + */ + function getUnlockId(IStore _store, bytes32 id) internal view returns (bytes32 unlockId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Set unlockId. + */ + function setUnlockId(bytes32 id, bytes32 unlockId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((unlockId)), _fieldLayout); + } + + /** + * @notice Set unlockId. + */ + function _setUnlockId(bytes32 id, bytes32 unlockId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((unlockId)), _fieldLayout); + } + + /** + * @notice Set unlockId (using the specified store). + */ + function setUnlockId(IStore _store, bytes32 id, bytes32 unlockId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((unlockId)), _fieldLayout); + } + + /** + * @notice Get triggerId. + */ + function getTriggerId(bytes32 id) internal view returns (bytes32 triggerId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get triggerId. + */ + function _getTriggerId(bytes32 id) internal view returns (bytes32 triggerId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Get triggerId (using the specified store). + */ + function getTriggerId(IStore _store, bytes32 id) internal view returns (bytes32 triggerId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes32 _blob = _store.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); + return (bytes32(_blob)); + } + + /** + * @notice Set triggerId. + */ + function setTriggerId(bytes32 id, bytes32 triggerId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((triggerId)), _fieldLayout); + } + + /** + * @notice Set triggerId. + */ + function _setTriggerId(bytes32 id, bytes32 triggerId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((triggerId)), _fieldLayout); + } + + /** + * @notice Set triggerId (using the specified store). + */ + function setTriggerId(IStore _store, bytes32 id, bytes32 triggerId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((triggerId)), _fieldLayout); + } + + /** + * @notice Get nameId. + */ + function getNameId(bytes32 id) internal view returns (string memory nameId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** + * @notice Get nameId. + */ + function _getNameId(bytes32 id) internal view returns (string memory nameId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** + * @notice Get nameId (using the specified store). + */ + function getNameId(IStore _store, bytes32 id) internal view returns (string memory nameId) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 0); + return (string(_blob)); + } + + /** + * @notice Set nameId. + */ + function setNameId(bytes32 id, string memory nameId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, bytes((nameId))); + } + + /** + * @notice Set nameId. + */ + function _setNameId(bytes32 id, string memory nameId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setDynamicField(_tableId, _keyTuple, 0, bytes((nameId))); + } + + /** + * @notice Set nameId (using the specified store). + */ + function setNameId(IStore _store, bytes32 id, string memory nameId) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setDynamicField(_tableId, _keyTuple, 0, bytes((nameId))); + } + + /** + * @notice Get the length of nameId. + */ + function lengthNameId(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of nameId. + */ + function _lengthNameId(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of nameId (using the specified store). + */ + function lengthNameId(IStore _store, bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 0); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get an item of nameId. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemNameId(bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Get an item of nameId. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function _getItemNameId(bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Get an item of nameId (using the specified store). + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemNameId(IStore _store, bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Push a slice to nameId. + */ + function pushNameId(bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Push a slice to nameId. + */ + function _pushNameId(bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Push a slice to nameId (using the specified store). + */ + function pushNameId(IStore _store, bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); + } + + /** + * @notice Pop a slice from nameId. + */ + function popNameId(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Pop a slice from nameId. + */ + function _popNameId(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Pop a slice from nameId (using the specified store). + */ + function popNameId(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.popFromDynamicField(_tableId, _keyTuple, 0, 1); + } + + /** + * @notice Update a slice of nameId at `_index`. + */ + function updateNameId(bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of nameId at `_index`. + */ + function _updateNameId(bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of nameId (using the specified store) at `_index`. + */ + function updateNameId(IStore _store, bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + _store.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Get displayName. + */ + function getDisplayName(bytes32 id) internal view returns (string memory displayName) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); + return (string(_blob)); + } + + /** + * @notice Get displayName. + */ + function _getDisplayName(bytes32 id) internal view returns (string memory displayName) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 1); + return (string(_blob)); + } + + /** + * @notice Get displayName (using the specified store). + */ + function getDisplayName(IStore _store, bytes32 id) internal view returns (string memory displayName) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + bytes memory _blob = _store.getDynamicField(_tableId, _keyTuple, 1); + return (string(_blob)); + } + + /** + * @notice Set displayName. + */ + function setDisplayName(bytes32 id, string memory displayName) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setDynamicField(_tableId, _keyTuple, 1, bytes((displayName))); + } + + /** + * @notice Set displayName. + */ + function _setDisplayName(bytes32 id, string memory displayName) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setDynamicField(_tableId, _keyTuple, 1, bytes((displayName))); + } + + /** + * @notice Set displayName (using the specified store). + */ + function setDisplayName(IStore _store, bytes32 id, string memory displayName) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setDynamicField(_tableId, _keyTuple, 1, bytes((displayName))); + } + + /** + * @notice Get the length of displayName. + */ + function lengthDisplayName(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 1); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of displayName. + */ + function _lengthDisplayName(bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 1); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get the length of displayName (using the specified store). + */ + function lengthDisplayName(IStore _store, bytes32 id) internal view returns (uint256) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + uint256 _byteLength = _store.getDynamicFieldLength(_tableId, _keyTuple, 1); + unchecked { + return _byteLength / 1; + } + } + + /** + * @notice Get an item of displayName. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemDisplayName(bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Get an item of displayName. + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function _getItemDisplayName(bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Get an item of displayName (using the specified store). + * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. + */ + function getItemDisplayName(IStore _store, bytes32 id, uint256 _index) internal view returns (string memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _blob = _store.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); + return (string(_blob)); + } + } + + /** + * @notice Push a slice to displayName. + */ + function pushDisplayName(bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); + } + + /** + * @notice Push a slice to displayName. + */ + function _pushDisplayName(bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); + } + + /** + * @notice Push a slice to displayName (using the specified store). + */ + function pushDisplayName(IStore _store, bytes32 id, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); + } + + /** + * @notice Pop a slice from displayName. + */ + function popDisplayName(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 1, 1); + } + + /** + * @notice Pop a slice from displayName. + */ + function _popDisplayName(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.popFromDynamicField(_tableId, _keyTuple, 1, 1); + } + + /** + * @notice Pop a slice from displayName (using the specified store). + */ + function popDisplayName(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.popFromDynamicField(_tableId, _keyTuple, 1, 1); + } + + /** + * @notice Update a slice of displayName at `_index`. + */ + function updateDisplayName(bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of displayName at `_index`. + */ + function _updateDisplayName(bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + StoreCore.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Update a slice of displayName (using the specified store) at `_index`. + */ + function updateDisplayName(IStore _store, bytes32 id, uint256 _index, string memory _slice) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + unchecked { + bytes memory _encoded = bytes((_slice)); + _store.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); + } + } + + /** + * @notice Get the full data. + */ + function get(bytes32 id) internal view returns (QuestData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (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(bytes32 id) internal view returns (QuestData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Get the full data (using the specified store). + */ + function get(IStore _store, bytes32 id) internal view returns (QuestData memory _table) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = _store.getRecord( + _tableId, + _keyTuple, + _fieldLayout + ); + return decode(_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function set( + bytes32 id, + bytes32 unlockId, + bytes32 triggerId, + string memory nameId, + string memory displayName + ) internal { + bytes memory _staticData = encodeStatic(unlockId, triggerId); + + EncodedLengths _encodedLengths = encodeLengths(nameId, displayName); + bytes memory _dynamicData = encodeDynamic(nameId, displayName); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using individual values. + */ + function _set( + bytes32 id, + bytes32 unlockId, + bytes32 triggerId, + string memory nameId, + string memory displayName + ) internal { + bytes memory _staticData = encodeStatic(unlockId, triggerId); + + EncodedLengths _encodedLengths = encodeLengths(nameId, displayName); + bytes memory _dynamicData = encodeDynamic(nameId, displayName); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using individual values (using the specified store). + */ + function set( + IStore _store, + bytes32 id, + bytes32 unlockId, + bytes32 triggerId, + string memory nameId, + string memory displayName + ) internal { + bytes memory _staticData = encodeStatic(unlockId, triggerId); + + EncodedLengths _encodedLengths = encodeLengths(nameId, displayName); + bytes memory _dynamicData = encodeDynamic(nameId, displayName); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function set(bytes32 id, QuestData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.unlockId, _table.triggerId); + + EncodedLengths _encodedLengths = encodeLengths(_table.nameId, _table.displayName); + bytes memory _dynamicData = encodeDynamic(_table.nameId, _table.displayName); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Set the full data using the data struct. + */ + function _set(bytes32 id, QuestData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.unlockId, _table.triggerId); + + EncodedLengths _encodedLengths = encodeLengths(_table.nameId, _table.displayName); + bytes memory _dynamicData = encodeDynamic(_table.nameId, _table.displayName); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); + } + + /** + * @notice Set the full data using the data struct (using the specified store). + */ + function set(IStore _store, bytes32 id, QuestData memory _table) internal { + bytes memory _staticData = encodeStatic(_table.unlockId, _table.triggerId); + + EncodedLengths _encodedLengths = encodeLengths(_table.nameId, _table.displayName); + bytes memory _dynamicData = encodeDynamic(_table.nameId, _table.displayName); + + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Decode the tightly packed blob of static data using this table's field layout. + */ + function decodeStatic(bytes memory _blob) internal pure returns (bytes32 unlockId, bytes32 triggerId) { + unlockId = (Bytes.getBytes32(_blob, 0)); + + triggerId = (Bytes.getBytes32(_blob, 32)); + } + + /** + * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. + */ + function decodeDynamic( + EncodedLengths _encodedLengths, + bytes memory _blob + ) internal pure returns (string memory nameId, string memory displayName) { + uint256 _start; + uint256 _end; + unchecked { + _end = _encodedLengths.atIndex(0); + } + nameId = (string(SliceLib.getSubslice(_blob, _start, _end).toBytes())); + + _start = _end; + unchecked { + _end += _encodedLengths.atIndex(1); + } + displayName = (string(SliceLib.getSubslice(_blob, _start, _end).toBytes())); + } + + /** + * @notice Decode the tightly packed blobs using this table's field layout. + * @param _staticData Tightly packed static fields. + * @param _encodedLengths Encoded lengths of dynamic fields. + * @param _dynamicData Tightly packed dynamic fields. + */ + function decode( + bytes memory _staticData, + EncodedLengths _encodedLengths, + bytes memory _dynamicData + ) internal pure returns (QuestData memory _table) { + (_table.unlockId, _table.triggerId) = decodeStatic(_staticData); + + (_table.nameId, _table.displayName) = decodeDynamic(_encodedLengths, _dynamicData); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Delete all data for given keys (using the specified store). + */ + function deleteRecord(IStore _store, bytes32 id) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + _store.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic(bytes32 unlockId, bytes32 triggerId) internal pure returns (bytes memory) { + return abi.encodePacked(unlockId, triggerId); + } + + /** + * @notice Tightly pack dynamic data lengths using this table's schema. + * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). + */ + function encodeLengths( + string memory nameId, + string memory displayName + ) internal pure returns (EncodedLengths _encodedLengths) { + // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits + unchecked { + _encodedLengths = EncodedLengthsLib.pack(bytes(nameId).length, bytes(displayName).length); + } + } + + /** + * @notice Tightly pack dynamic (variable length) data using this table's schema. + * @return The dynamic data, encoded into a sequence of bytes. + */ + function encodeDynamic(string memory nameId, string memory displayName) internal pure returns (bytes memory) { + return abi.encodePacked(bytes((nameId)), bytes((displayName))); + } + + /** + * @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( + bytes32 unlockId, + bytes32 triggerId, + string memory nameId, + string memory displayName + ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic(unlockId, triggerId); + + EncodedLengths _encodedLengths = encodeLengths(nameId, displayName); + bytes memory _dynamicData = encodeDynamic(nameId, displayName); + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(bytes32 id) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = id; + + return _keyTuple; + } +} diff --git a/packages/experience/src/codegen/world/IQuestSystem.sol b/packages/experience/src/codegen/world/IQuestSystem.sol new file mode 100644 index 00000000..c01256b6 --- /dev/null +++ b/packages/experience/src/codegen/world/IQuestSystem.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +/* Autogenerated file. Do not edit manually. */ + +import { QuestData } from "./../tables/Quest.sol"; + +/** + * @title IQuestSystem + * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) + * @dev This interface is automatically generated from the corresponding system contract. Do not edit manually. + */ +interface IQuestSystem { + function experience__addQuest(QuestData memory quest) external; +} diff --git a/packages/experience/src/codegen/world/IWorld.sol b/packages/experience/src/codegen/world/IWorld.sol index d6b26c54..8b43de89 100644 --- a/packages/experience/src/codegen/world/IWorld.sol +++ b/packages/experience/src/codegen/world/IWorld.sol @@ -20,6 +20,7 @@ import { INFTMetadataSystem } from "./INFTMetadataSystem.sol"; import { INFTSystem } from "./INFTSystem.sol"; import { INotificationSystem } from "./INotificationSystem.sol"; import { IPlayerSystem } from "./IPlayerSystem.sol"; +import { IQuestSystem } from "./IQuestSystem.sol"; import { IShopSystem } from "./IShopSystem.sol"; import { ITokenMetadataSystem } from "./ITokenMetadataSystem.sol"; import { ITokenSystem } from "./ITokenSystem.sol"; @@ -48,6 +49,7 @@ interface IWorld is INFTSystem, INotificationSystem, IPlayerSystem, + IQuestSystem, IShopSystem, ITokenMetadataSystem, ITokenSystem diff --git a/packages/experience/src/systems/QuestSystem.sol b/packages/experience/src/systems/QuestSystem.sol new file mode 100644 index 00000000..ba9b0190 --- /dev/null +++ b/packages/experience/src/systems/QuestSystem.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +import { IWorld } from "../codegen/world/IWorld.sol"; +import { System } from "@latticexyz/world/src/System.sol"; + +import { BaseTriggerKind, LeafTriggerKind } from "../codegen/common.sol"; +import { Quest, QuestData } from "../codegen/tables/Quest.sol"; +import { BaseTrigger, BaseTriggerData } from "../codegen/tables/BaseTrigger.sol"; +import { LeafTrigger, LeafTriggerData } from "../codegen/tables/LeafTrigger.sol"; + +contract QuestSystem is System { + function addQuest(QuestData memory quest) public { + bytes32 id = keccak256(abi.encodePacked(quest.nameId)); + require(Quest.getTriggerId(id) == bytes32(0), "QuestSystem: a quest with this id already exists"); + require(quest.triggerId != bytes32(0), "QuestSystem: triggerId must not be empty"); + require(bytes(quest.nameId).length > 0, "QuestSystem: nameId must not be empty"); + require(bytes(quest.displayName).length > 0, "QuestSystem: displayName must not be empty"); + require( + BaseTrigger.getKind(quest.triggerId) != BaseTriggerKind.None || + LeafTrigger.getKind(quest.triggerId) != LeafTriggerKind.None, + "QuestSystem: triggerId must be a valid trigger" + ); + if (quest.unlockId != bytes32(0)) { + require( + BaseTrigger.getKind(quest.unlockId) != BaseTriggerKind.None || + LeafTrigger.getKind(quest.unlockId) != LeafTriggerKind.None, + "QuestSystem: unlockId must be a valid trigger" + ); + } + + Quest.set(id, quest); + } + + // function addBaseTrigger(bytes32 id, BaseTriggerData memory data) public { + // BaseTrigger.set(id, data); + // } +} diff --git a/packages/experience/worlds.json b/packages/experience/worlds.json index 573bae46..26bacaf2 100644 --- a/packages/experience/worlds.json +++ b/packages/experience/worlds.json @@ -4,6 +4,6 @@ "blockNumber": 1110780 }, "31337": { - "address": "0x2fee61521f12f252ec3b16e038c59472a5c19ee1" + "address": "0xc1894382891ad8ea160d51e733df427ebd598553" } } \ No newline at end of file diff --git a/packages/world/worlds.json b/packages/world/worlds.json index 11fc0a93..8a645c96 100644 --- a/packages/world/worlds.json +++ b/packages/world/worlds.json @@ -11,6 +11,6 @@ "blockNumber": 1110780 }, "31337": { - "address": "0x2fee61521f12f252ec3b16e038c59472a5c19ee1" + "address": "0xc1894382891ad8ea160d51e733df427ebd598553" } } \ No newline at end of file