chiark / gitweb /
hidden placement: Refactor to make a place to put things
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 11:45:44 +0000 (11:45 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 11:51:00 +0000 (11:51 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/hand.rs
src/hidden.rs

index f04c7c24bb33d8842d5c39bd8e54643380ec7e33..dd3b8a737865efca1b42b2490375c4d4b9f8f255 100644 (file)
@@ -207,10 +207,11 @@ impl PieceTrait for Hand {
         let (region, views) = (||{
           dbgc!("claiming region");
           let region = self.shape.outline.region(gpc.pos)?;
+          let displace = OccDisplacement::Rect { area: region };
           let views = OwnerOccultationView {
             owner: player,
             owner_view: OccK::Visible,
-            defview: OccK::Displaced((region, gpc.zlevel.z.clone())),
+            defview: OccK::Displaced((displace, gpc.zlevel.z.clone())),
           }.views()?;
           dbgc!("claiming got region", &region, &views);
           Ok::<_,IE>((region, views))
index 64af9af0b6a397a575469bbe277ecb5357c787a6..855a0db1d2abcfcc7cf6a323f5b04b542823b7d0 100644 (file)
@@ -68,7 +68,15 @@ pub enum OccultationKindGeneral<D> {
   Displaced(D),
   Invisible,
 }
-pub type OccultationKind = OccultationKindGeneral<(Area, ZCoord)>;
+pub type OccultationKind = OccultationKindGeneral<(OccDisplacement,ZCoord)>;
+
+#[derive(Clone,Debug,Serialize,Deserialize)]
+#[derive(Eq,PartialEq,Hash)]
+pub enum OccDisplacement {
+  Rect {
+    area: Area,
+  },
+}
 
 impl PieceOccult {
   pub fn is_active(&self) -> bool { self.active.is_some() }
@@ -199,11 +207,10 @@ pub fn piece_pri(
     if let Some(zg) = occultation.notch_zg(notch);
     then {
       occultation.views.get_kind(player)
-        .map_displaced(|(area, z)| {
-          let x: Coord = (notch.index() % 3).try_into().unwrap(); // xxx
-          let pos = (area.0[0] + PosC([x*4, 0])).unwrap(); // xxx
-          let pos = (pos + PosC([5,5])).unwrap(); // xxx
-          let z = z.plus_offset(notch.into())
+        .map_displaced(|(displace, z)| {
+          let notch: NotchNumber = notch.into();
+          let pos = displace.place(notch);
+          let z = z.plus_offset(notch)
             .unwrap_or_else(|e| { // eek!
               error!("z coordinate overflow ({:?}), bodging! {:?} {:?}",
                      e, piece, &z);
@@ -231,6 +238,20 @@ pub fn piece_pri(
   Some(PieceRenderInstructions { vpid, occulted })
 }
 
+impl OccDisplacement {
+  fn place(&self, notch: NotchNumber) -> Pos {
+    use OccDisplacement as OD;
+    match self {
+      OD::Rect{area} => {
+        let x: Coord = (notch % 3).try_into().unwrap(); // xxx
+        let pos = (area.0[0] + PosC([x*4, 0])).unwrap(); // xxx
+        let pos = (pos + PosC([5,5])).unwrap(); // xxx
+        pos
+      },
+    }
+  }
+}
+
 impl ShowUnocculted {
   /// override
   pub const fn new_visible() -> ShowUnocculted {