From: Ian Jackson Date: Mon, 13 Jul 2020 22:54:21 +0000 (+0100) Subject: wip serde for gamestate X-Git-Tag: otter-0.2.0~1326 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7950e2aab6f095806b7bef513ed76031c70f460c;p=otter.git wip serde for gamestate --- diff --git a/src/gamestate.rs b/src/gamestate.rs index bc659f33..8235d338 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -38,7 +38,7 @@ pub struct ZLevel { // ---------- game state ---------- -#[derive(Debug)] +#[derive(Debug,Serialize)] pub struct GameState { pub pieces : DenseSlotMap, pub players : DenseSlotMap, @@ -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, pub face : FaceId, pub held : Option, @@ -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<::Ok,::Error>)] + pub fn serialize(pc : &Box, s:S) + -> Result { + s.serialize_none() + } + pub fn deserialize() { } +} + // ========== ad-hoc and temporary ========== pub fn make_pieceid_visible(p : PieceId) -> VisiblePieceId {