WIP: Begin porting to Bevy 0.6.

This commit is contained in:
Nolan Darilek 2022-01-10 13:50:52 -06:00
parent 3f8636a639
commit 356caa09e0
10 changed files with 132 additions and 144 deletions

View File

@ -7,11 +7,10 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies.bevy] [dependencies.bevy]
version = "0.5" version = "0.6"
default-features = false default-features = false
features = [ features = [
"bevy_gilrs", "bevy_gilrs",
"bevy_wgpu",
"bevy_winit", "bevy_winit",
"render", "render",
"x11", "x11",
@ -23,7 +22,7 @@ features = [
backtrace = "0.3" backtrace = "0.3"
bevy_input_actionmap = { path = "../bevy_input_actionmap" } bevy_input_actionmap = { path = "../bevy_input_actionmap" }
bevy_openal = { path = "../bevy_openal" } bevy_openal = { path = "../bevy_openal" }
bevy_rapier2d = { version = "0.11", features = ["serde-serialize", "simd-stable"] } bevy_rapier2d = { version = "0.12", features = ["serde-serialize", "simd-stable"] }
bevy_tts = { path = "../bevy_tts" } bevy_tts = { path = "../bevy_tts" }
coord_2d = "0.3" coord_2d = "0.3"
derive_more = "0.99" derive_more = "0.99"

View File

@ -14,7 +14,7 @@ use once_cell::sync::Lazy;
use rand::prelude::*; use rand::prelude::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, Deref, DerefMut, PartialEq, PartialOrd, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, Deref, DerefMut, PartialEq, PartialOrd, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Coordinates(pub (f32, f32)); pub struct Coordinates(pub (f32, f32));
@ -260,7 +260,7 @@ impl Display for MovementDirection {
} }
} }
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Component, Clone, Copy, Debug, Eq, PartialEq)]
pub enum CardinalDirection { pub enum CardinalDirection {
North, North,
East, East,
@ -570,7 +570,7 @@ impl From<&dyn PointLike> for (i32, i32) {
} }
} }
#[derive(Clone, Copy, Debug, Default, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Player; pub struct Player;
@ -645,10 +645,10 @@ fn copy_coordinates_to_transform(
(&Coordinates, &mut Transform), (&Coordinates, &mut Transform),
( (
Changed<Transform>, Changed<Transform>,
Without<RigidBodyPosition>, Without<RigidBodyPositionComponent>,
Without<RigidBodyPositionSync>, Without<RigidBodyPositionSyncComponent>,
Without<ColliderPosition>, Without<ColliderPositionComponent>,
Without<ColliderPositionSync>, Without<ColliderPositionSyncComponent>,
), ),
>, >,
) { ) {
@ -666,8 +666,8 @@ fn copy_coordinates_to_transform(
fn copy_rigid_body_position_to_coordinates( fn copy_rigid_body_position_to_coordinates(
mut query: Query< mut query: Query<
(&mut Coordinates, &RigidBodyPosition), (&mut Coordinates, &RigidBodyPositionComponent),
(Changed<RigidBodyPosition>, With<RigidBodyPositionSync>), (Changed<RigidBodyPositionComponent>, With<RigidBodyPositionSync>),
>, >,
) { ) {
for (mut coordinates, position) in query.iter_mut() { for (mut coordinates, position) in query.iter_mut() {
@ -682,11 +682,11 @@ fn copy_rigid_body_position_to_coordinates(
fn copy_collider_position_to_coordinates( fn copy_collider_position_to_coordinates(
mut query: Query< mut query: Query<
(&mut Coordinates, &ColliderPosition), (&mut Coordinates, &ColliderPositionComponent),
( (
Without<RigidBodyPosition>, Without<RigidBodyPositionComponent>,
Changed<ColliderPosition>, Changed<ColliderPositionComponent>,
With<ColliderPositionSync>, With<ColliderPositionSyncComponent>,
), ),
>, >,
) { ) {
@ -725,27 +725,23 @@ fn sync_config(config: Res<CoreConfig>) {
pub struct CorePlugin; pub struct CorePlugin;
impl Plugin for CorePlugin { impl Plugin for CorePlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<CoreConfig>() { if !app.world().contains_resource::<CoreConfig>() {
app.insert_resource(CoreConfig::default()); app.insert_resource(CoreConfig::default());
} }
app.register_type::<Coordinates>() app.register_type::<Coordinates>()
.add_startup_system(setup.system()) .add_startup_system(setup)
.add_system_to_stage( .add_system_to_stage(
CoreStage::PostUpdate, CoreStage::PostUpdate,
copy_coordinates_to_transform copy_coordinates_to_transform
.system()
.before(TransformSystem::TransformPropagate), .before(TransformSystem::TransformPropagate),
) )
.add_system_to_stage( .add_system_to_stage(
CoreStage::PostUpdate, CoreStage::PostUpdate,
copy_rigid_body_position_to_coordinates.system(), copy_rigid_body_position_to_coordinates,
) )
.add_system_to_stage( .add_system_to_stage(CoreStage::PostUpdate, copy_collider_position_to_coordinates)
CoreStage::PostUpdate, .add_system(sync_config);
copy_collider_position_to_coordinates.system(),
)
.add_system(sync_config.system());
} }
} }

View File

@ -52,7 +52,7 @@ pub struct ErrorConfig {
pub struct ErrorPlugin; pub struct ErrorPlugin;
impl Plugin for ErrorPlugin { impl Plugin for ErrorPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut App) {
init_panic_handler(); init_panic_handler();
if let Some(config) = app.world().get_resource::<ErrorConfig>() { if let Some(config) = app.world().get_resource::<ErrorConfig>() {
if let Some(dsn) = &config.sentry_dsn { if let Some(dsn) = &config.sentry_dsn {

View File

@ -15,16 +15,16 @@ use crate::{
visibility::{RevealedTiles, Viewshed, Visible, VisibleEntities}, visibility::{RevealedTiles, Viewshed, Visible, VisibleEntities},
}; };
#[derive(Clone, Copy, Debug, Default, PartialEq, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, PartialEq, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Explorable; pub struct Explorable;
#[derive(Clone, Copy, Debug, Default, PartialEq, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, PartialEq, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct ExplorationFocused; pub struct ExplorationFocused;
#[allow(dead_code)] #[allow(dead_code)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Reflect)] #[derive(Component, Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd, Reflect)]
pub enum ExplorationType { pub enum ExplorationType {
Portal = 0, Portal = 0,
Item = 1, Item = 1,
@ -61,16 +61,16 @@ impl Into<&str> for ExplorationType {
} }
} }
#[derive(Clone, Copy, Debug, Default, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Exploring(pub (f32, f32)); pub struct Exploring(pub (f32, f32));
impl_pointlike_for_tuple_component!(Exploring); impl_pointlike_for_tuple_component!(Exploring);
#[derive(Clone, Debug, Default, Deref, DerefMut)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut)]
pub struct FocusedExplorationType(pub Option<ExplorationType>); pub struct FocusedExplorationType(pub Option<ExplorationType>);
#[derive(Clone, Copy, Debug, Default, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Mappable; pub struct Mappable;
@ -456,7 +456,7 @@ where
A: Hash + Eq + Clone + Send + Sync, A: Hash + Eq + Clone + Send + Sync,
'a: 'static, 'a: 'static,
{ {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<ExplorationConfig<S, A>>() { if !app.world().contains_resource::<ExplorationConfig<S, A>>() {
app.insert_resource(ExplorationConfig::<S, A>::default()); app.insert_resource(ExplorationConfig::<S, A>::default());
} }
@ -470,53 +470,29 @@ where
.register_type::<Mappable>() .register_type::<Mappable>()
.add_system_to_stage( .add_system_to_stage(
CoreStage::PostUpdate, CoreStage::PostUpdate,
exploration_changed_announcement exploration_changed_announcement.chain(error_handler),
.system()
.chain(error_handler.system()),
); );
if config.exploration_control_states.is_empty() { if config.exploration_control_states.is_empty() {
app.add_system(exploration_focus::<S, A>.system()) app.add_system(exploration_focus::<S, A>)
.add_system( .add_system(exploration_type_focus::<S, A>.chain(error_handler))
exploration_type_focus::<S, A> .add_system(exploration_type_change::<S, A>.chain(error_handler))
.system() .add_system(navigate_to_explored::<S, A>)
.chain(error_handler.system()),
)
.add_system(
exploration_type_change::<S, A>
.system()
.chain(error_handler.system()),
)
.add_system(navigate_to_explored::<S, A>.system())
.add_system_to_stage( .add_system_to_stage(
CoreStage::PostUpdate, CoreStage::PostUpdate,
exploration_type_changed_announcement exploration_type_changed_announcement.chain(error_handler),
.system()
.chain(error_handler.system()),
); );
} else { } else {
let states = config.exploration_control_states; let states = config.exploration_control_states;
for state in states { for state in states {
app.add_system_set( app.add_system_set(
SystemSet::on_update(state.clone()) SystemSet::on_update(state.clone())
.with_system(exploration_focus::<S, A>.system()) .with_system(exploration_focus::<S, A>)
.with_system( .with_system(exploration_type_focus::<S, A>.chain(error_handler))
exploration_type_focus::<S, A> .with_system(exploration_type_change::<S, A>.chain(error_handler))
.system() .with_system(navigate_to_explored::<S, A>)
.chain(error_handler.system()), .with_system(exploration_type_changed_announcement.chain(error_handler)),
) )
.with_system( .add_system_set(SystemSet::on_exit(state).with_system(cleanup));
exploration_type_change::<S, A>
.system()
.chain(error_handler.system()),
)
.with_system(navigate_to_explored::<S, A>.system())
.with_system(
exploration_type_changed_announcement
.system()
.chain(error_handler.system()),
),
)
.add_system_set(SystemSet::on_exit(state).with_system(cleanup.system()));
} }
} }
} }

View File

@ -6,7 +6,7 @@ use derive_more::{Deref, DerefMut};
use crate::error::error_handler; use crate::error::error_handler;
#[derive(Clone, Debug, Default, Deref, DerefMut)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut)]
pub struct Log(pub Vec<LogEntry>); pub struct Log(pub Vec<LogEntry>);
impl Log { impl Log {
@ -18,7 +18,7 @@ impl Log {
} }
} }
#[derive(Clone, Debug)] #[derive(Component, Clone, Debug)]
pub struct LogEntry { pub struct LogEntry {
pub time: Instant, pub time: Instant,
pub message: String, pub message: String,
@ -47,10 +47,8 @@ fn read_log(
pub struct LogPlugin; pub struct LogPlugin;
impl Plugin for LogPlugin { impl Plugin for LogPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut App) {
app.add_startup_system(setup.system()).add_system_to_stage( app.add_startup_system(setup)
CoreStage::PostUpdate, .add_system_to_stage(CoreStage::PostUpdate, read_log.chain(error_handler));
read_log.system().chain(error_handler.system()),
);
} }
} }

View File

@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet};
use bevy::prelude::*; use bevy::prelude::*;
use bevy_rapier2d::prelude::*; use bevy_rapier2d::prelude::*;
use derive_more::{Deref, DerefMut}; use derive_more::{Deref, DerefMut};
pub use mapgen::Map; pub use mapgen::Map as MapgenMap;
use mapgen::{geometry::Rect as MRect, MapFilter, Tile}; use mapgen::{geometry::Rect as MRect, MapFilter, Tile};
use maze_generator::{prelude::*, recursive_backtracking::RbGenerator}; use maze_generator::{prelude::*, recursive_backtracking::RbGenerator};
use rand::prelude::StdRng; use rand::prelude::StdRng;
@ -22,23 +22,27 @@ impl From<mapgen::geometry::Point> for Coordinates {
} }
} }
#[derive(Clone, Debug, Default, Reflect)] #[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Area; pub struct Area;
#[derive(Clone, Debug, Default, Reflect)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)]
#[reflect(Component)]
pub struct Map(pub MapgenMap);
#[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct MapObstruction; pub struct MapObstruction;
#[derive(Clone, Debug, Default, Reflect)] #[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Portal; pub struct Portal;
#[derive(Clone, Debug, Default, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct SpawnColliderPerTile(pub bool); pub struct SpawnColliderPerTile(pub bool);
#[derive(Clone, Debug, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Debug, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct SpawnColliders(pub bool); pub struct SpawnColliders(pub bool);
@ -48,7 +52,7 @@ impl Default for SpawnColliders {
} }
} }
#[derive(Clone, Debug, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Debug, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct SpawnPortals(pub bool); pub struct SpawnPortals(pub bool);
@ -417,7 +421,7 @@ fn spawn_portals(
fn spawn_portal_colliders( fn spawn_portal_colliders(
mut commands: Commands, mut commands: Commands,
map: Query<(Entity, &SpawnColliders), With<Map>>, map: Query<(Entity, &SpawnColliders), With<Map>>,
portals: Query<(Entity, &Coordinates), Without<ColliderShape>>, portals: Query<(Entity, &Coordinates), Without<ColliderShapeComponent>>,
) { ) {
for (map_entity, spawn_colliders) in map.iter() { for (map_entity, spawn_colliders) in map.iter() {
if **spawn_colliders { if **spawn_colliders {
@ -479,17 +483,17 @@ fn area_description(
pub struct MapPlugin; pub struct MapPlugin;
impl Plugin for MapPlugin { impl Plugin for MapPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<MapConfig>() { if !app.world().contains_resource::<MapConfig>() {
app.insert_resource(MapConfig::default()); app.insert_resource(MapConfig::default());
} }
let config = app.world().get_resource::<MapConfig>().unwrap().clone(); let config = app.world().get_resource::<MapConfig>().unwrap().clone();
app.register_type::<Portal>() app.register_type::<Portal>()
.add_system(spawn_colliders.system()) .add_system(spawn_colliders)
.add_system(spawn_portals.system()) .add_system(spawn_portals)
.add_system(spawn_portal_colliders.system()); .add_system(spawn_portal_colliders);
if config.speak_area_descriptions { if config.speak_area_descriptions {
app.add_system_to_stage(CoreStage::PostUpdate, area_description.system()); app.add_system_to_stage(CoreStage::PostUpdate, area_description);
} }
} }
} }

View File

@ -13,7 +13,7 @@ use crate::{
pathfinding::Destination, pathfinding::Destination,
}; };
#[derive(Clone, Copy, Debug, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Copy, Debug, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct MaxSpeed(pub f32); pub struct MaxSpeed(pub f32);
@ -23,7 +23,7 @@ impl Default for MaxSpeed {
} }
} }
#[derive(Clone, Copy, Debug, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Copy, Debug, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct RotationSpeed(pub Angle); pub struct RotationSpeed(pub Angle);
@ -33,11 +33,11 @@ impl Default for RotationSpeed {
} }
} }
#[derive(Clone, Copy, Debug, Default, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Speed(pub f32); pub struct Speed(pub f32);
#[derive(Clone, Copy, Debug, Default, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Sprinting; pub struct Sprinting;
@ -49,11 +49,11 @@ fn movement_controls<S, A: 'static>(
mut query: Query< mut query: Query<
( (
Entity, Entity,
&mut RigidBodyVelocity, &mut RigidBodyVelocityComponent,
&mut Speed, &mut Speed,
&MaxSpeed, &MaxSpeed,
Option<&RotationSpeed>, Option<&RotationSpeed>,
&mut RigidBodyPosition, &mut RigidBodyPositionComponent,
Option<&Destination>, Option<&Destination>,
), ),
With<Player>, With<Player>,
@ -202,7 +202,7 @@ fn speak_direction(
Ok(()) Ok(())
} }
fn remove_speed(removed: RemovedComponents<Speed>, mut query: Query<&mut RigidBodyVelocity>) { fn remove_speed(removed: RemovedComponents<Speed>, mut query: Query<&mut RigidBodyVelocityComponent>) {
for entity in removed.iter() { for entity in removed.iter() {
if let Ok(mut velocity) = query.get_mut(entity) { if let Ok(mut velocity) = query.get_mut(entity) {
velocity.linvel = Vec2::ZERO.into(); velocity.linvel = Vec2::ZERO.into();
@ -259,7 +259,7 @@ where
A: Hash + Eq + Clone + Send + Sync, A: Hash + Eq + Clone + Send + Sync,
'a: 'static, 'a: 'static,
{ {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<NavigationConfig<S, A>>() { if !app.world().contains_resource::<NavigationConfig<S, A>>() {
app.insert_resource(NavigationConfig::<S, A>::default()); app.insert_resource(NavigationConfig::<S, A>::default());
} }
@ -271,16 +271,16 @@ where
app.register_type::<MaxSpeed>() app.register_type::<MaxSpeed>()
.register_type::<RotationSpeed>() .register_type::<RotationSpeed>()
.register_type::<Sprinting>() .register_type::<Sprinting>()
.add_system(update_direction.system()) .add_system(update_direction)
.add_system(speak_direction.system().chain(error_handler.system())) .add_system(speak_direction.chain(error_handler))
.add_system_to_stage(CoreStage::PostUpdate, remove_speed.system()); .add_system_to_stage(CoreStage::PostUpdate, remove_speed);
if config.movement_control_states.is_empty() { if config.movement_control_states.is_empty() {
app.add_system(movement_controls::<S, A>.system()); app.add_system(movement_controls::<S, A>);
} else { } else {
let states = config.movement_control_states; let states = config.movement_control_states;
for state in states { for state in states {
app.add_system_set( app.add_system_set(
SystemSet::on_update(state).with_system(movement_controls::<S, A>.system()), SystemSet::on_update(state).with_system(movement_controls::<S, A>),
); );
} }
} }

View File

@ -20,20 +20,20 @@ use crate::{
navigation::{RotationSpeed, Speed}, navigation::{RotationSpeed, Speed},
}; };
#[derive(Debug, Deref, DerefMut)] #[derive(Component, Debug, Deref, DerefMut)]
struct Calculating(Task<Option<Path>>); struct Calculating(Task<Option<Path>>);
#[derive(Clone, Copy, Debug, Default, Deref, DerefMut, Eq, Hash, PartialEq, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, Deref, DerefMut, Eq, Hash, PartialEq, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Destination(pub (i32, i32)); pub struct Destination(pub (i32, i32));
impl_pointlike_for_tuple_component!(Destination); impl_pointlike_for_tuple_component!(Destination);
#[derive(Clone, Debug, Default, Reflect)] #[derive(Component, Clone, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct NoPath; pub struct NoPath;
#[derive(Clone, Debug, Default, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Path(pub Vec<(i32, i32)>); pub struct Path(pub Vec<(i32, i32)>);
@ -62,15 +62,29 @@ struct StaticColliderComponentsSet(
HashMap<Entity, (ColliderPosition, ColliderShape, ColliderFlags)>, HashMap<Entity, (ColliderPosition, ColliderShape, ColliderFlags)>,
); );
impl impl<'world, 'state>
From<( From<(
&Query<'_, (Entity, &ColliderPosition, &SharedShape, &ColliderFlags)>, &Query<
&Query<'_, &MapObstruction>, 'world,
'state,
(
Entity,
&ColliderPositionComponent,
&ColliderShapeComponent,
&ColliderFlagsComponent,
),
>,
&Query<'world, 'state, &MapObstruction>,
)> for StaticColliderComponentsSet )> for StaticColliderComponentsSet
{ {
fn from( fn from(
query: ( query: (
&Query<(Entity, &ColliderPosition, &SharedShape, &ColliderFlags)>, &Query<(
Entity,
&ColliderPositionComponent,
&ColliderShapeComponent,
&ColliderFlagsComponent,
)>,
&Query<&MapObstruction>, &Query<&MapObstruction>,
), ),
) -> Self { ) -> Self {
@ -188,7 +202,10 @@ fn calculate_path(
query_pipeline: Res<QueryPipeline>, query_pipeline: Res<QueryPipeline>,
obstructions: Query<&MapObstruction>, obstructions: Query<&MapObstruction>,
collider_query: QueryPipelineColliderComponentsQuery, collider_query: QueryPipelineColliderComponentsQuery,
query: Query<(Entity, &Destination, &Coordinates, &ColliderShape), Changed<Destination>>, query: Query<
(Entity, &Destination, &Coordinates, &ColliderShapeComponent),
Changed<Destination>,
>,
map: Query<&Map>, map: Query<&Map>,
) { ) {
for (entity, destination, coordinates, shape) in query.iter() { for (entity, destination, coordinates, shape) in query.iter() {
@ -253,8 +270,8 @@ fn negotiate_path(
mut query: Query<( mut query: Query<(
Entity, Entity,
&mut Path, &mut Path,
&mut RigidBodyPosition, &mut RigidBodyPositionComponent,
&mut RigidBodyVelocity, &mut RigidBodyVelocityComponent,
&Speed, &Speed,
Option<&RotationSpeed>, Option<&RotationSpeed>,
)>, )>,
@ -312,11 +329,11 @@ fn remove_calculating(
pub struct PathfindingPlugin; pub struct PathfindingPlugin;
impl Plugin for PathfindingPlugin { impl Plugin for PathfindingPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut App) {
app.add_system(calculate_path.system()) app.add_system(calculate_path)
.add_system_to_stage(CoreStage::PostUpdate, remove_destination.system()) .add_system_to_stage(CoreStage::PostUpdate, remove_destination)
.add_system(poll_tasks.system()) .add_system(poll_tasks)
.add_system(negotiate_path.system()) .add_system(negotiate_path)
.add_system_to_stage(CoreStage::PostUpdate, remove_calculating.system()); .add_system_to_stage(CoreStage::PostUpdate, remove_calculating);
} }
} }

View File

@ -11,7 +11,7 @@ use crate::{
visibility::{Viewshed, VisibleEntities}, visibility::{Viewshed, VisibleEntities},
}; };
#[derive(Clone, Debug, Reflect)] #[derive(Component, Clone, Debug, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Footstep { pub struct Footstep {
pub sound: HandleId, pub sound: HandleId,
@ -39,7 +39,7 @@ impl Default for Footstep {
} }
} }
#[derive(Clone, Debug)] #[derive(Component, Clone, Debug)]
pub struct SoundIcon { pub struct SoundIcon {
pub sound: HandleId, pub sound: HandleId,
pub gain: f32, pub gain: f32,
@ -284,7 +284,7 @@ where
S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash, S: bevy::ecs::component::Component + Clone + Debug + Eq + Hash,
'a: 'static, 'a: 'static,
{ {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut App) {
if !app.world().contains_resource::<SoundConfig<S>>() { if !app.world().contains_resource::<SoundConfig<S>>() {
app.insert_resource(SoundConfig::<S>::default()); app.insert_resource(SoundConfig::<S>::default());
} }
@ -296,17 +296,15 @@ where
.unwrap(); .unwrap();
} }
app.register_type::<Footstep>() app.register_type::<Footstep>()
.add_system(add_footstep_sounds.system()) .add_system(add_footstep_sounds)
.add_system_to_stage( .add_system_to_stage(
CoreStage::PostUpdate, CoreStage::PostUpdate,
footstep.system().after(TransformSystem::TransformPropagate), footstep.after(TransformSystem::TransformPropagate),
) )
.add_system(add_sound_icon_sounds.system()) .add_system(add_sound_icon_sounds)
.add_system_to_stage( .add_system_to_stage(
CoreStage::PostUpdate, CoreStage::PostUpdate,
sound_icon::<S> sound_icon::<S>.after(TransformSystem::TransformPropagate),
.system()
.after(TransformSystem::TransformPropagate),
) )
.add_stage_after( .add_stage_after(
CoreStage::PostUpdate, CoreStage::PostUpdate,
@ -315,12 +313,12 @@ where
) )
.add_system_to_stage( .add_system_to_stage(
SOUND_ICON_AND_EXPLORATION_STAGE, SOUND_ICON_AND_EXPLORATION_STAGE,
sound_icon_exploration_focus_changed.system(), sound_icon_exploration_focus_changed,
) )
.add_system_to_stage( .add_system_to_stage(
SOUND_ICON_AND_EXPLORATION_STAGE, SOUND_ICON_AND_EXPLORATION_STAGE,
sound_icon_exploration_focus_removed.system(), sound_icon_exploration_focus_removed,
) )
.add_system(scale_sounds.system()); .add_system(scale_sounds);
} }
} }

View File

@ -17,15 +17,15 @@ use crate::{
utils::target_and_other, utils::target_and_other,
}; };
#[derive(Clone, Copy, Debug, Default, Reflect)] #[derive(Component, Clone, Copy, Debug, Default, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct DontLogWhenVisible; pub struct DontLogWhenVisible;
#[derive(Clone, Debug, Default, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct RevealedTiles(pub Vec<bool>); pub struct RevealedTiles(pub Vec<bool>);
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Component, Clone, Debug, Eq, PartialEq)]
pub struct Viewshed { pub struct Viewshed {
pub range: u32, pub range: u32,
pub visible_points: HashSet<(i32, i32)>, pub visible_points: HashSet<(i32, i32)>,
@ -139,7 +139,7 @@ impl Viewshed {
} }
} }
#[derive(Clone, Copy, Debug, Deref, DerefMut, Reflect)] #[derive(Component, Clone, Copy, Debug, Deref, DerefMut, Reflect)]
#[reflect(Component)] #[reflect(Component)]
pub struct Visible(pub u8); pub struct Visible(pub u8);
@ -159,7 +159,7 @@ impl Visible {
} }
} }
#[derive(Clone, Debug, Default, Deref, DerefMut)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut)]
pub struct VisibleEntities(HashSet<Entity>); pub struct VisibleEntities(HashSet<Entity>);
#[derive(Bundle, Default)] #[derive(Bundle, Default)]
@ -356,7 +356,7 @@ 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<&RigidBodyPosition>, Option<&ColliderPosition>), (&Name, Option<&RigidBodyPositionComponent>, Option<&ColliderPositionComponent>),
Without<DontLogWhenVisible>, Without<DontLogWhenVisible>,
>, >,
) { ) {
@ -402,17 +402,17 @@ pub const LOG_VISIBLE_LABEL: &str = "LOG_VISIBLE";
pub struct VisibilityPlugin; pub struct VisibilityPlugin;
impl Plugin for VisibilityPlugin { impl Plugin for VisibilityPlugin {
fn build(&self, app: &mut AppBuilder) { fn build(&self, app: &mut App) {
app.add_event::<VisibilityChanged>() app.add_event::<VisibilityChanged>()
.add_system(add_visibility_indices.system()) .add_system(add_visibility_indices)
.add_system_to_stage(CoreStage::PostUpdate, viewshed_removed.system()) .add_system_to_stage(CoreStage::PostUpdate, viewshed_removed)
.add_system_set( .add_system_set(
SystemSet::new() SystemSet::new()
.with_run_criteria(FixedTimestep::step(0.1)) .with_run_criteria(FixedTimestep::step(0.1))
.with_system(update_viewshed.system()), .with_system(update_viewshed),
) )
.add_system_to_stage(CoreStage::PostUpdate, remove_visible.system()) .add_system_to_stage(CoreStage::PostUpdate, remove_visible)
.add_system_to_stage(CoreStage::PostUpdate, update_revealed_tiles.system()) .add_system_to_stage(CoreStage::PostUpdate, update_revealed_tiles)
.add_system_to_stage(CoreStage::PostUpdate, log_visible.system()); .add_system_to_stage(CoreStage::PostUpdate, log_visible);
} }
} }