Skip to main content

manabrew_engine/keyword/
craft.rs

1//! Craft keyword implementation.
2//!
3//! Ported from Java's `Craft.java` in `forge/game/keyword/`.
4
5use super::keyword_instance::Keyword;
6use super::keyword_with_cost::KeywordWithCost;
7
8/// Craft keyword data.
9/// Pay cost, exile this artifact and other materials: Return transformed.
10#[derive(Debug, Clone)]
11pub struct Craft {
12    pub inner: KeywordWithCost,
13    /// The mana portion of the cost.
14    pub mana_string: String,
15    /// Description of what to exile.
16    pub exile_string: String,
17}
18
19impl Craft {
20    /// Create a new Craft keyword.
21    pub fn new(original: String) -> Self {
22        Self {
23            inner: KeywordWithCost::new(Keyword::Craft, original),
24            mana_string: "Mana?".to_string(),
25            exile_string: "Exile?".to_string(),
26        }
27    }
28
29    /// Parse the details string.
30    pub fn parse(&mut self, details: &str) {
31        let k: Vec<&str> = details.split(':').collect();
32        if !k.is_empty() {
33            self.inner.parse(k[0]);
34            self.mana_string = k[0].to_string();
35        }
36        if k.len() > 2 {
37            self.exile_string = format!(
38                "Exile {} from among permanents you control and/or cards in your graveyard",
39                k[2]
40            );
41        }
42    }
43
44    /// Format reminder text.
45    pub fn format_reminder_text(&self, reminder_text: &str) -> String {
46        let cost_desc = format!(
47            "{}, Exile this artifact, {}",
48            self.mana_string, self.exile_string
49        );
50        reminder_text.replace("%s", &cost_desc)
51    }
52
53    /// Get the display title.
54    pub fn get_title(&self) -> String {
55        self.inner.get_title()
56    }
57}