From 7aba6f088998e769ef41d1a706b981f41868e5a7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 19 May 2022 21:16:20 +0100 Subject: [PATCH] currency: Change Value::html to demand a ShowUnocculted This finds places we need to hide the quantity. One (new_value) was wrong, and is now fixed. Signed-off-by: Ian Jackson --- src/currency.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/currency.rs b/src/currency.rs index baf7559d..42702616 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -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) -> 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)] -- 2.30.2