From 2cd2b1876b72fabc68f3bfde5daa9229e31d2061 Mon Sep 17 00:00:00 2001 From: AlephCubed Date: Fri, 6 Feb 2026 19:15:29 -0800 Subject: [PATCH] Add Auto Plugin hooks. --- immediate_stats/src/bevy.rs | 6 ++++++ immediate_stats/src/bevy/auto_plugin.rs | 28 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 immediate_stats/src/bevy/auto_plugin.rs diff --git a/immediate_stats/src/bevy.rs b/immediate_stats/src/bevy.rs index fb59ff8..fd5f93b 100644 --- a/immediate_stats/src/bevy.rs +++ b/immediate_stats/src/bevy.rs @@ -1,6 +1,9 @@ #![cfg(feature = "bevy")] //! Contains systems and components for resetting [`StatContainer`]s in the Bevy game engine. +#[cfg(feature = "bevy_auto_plugin")] +mod auto_plugin; + use crate::StatContainer; use crate::modifier::Modifier; use crate::stat::Stat; @@ -12,6 +15,9 @@ use bevy_reflect::Reflect; use bevy_reflect::prelude::ReflectDefault; use std::marker::PhantomData; +#[cfg(feature = "bevy_auto_plugin")] +pub use auto_plugin::*; + /// Configures [system ordering](StatSystems) and registers types with the Bevy type registry. /// /// - [`StatSystems::Reset`] runs in `PreUpdate`. diff --git a/immediate_stats/src/bevy/auto_plugin.rs b/immediate_stats/src/bevy/auto_plugin.rs new file mode 100644 index 0000000..6d205fa --- /dev/null +++ b/immediate_stats/src/bevy/auto_plugin.rs @@ -0,0 +1,28 @@ +#![cfg(feature = "bevy_auto_plugin")] +//! Contains a hook for resetting [`StatContainer`]s using Bevy Auto Plugin. + +use crate::{ResetComponentPlugin, ResetResourcePlugin, StatContainer}; +use bevy_app::App; +use bevy_auto_plugin::prelude::AutoPluginBuildHook; +use bevy_ecs::component::Mutable; +use bevy_ecs::prelude::{Component, Resource}; + +/// A Bevy Auto Plugin hook that adds the [`ResetComponentPlugin`] for the component. +pub struct ResetComponentHook; + +impl + StatContainer + 'static> AutoPluginBuildHook + for ResetComponentHook +{ + fn on_build(&self, app: &mut App) { + app.add_plugins(ResetComponentPlugin::::new()); + } +} + +/// A Bevy Auto Plugin hook that adds the [`ResetResourcePlugin`] for the resource. +pub struct ResetResourceHook; + +impl AutoPluginBuildHook for ResetResourceHook { + fn on_build(&self, app: &mut App) { + app.add_plugins(ResetResourcePlugin::::new()); + } +} -- 2.51.2