Browse Source

initial wip

main
xenua 6 months ago
commit
78255939e3
Signed by: xenua
GPG Key ID: 8F93B68BD37255B8
  1. 2
      .gitignore
  2. 8
      Cargo.toml
  3. 278
      src/lib.rs

2
.gitignore vendored

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
/target
/Cargo.lock

8
Cargo.toml

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
[package]
name = "pokedata"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

278
src/lib.rs

@ -0,0 +1,278 @@ @@ -0,0 +1,278 @@
use std::{
fmt::Display,
ops::{Index, IndexMut},
};
pub struct Pokemon {
species: u32,
trainer_id: TrainerId,
generation: Generation,
nickname: Option<String>,
language: Language,
gender: Gender,
isFatefulEncounter: bool,
}
pub enum TrainerId {
/// used in gens 1-2. no secret id
SixteenBitSingle(u16),
/// gens 3-6, and 1-2 transferred to 7+
SixteenBit(u16, u16),
/// gens 7+
SixDigit(u32),
}
impl Display for TrainerId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{:06}",
match self {
TrainerId::SixteenBitSingle(v) => *v as u32,
TrainerId::SixteenBit(v, _) => *v as u32,
TrainerId::SixDigit(v) => v % 100_000,
}
)
}
}
pub enum Generation {
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9,
/// the Let's Go gamess
Gen7b,
/// Legends Arceus
Gen8a,
/// BDSP
Gen8b,
}
pub enum Nature {
Hardy = 0,
Lonely = 1,
Brave = 2,
Adamant = 3,
Naughty = 4,
Bold = 5,
Docile = 6,
Relaxed = 7,
Impish = 8,
Lax = 9,
Timid = 10,
Hasty = 11,
Serious = 12,
Jolly = 13,
Naive = 14,
Modest = 15,
Mild = 16,
Quiet = 17,
Bashful = 18,
Rash = 19,
Calm = 20,
Gentle = 21,
Sassy = 22,
Careful = 23,
Quirky = 24,
}
impl From<Nature> for Option<(Stat, Stat)> {
fn from(value: Nature) -> Self {
use Nature::*;
use Stat::*;
match value {
Hardy => None,
Lonely => Some((Attack, Defense)),
Brave => Some((Attack, Speed)),
Adamant => Some((Attack, SpAtk)),
Naughty => Some((Attack, SpDef)),
Bold => Some((Defense, Attack)),
Docile => None,
Relaxed => Some((Defense, Speed)),
Impish => Some((Defense, SpAtk)),
Lax => Some((Defense, SpDef)),
Timid => Some((Speed, Attack)),
Hasty => Some((Speed, Defense)),
Serious => None,
Jolly => Some((Speed, SpAtk)),
Naive => Some((Speed, SpDef)),
Modest => Some((SpAtk, Attack)),
Mild => Some((SpAtk, Defense)),
Quiet => Some((SpAtk, Speed)),
Bashful => None,
Rash => Some((SpAtk, SpDef)),
Calm => Some((SpDef, Attack)),
Gentle => Some((SpDef, Defense)),
Sassy => Some((SpDef, Speed)),
Careful => Some((SpDef, SpAtk)),
Quirky => None,
}
}
}
pub enum Stat {
HitPoints,
Attack,
Defense,
SpAtk,
SpDef,
Speed,
}
pub enum Flavor {
Spicy,
Sour,
Dry,
Bitter,
Sweet,
}
impl From<Flavor> for Stat {
fn from(value: Flavor) -> Self {
use Flavor::*;
use Stat::*;
match value {
Spicy => Attack,
Sour => Defense,
Dry => SpAtk,
Bitter => SpDef,
Sweet => Speed,
}
}
}
impl From<Stat> for Option<Flavor> {
fn from(value: Stat) -> Self {
use Flavor::*;
use Stat::*;
match value {
HitPoints => None,
Attack => Some(Spicy),
Defense => Some(Sour),
SpAtk => Some(Dry),
SpDef => Some(Bitter),
Speed => Some(Sweet),
}
}
}
pub enum Language {
Hacked = 0,
Japanese = 1,
English = 2,
French = 3,
Italian = 4,
German = 5,
Unused6 = 6,
Spanish = 7,
Korean = 8,
ChineseS = 9,
ChineseT = 10,
}
pub enum Gender {
Male = 0,
Female = 1,
Genderless = 2,
}
pub struct IVs {
pub hp: u8,
pub atk: u8,
pub def: u8,
pub spa: u8,
pub spd: u8,
pub spe: u8,
}
impl Index<Stat> for IVs {
type Output = u8;
fn index(&self, index: Stat) -> &Self::Output {
use Stat::*;
match index {
HitPoints => &self.hp,
Attack => &self.atk,
Defense => &self.def,
SpAtk => &self.spa,
SpDef => &self.spd,
Speed => &self.spe,
}
}
}
impl IndexMut<Stat> for IVs {
fn index_mut(&mut self, index: Stat) -> &mut Self::Output {
use Stat::*;
match index {
HitPoints => &mut self.hp,
Attack => &mut self.atk,
Defense => &mut self.def,
SpAtk => &mut self.spa,
SpDef => &mut self.spd,
Speed => &mut self.spe,
}
}
}
pub struct EVs {
pub hp: u8,
pub atk: u8,
pub def: u8,
pub spa: u8,
pub spd: u8,
pub spe: u8,
}
impl Index<Stat> for EVs {
type Output = u8;
fn index(&self, index: Stat) -> &Self::Output {
use Stat::*;
match index {
HitPoints => &self.hp,
Attack => &self.atk,
Defense => &self.def,
SpAtk => &self.spa,
SpDef => &self.spd,
Speed => &self.spe,
}
}
}
impl IndexMut<Stat> for EVs {
fn index_mut(&mut self, index: Stat) -> &mut Self::Output {
use Stat::*;
match index {
HitPoints => &mut self.hp,
Attack => &mut self.atk,
Defense => &mut self.def,
SpAtk => &mut self.spa,
SpDef => &mut self.spd,
Speed => &mut self.spe,
}
}
}
pub struct CurrentMoveSet(LearnedMove, LearnedMove, LearnedMove, LearnedMove);
pub struct LearnedMove {
inner: Move,
pp_up: u8,
}
pub enum Move {}
Loading…
Cancel
Save