PokeDex/lib/pokemon.dart
2025-03-22 22:31:19 -07:00

318 lines
11 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,
}
class Evolution {
final int to;
final int level;
final EvolutionCondition? condition;
const Evolution(this.to, this.level, {this.condition = null});
String printEvolution() {
String sRet = "";
if (level != -1) {
sRet += "Level $level";
}
if (condition != null) {
if (sRet.isNotEmpty) {
sRet += "\n";
}
sRet += condition.toString().split('.').last;
}
return sRet;
}
}
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], Evolution(2, 16)),
Ivysaur(2, Generation.One, [Type.Grass, Type.Poison], Evolution(3, 32)),
Venusaur(3, Generation.One, [Type.Grass, Type.Poison], null),
Charmander(4, Generation.One, [Type.Fire], Evolution(5, 16)),
Charmeleon(5, Generation.One, [Type.Fire], Evolution(6, 36)),
Charizard(6, Generation.One, [Type.Fire, Type.Flying], null),
Squirtle(7, Generation.One, [Type.Water], Evolution(8, 16)),
Wartortle(8, Generation.One, [Type.Water], Evolution(9, 36)),
Blastoise(9, Generation.One, [Type.Water], null),
Caterpie(10, Generation.One, [Type.Bug], Evolution(11, 7)),
Metapod(11, Generation.One, [Type.Bug], Evolution(12, 10)),
Butterfree(12, Generation.One, [Type.Bug, Type.Flying], null),
Weedle(13, Generation.One, [Type.Bug, Type.Poison], Evolution(14, 7)),
Kakuna(14, Generation.One, [Type.Bug, Type.Poison], Evolution(15, 10)),
Beedrill(15, Generation.One, [Type.Bug, Type.Poison], null),
Pidgey(16, Generation.One, [Type.Normal, Type.Flying], Evolution(17, 18)),
Pidgeotto(17, Generation.One, [Type.Normal, Type.Flying], Evolution(18, 36)),
Pidgeot(18, Generation.One, [Type.Normal, Type.Flying], null),
Rattata(19, Generation.One, [Type.Normal], Evolution(20, 20)),
Raticate(20, Generation.One, [Type.Normal], null),
Spearow(21, Generation.One, [Type.Normal, Type.Flying], Evolution(22, 20)),
Fearow(22, Generation.One, [Type.Normal, Type.Flying], null),
Pikachu(25, Generation.One, [
Type.Electric,
], Evolution(26, -1, condition: EvolutionCondition.ThunderStone)),
Raichu(26, Generation.One, [Type.Electric], null),
Sandshrew(27, Generation.One, [Type.Ground], Evolution(28, 22)),
Sandslash(28, Generation.One, [Type.Ground], null),
NidoranF(29, Generation.One, [Type.Poison], Evolution(30, 16)),
Nidorina(30, Generation.One, [Type.Poison], Evolution(31, 36)),
NidoQueen(31, Generation.One, [Type.Poison, Type.Ground], null),
NidoranM(32, Generation.One, [Type.Poison], Evolution(33, 16)),
Nidorino(33, Generation.One, [Type.Poison], Evolution(34, 36)),
NidoKing(34, Generation.One, [Type.Poison, Type.Ground], null),
Clefairy(35, Generation.One, [
Type.Fairy,
], Evolution(36, -1, condition: EvolutionCondition.MoonStone)),
Clefable(36, Generation.One, [Type.Fairy], null),
Vulpix(37, Generation.One, [
Type.Fire,
], Evolution(38, -1, condition: EvolutionCondition.FireStone)),
NineTales(38, Generation.One, [Type.Fire], null),
Jigglypuff(39, Generation.One, [
Type.Fairy,
], Evolution(40, -1, condition: EvolutionCondition.MoonStone)),
WigglyTuff(40, Generation.One, [Type.Fairy], null),
Zubat(41, Generation.One, [Type.Poison, Type.Flying], Evolution(42, 22)),
Golbat(42, Generation.One, [Type.Poison, Type.Flying], null),
Oddish(43, Generation.One, [Type.Poison, Type.Grass], Evolution(44, 21)),
Gloom(44, Generation.One, [
Type.Poison,
Type.Grass,
], Evolution(45, -1, condition: EvolutionCondition.LeafStone)),
Vileplume(45, Generation.One, [Type.Poison, Type.Grass], null),
Paras(46, Generation.One, [Type.Bug, Type.Grass], Evolution(47, 24)),
Parasect(47, Generation.One, [Type.Bug, Type.Grass], null),
Venonat(48, Generation.One, [Type.Bug, Type.Poison], Evolution(49, 31)),
Venomoth(49, Generation.One, [Type.Bug, Type.Poison], null),
Diglett(50, Generation.One, [Type.Ground], Evolution(51, 26)),
Dugtrio(51, Generation.One, [Type.Ground], null),
Meowth(52, Generation.One, [Type.Normal], Evolution(53, 28)),
Persian(53, Generation.One, [Type.Normal], null),
Psyduck(54, Generation.One, [Type.Water], Evolution(55, 33)),
Golduck(55, Generation.One, [Type.Water], null),
Mankey(56, Generation.One, [Type.Fighting], Evolution(57, 28)),
Primeape(57, Generation.One, [Type.Fighting], null),
Growlithe(58, Generation.One, [
Type.Fire,
], Evolution(59, -1, condition: EvolutionCondition.FireStone)),
Arcanine(59, Generation.One, [Type.Fire], null),
Poliwag(60, Generation.One, [Type.Water], Evolution(61, 25)),
Poliwhirl(61, Generation.One, [
Type.Water,
], Evolution(62, -1, condition: EvolutionCondition.WaterStone)),
Poliwrath(62, Generation.One, [Type.Water], 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.values.where((x) => x.id == evolution!.to).first;
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;
}
}