From 0206d86bbbf525b93c8cf4a10a41b345268a5038 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 5 Jul 2020 19:37:03 +0100 Subject: [PATCH] json in update --- src/bin/server.rs | 9 +++++++-- src/gamestate.rs | 3 ++- src/updates.rs | 10 +++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index e9a8ef9f..758af966 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -146,12 +146,17 @@ fn api_grab(form : Json) -> impl response::Responder<'static> { p.gen_before_lastclient = p.gen_lastclient; p.lastclient = client; } - let json = UpdatePayload::PieceUpdate(piece, p.mk_update()); + let vpiece = form.piece; // split view needs modified value! + let pri = PieceRenderInstructions { + id : vpiece, + face : p.face, + }; + let json = UpdatePayload::PieceUpdate(vpiece, p.mk_update(&pri)); let json = serde_json::to_string(&json).expect("convert to json"); let update = PreparedUpdate { gen, client, - piece : form.piece, // split view needs modified value! + piece : vpiece, cseq : form.cseq, json, }; diff --git a/src/gamestate.rs b/src/gamestate.rs index e06c8c92..681f60a4 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -74,10 +74,11 @@ impl PieceRecord { defs } - pub fn mk_update(&self) -> PieceUpdate { + pub fn mk_update(&self, pri : &PieceRenderInstructions) -> PieceUpdate { PieceUpdate { pos : self.pos, held : self.held, + svgs : self.make_defs(pri), // xxx want all piece's stuff in the same def } } diff --git a/src/updates.rs b/src/updates.rs index a0ce16a1..872cd8ec 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -15,15 +15,15 @@ pub struct Update { pub struct PieceUpdate { pub pos : Pos, pub held : Option, -// pub svgs : Vec; + pub svgs : String, } #[derive(Debug,Serialize)] pub enum UpdatePayload { NoUpdate, ClientSequence(PieceId, ClientSequence), - PieceDelete(PieceId), - PieceInsert(PieceId, PieceUpdate), - PieceUpdate(PieceId, PieceUpdate), - PieceMove(PieceId, Pos), + PieceDelete(VisiblePieceId), + PieceInsert(VisiblePieceId, PieceUpdate), + PieceUpdate(VisiblePieceId, PieceUpdate), + PieceMove(VisiblePieceId, Pos), } -- 2.30.2