From d95d3e8f9f6480ac66c1580b257afc935f3e4e20 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 18 Mar 2024 00:04:23 +0100 Subject: [PATCH] pluginize everything --- src/audio.rs | 8 ++++++++ src/main.rs | 40 +++++++++++++++++++--------------------- src/world.rs | 8 ++++++++ 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/audio.rs b/src/audio.rs index 6f984f5..1c8c801 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -1,6 +1,14 @@ use bevy::prelude::*; use bevy::audio::PlaybackMode; +pub struct AudioPlugin; +impl Plugin for AudioPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, setup); + app.add_systems(Update, toggle_bgm); + } +} + #[derive(Component)] pub struct ComponentBGM; diff --git a/src/main.rs b/src/main.rs index bbf990e..fd8b520 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,34 +5,32 @@ mod settings; mod hud; mod actor; -use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode }; +use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode}; use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}; use bevy::prelude::*; fn main() { - App::new() - .add_systems(Startup, ( - setup, - audio::setup, - world::setup, - )) - .add_systems(Update, ( - handle_input, - audio::toggle_bgm, - world::asset_loaded.after(world::load_cubemap_asset), - )) - .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) - .add_plugins(( + App::new().add_plugins(OutFlyPlugin).run(); +} + +pub struct OutFlyPlugin; +impl Plugin for OutFlyPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, setup); + app.add_systems(Update, handle_input); + app.insert_resource(settings::Settings::default()); + app.add_plugins(( + DefaultPlugins.set(ImagePlugin::default_nearest()), + FrameTimeDiagnosticsPlugin, + LogDiagnosticsPlugin::default(), + + world::WorldPlugin, camera::CameraControllerPlugin, hud::HudPlugin, actor::ActorPlugin, - )) - .add_plugins(( - FrameTimeDiagnosticsPlugin, - LogDiagnosticsPlugin::default(), - )) - .insert_resource(settings::Settings::default()) - .run(); + audio::AudioPlugin, + )); + } } fn setup( diff --git a/src/world.rs b/src/world.rs index 5dff907..494cdc0 100644 --- a/src/world.rs +++ b/src/world.rs @@ -7,6 +7,14 @@ use bevy::pbr::CascadeShadowConfigBuilder; use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings}; use std::f32::consts::PI; +pub struct WorldPlugin; +impl Plugin for WorldPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Startup, setup); + app.add_systems(Update, asset_loaded.after(load_cubemap_asset)); + } +} + #[derive(Resource)] pub struct Cubemap { is_loaded: bool,