chiark / gitweb /
dice: Reorganise occultation handling
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 16 Apr 2022 20:00:44 +0000 (21:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 17 Apr 2022 13:26:23 +0000 (14:26 +0100)
I was trying to support ilks properly.  This code is in fact going to
be considerably simplified.

But it will still make sense to split the interpretation of the spec
from the assembly of the Arc<dyn InertPieceImage> for the occulted
view.  That will make it possible for the spec interpretation to
provide an occulted view in more situations.

In fact it appears that these plans are going to be postponed and not
done right now, but I'm keeping this refactoring.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/dice.rs

index 33dcaaa9867e2c3ec5624339a97549ad75b2616f..809cf1de742888f278c39cfe255182cf42d63aed 100644 (file)
@@ -198,20 +198,23 @@ impl PieceSpec for Spec {
           // that aren't dice.  That would be mad even if they look a
           // bit like us.
           format!("die.{}.{}", nfaces, &image_occ_ilk);
-        let our_ilk = GoodItemName::try_from(our_ilk)
-          .map_err(|e| internal_error_bydebug(&e))?
-          .into();
-
-        let our_occ_image = Arc::new(Die {
-          nfaces, cooldown_time, cooldown_radius, surround_outline,
-          itemname: itemname.clone(),
-          image: image_occ_image,
-          labels: index_vec![occ_label],
-        }) as _;
-
-        Some((our_ilk, our_occ_image))
+
+        Some((image_occ_image, our_ilk, occ_label))
       },
-    };
+    }.map(|(occ_image, occ_ilk, occ_label)| {
+      let occ_ilk = GoodItemName::try_from(occ_ilk)
+        .map_err(|e| internal_error_bydebug(&e))?
+        .into();
+
+      let our_occ_image = Arc::new(Die {
+        nfaces, cooldown_time, cooldown_radius, surround_outline,
+        itemname: itemname.clone(),
+        image: occ_image,
+        labels: index_vec![occ_label],
+      }) as _;
+
+      Ok::<_,SpecError>((occ_ilk, our_occ_image))
+    }).transpose()?;
 
     let die = Die {
       nfaces, cooldown_time, cooldown_radius, surround_outline,