Skip to content

Commit

Permalink
refactor: example plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchantey committed Jul 10, 2024
1 parent a9c4116 commit 2b8e07a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 193 deletions.
2 changes: 1 addition & 1 deletion crates/beet_examples/examples/build_scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl SceneItem {
app.add_plugins((
utils::MostDefaultPlugins,
DefaultBeetPlugins::default(),
ExamplePlugins,
ExamplePluginTypesFull,
))
.finish();

Expand Down
16 changes: 13 additions & 3 deletions crates/beet_examples/src/plugins/example_default_plugins.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
use crate::beet::prelude::*;
use crate::prelude::load_scenes_from_args;
use bevy::asset::AssetMetaCheck;
use bevy::input::common_conditions::input_toggle_active;
use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use forky_bevy::systems::close_on_esc;


/// Default plugins and a couple of extra bells
/// and whistles for ui apps
#[derive(Default)]
pub struct ExampleDefaultPlugins;

Expand All @@ -21,7 +27,7 @@ impl Plugin for ExampleDefaultPlugins {
#[cfg(feature = "tokio")]
app.add_transport(NativeWsClient::new(DEFAULT_SOCKET_URL).unwrap());

app.add_plugins(
app.add_plugins((
DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
Expand All @@ -38,8 +44,12 @@ impl Plugin for ExampleDefaultPlugins {
..default()
})
.build(),
)
.add_systems(Update, close_on_esc);
WorldInspectorPlugin::default()
.run_if(input_toggle_active(false, KeyCode::Tab)),
))
.add_systems(Startup, load_scenes_from_args)
.add_systems(Update, close_on_esc)
/*-*/;
}
}

Expand Down
61 changes: 0 additions & 61 deletions crates/beet_examples/src/plugins/example_plugin_2d.rs

This file was deleted.

68 changes: 0 additions & 68 deletions crates/beet_examples/src/plugins/example_plugin_3d.rs

This file was deleted.

83 changes: 29 additions & 54 deletions crates/beet_examples/src/plugins/example_plugin_group.rs
Original file line number Diff line number Diff line change
@@ -1,85 +1,60 @@
use crate::beet::prelude::*;
use crate::prelude::*;
use bevy::app::PluginGroupBuilder;
use bevy::input::common_conditions::input_toggle_active;
use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;


/// Kitchen sink plugin, this is all you need for
/// ### Rendering
/// - text
/// - 2d
/// - 3d
/// ### Beet
/// - steering
/// - machine learning
///
pub struct ExamplePluginFull;

impl Plugin for ExamplePluginFull {
/// Some types, and ui elements
pub struct ExamplePluginBasics;

impl Plugin for ExamplePluginBasics {
fn build(&self, app: &mut App) {
app.add_plugins((
app
.add_plugins((
ExampleDefaultPlugins,
WorldInspectorPlugin::default()
.run_if(input_toggle_active(false, KeyCode::Tab)),
DefaultBeetPlugins,
ExamplePlugins,
ExamplePluginTypesBasic,
))
.add_systems(Startup, load_scenes_from_args);
/*-*/;
}
}
/// Just the essentials, no machine learning
pub struct ExamplePluginBasics;

impl Plugin for ExamplePluginBasics {
/// All types and ui elements
pub struct ExamplePluginFull;

impl Plugin for ExamplePluginFull {
fn build(&self, app: &mut App) {
app.add_plugins((ExampleDefaultPlugins, ExamplePluginTypesFull));
}
}


pub struct ExamplePluginTypesBasic;

impl Plugin for ExamplePluginTypesBasic {
fn build(&self, app: &mut App) {
app.add_plugins((
ExampleDefaultPlugins,
DefaultBeetPlugins,
BeetDebugPluginBase,
BeetDebugPluginStdout,
ExampleBasePlugin,
Example2dPlugin,
Example3dPlugin,
UiTerminalPlugin,
ExampleReplicatePlugin,
BundlePlaceholderPlugin,
))
.add_systems(Startup, load_scenes_from_args);
.register_type::<Collectable>();
}
}
pub struct ExamplePluginTypesFull;

pub struct ExampleBasePlugin;

impl Plugin for ExampleBasePlugin {
impl Plugin for ExamplePluginTypesFull {
fn build(&self, app: &mut App) {
app
.register_type::<Collectable>()
/*-*/;
}
}

#[derive(Default)]
pub struct ExamplePlugins;

impl PluginGroup for ExamplePlugins {
fn build(self) -> PluginGroupBuilder {
PluginGroupBuilder::start::<Self>()
.add(BeetDebugPluginBase)
.add(BeetDebugPluginStdout)
.add(ExampleBasePlugin)
.add(Example2dPlugin)
.add(Example3dPlugin)
.add(UiTerminalPlugin)
.add(ExampleReplicatePlugin)
.add(BundlePlaceholderPlugin)
.add(ExampleMlPlugin)
.add(FrozenLakePlugin)
app.add_plugins((
ExamplePluginTypesBasic,
ExampleMlPlugin,
FrozenLakePlugin,
));
}
}


pub struct ExampleMlPlugin;

impl Plugin for ExampleMlPlugin {
Expand Down
6 changes: 0 additions & 6 deletions crates/beet_examples/src/plugins/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
pub mod example_default_plugins;
#[allow(unused_imports)]
pub use self::example_default_plugins::*;
pub mod example_plugin_2d;
#[allow(unused_imports)]
pub use self::example_plugin_2d::*;
pub mod example_plugin_3d;
#[allow(unused_imports)]
pub use self::example_plugin_3d::*;
pub mod example_plugin_group;
#[allow(unused_imports)]
pub use self::example_plugin_group::*;

0 comments on commit 2b8e07a

Please sign in to comment.