From e0442a057b696749466861f577b88518ab7b15f8 Mon Sep 17 00:00:00 2001 From: cha0sg0d Date: Wed, 5 Oct 2022 23:39:00 -0400 Subject: [PATCH] contracts: move artifact getters to artifact facet --- eth/contracts/facets/DFArtifactFacet.sol | 77 +++++++++++++++++++++++- eth/contracts/facets/DFGetterFacet.sol | 72 ---------------------- 2 files changed, 76 insertions(+), 73 deletions(-) diff --git a/eth/contracts/facets/DFArtifactFacet.sol b/eth/contracts/facets/DFArtifactFacet.sol index 6fdb9429..99c6e3d7 100644 --- a/eth/contracts/facets/DFArtifactFacet.sol +++ b/eth/contracts/facets/DFArtifactFacet.sol @@ -18,7 +18,7 @@ import {LibPlanet} from "../libraries/LibPlanet.sol"; import {WithStorage} from "../libraries/LibStorage.sol"; // Type imports -import {Artifact, ArtifactRarity, ArtifactType, Biome, TokenType, DFTCreateArtifactArgs, DFPFindArtifactArgs} from "../DFTypes.sol"; +import {Artifact, ArtifactRarity, ArtifactType, Biome, TokenType, DFTCreateArtifactArgs, DFPFindArtifactArgs, Upgrade} from "../DFTypes.sol"; contract DFArtifactFacet is WithStorage { event PlanetProspected(address player, uint256 loc); @@ -192,4 +192,79 @@ contract DFArtifactFacet is WithStorage { LibArtifactUtils.prospectPlanet(locationId); emit PlanetProspected(msg.sender, locationId); } + + /** + * Getters + */ + function getArtifactActivationTimeOnPlanet(uint256 locationId) public view returns (uint256) { + return gs().planets[locationId].artifactActivationTime; + } + + function getUpgradeForArtifact(uint256 artifactId) public pure returns (Upgrade memory) { + return LibArtifact.getUpgradeForArtifact(LibArtifact.decode(artifactId)); + } + + function getArtifactsOnPlanet(uint256 locationId) public view returns (Artifact[] memory ret) { + uint256[] memory artifactIds = gs().planets[locationId].artifacts; + ret = new Artifact[](artifactIds.length); + for (uint256 i = 0; i < artifactIds.length; i++) { + ret[i] = LibArtifact.decode(artifactIds[i]); + } + return ret; + } + + function hasActiveArtifact(uint256 locationId) public view returns (bool) { + return LibArtifact.hasActiveArtifact(locationId); + } + + function getActiveArtifactOnPlanet(uint256 locationId) + public + view + returns (Artifact memory ret) + { + uint256 artifactId = gs().planets[locationId].activeArtifact; + return LibArtifact.decode(artifactId); + } + + function bulkGetPlanetAritfacts(uint256[] calldata planetIds) + public + view + returns (Artifact[][] memory) + { + Artifact[][] memory ret = new Artifact[][](planetIds.length); + + for (uint256 i = 0; i < planetIds.length; i++) { + uint256[] memory artifactsOnPlanet = gs().planets[planetIds[i]].artifacts; + ret[i] = bulkGetArtifactsByIds(artifactsOnPlanet); + } + + return ret; + } + + function bulkGetArtifactsByIds(uint256[] memory artifactIds) + public + pure + returns (Artifact[] memory ret) + { + ret = new Artifact[](artifactIds.length); + + for (uint256 i = 0; i < artifactIds.length; i++) { + ret[i] = LibArtifact.decode(artifactIds[i]); + } + } + + function getPlayerArtifacts(address player) public view returns (Artifact[] memory ret) { + uint256[] memory tokens = DFTokenFacet(address(this)).tokensByAccount(player); + uint256 numArtifacts = 0; + for (uint256 i = 0; i < tokens.length; i++) { + if (LibArtifact.isArtifact(tokens[i])) numArtifacts += 1; + } + + ret = new Artifact[](numArtifacts); + numArtifacts = 0; + for (uint256 i = 0; i < tokens.length; i++) { + if (LibArtifact.isArtifact(tokens[i])) + ret[numArtifacts++] = LibArtifact.decode(tokens[i]); + } + } } diff --git a/eth/contracts/facets/DFGetterFacet.sol b/eth/contracts/facets/DFGetterFacet.sol index 5adb09cd..81a42c8d 100644 --- a/eth/contracts/facets/DFGetterFacet.sol +++ b/eth/contracts/facets/DFGetterFacet.sol @@ -309,76 +309,4 @@ contract DFGetterFacet is WithStorage { return ret; } - - function getArtifactActivationTimeOnPlanet(uint256 locationId) public view returns (uint256) { - return gs().planets[locationId].artifactActivationTime; - } - - function getUpgradeForArtifact(uint256 artifactId) public pure returns (Upgrade memory) { - return LibArtifact.getUpgradeForArtifact(LibArtifact.decode(artifactId)); - } - - function getArtifactsOnPlanet(uint256 locationId) public view returns (Artifact[] memory ret) { - uint256[] memory artifactIds = gs().planets[locationId].artifacts; - ret = new Artifact[](artifactIds.length); - for (uint256 i = 0; i < artifactIds.length; i++) { - ret[i] = LibArtifact.decode(artifactIds[i]); - } - return ret; - } - - function hasActiveArtifact(uint256 locationId) public view returns (bool) { - return LibArtifact.hasActiveArtifact(locationId); - } - - function getActiveArtifactOnPlanet(uint256 locationId) - public - view - returns (Artifact memory ret) - { - uint256 artifactId = gs().planets[locationId].activeArtifact; - return LibArtifact.decode(artifactId); - } - - function bulkGetPlanetAritfacts(uint256[] calldata planetIds) - public - view - returns (Artifact[][] memory) - { - Artifact[][] memory ret = new Artifact[][](planetIds.length); - - for (uint256 i = 0; i < planetIds.length; i++) { - uint256[] memory artifactsOnPlanet = gs().planets[planetIds[i]].artifacts; - ret[i] = bulkGetArtifactsByIds(artifactsOnPlanet); - } - - return ret; - } - - function bulkGetArtifactsByIds(uint256[] memory artifactIds) - public - pure - returns (Artifact[] memory ret) - { - ret = new Artifact[](artifactIds.length); - - for (uint256 i = 0; i < artifactIds.length; i++) { - ret[i] = LibArtifact.decode(artifactIds[i]); - } - } - - function getPlayerArtifacts(address player) public view returns (Artifact[] memory ret) { - uint256[] memory tokens = DFTokenFacet(address(this)).tokensByAccount(player); - uint256 numArtifacts = 0; - for (uint256 i = 0; i < tokens.length; i++) { - if (LibArtifact.isArtifact(tokens[i])) numArtifacts += 1; - } - - ret = new Artifact[](numArtifacts); - numArtifacts = 0; - for (uint256 i = 0; i < tokens.length; i++) { - if (LibArtifact.isArtifact(tokens[i])) - ret[numArtifacts++] = LibArtifact.decode(tokens[i]); - } - } }