Finish port to Bevy 0.6.
This commit is contained in:
parent
65e7c0f870
commit
ae7a0d13fa
|
@ -265,7 +265,7 @@ 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() {
|
||||||
if let (entity, coordinates, exploring) = explorers.single() {
|
let (entity, coordinates, exploring) = explorers.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
|
||||||
|
@ -293,7 +293,6 @@ fn exploration_focus<S, A: 'static>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn navigate_to_explored<S, A: 'static>(
|
fn navigate_to_explored<S, A: 'static>(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
@ -334,7 +333,7 @@ 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>> {
|
||||||
if let (coordinates, exploring, viewshed) = explorer.single() {
|
let (coordinates, exploring, viewshed) = explorer.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() {
|
||||||
|
@ -392,8 +391,7 @@ fn exploration_changed_announcement(
|
||||||
if fog_of_war {
|
if fog_of_war {
|
||||||
tokens.push("in the fog of war".into());
|
tokens.push("in the fog of war".into());
|
||||||
}
|
}
|
||||||
tts.speak(format!("{}", tokens.join(", ")), true)?;
|
tts.speak(tokens.join(", ").to_string(), true)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
12
src/map.rs
12
src/map.rs
|
@ -274,8 +274,8 @@ fn spawn_colliders(
|
||||||
}
|
}
|
||||||
if let (Some(bl), Some(br)) = (bottom_left, bottom_right) {
|
if let (Some(bl), Some(br)) = (bottom_left, bottom_right) {
|
||||||
//println!("Got bottom, checking if can extend up");
|
//println!("Got bottom, checking if can extend up");
|
||||||
let mut top_left = bl.clone();
|
let mut top_left = bl;
|
||||||
let mut top_right = br.clone();
|
let mut top_right = br;
|
||||||
if y != map.height - 1 {
|
if y != map.height - 1 {
|
||||||
let mut can_extend_up = true;
|
let mut can_extend_up = true;
|
||||||
for y in bl.1 + 1..map.height {
|
for y in bl.1 + 1..map.height {
|
||||||
|
@ -322,7 +322,10 @@ fn spawn_colliders(
|
||||||
);*/
|
);*/
|
||||||
let id = commands
|
let id = commands
|
||||||
.spawn_bundle(ColliderBundle {
|
.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(),
|
position: Vec2::new(x, y).into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
|
@ -454,7 +457,7 @@ fn area_description(
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
if players.get(other).is_ok() {
|
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) {
|
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())
|
||||||
|
@ -475,7 +478,6 @@ fn area_description(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub struct MapPlugin;
|
pub struct MapPlugin;
|
||||||
|
|
||||||
|
|
|
@ -195,10 +195,9 @@ 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>> {
|
||||||
if let direction = player.single() {
|
let direction = player.single();
|
||||||
let direction: String = (*direction).into();
|
let direction: String = (*direction).into();
|
||||||
tts.speak(direction, true)?;
|
tts.speak(direction, true)?;
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -219,12 +219,12 @@ fn calculate_path(
|
||||||
.remove::<Speed>();
|
.remove::<Speed>();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let map = map.single() {
|
let map = map.single();
|
||||||
let coordinates_clone = *coordinates;
|
let coordinates_clone = *coordinates;
|
||||||
let destination_clone = *destination;
|
let destination_clone = *destination;
|
||||||
let query_pipeline_clone = query_pipeline.clone();
|
let query_pipeline_clone = query_pipeline.clone();
|
||||||
let map_clone = map.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 collider_set: StaticColliderComponentsSet = (&collider_query, &obstructions).into();
|
||||||
let task = pool.spawn(async move {
|
let task = pool.spawn(async move {
|
||||||
find_path_for_shape(
|
find_path_for_shape(
|
||||||
|
@ -234,7 +234,7 @@ fn calculate_path(
|
||||||
query_pipeline_clone,
|
query_pipeline_clone,
|
||||||
map_clone,
|
map_clone,
|
||||||
collider_set,
|
collider_set,
|
||||||
**shape_clone,
|
shape_clone,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
commands
|
commands
|
||||||
|
@ -244,7 +244,6 @@ fn calculate_path(
|
||||||
.remove::<NoPath>();
|
.remove::<NoPath>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn poll_tasks(mut commands: Commands, mut query: Query<(Entity, &mut Calculating)>) {
|
fn poll_tasks(mut commands: Commands, mut query: Query<(Entity, &mut Calculating)>) {
|
||||||
for (entity, mut calculating) in query.iter_mut() {
|
for (entity, mut calculating) in query.iter_mut() {
|
||||||
|
|
|
@ -61,7 +61,7 @@ impl Viewshed {
|
||||||
let shape = ColliderShape::cuboid(0.49, 0.49);
|
let shape = ColliderShape::cuboid(0.49, 0.49);
|
||||||
let origin = point!(start.x(), start.y());
|
let origin = point!(start.x(), start.y());
|
||||||
let coord = Coord::new(start.x_i32(), start.y_i32());
|
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 mut new_visible_entities = HashSet::<Entity>::new();
|
||||||
let visibility_grid = VisibilityGrid(
|
let visibility_grid = VisibilityGrid(
|
||||||
map,
|
map,
|
||||||
|
@ -281,7 +281,7 @@ 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)
|
||||||
{
|
{
|
||||||
if let map = map.single() {
|
let map = map.single();
|
||||||
let mut cache = HashMap::new();
|
let mut cache = HashMap::new();
|
||||||
viewshed.update(
|
viewshed.update(
|
||||||
&viewer_entity,
|
&viewer_entity,
|
||||||
|
@ -297,7 +297,6 @@ fn update_viewshed(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn remove_visible(
|
fn remove_visible(
|
||||||
removed: RemovedComponents<Visible>,
|
removed: RemovedComponents<Visible>,
|
||||||
|
@ -314,7 +313,7 @@ fn remove_visible(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
visible_entities.remove(&removed);
|
visible_entities.remove(&removed);
|
||||||
if let map = map.single() {
|
let map = map.single();
|
||||||
let mut cache = HashMap::new();
|
let mut cache = HashMap::new();
|
||||||
viewshed.update(
|
viewshed.update(
|
||||||
&viewer_entity,
|
&viewer_entity,
|
||||||
|
@ -330,7 +329,6 @@ fn remove_visible(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn update_revealed_tiles(
|
fn update_revealed_tiles(
|
||||||
mut map: Query<(&Map, &mut RevealedTiles)>,
|
mut map: Query<(&Map, &mut RevealedTiles)>,
|
||||||
|
@ -356,7 +354,11 @@ fn log_visible(
|
||||||
mut log: Query<&mut Log>,
|
mut log: Query<&mut Log>,
|
||||||
viewers: Query<(Entity, &Coordinates, &Transform), (With<Player>, With<Viewshed>)>,
|
viewers: Query<(Entity, &Coordinates, &Transform), (With<Player>, With<Viewshed>)>,
|
||||||
visible: Query<
|
visible: Query<
|
||||||
(&Name, Option<&RigidBodyPositionComponent>, Option<&ColliderPositionComponent>),
|
(
|
||||||
|
&Name,
|
||||||
|
Option<&RigidBodyPositionComponent>,
|
||||||
|
Option<&ColliderPositionComponent>,
|
||||||
|
),
|
||||||
Without<DontLogWhenVisible>,
|
Without<DontLogWhenVisible>,
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
|
@ -375,7 +377,7 @@ 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) {
|
||||||
if let mut log = log.single_mut() {
|
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 {
|
||||||
|
@ -385,11 +387,10 @@ fn log_visible(
|
||||||
};
|
};
|
||||||
let forward = viewer_transform.local_x();
|
let forward = viewer_transform.local_x();
|
||||||
let yaw = Angle::Radians(forward.y.atan2(forward.x));
|
let yaw = Angle::Radians(forward.y.atan2(forward.x));
|
||||||
let location = viewer_coordinates
|
let location =
|
||||||
.direction_and_distance(&viewed_coordinates, Some(yaw));
|
viewer_coordinates.direction_and_distance(&viewed_coordinates, Some(yaw));
|
||||||
log.push(format!("{}: {}", **name, location));
|
log.push(format!("{}: {}", **name, location));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} 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));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user