From: Ian Jackson Date: Wed, 8 Jul 2020 01:24:45 +0000 (+0100) Subject: wip raise X-Git-Tag: otter-0.2.0~1400 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=3013eaf9cbb235f2b29bcaa3bb084001cd710c26;p=otter.git wip raise --- diff --git a/src/bin/server.rs b/src/bin/server.rs index d6d47d4c..d63b7f5b 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -313,6 +313,27 @@ impl ApiPieceOp for ApiPieceUngrab { } } +#[derive(Debug,Serialize,Deserialize)] +struct ApiPieceRaise { +} +#[post("/_/api/raise", format="json", data="
")] +#[throws(OE)] +fn api_raise(form : Json>) + -> impl response::Responder<'static> { + api_piece_op(form) +} +impl ApiPieceOp for ApiPieceRaise { + #[throws(GameError)] + fn op(&self, gs: &mut GameState, _: PlayerId, piece: PieceId, + _: &dyn Lens) + -> (PieceUpdateOp<()>, Vec) { + let pc = gs.pieces.byid_mut(piece).unwrap(); + pc.raised = gs.gen; + let update = PieceUpdateOp::Raise; + (update, vec![]) + } +} + #[derive(Debug,Serialize,Deserialize)] struct ApiPieceMove (Pos); #[post("/_/api/m", format="json", data="")] @@ -372,6 +393,7 @@ fn main() { updates, api_grab, api_ungrab, + api_raise, api_move, ]) .launch(); diff --git a/src/global.rs b/src/global.rs index c46c31ed..4e6aee4c 100644 --- a/src/global.rs +++ b/src/global.rs @@ -59,6 +59,7 @@ pub enum PieceUpdateOp { Insert(NS), Modify(NS), Move(Pos), + Raise, } impl PieceUpdateOp { pub fn new_state(&self) -> Option<&NS> { @@ -68,6 +69,7 @@ impl PieceUpdateOp { Insert(ns) => Some(ns), Modify(ns) => Some(ns), Move(_) => None, + Raise => None, } } pub fn map_new_state NS2>(self, f:F) @@ -78,6 +80,7 @@ impl PieceUpdateOp { Insert(ns) => Insert(f(ns)), Modify(ns) => Modify(f(ns)), Move(pos) => Move(pos), + Raise => Raise, } } }