commit 78255939e31be18fa96e39745395493ecee9a15c Author: xenua Date: Wed Nov 15 08:15:05 2023 +0100 initial wip diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fffb2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a4115f7 --- /dev/null +++ b/Cargo.toml @@ -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] diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..be07f9a --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,278 @@ +use std::{ + fmt::Display, + ops::{Index, IndexMut}, +}; + +pub struct Pokemon { + species: u32, + trainer_id: TrainerId, + generation: Generation, + nickname: Option, + 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 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 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 for Option { + 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 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 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 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 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 {}