battler_data/items/
item_target.rs1use serde_string_enum::{
2 DeserializeLabeledStringEnum,
3 SerializeLabeledStringEnum,
4};
5
6#[derive(
8 Debug, Clone, Copy, PartialEq, Eq, SerializeLabeledStringEnum, DeserializeLabeledStringEnum,
9)]
10pub enum ItemTarget {
11 #[string = "Party"]
13 Party,
14 #[string = "Active"]
16 Active,
17 #[string = "Foe"]
19 Foe,
20 #[string = "IsolatedFoe"]
22 IsolatedFoe,
23}
24
25impl ItemTarget {
26 pub fn choosable(&self) -> bool {
28 match self {
29 Self::Party | Self::Foe => true,
30 _ => false,
31 }
32 }
33
34 pub fn requires_target(&self) -> bool {
36 true
37 }
38}
39
40#[cfg(test)]
41mod item_target_test {
42 use crate::{
43 items::ItemTarget,
44 test_util::{
45 test_string_deserialization,
46 test_string_serialization,
47 },
48 };
49
50 #[test]
51 fn serializes_to_string() {
52 test_string_serialization(ItemTarget::Party, "Party");
53 test_string_serialization(ItemTarget::Foe, "Foe");
54 test_string_serialization(ItemTarget::IsolatedFoe, "IsolatedFoe");
55 }
56
57 #[test]
58 fn deserializes_lowercase() {
59 test_string_deserialization("party", ItemTarget::Party);
60 test_string_deserialization("foe", ItemTarget::Foe);
61 test_string_deserialization("isolatedfoe", ItemTarget::IsolatedFoe);
62 }
63}