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_drag_state: Option<MultiDragState>,
|
||||||
pub multi_resize_state: Option<MultiResizeState>,
|
pub multi_resize_state: Option<MultiResizeState>,
|
||||||
pub clipboard_items: Vec<ClipboardItem>,
|
pub clipboard_items: Vec<ClipboardItem>,
|
||||||
|
pub debug_mode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DungeonApp {
|
impl DungeonApp {
|
||||||
// Provides default settings for this type.
|
pub fn new(debug_mode: bool) -> Self {
|
||||||
fn default() -> Self {
|
|
||||||
let settings = settings::load_settings().unwrap_or_default();
|
let settings = settings::load_settings().unwrap_or_default();
|
||||||
let mut app = Self {
|
let mut app = Self {
|
||||||
settings,
|
settings,
|
||||||
@@ -105,6 +105,7 @@ impl Default for DungeonApp {
|
|||||||
multi_drag_state: None,
|
multi_drag_state: None,
|
||||||
multi_resize_state: None,
|
multi_resize_state: None,
|
||||||
clipboard_items: Vec::new(),
|
clipboard_items: Vec::new(),
|
||||||
|
debug_mode,
|
||||||
};
|
};
|
||||||
if app.settings.composition_mode {
|
if app.settings.composition_mode {
|
||||||
app.enter_composition_layout();
|
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 {
|
impl Drop for DungeonApp {
|
||||||
// Cleans up background resources when the app is dropped.
|
// Cleans up background resources when the app is dropped.
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
@@ -129,6 +137,19 @@ impl Drop for DungeonApp {
|
|||||||
impl eframe::App for DungeonApp {
|
impl eframe::App for DungeonApp {
|
||||||
// Runs one UI frame and handles app interaction.
|
// Runs one UI frame and handles app interaction.
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
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(
|
let panel_result = draw_side_panel(
|
||||||
ctx,
|
ctx,
|
||||||
&mut self.settings,
|
&mut self.settings,
|
||||||
@@ -145,11 +166,15 @@ impl eframe::App for DungeonApp {
|
|||||||
for event in &i.events {
|
for event in &i.events {
|
||||||
match event {
|
match event {
|
||||||
egui::Event::Copy => {
|
egui::Event::Copy => {
|
||||||
|
if self.debug_mode {
|
||||||
println!("DEBUG: Received Event::Copy");
|
println!("DEBUG: Received Event::Copy");
|
||||||
|
}
|
||||||
copy_requested = true;
|
copy_requested = true;
|
||||||
}
|
}
|
||||||
egui::Event::Paste(_) => {
|
egui::Event::Paste(_) => {
|
||||||
|
if self.debug_mode {
|
||||||
println!("DEBUG: Received Event::Paste");
|
println!("DEBUG: Received Event::Paste");
|
||||||
|
}
|
||||||
paste_requested = true;
|
paste_requested = true;
|
||||||
}
|
}
|
||||||
egui::Event::Key {
|
egui::Event::Key {
|
||||||
@@ -158,7 +183,9 @@ impl eframe::App for DungeonApp {
|
|||||||
modifiers,
|
modifiers,
|
||||||
..
|
..
|
||||||
} if modifiers.command || modifiers.ctrl => {
|
} if modifiers.command || modifiers.ctrl => {
|
||||||
|
if self.debug_mode {
|
||||||
println!("DEBUG: Received Key::C with command/ctrl");
|
println!("DEBUG: Received Key::C with command/ctrl");
|
||||||
|
}
|
||||||
copy_requested = true;
|
copy_requested = true;
|
||||||
}
|
}
|
||||||
egui::Event::Key {
|
egui::Event::Key {
|
||||||
@@ -167,7 +194,9 @@ impl eframe::App for DungeonApp {
|
|||||||
modifiers,
|
modifiers,
|
||||||
..
|
..
|
||||||
} if modifiers.command || modifiers.ctrl => {
|
} if modifiers.command || modifiers.ctrl => {
|
||||||
|
if self.debug_mode {
|
||||||
println!("DEBUG: Received Key::V with command/ctrl");
|
println!("DEBUG: Received Key::V with command/ctrl");
|
||||||
|
}
|
||||||
paste_requested = true;
|
paste_requested = true;
|
||||||
}
|
}
|
||||||
egui::Event::Key {
|
egui::Event::Key {
|
||||||
@@ -200,19 +229,27 @@ impl eframe::App for DungeonApp {
|
|||||||
if escape_pressed || panel_result.settings_changed {
|
if escape_pressed || panel_result.settings_changed {
|
||||||
self.settings.add_tool = AddTool::None;
|
self.settings.add_tool = AddTool::None;
|
||||||
if !self.clipboard_items.is_empty() {
|
if !self.clipboard_items.is_empty() {
|
||||||
|
if self.debug_mode {
|
||||||
println!("DEBUG: Clipboard cleared (Escape or settings changed)");
|
println!("DEBUG: Clipboard cleared (Escape or settings changed)");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
self.clipboard_items.clear();
|
self.clipboard_items.clear();
|
||||||
|
if self.debug_mode {
|
||||||
println!("DEBUG: UI reset (Escape pressed or settings changed)");
|
println!("DEBUG: UI reset (Escape pressed or settings changed)");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
clamp_dependent_settings(&mut self.settings);
|
clamp_dependent_settings(&mut self.settings);
|
||||||
|
|
||||||
if undo_requested {
|
if undo_requested {
|
||||||
|
if self.debug_mode {
|
||||||
println!("DEBUG: Executing Undo");
|
println!("DEBUG: Executing Undo");
|
||||||
|
}
|
||||||
self.undo();
|
self.undo();
|
||||||
} else if redo_requested {
|
} else if redo_requested {
|
||||||
|
if self.debug_mode {
|
||||||
println!("DEBUG: Executing Redo");
|
println!("DEBUG: Executing Redo");
|
||||||
|
}
|
||||||
self.redo();
|
self.redo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,7 +469,9 @@ impl eframe::App for DungeonApp {
|
|||||||
|
|
||||||
if copy_requested {
|
if copy_requested {
|
||||||
if !self.selection.is_empty() {
|
if !self.selection.is_empty() {
|
||||||
|
if self.debug_mode {
|
||||||
println!("DEBUG: Copying {} selected items", self.selection.len());
|
println!("DEBUG: Copying {} selected items", self.selection.len());
|
||||||
|
}
|
||||||
if let Some(layout) = self.levels.get(self.settings.active_level_index) {
|
if let Some(layout) = self.levels.get(self.settings.active_level_index) {
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
for selected in &self.selection {
|
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());
|
println!("Copied {} items to clipboard", items.len());
|
||||||
|
}
|
||||||
self.clipboard_items = items;
|
self.clipboard_items = items;
|
||||||
}
|
}
|
||||||
} else if let Some(room_idx) = self.hover_room_idx {
|
} 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(layout) = self.levels.get(self.settings.active_level_index) {
|
||||||
if let Some(room) = layout.rooms.get(room_idx) {
|
if let Some(room) = layout.rooms.get(room_idx) {
|
||||||
|
if self.debug_mode {
|
||||||
println!(
|
println!(
|
||||||
"Copied room {}: {}x{} at ({}, {})",
|
"Copied room {}: {}x{} at ({}, {})",
|
||||||
room_idx, room.width, room.height, room.x, room.y
|
room_idx, room.width, room.height, room.x, room.y
|
||||||
);
|
);
|
||||||
|
}
|
||||||
self.clipboard_items = vec![ClipboardItem::Room(room.clone())];
|
self.clipboard_items = vec![ClipboardItem::Room(room.clone())];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if self.debug_mode {
|
||||||
println!("Copy requested but nothing is selected or hovered.");
|
println!("Copy requested but nothing is selected or hovered.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if paste_requested
|
if paste_requested
|
||||||
&& self.drag_state.is_none()
|
&& 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 let Some(grid_pos) = crate::interact::pointer_to_grid(pointer_pos, &geometry)
|
||||||
{
|
{
|
||||||
if !self.clipboard_items.is_empty() {
|
if !self.clipboard_items.is_empty() {
|
||||||
|
if self.debug_mode {
|
||||||
println!(
|
println!(
|
||||||
"Pasting {} items at grid pos: {:?}",
|
"Pasting {} items at grid pos: {:?}",
|
||||||
self.clipboard_items.len(),
|
self.clipboard_items.len(),
|
||||||
grid_pos
|
grid_pos
|
||||||
);
|
);
|
||||||
|
}
|
||||||
self.paste_items(grid_pos);
|
self.paste_items(grid_pos);
|
||||||
} else {
|
} else {
|
||||||
|
if self.debug_mode {
|
||||||
println!("Paste requested but clipboard is empty.");
|
println!("Paste requested but clipboard is empty.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if paste_requested {
|
} else if paste_requested {
|
||||||
|
if self.debug_mode {
|
||||||
println!("Paste requested but ignored due to active interaction state:");
|
println!("Paste requested but ignored due to active interaction state:");
|
||||||
if self.drag_state.is_some() {
|
if self.drag_state.is_some() {
|
||||||
println!(" - drag_state");
|
println!(" - drag_state");
|
||||||
@@ -531,6 +581,7 @@ impl eframe::App for DungeonApp {
|
|||||||
println!(" - selection_box_drag");
|
println!(" - selection_box_drag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if response.double_clicked() {
|
if response.double_clicked() {
|
||||||
if let Some(text_idx) = self.hover_text_idx {
|
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_corridor_idx = None;
|
||||||
app.hover_door_idx = None;
|
app.hover_door_idx = None;
|
||||||
app.hover_marker = None;
|
app.hover_marker = None;
|
||||||
|
if app.debug_mode {
|
||||||
println!("DEBUG: Hovering over room {}", room_idx);
|
println!("DEBUG: Hovering over room {}", room_idx);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
app.hover_room_idx = None;
|
app.hover_room_idx = None;
|
||||||
if let Some(corridor_drag) = corridor_drag_at_pointer(app, pointer_pos, geometry) {
|
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.
|
// Boot the native app and start the egui event loop.
|
||||||
fn main() -> eframe::Result<()> {
|
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();
|
let options = eframe::NativeOptions::default();
|
||||||
|
|
||||||
eframe::run_native(
|
eframe::run_native(
|
||||||
"Desktop Dungeon Generator",
|
"Desktop Dungeon Generator",
|
||||||
options,
|
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