import 'package:flutter/material.dart'; import 'package:pokedex/Session.dart'; import 'package:pokedex/pokemon.dart'; enum Type { Normal(Color.fromARGB(255, 192, 192, 192), Colors.black), Fire(Color.fromARGB(255, 255, 0, 0), Color.fromARGB(255, 255, 255, 255)), Water(Color.fromARGB(255, 0, 174, 255), Colors.black), Electric(Color(0xffFFD700), Colors.black), Grass(Color.fromARGB(255, 0, 255, 0), Colors.black), Ice(Color.fromARGB(255, 0, 255, 255), Colors.black), Fighting(Color.fromARGB(255, 255, 0, 0), Color.fromARGB(255, 255, 255, 255)), Poison(Color.fromARGB(255, 128, 0, 128), Color.fromARGB(255, 255, 255, 255)), Ground(Color.fromARGB(255, 128, 126, 0), Colors.black), Flying(Color.fromARGB(255, 128, 128, 255), Colors.black), Psychic(Color.fromARGB(255, 255, 0, 255), Color.fromARGB(255, 255, 255, 255)), Bug(Color.fromARGB(255, 128, 128, 0), Colors.black), Rock(Color.fromARGB(255, 128, 128, 128), Colors.black), Ghost(Color.fromARGB(255, 128, 0, 128), Colors.black), Dragon(Color.fromARGB(255, 85, 0, 102), Color.fromARGB(255, 255, 255, 255)), Dark(Color.fromARGB(255, 51, 51, 51), Color.fromARGB(255, 255, 255, 255)), Steel(Color.fromARGB(255, 192, 192, 192), Colors.black), Fairy(Color.fromARGB(255, 255, 102, 255), Colors.black); final Color backgroundColor; final Color textColor; const Type(this.backgroundColor, this.textColor); } class PokemonHelpers { static List getUnownList() { List widgets = []; List tmpWidgets = []; int i = 0; int end = 3; for (var digit in SessionData.ALPHABET) { tmpWidgets.add( Image.asset("assets/sprites/unown-${digit.toLowerCase()}.png"), ); i++; if (i >= end) { widgets.add( Row( crossAxisAlignment: CrossAxisAlignment.start, children: tmpWidgets, ), ); i = 0; tmpWidgets = []; } } widgets.add( Row(crossAxisAlignment: CrossAxisAlignment.start, children: tmpWidgets), ); return widgets; } static Widget getTypeWidgets(Pokemon pokemon) { List widgets = []; for (Type type in pokemon.types) { widgets.add( ElevatedButton( onPressed: () {}, style: ButtonStyle( backgroundColor: WidgetStatePropertyAll(type.backgroundColor), foregroundColor: WidgetStatePropertyAll(type.textColor), ), child: Text(type.name, style: TextStyle(fontSize: 16)), ), ); } return Row(children: widgets); } static Widget getVariations(Pokemon pokemon) { List variants = []; if (pokemon.id == Pokemon.Unown.id) { variants = getUnownList(); } else { List tmpRow = []; int i = 0; int row = 3; for (var variant in pokemon.extraVariants) { tmpRow.add(Image.asset("assets/sprites/$variant.png")); i++; if (i >= row) { variants.add(Row(children: tmpRow)); tmpRow = []; i = 0; } } if (tmpRow.isNotEmpty) variants.add(Row(children: tmpRow)); } return Column(children: variants); } static List getEvolutions(int subID, Pokemon pokemon) { //print("SUBID ${subID}"); List Evs = []; // ID must be in inclusive range of 1...MAXGeneration if (pokemon.previousPokemon != -1 && pokemon.previousPokemon <= SessionData.highestGenID()) { if (pokemon.previousPokemon != -1 && subID == 0) { Pokemon pkmn = Pokemon.values.where((x) => x.id == pokemon.previousPokemon).first; return getEvolutions(0, pkmn); } } if (!pokemon.hasEvolutions) return []; //print("Processing evolutions for ${pokemonName}"); if (pokemon.evolution is SingleEvolution) { //print("Single Evolution identified"); var pkmnx = Pokemon.values .where((x) => x.id == (pokemon.evolution! as SingleEvolution).to) .first; if (pkmnx.id <= SessionData.highestGenID()) Evs.add(pkmnx); } else { //print("Branching Evolution identified"); // Handle branched evolutions. Refactor below to accomodate a list of pokemon. for (var ev in (pokemon.evolution! as BranchedEvolution).alternates) { if (!(ev >= SessionData.highestGenID())) { var pkmnx = Pokemon.values.where((x) => x.id == ev).first; if (pkmnx.id <= SessionData.highestGenID()) Evs.add(pkmnx); } } } List sprites = []; if (subID == 0) { sprites.add(Text("Evolutions: ", style: TextStyle(fontSize: 24))); sprites.add( Card( elevation: 50, child: SizedBox( width: 256, height: 256, child: Column( children: [ Image.asset(pokemon.toDexPath(), width: 64, height: 64), Text(pokemon.pokemonName, style: TextStyle(fontSize: 24)), getTypeWidgets(pokemon), ], ), ), ), ); sprites.add(pokemon.evolution!.getEvolution()); //print("Main page EV."); } else { sprites.add(pokemon.evolution!.getEvolution()); } List afterEvs = []; for (var ev in Evs) { afterEvs.addAll(getEvolutions(subID + 1, ev)); //print("Processing evolution: ${ev.properName}"); } sprites.add( Row(crossAxisAlignment: CrossAxisAlignment.start, children: afterEvs), ); return sprites; } static Widget printDescription(Pokemon pokemon) { List widgets = []; for (var descs in pokemon.dexEntries) { if (descs.gameGen.idStart > SessionData.highestGenID()) continue; List gameNames = [descs.game.toString()]; for (var extra in descs.additionalGames) { gameNames.add(extra.toString()); } widgets.add( Card.filled( elevation: 50, child: Padding( padding: const EdgeInsets.all(8.0), child: Column( children: [ Text( "Game: ${gameNames.join(", ")}\nDescription: ${descs.desc}", ), ], ), ), ), ); } return Column( crossAxisAlignment: CrossAxisAlignment.start, children: widgets, ); } static Widget printLocations(Pokemon pokemon) { List widgets = []; for (var locs in pokemon.locations) { if (locs.gameGen.idStart > SessionData.highestGenID()) continue; List routes = []; for (var rt in locs.routes) { routes.add(rt.toString()); } List gameNames = [locs.game.toString()]; for (var extra in locs.additionalGames) { gameNames.add(extra.toString()); } widgets.add( Card.outlined( elevation: 50, child: Padding( padding: const EdgeInsets.all(8.0), child: Column( children: [ Text( "Game: ${gameNames.join(", ")}\n\nRoutes/Method: ${routes.join(", ")}", ), ], ), ), ), ); } return Column( crossAxisAlignment: CrossAxisAlignment.start, children: widgets, ); } } abstract class Evolution { const Evolution(); String printEvolution(); Widget getEvolution(); } class SingleEvolution extends Evolution { final int to; final int level; final List? condition; const SingleEvolution(this.to, this.level, {this.condition}); @override String printEvolution() { String sRet = ""; if (level != -1) { sRet += "Level $level"; } if (condition != null) { if (sRet.isNotEmpty) { sRet += "\n"; } for (var cond in condition!) { sRet += cond.name; } } return sRet; } @override Widget getEvolution() { if (to >= SessionData.highestGenID() + 1) { return Column(); } Pokemon pkmn = Pokemon.values.where((x) => x.id == to).first; List cardRow = []; cardRow.add( Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.arrow_downward, size: 48), Card( elevation: 50, child: SizedBox( width: 256, height: 256, child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Text(printEvolution(), style: TextStyle(fontSize: 16)), Image.asset(pkmn.toDexPath(), width: 64, height: 64), Text(pkmn.pokemonName, style: TextStyle(fontSize: 24)), PokemonHelpers.getTypeWidgets(pkmn), ], ), ), ), ], ), ); Column rw = Column( crossAxisAlignment: CrossAxisAlignment.start, children: [Row(children: cardRow)], ); return rw; } } class BranchedEvolution extends Evolution { final List alternates; final List levels; final List> conditions; const BranchedEvolution(this.alternates, this.levels, this.conditions); @override String printEvolution() { return ""; } String _prntEV(List conds, int level) { String sRet = ""; if (level != -1) { sRet += "Level $level"; } for (var condition in conds) { sRet += "${condition.name} "; } return sRet; } @override Widget getEvolution() { // This is a branched evolution. So first, we print the arrows, and conditions. List cardRow = []; for (var pkmn in alternates) { int index = alternates.indexOf(pkmn); if (pkmn >= SessionData.highestGenID() + 1) { print("Index too high"); continue; } Pokemon cpkmn = Pokemon.values.where((x) => x.id == pkmn).first; cardRow.add( Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.arrow_downward, size: 48), Card( elevation: 50, child: SizedBox( width: 256, height: 256, child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( _prntEV(conditions[index], levels[index]), style: TextStyle(fontSize: 16), ), Image.asset(cpkmn.toDexPath(), width: 64, height: 64), Text(cpkmn.pokemonName, style: TextStyle(fontSize: 24)), PokemonHelpers.getTypeWidgets(cpkmn), ], ), ), ), ], ), ); } return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [Row(children: cardRow)], ); } }