chiark / gitweb /
plumb goccults through to describe_html
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 17:00:40 +0000 (17:00 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 17:00:40 +0000 (17:00 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
13 files changed:
daemon/api.rs
daemon/cmdlistener.rs
daemon/session.rs
src/bin/otterlib.rs
src/clock.rs
src/deck.rs
src/gamestate.rs
src/hand.rs
src/hidden.rs
src/pcrender.rs
src/pieces.rs
src/shapelib.rs
src/updates.rs

index 147c8b3887734f728aabe12772d2bef8445ce1e6..9f8ffb6287e4e762622e4ea6b5c30ea144c1453e 100644 (file)
@@ -273,7 +273,7 @@ api_route!{
     let gpc = gs.pieces.byid_mut(piece)?;
 
     let logents = log_did_to_piece(
-      ioccults,gpl,gpc,ipc,
+      ioccults,&gs.occults, gpl,gpc,ipc,
       "grasped"
     )?;
 
@@ -311,7 +311,7 @@ api_route!{
       let pri = piece_pri(ioccults, &gs.occults, player, gpl, piece, gpc, ipc)
         .ok_or(POE::PieceGone)?;
 
-      let pcs = pri.describe(ioccults, gpc, ipc).0;
+      let pcs = pri.describe(ioccults,&gs.occults, gpc, ipc).0;
 
       gpc.held = Some(player);
 
@@ -345,7 +345,7 @@ api_route!{
     let gpc = gs.pieces.byid_mut(piece).unwrap();
 
     let (logents, who_by) = log_did_to_piece_whoby(
-      ioccults,gpl,gpc,ipc,
+      ioccults,&gs.occults,gpl,gpc,ipc,
       "released"
     )?;
     let who_by = who_by.ok_or(POE::PieceGone)?;
@@ -453,7 +453,7 @@ api_route!{
     let gpc = gs.pieces.byid_mut(piece).unwrap();
     let gpl = gs.players.byid_mut(player).unwrap();
     let logents = log_did_to_piece(
-      ioccults,gpl,gpc,ipc,
+      ioccults,&gs.occults,gpl,gpc,ipc,
       "rotated"
     )?;
     gpc.angle = PieceAngle::Compass(self.0);
@@ -474,7 +474,7 @@ api_route!{
     let gpc = gs.pieces.byid_mut(piece).unwrap();
     let gpl = gs.players.byid_mut(player).unwrap();
     let logents = log_did_to_piece(
-      ioccults,gpl,gpc,ipc,
+      ioccults,&gs.occults,gpl,gpc,ipc,
       if gpc.pinned { "pinned" } else { "unpinned" },
     )?;
     gpc.forbid_involved_in_occultation()?;
@@ -521,7 +521,7 @@ api_route!{
           ("flip", wrc@ WRC::UpdateSvg) => {
             let nfaces = ipc.show(y).nfaces();
             let logents = log_did_to_piece(
-              ioccults,gpl,gpc,ipc,
+              ioccults,&gs.occults,gpl,gpc,ipc,
               "flipped"
             )?;
             gpc.face = ((RawFaceId::from(gpc.face) + 1) % nfaces).into();
index 5a832703190af708d6cb8b2d60bd597f70ede9f3..f5ee6e37d9c21f9c5eb401e6127316d88bce9c1b 100644 (file)
@@ -401,7 +401,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
               VisiblePieceId(piece.data())
             );
             let bbox = ipc.show(y).bbox_approx()?;
-            let desc_html = pri.describe(ioccults, gpc, ipc);
+            let desc_html = pri.describe(ioccults,&ig.gs.occults, gpc, ipc);
             Some(MgmtGamePieceVisibleInfo {
               pos, face, desc_html, bbox
             })
@@ -607,7 +607,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
       let gpc = gs.pieces.as_mut(modperm).remove(piece);
       let desc_html = if let Some(gpc) = &gpc {
         let pri = PieceRenderInstructions::new_visible(default());
-        pri.describe(ioccults, gpc, &ipc)
+        pri.describe(ioccults,&gs.occults, gpc, &ipc)
       } else {
         Html::lit("&lt;piece partially missing from game state!&gt;")
       };
index cd20d1a799dafa3f95626f0e4c846fcb6cf55b32..ce68500e738d99eea58d3c0279ae2a5eceae4e86 100644 (file)
@@ -127,7 +127,7 @@ fn session_inner(form: Json<SessionForm>,
 
       let defs = pri.make_defs(ioccults, &ig.gs, gpc, ipc)?;
       alldefs.push((pri.vpid, defs));
-      let desc = pri.describe(ioccults, &gpc, ipc);
+      let desc = pri.describe(ioccults,&ig.gs.occults, &gpc, ipc);
 
       let vangle = pri.angle(gpc).to_compass();
       let (pos, zlevel) = pri.pos_zlevel(gpc);
index 44c2d95148763f4209186181965607687879a549..b99c08745e9a5cc0b551583cee0b0bdfadeb8f78 100644 (file)
@@ -131,7 +131,7 @@ 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>"#,
-             p.describe_html(&GPiece::dummy())?.0);
+             p.describe_html(&GPiece::dummy(), &default())?.0);
     let only1 = s.face_cols() == 1;
 
     for facecol in 0..(if only1 { 1 } else { max_facecols }) {
index 6b62b2119e3db3b33c75d173358065810fd70c6f..91faf833b5643d4c3fb6b8d3edbd707d92ded1b3 100644 (file)
@@ -533,7 +533,7 @@ impl PieceTrait for Clock {
   }
 
   #[throws(IE)]
-  fn describe_html(&self, _gpc: &GPiece) -> Html {
+  fn describe_html(&self, _gpc: &GPiece, _goccults: &GameOccults) -> Html {
     Html::lit("the chess clock")
   }
 
@@ -681,7 +681,7 @@ impl PieceTrait for Clock {
                            held, &self.spec, ig)
       .map_err(|e| APOE::ReportViaResponse(e.into()))?;
 
-    let log = log_did_to_piece(ioccults, gpl, gpc, ipc, &did)
+    let log = log_did_to_piece(ioccults,&gs.occults, gpl, gpc, ipc, &did)
       .unwrap_or_else(|e| {
         error!("failed to log: {:?}", &e);
         vec![LogEntry { html: Html::lit("&lt;failed to log&gt;") }]
index 90fbc82f6cfba2801ef642ce625766739ce757c8..ea85d5ec44f48cd1f2ad0997b6ee6db7f3e9346f 100644 (file)
@@ -75,7 +75,7 @@ impl PieceTrait for Deck {
   }
 
   #[throws(IE)]
-  fn describe_html(&self, gpc: &GPiece) -> Html {
+  fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) -> Html {
     Html::lit(
       if self.enabled(gpc) { ENABLED_DESC } else { DISABLED_DESC }
     )
index 18536042b38c1a4c8821a3101380e28aca8356e5..93a7f822521e59dd4b0ef3a09aba70dc6bd54e24 100644 (file)
@@ -141,7 +141,8 @@ pub trait PieceTrait: OutlineTrait + Send + Debug + 'static {
   fn svg_piece(&self, f: &mut Html, gpc: &GPiece, gs: &GameState,
                id: VisiblePieceId) -> Result<(),IE>;
 
-  fn describe_html(&self, gpc: &GPiece) -> Result<Html,IE>;
+  fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults)
+                   -> Result<Html,IE>;
 
   #[throws(IE)]
   /// Piece is responsible for dealing with the possibility that they
index b83589190b6145e0a13ca58384df6bbbba0bac27..ef188fed66b56c22594df686b987ddc6054ad57c 100644 (file)
@@ -118,7 +118,7 @@ impl PieceTrait for Hand {
   }
 
   #[throws(IE)]
-  fn describe_html(&self, gpc: &GPiece) -> Html {
+  fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) -> Html {
     let xdata = gpc.xdata.get()?;
     self.describe_html_inner(xdata)
   }
index f9d00a6edd2f1c0b93aa16c17d37e7a5e890d9d1..ae65d16c4447d816316f5646e70e5ea736d3ee09 100644 (file)
@@ -535,7 +535,7 @@ fn recalculate_occultation_general<
       let ounocc = ogpc.fully_visible_to_everyone()
         .ok_or_else(||internal_error_bydebug(&(occulteds, &ogpc)))?;
       then {
-        Some(oipc.show(ounocc).describe_html(ogpc)?)
+        Some(oipc.show(ounocc).describe_html(ogpc, goccults)?)
       } else {
         None
       }
@@ -554,7 +554,7 @@ fn recalculate_occultation_general<
       Some(prioc@ PriOG::Visible(_)) |
       Some(prioc@ PriOG::Occulted) |
       Some(prioc@ PriOG::Displaced(..)) => {
-        let show = prioc.describe(ioccults, gpc, ipc);
+        let show = prioc.describe(ioccults, goccults, gpc, ipc);
         call_log_callback(&show)?
       },
       None => {
index 77e9a0f25fd9ce55cf67359197af117e2484b28e..2e5b016e9e663444b87d6bb96448526c72090909 100644 (file)
@@ -57,10 +57,10 @@ impl<P,Z> PriOccultedGeneral<P,Z> {
     }
   }
 
-  pub fn describe(&self, ioccults: &IOccults,
+  pub fn describe(&self, ioccults: &IOccults, goccults: &GameOccults,
                   gpc: &GPiece, ipc: &IPiece) -> Html
   {
-    self.describe_fallible(ioccults, gpc, ipc)
+    self.describe_fallible(ioccults, goccults, gpc, ipc)
       .unwrap_or_else(|e| {
         error!("error describing piece: {:?}", e);
         Html::lit("&lt;internal error describing piece&gt;")
@@ -69,9 +69,10 @@ impl<P,Z> PriOccultedGeneral<P,Z> {
 
   #[throws(IE)]
   pub fn describe_fallible(&self, ioccults: &IOccults,
+                           goccults: &GameOccults,
                            gpc: &GPiece, ipc: &IPiece) -> Html {
     match self.instead(ioccults, ipc)? {
-      Left(y) => ipc.show(y).describe_html(gpc)?,
+      Left(y) => ipc.show(y).describe_html(gpc, goccults)?,
       Right(i) => i.describe_html()?,
     }
   }
index 7737011ab4254e355eb28011a59aa34c174f1182..febc131daecad7c6cb8c2fd81e3c881698a2ed5c 100644 (file)
@@ -134,7 +134,7 @@ impl PieceTrait for SimpleShape {
     self.svg_piece_raw(f, gpc.face, &mut |_|Ok(()))?;
   }
   #[throws(IE)]
-  fn describe_html(&self, gpc: &GPiece) -> Html {
+  fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) -> Html {
     Html(if_chain! {
       if let face = gpc.face;
       if let Some(colour) = self.colours.get(face);
index d29137cf994232dc6d1b33c9eee8ebc042f9d758..d734096f07baf1652c47442d3ba0ed0037eeb0dc 100644 (file)
@@ -288,7 +288,7 @@ impl PieceTrait for Item {
     self.svg_face(f, gpc.face, vpid)?;
   }
   #[throws(IE)]
-  fn describe_html(&self, gpc: &GPiece) -> Html {
+  fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) -> Html {
     self.describe_face(gpc.face)?
   }
 
index bc14b6ea15dc70028197072b3a257e0771326d76..5d0ba952ac70b3f87470d0b35f9985c3f3e8bad6 100644 (file)
@@ -267,7 +267,8 @@ struct FormattedLogEntry<'u> {
 // ---------- helpful utilities ----------
 
 #[throws(OE)]
-pub fn log_did_to_piece_whoby(ioccults: &IOccults, by_gpl: &GPlayer,
+pub fn log_did_to_piece_whoby(ioccults: &IOccults, goccults: &GameOccults,
+                              by_gpl: &GPlayer,
                               gpc: &GPiece, ipc: &IPiece, did: &str)
                               -> (Vec<LogEntry>, Option<Html>)
 {
@@ -275,7 +276,7 @@ pub fn log_did_to_piece_whoby(ioccults: &IOccults, by_gpl: &GPlayer,
   let y = gpc.fully_visible_to_everyone();
   let desc = (||{
     Ok::<_,IE>(match ipc.show_or_instead(ioccults, y)? {
-      Left(y) => ipc.show(y).describe_html(gpc)?,
+      Left(y) => ipc.show(y).describe_html(gpc, goccults)?,
       Right(instead) => instead.describe_html()?,
     })
   })().unwrap_or_else(|e|{
@@ -293,10 +294,11 @@ pub fn log_did_to_piece_whoby(ioccults: &IOccults, by_gpl: &GPlayer,
 }
 
 #[throws(OE)]
-pub fn log_did_to_piece(ioccults: &IOccults, by_gpl: &GPlayer,
+pub fn log_did_to_piece(ioccults: &IOccults, goccults: &GameOccults,
+                        by_gpl: &GPlayer,
                         gpc: &GPiece, ipc: &IPiece, did: &str)
                         -> Vec<LogEntry> {
-  log_did_to_piece_whoby(ioccults,by_gpl,gpc,ipc,did)?.0
+  log_did_to_piece_whoby(ioccults,goccults,by_gpl,gpc,ipc,did)?.0
 }
 
 // ---------- prepared updates, queued in memory ----------