From: Ian Jackson Date: Sun, 29 Nov 2020 21:18:37 +0000 (+0000) Subject: allow setting of the table colour X-Git-Tag: otter-0.2.0~299 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1c0ba0429494ffc641710b6b709bc2c1d3087fb5;p=otter.git allow setting of the table colour Signed-off-by: Ian Jackson --- diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 0448cc73..8cd15dd4 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -789,6 +789,7 @@ mod reset_game { let GameSpec { table_size, pieces, + table_colour, } = read_spec(&ma, &args.game_file)?; let mut insns = vec![]; @@ -816,6 +817,9 @@ mod reset_game { 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)); + } for pspec in pieces.into_iter() { insns.push(MGI::AddPieces(pspec)); diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index 663fdde7..37b62102 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -311,6 +311,19 @@ fn execute_game_insn<'cs, 'igr, 'ig : 'igr>( Fine, ig) } + Insn::SetTableColour(colour) => { + let ig = cs.check_acl(ag, ig, PCH::Instance, &[TP::ChangePieces])?.0; + let colour : Colour = (&colour).try_into()?; + ig.gs.table_colour = colour.clone(); + (U{ pcs: vec![], + log: vec![ LogEntry { + html: Html(format!("{} recoloured the tabletop to {}", + &who.0, &colour.0)), + }], + raw: Some(vec![ PreparedUpdateEntry::SetTableColour(colour) ]) }, + Fine, ig) + } + Insn::JoinGame { details: MgmtPlayerDetails { nick } } => { diff --git a/src/commands.rs b/src/commands.rs index 1e08f922..2f395204 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -71,6 +71,7 @@ pub enum MgmtGameInstruction { Noop, Info, SetTableSize(Pos), + SetTableColour(ColourSpec), ListPieces, AddPieces(PiecesSpec), diff --git a/src/spec.rs b/src/spec.rs index 98e2a5e0..c2656a8a 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -44,6 +44,7 @@ define_index_type! { #[derive(Serialize,Deserialize)] #[derive(Debug,Default)] #[repr(transparent)] +#[serde(transparent)] pub struct ColourSpec(String); #[derive(Error,Clone,Serialize,Deserialize,Debug)] @@ -128,6 +129,7 @@ pub struct UrlOnStdout; pub struct GameSpec { pub table_size : Option, pub pieces : Vec, + pub table_colour: Option, } #[derive(Debug,Serialize,Deserialize)] diff --git a/src/updates.rs b/src/updates.rs index 5aff07f1..5a4ad4e8 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -47,6 +47,7 @@ pub enum PreparedUpdateEntry { op : PieceUpdateOp, }, SetTableSize(Pos), + SetTableColour(Colour), AddPlayer { player: PlayerId, data: DataLoadPlayer }, RemovePlayer { player: PlayerId }, Log (Arc), @@ -111,6 +112,7 @@ enum TransmitUpdateEntry<'u> { ns: &'u PreparedPieceState, }, SetTableSize(Pos), + SetTableColour(&'u Colour), AddPlayer { player: PlayerId, data: &'u DataLoadPlayer }, RemovePlayer { player: PlayerId }, #[serde(serialize_with="serialize_logentry")] @@ -198,6 +200,9 @@ impl PreparedUpdateEntry { AddPlayer { player:_, data: DataLoadPlayer { dasharray } } => { dasharray.as_bytes().len() + 100 }, + SetTableColour(colour) => { + colour.0.as_bytes().len() + 50 + }, SetTableSize(_) | RemovePlayer { player:_ } | Error(_,_) => { @@ -532,6 +537,9 @@ impl PreparedUpdate { &PUE::SetTableSize(size) => { TUE::SetTableSize(size) }, + PUE::SetTableColour(colour) => { + TUE::SetTableColour(colour) + }, &PUE::AddPlayer { player, ref data } => { TUE::AddPlayer { player, data } },