From: Ian Jackson Date: Mon, 18 Apr 2022 12:08:44 +0000 (+0100) Subject: api: Introduce and use ApiPieceOpArgs::pri X-Git-Tag: otter-1.1.0~487 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=b32c89cbd9ad86e47d873bf20964111c7ed12975;p=otter.git api: Introduce and use ApiPieceOpArgs::pri We're going to have a new call site, too. Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index c5e0850f..206b9a70 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -320,7 +320,8 @@ api_route!{ impl op::Simple as { #[throws(ApiPieceOpError)] - fn op(&self, a: ApiPieceOpArgs) -> PieceUpdate { + fn op(&self, mut a: ApiPieceOpArgs) -> PieceUpdate { + let pri = a.pri()?; let ApiPieceOpArgs { gs,ioccults,player,piece,ipc, .. } = a; let gpc = gs.pieces.byid_mut(piece)?; let players = &mut gs.players; @@ -329,8 +330,6 @@ api_route!{ let was = was.map(|was| htmlescape::encode_minimal(&was.nick)); let gpl = players.byid_mut(player)?; - let pri = piece_pri(ioccults, &gs.occults, player, gpl, piece, gpc, ipc) - .ok_or(Ia::PieceGone)?; let pcs = pri.describe(ioccults,&gs.occults, gpc, ipc); @@ -575,13 +574,9 @@ api_route!{ impl op::Complex as { #[throws(ApiPieceOpError)] fn op_complex(&self, mut a: ApiPieceOpArgs) -> UpdateFromOpComplex { + let pri = a.pri()?; let ApiPieceOpArgs { ioccults,player,piece,ipc, .. } = a; let gs = &mut a.gs; - let pri = piece_pri(ioccults, &gs.occults, - player, gs.players.byid_mut(player)?, - piece, gs.pieces.byid(piece)?, - ipc) - .ok_or(Ia::PieceGone)?; let y = pri.fully_visible().ok_or(Ia::Occultation)?; '_normal_global_ops__not_loop: loop { diff --git a/src/gamestate.rs b/src/gamestate.rs index 9f2f3399..71d6af67 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -396,6 +396,19 @@ impl From> for MgmtError { fn from(pote: PosOffTableError) -> MgmtError { ME::BadSpec(pote.into()) } } +// ---------- ApiPieceOpArgs ---------- + +impl ApiPieceOpArgs<'_> { + #[throws(ApiPieceOpError)] + pub fn pri(&mut self) -> PieceRenderInstructions { + let ApiPieceOpArgs { gs,ioccults,player,piece,ipc, .. } = self; + let gpc = gs.pieces.byid(*piece)?; + let gpl = gs.players.byid_mut(*player)?; + piece_pri(ioccults, &gs.occults, *player, gpl, *piece, gpc, ipc) + .ok_or(Ia::PieceGone)? + } +} + // ---------- game state - rendering etc. ---------- impl GPiece {