use bevy::prelude::*;
use crate::ui::PendingAction;
use crate::{EditorState, EditorViewMode};
pub fn handle_keyboard_shortcuts(
keyboard: Res<ButtonInput<KeyCode>>,
mut editor_state: ResMut<EditorState>,
) {
let ctrl = keyboard.pressed(KeyCode::ControlLeft) || keyboard.pressed(KeyCode::ControlRight);
let shift = keyboard.pressed(KeyCode::ShiftLeft) || keyboard.pressed(KeyCode::ShiftRight);
if ctrl {
if keyboard.just_pressed(KeyCode::KeyZ) && !shift {
editor_state.pending_action = Some(PendingAction::Undo);
}
if (keyboard.just_pressed(KeyCode::KeyZ) && shift) || keyboard.just_pressed(KeyCode::KeyY) {
editor_state.pending_action = Some(PendingAction::Redo);
}
if keyboard.just_pressed(KeyCode::KeyC) {
editor_state.pending_action = Some(PendingAction::Copy);
}
if keyboard.just_pressed(KeyCode::KeyX) {
editor_state.pending_action = Some(PendingAction::Cut);
}
if keyboard.just_pressed(KeyCode::KeyV) {
editor_state.pending_action = Some(PendingAction::Paste);
}
if keyboard.just_pressed(KeyCode::KeyA) {
editor_state.pending_action = Some(PendingAction::SelectAll);
}
if keyboard.just_pressed(KeyCode::KeyS) {
editor_state.pending_action = Some(PendingAction::Save);
}
if keyboard.just_pressed(KeyCode::KeyO) {
editor_state.pending_action = Some(PendingAction::Open);
}
if keyboard.just_pressed(KeyCode::KeyN) {
editor_state.pending_action = Some(PendingAction::New);
}
}
if keyboard.just_pressed(KeyCode::Delete) || keyboard.just_pressed(KeyCode::Backspace) {
if !editor_state.tile_selection.is_empty() {
editor_state.pending_delete_selection = true;
}
}
if keyboard.just_pressed(KeyCode::Escape) {
if editor_state.is_moving {
editor_state.pending_cancel_move = true;
} else if editor_state.is_pasting {
editor_state.is_pasting = false;
} else {
editor_state.tile_selection.clear();
}
}
if !ctrl {
if keyboard.just_pressed(KeyCode::KeyW) {
editor_state.view_mode = match editor_state.view_mode {
EditorViewMode::Level => EditorViewMode::World,
EditorViewMode::World => EditorViewMode::Level,
};
}
if keyboard.just_pressed(KeyCode::KeyL) {
editor_state.view_mode = EditorViewMode::Level;
}
}
}