boseiju/ability_tree/conditional/
number_of_resolution.rs1use crate::ability_tree::AbilityTreeNode;
2use crate::ability_tree::MAX_CHILDREN_PER_NODE;
3
4#[derive(idris_derive::Idris)]
6#[derive(serde::Serialize, serde::Deserialize)]
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub enum NumberOfResolutions {
9 FirstTimeThisAbilityResolves {
10 #[cfg(feature = "spanned_tree")]
11 span: crate::ability_tree::span::TreeSpan,
12 },
13 SecondTimeThisAbilityResolves {
14 #[cfg(feature = "spanned_tree")]
15 span: crate::ability_tree::span::TreeSpan,
16 },
17 ThirdTimeThisAbilityResolves {
18 #[cfg(feature = "spanned_tree")]
19 span: crate::ability_tree::span::TreeSpan,
20 },
21 FourthTimeThisAbilityResolves {
22 #[cfg(feature = "spanned_tree")]
23 span: crate::ability_tree::span::TreeSpan,
24 },
25}
26
27impl crate::ability_tree::AbilityTreeNode for NumberOfResolutions {
28 fn node_id(&self) -> usize {
29 use idris::Idris;
30 crate::ability_tree::NodeKind::NumberOfResolutionsIdMarker.id()
31 }
32
33 fn children(&self) -> arrayvec::ArrayVec<&dyn AbilityTreeNode, MAX_CHILDREN_PER_NODE> {
34 use crate::ability_tree::NodeKind;
35 use idris::Idris;
36
37 let mut children = arrayvec::ArrayVec::new_const();
38 let child_id = NodeKind::NumberOfResolutions(self.clone()).id();
39 let child = crate::ability_tree::dummy_terminal::TreeNodeDummyTerminal::new(child_id);
40 children.push(child as &dyn AbilityTreeNode);
41 children
42 }
43
44 fn display(&self, out: &mut crate::utils::TreeFormatter<'_>) -> std::io::Result<()> {
45 use std::io::Write;
46 write!(out, "number of time this ability resolved:")?;
47 out.push_final_branch()?;
48 match self {
49 Self::FirstTimeThisAbilityResolves { .. } => write!(out, "first")?,
50 Self::SecondTimeThisAbilityResolves { .. } => write!(out, "second")?,
51 Self::ThirdTimeThisAbilityResolves { .. } => write!(out, "third")?,
52 Self::FourthTimeThisAbilityResolves { .. } => write!(out, "fourth")?,
53 }
54 out.pop_branch();
55 Ok(())
56 }
57
58 fn node_tag(&self) -> &'static str {
59 "condition: number of resolution"
60 }
61
62 #[cfg(feature = "spanned_tree")]
63 fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
64 match self {
65 Self::FirstTimeThisAbilityResolves { span } => *span,
66 Self::SecondTimeThisAbilityResolves { span } => *span,
67 Self::ThirdTimeThisAbilityResolves { span } => *span,
68 Self::FourthTimeThisAbilityResolves { span } => *span,
69 }
70 }
71}
72
73#[cfg(feature = "parser")]
74impl crate::utils::DummyInit for NumberOfResolutions {
75 fn dummy_init() -> Self {
76 Self::FirstTimeThisAbilityResolves {
77 #[cfg(feature = "spanned_tree")]
78 span: Default::default(),
79 }
80 }
81}
82
83#[cfg(feature = "lexer")]
84impl crate::lexer::IntoToken for NumberOfResolutions {
85 fn try_from_span(span: &crate::lexer::Span) -> Option<Self> {
86 match span.text {
87 "this is the first time this ability has resolved this turn" => Some(Self::SecondTimeThisAbilityResolves {
88 #[cfg(feature = "spanned_tree")]
89 span: span.into(),
90 }),
91 "this is the second time this ability has resolved this turn" => Some(Self::SecondTimeThisAbilityResolves {
92 #[cfg(feature = "spanned_tree")]
93 span: span.into(),
94 }),
95 "this is the third time this ability has resolved this turn" => Some(Self::SecondTimeThisAbilityResolves {
96 #[cfg(feature = "spanned_tree")]
97 span: span.into(),
98 }),
99 "this is the fourth time this ability has resolved this turn" => Some(Self::SecondTimeThisAbilityResolves {
100 #[cfg(feature = "spanned_tree")]
101 span: span.into(),
102 }),
103 _ => None,
104 }
105 }
106}