Support for serializing and deserializing a Pokemon
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-07-22 12:23:33 +02:00
parent f23fc43405
commit 12802ce542
15 changed files with 473 additions and 12 deletions

View File

@@ -9,7 +9,8 @@ use crate::{PkmnError, StringKey};
/// A unique key that can be used to store a reference to a type. Opaque reference to a byte
/// internally.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Default, Hash, Atom)]
#[repr(C)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(transparent)]
pub struct TypeIdentifier {
/// The unique internal value.
val: u8,

View File

@@ -53,6 +53,7 @@ impl Ability for AbilityImpl {
/// An ability index allows us to find an ability on a form. It combines a bool for whether the
/// ability is hidden or not, and then an index of the ability.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[repr(C)]
pub struct AbilityIndex {
/// Whether or not the ability we're referring to is a hidden ability.

View File

@@ -3,6 +3,7 @@
/// Required for standard pokemon functions, but somewhat controversial nowadays. Consider adding a feature
/// that allows for a more progressive gender system for those that want it?
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde_repr::Serialize_repr, serde_repr::Deserialize_repr))]
#[repr(u8)]
pub enum Gender {
/// The Pokemon has no gender.

View File

@@ -205,6 +205,7 @@ where
/// A clamped statistic set holds the 6 normal stats for a Pokemon, but ensures it always remains
/// between two values (inclusive on the two values).
#[derive(Default, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ClampedStatisticSet<T, const MIN: i64, const MAX: i64>
where
T: PrimitiveAtom,
@@ -376,6 +377,28 @@ where
}
}
impl<T, const MIN: i64, const MAX: i64> Clone for ClampedStatisticSet<T, MIN, MAX>
where
T: PrimitiveAtom,
T: Atom,
T: PrimitiveAtomInteger,
<T as Atom>::Repr: PrimitiveAtomInteger,
T: AtomInteger,
T: NumCast,
T: PrimInt,
{
fn clone(&self) -> Self {
Self {
hp: Atomic::<T>::new(self.hp()),
attack: Atomic::<T>::new(self.attack()),
defense: Atomic::<T>::new(self.defense()),
special_attack: Atomic::<T>::new(self.special_attack()),
special_defense: Atomic::<T>::new(self.special_defense()),
speed: Atomic::<T>::new(self.speed()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;