chiark / gitweb /
recalculate_occultation: Add log callback
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 16 Feb 2021 20:51:37 +0000 (20:51 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 16 Feb 2021 20:51:37 +0000 (20:51 +0000)
NFC

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

index 413dc9965e19414a7b5769a67b298192185b1b31..cbb00df87f6fe419735b72e13c290e444977cab7 100644 (file)
@@ -286,11 +286,20 @@ api_route!{
                    logents);
 
     let update=
-      recalculate_occultation(gs,
-                              who_by,
-                              ipieces,
-                              piece,
-                              vanilla).map_err(|e| OnlineError::from(e))?;
+      recalculate_occultation(
+        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
   }
index aba911bdf8fe4e66d74859aa370973a148553dc3..fb8dc598ddae8f5a063215f82011312db690a5bc 100644 (file)
@@ -210,12 +210,15 @@ pub fn massage_prep_piecestate(
 // xxx this means this only happens on ungrab I think ?
 
 #[throws(InternalError)]
-pub fn recalculate_occultation(
+pub fn recalculate_occultation<
+  L: FnOnce(&Html, Html, Html, Option<&Html>) -> Vec<LogEntry>,
+  >(
   gs: &mut GameState,
   who_by: Html,
   ipieces: &PiecesLoaded,
   piece: PieceId,
   vanilla: PUFOS,
+  log_callback: L,
 )
   -> PieceUpdate
 {
@@ -316,6 +319,14 @@ pub fn recalculate_occultation(
 
     let most_obscure = most_obscure.unwrap_or(&OccK::Visible); // no players!
 
+    let call_log_callback =
+      |show| Ok::<_,IE>(
+        log_callback(&who_by,
+                     describe_occulter(ONI::Old)?,
+                     describe_occulter(ONI::New)?,
+                     show)
+      );
+
     let log = match most_obscure {
       OccK::Visible => {
         vanilla.2
@@ -323,19 +334,11 @@ pub fn recalculate_occultation(
       OccK::Scrambled | OccK::Displaced{..} => {
         let face = ipc.nfaces() - 1;
         let show = ipc.describe_html(Some(face.into()), gpc)?;
-        vec![ LogEntry { html: Html(format!(
-          "{} moved {} from {} to {}",
-          who_by.0, &show.0,
-          describe_occulter(ONI::Old)?.0,
-          describe_occulter(ONI::New)?.0,
-        ))}]
+        call_log_callback(Some(&show))?
+      },
+      OccK::Invisible => {
+        call_log_callback(None)?
       },
-      OccK::Invisible => vec![ LogEntry { html: Html(format!(
-        "{} moved something from {} to {}",
-        who_by.0,
-        describe_occulter(ONI::Old)?.0,
-        describe_occulter(ONI::New)?.0,
-      ))}],
     };
 
     let update = PieceUpdate {