Finish port to Bevy 0.6.

This commit is contained in:
Nolan Darilek 2022-01-12 11:05:12 -06:00
parent 65e7c0f870
commit ae7a0d13fa
5 changed files with 165 additions and 166 deletions

View File

@ -265,7 +265,7 @@ fn exploration_focus<S, A: 'static>(
config.action_explore_right.clone(),
) {
for map in map.iter() {
if let (entity, coordinates, exploring) = explorers.single() {
let (entity, coordinates, exploring) = explorers.single();
let coordinates = **coordinates;
let mut exploring = if let Some(exploring) = exploring {
**exploring
@ -292,7 +292,6 @@ fn exploration_focus<S, A: 'static>(
}
}
}
}
}
fn navigate_to_explored<S, A: 'static>(
@ -334,7 +333,7 @@ fn exploration_changed_announcement(
query_pipeline: Res<QueryPipeline>,
collider_query: QueryPipelineColliderComponentsQuery,
) -> Result<(), Box<dyn Error>> {
if let (coordinates, exploring, viewshed) = explorer.single() {
let (coordinates, exploring, viewshed) = explorer.single();
let collider_set = QueryPipelineColliderComponentsSet(&collider_query);
let coordinates = coordinates.floor();
for (map, revealed_tiles) in map.iter() {
@ -392,8 +391,7 @@ fn exploration_changed_announcement(
if fog_of_war {
tokens.push("in the fog of war".into());
}
tts.speak(format!("{}", tokens.join(", ")), true)?;
}
tts.speak(tokens.join(", ").to_string(), true)?;
}
Ok(())
}

View File

@ -274,8 +274,8 @@ fn spawn_colliders(
}
if let (Some(bl), Some(br)) = (bottom_left, bottom_right) {
//println!("Got bottom, checking if can extend up");
let mut top_left = bl.clone();
let mut top_right = br.clone();
let mut top_left = bl;
let mut top_right = br;
if y != map.height - 1 {
let mut can_extend_up = true;
for y in bl.1 + 1..map.height {
@ -322,7 +322,10 @@ fn spawn_colliders(
);*/
let id = commands
.spawn_bundle(ColliderBundle {
shape: ColliderShapeComponent(ColliderShape::cuboid(half_width, half_height)),
shape: ColliderShapeComponent(ColliderShape::cuboid(
half_width,
half_height,
)),
position: Vec2::new(x, y).into(),
..Default::default()
})
@ -454,7 +457,7 @@ fn area_description(
})
{
if players.get(other).is_ok() {
if let mut log = log.single_mut() {
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())
@ -474,7 +477,6 @@ fn area_description(
}
}
}
}
}
pub struct MapPlugin;

View File

@ -195,10 +195,9 @@ fn speak_direction(
mut tts: ResMut<Tts>,
player: Query<&CardinalDirection, (With<Player>, Changed<CardinalDirection>)>,
) -> Result<(), Box<dyn Error>> {
if let direction = player.single() {
let direction = player.single();
let direction: String = (*direction).into();
tts.speak(direction, true)?;
}
Ok(())
}

View File

@ -219,12 +219,12 @@ fn calculate_path(
.remove::<Speed>();
continue;
}
if let map = map.single() {
let map = map.single();
let coordinates_clone = *coordinates;
let destination_clone = *destination;
let query_pipeline_clone = query_pipeline.clone();
let map_clone = map.clone();
let shape_clone = shape.clone();
let shape_clone = (*shape).clone();
let collider_set: StaticColliderComponentsSet = (&collider_query, &obstructions).into();
let task = pool.spawn(async move {
find_path_for_shape(
@ -234,7 +234,7 @@ fn calculate_path(
query_pipeline_clone,
map_clone,
collider_set,
**shape_clone,
shape_clone,
)
});
commands
@ -243,7 +243,6 @@ fn calculate_path(
.remove::<Path>()
.remove::<NoPath>();
}
}
}
fn poll_tasks(mut commands: Commands, mut query: Query<(Entity, &mut Calculating)>) {

View File

@ -61,7 +61,7 @@ impl Viewshed {
let shape = ColliderShape::cuboid(0.49, 0.49);
let origin = point!(start.x(), start.y());
let coord = Coord::new(start.x_i32(), start.y_i32());
let collider_set = QueryPipelineColliderComponentsSet(&collider_query);
let collider_set = QueryPipelineColliderComponentsSet(collider_query);
let mut new_visible_entities = HashSet::<Entity>::new();
let visibility_grid = VisibilityGrid(
map,
@ -281,7 +281,7 @@ fn update_viewshed(
if let Ok((viewer_entity, mut viewshed, mut visible_entities, viewer_coordinates)) =
viewers.get_mut(*entity)
{
if let map = map.single() {
let map = map.single();
let mut cache = HashMap::new();
viewshed.update(
&viewer_entity,
@ -296,7 +296,6 @@ fn update_viewshed(
);
}
}
}
}
fn remove_visible(
@ -314,7 +313,7 @@ fn remove_visible(
continue;
}
visible_entities.remove(&removed);
if let map = map.single() {
let map = map.single();
let mut cache = HashMap::new();
viewshed.update(
&viewer_entity,
@ -329,7 +328,6 @@ fn remove_visible(
);
}
}
}
}
fn update_revealed_tiles(
@ -356,7 +354,11 @@ fn log_visible(
mut log: Query<&mut Log>,
viewers: Query<(Entity, &Coordinates, &Transform), (With<Player>, With<Viewshed>)>,
visible: Query<
(&Name, Option<&RigidBodyPositionComponent>, Option<&ColliderPositionComponent>),
(
&Name,
Option<&RigidBodyPositionComponent>,
Option<&ColliderPositionComponent>,
),
Without<DontLogWhenVisible>,
>,
) {
@ -375,7 +377,7 @@ fn log_visible(
continue;
}
if let Ok((name, body_position, collider_position)) = visible.get(*viewed) {
if let mut log = log.single_mut() {
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 {
@ -385,11 +387,10 @@ fn log_visible(
};
let forward = viewer_transform.local_x();
let yaw = Angle::Radians(forward.y.atan2(forward.x));
let location = viewer_coordinates
.direction_and_distance(&viewed_coordinates, Some(yaw));
let location =
viewer_coordinates.direction_and_distance(&viewed_coordinates, Some(yaw));
log.push(format!("{}: {}", **name, location));
}
}
} else if let VisibilityChanged::Lost { viewed, .. } = event {
recently_lost.insert(*viewed, Timer::from_seconds(2., false));
}