chiark / gitweb /
refactor: drop PieceRenderInstructions from Piece, etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Feb 2021 13:10:33 +0000 (13:10 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 28 Feb 2021 13:10:33 +0000 (13:10 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otterlib.rs
src/gamestate.rs
src/hand.rs
src/hidden.rs
src/pieces.rs
src/shapelib.rs

index a4200693af6a7ab90f656ebdbfead77a6e3b6c94..1af8ab79c8a27204231924a22c5d6eda8fe98cf0 100644 (file)
@@ -132,14 +132,8 @@ fn preview(items: Vec<ItemForOutput>) {
     println!(r#"<th align="left"><kbd>{}</kbd></th>"#,
              Html::from_txt(&spec.item).0);
     println!(r#"<th align="left">{}</th>"#,
-             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<ItemForOutput>) {
              });
       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<ItemForOutput>) {
                  &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!("{}</svg>", html.0);
       }
       println!("</td>");
index 9b702ae7872209937c5752837bd7a5b1653f03d2..d977dfa51bc5ded8acb1e3fe143cbcd393140d61 100644 (file)
@@ -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<FaceId>, gpc: &GPiece)
-                   -> Result<Html,IE>;
+  fn describe_html(&self, gpc: &GPiece) -> Result<Html,IE>;
 
   fn delete_hook(&self, _p: &GPiece, _gs: &mut GameState)
                  -> ExecuteGameChangeUpdates { 
@@ -386,7 +385,7 @@ impl PieceRenderInstructions {
     write!(&mut defs.0,
            r##"<g id="piece{}" transform="{}" data-dragraise="{}">"##,
            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##"</g>"##)?;
     write!(&mut defs.0,
            r##"<path id="surround{}" d="{}"/>"##,
@@ -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)]
index 060077d32d208e719a01fb3621c2c6c935be6ce4..4235901208f84647397fd0cb7881c1613e2ad847 100644 (file)
@@ -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::<HandState>()?;
         if let Some(owned) = &xdata.owner;
@@ -99,7 +98,7 @@ impl PieceTrait for Hand {
   }
 
   #[throws(IE)]
-  fn describe_html(&self, _face: Option<FaceId>, gpc: &GPiece) -> Html {
+  fn describe_html(&self, gpc: &GPiece) -> Html {
     let xdata = gpc.xdata.get()?;
     self.describe_html_inner(xdata)
   }
index 1e2b1b42dc4841cf640e46c5c17eae973473b106..f45b9fbf4a6d93fb28e3c5dd3d2a3447ce5d1880 100644 (file)
@@ -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 => {
index d03beacf6882eaafeb570d0a5e46bdf2e63a5cee..9b7a05be53fbdac677d1ef58a82680579f401758 100644 (file)
@@ -128,14 +128,13 @@ impl<Desc, Outl> OutlineTrait for GenericSimpleShape<Desc, Outl>
 #[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<FaceId>, _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<Desc, Outl> GenericSimpleShape<Desc, Outl>
 
   #[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)
index 45b084b43aa9c9aaf6368584b4013f273bce25a6..c1b4a8b5333a2beccfb3f76491097c9ba9434909 100644 (file)
@@ -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##"<g transform="scale({} {}) translate({} {})">{}</g>"##,
@@ -163,11 +162,8 @@ impl PieceTrait for Item {
            svgd.0)?;
   }
   #[throws(IE)]
-  fn describe_html(&self, face: Option<FaceId>, _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);
     }