Skip to content

Commit

Permalink
remove callback, use plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Nov 18, 2023
1 parent edd52c4 commit 1a05a2b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 45 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ edition.workspace = true
bevy = "0.12.0"
bevy_rapier3d = { version = "0.23.0", features = ["simd-stable"] }
bevy_vrm = "0.0.5"
tracing = "0.1.40"
16 changes: 6 additions & 10 deletions app/examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ use bevy::{prelude::*, render::mesh::VertexAttributeValues};
use bevy_rapier3d::prelude::{Real, *};

fn main() {
let options = unavi_app::StartOptions {
file_path: "../assets".to_string(),
callback: Some(Box::new(callback)),
};

unavi_app::start(options);
}

fn callback(app: &mut App) {
app.add_systems(Startup, setup_world);
unavi_app::App::new()
.add_plugins(unavi_app::UnaviPlugin {
file_path: "../assets".to_string(),
})
.add_systems(Startup, setup_world)
.run();
}

const GROUND_SIZE: f32 = 40.0;
Expand Down
58 changes: 26 additions & 32 deletions app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,43 @@ mod player;
mod settings;
mod world;

pub struct StartOptions {
pub use bevy::app::App;

pub struct UnaviPlugin {
pub file_path: String,
pub callback: Option<Box<dyn FnOnce(&mut App)>>,
}

impl Default for StartOptions {
impl Default for UnaviPlugin {
fn default() -> Self {
Self {
file_path: "assets".to_string(),
callback: None,
}
}
}

pub fn start(options: StartOptions) {
let mut app = App::new();

app.add_plugins((
DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
fit_canvas_to_parent: true,
impl Plugin for UnaviPlugin {
fn build(&self, app: &mut App) {
app.add_plugins((
DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
fit_canvas_to_parent: true,
..default()
}),
..default()
})
.set(AssetPlugin {
file_path: self.file_path.clone(),
..default()
}),
..default()
})
.set(AssetPlugin {
file_path: options.file_path,
..default()
}),
RapierPhysicsPlugin::<NoUserData>::default(),
RapierDebugRenderPlugin::default(),
avatar::AvatarPlugin,
world::WorldPlugin,
settings::SettingsPlugin,
player::PlayerPlugin,
// bevy::diagnostic::LogDiagnosticsPlugin::default(),
// bevy::diagnostic::FrameTimeDiagnosticsPlugin::default(),
));

if let Some(callback) = options.callback {
callback(&mut app);
RapierPhysicsPlugin::<NoUserData>::default(),
RapierDebugRenderPlugin::default(),
avatar::AvatarPlugin,
world::WorldPlugin,
settings::SettingsPlugin,
player::PlayerPlugin,
// bevy::diagnostic::LogDiagnosticsPlugin::default(),
// bevy::diagnostic::FrameTimeDiagnosticsPlugin::default(),
));
}

app.run();
}
6 changes: 5 additions & 1 deletion web/frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use wasm_bindgen::prelude::wasm_bindgen;
#[wasm_bindgen]
pub fn hydrate() {
console_error_panic_hook::set_once();
unavi_app::start(unavi_app::StartOptions::default());

unavi_app::App::new()
.add_plugins(unavi_app::UnaviPlugin::default())
.run();

leptos::mount_to_body(unavi_web_app::App);
}

0 comments on commit 1a05a2b

Please sign in to comment.