Skip to content

Commit f05d18b

Browse files
committed
correct ids on load
1 parent 57eaee4 commit f05d18b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/grid/plugin.rs

+7
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,11 @@ impl ComponentIDs {
4949
pub fn decrement_wall_ids(&mut self) {
5050
self.current_wall_id -= 1;
5151
}
52+
53+
/// Resets **all** ids to 0
54+
pub fn reset(&mut self) {
55+
self.current_mic_id = 0;
56+
self.current_source_id = 0;
57+
self.current_wall_id = 0;
58+
}
5259
}

src/ui/dialog.rs

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::components::source::Source;
88
use crate::components::wall::{CircWall, RectWall};
99
use crate::events::UpdateWalls;
1010
use crate::grid::grid::Grid;
11+
use crate::grid::plugin::ComponentIDs;
1112

1213
/// Marker component for the file dialog and the corresponding event.
1314
pub struct SaveFileContents;
@@ -33,6 +34,7 @@ pub fn file_loaded(
3334
rect_walls: Query<(Entity, &RectWall)>,
3435
circ_walls: Query<(Entity, &CircWall)>,
3536
ui_state: Res<UiState>,
37+
mut ids: ResMut<ComponentIDs>,
3638
) {
3739
if let Some(data) = ev_loaded.read().next() {
3840
let save_data = serde_json::from_slice::<SaveData>(&data.contents).unwrap();
@@ -51,18 +53,24 @@ pub fn file_loaded(
5153
commands.entity(entity).despawn();
5254
}
5355

56+
ids.reset();
57+
5458
// Load entities
5559
for source in save_data.sources {
5660
commands.spawn(source);
61+
ids.get_new_source_id();
5762
}
5863
for mic in save_data.mics {
5964
commands.spawn(mic);
65+
ids.get_new_mic_id();
6066
}
6167
for rect_wall in save_data.rect_walls {
6268
commands.spawn(rect_wall);
69+
ids.get_new_wall_id();
6370
}
6471
for circ_wall in save_data.circ_walls {
6572
commands.spawn(circ_wall);
73+
ids.get_new_wall_id();
6674
}
6775

6876
grid.reset_cells(ui_state.boundary_width);

0 commit comments

Comments
 (0)