boseiju/ability_tree/ability/statik/
cost_modification_effect.rs1use crate::ability_tree::AbilityTreeNode;
2use crate::ability_tree::MAX_CHILDREN_PER_NODE;
3
4#[derive(serde::Serialize, serde::Deserialize)]
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct CostModificationEffect {
8 pub applies_to: crate::ability_tree::object::ObjectReference,
9 pub modification: CostModification,
10 #[cfg(feature = "spanned_tree")]
11 pub span: crate::ability_tree::span::TreeSpan,
12}
13
14impl crate::ability_tree::AbilityTreeNode for CostModificationEffect {
15 fn node_id(&self) -> usize {
16 use idris::Idris;
17 crate::ability_tree::NodeKind::CostModificationEffect.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.applies_to as &dyn AbilityTreeNode);
23 children.push(&self.modification 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, "cost modification effect:")?;
30 out.push_inter_branch()?;
31 write!(out, "applies to:")?;
32 out.push_final_branch()?;
33 self.applies_to.display(out)?;
34 out.pop_branch();
35 out.next_final_branch()?;
36 self.modification.display(out)?;
37 out.pop_branch();
38 Ok(())
39 }
40
41 fn node_tag(&self) -> &'static str {
42 "cost modification effect"
43 }
44
45 #[cfg(feature = "spanned_tree")]
46 fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
47 self.span
48 }
49}
50
51#[cfg(feature = "parser")]
52impl crate::utils::DummyInit for CostModificationEffect {
53 fn dummy_init() -> Self {
54 Self {
55 applies_to: crate::utils::dummy(),
56 modification: crate::utils::dummy(),
57 #[cfg(feature = "spanned_tree")]
58 span: Default::default(),
59 }
60 }
61}
62
63#[derive(serde::Serialize, serde::Deserialize)]
65#[derive(Debug, Clone, PartialEq, Eq)]
66pub enum CostModification {
67 More(CostModificationCostMore),
68 Less(CostModificationCostLess),
69 Set(CostModificationCostSet),
70}
71
72#[cfg(feature = "spanned_tree")]
73impl CostModification {
74 pub fn span(&self) -> crate::ability_tree::span::TreeSpan {
75 match self {
76 Self::More(child) => child.span,
77 Self::Less(child) => child.span,
78 Self::Set(child) => child.span,
79 }
80 }
81}
82
83impl crate::ability_tree::AbilityTreeNode for CostModification {
84 fn node_id(&self) -> usize {
85 use idris::Idris;
86 crate::ability_tree::NodeKind::CostModification.id()
87 }
88
89 fn children(&self) -> arrayvec::ArrayVec<&dyn AbilityTreeNode, MAX_CHILDREN_PER_NODE> {
90 let mut children = arrayvec::ArrayVec::new_const();
91 match self {
92 Self::More(child) => children.push(child as &dyn AbilityTreeNode),
93 Self::Less(child) => children.push(child as &dyn AbilityTreeNode),
94 Self::Set(child) => children.push(child as &dyn AbilityTreeNode),
95 }
96 children
97 }
98
99 fn display(&self, out: &mut crate::utils::TreeFormatter<'_>) -> std::io::Result<()> {
100 use std::io::Write;
101 write!(out, "cost modification effect:")?;
102 out.push_final_branch()?;
103 match self {
104 Self::More(child) => child.display(out)?,
105 Self::Less(child) => child.display(out)?,
106 Self::Set(child) => child.display(out)?,
107 }
108 out.pop_branch();
109 Ok(())
110 }
111
112 fn node_tag(&self) -> &'static str {
113 "cost modification"
114 }
115
116 #[cfg(feature = "spanned_tree")]
117 fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
118 match self {
119 Self::More(child) => child.node_span(),
120 Self::Less(child) => child.node_span(),
121 Self::Set(child) => child.node_span(),
122 }
123 }
124}
125
126#[cfg(feature = "parser")]
127impl crate::utils::DummyInit for CostModification {
128 fn dummy_init() -> Self {
129 Self::Less(crate::utils::dummy())
130 }
131}
132
133#[derive(serde::Serialize, serde::Deserialize)]
135#[derive(Debug, Clone, PartialEq, Eq)]
136pub struct CostModificationCostMore {
137 pub more: crate::ability_tree::terminals::ManaCost,
138 #[cfg(feature = "spanned_tree")]
139 pub span: crate::ability_tree::span::TreeSpan,
140}
141
142impl AbilityTreeNode for CostModificationCostMore {
143 fn node_id(&self) -> usize {
144 use idris::Idris;
145 crate::ability_tree::NodeKind::CostModificationCostMore.id()
146 }
147
148 fn children(&self) -> arrayvec::ArrayVec<&dyn AbilityTreeNode, MAX_CHILDREN_PER_NODE> {
149 let mut children = arrayvec::ArrayVec::new_const();
150 children.push(&self.more as &dyn AbilityTreeNode);
151 children
152 }
153
154 fn display(&self, out: &mut crate::utils::TreeFormatter<'_>) -> std::io::Result<()> {
155 use std::io::Write;
156 write!(out, "cost ")?;
157 self.more.display(out)?;
158 write!(out, " more to cast")?;
159 Ok(())
160 }
161
162 fn node_tag(&self) -> &'static str {
163 "cost modification: cost more"
164 }
165
166 #[cfg(feature = "spanned_tree")]
167 fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
168 self.span
169 }
170}
171
172#[cfg(feature = "parser")]
173impl crate::utils::DummyInit for CostModificationCostMore {
174 fn dummy_init() -> Self {
175 Self {
176 more: crate::utils::dummy(),
177 #[cfg(feature = "spanned_tree")]
178 span: Default::default(),
179 }
180 }
181}
182
183#[derive(serde::Serialize, serde::Deserialize)]
185#[derive(Debug, Clone, PartialEq, Eq)]
186pub struct CostModificationCostLess {
187 pub less: crate::ability_tree::terminals::ManaCost,
188 #[cfg(feature = "spanned_tree")]
189 pub span: crate::ability_tree::span::TreeSpan,
190}
191
192impl AbilityTreeNode for CostModificationCostLess {
193 fn node_id(&self) -> usize {
194 use idris::Idris;
195 crate::ability_tree::NodeKind::CostModificationCostLess.id()
196 }
197
198 fn children(&self) -> arrayvec::ArrayVec<&dyn AbilityTreeNode, MAX_CHILDREN_PER_NODE> {
199 let mut children = arrayvec::ArrayVec::new_const();
200 children.push(&self.less as &dyn AbilityTreeNode);
201 children
202 }
203
204 fn display(&self, out: &mut crate::utils::TreeFormatter<'_>) -> std::io::Result<()> {
205 use std::io::Write;
206 write!(out, "cost ")?;
207 self.less.display(out)?;
208 write!(out, " less to cast")?;
209 Ok(())
210 }
211
212 fn node_tag(&self) -> &'static str {
213 "cost modification: cost less"
214 }
215
216 #[cfg(feature = "spanned_tree")]
217 fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
218 self.span
219 }
220}
221
222#[cfg(feature = "parser")]
223impl crate::utils::DummyInit for CostModificationCostLess {
224 fn dummy_init() -> Self {
225 Self {
226 less: crate::utils::dummy(),
227 #[cfg(feature = "spanned_tree")]
228 span: Default::default(),
229 }
230 }
231}
232
233#[derive(serde::Serialize, serde::Deserialize)]
235#[derive(Debug, Clone, PartialEq, Eq)]
236pub struct CostModificationCostSet {
237 pub set: crate::ability_tree::terminals::ManaCost,
238 #[cfg(feature = "spanned_tree")]
239 pub span: crate::ability_tree::span::TreeSpan,
240}
241
242impl AbilityTreeNode for CostModificationCostSet {
243 fn node_id(&self) -> usize {
244 use idris::Idris;
245 crate::ability_tree::NodeKind::CostModificationCostSet.id()
246 }
247
248 fn children(&self) -> arrayvec::ArrayVec<&dyn AbilityTreeNode, MAX_CHILDREN_PER_NODE> {
249 let mut children = arrayvec::ArrayVec::new_const();
250 children.push(&self.set as &dyn AbilityTreeNode);
251 children
252 }
253
254 fn display(&self, out: &mut crate::utils::TreeFormatter<'_>) -> std::io::Result<()> {
255 use std::io::Write;
256 write!(out, "cost ")?;
257 self.set.display(out)?;
258 write!(out, " to cast")?;
259 Ok(())
260 }
261
262 fn node_tag(&self) -> &'static str {
263 "cost modification: set cost to"
264 }
265
266 #[cfg(feature = "spanned_tree")]
267 fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
268 self.span
269 }
270}
271
272#[cfg(feature = "parser")]
273impl crate::utils::DummyInit for CostModificationCostSet {
274 fn dummy_init() -> Self {
275 Self {
276 set: crate::utils::dummy(),
277 #[cfg(feature = "spanned_tree")]
278 span: Default::default(),
279 }
280 }
281}