#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct ChessClock { // Spec
time: Time,
- #[serde(default)] per_move: usize,
+ #[serde(default)] per_move: Time,
}
#[derive(Debug,Serialize,Deserialize)]
fn do_start_or_stop(&mut self, piece: PieceId,
was_implied_running: Option<User>,
held: Option<PlayerId>,
+ spec: &ChessClock,
ig: &InstanceRef) {
let state = self;
if state.implies_running(held) == was_implied_running { return }
}
}
+ if_chain! {
+ if let Some(was_running_user) = was_implied_running;
+ if let Some(now_running_user) = state.implies_running(held);
+ if now_running_user != was_running_user;
+ then {
+ let remaining = &mut state.users[now_running_user].remaining;
+ *remaining = *remaining + TVL::seconds(spec.per_move.into());
+ }
+ }
+
if_chain! {
if let Some(now_running_user) = state.implies_running(held);
then {
}
};
- state.do_start_or_stop(piece, was_implied_running, held, ig)
+ state.do_start_or_stop(piece, was_implied_running, held, &self.spec, ig)
.map_err(|e| APOE::ReportViaResponse(e.into()))?;
let log = log_did_to_piece(ioccults, gpl, gpc, ipc, &did)
}
}
- state.do_start_or_stop(piece, was_running, now_held, ig)?;
+ state.do_start_or_stop(piece, was_running, now_held, &self.spec, ig)?;
unprepared_update(piece)
}