chiark / gitweb /
multigrab/fastsplit: Plumb ShowUnocculted and &PieceTrait
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 30 Apr 2022 01:21:05 +0000 (02:21 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 30 Apr 2022 14:15:30 +0000 (15:15 +0100)
The implementation doesn't really want PieceRenderingInstructions,
just permission to get at trait objects.

The currency fastsplit implementation callback is going to want to
look at its Banknote so that it can make a nice log message.  I think
fastsplit piece impls are entitled access to their concret piece type.
So downcast it, and pass it down the layers.

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

index 24c4f94f9607f4d839413c720b9bed0754d5d046..7ad73c400e80a7dfb835cec853ce3646883af878 100644 (file)
@@ -584,7 +584,7 @@ api_route!{
       if gpc.held != None { throw!(Ia::PieceHeld) }
       if ! (self.z > gpc.zlevel.z) { throw!(Ia::BadPieceStateForOperation); }
       op_do_set_z(gpc, a.gs.gen, &self.z)?;
-      a.ipc.show(y).op_multigrab(a, pri, self.n, &self.z).map_err(|e| match e {
+      a.ipc.show(y).op_multigrab(a, y, self.n, &self.z).map_err(|e| match e {
         // TODO: The error handling is wrong, here.  If op_multigrab
         // returns a deferred thunk, the APOE::PartiallyProcessed will
         // not be applked.
index 2b3ef97e435c2ac68a50c9687e55a32a7f295623..70f77f2d20e9cd2f1fc30f4a3793894c37a5e75c 100644 (file)
@@ -123,16 +123,16 @@ impl PieceTrait for Banknote {
   }
 
   #[throws(ApiPieceOpError)]
-  fn op_multigrab(&self, _: ApiPieceOpArgs, _: PieceRenderInstructions,
+  fn op_multigrab(&self, _: ApiPieceOpArgs, show: ShowUnocculted,
                   take: MultigrabQty, new_z: &ZCoord) -> OpOutcomeThunk {
     let currency = self.currency.clone();
     let new_z = new_z.clone();
     OpOutcomeThunk::Reborrow(Box::new(
       move |ig: &mut InstanceGuard, player: PlayerId, tpiece: PieceId|
   {
-    ig.fastsplit_split(player, tpiece, new_z,
+    ig.fastsplit_split(player, tpiece, show, new_z,
       move |ioccults: &IOccults, goccults: &GameOccults, gpl: &GPlayer,
-            tgpc: &mut GPiece, tipc: &IPiece,
+            tgpc: &mut GPiece, tipc: &IPiece, _tipc_p: &dyn PieceTrait,
             ngpc: &mut GPiece|
   {
     let tgpc_value: &mut Value = tgpc.xdata.get_mut_exp()?;
index ae9d386a9676a3d79b35e2437af7c166c665bbc5..2c084fdd9d6903060a5c9a6ff08ee8a7e0358b86 100644 (file)
@@ -83,11 +83,12 @@ impl InstanceGuard<'_> {
   #[throws(ApiPieceOpError)]
   pub fn fastsplit_split<I>(
     &mut self, player: PlayerId,
-    tpiece: PieceId, new_z: ZCoord,
+    tpiece: PieceId, show: ShowUnocculted, new_z: ZCoord,
     implementation: I
   ) -> UpdateFromOpComplex
   where I: FnOnce(&IOccults, &GameOccults, &GPlayer,
-                  &mut GPiece, &IPiece, &mut GPiece)
+                  &mut GPiece, &IPiece, &dyn PieceTrait,
+                  &mut GPiece)
                   -> Result<UpdateFromOpComplex, ApiPieceOpError>
   {
     // The "save later" part of this ought to be unnecessarily, because
@@ -123,9 +124,16 @@ impl InstanceGuard<'_> {
       fastsplit:     tgpc.fastsplit,
     };
 
+    let tipc_p = (||{
+      let p = tipc.p.show(show);
+      let p: &Piece = p.downcast_ref::<Piece>()?;
+      let p = p.ipc.as_ref()?.p.show(show);
+      Some(p)
+    })().ok_or_else(|| internal_error_bydebug(tipc))?;
+
     let (t_pu, t_unprepared) = implementation(
       &ig.ioccults, &ig.gs.occults, gpl,
-      tgpc, tipc,
+      tgpc, tipc, tipc_p,
       &mut ngpc
     )?;
 
index 242aa00b84916b0527e793108a5e25d966228c15..5ef3a5cbc034aa0b56b504eb0b60931cbb643faf 100644 (file)
@@ -273,7 +273,7 @@ pub trait PieceTrait: PieceBaseTrait + Downcast + Send + Debug + 'static {
   // one will do.
   //
   // So the multigrab operation specifies a ZCoord.
-  fn op_multigrab(&self, _a: ApiPieceOpArgs, _pri: PieceRenderInstructions,
+  fn op_multigrab(&self, _a: ApiPieceOpArgs, _show: ShowUnocculted,
                   _qty: MultigrabQty, _new_z: &ZCoord)
                   -> Result<OpOutcomeThunk,ApiPieceOpError>  {
     Err(Ia::BadPieceStateForOperation)?