From 40fdb9f13c21afb8711fbebb76f4195885f159b5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 25 Apr 2022 00:41:55 +0100 Subject: [PATCH] hidden: Refactor a bit in preparation for unnotched pieces fix In both of these places, we're going to want to do something if there is an occultation but notch is None. Signed-off-by: Ian Jackson --- src/hidden.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/hidden.rs b/src/hidden.rs index 26784e4e..e2b02ec1 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -154,11 +154,12 @@ impl PieceOccult { piece: PieceId) { if_chain! { if let Some(Passive { occid, permute_notch }) = self.passive; - if let Some(notch) = permute_notch; if let Some(occ) = goccults.occults.get_mut(occid); then { - occ.notches.remove(piece, notch) - .unwrap_or_else(|e| error!("removing occulted piece {:?}", e)); + if let Some(notch) = permute_notch { + occ.notches.remove(piece, notch) + .unwrap_or_else(|e| error!("removing occulted piece {:?}", e)); + } } } } @@ -707,11 +708,14 @@ fn recalculate_occultation_general< to_recalculate.mark_dirty(occid); goccults.occults.get_mut(occid).unwrap() }; - if let Some((occid, Some(old_notch))) = occulteds.old { - occultation(goccults, occid) - .notches - .remove(piece, old_notch) - .unwrap() + if let Some((occid, old_notch)) = occulteds.old { + let occ = occultation(goccults, occid); + if let Some(old_notch) = old_notch { + occ + .notches + .remove(piece, old_notch) + .unwrap(); + } }; let passive = if_chain!{ if let Some(occid) = occulteds.new; -- 2.30.2