From: Ian Jackson Date: Tue, 30 Mar 2021 19:04:55 +0000 (+0100) Subject: hand generalisation: Introduce Sort X-Git-Tag: otter-0.5.0~372 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=2d0e9558b6d472ca5f939c781a1179b3dcf676fd;p=otter.git hand generalisation: Introduce Sort Signed-off-by: Ian Jackson --- diff --git a/src/hand.rs b/src/hand.rs index 3bdf39ba..53f7c1c1 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -17,6 +17,7 @@ struct MagicOwner { struct Hand { shape: GenericSimpleShape<(), RectShape>, label: Option, + #[serde(default="Sort::backcompat_upgrade")] sort: Sort, } #[derive(Debug,Clone,Default,Serialize,Deserialize)] @@ -24,6 +25,18 @@ struct HandState { owner: Option, } +#[derive(Debug,Copy,Clone,Serialize,Deserialize)] +enum Sort { + Hand, +} + +impl Sort { + fn backcompat_upgrade() -> Self { Sort::Hand } + fn itemname(self) -> &'static str { use Sort::*; match self { + Hand => "magic-hand", + } } +} + impl HandState { fn player(&self) -> Option { self.owner.as_ref().map(|o| o.player) @@ -46,12 +59,9 @@ impl OutlineTrait for Hand { } } -#[typetag::serde] -impl PieceSpec for piece_specs::Hand { +impl piece_specs::OwnedCommon { #[throws(SpecError)] - fn load(&self, _: usize, _: &mut GPiece, - _pcaliases: &PieceAliases, _ir: &InstanceRef) - -> PieceSpecLoaded { + fn load(&self, sort: Sort) -> PieceSpecLoaded { let common = SimpleCommon { itemname: None, faces: index_vec![self.colour.clone()], @@ -65,16 +75,26 @@ impl PieceSpec for piece_specs::Hand { let shape = GenericSimpleShape::new( (), shape, - "magic-hand", + sort.itemname(), &common)?; let p = Box::new(Hand { - shape, + shape, sort, label: self.label.load()?, }) as Box; PieceSpecLoaded { p, occultable: None } } } +#[typetag::serde] +impl PieceSpec for piece_specs::Hand { + #[throws(SpecError)] + fn load(&self, _: usize, _: &mut GPiece, + _pcaliases: &PieceAliases, _ir: &InstanceRef) + -> PieceSpecLoaded { + self.c.load(Sort::Hand)? + } +} + impl Hand { fn describe_html_inner(&self, xdata: Option<&HandState>) -> Html { if_chain! { diff --git a/src/spec.rs b/src/spec.rs index 164193c8..c93b2f2c 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -241,6 +241,11 @@ pub mod piece_specs { #[derive(Debug,Serialize,Deserialize)] pub struct Hand { + #[serde(flatten)] pub c: OwnedCommon, + } + + #[derive(Debug,Serialize,Deserialize)] + pub struct OwnedCommon { pub colour: ColourSpec, pub edge: Option, pub edge_width: Option,