diff --git a/src/core.rs b/src/core.rs index a8e327d..6d03afe 100644 --- a/src/core.rs +++ b/src/core.rs @@ -701,6 +701,7 @@ impl PluginGroup for CorePlugins { PluginGroupBuilder::start::() .add(crate::bevy_tts::TtsPlugin) .add(crate::bevy_synthizer::SynthizerPlugin::default()) + .add(crate::navigation::NavigationPlugin::default()) .add(CorePlugin::default()) } } diff --git a/src/exploration.rs b/src/exploration.rs index a91660c..788c7ca 100644 --- a/src/exploration.rs +++ b/src/exploration.rs @@ -376,27 +376,8 @@ fn cancel_on_navigate( } } -fn cleanup( - mut commands: Commands, - explorers: Query>, - focus: Query>, -) { - for entity in &explorers { - commands.entity(entity).remove::(); - } - for entity in &focus { - commands.entity(entity).remove::(); - } -} - -#[derive(Resource, Clone, Debug, Default)] -struct ExplorationConfig { - states: Vec, -} - #[derive(Resource, Clone, Default)] -pub struct ExplorationPlugin { - pub states: Vec, +pub struct ExplorationPlugin { pub exploration_type: PhantomData, pub map_data: PhantomData, } @@ -404,18 +385,13 @@ pub struct ExplorationPlugin { #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)] pub struct Exploration; -impl Plugin for ExplorationPlugin +impl Plugin for ExplorationPlugin where ExplorationType: 'static + Component + Default + Copy + Ord + PartialEq + Into, - State: States, MapData: 'static + Clone + Default + Send + Sync, { fn build(&self, app: &mut App) { - let config = ExplorationConfig { - states: self.states.clone(), - }; - app.insert_resource(config.clone()) - .register_type::() + app.register_type::() .register_type::() .register_type::() .add_plugins(InputManagerPlugin::::default()) @@ -443,12 +419,5 @@ where FixedUpdate, (navigate_to_explored::, cancel_on_navigate).in_set(Exploration), ); - if !config.states.is_empty() { - let states = config.states; - for state in states { - app.configure_sets(FixedUpdate, Exploration.run_if(in_state(state.clone()))) - .add_systems(OnExit(state), cleanup); - } - } } } diff --git a/src/navigation.rs b/src/navigation.rs index fc90a05..f2bc707 100644 --- a/src/navigation.rs +++ b/src/navigation.rs @@ -312,15 +312,13 @@ fn add_speed( } } -fn log_zone_descriptions( +fn log_zone_descriptions( mut events: EventReader, zones: Query<(&ColliderAabb, Option<&Name>), With>, players: Query<&Player>, - config: Res>, + config: Res, mut log: Query<&mut Log>, -) where - State: 'static + Send + Sync, -{ +) { if !config.log_area_descriptions { return; } @@ -361,29 +359,24 @@ fn log_zone_descriptions( pub struct Movement; #[derive(Resource, Clone, Debug)] -pub struct NavigationPlugin { - pub states: Vec, +pub struct NavigationPlugin { pub describe_undescribed_areas: bool, pub log_area_descriptions: bool, } -impl Default for NavigationPlugin { +impl Default for NavigationPlugin { fn default() -> Self { Self { - states: vec![], describe_undescribed_areas: false, log_area_descriptions: true, } } } -impl Plugin for NavigationPlugin -where - State: States, -{ +impl Plugin for NavigationPlugin { fn build(&self, app: &mut App) { - app.insert_resource(self.clone()); - app.init_resource::() + app.insert_resource(self.clone()) + .init_resource::() .register_type::() .register_type::() .register_type::() @@ -401,14 +394,6 @@ where FixedUpdate, (tick_snap_timers, speak_direction.pipe(error_handler)), ) - .add_systems( - PostUpdate, - (remove_direction, log_zone_descriptions::), - ); - if !self.states.is_empty() { - for state in &self.states { - app.configure_sets(Update, Movement.run_if(in_state(state.clone()))); - } - } + .add_systems(PostUpdate, (remove_direction, log_zone_descriptions)); } }