use crate::util::Id;
#[cfg(feature = "serialization")]
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use std::hash::Hash;
#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
pub struct SimpleAbility<I, V> {
id: I,
power: V,
}
impl<I: Send, V: Copy> SimpleAbility<I, V> {
pub fn new(id: I, power: V) -> Self {
Self { id, power }
}
pub fn power(&self) -> V {
self.power
}
pub fn set_power(&mut self, power: V) {
self.power = power;
}
}
#[cfg(not(feature = "serialization"))]
impl<I, V> Id for SimpleAbility<I, V>
where
I: Debug + Hash + Eq + Clone + Send,
{
type Id = I;
fn id(&self) -> &Self::Id {
&self.id
}
}
#[cfg(feature = "serialization")]
impl<I, V> Id for SimpleAbility<I, V>
where
I: Debug + Hash + Eq + Clone + Send + Serialize + for<'a> Deserialize<'a>,
{
type Id = I;
fn id(&self) -> &Self::Id {
&self.id
}
}