Skip to main content

manabrew_engine/zone/
zone_type.rs

1//! ZoneType — game zone types.
2//!
3//! Mirrors Java's `ZoneType.java`.
4//! The core enum lives in `forge_foundation::ZoneType`; this module
5//! re-exports it and adds zone-module-specific helper functions.
6
7pub use forge_foundation::ZoneType;
8
9/// Whether this zone holds hidden information.
10/// Mirrors Java's `ZoneType.isHidden()`.
11pub fn is_hidden(zone: ZoneType) -> bool {
12    zone.is_hidden()
13}
14
15/// Whether this zone holds known (public) information.
16/// Mirrors Java's `ZoneType.isKnown()`.
17pub fn is_known(zone: ZoneType) -> bool {
18    zone.is_known()
19}
20
21/// Parse a zone type from a string.
22/// Mirrors Java's `ZoneType.smartValueOf()`.
23pub fn smart_value_of(value: &str) -> Option<ZoneType> {
24    ZoneType::from_str_compat(value)
25}
26
27/// Parse a comma/space-separated list of zone types.
28/// "All" returns the standard set of zones.
29/// Mirrors Java's `ZoneType.listValueOf()`.
30pub fn list_value_of(values: &str) -> Vec<ZoneType> {
31    if values.trim().eq_ignore_ascii_case("All") {
32        return vec![
33            ZoneType::Battlefield,
34            ZoneType::Hand,
35            ZoneType::Graveyard,
36            ZoneType::Exile,
37            ZoneType::Stack,
38            ZoneType::Library,
39            ZoneType::Command,
40        ];
41    }
42    let mut result = Vec::new();
43    for s in values.split([',', ' ']) {
44        let s = s.trim();
45        if s.is_empty() {
46            continue;
47        }
48        if let Some(zt) = smart_value_of(s) {
49            result.push(zt);
50        }
51    }
52    result
53}
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn smart_value_of_test() {
61        assert_eq!(smart_value_of("Battlefield"), Some(ZoneType::Battlefield));
62        assert_eq!(smart_value_of("Hand"), Some(ZoneType::Hand));
63        assert_eq!(smart_value_of("All"), None);
64    }
65
66    #[test]
67    fn list_value_of_test() {
68        let result = list_value_of("Hand,Graveyard");
69        assert_eq!(result, vec![ZoneType::Hand, ZoneType::Graveyard]);
70    }
71
72    #[test]
73    fn list_value_of_all() {
74        let result = list_value_of("All");
75        assert_eq!(result.len(), 7);
76        assert!(result.contains(&ZoneType::Battlefield));
77    }
78}