optional parameter for debug
This commit is contained in:
+54
-3
@@ -72,11 +72,11 @@ pub struct DungeonApp {
|
||||
pub multi_drag_state: Option<MultiDragState>,
|
||||
pub multi_resize_state: Option<MultiResizeState>,
|
||||
pub clipboard_items: Vec<ClipboardItem>,
|
||||
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 => {
|
||||
if self.debug_mode {
|
||||
println!("DEBUG: Received Event::Copy");
|
||||
}
|
||||
copy_requested = true;
|
||||
}
|
||||
egui::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 => {
|
||||
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 => {
|
||||
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() {
|
||||
if self.debug_mode {
|
||||
println!("DEBUG: Clipboard cleared (Escape or settings changed)");
|
||||
}
|
||||
}
|
||||
self.clipboard_items.clear();
|
||||
if self.debug_mode {
|
||||
println!("DEBUG: UI reset (Escape pressed or settings changed)");
|
||||
}
|
||||
}
|
||||
|
||||
clamp_dependent_settings(&mut self.settings);
|
||||
|
||||
if undo_requested {
|
||||
if self.debug_mode {
|
||||
println!("DEBUG: Executing Undo");
|
||||
}
|
||||
self.undo();
|
||||
} else if redo_requested {
|
||||
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() {
|
||||
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,23 +504,29 @@ impl eframe::App for DungeonApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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 {
|
||||
if self.debug_mode {
|
||||
println!("Copy requested but nothing is selected or hovered.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if paste_requested
|
||||
&& self.drag_state.is_none()
|
||||
@@ -496,18 +541,23 @@ impl eframe::App for DungeonApp {
|
||||
if let Some(grid_pos) = crate::interact::pointer_to_grid(pointer_pos, &geometry)
|
||||
{
|
||||
if !self.clipboard_items.is_empty() {
|
||||
if self.debug_mode {
|
||||
println!(
|
||||
"Pasting {} items at grid pos: {:?}",
|
||||
self.clipboard_items.len(),
|
||||
grid_pos
|
||||
);
|
||||
}
|
||||
self.paste_items(grid_pos);
|
||||
} else {
|
||||
if self.debug_mode {
|
||||
println!("Paste requested but clipboard is empty.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if paste_requested {
|
||||
if self.debug_mode {
|
||||
println!("Paste requested but ignored due to active interaction state:");
|
||||
if self.drag_state.is_some() {
|
||||
println!(" - drag_state");
|
||||
@@ -531,6 +581,7 @@ impl eframe::App for DungeonApp {
|
||||
println!(" - selection_box_drag");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if response.double_clicked() {
|
||||
if let Some(text_idx) = self.hover_text_idx {
|
||||
|
||||
@@ -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;
|
||||
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) {
|
||||
|
||||
+4
-1
@@ -18,11 +18,14 @@ use app::DungeonApp;
|
||||
|
||||
// Boot the native app and start the egui event loop.
|
||||
fn main() -> eframe::Result<()> {
|
||||
let args: Vec<String> = 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)))),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user