From: Ian Jackson Date: Mon, 15 Mar 2021 18:35:46 +0000 (+0000) Subject: Plumb ShowUnocculted through to nfaces X-Git-Tag: otter-0.4.0~26 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9806fb3bfa5e7920b5398caaf512bd14e5e31dcd;p=otter.git Plumb ShowUnocculted through to nfaces Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index 03acd0d9..c6939bb3 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -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" diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 9931141b..435ceeb2 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -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 { diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index ccbd406e..674bd6db 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -83,8 +83,8 @@ fn preview(items: Vec) { 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) { // 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) { Html::from_txt(&spec.item).0); println!(r#"{}"#, 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) { _ => 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() diff --git a/src/gamestate.rs b/src/gamestate.rs index ec9836f5..3c84bccb 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -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, diff --git a/src/hand.rs b/src/hand.rs index 3462e598..f6a052ea 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -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) { diff --git a/src/hidden.rs b/src/hidden.rs index 7973891e..a59d5c17 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -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))? }, diff --git a/src/pcrender.rs b/src/pcrender.rs index 24491e5c..d4377d3a 100644 --- a/src/pcrender.rs +++ b/src/pcrender.rs @@ -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, diff --git a/src/pieces.rs b/src/pieces.rs index 1ef48572..fc1cceaa 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -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) } } diff --git a/src/shapelib.rs b/src/shapelib.rs index ab275b7a..3297528f 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -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,