From 7aa33c9e7cca533bc6e9ffcd06f192094d3f9aaa Mon Sep 17 00:00:00 2001 From: grimsace Date: Tue, 7 Apr 2026 11:28:34 -0500 Subject: [PATCH] fixed a problem with doors not adding and doors not able to be deleted --- src/main.rs | 70 ++++++++++++++++++----------------------------------- src/ui.rs | 3 +++ 2 files changed, 27 insertions(+), 46 deletions(-) diff --git a/src/main.rs b/src/main.rs index ab5d059..31e0cd2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ use ui::{AddTool, UiSettings, draw_side_panel}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] enum ManualDoorKind { + Archway, Regular, Locked, Secret, @@ -642,12 +643,13 @@ impl DungeonApp { self.settings.add_tool = AddTool::None; } } - AddTool::Door | AddTool::LockedDoor | AddTool::SecretDoor => { + AddTool::Archway | AddTool::Door | AddTool::LockedDoor | AddTool::SecretDoor => { self.add_corridor_drag = None; if response.clicked() && let Some(pointer_pos) = response.interact_pointer_pos() { let kind = match self.settings.add_tool { + AddTool::Archway => ManualDoorKind::Archway, AddTool::Door => ManualDoorKind::Regular, AddTool::LockedDoor => ManualDoorKind::Locked, AddTool::SecretDoor => ManualDoorKind::Secret, @@ -1186,43 +1188,7 @@ impl DungeonApp { return; } - let edges = door_edges_for( - &self.layout.doors[idx], - self.settings.cols, - self.settings.rows, - ); - let mut spawned = Vec::new(); - for edge in edges { - if normalized_edge(edge.0, edge.1) == target { - continue; - } - if self - .layout - .doors - .iter() - .any(|d| normalized_edge(d.from, d.to) == normalized_edge(edge.0, edge.1)) - { - continue; - } - spawned.push(layout::Door { - from: edge.0, - to: edge.1, - width: 1, - span_width: false, - locked: false, - archway: true, - secret: false, - manual: true, - }); - } - let door = &mut self.layout.doors[idx]; - door.locked = false; - door.archway = true; - door.secret = false; - door.width = 1; - door.span_width = false; - door.manual = true; - self.layout.doors.extend(spawned); + self.layout.doors.remove(idx); return; } } @@ -1312,7 +1278,7 @@ impl DungeonApp { } let door = &mut self.layout.doors[idx]; door.locked = kind == ManualDoorKind::Locked; - door.archway = false; + door.archway = kind == ManualDoorKind::Archway; door.secret = kind == ManualDoorKind::Secret; door.width = 1; door.span_width = false; @@ -1325,15 +1291,12 @@ impl DungeonApp { } let corridor_cells = corridor_cells(&self.layout, self.settings.cols, self.settings.rows); - let a_in_room = room_index_at_cell(&self.layout.rooms, edge.0).is_some(); - let b_in_room = room_index_at_cell(&self.layout.rooms, edge.1).is_some(); + let a_room = room_index_at_cell(&self.layout.rooms, edge.0); + let b_room = room_index_at_cell(&self.layout.rooms, edge.1); let a_in_corridor = corridor_cells.contains(&edge.0); let b_in_corridor = corridor_cells.contains(&edge.1); - if !(a_in_room ^ b_in_room) { - return; - } - if !(a_in_corridor ^ b_in_corridor) { + if !manual_door_edge_allowed(a_room, b_room, a_in_corridor, b_in_corridor) { return; } @@ -1343,7 +1306,7 @@ impl DungeonApp { width: 1, span_width: false, locked: kind == ManualDoorKind::Locked, - archway: false, + archway: kind == ManualDoorKind::Archway, secret: kind == ManualDoorKind::Secret, manual: true, }); @@ -1883,6 +1846,21 @@ fn rooms_overlap(a: &layout::Room, b: &layout::Room) -> bool { a.x < b_right && a_right > b.x && a.y < b_bottom && a_bottom > b.y } +fn manual_door_edge_allowed( + a_room: Option, + b_room: Option, + a_in_corridor: bool, + b_in_corridor: bool, +) -> bool { + if matches!((a_room, b_room), (Some(a), Some(b)) if a == b) { + return false; + } + + let a_is_feature = a_room.is_some() || a_in_corridor; + let b_is_feature = b_room.is_some() || b_in_corridor; + a_is_feature || b_is_feature +} + fn resize_hit_cells( room: &layout::Room, room_idx: usize, diff --git a/src/ui.rs b/src/ui.rs index 424a916..54a3e1c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -180,6 +180,7 @@ pub enum AddTool { None, Room, Corridor, + Archway, Door, LockedDoor, SecretDoor, @@ -708,6 +709,7 @@ fn draw_add_tab(ui: &mut egui::Ui, settings: &mut UiSettings) { }); ui.add_space(4.0); ui.horizontal(|ui| { + ui.selectable_value(&mut settings.add_tool, AddTool::Archway, "Add Archway"); ui.selectable_value(&mut settings.add_tool, AddTool::Door, "Add Door"); ui.selectable_value( &mut settings.add_tool, @@ -729,6 +731,7 @@ fn draw_add_tab(ui: &mut egui::Ui, settings: &mut UiSettings) { match settings.add_tool { AddTool::Room => ui.label("Click to place a room at the grid cell."), AddTool::Corridor => ui.label("Click-drag to place a corridor between two cells."), + AddTool::Archway => ui.label("Click a valid room or corridor edge to place an archway."), AddTool::Door => ui.label("Click a room/corridor edge to place a door."), AddTool::LockedDoor => ui.label("Click a room/corridor edge to place a locked door."), AddTool::SecretDoor => ui.label("Click a room/corridor edge to place a secret door."),