chiark / gitweb /
currency: Change Value::html to demand a ShowUnocculted
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 May 2022 20:16:20 +0000 (21:16 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 May 2022 20:19:07 +0000 (21:19 +0100)
This finds places we need to hide the quantity.  One (new_value) was
wrong, and is now fixed.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/currency.rs

index baf7559d1300656740845ea368cb4d3190af5e6e..42702616321bdc6b178317699022ed5fa5737a0e 100644 (file)
@@ -129,15 +129,17 @@ impl PieceBaseTrait for Banknote {
 impl PieceTrait for Banknote {
   #[throws(IE)]
   fn describe_html(&self, gpc: &GPiece, _: &GOccults) -> Html {
+    let show = ShowUnocculted::new_visible(); // we are in PieceTrait, so ok
     let value: &Value = gpc.xdata.get_exp()?;
-    self.describe(gpc.face, &value.html())?
+    self.describe(gpc.face, &value.html(Some(show)))?
   }
 
   #[throws(IE)]
   fn svg_piece(&self, f: &mut Html, gpc: &GPiece, _gs: &GameState,
                vpid: VisiblePieceId) {
+    let show = ShowUnocculted::new_visible(); // we are in PieceTrait, so ok
     let value: &Value = gpc.xdata.get_exp()?;
-    self.render(f, vpid, gpc.face, &gpc.xdata, &value.html())?
+    self.render(f, vpid, gpc.face, &gpc.xdata, &value.html(Some(show)))?
   }
 
   #[throws(ApiPieceOpError)]
@@ -261,6 +263,8 @@ impl PieceTrait for Banknote {
       None => return default(), // arithmetic overflow!
     };
 
+    let show_qty = mgpc.fully_visible_to_everyone();
+
     let logent = hformat!(
       "{} deposited {}, giving {}{}",
       match gpl {
@@ -268,7 +272,7 @@ impl PieceTrait for Banknote {
         None => Html::lit("Departing player").into(),
       },
       tipc.p.show(show).describe_html(tgpc, goccults)?,
-      &new_value.html(),
+      &new_value.html(show_qty),
       currency,
     );
 
@@ -305,8 +309,16 @@ impl PieceTrait for Banknote {
   }))}
 }
 
+const OCCULT_QTY: HtmlLit = Html::lit("?");
+
 impl Value {
-  fn html(&self) -> Html { hformat!("{}", self.qty) }
+  fn html(&self, show: Option<ShowUnocculted>) -> Html {
+    if show.is_some() {
+      hformat!("{}", self.qty)
+    } else {
+      hformat!("{}", OCCULT_QTY)
+    }
+  }
 }
 
 impl Banknote {
@@ -329,8 +341,6 @@ impl Banknote {
   }
 }
 
-const OCCULT_QTY: HtmlLit = Html::lit("?");
-
 #[typetag::serde(name="Currency")]
 impl InertPieceTrait for Banknote {
   #[throws(IE)]