diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f17426..34022ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Add `enable_debug` field to `TimeRunnerPlugin` by [#15](https://github.com/Multirious/bevy_time_runner/pull/15) - Add `Tagging` variant to `TimeRunnerSet` by [#15](https://github.com/Multirious/bevy_time_runner/pull/15) - Systems now expected `TimeCtx` generic parameter by [#15](https://github.com/Multirious/bevy_time_runner/pull/15) + - `TimeRunnerPlugin` now expected `TimeCtx` generic parameter by [#19](https://github.com/Multirious/bevy_time_runner/pull/19) - Migrate to bevy 0.18 by [#16](https://github.com/Multirious/bevy_time_runner/pull/16) - Update flake by [#17](https://github.com/Multirious/bevy_time_runner/pull/17) diff --git a/src/lib.rs b/src/lib.rs index b7e93e5..c88f3e3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,90 +53,60 @@ use std::marker::PhantomData; pub use time_runner::*; pub use time_span::*; -/// Add [`time_runner_system::`] on schedule #[cfg(feature = "bevy_app")] -#[derive(Debug)] -pub struct TimeRunnerSystemsPlugin +/// Registers all types and adds TimeRunnerRegistrationPlugin with default config +pub struct TimeRunnerPlugin where TimeCtx: Default + Send + Sync + 'static, { - /// All systems will be put to this schedule + /// The schedule on which the time runners would run pub schedule: InternedScheduleLabel, /// The time step ticked by (for example, () for regular time or Fixed for fixed time steps) - _time_step: PhantomData, + marker: PhantomData, + /// Enables [`TimeRunnerDebugPlugin`] with default configuration. + /// You may manually insert [`TimeRunnerDebugPlugin`] for custom configuration. + #[cfg(feature = "debug")] + pub enable_debug: bool, } #[cfg(feature = "bevy_app")] -impl TimeRunnerSystemsPlugin +impl TimeRunnerPlugin where TimeCtx: Default + Send + Sync + 'static, { /// Initializes the plugin to run on the specified schedule - pub fn from_schedule_intern(schedule: InternedScheduleLabel) -> Self { + pub fn in_schedule(schedule: InternedScheduleLabel) -> Self { Self { schedule, - _time_step: Default::default(), + ..Default::default() } } } #[cfg(feature = "bevy_app")] -/// Registers all types and adds TimeRunnerRegistrationPlugin with default config -pub struct TimeRunnerPlugin { - /// The schedule where the default time runners will be registered (TimerRunner<()>) - pub schedule: InternedScheduleLabel, - /// Enables [`TimeRunnerDebugPlugin`] with default configuration. - /// You may manually insert [`TimeRunnerDebugPlugin`] for custom configuration. - #[cfg(feature = "debug")] - pub enable_debug: bool, -} - -#[cfg(feature = "bevy_app")] -impl Default for TimeRunnerPlugin { +impl Default for TimeRunnerPlugin +where + TimeCtx: Default + Send + Sync + 'static, +{ fn default() -> Self { TimeRunnerPlugin { schedule: PostUpdate.intern(), #[cfg(feature = "debug")] enable_debug: true, + marker: PhantomData::default(), } } } #[cfg(feature = "bevy_app")] -impl Plugin for TimeRunnerPlugin { - fn build(&self, app: &mut App) { - if !app.is_plugin_added::>() { - app.add_plugins(TimeRunnerSystemsPlugin::<()>::from_schedule_intern( - self.schedule, - )); - } - app.add_message::(); - - #[cfg(feature = "bevy_reflect")] - app.register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::() - .register_type::(); - - #[cfg(feature = "debug")] - if self.enable_debug && !app.is_plugin_added::() { - app.add_plugins(TimeRunnerDebugPlugin::default()); - } - } -} - -#[cfg(feature = "bevy_app")] -impl Plugin for TimeRunnerSystemsPlugin +impl Plugin for TimeRunnerPlugin where TimeCtx: Default + Send + Sync + 'static, { fn build(&self, app: &mut App) { + app.add_message::(); + + #[cfg(feature = "bevy_app")] app.configure_sets( self.schedule, ( @@ -154,6 +124,23 @@ where time_runner_system::.in_set(TimeRunnerSet::Progress), ), ); + + #[cfg(feature = "bevy_reflect")] + app.register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::() + .register_type::(); + + #[cfg(feature = "debug")] + if self.enable_debug && !app.is_plugin_added::() { + app.add_plugins(TimeRunnerDebugPlugin::default()); + } } }