Assorted small changes.
This commit is contained in:
parent
10bf503c89
commit
a214206caf
|
@ -333,65 +333,66 @@ fn exploration_changed_announcement(
|
||||||
query_pipeline: Res<QueryPipeline>,
|
query_pipeline: Res<QueryPipeline>,
|
||||||
collider_query: QueryPipelineColliderComponentsQuery,
|
collider_query: QueryPipelineColliderComponentsQuery,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let (coordinates, exploring, viewshed) = explorer.single();
|
if let Ok((coordinates, exploring, viewshed)) = explorer.get_single() {
|
||||||
let collider_set = QueryPipelineColliderComponentsSet(&collider_query);
|
let collider_set = QueryPipelineColliderComponentsSet(&collider_query);
|
||||||
let coordinates = coordinates.floor();
|
let coordinates = coordinates.floor();
|
||||||
for (map, revealed_tiles) in map.iter() {
|
for (map, revealed_tiles) in map.iter() {
|
||||||
let point = **exploring;
|
let point = **exploring;
|
||||||
let idx = point.to_index(map.width);
|
let idx = point.to_index(map.width);
|
||||||
let shape = Cuboid::new(Vec2::new(0.49, 0.49).into());
|
let shape = Cuboid::new(Vec2::new(0.49, 0.49).into());
|
||||||
let known = revealed_tiles[idx];
|
let known = revealed_tiles[idx];
|
||||||
let visible = viewshed.is_point_visible(exploring);
|
let visible = viewshed.is_point_visible(exploring);
|
||||||
let fog_of_war = known && !visible;
|
let fog_of_war = known && !visible;
|
||||||
let description = if known {
|
let description = if known {
|
||||||
let mut tokens: Vec<&str> = vec![];
|
let mut tokens: Vec<&str> = vec![];
|
||||||
for entity in focused.iter() {
|
for entity in focused.iter() {
|
||||||
commands.entity(entity).remove::<ExplorationFocused>();
|
commands.entity(entity).remove::<ExplorationFocused>();
|
||||||
}
|
}
|
||||||
let shape_pos = (Vec2::new(exploring.x(), exploring.y()), 0.);
|
let shape_pos = (Vec2::new(exploring.x(), exploring.y()), 0.);
|
||||||
query_pipeline.intersections_with_shape(
|
query_pipeline.intersections_with_shape(
|
||||||
&collider_set,
|
&collider_set,
|
||||||
&shape_pos.into(),
|
&shape_pos.into(),
|
||||||
&shape,
|
&shape,
|
||||||
InteractionGroups::all(),
|
InteractionGroups::all(),
|
||||||
Some(&|v| explorable.get(v.entity()).is_ok()),
|
Some(&|v| explorable.get(v.entity()).is_ok()),
|
||||||
|handle| {
|
|handle| {
|
||||||
let entity = handle.entity();
|
let entity = handle.entity();
|
||||||
commands.entity(entity).insert(ExplorationFocused);
|
commands.entity(entity).insert(ExplorationFocused);
|
||||||
if visible || mappables.get(entity).is_ok() {
|
if visible || mappables.get(entity).is_ok() {
|
||||||
if let Ok(name) = names.get(entity) {
|
if let Ok(name) = names.get(entity) {
|
||||||
tokens.push(name.as_str());
|
tokens.push(name.as_str());
|
||||||
}
|
}
|
||||||
if tokens.is_empty() {
|
if tokens.is_empty() {
|
||||||
if let Ok(t) = types.get(entity) {
|
if let Ok(t) = types.get(entity) {
|
||||||
tokens.push((*t).into());
|
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 {
|
} else {
|
||||||
"floor".to_string()
|
tokens.join(": ")
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
tts.speak(tokens.join(", ").to_string(), true)?;
|
||||||
"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)?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ impl From<mapgen::geometry::Point> for Coordinates {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Component, Clone, Debug, Deref, DerefMut)]
|
#[derive(Component, Copy, Clone, Debug, Deref, DerefMut, PartialEq)]
|
||||||
pub struct Area(AABB);
|
pub struct Area(pub AABB);
|
||||||
|
|
||||||
#[derive(Component, Clone, Default, Deref, DerefMut)]
|
#[derive(Component, Clone, Default, Deref, DerefMut)]
|
||||||
pub struct Map(pub MapgenMap);
|
pub struct Map(pub MapgenMap);
|
||||||
|
|
|
@ -195,9 +195,10 @@ fn speak_direction(
|
||||||
mut tts: ResMut<Tts>,
|
mut tts: ResMut<Tts>,
|
||||||
player: Query<&CardinalDirection, (With<Player>, Changed<CardinalDirection>)>,
|
player: Query<&CardinalDirection, (With<Player>, Changed<CardinalDirection>)>,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let direction = player.single();
|
if let Ok(direction) = player.get_single() {
|
||||||
let direction: String = (*direction).into();
|
let direction: String = (*direction).into();
|
||||||
tts.speak(direction, true)?;
|
tts.speak(direction, true)?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -281,19 +281,20 @@ fn update_viewshed(
|
||||||
if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates)) =
|
if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates)) =
|
||||||
viewers.get_mut(*entity)
|
viewers.get_mut(*entity)
|
||||||
{
|
{
|
||||||
let map = map.single();
|
if let Ok(map) = map.get_single() {
|
||||||
let mut cache = HashMap::new();
|
let mut cache = HashMap::new();
|
||||||
viewshed.update(
|
viewshed.update(
|
||||||
&viewer_entity,
|
&viewer_entity,
|
||||||
&mut visible_entities,
|
&mut visible_entities,
|
||||||
viewer_coordinates,
|
viewer_coordinates,
|
||||||
&*query_pipeline,
|
&*query_pipeline,
|
||||||
&collider_query,
|
&collider_query,
|
||||||
map,
|
map,
|
||||||
&visible,
|
&visible,
|
||||||
&mut cache,
|
&mut cache,
|
||||||
&mut changed,
|
&mut changed,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user