chiark / gitweb /
hidden: enforce via types that Scrambled is the only view
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 26 Mar 2021 18:19:01 +0000 (18:19 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 26 Mar 2021 18:19:01 +0000 (18:19 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/hand.rs
src/hidden.rs
src/prelude.rs

index 27b3825ecc167c6d143a3a489a337b041332af45..eeedbd7b5fab32be36a2ea457bb168d5ec93cca1 100644 (file)
@@ -193,8 +193,8 @@ impl PieceTrait for Hand {
           let displace = OccDisplacement::Rect { rect };
           let views = OwnerOccultationView {
             owner: player,
-            owner_view: OccK::Visible,
-            defview: OccK::Displaced((displace, gpc.zlevel.z.clone())),
+            owner_view: OccKA::Visible,
+            defview: OccKA::Displaced((displace, gpc.zlevel.z.clone())),
           }.views()?;
           dbgc!("claiming got region", &region, &views);
           Ok::<_,IE>((region, views))
index aef082e16f5104efd309da87ddf8a9f6beb215eb..23372f3315d66a6009ab4d59df286b902bcd98a9 100644 (file)
@@ -72,6 +72,25 @@ pub enum OccultationKindGeneral<D> {
 }
 pub type OccultationKind = OccultationKindGeneral<(OccDisplacement,ZCoord)>;
 
+#[derive(Clone,Debug)]
+#[derive(Eq,PartialEq,Hash)]
+pub enum OccultationKindAlwaysOk {
+  Visible,
+  // Scrambled is only allowed as the only view; enforced by our
+  // OccultationViewDef trait impls
+  Displaced((OccDisplacement,ZCoord)),
+  Invisible,
+}
+impl From<OccultationKindAlwaysOk> for OccultationKind {
+  fn from(i: OccultationKindAlwaysOk) -> OccultationKind {
+    match i {
+      OccKA::Visible      => OccKG::Visible,
+      OccKA::Displaced(d) => OccKG::Displaced(d),
+      OccKA::Invisible    => OccKG::Invisible,
+    }
+  }
+}
+
 #[derive(Clone,Debug,Serialize,Deserialize)]
 #[derive(Eq,PartialEq,Hash)]
 pub enum OccDisplacement {
@@ -788,9 +807,9 @@ pub struct UniformOccultationView(
 );
 #[derive(Debug,Clone)]
 pub struct OwnerOccultationView {
-  pub defview: OccultationKind,
+  pub defview: OccultationKindAlwaysOk,
   pub owner: PlayerId,
-  pub owner_view: OccultationKind,
+  pub owner_view: OccultationKindAlwaysOk,
 }
 
 pub trait OccultationViewDef {
@@ -806,10 +825,10 @@ impl OccultationViewDef for UniformOccultationView {
 impl OccultationViewDef for OwnerOccultationView {
   #[throws(IE)]
   fn views(self) -> OccultationViews { OccultationViews {
-    defview: self.defview,
+    defview: self.defview.into(),
     views: vec![OccultView {
       players: vec![self.owner],
-      occult: self.owner_view,
+      occult: self.owner_view.into(),
     }]
   } }
 }
index acaddafa26f36d261bfc8e040b4b8ec6e03ab56a..8d98bb88403c9752f2913e1aba10f8a5656958b8 100644 (file)
@@ -180,6 +180,7 @@ pub type SpE = SpecError;
 // hidden.rs
 pub type OccK = OccultationKind;
 pub use OccultationKindGeneral as OccKG;
+pub use OccultationKindAlwaysOk as OccKA;
 
 // pcrender.rs
 pub use PriOccultedGeneral as PriOG;