chiark / gitweb /
deck: Add label facility, giving piece count when enabled
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 18:18:47 +0000 (18:18 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 24 Mar 2021 18:19:20 +0000 (18:19 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/deck.rs
src/spec.rs

index 6733373c4437041f954eac29b9da9072a735c252..e0b171c010606df5057421665a376056f7b2af22 100644 (file)
@@ -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<piece_specs::PieceLabel>,
 }
 
 #[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<dyn PieceTrait>;
     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)]
index 4ad6e1a0879b1d4bb7d15b292115856b2b7eb1a1..d573580448ba8de3f642ffa52c01f2ed7e026eb1 100644 (file)
@@ -267,6 +267,7 @@ pub mod piece_specs {
     #[serde(default)] pub edges: IndexVec<FaceId, ColourSpec>,
     pub edge_width: Option<f64>,
     pub shape: Outline,
+    pub label: Option<PieceLabel>,
   }
 }