chiark / gitweb /
dice: Start a cooldown the first time a die is added to the game
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 15 Apr 2022 12:14:24 +0000 (13:14 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 15 Apr 2022 21:43:43 +0000 (22:43 +0100)
This is useful for testing.  It also means you can't just add a die
showing what you want using the game management interface...

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

index 80bd56111618edde9da1c444e349c7db1eeba7bb..72a15870ab976aa641673b321a2a780f8b41b4df 100644 (file)
@@ -148,11 +148,14 @@ impl PieceSpec for Spec {
       if t <= MAX_COOLDOWN { t }
       else { throw!(SpecError::TimeoutTooLarge { got: t, max: MAX_COOLDOWN }) }
     };
-
     let itemname = self.itemname.clone().unwrap_or_else(
       || format!("die.{}.{}", nfaces, image.itemname()));
 
-    let _state: &mut State = gpc.xdata_mut(|| State::dummy())?;
+    let initial_state = {
+      let t = cooldown_time.try_into().map_err(IE::from)?;
+      State { cooldown_expires: Some(t) }
+    };
+    let _state: &mut State = gpc.xdata_mut(|| initial_state)?;
 
     let occultable = match (img_occultable, &self.occult_label) {
       (None, l) => if l == "" {