genius_invokation/cards/action/
card_trait.rs

1use super::Price;
2use crate::*;
3
4macro_rules! impl_method {
5    ($($type:ident : $article:ident $name:ident ,)+) => {
6        $(
7            #[doc = "Attempts to parse `self` as "]
8            #[doc = stringify!($article)]
9            #[doc = stringify!($name)]
10            #[doc = "card. Returns None if this card is of another type/subtype"]
11            fn $name(&self) -> Option<$type> { None }
12        )+
13    };
14}
15
16pub trait PlayingCard: sealed::Trait {
17    /// The display name of the card
18    fn name(&self) -> &'static str;
19
20    /// How much it costs to play this card ingame
21    fn cost(&self) -> CardCost;
22
23    /// Returns the price for buying this card in Prince's shop (in Lucky Coins)
24    /// 
25    /// If this card is not obtainable from the shop (such as [talent cards]
26    /// or [Paimon]), returns [`None`]
27    /// 
28    /// [talent cards]: crate::TalentCard
29    /// [Paimon]: crate::CompanionCard::Paimon
30    fn shop_price(&self) -> Option<Price>;
31
32    impl_method!(
33        EquipmentCard: an equipment,
34        EventCard: an event,
35        SupportCard: a support,
36        ArtifactCard: an artifact,
37        TalentCard: a talent,
38        WeaponCard: a weapon,
39        FoodCard: a food,
40        CompanionCard: a companion,
41        ItemCard: an item,
42        LocationCard: a location,
43        ElementalResonanceCard: a resonance,
44    );
45
46    /// Attempts to parse `self` as a normal event card (non-food and non-resonance).
47    /// Returns None if this card is of another type/subtype
48    fn normal_event(&self) -> Option<NormalEventCard> { None }
49
50}
51
52mod sealed {
53    use crate::*;
54    pub trait Trait {}
55
56    macro_rules! impl_trait {
57        ($($card:ident)+) => {
58            $(
59                impl Trait for $card {}
60            )+
61        };
62    }
63
64    impl_trait!(ActionCard
65        EquipmentCard ArtifactCard TalentCard WeaponCard
66        EventCard FoodCard NormalEventCard ElementalResonanceCard
67        SupportCard CompanionCard ItemCard LocationCard
68    );
69}