Skip to content

Commit

Permalink
Add reto gelopfalcon#3
Browse files Browse the repository at this point in the history
Los datos de la tubla deben enviarce asi : [ [ "Nombre de abiilidad", "descriptcion" ] ]
  • Loading branch information
wolftrax5 authored Jul 24, 2022
1 parent a59d68e commit c4c9896
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions PokemonFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,44 @@ contract PokemonFactory {
struct Pokemon {
uint id;
string name;
Ability[] abilities;
}

struct Ability {
string name;
string description;
}
Pokemon[] private pokemons;
event eventNewPokemon(
uint id,
string name
);

mapping (uint => address) public pokemonToOwner;
mapping (address => uint) ownerPokemonCount;

// VALIDATIONS
modifier validPokemon(string memory _name ,uint _id){
require(_id > 0, "El Id debe ser mayor de 0");
bytes memory strinCheck = bytes(_name);
require(strinCheck.length != 0,"El nombre no debe ser vacio");
require(strinCheck.length > 2,"La longitud del nombre debe ser mayor de 2");
_;
}

function createPokemon (string memory _name, uint _id) validPokemon(_name, _id) public {
pokemons.push(Pokemon(_id, _name));
//////////////
//
function createPokemon (string memory _name, uint _id, Ability[] memory _abilities) validPokemon(_name, _id) public {

Pokemon storage pokemon = pokemons.push();
pokemon.id = _id;
pokemon.name = _name;
for (uint i = 0; i <_abilities.length; i++) {
pokemon.abilities.push(Ability(_abilities[i].name, _abilities[i].description));
}

pokemonToOwner[_id] = msg.sender;
ownerPokemonCount[msg.sender]++;
emit eventNewPokemon(_id, _name);
}


// VIEWS
function getAllPokemons() public view returns (Pokemon[] memory) {
return pokemons;
}
Expand Down

0 comments on commit c4c9896

Please sign in to comment.