From: Ian Jackson Date: Tue, 30 Mar 2021 20:10:17 +0000 (+0100) Subject: PlayerLabel: wip provide X-Git-Tag: otter-0.5.0~367 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=4a008c7b8b2b3a709e183648c042af607045afd8;p=otter.git PlayerLabel: wip provide Signed-off-by: Ian Jackson --- diff --git a/src/hand.rs b/src/hand.rs index 01f4f657..48681ca1 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -28,6 +28,7 @@ struct HandState { #[derive(Debug,Copy,Clone,Serialize,Deserialize)] enum Sort { Hand, + PlayerLabel, } type MkOccCA = fn(&OccDisplacement, &ZCoord) -> OccKA; @@ -36,22 +37,28 @@ impl Sort { fn backcompat_upgrade() -> Self { Sort::Hand } fn itemname(self) -> &'static str { use Sort::*; match self { Hand => "magic-hand", + PlayerLabel => "player-label", } } fn unclaimed_desc(self) -> HtmlLit { use Sort::*; Html::lit(match self { Hand => UNCLAIMED_HAND_DESC, + PlayerLabel => "unclaimed player label", }) } fn deact_desc(self) -> HtmlLit { use Sort::*; Html::lit(match self { Hand => "Deactivate hand", + PlayerLabel => "Relinquish player label", }) } fn claim_desc(self) -> HtmlLit { use Sort::*; Html::lit(match self { Hand => "Claim this as your hand", + PlayerLabel => "Claim player label", }) } fn owned_desc(self, nick: &HtmlStr) -> Html { use Sort::*; match self { Hand => hformat!("{}'s hand", nick), + PlayerLabel => hformat!("{}'s player label", nick), } } fn views(self) -> Option<(MkOccCA, MkOccCA)> { use Sort::*; match self { Hand => Some((|_,_| OccKA::Visible, |d,z| OccKA::Displaced((d.clone(), z.clone())))), + PlayerLabel => None, } } } @@ -113,6 +120,16 @@ impl PieceSpec for piece_specs::Hand { } } +#[typetag::serde] +impl PieceSpec for piece_specs::PlayerLabel { + #[throws(SpecError)] + fn load(&self, _: usize, _: &mut GPiece, + _pcaliases: &PieceAliases, _ir: &InstanceRef) + -> PieceSpecLoaded { + self.c.load(Sort::Hand)? + } +} + impl Sort { fn describe_html_inner(self, xdata: Option<&HandState>) -> Html { if_chain! { diff --git a/src/spec.rs b/src/spec.rs index c93b2f2c..ebdecf8a 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -244,6 +244,11 @@ pub mod piece_specs { #[serde(flatten)] pub c: OwnedCommon, } + #[derive(Debug,Serialize,Deserialize)] + pub struct PlayerLabel { + #[serde(flatten)] pub c: OwnedCommon, + } + #[derive(Debug,Serialize,Deserialize)] pub struct OwnedCommon { pub colour: ColourSpec,