From 2beabde7e49dc8c8236f79f76c3f1988f7cc6f49 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 18 Apr 2022 13:00:56 +0100 Subject: [PATCH] Plumbing for "multigrab" piece API call We can now pass this through to a piece. Signed-off-by: Ian Jackson --- daemon/api.rs | 17 +++++++++++++++++ src/currency.rs | 2 +- src/gamestate.rs | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/daemon/api.rs b/daemon/api.rs index 206b9a70..54f24271 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -563,6 +563,22 @@ api_route!{ } } +api_route!{ + api_multigrab, "/_/api/multigrab", + struct ApiPieceMultigrab { + n: MultigrabQty, + } + + as: + #[throws(ApiPieceOpError)] + fn op(&self, mut a: ApiPieceOpArgs) -> PieceUpdate { + if ! a.ipc.special.multigrab { throw!(Ia::BadPieceStateForOperation) } + let pri = a.pri()?; + let y = pri.fully_visible().ok_or(Ia::Occultation)?; + a.ipc.show(y).op_multigrab(a, pri, self.n)? + } +} + api_route!{ api_uo, "/_/api/k", struct ApiPieceUo { @@ -628,5 +644,6 @@ pub fn routes() -> impl HttpServiceFactory { api_wrest, api_pin, api_uo, + api_multigrab, ] } diff --git a/src/currency.rs b/src/currency.rs index 29e632bf..c14360b8 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -17,7 +17,7 @@ use crate::prelude::*; const QTY_FONT_SIZE: f64 = 6.; -type Qty = u32; +type Qty = MultigrabQty; #[derive(Debug,Serialize,Deserialize)] pub struct Spec { diff --git a/src/gamestate.rs b/src/gamestate.rs index 68ea20ce..701d5d0d 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -35,6 +35,8 @@ pub struct ZLevel { pub zg: Generation, } +pub type MultigrabQty = u32; + // ---------- game state ---------- #[derive(Debug,Serialize,Deserialize)] @@ -242,6 +244,11 @@ pub trait PieceTrait: PieceBaseTrait + Send + Debug + 'static { None } + fn op_multigrab(&self, _: ApiPieceOpArgs, _: PieceRenderInstructions, + _: MultigrabQty) -> Result { + Err(Ia::BadPieceStateForOperation)? + } + #[throws(IE)] fn abs_bbox(&self, p: &GPiece) -> Rect { Rect { corners: self.bbox_approx()?.corners.iter().map( -- 2.30.2