boseiju/ability_tree/zone/
owned_zone.rs

1use crate::ability_tree::AbilityTreeNode;
2use crate::ability_tree::MAX_CHILDREN_PER_NODE;
3
4/// A zone that is owned by a player: libraries, hands, graveyards.
5#[derive(serde::Serialize, serde::Deserialize)]
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
7pub struct OwnedZone {
8    pub zone: crate::ability_tree::zone::OwnableZone,
9    pub owner: crate::ability_tree::terminals::OwnerSpecifier,
10    #[cfg(feature = "spanned_tree")]
11    pub span: crate::ability_tree::span::TreeSpan,
12}
13
14impl AbilityTreeNode for OwnedZone {
15    fn node_id(&self) -> usize {
16        use idris::Idris;
17        crate::ability_tree::NodeKind::OwnedZone.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.zone as &dyn AbilityTreeNode);
23        children.push(&self.owner 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, "owned zone:")?;
30        out.push_inter_branch()?;
31        write!(out, "zone: ")?;
32        self.zone.display(out)?;
33        out.next_final_branch()?;
34        write!(out, "owner: ")?;
35        self.owner.display(out)?;
36        out.pop_branch();
37        Ok(())
38    }
39
40    fn node_tag(&self) -> &'static str {
41        "owned zone"
42    }
43
44    #[cfg(feature = "spanned_tree")]
45    fn node_span(&self) -> crate::ability_tree::span::TreeSpan {
46        self.span
47    }
48}
49
50impl idris::Idris for OwnedZone {
51    const COUNT: usize = 1;
52    fn id(&self) -> usize {
53        0
54    }
55    fn name_from_id(_: usize) -> &'static str {
56        "owned zone"
57    }
58}
59
60#[cfg(feature = "parser")]
61impl crate::utils::DummyInit for OwnedZone {
62    fn dummy_init() -> Self {
63        Self {
64            zone: crate::utils::dummy(),
65            owner: crate::utils::dummy(),
66            #[cfg(feature = "spanned_tree")]
67            span: Default::default(),
68        }
69    }
70}