fixed a bug with deleting doors
This commit is contained in:
@@ -36,6 +36,7 @@ pub struct Door {
|
|||||||
pub locked: bool,
|
pub locked: bool,
|
||||||
pub archway: bool,
|
pub archway: bool,
|
||||||
pub secret: bool,
|
pub secret: bool,
|
||||||
|
pub manual: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -362,6 +363,7 @@ pub fn apply_doors(
|
|||||||
locked: place_door && rng.next_f32() <= locked,
|
locked: place_door && rng.next_f32() <= locked,
|
||||||
archway: !place_door,
|
archway: !place_door,
|
||||||
secret: false,
|
secret: false,
|
||||||
|
manual: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,6 +379,7 @@ pub fn apply_doors(
|
|||||||
locked: place_door && rng.next_f32() <= locked,
|
locked: place_door && rng.next_f32() <= locked,
|
||||||
archway: !place_door,
|
archway: !place_door,
|
||||||
secret: false,
|
secret: false,
|
||||||
|
manual: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -397,6 +400,7 @@ pub fn apply_doors(
|
|||||||
locked: place_door && rng.next_f32() <= locked,
|
locked: place_door && rng.next_f32() <= locked,
|
||||||
archway: !place_door,
|
archway: !place_door,
|
||||||
secret: false,
|
secret: false,
|
||||||
|
manual: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,6 +422,7 @@ pub fn apply_doors(
|
|||||||
locked: rng.next_f32() <= locked,
|
locked: rng.next_f32() <= locked,
|
||||||
archway: false,
|
archway: false,
|
||||||
secret: false,
|
secret: false,
|
||||||
|
manual: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,6 +437,7 @@ pub fn apply_doors(
|
|||||||
locked: rng.next_f32() <= locked,
|
locked: rng.next_f32() <= locked,
|
||||||
archway: false,
|
archway: false,
|
||||||
secret: false,
|
secret: false,
|
||||||
|
manual: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -470,6 +476,7 @@ fn apply_packed_room_doors(layout: &mut DungeonLayout, seed: u64, settings: Door
|
|||||||
locked: place_door && rng.next_f32() <= locked,
|
locked: place_door && rng.next_f32() <= locked,
|
||||||
archway: !place_door,
|
archway: !place_door,
|
||||||
secret: false,
|
secret: false,
|
||||||
|
manual: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+30
@@ -37,6 +37,7 @@ fn main() -> eframe::Result<()> {
|
|||||||
struct DungeonApp {
|
struct DungeonApp {
|
||||||
settings: UiSettings,
|
settings: UiSettings,
|
||||||
layout: DungeonLayout,
|
layout: DungeonLayout,
|
||||||
|
suppressed_auto_door_edges: HashSet<((usize, usize), (usize, usize))>,
|
||||||
drag_state: Option<DragState>,
|
drag_state: Option<DragState>,
|
||||||
export_rx: Option<mpsc::Receiver<Result<std::path::PathBuf, String>>>,
|
export_rx: Option<mpsc::Receiver<Result<std::path::PathBuf, String>>>,
|
||||||
pending_delete: bool,
|
pending_delete: bool,
|
||||||
@@ -70,6 +71,7 @@ impl Default for DungeonApp {
|
|||||||
Self {
|
Self {
|
||||||
settings,
|
settings,
|
||||||
layout,
|
layout,
|
||||||
|
suppressed_auto_door_edges: HashSet::new(),
|
||||||
drag_state: None,
|
drag_state: None,
|
||||||
export_rx: None,
|
export_rx: None,
|
||||||
pending_delete: false,
|
pending_delete: false,
|
||||||
@@ -232,6 +234,7 @@ impl DungeonApp {
|
|||||||
packed_rooms: self.settings.pack_rooms_without_corridors,
|
packed_rooms: self.settings.pack_rooms_without_corridors,
|
||||||
..DungeonLayout::default()
|
..DungeonLayout::default()
|
||||||
};
|
};
|
||||||
|
self.suppressed_auto_door_edges.clear();
|
||||||
self.drag_state = None;
|
self.drag_state = None;
|
||||||
self.add_corridor_drag = None;
|
self.add_corridor_drag = None;
|
||||||
self.resize_state = None;
|
self.resize_state = None;
|
||||||
@@ -244,6 +247,7 @@ impl DungeonApp {
|
|||||||
// Regenerate the dungeon layout from current settings and reset drag state.
|
// Regenerate the dungeon layout from current settings and reset drag state.
|
||||||
fn regenerate_layout(&mut self) {
|
fn regenerate_layout(&mut self) {
|
||||||
self.drag_state = None;
|
self.drag_state = None;
|
||||||
|
self.suppressed_auto_door_edges.clear();
|
||||||
self.layout = layout::generate_layout(
|
self.layout = layout::generate_layout(
|
||||||
self.settings.cols,
|
self.settings.cols,
|
||||||
self.settings.rows,
|
self.settings.rows,
|
||||||
@@ -464,6 +468,11 @@ impl DungeonApp {
|
|||||||
self.settings.cols,
|
self.settings.cols,
|
||||||
self.settings.rows,
|
self.settings.rows,
|
||||||
);
|
);
|
||||||
|
self.layout.doors.retain(|door| {
|
||||||
|
!door_edges_for(door, self.settings.cols, self.settings.rows)
|
||||||
|
.iter()
|
||||||
|
.any(|edge| self.suppressed_auto_door_edges.contains(edge))
|
||||||
|
});
|
||||||
layout::apply_windows(
|
layout::apply_windows(
|
||||||
&mut self.layout,
|
&mut self.layout,
|
||||||
self.settings.seed,
|
self.settings.seed,
|
||||||
@@ -915,6 +924,18 @@ impl DungeonApp {
|
|||||||
.iter()
|
.iter()
|
||||||
.any(|e| normalized_edge(e.0, e.1) == target)
|
.any(|e| normalized_edge(e.0, e.1) == target)
|
||||||
}) {
|
}) {
|
||||||
|
if !self.layout.doors[idx].manual {
|
||||||
|
for edge in door_edges_for(
|
||||||
|
&self.layout.doors[idx],
|
||||||
|
self.settings.cols,
|
||||||
|
self.settings.rows,
|
||||||
|
) {
|
||||||
|
self.suppressed_auto_door_edges.insert(edge);
|
||||||
|
}
|
||||||
|
self.layout.doors.remove(idx);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let edges = door_edges_for(
|
let edges = door_edges_for(
|
||||||
&self.layout.doors[idx],
|
&self.layout.doors[idx],
|
||||||
self.settings.cols,
|
self.settings.cols,
|
||||||
@@ -941,6 +962,7 @@ impl DungeonApp {
|
|||||||
locked: false,
|
locked: false,
|
||||||
archway: true,
|
archway: true,
|
||||||
secret: false,
|
secret: false,
|
||||||
|
manual: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let door = &mut self.layout.doors[idx];
|
let door = &mut self.layout.doors[idx];
|
||||||
@@ -949,6 +971,7 @@ impl DungeonApp {
|
|||||||
door.secret = false;
|
door.secret = false;
|
||||||
door.width = 1;
|
door.width = 1;
|
||||||
door.span_width = false;
|
door.span_width = false;
|
||||||
|
door.manual = true;
|
||||||
self.layout.doors.extend(spawned);
|
self.layout.doors.extend(spawned);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1031,6 +1054,7 @@ impl DungeonApp {
|
|||||||
locked: false,
|
locked: false,
|
||||||
archway: true,
|
archway: true,
|
||||||
secret: false,
|
secret: false,
|
||||||
|
manual: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
let door = &mut self.layout.doors[idx];
|
let door = &mut self.layout.doors[idx];
|
||||||
@@ -1039,6 +1063,10 @@ impl DungeonApp {
|
|||||||
door.secret = kind == ManualDoorKind::Secret;
|
door.secret = kind == ManualDoorKind::Secret;
|
||||||
door.width = 1;
|
door.width = 1;
|
||||||
door.span_width = false;
|
door.span_width = false;
|
||||||
|
door.manual = true;
|
||||||
|
for edge in door_edges_for(door, self.settings.cols, self.settings.rows) {
|
||||||
|
self.suppressed_auto_door_edges.remove(&edge);
|
||||||
|
}
|
||||||
self.layout.doors.extend(spawned);
|
self.layout.doors.extend(spawned);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1064,7 +1092,9 @@ impl DungeonApp {
|
|||||||
locked: kind == ManualDoorKind::Locked,
|
locked: kind == ManualDoorKind::Locked,
|
||||||
archway: false,
|
archway: false,
|
||||||
secret: kind == ManualDoorKind::Secret,
|
secret: kind == ManualDoorKind::Secret,
|
||||||
|
manual: true,
|
||||||
});
|
});
|
||||||
|
self.suppressed_auto_door_edges.remove(&target);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the nearest cell edge under the pointer for door placement.
|
// Find the nearest cell edge under the pointer for door placement.
|
||||||
|
|||||||
Reference in New Issue
Block a user