grow board margins when placing near but inside the edge

This commit is contained in:
Crispy 2024-10-10 17:17:32 +02:00
parent bc4cd5ccc9
commit dee52fa2fd
2 changed files with 16 additions and 8 deletions

View file

@ -120,7 +120,7 @@ impl Board {
let mut offset_x = 0;
let mut offset_y = 0;
if p.x < 0 {
let len = p.x.unsigned_abs() + 2;
let len = p.x.unsigned_abs();
for row in &mut self.rows {
let mut new_row = vec![Tile::Blank; len];
new_row.append(row);
@ -129,7 +129,7 @@ impl Board {
offset_x = len;
self.width += len;
} else if p.x as usize >= self.width {
let new_width = p.x as usize + 3;
let new_width = p.x as usize + 1;
for row in &mut self.rows {
row.resize(new_width, Tile::Blank);
}
@ -137,14 +137,14 @@ impl Board {
}
if p.y < 0 {
let len = p.y.unsigned_abs() + 2;
let len = p.y.unsigned_abs();
let mut new_rows = vec![vec![Tile::Blank; self.width]; len];
new_rows.append(&mut self.rows);
self.rows = new_rows;
offset_y = len;
self.height += len;
} else if p.y as usize >= self.height {
let new_height = p.y as usize + 3;
let new_height = p.y as usize + 1;
self.rows.resize(new_height, vec![Tile::Blank; self.width]);
self.height = new_height;
}