boseiju/ability_tree/event/replacement/
counter_on_permanent.rs

1use crate::ability_tree::AbilityTreeNode;
2use crate::ability_tree::MAX_CHILDREN_PER_NODE;
3
4/// Fixme: doc
5#[derive(serde::Serialize, serde::Deserialize)]
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct CounterOnPermanentReplacement {
8    pub source_ref: super::EventSourceReference,
9    pub put_counters: crate::ability_tree::imperative::PutCountersImperative,
10    #[cfg(feature = "spanned_tree")]
11    pub span: crate::ability_tree::span::TreeSpan,
12}
13
14impl AbilityTreeNode for CounterOnPermanentReplacement {
15    fn node_id(&self) -> usize {
16        use idris::Idris;
17        crate::ability_tree::NodeKind::CounterOnPermanentReplacement.id()
18    }
19
20    fn children(&self) -> arrayvec::ArrayVec<&dyn AbilityTreeNode, MAX_CHILDREN_PER_NODE> {
21        let mut children = arrayvec::ArrayVec::new_const();
22        children.push(&self.source_ref as &dyn AbilityTreeNode);
23        children.push(&self.put_counters as &dyn AbilityTreeNode);
24        children
25    }
26
27    fn display(&self, out: &mut crate::utils::TreeFormatter<'_>) -> std::io::Result<()> {
28        use std::io::Write;
29        write!(out, "put counters replacement:")?;
30        out.push_inter_branch()?;
31        write!(out, "effect source:")?;
32        out.push_final_branch()?;
33        self.source_ref.display(out)?;
34        out.pop_branch();
35        out.next_final_branch()?;
36        write!(out, "put counters:")?;
37        out.push_final_branch()?;
38        self.put_counters.display(out)?;
39        out.pop_branch();
40        out.pop_branch();
41        Ok(())
42    }
43
44    fn node_tag(&self) -> &'static str {
45        "counter on permanent replacement"
46    }
47
48    #[cfg(feature = "spanned_tree")]
49    fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
50        self.span
51    }
52}
53
54#[cfg(feature = "parser")]
55impl crate::utils::DummyInit for CounterOnPermanentReplacement {
56    fn dummy_init() -> Self {
57        Self {
58            source_ref: crate::utils::dummy(),
59            put_counters: crate::utils::dummy(),
60            #[cfg(feature = "spanned_tree")]
61            span: Default::default(),
62        }
63    }
64}