Assorted small changes.

This commit is contained in:
Nolan Darilek 2022-01-13 14:43:02 -06:00
parent 10bf503c89
commit a214206caf
4 changed files with 72 additions and 69 deletions

View File

@ -333,65 +333,66 @@ fn exploration_changed_announcement(
query_pipeline: Res<QueryPipeline>,
collider_query: QueryPipelineColliderComponentsQuery,
) -> Result<(), Box<dyn Error>> {
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::<ExplorationFocused>();
}
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::<ExplorationFocused>();
}
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<String> = 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<String> = 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(())
}

View File

@ -22,8 +22,8 @@ impl From<mapgen::geometry::Point> 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);

View File

@ -195,9 +195,10 @@ fn speak_direction(
mut tts: ResMut<Tts>,
player: Query<&CardinalDirection, (With<Player>, Changed<CardinalDirection>)>,
) -> Result<(), Box<dyn Error>> {
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(())
}

View File

@ -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,
);
}
}
}
}