goud_engine/ecs/app/plugin.rs
1//! Plugin and PluginGroup traits for modular app composition.
2//!
3//! Plugins encapsulate reusable bundles of systems, resources, and configuration
4//! that can be added to an [`App`](super::App).
5
6use std::any::TypeId;
7
8use super::App;
9
10/// A modular unit of app configuration.
11///
12/// Plugins add systems, resources, and other configuration to an [`App`].
13/// They enable reusable, composable game engine features.
14///
15/// # Example
16///
17/// ```rust,ignore
18/// use goud_engine::ecs::app::{App, Plugin};
19///
20/// struct PhysicsPlugin;
21///
22/// impl Plugin for PhysicsPlugin {
23/// fn build(&self, app: &mut App) {
24/// // Add physics systems, resources, etc.
25/// }
26/// }
27/// ```
28pub trait Plugin: Send + Sync + 'static {
29 /// Configures the app with this plugin's systems and resources.
30 fn build(&self, app: &mut App);
31
32 /// Returns the name of this plugin for debugging.
33 fn name(&self) -> &'static str {
34 std::any::type_name::<Self>()
35 }
36
37 /// Returns the TypeIds of plugins this plugin depends on.
38 ///
39 /// Dependencies must be added before this plugin. The default
40 /// implementation returns an empty list (no dependencies).
41 fn dependencies(&self) -> Vec<TypeId> {
42 Vec::new()
43 }
44}
45
46/// A group of plugins that can be added to an [`App`] together.
47///
48/// Plugin groups provide a convenient way to add multiple related plugins
49/// at once.
50pub trait PluginGroup {
51 /// Adds all plugins in this group to the app.
52 fn build(self, app: &mut App);
53}