refactor: split structures and functions into related modules
This commit is contained in:
parent
1119f7b0a0
commit
4109e29d4d
6 changed files with 223 additions and 370 deletions
31
src/grid/manipulation.rs
Normal file
31
src/grid/manipulation.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use bevy::math::UVec3;
|
||||
use crate::grid::{Grid, GridElement};
|
||||
|
||||
pub struct GridManipulationTools<'a> {
|
||||
grid: &'a mut Grid
|
||||
}
|
||||
|
||||
impl<'a> GridManipulationTools<'a> {
|
||||
pub fn new(grid: &'a mut Grid) -> Self {
|
||||
Self { grid }
|
||||
}
|
||||
pub fn set_xyz(&mut self,x: u32, y: u32, z: u32, element: GridElement) {
|
||||
let index = self.grid.indexify(UVec3::new(x,y,z));
|
||||
self.grid.data[index] = element;
|
||||
}
|
||||
pub fn fill_xyz(&mut self,x1: u32, y1: u32, z1: u32, x2: u32, y2: u32, z2: u32, element: GridElement) {
|
||||
if x1 > x2 || y1 > y2 || z1 > z2 {
|
||||
return;
|
||||
}
|
||||
|
||||
for x in x1..=x2 {
|
||||
for y in y1..=y2 {
|
||||
for z in z1..=z2 {
|
||||
let index = self.grid.indexify(UVec3::new(x,y,z));
|
||||
|
||||
self.grid.data[index] = element.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue