From 3cfb638b488478e6763404598ac4598e2c49c17b Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 1 Feb 2022 08:41:27 -0600 Subject: [PATCH] Remove calls to \.single. --- src/exploration.rs | 49 +++++++++++++++++++++++----------------------- src/map.rs | 11 ++++++----- src/visibility.rs | 5 +++-- 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/exploration.rs b/src/exploration.rs index 8cbfdcd..5f34ed3 100644 --- a/src/exploration.rs +++ b/src/exploration.rs @@ -265,30 +265,31 @@ fn exploration_focus( config.action_explore_right.clone(), ) { for map in map.iter() { - let (entity, coordinates, exploring) = explorers.single(); - let coordinates = **coordinates; - let mut exploring = if let Some(exploring) = exploring { - **exploring - } else { - coordinates.floor() - }; - let orig = exploring; - if input.just_active(explore_forward.clone()) { - exploring.1 += 1.; - } else if input.just_active(explore_backward.clone()) { - exploring.1 -= 1.; - } else if input.just_active(explore_left.clone()) { - exploring.0 -= 1.; - } else if input.just_active(explore_right.clone()) { - exploring.0 += 1.; - } - if orig != exploring - && exploring.0 >= 0. - && exploring.0 < map.width as f32 - && exploring.1 >= 0. - && exploring.1 < map.height as f32 - { - commands.entity(entity).insert(Exploring(exploring)); + if let Ok((entity, coordinates, exploring)) = explorers.get_single() { + let coordinates = **coordinates; + let mut exploring = if let Some(exploring) = exploring { + **exploring + } else { + coordinates.floor() + }; + let orig = exploring; + if input.just_active(explore_forward.clone()) { + exploring.1 += 1.; + } else if input.just_active(explore_backward.clone()) { + exploring.1 -= 1.; + } else if input.just_active(explore_left.clone()) { + exploring.0 -= 1.; + } else if input.just_active(explore_right.clone()) { + exploring.0 += 1.; + } + if orig != exploring + && exploring.0 >= 0. + && exploring.0 < map.width as f32 + && exploring.1 >= 0. + && exploring.1 < map.height as f32 + { + commands.entity(entity).insert(Exploring(exploring)); + } } } } diff --git a/src/map.rs b/src/map.rs index bf8188c..cb0eec4 100644 --- a/src/map.rs +++ b/src/map.rs @@ -454,7 +454,6 @@ fn area_description( }) { if players.get(other).is_ok() { - let mut log = log.single_mut(); if let Ok((aabb, area_name)) = areas.get(area) { let name = if let Some(name) = area_name { Some(name.to_string()) @@ -464,10 +463,12 @@ fn area_description( None }; if let Some(name) = name { - if event.intersecting { - log.push(format!("Entering {name}.")); - } else { - log.push(format!("Leaving {name}.")); + if let Ok(mut log) = log.get_single_mut() { + if event.intersecting { + log.push(format!("Entering {name}.")); + } else { + log.push(format!("Leaving {name}.")); + } } } } diff --git a/src/visibility.rs b/src/visibility.rs index 5115b43..9332b6b 100644 --- a/src/visibility.rs +++ b/src/visibility.rs @@ -379,7 +379,6 @@ fn log_visible( continue; } if let Ok((name, body_position, collider_position)) = visible.get(*viewed) { - let mut log = log.single_mut(); let viewed_coordinates = if let Some(p) = body_position { (p.position.translation.x, p.position.translation.y) } else if let Some(p) = collider_position { @@ -391,7 +390,9 @@ fn log_visible( let yaw = Angle::Radians(forward.y.atan2(forward.x)); let location = viewer_coordinates.direction_and_distance(&viewed_coordinates, Some(yaw)); - log.push(format!("{}: {location}", **name)); + if let Ok(mut log) = log.get_single_mut() { + log.push(format!("{}: {location}", **name)); + } } } else if let VisibilityChanged::Lost { viewed, .. } = event { recently_lost.insert(*viewed, Timer::from_seconds(2., false));