From: Ian Jackson Date: Sun, 1 May 2022 11:39:26 +0000 (+0100) Subject: delete_piece: Plumb PieceUpdateOp, and document re log X-Git-Tag: otter-1.1.0~370 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0c7ee41161cf667f652586ab17a84d1a30195c82;p=otter.git delete_piece: Plumb PieceUpdateOp, and document re log Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index a3c1a550..32aab755 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -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), diff --git a/src/global.rs b/src/global.rs index 02ec3169..d66ce087 100644 --- a/src/global.rs +++ b/src/global.rs @@ -641,12 +641,17 @@ impl InstanceAccessDetails } 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(&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