Remove state configuration from plugins.
This commit is contained in:
parent
fb34f6ef12
commit
c9c45b2569
|
@ -691,6 +691,7 @@ impl PluginGroup for CorePlugins {
|
|||
PluginGroupBuilder::start::<Self>()
|
||||
.add(crate::bevy_tts::TtsPlugin)
|
||||
.add(crate::bevy_synthizer::SynthizerPlugin::default())
|
||||
.add(crate::navigation::NavigationPlugin::default())
|
||||
.add(CorePlugin::default())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -374,27 +374,8 @@ fn cancel_on_navigate(
|
|||
}
|
||||
}
|
||||
|
||||
fn cleanup(
|
||||
mut commands: Commands,
|
||||
explorers: Query<Entity, With<Exploring>>,
|
||||
focus: Query<Entity, With<ExplorationFocused>>,
|
||||
) {
|
||||
for entity in &explorers {
|
||||
commands.entity(entity).remove::<Exploring>();
|
||||
}
|
||||
for entity in &focus {
|
||||
commands.entity(entity).remove::<ExplorationFocused>();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone, Debug, Default)]
|
||||
struct ExplorationConfig<State> {
|
||||
states: Vec<State>,
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone, Default)]
|
||||
pub struct ExplorationPlugin<ExplorationType, State, MapData> {
|
||||
pub states: Vec<State>,
|
||||
pub struct ExplorationPlugin<ExplorationType, MapData> {
|
||||
pub exploration_type: PhantomData<ExplorationType>,
|
||||
pub map_data: PhantomData<MapData>,
|
||||
}
|
||||
|
@ -402,18 +383,13 @@ pub struct ExplorationPlugin<ExplorationType, State, MapData> {
|
|||
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
|
||||
pub struct Exploration;
|
||||
|
||||
impl<ExplorationType, State, MapData> Plugin for ExplorationPlugin<ExplorationType, State, MapData>
|
||||
impl<ExplorationType, MapData> Plugin for ExplorationPlugin<ExplorationType, MapData>
|
||||
where
|
||||
ExplorationType: 'static + Component + Default + Copy + Ord + PartialEq + Into<String>,
|
||||
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::<ExplorationFocused>()
|
||||
app.register_type::<ExplorationFocused>()
|
||||
.register_type::<Mappable>()
|
||||
.register_type::<Explorable>()
|
||||
.add_plugins(InputManagerPlugin::<ExplorationAction>::default())
|
||||
|
@ -441,12 +417,5 @@ where
|
|||
FixedUpdate,
|
||||
(navigate_to_explored::<MapData>, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,15 +311,13 @@ fn add_speed(mut commands: Commands, query: Query<Entity, (Added<Speed>, Without
|
|||
}
|
||||
}
|
||||
|
||||
fn log_area_descriptions<State>(
|
||||
fn log_area_descriptions(
|
||||
mut events: EventReader<CollisionEvent>,
|
||||
areas: Query<(&Area, Option<&Name>)>,
|
||||
players: Query<&Player>,
|
||||
config: Res<NavigationPlugin<State>>,
|
||||
config: Res<NavigationPlugin>,
|
||||
mut log: Query<&mut Log>,
|
||||
) where
|
||||
State: 'static + Send + Sync,
|
||||
{
|
||||
) {
|
||||
if !config.log_area_descriptions {
|
||||
return;
|
||||
}
|
||||
|
@ -358,29 +356,24 @@ fn log_area_descriptions<State>(
|
|||
pub struct Movement;
|
||||
|
||||
#[derive(Resource, Clone, Debug)]
|
||||
pub struct NavigationPlugin<State> {
|
||||
pub states: Vec<State>,
|
||||
pub struct NavigationPlugin {
|
||||
pub describe_undescribed_areas: bool,
|
||||
pub log_area_descriptions: bool,
|
||||
}
|
||||
|
||||
impl<State> Default for NavigationPlugin<State> {
|
||||
impl Default for NavigationPlugin {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
states: vec![],
|
||||
describe_undescribed_areas: false,
|
||||
log_area_descriptions: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<State> Plugin for NavigationPlugin<State>
|
||||
where
|
||||
State: States,
|
||||
{
|
||||
impl Plugin for NavigationPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(self.clone());
|
||||
app.init_resource::<SnapTimers>()
|
||||
app.insert_resource(self.clone())
|
||||
.init_resource::<SnapTimers>()
|
||||
.register_type::<BackwardMovementFactor>()
|
||||
.register_type::<ForwardMovementFactor>()
|
||||
.register_type::<StrafeMovementFactor>()
|
||||
|
@ -398,14 +391,6 @@ where
|
|||
FixedUpdate,
|
||||
(tick_snap_timers, speak_direction.pipe(error_handler)),
|
||||
)
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(remove_direction, log_area_descriptions::<State>),
|
||||
);
|
||||
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_area_descriptions));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user