chiark / gitweb /
delete_piece: Plumb PieceUpdateOp, and document re log
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 11:39:26 +0000 (12:39 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2022 12:00:58 +0000 (13:00 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/global.rs

index a3c1a550abcf78f80bde7c70b2522515848fcaa1..32aab755356fce6ab397a9b78d57527dc0dc6fa8 100644 (file)
@@ -1016,7 +1016,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
       let _ipc = ig.ipieces.as_mut(modperm)
         .get(piece).ok_or(ME::PieceNotFound)?;
 
-      let (desc_html, xupdates) =
+      let (desc_html, puo, xupdates) =
         ig.delete_piece(modperm, to_permute, piece,
                         |ioccults, goccults, ipc, gpc| {
           if let (Some(ipc), Some(gpc)) = (ipc, gpc) {
@@ -1027,7 +1027,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
           }
         })?;
 
-      (U{ pcs: vec![(piece, PieceUpdateOp::Delete())],
+      (U{ pcs: vec![(piece, puo)],
           log: vec![ LogEntry {
             html: hformat!("A piece {} was removed from the game",
                           desc_html),
index 02ec316997a503ba952fbb96032c705e3eda9fb5..d66ce087edd8b54a0caa1cc654c0593a15d85ec9 100644 (file)
@@ -641,12 +641,17 @@ impl<Id> InstanceAccessDetails<Id>
 }
 
 impl<'ig> InstanceGuard<'ig> {
-  /// Idempotent.
+  /// Core of piece deletion
+  ///
+  /// Caller is completely responsible for the necessary log entries.
+  ///
+  /// Idempotent (so does not detect if the piece didn't exist,
+  /// other than by passing `None`s to the callback.
   #[throws(IE)]
   pub fn delete_piece<H,T>(&mut self, modperm: ModifyingPieces,
                              to_permute: &mut ToRecalculate,
                              piece: PieceId, hook: H)
-                             -> (T, UnpreparedUpdates)
+                             -> (T, PieceUpdateOp<(),()>, UnpreparedUpdates)
   where H: FnOnce(&IOccults, &GOccults,
                   Option<&IPiece>, Option<&GPiece>) -> T
   {
@@ -687,7 +692,7 @@ impl<'ig> InstanceGuard<'ig> {
       }
     }
 
-    (hook_r, xupdates.into_unprepared(None))
+    (hook_r, PieceUpdateOp::Delete(), xupdates.into_unprepared(None))
   }
 
   /// caller is responsible for logging; threading it through