boseiju/ability_tree/card_layout/
saga_layout.rs1#[derive(Debug, Clone)]
2#[derive(serde::Serialize, serde::Deserialize)]
3pub struct SagaLayout {
4 pub mana_cost: Option<crate::ability_tree::terminals::ManaCost>,
5 pub card_type: crate::ability_tree::type_line::TypeLine,
6 pub chapters: crate::utils::HeapArrayVec<SagaChapter, 4>,
7 #[cfg(feature = "spanned_tree")]
8 pub span: crate::ability_tree::span::TreeSpan,
9}
10
11#[derive(Debug, Clone)]
12#[derive(serde::Serialize, serde::Deserialize)]
13pub struct SagaChapter {
14 chapter: usize,
15 effect: crate::ability_tree::ability::spell::SpellAbility,
16}
17
18impl super::LayoutImpl for SagaLayout {
19 fn card_types(&self) -> arrayvec::ArrayVec<mtg_data::CardType, 4> {
20 self.card_type.card_types()
21 }
22
23 fn mana_value(&self) -> usize {
24 self.mana_cost.as_ref().map(|cost| cost.mana_value()).unwrap_or(0)
25 }
26
27 #[cfg(feature = "parser")]
28 fn from_raw_card(raw_card: &mtg_cardbase::Card) -> Result<Self, String> {
29 use crate::lexer::IntoToken;
36 let chapters = crate::utils::HeapArrayVec::new();
37
38 let type_line_span = crate::lexer::Span {
42 start: 0,
43 length: raw_card.type_line.len(),
44 text: raw_card.type_line.as_str(),
45 };
46
47 Ok(SagaLayout {
48 mana_cost: match raw_card.mana_cost.as_ref() {
49 Some(mana_cost) => {
50 use crate::lexer::IntoToken;
51
52 let mana_cost_span = crate::lexer::Span {
53 start: 0,
54 length: mana_cost.len(),
55 text: mana_cost,
56 };
57 Some(
58 crate::ability_tree::terminals::ManaCost::try_from_span(&mana_cost_span)
59 .ok_or_else(|| format!("Failed to parse mana cost from: {mana_cost}"))?,
60 )
61 }
62 None => None,
63 },
64
65 card_type: crate::ability_tree::type_line::TypeLine::try_from_span(&type_line_span)
66 .ok_or_else(|| format!("Failed to parse card type: {}", raw_card.type_line))?,
67 chapters,
68 #[cfg(feature = "spanned_tree")]
69 span: Default::default(),
70 })
71 }
72
73 fn layout_debug_display<W: std::io::Write>(&self, _output: &mut W) -> std::io::Result<()> {
74 unimplemented!()
75 }
76}