Remove calls to \.single.

This commit is contained in:
Nolan Darilek 2022-02-01 08:41:27 -06:00
parent 7b1aaf69a2
commit 3cfb638b48
3 changed files with 34 additions and 31 deletions

View File

@ -265,30 +265,31 @@ fn exploration_focus<S, A: 'static>(
config.action_explore_right.clone(), config.action_explore_right.clone(),
) { ) {
for map in map.iter() { for map in map.iter() {
let (entity, coordinates, exploring) = explorers.single(); if let Ok((entity, coordinates, exploring)) = explorers.get_single() {
let coordinates = **coordinates; let coordinates = **coordinates;
let mut exploring = if let Some(exploring) = exploring { let mut exploring = if let Some(exploring) = exploring {
**exploring **exploring
} else { } else {
coordinates.floor() coordinates.floor()
}; };
let orig = exploring; let orig = exploring;
if input.just_active(explore_forward.clone()) { if input.just_active(explore_forward.clone()) {
exploring.1 += 1.; exploring.1 += 1.;
} else if input.just_active(explore_backward.clone()) { } else if input.just_active(explore_backward.clone()) {
exploring.1 -= 1.; exploring.1 -= 1.;
} else if input.just_active(explore_left.clone()) { } else if input.just_active(explore_left.clone()) {
exploring.0 -= 1.; exploring.0 -= 1.;
} else if input.just_active(explore_right.clone()) { } else if input.just_active(explore_right.clone()) {
exploring.0 += 1.; exploring.0 += 1.;
} }
if orig != exploring if orig != exploring
&& exploring.0 >= 0. && exploring.0 >= 0.
&& exploring.0 < map.width as f32 && exploring.0 < map.width as f32
&& exploring.1 >= 0. && exploring.1 >= 0.
&& exploring.1 < map.height as f32 && exploring.1 < map.height as f32
{ {
commands.entity(entity).insert(Exploring(exploring)); commands.entity(entity).insert(Exploring(exploring));
}
} }
} }
} }

View File

@ -454,7 +454,6 @@ fn area_description(
}) })
{ {
if players.get(other).is_ok() { if players.get(other).is_ok() {
let mut log = log.single_mut();
if let Ok((aabb, area_name)) = areas.get(area) { if let Ok((aabb, area_name)) = areas.get(area) {
let name = if let Some(name) = area_name { let name = if let Some(name) = area_name {
Some(name.to_string()) Some(name.to_string())
@ -464,10 +463,12 @@ fn area_description(
None None
}; };
if let Some(name) = name { if let Some(name) = name {
if event.intersecting { if let Ok(mut log) = log.get_single_mut() {
log.push(format!("Entering {name}.")); if event.intersecting {
} else { log.push(format!("Entering {name}."));
log.push(format!("Leaving {name}.")); } else {
log.push(format!("Leaving {name}."));
}
} }
} }
} }

View File

@ -379,7 +379,6 @@ fn log_visible(
continue; continue;
} }
if let Ok((name, body_position, collider_position)) = visible.get(*viewed) { 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 { let viewed_coordinates = if let Some(p) = body_position {
(p.position.translation.x, p.position.translation.y) (p.position.translation.x, p.position.translation.y)
} else if let Some(p) = collider_position { } else if let Some(p) = collider_position {
@ -391,7 +390,9 @@ fn log_visible(
let yaw = Angle::Radians(forward.y.atan2(forward.x)); let yaw = Angle::Radians(forward.y.atan2(forward.x));
let location = let location =
viewer_coordinates.direction_and_distance(&viewed_coordinates, Some(yaw)); 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 { } else if let VisibilityChanged::Lost { viewed, .. } = event {
recently_lost.insert(*viewed, Timer::from_seconds(2., false)); recently_lost.insert(*viewed, Timer::from_seconds(2., false));