diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a4d3d9e..a13283b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,8 +9,7 @@ env: # update with the name of the main binary binary: candy-blocks add_binaries_to_github_release: true - # todo: upload to itch - # itch_target: chrisbiscardi/candy-blocks + itch_target: chrisbiscardi/candy-blocks jobs: # Build for wasm diff --git a/src/brick/materials.rs b/src/brick/materials.rs index 33a60b0..51f7166 100644 --- a/src/brick/materials.rs +++ b/src/brick/materials.rs @@ -1,5 +1,5 @@ use bevy::{ - asset::{embedded_asset, embedded_path}, + asset::embedded_asset, prelude::*, render::render_resource::{AsBindGroup, ShaderRef}, }; diff --git a/src/camera_controller.rs b/src/camera_controller.rs new file mode 100644 index 0000000..5cbe492 --- /dev/null +++ b/src/camera_controller.rs @@ -0,0 +1,289 @@ +use bevy::{ + input::mouse::{ + MouseMotion, MouseScrollUnit, MouseWheel, + }, + prelude::*, +}; + +pub struct CameraControllerPlugin; + +impl Plugin for CameraControllerPlugin { + fn build(&self, app: &mut App) { + app.insert_resource(RotateCamera(false)) + .add_systems( + Update, + (mouse, camera_controller), + ); + } +} + +#[derive(Resource)] +struct RotateCamera(bool); + +fn mouse( + mut windows: Query<&mut Window>, + mouse: Res>, + key: Res>, + mut rotate_camera: ResMut, +) { + if mouse.just_pressed(MouseButton::Right) { + *rotate_camera = RotateCamera(true); + } + if mouse.just_released(MouseButton::Right) + || key.just_pressed(KeyCode::Escape) + { + *rotate_camera = RotateCamera(false); + } +} + +/// Provides basic movement functionality to the attached camera +#[derive(Component, Clone)] +pub struct CameraController { + pub enabled: bool, + pub initialized: bool, + pub sensitivity: f32, + pub key_forward: KeyCode, + pub key_back: KeyCode, + pub key_left: KeyCode, + pub key_right: KeyCode, + pub key_up: KeyCode, + pub key_down: KeyCode, + pub key_run: KeyCode, + pub mouse_key_enable_mouse: MouseButton, + pub mouse_key_enable_mouse_pan: MouseButton, + pub keyboard_key_enable_mouse: KeyCode, + pub walk_speed: f32, + pub run_speed: f32, + pub friction: f32, + pub pitch: f32, + pub yaw: f32, + pub velocity: Vec3, + pub orbit_focus: Vec3, + pub orbit_mode: bool, + pub scroll_wheel_speed: f32, + pub lock_y: bool, + // pub low_bounds: Vec3, + // pub high_bounds: Vec3, +} + +impl Default for CameraController { + fn default() -> Self { + Self { + enabled: true, + initialized: false, + sensitivity: 0.25, + key_forward: KeyCode::W, + key_back: KeyCode::S, + key_left: KeyCode::A, + key_right: KeyCode::D, + key_up: KeyCode::E, + key_down: KeyCode::Q, + key_run: KeyCode::ShiftLeft, + mouse_key_enable_mouse: MouseButton::Left, + mouse_key_enable_mouse_pan: MouseButton::Right, + keyboard_key_enable_mouse: KeyCode::M, + walk_speed: 5.0, + run_speed: 15.0, + friction: 0.5, + pitch: 0.0, + yaw: 0.0, + velocity: Vec3::ZERO, + orbit_focus: Vec3::ZERO, + orbit_mode: false, + scroll_wheel_speed: 0.1, + lock_y: false, + // low_bounds: Vec3::new(20., 5.0, 20.), + // high_bounds: Vec3::new(30., 10., 30.), + } + } +} + +pub fn camera_controller( + time: Res