fix blueprint id generation overwriting old blueprints if any were removed before

This commit is contained in:
Crispy 2024-10-11 21:22:56 +02:00
parent ce90a22ea0
commit 52288bdf6c
2 changed files with 15 additions and 1 deletions

View file

@ -27,6 +27,10 @@ impl Blueprint {
}
}
pub fn id(&self)->&String{
&self.id
}
pub fn convert_board(&mut self) -> &Board {
if self.tile_board.is_none() {
self.tile_board = Some(Board::parse(&self.board));

View file

@ -280,7 +280,17 @@ impl Editor {
}
}
board.trim_size(0);
let mut blueprint = Blueprint::new(&board, self.blueprints.len());
let mut id = 0;
'outer: loop {
for b in &self.blueprints {
if b.id() == &format!("blueprint_{id}") {
id += 1;
continue 'outer;
}
}
break;
}
let mut blueprint = Blueprint::new(&board, id);
if !self.new_blueprint_name.is_empty() {
blueprint.name = self.new_blueprint_name.clone();
}