-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(facets): implement functions in PlayerFacet.sol
- player - addPlayer - levelUp
- Loading branch information
1 parent
465e98b
commit 283ba44
Showing
13 changed files
with
524 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import {AppStorage} from "../libraries/LibAppStorage.sol"; | ||
import {AppStorage, Modifiers} from "../libraries/LibAppStorage.sol"; | ||
|
||
contract LootboxFacet is Modifiers { | ||
|
||
contract LootboxFacet { | ||
AppStorage internal s; | ||
event OpenLootboxEvent(address player, uint32 lootboxId); | ||
|
||
function openLootbox(address player, uint32 lootboxId) external { | ||
require(player != address(0), "Player address is not valid"); | ||
require(s.playersExists[player], "Player does not exist"); | ||
/// @notice Open a lootbox | ||
/// @dev This function throws for queries about the zero address and non-existing players. | ||
/// @param playerAddress The player to query | ||
function openLootbox(address playerAddress, uint32 lootboxId) external { | ||
require(playerAddress != address(0), "Player address is not valid"); | ||
require(s.players[playerAddress].createdAt > 0, "Player does not exist"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
pragma solidity 0.8.13; | ||
|
||
import {AppStorage} from "../libraries/LibAppStorage.sol"; | ||
import {AppStorage, Modifiers, Player} from "../libraries/LibAppStorage.sol"; | ||
|
||
contract PlayerFacet { | ||
AppStorage internal s; | ||
contract PlayerFacet is Modifiers { | ||
event LevelUpEvent(address player, uint16 level); | ||
|
||
function levelUp(address player) external { | ||
require(player != address(0), "Player address is not valid"); | ||
//require(s.playersExists[player], "Player does not exist"); | ||
//s.players[player].level++; | ||
/// @notice Query all details relating to a player | ||
/// @dev This function throws for queries about the zero address and non-existing players. | ||
/// @param playerAddress The player to query | ||
/// @return _player The player's details | ||
function player(address playerAddress) public view returns (Player memory _player) { | ||
require(playerAddress != address(0), "Player address is not valid"); | ||
require(s.players[playerAddress].createdAt > 0, "Player does not exist"); | ||
_player = s.players[playerAddress]; | ||
} | ||
|
||
// for testing purposes | ||
function supportsInterface(bytes4 _interfaceID) external view returns (bool) { | ||
return false; | ||
/// @notice Add a player | ||
/// @dev This function throws for queries about the zero address and already existing players. | ||
/// @param playerAddress Address of the player to add | ||
function addPlayer(address playerAddress) external onlyGuildAdmin { | ||
require(playerAddress != address(0), "PlayerFacet: Player address is not valid"); | ||
require(!(s.players[playerAddress].createdAt > 0), "PlayerFacet: Player already exists"); | ||
s.players[playerAddress] = Player(block.timestamp, 0); | ||
} | ||
|
||
/// @notice Level-up a player | ||
/// @dev This function throws for queries about the zero address and non-existing players. | ||
/// @param playerAddress Address of the player to level-up | ||
function levelUp(address playerAddress) external onlyGallion playerExists(playerAddress) { | ||
require(playerAddress != address(0), "PlayerFacet: Player address is not valid"); | ||
s.players[playerAddress].level++; | ||
} | ||
|
||
/// @notice Remove a player | ||
/// @dev This function throws for queries about the zero address and non-existing players. | ||
/// @param playerAddress Address of the player to remove | ||
function removePlayer(address playerAddress) external onlyGuildAdmin { | ||
require(playerAddress != address(0), "PlayerFacet: Player address is not valid"); | ||
require(s.players[playerAddress].createdAt > 0, "PlayerFacet: Player does not exist"); | ||
delete s.players[playerAddress]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
// For test purposes only. | ||
contract Test1Facet { | ||
|
||
event TestEvent(address something); | ||
|
||
function test1Func1() external {} | ||
|
||
function test1Func2() external {} | ||
|
||
function test1Func3() external {} | ||
|
||
function test1Func4() external {} | ||
|
||
function test1Func5() external {} | ||
|
||
function test1Func6() external {} | ||
|
||
function test1Func7() external {} | ||
|
||
function test1Func8() external {} | ||
|
||
function test1Func9() external {} | ||
|
||
function test1Func10() external {} | ||
|
||
function test1Func11() external {} | ||
|
||
function test1Func12() external {} | ||
|
||
function test1Func13() external {} | ||
|
||
function test1Func14() external {} | ||
|
||
function test1Func15() external {} | ||
|
||
function test1Func16() external {} | ||
|
||
function test1Func17() external {} | ||
|
||
function test1Func18() external {} | ||
|
||
function test1Func19() external {} | ||
|
||
function test1Func20() external {} | ||
|
||
function supportsInterface(bytes4 _interfaceID) external view returns (bool) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
// For test purposes only. | ||
contract Test2Facet { | ||
|
||
function test2Func1() external {} | ||
|
||
function test2Func2() external {} | ||
|
||
function test2Func3() external {} | ||
|
||
function test2Func4() external {} | ||
|
||
function test2Func5() external {} | ||
|
||
function test2Func6() external {} | ||
|
||
function test2Func7() external {} | ||
|
||
function test2Func8() external {} | ||
|
||
function test2Func9() external {} | ||
|
||
function test2Func10() external {} | ||
|
||
function test2Func11() external {} | ||
|
||
function test2Func12() external {} | ||
|
||
function test2Func13() external {} | ||
|
||
function test2Func14() external {} | ||
|
||
function test2Func15() external {} | ||
|
||
function test2Func16() external {} | ||
|
||
function test2Func17() external {} | ||
|
||
function test2Func18() external {} | ||
|
||
function test2Func19() external {} | ||
|
||
function test2Func20() external {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,61 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.13; | ||
|
||
struct AppStorage { | ||
address gallionLabs; | ||
address guildTokenContract; | ||
address guildContract; | ||
mapping(address => bool) playersExists; | ||
mapping(address => Player) players; | ||
mapping(uint32 => Lootbox) lootboxes; | ||
import {LibDiamond} from "./LibDiamond.sol"; | ||
import {LibMeta} from "./LibMeta.sol"; | ||
|
||
struct AppStorage { | ||
bytes32 domainSeparator; | ||
address owner; | ||
address gallionLabs; | ||
address guildTokenContract; | ||
address guildContract; | ||
mapping(address => Admin) guildAdmins; | ||
mapping(address => Player) players; | ||
mapping(uint32 => Lootbox) lootboxes; | ||
} | ||
|
||
struct Admin { | ||
uint createdAt; | ||
} | ||
|
||
struct Player { | ||
uint createdAt; | ||
uint16 level; | ||
} | ||
|
||
struct Lootbox { | ||
address owner; | ||
Rarity rarity; | ||
} | ||
|
||
enum Rarity { | ||
common, | ||
rare, | ||
epic, | ||
legendary | ||
} | ||
|
||
contract Modifiers { | ||
AppStorage internal s; | ||
|
||
modifier onlyGuildAdmin() { | ||
require(s.guildAdmins[LibMeta.msgSender()].createdAt > 0, "LibAppStorage: Only guild admins can call this function"); | ||
_; | ||
} | ||
|
||
struct Player { | ||
address owner; | ||
uint16 level; | ||
modifier playerExists(address player) { | ||
require(s.players[player].createdAt > 0, "LibAppStorage: Player does not exist"); | ||
_; | ||
} | ||
|
||
struct Lootbox { | ||
address owner; | ||
Rarity rarity; | ||
modifier onlyOwner() { | ||
LibDiamond.enforceIsContractOwner(); | ||
_; | ||
} | ||
|
||
enum Rarity { | ||
common, | ||
rare, | ||
epic, | ||
legendary | ||
modifier onlyGallion() { | ||
require(LibMeta.msgSender() == s.gallionLabs, "LibAppStorage: Only Gallion can call this function"); | ||
_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.13; | ||
|
||
library LibMeta { | ||
bytes32 internal constant EIP712_DOMAIN_TYPEHASH = | ||
keccak256(bytes("EIP712Domain(string name,string version,uint256 salt,address verifyingContract)")); | ||
|
||
function domainSeparator(string memory name, string memory version) internal view returns (bytes32 domainSeparator_) { | ||
domainSeparator_ = keccak256( | ||
abi.encode(EIP712_DOMAIN_TYPEHASH, keccak256(bytes(name)), keccak256(bytes(version)), getChainID(), address(this)) | ||
); | ||
} | ||
|
||
function getChainID() internal view returns (uint256 id) { | ||
assembly { | ||
id := chainid() | ||
} | ||
} | ||
|
||
function msgSender() internal view returns (address sender_) { | ||
if (msg.sender == address(this)) { | ||
bytes memory array = msg.data; | ||
uint256 index = msg.data.length; | ||
assembly { | ||
// Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those. | ||
sender_ := and(mload(add(array, index)), 0xffffffffffffffffffffffffffffffffffffffff) | ||
} | ||
} else { | ||
sender_ = msg.sender; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.