chiark / gitweb /
wip serde for gamestate
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 13 Jul 2020 22:54:21 +0000 (23:54 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 13 Jul 2020 22:54:21 +0000 (23:54 +0100)
src/gamestate.rs

index bc659f3388f57f80b7b66061d1ee3510e1a531f9..8235d338180d0f2485e352c65cbbcb05252e3163 100644 (file)
@@ -38,7 +38,7 @@ pub struct ZLevel {
 
 // ---------- game state ----------
 
-#[derive(Debug)]
+#[derive(Debug,Serialize)]
 pub struct GameState {
   pub pieces : DenseSlotMap<PieceId,PieceState>,
   pub players : DenseSlotMap<PlayerId,PlayerState>,
@@ -46,9 +46,10 @@ pub struct GameState {
   pub log : Vec<(Generation,LogEntryRef)>,
 }
 
-#[derive(Debug)]
+#[derive(Debug,Serialize)]
 pub struct PieceState {
   pub pos : Pos,
+  #[serde(with="self::piece_serde")]
   pub p : Box<dyn Piece>,
   pub face : FaceId,
   pub held : Option<PlayerId>,
@@ -58,7 +59,7 @@ pub struct PieceState {
   pub gen_before_lastclient : Generation,
 }
 
-#[derive(Debug)]
+#[derive(Debug,Serialize)]
 pub struct PlayerState {
   pub nick : String,
 }
@@ -187,6 +188,19 @@ impl PieceState {
   }
 }
 
+// ---------- pice load and save ----------
+
+mod piece_serde {
+  use crate::gamestate::*;
+  use serde::Serializer;
+//  #[throws(Result<<S as Serializer>::Ok,<S as Serializer>::Error>)]
+  pub fn serialize<S:Serializer>(pc : &Box<dyn Piece>, s:S)
+                                 -> Result<S::Ok, S::Error> {
+    s.serialize_none()
+  }
+  pub fn deserialize() { }
+}
+
 // ========== ad-hoc and temporary ==========
 
 pub fn make_pieceid_visible(p : PieceId) -> VisiblePieceId {