From: Ian Jackson Date: Mon, 18 Apr 2022 10:07:55 +0000 (+0100) Subject: split PieceSpecLoaded X-Git-Tag: otter-1.1.0~486 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e9c0972b12049fb593228131c2a42af0068f56b3;p=otter.git split PieceSpecLoaded We are goint to want to add a field to only the non-inert version, so this generic is not applicable any more. Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index dd59a4a8..77468fbf 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -1110,7 +1110,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>( last_released: default(), rotateable: true, }; - let PieceSpecLoaded { p, occultable } = + let SpecLoaded { p, occultable } = info.load(piece_i as usize, &mut gpc, ig, SpecDepth::zero())?; if p.nfaces() <= face.into() { throw!(SpecError::FaceNotFound); diff --git a/src/clock.rs b/src/clock.rs index 886a13b0..2b1eb47f 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -405,7 +405,7 @@ fn unprepared_update(piece: PieceId) -> UnpreparedUpdates { impl PieceSpec for Spec { #[throws(SpecError)] fn load(&self, _: usize, gpc: &mut GPiece, _ig: &Instance, _:SpecDepth) - -> PieceSpecLoaded { + -> SpecLoaded { if self.time <= 0 { throw!(SpecError::NegativeTimeout) } let clock = Clock { @@ -414,7 +414,7 @@ impl PieceSpec for Spec { gpc.xdata_mut(|| State::new(self) )?; - PieceSpecLoaded { + SpecLoaded { p: Box::new(clock), occultable: None, } diff --git a/src/currency.rs b/src/currency.rs index 03a1a02b..04dc23a0 100644 --- a/src/currency.rs +++ b/src/currency.rs @@ -42,12 +42,12 @@ pub struct Banknote { impl PieceSpec for Spec { #[throws(SpecError)] fn load(&self, _: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth) - -> PieceSpecLoaded { + -> SpecLoaded { gpc.rotateable = false; let Spec { ref image, ref currency, qty, min_unit } = *self; - let SpecLoaded { p: image, occultable:_ } = + let SpecLoadedInert { p: image, occultable:_ } = image.load_inert(ig, depth)?; let itemname = format!("currency-{}", image.itemname()); diff --git a/src/deck.rs b/src/deck.rs index d466eee3..e31de48e 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -38,7 +38,7 @@ impl OutlineTrait for Deck { impl PieceSpec for piece_specs::Deck { #[throws(SpecError)] fn load(&self, _: usize, gpc: &mut GPiece, _ig: &Instance, _:SpecDepth) - -> PieceSpecLoaded { + -> SpecLoaded { let common = SimpleCommon { itemname: None, faces: self.faces.clone(), @@ -68,7 +68,7 @@ impl PieceSpec for piece_specs::Deck { shape, label: self.label.load()?, }) as Box; - PieceSpecLoaded { + SpecLoaded { p, occultable: None, } diff --git a/src/dice.rs b/src/dice.rs index a43c3e63..6c72dcc5 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -99,10 +99,10 @@ struct OverlayTemplateContext<'c> { impl PieceSpec for Spec { #[throws(SpecError)] fn load(&self, _: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth) - -> PieceSpecLoaded { + -> SpecLoaded { gpc.rotateable = false; - let SpecLoaded { p: image, occultable: img_occultable } = + let SpecLoadedInert { p: image, occultable: img_occultable } = self.image.load_inert(ig, depth)?; let mut nfaces: Option<(RawFaceId, &'static str)> = None; @@ -183,7 +183,7 @@ impl PieceSpec for Spec { let occultable = match (img_occultable, &self.occult) { (None, None) => None, (None, Some(occ)) => { - let SpecLoaded { p: image, occultable: image_occ_reload } = + let SpecLoadedInert { p: image, occultable: image_occ_reload } = self.image.load_inert(ig, depth)?; if image_occ_reload.is_some() { @@ -221,7 +221,7 @@ impl PieceSpec for Spec { image: image.into() }; - PieceSpecLoaded { + SpecLoaded { p: Box::new(die) as _, occultable, } diff --git a/src/gamestate.rs b/src/gamestate.rs index 71d6af67..aa1a55a6 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -280,11 +280,16 @@ pub struct ApiPieceOpArgs<'a> { } #[derive(Debug)] -pub struct SpecLoaded { - pub p: Box, +pub struct SpecLoaded { + pub p: Box, pub occultable: PieceSpecLoadedOccultable, } -pub type PieceSpecLoaded = SpecLoaded; +#[derive(Debug)] +pub struct SpecLoadedInert { + pub p: Box, + pub occultable: PieceSpecLoadedOccultable, +} + pub type PieceSpecLoadedOccultable = Option<(LOccultIlk, Arc)>; @@ -293,10 +298,10 @@ pub trait PieceSpec: Debug + Sync + Send + 'static { #[throws(SpecError)] fn count(&self, _pcaliases: &PieceAliases) -> usize { 1 } fn load(&self, i: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth) - -> Result; + -> Result; /// Used when a piece wants to use another for its occulted form fn load_inert(&self, _ig: &Instance, _:SpecDepth) - -> Result, SpecError> { + -> Result { throw!(SpE::ComplexPieceWhereInertRequired) } } diff --git a/src/hand.rs b/src/hand.rs index 42994149..5ed96ae0 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -88,7 +88,7 @@ impl OutlineTrait for Hand { impl piece_specs::OwnedCommon { #[throws(SpecError)] - fn load(&self, behaviour: Behaviour) -> PieceSpecLoaded { + fn load(&self, behaviour: Behaviour) -> SpecLoaded { let common = SimpleCommon { itemname: None, faces: index_vec![self.colour.clone()], @@ -108,7 +108,7 @@ impl piece_specs::OwnedCommon { shape, behaviour, label: self.label.load()?, }) as Box; - PieceSpecLoaded { + SpecLoaded { p, occultable: None, } @@ -119,7 +119,7 @@ impl piece_specs::OwnedCommon { impl PieceSpec for piece_specs::Hand { #[throws(SpecError)] fn load(&self, _: usize, gpc: &mut GPiece, _ig: &Instance, _:SpecDepth) - -> PieceSpecLoaded { + -> SpecLoaded { gpc.moveable = PieceMoveable::IfWresting; gpc.rotateable = false; self.c.load(Behaviour::Hand)? @@ -130,7 +130,7 @@ impl PieceSpec for piece_specs::Hand { impl PieceSpec for piece_specs::PlayerLabel { #[throws(SpecError)] fn load(&self, _: usize, _: &mut GPiece, _ig: &Instance, _:SpecDepth) - -> PieceSpecLoaded { + -> SpecLoaded { self.c.load(Behaviour::PlayerLabel)? } } diff --git a/src/pcaliases.rs b/src/pcaliases.rs index 9d4f30ee..e123adb8 100644 --- a/src/pcaliases.rs +++ b/src/pcaliases.rs @@ -65,14 +65,13 @@ impl PieceSpec for Alias { } #[throws(SpecError)] fn load(&self, i: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth) - -> PieceSpecLoaded { + -> SpecLoaded { let r = self.resolve(&ig.pcaliases)? .load(i, gpc, ig, self.new_depth(depth)?)?; r } #[throws(SpecError)] - fn load_inert(&self, ig: &Instance, depth: SpecDepth) - -> SpecLoaded { + fn load_inert(&self, ig: &Instance, depth: SpecDepth) -> SpecLoadedInert { self.resolve(&ig.pcaliases)?.load_inert(ig, self.new_depth(depth)?)? } } diff --git a/src/pieces.rs b/src/pieces.rs index e06d8e39..b353037a 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -354,17 +354,16 @@ macro_rules! impl_PieceSpec_for_SimplePieceSpec { { $ty:ty } => { impl PieceSpec for $ty { #[throws(SpecError)] fn load(&self, _: usize, _: &mut GPiece, _ig: &Instance, _:SpecDepth) - -> PieceSpecLoaded { - PieceSpecLoaded { + -> SpecLoaded { + SpecLoaded { p: Box::new(self.load_raw()?.0), occultable: None, } } #[throws(SpecError)] - fn load_inert(&self, _ig: &Instance, _:SpecDepth) - -> SpecLoaded { - SpecLoaded { + fn load_inert(&self, _ig: &Instance, _:SpecDepth) -> SpecLoadedInert { + SpecLoadedInert { p: Box::new(self.load_raw()?.0) as _, occultable: None } diff --git a/src/shapelib.rs b/src/shapelib.rs index b075722c..3eee455c 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -488,9 +488,9 @@ impl<'ig> AllRegistries<'ig> { pub type ItemSpecLoaded = (Box, PieceSpecLoadedOccultable); -impl From for PieceSpecLoaded { - fn from((p, occultable): ItemSpecLoaded) -> PieceSpecLoaded { - PieceSpecLoaded { +impl From for SpecLoaded { + fn from((p, occultable): ItemSpecLoaded) -> SpecLoaded { + SpecLoaded { p, occultable, } @@ -654,14 +654,13 @@ impl Contents { impl PieceSpec for ItemSpec { #[throws(SpecError)] fn load(&self, _: usize, _: &mut GPiece, ig: &Instance, depth: SpecDepth) - -> PieceSpecLoaded { + -> SpecLoaded { self.find_load(ig,depth)?.into() } #[throws(SpecError)] - fn load_inert(&self, ig: &Instance, depth: SpecDepth) - -> SpecLoaded { + fn load_inert(&self, ig: &Instance, depth: SpecDepth) -> SpecLoadedInert { let (p, occultable) = self.find_load(ig,depth)?; - SpecLoaded { p: p as _, occultable } + SpecLoadedInert { p: p as _, occultable } } } @@ -672,7 +671,7 @@ impl PieceSpec for MultiSpec { #[throws(SpecError)] fn load(&self, i: usize, _: &mut GPiece, ig: &Instance, depth:SpecDepth) - -> PieceSpecLoaded + -> SpecLoaded { let item = self.items.get(i).ok_or_else( || SpE::InternalError(format!("item {:?} from {:?}", i, &self))