forked from gelopfalcon/solidity-eth-challenge
-
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.
…con#4 types and weaknesses
- Loading branch information
oriana
committed
Jul 23, 2022
1 parent
f3978e5
commit 8146e91
Showing
4 changed files
with
241 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Source: | ||
// https://github.com/ensdomains/ens-contracts/blob/master/contracts/ethregistrar/StringUtils.sol | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
library StringUtils { | ||
/** | ||
* @dev Returns the length of a given string | ||
* | ||
* @param s The string to measure the length of | ||
* @return The length of the input string | ||
*/ | ||
function strlen(string memory s) internal pure returns (uint) { | ||
uint len; | ||
uint i = 0; | ||
uint bytelength = bytes(s).length; | ||
for(len = 0; i < bytelength; len++) { | ||
bytes1 b = bytes(s)[i]; | ||
if(b < 0x80) { | ||
i += 1; | ||
} else if (b < 0xE0) { | ||
i += 2; | ||
} else if (b < 0xF0) { | ||
i += 3; | ||
} else if (b < 0xF8) { | ||
i += 4; | ||
} else if (b < 0xFC) { | ||
i += 5; | ||
} else { | ||
i += 6; | ||
} | ||
} | ||
return len; | ||
} | ||
} |
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,98 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
library TypesUtils { | ||
|
||
/** | ||
* @dev Returns Name | ||
* | ||
* @param id Type of pokemon | ||
* @return string Name | ||
*/ | ||
function typeName(uint8 id) internal pure returns (string memory){ | ||
if (id == 0) { | ||
return "Normal"; | ||
} else if (id == 1) { | ||
return "Fighting"; | ||
} else if (id == 2) { | ||
return "Flying"; | ||
} else if (id == 3) { | ||
return "Poison"; | ||
} else if (id == 4) { | ||
return "Ground"; | ||
} else if (id == 5) { | ||
return "Rock"; | ||
} else if (id == 6) { | ||
return "Bug"; | ||
} else if (id == 7) { | ||
return "Ghost"; | ||
} else if (id == 8) { | ||
return "Steel"; | ||
} else if (id == 9) { | ||
return "Fire"; | ||
} else if (id == 10) { | ||
return "Water"; | ||
} else if (id == 11) { | ||
return "Grass"; | ||
} else if (id == 12) { | ||
return "Electric"; | ||
} else if (id == 13) { | ||
return "Psychic"; | ||
} else if (id == 14) { | ||
return "Ice"; | ||
} else if (id == 15) { | ||
return "Dragon"; | ||
} else if (id == 16) { | ||
return "Fairy"; | ||
} else { | ||
return "Dark"; | ||
} | ||
} | ||
|
||
/** | ||
* @dev Returns string of weaknesses per type | ||
* | ||
* @param id Type of pokemon | ||
* @return string of weaknesses | ||
*/ | ||
function Weakness(uint8 id) internal pure returns (string memory) { | ||
if (id == 0) { | ||
return "Rock, Ghost, Steel"; | ||
} else if (id == 1) { | ||
return "Flying, Poison, Psychic, Bug, Ghost, Fairy"; | ||
} else if (id == 2) { | ||
return "Rock, Steel, Electric"; | ||
} else if (id == 3) { | ||
return "Poison, Ground, Rock, Ghost, Steel"; | ||
} else if (id == 4) { | ||
return "Flying, Bug, Grass"; | ||
} else if (id == 5) { | ||
return "Fighting, Ground, Steel"; | ||
} else if (id == 6) { | ||
return "Fighting, Flying, Poison, Ghost, Steel, Fire, Fairy"; | ||
} else if (id == 7) { | ||
return "Normal, Dark"; | ||
} else if (id == 8) { | ||
return "Steel, Fire, Water, Electric"; | ||
} else if (id == 9) { | ||
return "Rock, Fire, Water, Dragon"; | ||
} else if (id == 10) { | ||
return "Water, Grass, Dragon"; | ||
} else if (id == 11) { | ||
return "Flying, Poison, Bug, Steel, Fire, Grass, Dragon"; | ||
} else if (id == 12) { | ||
return "Flying, Steel, Electric"; | ||
} else if (id == 13) { | ||
return "Steel, Psychic, Dark"; | ||
} else if (id == 14) { | ||
return "Steel, Fire, Water, Ice"; | ||
} else if (id == 15) { | ||
return "Steel, Fairy"; | ||
} else if (id == 16) { | ||
return "Poison, Steel, Fire"; | ||
} else { | ||
return "Fighting, Dark, Fairy"; | ||
} | ||
} | ||
} |