#[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)]
}
let p = Box::new(Deck {
shape,
- label: self.label.clone(),
+ label: self.label.load()?,
}) as Box<dyn PieceTrait>;
PieceSpecLoaded { p, occultable: None }
}
// There is NO WARRANTY.
use crate::prelude::*;
-use piece_specs::PieceLabel;
pub const UNCLAIMED_DESC: &str = "a hand repository";
#[derive(Debug,Serialize,Deserialize)]
struct Hand {
shape: GenericSimpleShape<(), RectShape>,
- label: Option<PieceLabel>,
+ label: Option<PieceLabelLoaded>,
}
#[derive(Debug,Clone,Default,Serialize,Deserialize)]
&common)?;
let p = Box::new(Hand {
shape,
- label: self.label.clone(),
+ label: self.label.load()?,
}) as Box<dyn PieceTrait>;
PieceSpecLoaded { p, occultable: None }
}
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,