use serde_string_enum::{
DeserializeLabeledStringEnum,
SerializeLabeledStringEnum,
};
#[derive(
Debug, Clone, Copy, PartialEq, Eq, SerializeLabeledStringEnum, DeserializeLabeledStringEnum,
)]
pub enum ItemTarget {
#[string = "Party"]
Party,
#[string = "Active"]
Active,
#[string = "Foe"]
Foe,
#[string = "IsolatedFoe"]
IsolatedFoe,
}
impl ItemTarget {
pub fn choosable(&self) -> bool {
match self {
Self::Party | Self::Foe => true,
_ => false,
}
}
pub fn requires_target(&self) -> bool {
true
}
}
#[cfg(test)]
mod item_target_test {
use crate::{
items::ItemTarget,
test_util::{
test_string_deserialization,
test_string_serialization,
},
};
#[test]
fn serializes_to_string() {
test_string_serialization(ItemTarget::Party, "Party");
test_string_serialization(ItemTarget::Foe, "Foe");
test_string_serialization(ItemTarget::IsolatedFoe, "IsolatedFoe");
}
#[test]
fn deserializes_lowercase() {
test_string_deserialization("party", ItemTarget::Party);
test_string_deserialization("foe", ItemTarget::Foe);
test_string_deserialization("isolatedfoe", ItemTarget::IsolatedFoe);
}
}