From: Ian Jackson Date: Thu, 18 Mar 2021 21:10:11 +0000 (+0000) Subject: clock: actually load state X-Git-Tag: otter-0.5.0~667 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=3f11d319fba2ade3d022dad2d33c86353ab19416;p=otter.git clock: actually load state Signed-off-by: Ian Jackson --- diff --git a/src/clock.rs b/src/clock.rs index 55a47b5d..af4e88a2 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -82,9 +82,8 @@ struct State { #[serde(skip)] running: Option, } -#[typetag::serde(name="Hand")] -impl PieceXData for State { - fn dummy() -> Self { +impl State { + fn new() -> Self { State { users: [UState { player: default(), remaining: TVL::zero() }; N], running: None, @@ -92,6 +91,11 @@ impl PieceXData for State { } } +#[typetag::serde(name="Hand")] +impl PieceXData for State { + fn dummy() -> Self { State::new() } +} + #[derive(Debug,Copy,Clone,Serialize,Deserialize)] struct UState { @@ -191,12 +195,15 @@ const OUTLINE: Rectangle = Rectangle { xy: PosC([W as f64, H as f64]) }; #[typetag::serde] impl PieceSpec for ChessClock { #[throws(SpecError)] - fn load(&self, _: usize, _gpc: &mut GPiece) -> PieceSpecLoaded { + fn load(&self, _: usize, gpc: &mut GPiece) -> PieceSpecLoaded { if self.time <= 0 { throw!(SpecError::NegativeTimeout) } let clock = Clock { spec: self.clone(), }; + + gpc.xdata_mut(|| State::new())?; + PieceSpecLoaded { p: Box::new(clock), occultable: None,