chiark / gitweb /
Plumbing for "multigrab" piece API call
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 18 Apr 2022 12:00:56 +0000 (13:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 18 Apr 2022 12:35:29 +0000 (13:35 +0100)
We can now pass this through to a piece.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/currency.rs
src/gamestate.rs

index 206b9a709f96e7ca9d9d6b9d97f83e8a028f55ca..54f242716a3cf3dd3266024d3c81fd5a489395ef 100644 (file)
@@ -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,
   ]
 }
index 29e632bfc067566f40df823d8c2a517fcd68c9cc..c14360b8042a0086acd49551eafd8744e7a6d42c 100644 (file)
@@ -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 {
index 68ea20cec8d37c98c21044b7bf219571906f0a76..701d5d0d654d36dccf466d7662cfe7387da4e0da 100644 (file)
@@ -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<PieceUpdate,ApiPieceOpError> {
+    Err(Ia::BadPieceStateForOperation)?
+  }
+
   #[throws(IE)]
   fn abs_bbox(&self, p: &GPiece) -> Rect {
     Rect { corners: self.bbox_approx()?.corners.iter().map(