From: Ian Jackson Date: Sat, 16 Apr 2022 20:00:44 +0000 (+0100) Subject: dice: Reorganise occultation handling X-Git-Tag: otter-1.1.0~518 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e2d90f3966cde576024fb549504f226e6e535bd7;p=otter.git dice: Reorganise occultation handling 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 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 --- diff --git a/src/dice.rs b/src/dice.rs index 33dcaaa9..809cf1de 100644 --- a/src/dice.rs +++ b/src/dice.rs @@ -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,