From 580589f983398b487f9cb7438fb04faa0e1df72a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 24 Mar 2021 17:00:40 +0000 Subject: [PATCH] plumb goccults through to describe_html Signed-off-by: Ian Jackson --- daemon/api.rs | 12 ++++++------ daemon/cmdlistener.rs | 4 ++-- daemon/session.rs | 2 +- src/bin/otterlib.rs | 2 +- src/clock.rs | 4 ++-- src/deck.rs | 2 +- src/gamestate.rs | 3 ++- src/hand.rs | 2 +- src/hidden.rs | 4 ++-- src/pcrender.rs | 7 ++++--- src/pieces.rs | 2 +- src/shapelib.rs | 2 +- src/updates.rs | 10 ++++++---- 13 files changed, 30 insertions(+), 26 deletions(-) diff --git a/daemon/api.rs b/daemon/api.rs index 147c8b38..9f8ffb62 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -273,7 +273,7 @@ api_route!{ let gpc = gs.pieces.byid_mut(piece)?; let logents = log_did_to_piece( - ioccults,gpl,gpc,ipc, + ioccults,&gs.occults, gpl,gpc,ipc, "grasped" )?; @@ -311,7 +311,7 @@ api_route!{ let pri = piece_pri(ioccults, &gs.occults, player, gpl, piece, gpc, ipc) .ok_or(POE::PieceGone)?; - let pcs = pri.describe(ioccults, gpc, ipc).0; + let pcs = pri.describe(ioccults,&gs.occults, gpc, ipc).0; gpc.held = Some(player); @@ -345,7 +345,7 @@ api_route!{ let gpc = gs.pieces.byid_mut(piece).unwrap(); let (logents, who_by) = log_did_to_piece_whoby( - ioccults,gpl,gpc,ipc, + ioccults,&gs.occults,gpl,gpc,ipc, "released" )?; let who_by = who_by.ok_or(POE::PieceGone)?; @@ -453,7 +453,7 @@ api_route!{ let gpc = gs.pieces.byid_mut(piece).unwrap(); let gpl = gs.players.byid_mut(player).unwrap(); let logents = log_did_to_piece( - ioccults,gpl,gpc,ipc, + ioccults,&gs.occults,gpl,gpc,ipc, "rotated" )?; gpc.angle = PieceAngle::Compass(self.0); @@ -474,7 +474,7 @@ api_route!{ let gpc = gs.pieces.byid_mut(piece).unwrap(); let gpl = gs.players.byid_mut(player).unwrap(); let logents = log_did_to_piece( - ioccults,gpl,gpc,ipc, + ioccults,&gs.occults,gpl,gpc,ipc, if gpc.pinned { "pinned" } else { "unpinned" }, )?; gpc.forbid_involved_in_occultation()?; @@ -521,7 +521,7 @@ api_route!{ ("flip", wrc@ WRC::UpdateSvg) => { let nfaces = ipc.show(y).nfaces(); let logents = log_did_to_piece( - ioccults,gpl,gpc,ipc, + ioccults,&gs.occults,gpl,gpc,ipc, "flipped" )?; gpc.face = ((RawFaceId::from(gpc.face) + 1) % nfaces).into(); diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 5a832703..f5ee6e37 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -401,7 +401,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>( VisiblePieceId(piece.data()) ); let bbox = ipc.show(y).bbox_approx()?; - let desc_html = pri.describe(ioccults, gpc, ipc); + let desc_html = pri.describe(ioccults,&ig.gs.occults, gpc, ipc); Some(MgmtGamePieceVisibleInfo { pos, face, desc_html, bbox }) @@ -607,7 +607,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>( let gpc = gs.pieces.as_mut(modperm).remove(piece); let desc_html = if let Some(gpc) = &gpc { let pri = PieceRenderInstructions::new_visible(default()); - pri.describe(ioccults, gpc, &ipc) + pri.describe(ioccults,&gs.occults, gpc, &ipc) } else { Html::lit("<piece partially missing from game state!>") }; diff --git a/daemon/session.rs b/daemon/session.rs index cd20d1a7..ce68500e 100644 --- a/daemon/session.rs +++ b/daemon/session.rs @@ -127,7 +127,7 @@ fn session_inner(form: Json, let defs = pri.make_defs(ioccults, &ig.gs, gpc, ipc)?; alldefs.push((pri.vpid, defs)); - let desc = pri.describe(ioccults, &gpc, ipc); + let desc = pri.describe(ioccults,&ig.gs.occults, &gpc, ipc); let vangle = pri.angle(gpc).to_compass(); let (pos, zlevel) = pri.pos_zlevel(gpc); diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index 44c2d951..b99c0874 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -131,7 +131,7 @@ fn preview(items: Vec) { println!(r#"{}"#, Html::from_txt(&spec.item).0); println!(r#"{}"#, - p.describe_html(&GPiece::dummy())?.0); + p.describe_html(&GPiece::dummy(), &default())?.0); let only1 = s.face_cols() == 1; for facecol in 0..(if only1 { 1 } else { max_facecols }) { diff --git a/src/clock.rs b/src/clock.rs index 6b62b211..91faf833 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -533,7 +533,7 @@ impl PieceTrait for Clock { } #[throws(IE)] - fn describe_html(&self, _gpc: &GPiece) -> Html { + fn describe_html(&self, _gpc: &GPiece, _goccults: &GameOccults) -> Html { Html::lit("the chess clock") } @@ -681,7 +681,7 @@ impl PieceTrait for Clock { held, &self.spec, ig) .map_err(|e| APOE::ReportViaResponse(e.into()))?; - let log = log_did_to_piece(ioccults, gpl, gpc, ipc, &did) + let log = log_did_to_piece(ioccults,&gs.occults, gpl, gpc, ipc, &did) .unwrap_or_else(|e| { error!("failed to log: {:?}", &e); vec![LogEntry { html: Html::lit("<failed to log>") }] diff --git a/src/deck.rs b/src/deck.rs index 90fbc82f..ea85d5ec 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -75,7 +75,7 @@ impl PieceTrait for Deck { } #[throws(IE)] - fn describe_html(&self, gpc: &GPiece) -> Html { + fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) -> Html { Html::lit( if self.enabled(gpc) { ENABLED_DESC } else { DISABLED_DESC } ) diff --git a/src/gamestate.rs b/src/gamestate.rs index 18536042..93a7f822 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -141,7 +141,8 @@ pub trait PieceTrait: OutlineTrait + Send + Debug + 'static { fn svg_piece(&self, f: &mut Html, gpc: &GPiece, gs: &GameState, id: VisiblePieceId) -> Result<(),IE>; - fn describe_html(&self, gpc: &GPiece) -> Result; + fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) + -> Result; #[throws(IE)] /// Piece is responsible for dealing with the possibility that they diff --git a/src/hand.rs b/src/hand.rs index b8358919..ef188fed 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -118,7 +118,7 @@ impl PieceTrait for Hand { } #[throws(IE)] - fn describe_html(&self, gpc: &GPiece) -> Html { + fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) -> Html { let xdata = gpc.xdata.get()?; self.describe_html_inner(xdata) } diff --git a/src/hidden.rs b/src/hidden.rs index f9d00a6e..ae65d16c 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -535,7 +535,7 @@ fn recalculate_occultation_general< let ounocc = ogpc.fully_visible_to_everyone() .ok_or_else(||internal_error_bydebug(&(occulteds, &ogpc)))?; then { - Some(oipc.show(ounocc).describe_html(ogpc)?) + Some(oipc.show(ounocc).describe_html(ogpc, goccults)?) } else { None } @@ -554,7 +554,7 @@ fn recalculate_occultation_general< Some(prioc@ PriOG::Visible(_)) | Some(prioc@ PriOG::Occulted) | Some(prioc@ PriOG::Displaced(..)) => { - let show = prioc.describe(ioccults, gpc, ipc); + let show = prioc.describe(ioccults, goccults, gpc, ipc); call_log_callback(&show)? }, None => { diff --git a/src/pcrender.rs b/src/pcrender.rs index 77e9a0f2..2e5b016e 100644 --- a/src/pcrender.rs +++ b/src/pcrender.rs @@ -57,10 +57,10 @@ impl PriOccultedGeneral { } } - pub fn describe(&self, ioccults: &IOccults, + pub fn describe(&self, ioccults: &IOccults, goccults: &GameOccults, gpc: &GPiece, ipc: &IPiece) -> Html { - self.describe_fallible(ioccults, gpc, ipc) + self.describe_fallible(ioccults, goccults, gpc, ipc) .unwrap_or_else(|e| { error!("error describing piece: {:?}", e); Html::lit("<internal error describing piece>") @@ -69,9 +69,10 @@ impl PriOccultedGeneral { #[throws(IE)] pub fn describe_fallible(&self, ioccults: &IOccults, + goccults: &GameOccults, gpc: &GPiece, ipc: &IPiece) -> Html { match self.instead(ioccults, ipc)? { - Left(y) => ipc.show(y).describe_html(gpc)?, + Left(y) => ipc.show(y).describe_html(gpc, goccults)?, Right(i) => i.describe_html()?, } } diff --git a/src/pieces.rs b/src/pieces.rs index 7737011a..febc131d 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -134,7 +134,7 @@ impl PieceTrait for SimpleShape { self.svg_piece_raw(f, gpc.face, &mut |_|Ok(()))?; } #[throws(IE)] - fn describe_html(&self, gpc: &GPiece) -> Html { + fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) -> Html { Html(if_chain! { if let face = gpc.face; if let Some(colour) = self.colours.get(face); diff --git a/src/shapelib.rs b/src/shapelib.rs index d29137cf..d734096f 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -288,7 +288,7 @@ impl PieceTrait for Item { self.svg_face(f, gpc.face, vpid)?; } #[throws(IE)] - fn describe_html(&self, gpc: &GPiece) -> Html { + fn describe_html(&self, gpc: &GPiece, _goccults: &GameOccults) -> Html { self.describe_face(gpc.face)? } diff --git a/src/updates.rs b/src/updates.rs index bc14b6ea..5d0ba952 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -267,7 +267,8 @@ struct FormattedLogEntry<'u> { // ---------- helpful utilities ---------- #[throws(OE)] -pub fn log_did_to_piece_whoby(ioccults: &IOccults, by_gpl: &GPlayer, +pub fn log_did_to_piece_whoby(ioccults: &IOccults, goccults: &GameOccults, + by_gpl: &GPlayer, gpc: &GPiece, ipc: &IPiece, did: &str) -> (Vec, Option) { @@ -275,7 +276,7 @@ pub fn log_did_to_piece_whoby(ioccults: &IOccults, by_gpl: &GPlayer, let y = gpc.fully_visible_to_everyone(); let desc = (||{ Ok::<_,IE>(match ipc.show_or_instead(ioccults, y)? { - Left(y) => ipc.show(y).describe_html(gpc)?, + Left(y) => ipc.show(y).describe_html(gpc, goccults)?, Right(instead) => instead.describe_html()?, }) })().unwrap_or_else(|e|{ @@ -293,10 +294,11 @@ pub fn log_did_to_piece_whoby(ioccults: &IOccults, by_gpl: &GPlayer, } #[throws(OE)] -pub fn log_did_to_piece(ioccults: &IOccults, by_gpl: &GPlayer, +pub fn log_did_to_piece(ioccults: &IOccults, goccults: &GameOccults, + by_gpl: &GPlayer, gpc: &GPiece, ipc: &IPiece, did: &str) -> Vec { - log_did_to_piece_whoby(ioccults,by_gpl,gpc,ipc,did)?.0 + log_did_to_piece_whoby(ioccults,goccults,by_gpl,gpc,ipc,did)?.0 } // ---------- prepared updates, queued in memory ---------- -- 2.30.2