chiark / gitweb /
PieceLabel: Properly run through the colour checker
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 29 Mar 2021 19:44:35 +0000 (20:44 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 29 Mar 2021 19:44:35 +0000 (20:44 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/deck.rs
src/hand.rs
src/pieces.rs

index f9eb1606c2846441523311f849238d50e03ed96e..86c3d9df6541aaa76afb9bd00b7ebe88e60739f8 100644 (file)
@@ -12,7 +12,7 @@ pub const ENABLED_DESC: &str = "a pickup deck (enabled)";
 #[derive(Debug,Serialize,Deserialize)]
 struct Deck {
   shape: GenericSimpleShape<(), RectShape>,
-  label: Option<piece_specs::PieceLabel>,
+  label: Option<PieceLabelLoaded>,
 }
 
 #[derive(Debug,Clone,Copy,Ord,PartialOrd,Eq,PartialEq)]
@@ -60,7 +60,7 @@ impl PieceSpec for piece_specs::Deck {
     }
     let p = Box::new(Deck {
       shape,
-      label: self.label.clone(),
+      label: self.label.load()?,
     }) as Box<dyn PieceTrait>;
     PieceSpecLoaded { p, occultable: None }
   }
index eeedbd7b5fab32be36a2ea457bb168d5ec93cca1..e35be6376ea81c64148530d0ba3cb26cea9b6664 100644 (file)
@@ -3,7 +3,6 @@
 // There is NO WARRANTY.
 
 use crate::prelude::*;
-use piece_specs::PieceLabel;
 
 pub const UNCLAIMED_DESC: &str = "a hand repository";
 
@@ -17,7 +16,7 @@ struct MagicOwner {
 #[derive(Debug,Serialize,Deserialize)]
 struct Hand {
   shape: GenericSimpleShape<(), RectShape>,
-  label: Option<PieceLabel>,
+  label: Option<PieceLabelLoaded>,
 }
 
 #[derive(Debug,Clone,Default,Serialize,Deserialize)]
@@ -70,7 +69,7 @@ impl PieceSpec for piece_specs::Hand {
       &common)?;
     let p = Box::new(Hand {
       shape,
-      label: self.label.clone(),
+      label: self.label.load()?,
     }) as Box<dyn PieceTrait>;
     PieceSpecLoaded { p, occultable: None }
   }
index 9befa20eae34954415bb63829ed25dc85ad9bd48..b1546741f79852ac6812bda1b65b71f58c243845 100644 (file)
@@ -149,7 +149,30 @@ impl PieceTrait for SimpleShape {
   fn itemname(&self) -> &str { self.itemname() }
 }
 
+#[derive(Debug,Clone,Serialize,Deserialize)]
+pub struct PieceLabelLoaded {
+  #[serde(default)] pub place: piece_specs::PieceLabelPlace,
+  pub colour: Option<Colour>,
+}
+
 impl piece_specs::PieceLabel {
+  #[throws(SpecError)]
+  pub fn load(&self) -> PieceLabelLoaded {
+    let Self { place, ref colour } = *self;
+    let colour = colour.as_ref().map(|c| c.try_into()).transpose()?;
+    PieceLabelLoaded { place, colour }
+  }
+}  
+
+#[ext(pub)]
+impl Option<piece_specs::PieceLabel> {
+  #[throws(SpecError)]
+  fn load(&self) -> Option<PieceLabelLoaded> {
+    self.as_ref().map(|l| l.load()).transpose()?
+  }
+}
+
+impl PieceLabelLoaded {
   #[throws(IE)]
   pub fn svg(&self, f: &mut Html,
              outline: &RectShape,