From: Ian Jackson Date: Sat, 14 May 2022 12:51:26 +0000 (+0100) Subject: dice: Preview partially-cooled-down X-Git-Tag: otter-1.1.0~151 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=9cd586516cee87cb98cf9547b89e4c468733228a;p=otter.git dice: Preview partially-cooled-down Signed-off-by: Ian Jackson --- diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index 70368d82..d9d4e3a5 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -110,6 +110,7 @@ fn preview(opts: &Opts, items: Vec) { 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()) diff --git a/src/dice.rs b/src/dice.rs index 78a72d8c..2b307bba 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -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")] diff --git a/src/gamestate.rs b/src/gamestate.rs index bca44d12..3a3d118f 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -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.