chiark / gitweb /
Plumb ShowUnocculted through to nfaces
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 15 Mar 2021 18:35:46 +0000 (18:35 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 15 Mar 2021 18:35:46 +0000 (18:35 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
daemon/cmdlistener.rs
src/bin/otterlib.rs
src/gamestate.rs
src/hand.rs
src/hidden.rs
src/pcrender.rs
src/pieces.rs
src/shapelib.rs

index 03acd0d9cfad89d12b566b6753302525dc21f22b..c6939bb39ce26e787f91fa00281ab150bf84f7ff 100644 (file)
@@ -488,7 +488,7 @@ api_route!{
         let _: Void = match (self.opname.as_str(), self.wrc) {
 
           ("flip", wrc@ WRC::UpdateSvg) => {
-            let nfaces = ipc.p.nfaces();
+            let nfaces = ipc.p.nfaces(y);
             let logents = log_did_to_piece(
               ioccults, &gs.occults, player, gpl, piece, gpc, ipc,
               "flipped"
index 9931141b1a01cb7b480d8b86f83807273021d915..435ceeb235f6b512dd290c5c2ff131f84988d43f 100644 (file)
@@ -658,6 +658,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
       let mut updates = Vec::with_capacity(count_len);
       let mut pos = pos.unwrap_or(DEFAULT_POS_START);
       let mut z = gs.max_z.clone_mut();
+      let not_occ = ShowUnocculted::new_visible();
       for piece_i in count {
         let PieceSpecLoaded { p, occultable } = info.load(piece_i as usize)?;
         let ilks = &mut ig.ioccults.ilks;
@@ -665,7 +666,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
           ilks.insert(ilkname, OccultIlkData { p_occ })
         });
         let face = face.unwrap_or_default();
-        if p.nfaces() <= face.into() {
+        if p.nfaces(not_occ) <= face.into() {
           throw!(SpecError::FaceNotFound);
         }
         let gpc = GPiece {
index ccbd406eae87cc26f1edb98ea5d32dbebedfca3d..674bd6dbe5dcc70f0cc51640446252a4606fa75b 100644 (file)
@@ -83,8 +83,8 @@ fn preview(items: Vec<ItemForOutput>) {
     fn want_several(&self) -> bool {
       self.size[0] < 20.0
     }
-    fn face_cols(&self) -> usize {
-      usize::from(self.p.nfaces())
+    fn face_cols(&self, unocc_ok: ShowUnocculted) -> usize {
+      usize::from(self.p.nfaces(unocc_ok))
         * if self.want_several() { SEVERAL } else { 1 }
     }
   }
@@ -119,7 +119,9 @@ fn preview(items: Vec<ItemForOutput>) {
   // clones as a bodge for https://github.com/rust-lang/rust/issues/34162
   pieces.sort_by_key(|p| (p.spec.item.clone(), p.spec.lib.clone()));
                      
-  let max_facecols = pieces.iter().map(|s| s.face_cols()).max().unwrap_or(1);
+  let max_facecols = pieces.iter().map(
+    |s| s.face_cols(unocc_ok)
+  ).max().unwrap_or(1);
   let max_uos = pieces.iter().map(|s| s.uos.len()).max().unwrap_or(0);
 
   println!("{}", &HTML_PRELUDE);
@@ -133,7 +135,7 @@ fn preview(items: Vec<ItemForOutput>) {
              Html::from_txt(&spec.item).0);
     println!(r#"<th align="left">{}</th>"#,
              p.describe_html(&GPiece::dummy())?.0);
-    let only1 = s.face_cols() == 1;
+    let only1 = s.face_cols(unocc_ok) == 1;
 
     for facecol in 0..(if only1 { 1 } else { max_facecols }) {
       let (face, inseveral) = if s.want_several() {
@@ -153,7 +155,7 @@ fn preview(items: Vec<ItemForOutput>) {
                _ => panic!(),
              });
       println!(r#">"#);
-      if face < (p.nfaces() as usize) {
+      if face < (p.nfaces(unocc_ok) as usize) {
         let viewport =
           [bbox[0].clone(), size.clone()]
           .iter().cloned()
index ec9836f5f82eca5732f414d6430cc0cbe983662e..3c84bccb1c88d8f5f123f673c1e10a549711d0c5 100644 (file)
@@ -130,7 +130,7 @@ pub trait PieceTrait: OutlineTrait + Send + Debug + 'static {
   /// by convention, occult face is nfaces-1
   // xxx this is no good, we need a central definition of the occult
   // face to avoid weird behaviour with buggy gamespecs
-  fn nfaces(&self) -> RawFaceId;
+  fn nfaces(&self, y: ShowUnocculted) -> RawFaceId;
 
   #[throws(InternalError)]
   fn add_ui_operations(&self, _upd: &mut Vec<UoDescription>,
index 3462e598582a89e0a8efd315dc67ca7611c6b76f..f6a052ea104750e59135e08103f960a9b0ca9901 100644 (file)
@@ -85,7 +85,7 @@ impl Hand {
 
 #[typetag::serde]
 impl PieceTrait for Hand {
-  fn nfaces(&self) -> RawFaceId { 1 }
+  fn nfaces(&self, _: ShowUnocculted) -> RawFaceId { 1 }
   #[throws(IE)]
   fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
                _vpid: VisiblePieceId, _: ShowUnocculted) {
index 7973891e23432a6f3228ceb3abec3203066ccd0e..a59d5c177faf467afdbd14bde05e6e05ae605704 100644 (file)
@@ -427,7 +427,6 @@ fn recalculate_occultation_general<
         log_visible
       }
       OccK::Scrambled | OccK::Displaced{..} => {
-        let _face = ipc.p.nfaces() - 1; // xxx use other thing entirely
         let show = ipc.p.describe_html(gpc)?;
         call_log_callback(Some(&show))?
       },
index 24491e5cf7b0196583ca3fea3eda9c6e18f9c2df..d4377d3a487647579a92b95e7d6a16f5880bb8ac 100644 (file)
@@ -199,7 +199,7 @@ impl PieceRenderInstructions {
     type WRC = WhatResponseToClientOp;
 
     let mut out = vec![];
-    if p.nfaces() > 1 {
+    if p.nfaces(y) > 1 {
       out.push(UoDescription {
         wrc: WRC::UpdateSvg,
         kind: UoKind::Global,
index 1ef485723593aa32d97b24c78772f1b5beccc1f4..fc1cceaa8e8eb78ea1cd5bb4360106cdac1a74ba 100644 (file)
@@ -142,7 +142,9 @@ impl PieceTrait for SimpleShape {
       else { format!("a {}", self.desc.0) }
     })
   }
-  fn nfaces(&self) -> RawFaceId { self.count_faces().try_into().unwrap() }
+  fn nfaces(&self, _: ShowUnocculted) -> RawFaceId {
+    self.count_faces().try_into().unwrap()
+  }
 
   fn itemname(&self, y: ShowUnocculted) -> &str { self.itemname(y) }
 }
index ab275b7ad10cd8bb8ef47e28e6e1cc100e88f6b1..3297528fe83afc7bb29fe61bfcc4f61c54d30044 100644 (file)
@@ -211,7 +211,9 @@ impl FaceTransform {
 
 #[typetag::serde(name="Lib")]
 impl PieceTrait for Item {
-  fn nfaces(&self) -> RawFaceId { self.faces.len().try_into().unwrap() }
+  fn nfaces(&self, _: ShowUnocculted) -> RawFaceId {
+    self.faces.len().try_into().unwrap()
+  }
 
   #[throws(IE)]
   fn svg_piece(&self, f: &mut Html, gpc: &GPiece,