From 0e5e5b8a42450cf156e16be6123ab7c01d3922c6 Mon Sep 17 00:00:00 2001 From: Toniman575 Date: Thu, 15 Aug 2024 12:58:45 +0200 Subject: [PATCH 1/4] Added keyboard movement --- src/lib.rs | 129 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 113 insertions(+), 16 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1d61a43..2f6cd42 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,13 +21,34 @@ pub struct PanCamPlugin; #[derive(Debug, Clone, Copy, SystemSet, PartialEq, Eq, Hash)] pub struct PanCamSystemSet; +/// How the camera is moved. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect, Default)] +pub enum MoveMode { + #[default] + /// Camera is moved through only the mouse. + Mouse, + /// Camera is moved through only the keyboard. + Keyboard, +} + +/// Which keys move the camera in particular directions for keyboard movement. +#[derive(Debug, Clone, PartialEq, Eq, Hash, Reflect)] +pub struct DirectionKeys { + up: Vec, + down: Vec, + left: Vec, + right: Vec, +} + impl Plugin for PanCamPlugin { fn build(&self, app: &mut App) { app.add_systems( Update, (do_camera_movement, do_camera_zoom).in_set(PanCamSystemSet), ) - .register_type::(); + .register_type::() + .register_type::() + .register_type::(); #[cfg(feature = "bevy_egui")] { @@ -179,8 +200,10 @@ fn clamp_to_safe_zone(pos: Vec2, aabb: Aabb2d, bounded_area_size: Vec2) -> Vec2 fn do_camera_movement( primary_window: Query<&Window, With>, mouse_buttons: Res>, + keyboard_buttons: Res>, mut query: Query<(&PanCam, &mut Transform, &OrthographicProjection)>, mut last_pos: Local>, + time: Res