chiark / gitweb /
dice: Preview partially-cooled-down
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 14 May 2022 12:51:26 +0000 (13:51 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 15 May 2022 00:03:33 +0000 (01:03 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otterlib.rs
src/dice.rs
src/gamestate.rs

index 70368d82dc35e591ab795e40ee6dde3723b5850d..d9d4e3a514d9a15a6dd6a9351340f66e796fa193 100644 (file)
@@ -110,6 +110,7 @@ fn preview(opts: &Opts, items: Vec<ItemForOutput>) {
           i: 0,
         })
         .context("load")?;
+      p.loaded_hook_preview(&mut gpc)?;
       // todo show occulted version too
       let mut uos = vec![];
       p.add_ui_operations(VIS, &mut uos, &GameState::dummy(), &GPiece::dummy())
index 78a72d8c63013ae91361039c706aa1004b9226d5..2b307bbaeb0ea66b16f5f72f0a3bf08ccb4a43a3 100644 (file)
@@ -433,6 +433,17 @@ impl PieceTrait for Die {
                         , _: &InstanceRef) {
     self.cooldown_cleanup_hook(&mut gs.pieces, piece)?;
   }
+
+  #[throws(IE)]
+  fn loaded_hook_preview(&self, gpc: &mut GPiece) {
+    let state: &mut State = gpc.xdata.get_mut_exp()?;
+    state.cooldown_expires = Some(FutureInstant::try_from(
+      Duration::from_secs_f64(
+        self.cooldown_time.as_secs_f64() * 0.25
+      )
+    )?)
+//.map_err(|e| internal_error_bydebug(&e))?
+  }
 }
 
 #[typetag::serde(name="Die")]
index bca44d128338e687611dc650eb8720219352b7c6..3a3d118f1f4dcd038ee9c3f4c20ec10daf36ecd9 100644 (file)
@@ -236,6 +236,10 @@ pub trait PieceTrait: PieceBaseTrait + Downcast + Send + Debug + 'static {
     Ok(())
   }
 
+  fn loaded_hook_preview(&self, _gpc: &mut GPiece) -> Result<(),IE> {
+    Ok(())
+  }
+
   /// Not called if the whole game is destroyed.
   /// You can use Drop of course but it's not usually much use since
   /// you don't have a reference to the game or anything.