From: Ian Jackson Date: Mon, 29 Mar 2021 19:44:35 +0000 (+0100) Subject: PieceLabel: Properly run through the colour checker X-Git-Tag: otter-0.5.0~384 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e467317665029b3c4e2f104e627380a7fe6df966;p=otter.git PieceLabel: Properly run through the colour checker Signed-off-by: Ian Jackson --- diff --git a/src/deck.rs b/src/deck.rs index f9eb1606..86c3d9df 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -12,7 +12,7 @@ pub const ENABLED_DESC: &str = "a pickup deck (enabled)"; #[derive(Debug,Serialize,Deserialize)] struct Deck { shape: GenericSimpleShape<(), RectShape>, - label: Option, + label: Option, } #[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; PieceSpecLoaded { p, occultable: None } } diff --git a/src/hand.rs b/src/hand.rs index eeedbd7b..e35be637 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -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, + label: Option, } #[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; PieceSpecLoaded { p, occultable: None } } diff --git a/src/pieces.rs b/src/pieces.rs index 9befa20e..b1546741 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -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, +} + 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 { + #[throws(SpecError)] + fn load(&self) -> Option { + self.as_ref().map(|l| l.load()).transpose()? + } +} + +impl PieceLabelLoaded { #[throws(IE)] pub fn svg(&self, f: &mut Html, outline: &RectShape,