diff --git a/src/app.rs b/src/app.rs index a518501..4993f75 100644 --- a/src/app.rs +++ b/src/app.rs @@ -72,11 +72,11 @@ pub struct DungeonApp { pub multi_drag_state: Option, pub multi_resize_state: Option, pub clipboard_items: Vec, + pub debug_mode: bool, } -impl Default for DungeonApp { - // Provides default settings for this type. - fn default() -> Self { +impl DungeonApp { + pub fn new(debug_mode: bool) -> Self { let settings = settings::load_settings().unwrap_or_default(); let mut app = Self { settings, @@ -105,6 +105,7 @@ impl Default for DungeonApp { multi_drag_state: None, multi_resize_state: None, clipboard_items: Vec::new(), + debug_mode, }; if app.settings.composition_mode { app.enter_composition_layout(); @@ -116,6 +117,13 @@ impl Default for DungeonApp { } } +impl Default for DungeonApp { + // Provides default settings for this type. + fn default() -> Self { + Self::new(false) + } +} + impl Drop for DungeonApp { // Cleans up background resources when the app is dropped. fn drop(&mut self) { @@ -129,6 +137,19 @@ impl Drop for DungeonApp { impl eframe::App for DungeonApp { // Runs one UI frame and handles app interaction. fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + // Reset transient states that depend on pointer being down if pointer is released + if !ctx.input(|i| i.pointer.primary_down()) { + self.drag_state = None; + self.multi_drag_state = None; + self.selection_box_drag = None; + self.add_corridor_drag = None; + self.add_door_drag = None; + } + if !ctx.input(|i| i.pointer.secondary_down()) { + self.resize_state = None; + self.multi_resize_state = None; + } + let panel_result = draw_side_panel( ctx, &mut self.settings, @@ -145,11 +166,15 @@ impl eframe::App for DungeonApp { for event in &i.events { match event { egui::Event::Copy => { - println!("DEBUG: Received Event::Copy"); + if self.debug_mode { + println!("DEBUG: Received Event::Copy"); + } copy_requested = true; } egui::Event::Paste(_) => { - println!("DEBUG: Received Event::Paste"); + if self.debug_mode { + println!("DEBUG: Received Event::Paste"); + } paste_requested = true; } egui::Event::Key { @@ -158,7 +183,9 @@ impl eframe::App for DungeonApp { modifiers, .. } if modifiers.command || modifiers.ctrl => { - println!("DEBUG: Received Key::C with command/ctrl"); + if self.debug_mode { + println!("DEBUG: Received Key::C with command/ctrl"); + } copy_requested = true; } egui::Event::Key { @@ -167,7 +194,9 @@ impl eframe::App for DungeonApp { modifiers, .. } if modifiers.command || modifiers.ctrl => { - println!("DEBUG: Received Key::V with command/ctrl"); + if self.debug_mode { + println!("DEBUG: Received Key::V with command/ctrl"); + } paste_requested = true; } egui::Event::Key { @@ -200,19 +229,27 @@ impl eframe::App for DungeonApp { if escape_pressed || panel_result.settings_changed { self.settings.add_tool = AddTool::None; if !self.clipboard_items.is_empty() { - println!("DEBUG: Clipboard cleared (Escape or settings changed)"); + if self.debug_mode { + println!("DEBUG: Clipboard cleared (Escape or settings changed)"); + } } self.clipboard_items.clear(); - println!("DEBUG: UI reset (Escape pressed or settings changed)"); + if self.debug_mode { + println!("DEBUG: UI reset (Escape pressed or settings changed)"); + } } clamp_dependent_settings(&mut self.settings); if undo_requested { - println!("DEBUG: Executing Undo"); + if self.debug_mode { + println!("DEBUG: Executing Undo"); + } self.undo(); } else if redo_requested { - println!("DEBUG: Executing Redo"); + if self.debug_mode { + println!("DEBUG: Executing Redo"); + } self.redo(); } @@ -432,7 +469,9 @@ impl eframe::App for DungeonApp { if copy_requested { if !self.selection.is_empty() { - println!("DEBUG: Copying {} selected items", self.selection.len()); + if self.debug_mode { + println!("DEBUG: Copying {} selected items", self.selection.len()); + } if let Some(layout) = self.levels.get(self.settings.active_level_index) { let mut items = Vec::new(); for selected in &self.selection { @@ -465,21 +504,27 @@ impl eframe::App for DungeonApp { } } } - println!("Copied {} items to clipboard", items.len()); + if self.debug_mode { + println!("Copied {} items to clipboard", items.len()); + } self.clipboard_items = items; } } else if let Some(room_idx) = self.hover_room_idx { if let Some(layout) = self.levels.get(self.settings.active_level_index) { if let Some(room) = layout.rooms.get(room_idx) { - println!( - "Copied room {}: {}x{} at ({}, {})", - room_idx, room.width, room.height, room.x, room.y - ); + if self.debug_mode { + println!( + "Copied room {}: {}x{} at ({}, {})", + room_idx, room.width, room.height, room.x, room.y + ); + } self.clipboard_items = vec![ClipboardItem::Room(room.clone())]; } } } else { - println!("Copy requested but nothing is selected or hovered."); + if self.debug_mode { + println!("Copy requested but nothing is selected or hovered."); + } } } @@ -496,39 +541,45 @@ impl eframe::App for DungeonApp { if let Some(grid_pos) = crate::interact::pointer_to_grid(pointer_pos, &geometry) { if !self.clipboard_items.is_empty() { - println!( - "Pasting {} items at grid pos: {:?}", - self.clipboard_items.len(), - grid_pos - ); + if self.debug_mode { + println!( + "Pasting {} items at grid pos: {:?}", + self.clipboard_items.len(), + grid_pos + ); + } self.paste_items(grid_pos); } else { - println!("Paste requested but clipboard is empty."); + if self.debug_mode { + println!("Paste requested but clipboard is empty."); + } } } } } else if paste_requested { - println!("Paste requested but ignored due to active interaction state:"); - if self.drag_state.is_some() { - println!(" - drag_state"); - } - if self.multi_drag_state.is_some() { - println!(" - multi_drag_state"); - } - if self.resize_state.is_some() { - println!(" - resize_state"); - } - if self.multi_resize_state.is_some() { - println!(" - multi_resize_state"); - } - if self.add_corridor_drag.is_some() { - println!(" - add_corridor_drag"); - } - if self.add_door_drag.is_some() { - println!(" - add_door_drag"); - } - if self.selection_box_drag.is_some() { - println!(" - selection_box_drag"); + if self.debug_mode { + println!("Paste requested but ignored due to active interaction state:"); + if self.drag_state.is_some() { + println!(" - drag_state"); + } + if self.multi_drag_state.is_some() { + println!(" - multi_drag_state"); + } + if self.resize_state.is_some() { + println!(" - resize_state"); + } + if self.multi_resize_state.is_some() { + println!(" - multi_resize_state"); + } + if self.add_corridor_drag.is_some() { + println!(" - add_corridor_drag"); + } + if self.add_door_drag.is_some() { + println!(" - add_door_drag"); + } + if self.selection_box_drag.is_some() { + println!(" - selection_box_drag"); + } } } diff --git a/src/interact/hit_test.rs b/src/interact/hit_test.rs index 8fd8308..26841b5 100644 --- a/src/interact/hit_test.rs +++ b/src/interact/hit_test.rs @@ -79,7 +79,9 @@ pub fn update_hover_targets(app: &mut DungeonApp, ctx: &egui::Context, geometry: app.hover_corridor_idx = None; app.hover_door_idx = None; app.hover_marker = None; - println!("DEBUG: Hovering over room {}", room_idx); + if app.debug_mode { + println!("DEBUG: Hovering over room {}", room_idx); + } } else { app.hover_room_idx = None; if let Some(corridor_drag) = corridor_drag_at_pointer(app, pointer_pos, geometry) { diff --git a/src/main.rs b/src/main.rs index 92d5b0c..7b9a714 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,11 +18,14 @@ use app::DungeonApp; // Boot the native app and start the egui event loop. fn main() -> eframe::Result<()> { + let args: Vec = std::env::args().collect(); + let debug_mode = args.contains(&"-debug".to_string()); + let options = eframe::NativeOptions::default(); eframe::run_native( "Desktop Dungeon Generator", options, - Box::new(|_cc| Ok(Box::new(DungeonApp::default()))), + Box::new(move |_cc| Ok(Box::new(DungeonApp::new(debug_mode)))), ) }