From 11bf9b6772947f433df381a9d89333d2cf8cea5d Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 17 Sep 2023 19:51:35 +0200 Subject: [PATCH] Updated to bevy_dolly crate and bevy 0.11 --- Cargo.toml | 10 +++++----- examples/minimal.rs | 4 ++-- src/drivers/fpv.rs | 6 +++--- src/drivers/orbit.rs | 8 ++++---- src/lib.rs | 29 +++++++++++++++-------------- 5 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 19acb66..9c9f0c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,17 +23,17 @@ name = "bevy_config_cam" [dependencies] rand = "0.8" -strum = "0.24" -strum_macros = "0.24" -bevy_dolly = { git = "https://github.com/BlackPhlox/bevy_dolly", branch = "map_fork_v2" }#{ path = "../bevy_dolly" } +strum = "0.25" +strum_macros = "0.25" +bevy_dolly = "0.0.1" config_cam_derive = { path = "config_cam_derive" } [dependencies.bevy] -version = "0.10" +version = "0.11" features = ["bevy_render","bevy_pbr"] default-features = false [dev-dependencies.bevy] -version = "0.10" +version = "0.11" features = ["bevy_core_pipeline", "bevy_asset", "bevy_scene", "bevy_pbr", "bevy_gltf", "x11", "wayland"] default-features = false \ No newline at end of file diff --git a/examples/minimal.rs b/examples/minimal.rs index 2b8bc9e..132a808 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -4,8 +4,8 @@ use bevy_config_cam::*; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_plugin(ConfigCam) - .add_startup_system(setup) + .add_plugins(ConfigCam) + .add_systems(Startup, setup) .run(); } diff --git a/src/drivers/fpv.rs b/src/drivers/fpv.rs index 56cc555..f23b553 100644 --- a/src/drivers/fpv.rs +++ b/src/drivers/fpv.rs @@ -88,7 +88,7 @@ pub fn update_fpv_camera( move_vec.y -= 1.0; } - let boost: f32 = if keys.pressed(KeyCode::LShift) { + let boost: f32 = if keys.pressed(KeyCode::ShiftLeft) { 1. } else { 0. @@ -104,13 +104,13 @@ pub fn update_fpv_camera( move_vec, boost, boost_mult, - fps_state.0.eq(&MovementType::FirstPerson), + fps_state.get().eq(&MovementType::FirstPerson), ); if let Ok(window) = windows.get_single() { if !window.cursor.visible { if let Some(fpv) = r.try_driver_mut::() { - fpv.set_rotation(delta, sensitivity, move_vec, time_delta_seconds); + fpv.set_rotation(delta, move_vec, time_delta_seconds); } } } diff --git a/src/drivers/orbit.rs b/src/drivers/orbit.rs index 2c09b02..f36e54b 100644 --- a/src/drivers/orbit.rs +++ b/src/drivers/orbit.rs @@ -78,9 +78,9 @@ fn update_orbit_camera( delta += event.delta; } - config.rotation = Quat::from_rotation_y(delta.x); + config.transform.rotation = Quat::from_rotation_y(delta.x); - if pan.0.eq(&Pan::Keys) { + if pan.get().eq(&Pan::Keys) { if keys.just_pressed(KeyCode::Z) { camera_driver.rotate_yaw_pitch(-90.0, 0.0); } @@ -95,12 +95,12 @@ fn update_orbit_camera( } if keys.just_pressed(KeyCode::E) { - let result = if pan.0.eq(&Pan::Keys) { + let result = if pan.get().eq(&Pan::Keys) { Pan::Mouse } else { Pan::Keys }; - pan.0 = result; + *pan = State::new(result); println!("State:{result:?}"); } diff --git a/src/lib.rs b/src/lib.rs index 250d145..32153d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,8 +4,8 @@ pub mod drivers; use bevy::{ prelude::{ default, App, Camera, Commands, Component, - IntoSystemConfig, OrthographicProjection, Plugin, Query, Res, Resource, SystemSet, - Transform, Vec3, With, Camera3dBundle, Camera2dBundle, + OrthographicProjection, Plugin, Query, Res, Resource, SystemSet, + Transform, Vec3, With, Camera3dBundle, Camera2dBundle, Update, Startup, IntoSystemConfigs, }, render::camera::ScalingMode, }; @@ -24,18 +24,18 @@ impl Plugin for ConfigCam { fn build(&self, app: &mut App) { app.init_resource::() .init_resource::() - .add_plugin(DollyPosCtrl) - .add_plugin(DollyCursorGrab) + .add_plugins(DollyPosCtrl) + .add_plugins(DollyCursorGrab) .insert_resource(DollyPosCtrlConfig { - default_player: false, + player: Player::None, ..Default::default() }) - .add_startup_system(camera_setup.in_set(CCSetupLabel)) - .add_plugin(CCFpv) - .add_plugin(CCOrbit) - .add_system(change_driver_system) - .add_system(update_driver_system) - .add_system(update_look_at); + .add_systems(Startup, camera_setup.run_if(is_init_cameras).in_set(CCSetupLabel)) + .add_plugins(CCFpv) + .add_plugins(CCOrbit) + .add_systems(Update, change_driver_system) + .add_systems(Update, update_driver_system) + .add_systems(Update, update_look_at); } } @@ -80,10 +80,11 @@ impl Default for CCConfig { } } +fn is_init_cameras(config: Res) -> bool { + config.init_cameras +} + fn camera_setup(mut commands: Commands, config: Res) { - if !config.init_cameras { - return; - } commands.spawn(( MainCamera, PerspectiveCamera,