From b133256e04f21ef6aead4feaa09977ffdfcef73c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 30 Apr 2022 02:21:05 +0100 Subject: [PATCH] multigrab/fastsplit: Plumb ShowUnocculted and &PieceTrait 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 --- daemon/api.rs | 2 +- src/currency.rs | 6 +++--- src/fastsplit.rs | 14 +++++++++++--- src/gamestate.rs | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/daemon/api.rs b/daemon/api.rs index 24c4f94f..7ad73c40 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -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. diff --git a/src/currency.rs b/src/currency.rs index 2b3ef97e..70f77f2d 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -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()?; diff --git a/src/fastsplit.rs b/src/fastsplit.rs index ae9d386a..2c084fdd 100644 --- a/src/fastsplit.rs +++ b/src/fastsplit.rs @@ -83,11 +83,12 @@ impl InstanceGuard<'_> { #[throws(ApiPieceOpError)] pub fn fastsplit_split( &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 { // 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::()?; + 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 )?; diff --git a/src/gamestate.rs b/src/gamestate.rs index 242aa00b..5ef3a5cb 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -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 { Err(Ia::BadPieceStateForOperation)? -- 2.30.2