From: Ian Jackson Date: Mon, 18 Apr 2022 10:20:12 +0000 (+0100) Subject: Move special rendering instructions to PieceSpecialProperties X-Git-Tag: otter-1.1.0~484 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=6b975afddf5baa83d882b44bfa0a5560fce8d85b;p=otter.git Move special rendering instructions to PieceSpecialProperties This gets rid of an ipc method (meaning we get rid of one method call during piece rendering) and is also more principled, than a call which might conceivably give different answers at different times. Signed-off-by: Ian Jackson --- diff --git a/src/dice.rs b/src/dice.rs index 1701b52c..76fb300a 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -221,10 +221,14 @@ impl PieceSpec for Spec { image: image.into() }; + let special = PieceSpecialProperties { + rendering: Some(SpecialClientRendering::Die{}), + ..default() + }; SpecLoaded { p: Box::new(die) as _, occultable, - special: default(), + special, } } } @@ -315,11 +319,6 @@ impl PieceBaseTrait for Die { fn nfaces(&self) -> RawFaceId { self.nfaces } fn itemname(&self) -> &str { &self.itemname } - - #[throws(IE)] - fn special(&self) -> Option { - Some(SpecialClientRendering::Die{}) - } } #[typetag::serde(name="Die")] diff --git a/src/gamestate.rs b/src/gamestate.rs index 85b7e011..1eaf95b1 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -181,12 +181,6 @@ pub trait PieceBaseTrait: OutlineTrait + Send + Debug + 'static { fn nfaces(&self) -> RawFaceId; fn itemname(&self) -> &str; - - // Don't add an xdata argument to this. Implementors must not make - // this depend on the piece state, because the piece state might change - // between svg() (which sets up information in the DOM) and special() - // (which arranges to use that information). - fn special(&self) -> Result,IE> { Ok(None) } } #[typetag::serde] // usual variable: p @@ -300,6 +294,7 @@ pub type PieceSpecLoadedOccultable = /// so they are mostly "can/do we do this thing". #[derive(Debug,Clone,Default,Serialize,Deserialize)] pub struct PieceSpecialProperties { + pub rendering: Option, } #[typetag::serde(tag="type")] diff --git a/src/pcrender.rs b/src/pcrender.rs index f41aa71d..c29b3387 100644 --- a/src/pcrender.rs +++ b/src/pcrender.rs @@ -13,7 +13,7 @@ pub struct VisibleAngleTransform(Html); const DEFKEY_FLIP: UoKey = 'f'; -#[derive(Serialize,Debug)] +#[derive(Deserialize,Serialize,Clone,Debug)] #[serde(tag="kind")] pub enum SpecialClientRendering { Die { }, @@ -194,7 +194,6 @@ impl PieceRenderInstructions { let angle = pri.angle(gpc); let bbox = o.bbox_approx()?; - let special = o.special()?; let dragraise = match o.thresh_dragraise()? { Some(n) if n < 0 => throw!(SvgE::NegativeDragraise), @@ -208,7 +207,7 @@ impl PieceRenderInstructions { hwrite!(&mut defs, r##"