diff --git a/src/exploration.rs b/src/exploration.rs index 43d2320..8cbfdcd 100644 --- a/src/exploration.rs +++ b/src/exploration.rs @@ -333,65 +333,66 @@ fn exploration_changed_announcement( query_pipeline: Res, collider_query: QueryPipelineColliderComponentsQuery, ) -> Result<(), Box> { - let (coordinates, exploring, viewshed) = explorer.single(); - let collider_set = QueryPipelineColliderComponentsSet(&collider_query); - let coordinates = coordinates.floor(); - for (map, revealed_tiles) in map.iter() { - let point = **exploring; - let idx = point.to_index(map.width); - let shape = Cuboid::new(Vec2::new(0.49, 0.49).into()); - let known = revealed_tiles[idx]; - let visible = viewshed.is_point_visible(exploring); - let fog_of_war = known && !visible; - let description = if known { - let mut tokens: Vec<&str> = vec![]; - for entity in focused.iter() { - commands.entity(entity).remove::(); - } - let shape_pos = (Vec2::new(exploring.x(), exploring.y()), 0.); - query_pipeline.intersections_with_shape( - &collider_set, - &shape_pos.into(), - &shape, - InteractionGroups::all(), - Some(&|v| explorable.get(v.entity()).is_ok()), - |handle| { - let entity = handle.entity(); - commands.entity(entity).insert(ExplorationFocused); - if visible || mappables.get(entity).is_ok() { - if let Ok(name) = names.get(entity) { - tokens.push(name.as_str()); - } - if tokens.is_empty() { - if let Ok(t) = types.get(entity) { - tokens.push((*t).into()); + if let Ok((coordinates, exploring, viewshed)) = explorer.get_single() { + let collider_set = QueryPipelineColliderComponentsSet(&collider_query); + let coordinates = coordinates.floor(); + for (map, revealed_tiles) in map.iter() { + let point = **exploring; + let idx = point.to_index(map.width); + let shape = Cuboid::new(Vec2::new(0.49, 0.49).into()); + let known = revealed_tiles[idx]; + let visible = viewshed.is_point_visible(exploring); + let fog_of_war = known && !visible; + let description = if known { + let mut tokens: Vec<&str> = vec![]; + for entity in focused.iter() { + commands.entity(entity).remove::(); + } + let shape_pos = (Vec2::new(exploring.x(), exploring.y()), 0.); + query_pipeline.intersections_with_shape( + &collider_set, + &shape_pos.into(), + &shape, + InteractionGroups::all(), + Some(&|v| explorable.get(v.entity()).is_ok()), + |handle| { + let entity = handle.entity(); + commands.entity(entity).insert(ExplorationFocused); + if visible || mappables.get(entity).is_ok() { + if let Ok(name) = names.get(entity) { + tokens.push(name.as_str()); + } + if tokens.is_empty() { + if let Ok(t) = types.get(entity) { + tokens.push((*t).into()); + } } } + true + }, + ); + if tokens.is_empty() { + let tile = map.tiles[idx]; + if tile.is_blocked() { + "wall".to_string() + } else { + "floor".to_string() } - true - }, - ); - if tokens.is_empty() { - let tile = map.tiles[idx]; - if tile.is_blocked() { - "wall".to_string() } else { - "floor".to_string() + tokens.join(": ") } } else { - tokens.join(": ") + "Unknown".to_string() + }; + let mut tokens: Vec = vec![ + description, + coordinates.direction_and_distance(exploring, None), + ]; + if fog_of_war { + tokens.push("in the fog of war".into()); } - } else { - "Unknown".to_string() - }; - let mut tokens: Vec = vec![ - description, - coordinates.direction_and_distance(exploring, None), - ]; - if fog_of_war { - tokens.push("in the fog of war".into()); + tts.speak(tokens.join(", ").to_string(), true)?; } - tts.speak(tokens.join(", ").to_string(), true)?; } Ok(()) } diff --git a/src/map.rs b/src/map.rs index e28628f..38a2a0c 100644 --- a/src/map.rs +++ b/src/map.rs @@ -22,8 +22,8 @@ impl From for Coordinates { } } -#[derive(Component, Clone, Debug, Deref, DerefMut)] -pub struct Area(AABB); +#[derive(Component, Copy, Clone, Debug, Deref, DerefMut, PartialEq)] +pub struct Area(pub AABB); #[derive(Component, Clone, Default, Deref, DerefMut)] pub struct Map(pub MapgenMap); diff --git a/src/navigation.rs b/src/navigation.rs index 3524adb..c589888 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -195,9 +195,10 @@ fn speak_direction( mut tts: ResMut, player: Query<&CardinalDirection, (With, Changed)>, ) -> Result<(), Box> { - let direction = player.single(); - let direction: String = (*direction).into(); - tts.speak(direction, true)?; + if let Ok(direction) = player.get_single() { + let direction: String = (*direction).into(); + tts.speak(direction, true)?; + } Ok(()) } diff --git a/src/visibility.rs b/src/visibility.rs index 46e79eb..3ba3145 100644 --- a/src/visibility.rs +++ b/src/visibility.rs @@ -281,19 +281,20 @@ fn update_viewshed( if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates)) = viewers.get_mut(*entity) { - let map = map.single(); - let mut cache = HashMap::new(); - viewshed.update( - &viewer_entity, - &mut visible_entities, - viewer_coordinates, - &*query_pipeline, - &collider_query, - map, - &visible, - &mut cache, - &mut changed, - ); + if let Ok(map) = map.get_single() { + let mut cache = HashMap::new(); + viewshed.update( + &viewer_entity, + &mut visible_entities, + viewer_coordinates, + &*query_pipeline, + &collider_query, + map, + &visible, + &mut cache, + &mut changed, + ); + } } } }