boseiju/ability_tree/event/
put_counter_on_permanent_event.rs1use super::*;
2use crate::ability_tree::AbilityTreeNode;
3use crate::ability_tree::MAX_CHILDREN_PER_NODE;
4
5#[derive(serde::Serialize, serde::Deserialize)]
7#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct PutCounterOnPermanentEvent {
9 pub source: source::EventSource,
10 pub quantity: crate::ability_tree::number::Number,
11 pub on_permanent: crate::ability_tree::object::ObjectReference,
12 pub counter_kind: Option<crate::ability_tree::terminals::Counter>,
13 #[cfg(feature = "spanned_tree")]
14 pub span: crate::ability_tree::span::TreeSpan,
15}
16
17impl crate::ability_tree::AbilityTreeNode for PutCounterOnPermanentEvent {
18 fn node_id(&self) -> usize {
19 use idris::Idris;
20 crate::ability_tree::NodeKind::PutCounterOnPermanentEvent.id()
21 }
22
23 fn children(&self) -> arrayvec::ArrayVec<&dyn AbilityTreeNode, MAX_CHILDREN_PER_NODE> {
24 let mut children = arrayvec::ArrayVec::new_const();
25 children.push(&self.source as &dyn AbilityTreeNode);
26 children.push(&self.quantity as &dyn AbilityTreeNode);
27 children.push(&self.on_permanent as &dyn AbilityTreeNode);
28 match self.counter_kind.as_ref() {
29 Some(amount) => children.push(amount as &dyn AbilityTreeNode),
30 None => {
31 let dummy = crate::ability_tree::dummy_terminal::TreeNodeDummyTerminal::none_node();
32 children.push(dummy as &dyn AbilityTreeNode)
33 }
34 }
35 children
36 }
37
38 fn display(&self, out: &mut crate::utils::TreeFormatter<'_>) -> std::io::Result<()> {
39 use std::io::Write;
40 write!(out, "put counters on permanents")?;
41 out.push_inter_branch()?;
42 write!(out, "put counters source:")?;
43 out.push_final_branch()?;
44 self.source.display(out)?;
45 out.pop_branch();
46 out.next_inter_branch()?;
47 write!(out, "amount:")?;
48 out.push_final_branch()?;
49 self.quantity.display(out)?;
50 out.pop_branch();
51 out.next_inter_branch()?;
52 match self.counter_kind.as_ref() {
53 Some(counter) => counter.display(out)?,
54 None => write!(out, "any counter kind")?,
55 }
56 out.next_final_branch()?;
57 write!(out, "on permanent:")?;
58 out.push_final_branch()?;
59 self.on_permanent.display(out)?;
60 out.pop_branch();
61 out.pop_branch();
62
63 Ok(())
64 }
65
66 fn node_tag(&self) -> &'static str {
67 "put counters on permanent event"
68 }
69
70 #[cfg(feature = "spanned_tree")]
71 fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
72 self.span
73 }
74}
75
76#[cfg(feature = "parser")]
77impl crate::utils::DummyInit for PutCounterOnPermanentEvent {
78 fn dummy_init() -> Self {
79 Self {
80 source: crate::utils::dummy(),
81 quantity: crate::utils::dummy(),
82 on_permanent: crate::utils::dummy(),
83 counter_kind: crate::utils::dummy(),
84 #[cfg(feature = "spanned_tree")]
85 span: Default::default(),
86 }
87 }
88}