From 06fd7d954c7ce8f8bd34cd89e12aa3d9a7e59276 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 27 Sep 2020 22:56:19 +0100 Subject: [PATCH] Prep for flip Signed-off-by: Ian Jackson --- src/api.rs | 7 ++++--- src/error.rs | 2 ++ src/imports.rs | 2 +- src/spec.rs | 3 ++- src/updates.rs | 3 +++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/api.rs b/src/api.rs index 2078fb2a..13bf4c7d 100644 --- a/src/api.rs +++ b/src/api.rs @@ -12,16 +12,17 @@ struct ApiPiece { cseq : ClientSequence, op : O, } + trait ApiPieceOp : Debug { #[throws(ApiPieceOpError)] fn op(&self, gs: &mut GameState, player: PlayerId, piece: PieceId, p: &dyn Piece, lens: &dyn Lens /* used for LogEntry and PieceId but not Pos */) - -> (PieceUpdateOp<()>, Vec); + -> PieceUpdateFromOp; } #[derive(Error,Debug)] -enum ApiPieceOpError { +pub enum ApiPieceOpError { ReportViaResponse(#[from] OnlineError), ReportViaUpdate(#[from] PieceOpError), PartiallyProcessed(PieceOpError, Vec), @@ -77,7 +78,7 @@ impl<'r> Responder<'r> for OnlineError { => Status::NotFound, OnlineError::PieceHeld | OnlineError::PieceGone => Status::Conflict, - InvalidZCoord | BadJSON(_) + InvalidZCoord | BadOperation | BadJSON(_) => Status::BadRequest, }; let mut resp = Responder::respond_to(msg,req).unwrap(); diff --git a/src/error.rs b/src/error.rs index b45d88ae..1312d124 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,6 +22,8 @@ pub enum OnlineError { PieceGone, #[error("improper piece hold status for op (maybe race)")] PieceHeld, + #[error("improper UI operation")] + BadOperation, } from_instance_lock_error!{OnlineError} diff --git a/src/imports.rs b/src/imports.rs index ba24e764..fa6d610b 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -106,7 +106,7 @@ pub use crate::commands::*; pub use crate::slotmap_slot_idx::*; pub use crate::cmdlistener::*; pub use crate::mgmtchannel::*; -pub use crate::api::{Lens,TransparentLens}; +pub use crate::api::{Lens,TransparentLens,ApiPieceOpError}; pub use crate::utils::*; pub use crate::spec::*; pub use crate::debugreader::DebugReader; diff --git a/src/spec.rs b/src/spec.rs index 64512b39..332c3cb3 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -27,9 +27,10 @@ pub type Pos = PosC; #[serde(transparent)] pub struct RawToken (pub String); +pub type RawFaceId = u8; define_index_type! { #[derive(Default)] - pub struct FaceId = u8; + pub struct FaceId = RawFaceId; } #[derive(Serialize,Deserialize)] diff --git a/src/updates.rs b/src/updates.rs index e4e78006..359d6bed 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -72,6 +72,9 @@ pub enum PieceUpdateOp { SetZLevel(ZLevel), } +pub type PieceUpdateFromOp = (PieceUpdateOp<()>, Vec); +pub type PieceUpdateResult = Result; + // ---------- for traansmission ---------- #[derive(Debug,Serialize)] -- 2.30.2