boseiju/ability_tree/object/object_kind/
permanent.rs

1use crate::ability_tree::AbilityTreeNode;
2use crate::ability_tree::MAX_CHILDREN_PER_NODE;
3use crate::ability_tree::tree_node::MtgDataNodeKind;
4use idris::Idris;
5
6/// Wrapper around the card type.
7#[derive(serde::Serialize, serde::Deserialize)]
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
9pub struct PermanentObjectKind {
10    #[cfg(feature = "spanned_tree")]
11    pub span: crate::ability_tree::span::TreeSpan,
12}
13
14impl PermanentObjectKind {
15    pub fn all() -> impl Iterator<Item = Self> {
16        std::iter::once(Self {
17            #[cfg(feature = "spanned_tree")]
18            span: Default::default(),
19        })
20    }
21}
22
23impl AbilityTreeNode for PermanentObjectKind {
24    fn node_id(&self) -> usize {
25        crate::ability_tree::NodeKind::MtgData(MtgDataNodeKind::PermanentIdMarker).id()
26    }
27
28    fn children(&self) -> arrayvec::ArrayVec<&dyn AbilityTreeNode, MAX_CHILDREN_PER_NODE> {
29        arrayvec::ArrayVec::new_const()
30    }
31
32    fn display(&self, out: &mut crate::utils::TreeFormatter<'_>) -> std::io::Result<()> {
33        use std::io::Write;
34        write!(out, "permanent")
35    }
36
37    fn node_tag(&self) -> &'static str {
38        "permanent"
39    }
40
41    #[cfg(feature = "spanned_tree")]
42    fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
43        self.span
44    }
45}
46
47impl idris::Idris for PermanentObjectKind {
48    const COUNT: usize = 1;
49    fn id(&self) -> usize {
50        0
51    }
52    fn name_from_id(_: usize) -> &'static str {
53        "Permanent"
54    }
55}
56
57#[cfg(feature = "lexer")]
58impl crate::lexer::IntoToken for PermanentObjectKind {
59    fn try_from_span(span: &crate::lexer::Span) -> Option<Self> {
60        match span.text {
61            "permanent" | "permanents" => Some(PermanentObjectKind {
62                #[cfg(feature = "spanned_tree")]
63                span: span.into(),
64            }),
65            _ => None,
66        }
67    }
68}
69
70#[cfg(feature = "parser")]
71impl crate::utils::DummyInit for PermanentObjectKind {
72    fn dummy_init() -> Self {
73        Self {
74            #[cfg(feature = "spanned_tree")]
75            span: Default::default(),
76        }
77    }
78}