Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/contracts/mud.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default defineWorld({
schema: {
adminAddress: "address",
tokenAddress: "address",
escapedStumpTokenAddress: "address",
globalSpawnIndex: "uint32", // Global index for all players
globalEscapeIndex: "uint32", // Global index for all players
scaleDown: "uint32", // Used to scale down the amounts in the UI
flowRate: "uint32", // Amount flowing from the inlet
depotCapacity: "uint32", // Amount of material that can be stored in a depot
Expand All @@ -34,6 +36,23 @@ export default defineWorld({
BuildIndex: "uint32", // Build index of a particular machine type in a particular pod
BuildTracker: "uint32[]", // How many machines of each type have been built in pod since its creation?
SpawnIndex: "uint32", // How many players have spawned?
EscapeIndex: "uint32", // How many players have escaped?
EscapeIndexRanked: {
key: ["completedOrdersRank", "pointsRank"],
schema: {
completedOrdersRank: "uint256",
pointsRank: "uint256",
value: "uint32"
}
},
EscapeRankName: {
key: ["completedOrdersRank", "pointsRank"],
schema: {
completedOrdersRank: "uint256",
pointsRank: "uint256",
value: "string"
}
},
Tutorial: "bool",
TutorialLevel: "uint32",
Order: {
Expand Down
24 changes: 21 additions & 3 deletions packages/contracts/script/PostDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { IERC20Mintable } from "@latticexyz/world-modules/src/modules/erc20-puppet/IERC20Mintable.sol";
import { registerERC20 } from "@latticexyz/world-modules/src/modules/erc20-puppet/registerERC20.sol";
import { ERC20MetadataData } from "@latticexyz/world-modules/src/modules/erc20-puppet/tables/ERC20Metadata.sol";
import { IERC721Mintable } from "@latticexyz/world-modules/src/modules/erc721-puppet/IERC721Mintable.sol";
import { registerERC721 } from "@latticexyz/world-modules/src/modules/erc721-puppet/registerERC721.sol";
import { ERC721MetadataData } from "@latticexyz/world-modules/src/modules/erc721-puppet/tables/ERC721Metadata.sol";

import { IWorld } from "../src/codegen/world/IWorld.sol";

import { WorldResourceIdLib } from "@latticexyz/world/src/WorldResourceId.sol";
import { ROOT_NAMESPACE_ID } from "@latticexyz/world/src/constants.sol";
import { NamespaceOwner } from "@latticexyz/world/src/codegen/tables/NamespaceOwner.sol";
import { NamespaceOwner } from "@latticexyz/world/src/codegen/index.sol";

import { MATERIAL_TYPE } from "../src/codegen/common.sol";
import { LibOrder, LibInitRecipes, LibInit, LibOffer } from "../src/libraries/Libraries.sol";
import { LibOrder, LibInitRecipes, LibInitEscapeRankNames, LibInit, LibOffer } from "../src/libraries/Libraries.sol";
import { ONE_MINUTE, ONE_DAY, ONE_HOUR } from "../src/constants.sol";

uint256 constant POOL_SUPPLY = 1_000_000 wei;
Expand All @@ -38,13 +42,27 @@ contract PostDeploy is Script {

token.mint(worldAddress, POOL_SUPPLY);

// Register ERC721 escaped stump token
IERC721Mintable escapedStumpToken = registerERC721(
world,
"EscapedStumpT",
ERC721MetadataData({ name: "TCM", symbol: "TCM", baseURI: "" })
);

// Transfer token namespaces to World
world.transferOwnership(WorldResourceIdLib.encodeNamespace("Token"), worldAddress);
world.transferOwnership(WorldResourceIdLib.encodeNamespace("EscapedStumpT"), worldAddress);

// Initialize gameConfig and tutorial levels
// Root namespace owner is admin
LibInit.init(NamespaceOwner.get(ROOT_NAMESPACE_ID), address(token));
LibInit.init(NamespaceOwner.get(ROOT_NAMESPACE_ID), address(token), address(escapedStumpToken));

// Initialize recipes
LibInitRecipes.init();

// Initialize rank names for escaped pod NFTs
LibInitEscapeRankNames.init();

// Create offer
LibOffer.create(MATERIAL_TYPE.BUG, 10000, 100); // 1:1 ratio : 100 $BUG => 10000 Bug (Shown as 100 Bugs with scale-down in UI)

Expand Down
3 changes: 3 additions & 0 deletions packages/contracts/src/codegen/index.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { CarriedBy } from "./tables/CarriedBy.sol";
import { BuildIndex } from "./tables/BuildIndex.sol";
import { BuildTracker } from "./tables/BuildTracker.sol";
import { SpawnIndex } from "./tables/SpawnIndex.sol";
import { EscapeIndex } from "./tables/EscapeIndex.sol";
import { EscapeIndexRanked } from "./tables/EscapeIndexRanked.sol";
import { EscapeRankName } from "./tables/EscapeRankName.sol";
import { Tutorial } from "./tables/Tutorial.sol";
import { TutorialLevel } from "./tables/TutorialLevel.sol";
import { Order, OrderData } from "./tables/Order.sol";
Expand Down
199 changes: 199 additions & 0 deletions packages/contracts/src/codegen/tables/EscapeIndex.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// 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 EscapeIndex {
// Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "EscapeIndex", typeId: RESOURCE_TABLE });`
ResourceId constant _tableId = ResourceId.wrap(0x74620000000000000000000000000000457363617065496e6465780000000000);

FieldLayout constant _fieldLayout =
FieldLayout.wrap(0x0004010004000000000000000000000000000000000000000000000000000000);

// Hex-encoded key schema of (bytes32)
Schema constant _keySchema = Schema.wrap(0x002001005f000000000000000000000000000000000000000000000000000000);
// Hex-encoded value schema of (uint32)
Schema constant _valueSchema = Schema.wrap(0x0004010003000000000000000000000000000000000000000000000000000000);

/**
* @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] = "value";
}

/**
* @notice Register the table with its config.
*/
function register() internal {
StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
}

/**
* @notice Register the table with its config.
*/
function _register() internal {
StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames());
}

/**
* @notice Get value.
*/
function getValue(bytes32 id) internal view returns (uint32 value) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = id;

bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
return (uint32(bytes4(_blob)));
}

/**
* @notice Get value.
*/
function _getValue(bytes32 id) internal view returns (uint32 value) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = id;

bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
return (uint32(bytes4(_blob)));
}

/**
* @notice Get value.
*/
function get(bytes32 id) internal view returns (uint32 value) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = id;

bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
return (uint32(bytes4(_blob)));
}

/**
* @notice Get value.
*/
function _get(bytes32 id) internal view returns (uint32 value) {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = id;

bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout);
return (uint32(bytes4(_blob)));
}

/**
* @notice Set value.
*/
function setValue(bytes32 id, uint32 value) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = id;

StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
}

/**
* @notice Set value.
*/
function _setValue(bytes32 id, uint32 value) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = id;

StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
}

/**
* @notice Set value.
*/
function set(bytes32 id, uint32 value) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = id;

StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _fieldLayout);
}

/**
* @notice Set value.
*/
function _set(bytes32 id, uint32 value) internal {
bytes32[] memory _keyTuple = new bytes32[](1);
_keyTuple[0] = id;

StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((value)), _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 Tightly pack static (fixed length) data using this table's schema.
* @return The static data, encoded into a sequence of bytes.
*/
function encodeStatic(uint32 value) internal pure returns (bytes memory) {
return abi.encodePacked(value);
}

/**
* @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(uint32 value) internal pure returns (bytes memory, EncodedLengths, bytes memory) {
bytes memory _staticData = encodeStatic(value);

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;
}
}
Loading