chiark / gitweb /
Introduce PieceLoadArgs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 22 Apr 2022 18:26:29 +0000 (19:26 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 28 Apr 2022 22:56:17 +0000 (23:56 +0100)
So that we can add more parameters to PieceTrait::load() without
having to edit everywhere *again*.

In fact it turns out I don't need to do this right now (for currency
and fastsplit) but I think it's worth keeping.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/clock.rs
src/currency.rs
src/deck.rs
src/dice.rs
src/gamestate.rs
src/hand.rs
src/pcaliases.rs
src/pieces.rs
src/prelude.rs
src/shapelib.rs

index 3d49123dc1c064986921d76f90d265ed4d2ed417..73a0e766f516ad96a887ebd2aa25b8c44ec3b118 100644 (file)
@@ -1118,7 +1118,12 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
           rotateable: true,
         };
         let SpecLoaded { p, occultable, special } =
-          info.load(piece_i as usize, &mut gpc, ig, SpecDepth::zero())?;
+          info.load(PLA {
+            i: piece_i as usize,
+            gpc: &mut gpc,
+            ig,
+            depth: SpecDepth::zero(),
+          })?;
         if p.nfaces() <= face.into() {
           throw!(SpecError::FaceNotFound);
         }
index 95eabb7fdfb5c691af541c692281ed5aec055222..b8c49bc9e2ae977f51663446b6489d24ab3bd47e 100644 (file)
@@ -404,8 +404,7 @@ fn unprepared_update(piece: PieceId) -> UnpreparedUpdates {
 #[typetag::serde(name="ChessClock")]
 impl PieceSpec for Spec {
   #[throws(SpecError)]
-  fn load(&self, _: usize, gpc: &mut GPiece, _ig: &Instance, _:SpecDepth)
-          -> SpecLoaded {
+  fn load(&self, PLA { gpc,.. }: PLA) -> SpecLoaded {
     if self.time <= 0 { throw!(SpecError::NegativeTimeout) }
 
     let clock = Clock {
index 1a69fc22844a6210ec6a2a0b16fa05a0bdda426b..b427e248ba38edcb1ee8d7317b5b863389016684 100644 (file)
@@ -44,8 +44,7 @@ impl PieceXData for Value { fn dummy() -> Self { Value { qty: 0 } } }
 #[typetag::serde(name="Currency")]
 impl PieceSpec for Spec {
   #[throws(SpecError)]
-  fn load(&self, _: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth)
-          -> SpecLoaded {
+  fn load(&self, PLA { gpc,ig,depth,.. }: PLA) -> SpecLoaded {
     gpc.rotateable = false;
 
     let Spec { ref image, ref currency, qty } = *self;
index 7949caee75904988f433dc091c3d6bd162d26ba6..006af8d000a93eb5811ec4f807c27f5002e00edd 100644 (file)
@@ -37,8 +37,7 @@ impl OutlineTrait for Deck {
 #[typetag::serde(name="PickupDeck")]
 impl PieceSpec for piece_specs::Deck {
   #[throws(SpecError)]
-  fn load(&self, _: usize, gpc: &mut GPiece, _ig: &Instance, _:SpecDepth)
-          -> SpecLoaded {
+  fn load(&self, PLA { gpc,.. }: PLA) -> SpecLoaded {
     let common = SimpleCommon {
       itemname: None,
       faces: self.faces.clone(),
index 4b8b388af5799a058274ec82bf76877b68b3d9db..5026eaadd15c8398331eead82694f607a07cc357 100644 (file)
@@ -100,8 +100,7 @@ struct OverlayTemplateContext<'c> {
 #[typetag::serde(name="Die")]
 impl PieceSpec for Spec {
   #[throws(SpecError)]
-  fn load(&self, _: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth)
-          -> SpecLoaded {
+  fn load(&self, PLA { gpc,ig,depth,.. }: PLA) -> SpecLoaded {
     gpc.rotateable = false;
 
     let SpecLoadedInert { p: image, occultable: img_occultable } =
index 54045328370414f87fcac0fe0b734c9421ca377d..523eb8a8392ea24ab223e742752e70053efaab7e 100644 (file)
@@ -313,12 +313,18 @@ pub struct PieceSpecialProperties {
   pub multigrab: bool,
 }
 
+pub struct PieceLoadArgs<'a> {
+  pub i: usize,
+  pub gpc: &'a mut GPiece,
+  pub ig: &'a Instance,
+  pub depth: SpecDepth,
+}
+
 #[typetag::serde(tag="type")]
 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<SpecLoaded, SpecError>;
+  fn load(&self, pla: PieceLoadArgs<'_>) -> Result<SpecLoaded, SpecError>;
   /// Used when a piece wants to use another for its occulted form
   fn load_inert(&self, _ig: &Instance, _:SpecDepth)
                 -> Result<SpecLoadedInert, SpecError> {
index a6c02802b28f962791618868b4822211c6624776..23972717d03de38c06b922a9226128c9d9c64ed5 100644 (file)
@@ -119,8 +119,7 @@ impl piece_specs::OwnedCommon {
 #[typetag::serde]
 impl PieceSpec for piece_specs::Hand {
   #[throws(SpecError)]
-  fn load(&self, _: usize, gpc: &mut GPiece, _ig: &Instance, _:SpecDepth)
-          -> SpecLoaded {
+  fn load(&self, PLA { gpc,..}: PLA) -> SpecLoaded {
     gpc.moveable = PieceMoveable::IfWresting;
     gpc.rotateable = false;
     self.c.load(Behaviour::Hand)?
@@ -130,8 +129,7 @@ impl PieceSpec for piece_specs::Hand {
 #[typetag::serde]
 impl PieceSpec for piece_specs::PlayerLabel {
   #[throws(SpecError)]
-  fn load(&self, _: usize, _: &mut GPiece, _ig: &Instance, _:SpecDepth)
-          -> SpecLoaded {
+  fn load(&self, PLA { .. }: PLA) -> SpecLoaded {
     self.c.load(Behaviour::PlayerLabel)?
   }
 }
index e123adb84745fbe308357e14e86848ec8b4cc43c..84b0788fb8d5875b34c6e3c2d15fb52f6c9ed4d9 100644 (file)
@@ -64,10 +64,9 @@ impl PieceSpec for Alias {
     self.resolve(pcaliases)?.count(&default())?
   }
   #[throws(SpecError)]
-  fn load(&self, i: usize, gpc: &mut GPiece, ig: &Instance, depth: SpecDepth)
-          -> SpecLoaded {
+  fn load(&self, PLA { i,gpc,ig,depth,.. }: PLA) -> SpecLoaded {
     let r = self.resolve(&ig.pcaliases)?
-      .load(i, gpc, ig, self.new_depth(depth)?)?;
+      .load(PLA { i, gpc, ig, depth: self.new_depth(depth)? })?;
     r
   }
   #[throws(SpecError)]
index cf52fb5efda0da8faa08129613c5fb2bed9a6d46..b0927596ab5f53e94d71e9ec80d6cbc54d2c2141 100644 (file)
@@ -353,8 +353,7 @@ macro_rules! impl_PieceSpec_for_SimplePieceSpec { { $ty:ty } => {
   #[typetag::serde]
   impl PieceSpec for $ty {
     #[throws(SpecError)]
-    fn load(&self, _: usize, _: &mut GPiece, _ig: &Instance, _:SpecDepth)
-            -> SpecLoaded {
+    fn load(&self, PLA { .. }: PLA) -> SpecLoaded {
       SpecLoaded {
         p: Box::new(self.load_raw()?.0),
         occultable: None,
index 20c0f970a68930834cac8727108ad515db40a483..c03b62f474a88619fca89c9687b72ba4b70fe363 100644 (file)
@@ -216,6 +216,9 @@ pub type POEPP = PieceOpErrorPartiallyProcessed;
 pub type SvgE = SVGProcessingError;
 pub type SpE = SpecError;
 
+// gamestate.rs
+pub use PieceLoadArgs as PLA;
+
 // hidden.rs
 pub type OccK = OccultationKind;
 pub use OccultationKindGeneral as OccKG;
index 98df20547655b07fb0cbfcc764982a2ec6f59cbb..f1e6bef66a1df85c27ae1ba282ef6c846847f691 100644 (file)
@@ -654,8 +654,7 @@ impl Contents {
 #[typetag::serde(name="Lib")]
 impl PieceSpec for ItemSpec {
   #[throws(SpecError)]
-  fn load(&self, _: usize, _: &mut GPiece, ig: &Instance, depth: SpecDepth)
-          -> SpecLoaded {
+  fn load(&self, PLA { ig,depth,.. }: PLA) -> SpecLoaded {
     self.find_load(ig,depth)?.into()
   }
   #[throws(SpecError)]
@@ -671,8 +670,7 @@ impl PieceSpec for MultiSpec {
   fn count(&self, _pcaliases: &PieceAliases) -> usize { self.items.len() }
 
   #[throws(SpecError)]
-  fn load(&self, i: usize, _: &mut GPiece, ig: &Instance, depth:SpecDepth)
-          -> SpecLoaded
+  fn load(&self, PLA { i,ig,depth,.. }: PLA) -> SpecLoaded
   {
     let item = self.items.get(i).ok_or_else(
       || SpE::InternalError(format!("item {:?} from {:?}", i, &self))