From: Ian Jackson Date: Wed, 24 Mar 2021 18:18:47 +0000 (+0000) Subject: deck: Add label facility, giving piece count when enabled X-Git-Tag: otter-0.5.0~451 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=139c4b99a13770ca9c53d77afacb0b2675ad42e3;p=otter.git deck: Add label facility, giving piece count when enabled Signed-off-by: Ian Jackson --- diff --git a/src/deck.rs b/src/deck.rs index 6733373c..e0b171c0 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -11,6 +11,7 @@ pub const DISABLED_DESC: &str = "a pickup deck (disabled)"; #[derive(Debug,Serialize,Deserialize)] struct Deck { shape: GenericSimpleShape<(), shapelib::Rectangle>, + label: Option, } #[derive(Debug,Clone,Copy,Ord,PartialOrd,Eq,PartialEq)] @@ -56,6 +57,7 @@ impl PieceSpec for piece_specs::Deck { } let p = Box::new(Deck { shape, + label: self.label.clone(), }) as Box; PieceSpecLoaded { p, occultable: None } } @@ -76,9 +78,19 @@ impl PieceTrait for Deck { fn nfaces(&self) -> RawFaceId { 1 } #[throws(IE)] fn svg_piece(&self, f: &mut Html, gpc: &GPiece, - _gs: &GameState, _vpid: VisiblePieceId) { + gs: &GameState, _vpid: VisiblePieceId) { let face = self.current_face(gpc); self.shape.svg_piece_raw(f, face, &mut |_|Ok::<_,IE>(()))?; + if_chain! { + if let Some(label) = &self.label; + if let Some(count) = gpc.occult.active_total_ppieces(&gs.occults)?; + then { + label.svg(f, + &self.shape.outline, + self.shape.edges.get(0), + &Html(count.to_string()))?; + } + } } #[throws(IE)] diff --git a/src/spec.rs b/src/spec.rs index 4ad6e1a0..d5735804 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -267,6 +267,7 @@ pub mod piece_specs { #[serde(default)] pub edges: IndexVec, pub edge_width: Option, pub shape: Outline, + pub label: Option, } }