some getters and setters
This commit is contained in:
parent
50f94820a5
commit
b9298c9c5e
1 changed files with 29 additions and 0 deletions
29
src/lib.rs
29
src/lib.rs
|
@ -52,6 +52,25 @@ impl Universe{
|
||||||
}
|
}
|
||||||
count
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn regenerate_cells(&mut self) {
|
||||||
|
let size = (self.width * self.height) as usize;
|
||||||
|
self.cells = FixedBitSet::with_capacity(size);
|
||||||
|
for i in 0..size {
|
||||||
|
self.cells.set(i, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_cells(&self) -> &FixedBitSet {
|
||||||
|
&self.cells
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_cells(&mut self, cells: &[(u32, u32)]) {
|
||||||
|
for (row, col) in cells.iter().cloned() {
|
||||||
|
let i = self.get_index(row, col);
|
||||||
|
self.cells.set(i, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
|
@ -76,6 +95,16 @@ impl Universe {
|
||||||
self.cells = next;
|
self.cells = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_width(&mut self, width: u32) {
|
||||||
|
self.width = width;
|
||||||
|
self.regenerate_cells();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_height(&mut self, height: u32) {
|
||||||
|
self.height = height;
|
||||||
|
self.regenerate_cells();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new() -> Universe {
|
pub fn new() -> Universe {
|
||||||
let width = 64;
|
let width = 64;
|
||||||
let height = 64;
|
let height = 64;
|
||||||
|
|
Loading…
Reference in a new issue