From: Ian Jackson Date: Tue, 16 Feb 2021 23:56:32 +0000 (+0000) Subject: recalculate_occultation: Refactor into ..._general etc. X-Git-Tag: otter-0.4.0~437 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7ec6d0f11abbc87fc2c20d338f6acc0eafd17b90;p=otter.git recalculate_occultation: Refactor into ..._general etc. NFC Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index cbb00df8..2b8545e9 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -286,19 +286,12 @@ api_route!{ logents); let update= - recalculate_occultation( + recalculate_occultation_piece( gs, who_by, ipieces, piece, vanilla, - |who_by, old, new, show| vec![ LogEntry { html: Html(format!( - "{} moved {} from {} to {}", - &who_by.0, - if let Some(show) = show { &show.0 } else { "something" }, - &old.0, &new.0, - ))}], - ).map_err(|e| OnlineError::from(e))?; update diff --git a/src/hidden.rs b/src/hidden.rs index fb8dc598..25246e00 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -210,7 +210,7 @@ pub fn massage_prep_piecestate( // xxx this means this only happens on ungrab I think ? #[throws(InternalError)] -pub fn recalculate_occultation< +fn recalculate_occultation_general< L: FnOnce(&Html, Html, Html, Option<&Html>) -> Vec, >( gs: &mut GameState, @@ -370,3 +370,28 @@ pub fn recalculate_occultation< update } + +#[throws(InternalError)] +pub fn recalculate_occultation_piece( + gs: &mut GameState, + who_by: Html, + ipieces: &PiecesLoaded, + piece: PieceId, + vanilla: PUFOS, +) + -> PieceUpdate +{ + recalculate_occultation_general( + gs, + who_by, + ipieces, + piece, + vanilla, + |who_by, old, new, show| vec![ LogEntry { html: Html(format!( + "{} moved {} from {} to {}", + &who_by.0, + if let Some(show) = show { &show.0 } else { "something" }, + &old.0, &new.0, + ))}] + )? +}