diff --git a/PokemonFactory.sol b/PokemonFactory.sol index a3267da1..f53f8aa7 100644 --- a/PokemonFactory.sol +++ b/PokemonFactory.sol @@ -4,20 +4,89 @@ pragma solidity >=0.7.0 <0.9.0; contract PokemonFactory { - struct Pokemon { - uint id; - string name; - } + struct Pokemon { + uint id; + string name; + Ability[] abilities; + PokemonType[] pokemonTypes; + PokemonType[] weaknesses; + } + + struct Ability { + string name; + string description; + } + + enum PokemonType { + BUG, + DARK, + DRAGON, + ELECTRIC, + FAIRY, + FIGHTING, + FIRE, + FLYING, + GHOST, + GRASS, + GROUND, + ICE, + NORMAL, + POISON, + PSYCHIC, + ROCK, + STEEL, + WATER + } Pokemon[] private pokemons; - mapping (uint => address) public pokemonToOwner; - mapping (address => uint) ownerPokemonCount; + mapping (uint => address) public pokemonToOwner; //guarda el id del pokemon vs el address del que esta ejecutando el smart contract, el address viene del frontend + mapping (address => uint) ownerPokemonCount;// vamos a a tener un conteo de la cantidad de pokemones por address. + + event eventNewPokemon (Pokemon pokemon); - function createPokemon (string memory _name, uint _id) public { - pokemons.push(Pokemon(_id, _name)); + function createPokemon (string memory _name, uint _id) public { + require(_id > 0, "Pokemon's id should be greater than 0"); + require(bytes(_name).length > 2, "Pokemon's name should have more that two characters."); + Pokemon storage pokemon = pokemons.push(); + pokemon.id = _id; + pokemon.name = _name; pokemonToOwner[_id] = msg.sender; ownerPokemonCount[msg.sender]++; + emit eventNewPokemon (pokemon); + } + + function addAbilitiesToPokemon(uint _idPokemon, Ability[] memory _abilities) public { + for (uint256 i; i