From: Ian Jackson Date: Sat, 27 Feb 2021 11:30:21 +0000 (+0000) Subject: Pass ApiPieceOpArgs to ui_operation X-Git-Tag: otter-0.4.0~325 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=b7910d258716708307bbd9da21193544465e9583;p=otter.git Pass ApiPieceOpArgs to ui_operation Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index afa9a30d..ef892f3c 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -35,14 +35,6 @@ struct ApiPiece { 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)? } } diff --git a/src/gamestate.rs b/src/gamestate.rs index 4cf6340b..c091edc2 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -147,9 +147,7 @@ pub trait Piece: Outline + Send + Debug { fn add_ui_operations(&self, _upd: &mut Vec, _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, diff --git a/src/hand.rs b/src/hand.rs index a7e7e08d..12601914 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -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::()