From: Ian Jackson Date: Wed, 31 Mar 2021 18:23:47 +0000 (+0100) Subject: spec: Make table size and colour defaulted in serde X-Git-Tag: otter-0.5.0~358 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=bafd2cadf093f21b2cb38404e85e486417057ca0;p=otter.git 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 --- 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)?;