boseiju/ability_tree/event/
replacement.rs1mod counter_on_permanent;
2mod source_ref;
3mod token_creation;
4
5pub use counter_on_permanent::CounterOnPermanentReplacement;
6pub use source_ref::EventSourceReference;
7pub use token_creation::TokenCreationReplacement;
8
9use crate::ability_tree::AbilityTreeNode;
10use crate::ability_tree::MAX_CHILDREN_PER_NODE;
11
12#[derive(serde::Serialize, serde::Deserialize)]
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub enum EventReplacement {
16 TokenCreation(TokenCreationReplacement),
17 CounterOnPermanent(CounterOnPermanentReplacement),
18}
19
20#[cfg(feature = "spanned_tree")]
21impl EventReplacement {
22 pub fn span(&self) -> crate::ability_tree::span::TreeSpan {
23 match self {
24 Self::TokenCreation(child) => child.span,
25 Self::CounterOnPermanent(child) => child.span,
26 }
27 }
28}
29
30impl crate::ability_tree::AbilityTreeNode for EventReplacement {
31 fn node_id(&self) -> usize {
32 use idris::Idris;
33 crate::ability_tree::NodeKind::EventReplacement.id()
34 }
35
36 fn children(&self) -> arrayvec::ArrayVec<&dyn AbilityTreeNode, MAX_CHILDREN_PER_NODE> {
37 let mut children = arrayvec::ArrayVec::new_const();
38 match self {
39 Self::TokenCreation(child) => children.push(child as &dyn AbilityTreeNode),
40 Self::CounterOnPermanent(child) => children.push(child as &dyn AbilityTreeNode),
41 }
42 children
43 }
44
45 fn display(&self, out: &mut crate::utils::TreeFormatter<'_>) -> std::io::Result<()> {
46 use std::io::Write;
47 write!(out, "event replacement")?;
48 out.push_final_branch()?;
49 match self {
50 Self::TokenCreation(child) => child.display(out)?,
51 Self::CounterOnPermanent(child) => child.display(out)?,
52 }
53 out.pop_branch();
54 Ok(())
55 }
56
57 fn node_tag(&self) -> &'static str {
58 "event replacement"
59 }
60
61 #[cfg(feature = "spanned_tree")]
62 fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
63 match self {
64 Self::TokenCreation(child) => child.node_span(),
65 Self::CounterOnPermanent(child) => child.node_span(),
66 }
67 }
68}
69
70#[cfg(feature = "parser")]
71impl crate::utils::DummyInit for EventReplacement {
72 fn dummy_init() -> Self {
73 Self::TokenCreation(crate::utils::dummy())
74 }
75}