chiark / gitweb /
Pass ApiPieceOpArgs to ui_operation
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Feb 2021 11:30:21 +0000 (11:30 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Feb 2021 11:30:21 +0000 (11:30 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/gamestate.rs
src/hand.rs

index afa9a30d9514674f4dd35fa3bfa61f005801ca76..ef892f3c0ce390f319bff9f09444ad66fea376c5 100644 (file)
@@ -35,14 +35,6 @@ struct ApiPiece<O:ApiPieceOp> {
   op: O,
 }
 
-struct ApiPieceOpArgs<'a> {
-  gs: &'a mut GameState,
-  ipieces: &'a PiecesLoaded,
-  player: PlayerId,
-  piece: PieceId,
-  p: &'a dyn Piece,
-}
-
 trait ApiPieceOp: Debug {
   #[throws(ApiPieceOpError)]
   fn op(&self, a: ApiPieceOpArgs) -> PieceUpdate;
@@ -408,8 +400,9 @@ api_route!{
     wrc: WhatResponseToClientOp,
   }
   #[throws(ApiPieceOpError)]
-  fn op(&self, a: ApiPieceOpArgs) -> PieceUpdate {
-    let ApiPieceOpArgs { gs,player,piece,p,ipieces, .. } = a;
+  fn op(&self, mut a: ApiPieceOpArgs) -> PieceUpdate {
+    let ApiPieceOpArgs { player,piece,p, .. } = a;
+    let gs = &mut a.gs;
     '_normal_global_ops__not_loop: loop {
       let pc = gs.pieces.byid_mut(piece)?;
       let gpl = gs.players.byid_mut(player)?;
@@ -439,7 +432,7 @@ api_route!{
       };
     }
 
-    p.ui_operation(gs, ipieces, player, piece, &self.opname, self.wrc)?
+    p.ui_operation(a, &self.opname, self.wrc)?
   }
 }
 
index 4cf6340b787572009390912f46f21004b21eda41..c091edc2d97e7b0c7cf97acf532b8c56d1a0d788 100644 (file)
@@ -147,9 +147,7 @@ pub trait Piece: Outline + Send + Debug {
   fn add_ui_operations(&self, _upd: &mut Vec<UoDescription>,
                        _gpc: &PieceState) { }
 
-  fn ui_operation(&self,
-                  _gs: &mut GameState, _ipieces: &PiecesLoaded,
-                  _player: PlayerId, _piece: PieceId,
+  fn ui_operation(&self, _a: ApiPieceOpArgs<'_>,
                   _opname: &str, _wrc: WhatResponseToClientOp)
                   -> PieceUpdateResult {
     throw!(OE::BadOperation)
@@ -170,6 +168,15 @@ pub trait Piece: Outline + Send + Debug {
   fn itemname(&self) -> &str;
 }
 
+#[derive(Debug)]
+pub struct ApiPieceOpArgs<'a> {
+  pub gs: &'a mut GameState,
+  pub ipieces: &'a PiecesLoaded,
+  pub player: PlayerId,
+  pub piece: PieceId,
+  pub p: &'a dyn Piece,
+}
+
 #[derive(Debug,Clone)]
 pub struct PieceRenderInstructions {
   pub id: VisiblePieceId,
index a7e7e08d3d5bf4882a3210af309187326e19df33..12601914f192fcbe83d452498c6074097b9a632d 100644 (file)
@@ -127,10 +127,10 @@ impl Piece for Hand {
     })
   }
 
-  fn ui_operation(&self, gs: &mut GameState, _ipieces: &PiecesLoaded,
-                  player: PlayerId, piece: PieceId,
+  fn ui_operation(&self, a: ApiPieceOpArgs<'_>,
                   opname: &str, wrc: WhatResponseToClientOp)
                   -> PieceUpdateResult {
+    let ApiPieceOpArgs { gs, player, piece, ..} = a;
     let gplayers = &mut gs.players;
     let gpc = gs.pieces.byid_mut(piece)?;
     let xdata = gpc.xdata.get_mut::<HandState>()