From bafd2cadf093f21b2cb38404e85e486417057ca0 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 31 Mar 2021 19:23:47 +0100 Subject: [PATCH] spec: Make table size and colour defaulted in serde This way `reset` works properly, always resetting the colour to the default. Signed-off-by: Ian Jackson --- src/bin/otter.rs | 8 ++------ src/gamestate.rs | 1 + src/spec.rs | 11 +++++++++-- wdriver/wdt-simple.rs | 3 +-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 9d0e7501..5ebb3689 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -700,12 +700,8 @@ mod reset_game { insns.push(MGI::DefinePieceAlias{ alias, target }); } - if let Some(table_size) = table_size { - insns.push(MGI::SetTableSize(table_size)); - } - if let Some(table_colour) = table_colour { - insns.push(MGI::SetTableColour(table_colour)); - } + insns.push(MGI::SetTableSize(table_size)); + insns.push(MGI::SetTableColour(table_colour)); for pspec in pieces.into_iter() { insns.push(MGI::AddPieces(pspec)); diff --git a/src/gamestate.rs b/src/gamestate.rs index a1c73509..7658d740 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -24,6 +24,7 @@ visible_slotmap_key!{ VisiblePieceId(b'.') } pub struct Timestamp(pub u64); /* time_t */ pub const DEFAULT_TABLE_SIZE: Pos = PosC::new( 400, 200 ); +pub const DEFAULT_TABLE_COLOUR: &str = "green"; // ---------- general data types ---------- diff --git a/src/spec.rs b/src/spec.rs index 540800cf..921a1721 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -164,9 +164,9 @@ pub struct UrlOnStdout; #[derive(Debug,Serialize,Deserialize)] pub struct GameSpec { - pub table_size: Option, + #[serde(default="imp::def_table_size")] pub table_size: Pos, pub pieces: Vec, - pub table_colour: Option, + #[serde(default="imp::def_table_colour")] pub table_colour: ColourSpec, #[serde(default)] pub pcaliases: HashMap>, } @@ -310,6 +310,13 @@ pub mod imp { type AS = AccountScope; type TPS = TablePlayerSpec; + pub fn def_table_size() -> Pos { + DEFAULT_TABLE_SIZE + } + pub fn def_table_colour() -> ColourSpec { + ColourSpec(DEFAULT_TABLE_COLOUR.into()) + } + impl Default for piece_specs::PieceLabelPlace { fn default() -> Self { Self::BottomLeft } } diff --git a/wdriver/wdt-simple.rs b/wdriver/wdt-simple.rs index 8e9a51d9..4fc17769 100644 --- a/wdriver/wdt-simple.rs +++ b/wdriver/wdt-simple.rs @@ -96,8 +96,7 @@ impl Ctx { Ok::<_,AE>(()) }; - let table_size = self.spec.table_size - .ok_or(anyhow!("table size missing from spec"))?; + let table_size = self.spec.table_size; let exp_end = { let mut w = su.w(&self.alice)?; -- 2.30.2