Cursor gizmo mode changing inputs are working

This commit is contained in:
2024-07-11 11:14:56 -05:00
parent 3b03be7dbf
commit c75374a566

View File

@@ -5,7 +5,11 @@ pub struct BoidsDebugPlugin;
impl Plugin for BoidsDebugPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup)
.add_systems(FixedUpdate, update_cursor);
.add_systems(FixedUpdate, (
update_cursor,
update_scanner_mode,
print_gizmo_config,
));
}
}
@@ -44,13 +48,13 @@ impl Default for ScannerWidget {
#[derive(Component)]
struct Cursor;
#[derive(Component)]
#[derive(Component, Debug)]
enum SelectionMode {
NearestSingle,
CircularArea,
}
#[derive(Component)]
#[derive(Component, Debug)]
enum ScannerMode {
CenterOfMass,
Velocity,
@@ -77,3 +81,35 @@ fn update_cursor(
cursor.translation = cursor_in_world.extend(0.0);
}
}
// System to monitor for mouse and keyboard input and then update
// the scanner's modes accordingly.
fn update_scanner_mode(
keycodes: Res<ButtonInput<KeyCode>>,
mousebuttons: Res<ButtonInput<MouseButton>>,
mut scanner_query: Query<(&mut SelectionMode, &mut ScannerMode), With<Cursor>>,
) {
// I'm making another assertion that there is exactly one scanner.
let (mut select_mode, mut scan_mode) = scanner_query.get_single_mut().unwrap();
// Assign selection mode
if keycodes.just_pressed(KeyCode::Digit1) {
*select_mode = SelectionMode::NearestSingle;
} else if keycodes.just_pressed(KeyCode::Digit2) {
*select_mode = SelectionMode::CircularArea;
}
// Select property scanning mode
if mousebuttons.just_pressed(MouseButton::Left) {
*scan_mode = ScannerMode::CenterOfMass;
} else if mousebuttons.just_pressed(MouseButton::Right) {
*scan_mode = ScannerMode::Velocity;
}
}
fn print_gizmo_config(
query: Query<(&SelectionMode, &ScannerMode), With<Cursor>>,
) {
let (select, scan) = query.get_single().unwrap();
println!("Selection: {select:?}, Scanning: {scan:?}");
}