some getters and setters

master
histausse 3 years ago
parent 50f94820a5
commit b9298c9c5e
Signed by: histausse
GPG Key ID: 67486F107F62E9E9

@ -52,6 +52,25 @@ impl Universe{
}
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]
@ -76,6 +95,16 @@ impl Universe {
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 {
let width = 64;
let height = 64;

Loading…
Cancel
Save