savestate: add Stats struct in IndividualPk
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
9ec4075f62
commit
fa556b253a
1 changed files with 30 additions and 6 deletions
|
@ -166,11 +166,32 @@ impl TryFrom<&[u8; 10]> for EV {
|
||||||
/// Displayed stats. These can be recalculated from IVs and EVs.
|
/// Displayed stats. These can be recalculated from IVs and EVs.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Stats {
|
pub struct Stats {
|
||||||
hp: u32,
|
hp: u16,
|
||||||
attack: u32,
|
attack: u16,
|
||||||
defense: u32,
|
defense: u16,
|
||||||
speed: u32,
|
speed: u16,
|
||||||
special: u32,
|
special: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&[u8]> for Stats {
|
||||||
|
type Error = Error;
|
||||||
|
|
||||||
|
fn try_from(data: &[u8]) -> Result<Stats, Error> {
|
||||||
|
let data: &[u8; 10] = data.try_into()?;
|
||||||
|
Ok(Stats::from(data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&[u8; 10]> for Stats {
|
||||||
|
fn from(data: &[u8; 10]) -> Stats {
|
||||||
|
Stats {
|
||||||
|
hp: u16::from_be_bytes(data[0x0..0x2].try_into().unwrap()),
|
||||||
|
attack: u16::from_be_bytes(data[0x2..0x4].try_into().unwrap()),
|
||||||
|
defense: u16::from_be_bytes(data[0x4..0x6].try_into().unwrap()),
|
||||||
|
speed: u16::from_be_bytes(data[0x6..0x8].try_into().unwrap()),
|
||||||
|
special: u16::from_be_bytes(data[0x8..0xa].try_into().unwrap()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Types are properties for Pokémons and their moves.
|
/// Types are properties for Pokémons and their moves.
|
||||||
|
@ -501,6 +522,7 @@ const PK_XP_OFFSET: usize = 0xe; // Over 3 bytes
|
||||||
const PK_OT_RANGE: Range<usize> = 0xc..0xe;
|
const PK_OT_RANGE: Range<usize> = 0xc..0xe;
|
||||||
const PK_MOVES_RANGE: Range<usize> = 0x8..0xc;
|
const PK_MOVES_RANGE: Range<usize> = 0x8..0xc;
|
||||||
const PK_PP_RANGE: Range<usize> = 0x1d..0x21;
|
const PK_PP_RANGE: Range<usize> = 0x1d..0x21;
|
||||||
|
const PK_STATS_RANGE: Range<usize> = 0x22..0x2c;
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct IndividualPk {
|
pub struct IndividualPk {
|
||||||
|
@ -516,7 +538,7 @@ pub struct IndividualPk {
|
||||||
pub xp: u32,
|
pub xp: u32,
|
||||||
pub iv: IV,
|
pub iv: IV,
|
||||||
pub ev: EV,
|
pub ev: EV,
|
||||||
// pub stats: Stats,
|
pub stats: Stats,
|
||||||
pub moves: Moves,
|
pub moves: Moves,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,6 +556,7 @@ impl fmt::Debug for IndividualPk {
|
||||||
.field("xp", &self.xp)
|
.field("xp", &self.xp)
|
||||||
.field("iv", &self.iv)
|
.field("iv", &self.iv)
|
||||||
.field("ev", &self.ev)
|
.field("ev", &self.ev)
|
||||||
|
.field("stats", &self.stats)
|
||||||
.field("moves", &self.moves)
|
.field("moves", &self.moves)
|
||||||
.finish_non_exhaustive()
|
.finish_non_exhaustive()
|
||||||
}
|
}
|
||||||
|
@ -582,6 +605,7 @@ impl TryFrom<(&[u8], PKString, PKString)> for IndividualPk {
|
||||||
xp,
|
xp,
|
||||||
iv: IV::try_from(&data[PK_IV_RANGE])?,
|
iv: IV::try_from(&data[PK_IV_RANGE])?,
|
||||||
ev: EV::try_from(&data[PK_EV_RANGE])?,
|
ev: EV::try_from(&data[PK_EV_RANGE])?,
|
||||||
|
stats: Stats::try_from(&data[PK_STATS_RANGE])?,
|
||||||
moves,
|
moves,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue