chiark / gitweb /
currency: Occult the left-behind value too
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 19 May 2022 23:22:59 +0000 (00:22 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 20 May 2022 18:20:47 +0000 (19:20 +0100)
By plumbing Value more, rather than raw Qty.

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

index 31c4193467a09dfff5e862b9c5973b6269e5bb2a..2b4c71b3cfbff7b4a1cf4ae88a270f65965db582 100644 (file)
@@ -45,7 +45,7 @@ pub struct Banknote {
   label_options: TextOptions,
 }
 
-#[derive(Debug,Serialize,Deserialize)]
+#[derive(Debug,Clone,Serialize,Deserialize)]
 pub struct Value {
   qty: Qty,
 }
@@ -162,9 +162,10 @@ impl PieceTrait for Banknote {
     let tgpc_value: &mut Value = tgpc.xdata.get_mut_exp()?;
     let remaining = tgpc_value.qty.checked_sub(take)
       .ok_or(Ia::CurrencyShortfall)?;
+    let remaining = Value { qty: remaining };
 
     tgpc_value.qty = take;
-    ngpc.xdata_init(Value { qty: remaining })?;
+    ngpc.xdata_init(remaining.clone())?;
 
     tgpc.held = Some(player);
     ngpc.held = None;
@@ -175,7 +176,8 @@ impl PieceTrait for Banknote {
       "{} took {}, leaving {}{}",
       gpl.nick.to_html(),
       self_unocc.describe(tgpc.face, &tgpc_value.html(show_to_all))?,
-      remaining, &currency,
+      remaining.html(show_to_all),
+      &currency,
     )}];
 
     let update = PieceUpdateOp::ModifyQuiet(());