From: Ian Jackson Date: Sun, 28 Feb 2021 13:10:33 +0000 (+0000) Subject: refactor: drop PieceRenderInstructions from Piece, etc. X-Git-Tag: otter-0.4.0~283 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0e2f5260bbc40f44dd053ee046c7db2775c1e8a5;p=otter.git refactor: drop PieceRenderInstructions from Piece, etc. Signed-off-by: Ian Jackson --- diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index a4200693..1af8ab79 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -132,14 +132,8 @@ fn preview(items: Vec) { println!(r#"{}"#, Html::from_txt(&spec.item).0); println!(r#"{}"#, - pc.describe_html(None, &gpc_dummy)?.0); + pc.describe_html(&gpc_dummy)?.0); let only1 = s.face_cols() == 1; - let getpri = |face: FaceId| PieceRenderInstructions { - id: default(), - angle: VisiblePieceAngle(default()), - face, - occluded: PriOccluded::Visible, - }; for facecol in 0..(if only1 { 1 } else { max_facecols }) { let (face, inseveral) = if s.want_several() { @@ -160,7 +154,6 @@ fn preview(items: Vec) { }); println!(r#">"#); if face < (pc.nfaces() as usize) { - let pri = getpri(face.into()); let viewport = [bbox[0].clone(), size.clone()] .iter().cloned() @@ -180,7 +173,8 @@ fn preview(items: Vec) { &surround.0, &dasharray.0, HELD_SURROUND_COLOUR); } let mut html = Html("".into()); - pc.svg_piece(&mut html, &gpc_dummy, &pri)?; + let gpc = GPiece { face: face.into(), ..GPiece::dummy() }; + pc.svg_piece(&mut html, &gpc, default())?; println!("{}", html.0); } println!(""); diff --git a/src/gamestate.rs b/src/gamestate.rs index 9b702ae7..d977dfa5 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -153,10 +153,9 @@ pub trait PieceTrait: OutlineTrait + Send + Debug { // #[throws] doesn't work here - fehler #todo fn svg_piece(&self, f: &mut Html, gpc: &GPiece, - pri: &PieceRenderInstructions) -> Result<(),IE>; + id: VisiblePieceId) -> Result<(),IE>; - fn describe_html(&self, face: Option, gpc: &GPiece) - -> Result; + fn describe_html(&self, gpc: &GPiece) -> Result; fn delete_hook(&self, _p: &GPiece, _gs: &mut GameState) -> ExecuteGameChangeUpdates { @@ -386,7 +385,7 @@ impl PieceRenderInstructions { write!(&mut defs.0, r##""##, pri.id, &transform.0, dragraise)?; - p.svg_piece(&mut defs, gpc, pri)?; + p.svg_piece(&mut defs, gpc, pri.id)?; write!(&mut defs.0, r##""##)?; write!(&mut defs.0, r##""##, @@ -415,7 +414,7 @@ impl PieceRenderInstructions { #[throws(IE)] pub fn describe_fallible(&self, gpc: &GPiece, p: &dyn PieceTrait) -> Html { - p.describe_html(Some(gpc.face), gpc)? + p.describe_html(gpc)? } #[throws(InternalError)] diff --git a/src/hand.rs b/src/hand.rs index 060077d3..42359012 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -85,9 +85,8 @@ impl Hand { impl PieceTrait for Hand { fn nfaces(&self) -> RawFaceId { 1 } #[throws(IE)] - fn svg_piece(&self, f: &mut Html, gpc: &GPiece, - pri: &PieceRenderInstructions) { - self.shape.svg_piece_raw(f, pri, &mut |f: &mut String| { + fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _vpid: VisiblePieceId) { + self.shape.svg_piece_raw(f, gpc.face, &mut |f: &mut String| { if_chain!{ if let Some(xdata) = gpc.xdata.get::()?; if let Some(owned) = &xdata.owner; @@ -99,7 +98,7 @@ impl PieceTrait for Hand { } #[throws(IE)] - fn describe_html(&self, _face: Option, gpc: &GPiece) -> Html { + fn describe_html(&self, gpc: &GPiece) -> Html { let xdata = gpc.xdata.get()?; self.describe_html_inner(xdata) } diff --git a/src/hidden.rs b/src/hidden.rs index 1e2b1b42..f45b9fbf 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -336,7 +336,7 @@ fn recalculate_occultation_general< let bad = || internal_error_bydebug(&("missing", opiece, h.occid)); let oipc = ipieces.get(opiece).ok_or_else(bad)?; let ogpc = gpieces.get(opiece).ok_or_else(bad)?; - Ok::<_,IE>(oipc.describe_html(None, ogpc)?) + Ok::<_,IE>(oipc.describe_html(ogpc)?) }; let most_obscure = most_obscure.unwrap_or(&OccK::Visible); // no players! @@ -353,8 +353,8 @@ fn recalculate_occultation_general< log_visible } OccK::Scrambled | OccK::Displaced{..} => { - let face = ipc.nfaces() - 1; // xxx use other thing entirely - let show = ipc.describe_html(Some(face.into()), gpc)?; + let _face = ipc.nfaces() - 1; // xxx use other thing entirely + let show = ipc.describe_html(gpc)?; call_log_callback(Some(&show))? }, OccK::Invisible => { diff --git a/src/pieces.rs b/src/pieces.rs index d03beacf..9b7a05be 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -128,14 +128,13 @@ impl OutlineTrait for GenericSimpleShape #[typetag::serde] impl PieceTrait for SimpleShape { #[throws(IE)] - fn svg_piece(&self, f: &mut Html, _gpc: &GPiece, - pri: &PieceRenderInstructions) { - self.svg_piece_raw(f, pri, &mut |_|Ok(()))?; + fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _vpid: VisiblePieceId) { + self.svg_piece_raw(f, gpc.face, &mut |_|Ok(()))?; } #[throws(IE)] - fn describe_html(&self, face: Option, _gpc: &GPiece) -> Html { + fn describe_html(&self, gpc: &GPiece) -> Html { Html(if_chain! { - if let Some(face) = face; + if let face = gpc.face; if let Some(colour) = self.colours.get(face); then { format!("a {} {}", colour.0, self.desc.0) } else { format!("a {}", self.desc.0) } @@ -198,12 +197,12 @@ impl GenericSimpleShape #[throws(IE)] pub fn svg_piece_raw( - &self, f: &mut Html, pri: &PieceRenderInstructions, + &self, f: &mut Html, face: FaceId, stroke_attrs_hook: &mut dyn FnMut(&mut String) -> Result<(),IE>, ) { let f = &mut f.0; let ef = |f: &mut String, cmap: &ColourMap, attrname: &str, otherwise| { - if let Some(colour) = cmap.get(pri.face) { + if let Some(colour) = cmap.get(face) { write!(f, r##" {}="{}""##, attrname, colour.0) } else { write!(f, "{}", otherwise) diff --git a/src/shapelib.rs b/src/shapelib.rs index 45b084b4..c1b4a8b5 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -153,9 +153,8 @@ impl PieceTrait for Item { fn nfaces(&self) -> RawFaceId { self.faces.len().try_into().unwrap() } #[throws(IE)] - fn svg_piece(&self, f: &mut Html, _gpc: &GPiece, - pri: &PieceRenderInstructions) { - let face = &self.faces[pri.face]; + fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _vpid: VisiblePieceId) { + let face = &self.faces[gpc.face]; let svgd = &self.svgs[face.svg]; write!(&mut f.0, r##"{}"##, @@ -163,11 +162,8 @@ impl PieceTrait for Item { svgd.0)?; } #[throws(IE)] - fn describe_html(&self, face: Option, _gpc: &GPiece) -> Html { - self.descs[ match face { - Some(face) => self.faces[face].desc, - None => self.desc_hidden, - }].clone() + fn describe_html(&self, gpc: &GPiece) -> Html { + self.descs[ self.faces[gpc.face].desc ].clone() } fn itemname(&self) -> &str { &self.itemname } @@ -264,7 +260,7 @@ impl Contents { let ier = ItemEnquiryData { itemname: k.clone(), f0bbox, - f0desc: loaded.describe_html(Some(default()), &GPiece::dummy())?, + f0desc: loaded.describe_html(&GPiece::dummy())?, }; out.push(ier); }