chiark / gitweb /
json in update
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 5 Jul 2020 18:37:03 +0000 (19:37 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 5 Jul 2020 18:37:03 +0000 (19:37 +0100)
src/bin/server.rs
src/gamestate.rs
src/updates.rs

index e9a8ef9fc681346ef3f53b2d3c232a3cb4f51172..758af9665eacea1a93a2fd81dc1776c1a84dbf26 100644 (file)
@@ -146,12 +146,17 @@ fn api_grab(form : Json<ApiGrab>) -> 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,
     };
index e06c8c9222f8fe56b86261ec21dbf202e8afac70..681f60a472ce171856b57f74fde0d90cbd52d477 100644 (file)
@@ -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
     }
   }
index a0ce16a18948da36a549221b5addeca8e2478dd4..872cd8ecfe470e7723ba25316b1df5d53fd8ce6c 100644 (file)
@@ -15,15 +15,15 @@ pub struct Update {
 pub struct PieceUpdate {
   pub pos : Pos,
   pub held : Option<PlayerId>,
-//  pub svgs : Vec<String,String>;
+  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),
 }