PokeDex/lib/pokemon.dart
2025-03-23 14:27:46 -07:00

452 lines
14 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:pokedex/Consts.dart';
enum Generation {
One,
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine;
toSpritePath() {
switch (this) {
case Generation.One:
return 'assets/sprites/gen1';
case Generation.Two:
return 'assets/sprites/gen2';
case Generation.Three:
return 'assets/sprites/gen3';
case Generation.Four:
return 'assets/sprites/gen4';
case Generation.Five:
return 'assets/sprites/gen5';
case Generation.Six:
return 'assets/sprites/gen6';
case Generation.Seven:
return 'assets/sprites/gen7';
case Generation.Eight:
return 'assets/sprites/gen8';
case Generation.Nine:
return 'assets/sprites/gen9';
}
}
}
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), Colors.black),
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), Colors.black),
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), Colors.black),
Dark(Color.fromARGB(255, 51, 51, 51), Colors.black),
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);
}
enum EvolutionCondition {
HighFriendship,
ThunderStone,
WaterStone,
Trading,
MoonStone,
FireStone,
LeafStone,
}
abstract class Evolution {
const Evolution();
String printEvolution();
}
class SingleEvolution extends Evolution {
final int to;
final int level;
final List<EvolutionCondition>? condition;
const SingleEvolution(this.to, this.level, {this.condition = null});
@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;
}
}
class BranchedEvolution extends Evolution {
final List<int> alternates;
final List<int> levels;
final List<List<EvolutionCondition>?> conditions;
const BranchedEvolution(this.alternates, this.levels, this.conditions);
@override
String printEvolution() {
return "";
}
}
enum LearnType { TM, HM }
enum Move {
Growl(LearnType.TM, Type.Normal, "Growl", 0, 100, 40),
Tackle(LearnType.TM, Type.Normal, "Tackle", 40, 100, 35),
VineWhip(LearnType.TM, Type.Grass, "Vine Whip", 45, 100, 25),
RazorLeaf(LearnType.TM, Type.Grass, "Razor Leaf", 55, 95, 25),
SolarBeam(LearnType.TM, Type.Grass, "Solar Beam", 120, 100, 10),
PoisonPowder(LearnType.TM, Type.Poison, "Poison Powder", 0, 75, 35),
SleepPowder(LearnType.TM, Type.Grass, "Sleep Powder", 0, 75, 15),
TakeDown(LearnType.TM, Type.Normal, "Take Down", 90, 85, 20),
DoubleEdge(LearnType.TM, Type.Normal, "Double-Edge", 120, 100, 15),
LeechSeed(LearnType.TM, Type.Grass, "Leech Seed", 0, 90, 10),
Growth(LearnType.TM, Type.Normal, "Growth", 0, 0, 20),
PoisonSting(LearnType.TM, Type.Poison, "Poison Sting", 15, 100, 35),
StringShot(LearnType.TM, Type.Bug, "String Shot", 0, 95, 40),
BugBite(LearnType.TM, Type.Bug, "Bug Bite", 60, 100, 20),
Confusion(LearnType.TM, Type.Psychic, "Confusion", 50, 100, 25);
final LearnType type;
final Type moveType;
final String moveName;
final int power;
final int accuracy;
final int pp;
const Move(
this.type,
this.moveType,
this.moveName,
this.power,
this.accuracy,
this.pp,
);
}
enum Pokemon {
Bulbasaur(1, Generation.One, [
Type.Grass,
Type.Poison,
], SingleEvolution(2, 16)),
Ivysaur(2, Generation.One, [Type.Grass, Type.Poison], SingleEvolution(3, 32)),
Venusaur(3, Generation.One, [Type.Grass, Type.Poison], null),
Charmander(4, Generation.One, [Type.Fire], SingleEvolution(5, 16)),
Charmeleon(5, Generation.One, [Type.Fire], SingleEvolution(6, 36)),
Charizard(6, Generation.One, [Type.Fire, Type.Flying], null),
Squirtle(7, Generation.One, [Type.Water], SingleEvolution(8, 16)),
Wartortle(8, Generation.One, [Type.Water], SingleEvolution(9, 36)),
Blastoise(9, Generation.One, [Type.Water], null),
Caterpie(10, Generation.One, [Type.Bug], SingleEvolution(11, 7)),
Metapod(11, Generation.One, [Type.Bug], SingleEvolution(12, 10)),
Butterfree(12, Generation.One, [Type.Bug, Type.Flying], null),
Weedle(13, Generation.One, [Type.Bug, Type.Poison], SingleEvolution(14, 7)),
Kakuna(14, Generation.One, [Type.Bug, Type.Poison], SingleEvolution(15, 10)),
Beedrill(15, Generation.One, [Type.Bug, Type.Poison], null),
Pidgey(16, Generation.One, [
Type.Normal,
Type.Flying,
], SingleEvolution(17, 18)),
Pidgeotto(17, Generation.One, [
Type.Normal,
Type.Flying,
], SingleEvolution(18, 36)),
Pidgeot(18, Generation.One, [Type.Normal, Type.Flying], null),
Rattata(19, Generation.One, [Type.Normal], SingleEvolution(20, 20)),
Raticate(20, Generation.One, [Type.Normal], null),
Spearow(21, Generation.One, [
Type.Normal,
Type.Flying,
], SingleEvolution(22, 20)),
Fearow(22, Generation.One, [Type.Normal, Type.Flying], null),
Pikachu(
25,
Generation.One,
[Type.Electric],
SingleEvolution(26, -1, condition: [EvolutionCondition.ThunderStone]),
),
Raichu(26, Generation.One, [Type.Electric], null),
Sandshrew(27, Generation.One, [Type.Ground], SingleEvolution(28, 22)),
Sandslash(28, Generation.One, [Type.Ground], null),
NidoranF(29, Generation.One, [Type.Poison], SingleEvolution(30, 16)),
Nidorina(30, Generation.One, [Type.Poison], SingleEvolution(31, 36)),
NidoQueen(31, Generation.One, [Type.Poison, Type.Ground], null),
NidoranM(32, Generation.One, [Type.Poison], SingleEvolution(33, 16)),
Nidorino(33, Generation.One, [Type.Poison], SingleEvolution(34, 36)),
NidoKing(34, Generation.One, [Type.Poison, Type.Ground], null),
Clefairy(
35,
Generation.One,
[Type.Fairy],
SingleEvolution(36, -1, condition: [EvolutionCondition.MoonStone]),
),
Clefable(36, Generation.One, [Type.Fairy], null),
Vulpix(
37,
Generation.One,
[Type.Fire],
SingleEvolution(38, -1, condition: [EvolutionCondition.FireStone]),
),
NineTales(38, Generation.One, [Type.Fire], null),
Jigglypuff(
39,
Generation.One,
[Type.Fairy],
SingleEvolution(40, -1, condition: [EvolutionCondition.MoonStone]),
),
WigglyTuff(40, Generation.One, [Type.Fairy], null),
Zubat(41, Generation.One, [
Type.Poison,
Type.Flying,
], SingleEvolution(42, 22)),
Golbat(42, Generation.One, [Type.Poison, Type.Flying], null),
Oddish(43, Generation.One, [
Type.Poison,
Type.Grass,
], SingleEvolution(44, 21)),
Gloom(
44,
Generation.One,
[Type.Poison, Type.Grass],
SingleEvolution(45, -1, condition: [EvolutionCondition.LeafStone]),
),
Vileplume(45, Generation.One, [Type.Poison, Type.Grass], null),
Paras(46, Generation.One, [Type.Bug, Type.Grass], SingleEvolution(47, 24)),
Parasect(47, Generation.One, [Type.Bug, Type.Grass], null),
Venonat(48, Generation.One, [Type.Bug, Type.Poison], SingleEvolution(49, 31)),
Venomoth(49, Generation.One, [Type.Bug, Type.Poison], null),
Diglett(50, Generation.One, [Type.Ground], SingleEvolution(51, 26)),
Dugtrio(51, Generation.One, [Type.Ground], null),
Meowth(52, Generation.One, [Type.Normal], SingleEvolution(53, 28)),
Persian(53, Generation.One, [Type.Normal], null),
Psyduck(54, Generation.One, [Type.Water], SingleEvolution(55, 33)),
Golduck(55, Generation.One, [Type.Water], null),
Mankey(56, Generation.One, [Type.Fighting], SingleEvolution(57, 28)),
Primeape(57, Generation.One, [Type.Fighting], null),
Growlithe(
58,
Generation.One,
[Type.Fire],
SingleEvolution(59, -1, condition: [EvolutionCondition.FireStone]),
),
Arcanine(59, Generation.One, [Type.Fire], null),
Poliwag(60, Generation.One, [Type.Water], SingleEvolution(61, 25)),
Poliwhirl(
61,
Generation.One,
[Type.Water],
SingleEvolution(62, -1, condition: [EvolutionCondition.WaterStone]),
),
Poliwrath(62, Generation.One, [Type.Water], null),
Abra(63, Generation.One, [Type.Psychic], SingleEvolution(64, 16)),
Kadabra(64, Generation.One, [
Type.Psychic,
], SingleEvolution(65, -1, condition: [EvolutionCondition.Trading])),
Alakazam(65, Generation.One, [Type.Psychic], null),
Machop(66, Generation.One, [Type.Fighting], SingleEvolution(67, 28)),
Machoke(67, Generation.One, [
Type.Fighting,
], SingleEvolution(68, -1, condition: [EvolutionCondition.Trading])),
Machamp(68, Generation.One, [Type.Fighting], null),
Bellsprout(69, Generation.One, [
Type.Grass,
Type.Poison,
], SingleEvolution(70, 21)),
Weepinbell(
70,
Generation.One,
[Type.Grass, Type.Poison],
SingleEvolution(71, -1, condition: [EvolutionCondition.LeafStone]),
),
Victreebel(71, Generation.One, [Type.Grass, Type.Poison], null),
Tentacool(72, Generation.One, [
Type.Water,
Type.Poison,
], SingleEvolution(73, 30)),
Tentacruel(73, Generation.One, [Type.Water, Type.Poison], null),
Geodude(74, Generation.One, [
Type.Rock,
Type.Ground,
], SingleEvolution(75, 25)),
Graveler(75, Generation.One, [
Type.Rock,
Type.Ground,
], SingleEvolution(76, -1, condition: [EvolutionCondition.Trading])),
Golem(76, Generation.One, [Type.Rock, Type.Ground], null),
Ponyta(77, Generation.One, [Type.Fire], SingleEvolution(78, 40)),
Rapidash(78, Generation.One, [Type.Fire], null),
Slowpoke(79, Generation.One, [
Type.Water,
Type.Psychic,
], SingleEvolution(80, 37)),
Slowbro(80, Generation.One, [Type.Water, Type.Psychic], null),
Magnemite(81, Generation.One, [
Type.Electric,
Type.Steel,
], SingleEvolution(82, 30)),
Magneton(82, Generation.One, [Type.Electric, Type.Steel], null),
Farfetchd(83, Generation.One, [Type.Fighting], null),
Doduo(84, Generation.One, [
Type.Normal,
Type.Flying,
], SingleEvolution(85, 31)),
Dodrio(85, Generation.One, [Type.Normal, Type.Flying], null),
Seel(86, Generation.One, [Type.Water], SingleEvolution(87, 34)),
Dewgong(87, Generation.One, [Type.Water, Type.Ice], null),
Grimer(88, Generation.One, [Type.Poison], SingleEvolution(89, 38)),
Muk(89, Generation.One, [Type.Poison], null),
Shellder(
90,
Generation.One,
[Type.Water],
SingleEvolution(91, -1, condition: [EvolutionCondition.WaterStone]),
),
Cloyster(91, Generation.One, [Type.Water, Type.Ice], null);
final int id;
final Generation generation;
final List<Type> types;
final Evolution? evolution;
bool get hasEvolutions => evolution != null;
const Pokemon(this.id, this.generation, this.types, this.evolution);
String toDexPath() {
return 'assets/sprites/${printName().replaceAll("", "-f").replaceAll("", "-m").toLowerCase()}.png';
}
Widget getTypeWidgets() {
List<Widget> widgets = [];
for (Type type in types) {
widgets.add(
ElevatedButton(
onPressed: () {},
style: ButtonStyle(
backgroundColor: WidgetStatePropertyAll(type.backgroundColor),
foregroundColor: WidgetStatePropertyAll(type.textColor),
),
child: Text(
type.name,
style: TextStyle(fontSize: Constants.isMobile ? 16 : 32),
),
),
);
}
return Row(children: widgets);
}
String printName() {
String sRet = name.replaceAll("_", " ");
if (sRet.endsWith("F")) sRet = sRet.substring(0, sRet.length - 1) + "";
if (sRet.endsWith("M")) sRet = sRet.substring(0, sRet.length - 1) + "";
return sRet;
}
List<Widget> getEvolutions(int subID) {
if (!hasEvolutions) return [];
Pokemon ev = Pokemon.Abra;
if (evolution is SingleEvolution)
ev =
Pokemon.values
.where((x) => x.id == (evolution! as SingleEvolution).to)
.first;
else {
// Handle branched evolutions. Refactor below to accomodate a list of pokemon.
}
List<Widget> sprites = [];
if (subID == 0) {
sprites.add(Text("Evolutions: ", style: TextStyle(fontSize: 24)));
sprites.add(
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.asset(
toDexPath(),
width: Constants.isMobile ? 64 : 128,
height: Constants.isMobile ? 64 : 128,
),
getTypeWidgets(),
],
),
);
sprites.add(
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
Constants.isMobile ? Icons.arrow_downward : Icons.arrow_forward,
size: 48,
),
Text(evolution!.printEvolution(), style: TextStyle(fontSize: 24)),
],
),
);
}
sprites.add(
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Constants.isMobile
? Image.asset(ev.toDexPath(), width: 64, height: 64)
: Image.asset(ev.toDexPath(), width: 128, height: 128),
ev.getTypeWidgets(),
],
),
);
if (ev.hasEvolutions) {
sprites.add(
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(
Constants.isMobile ? Icons.arrow_downward : Icons.arrow_forward,
size: 48,
),
Text(
ev.evolution!.printEvolution(),
style: TextStyle(fontSize: 24),
),
],
),
);
//sprites.add(Icon(Icons.arrow_forward, size: 48));
sprites.addAll(ev.getEvolutions(subID + 1));
}
return sprites;
}
}