use cell::{Cell, CellRef}; pub mod cell; pub mod map; pub mod register; pub mod luaref; pub mod loader; pub mod tablized; #[derive(Debug, Default)] pub struct Sheet { id: register::SheetId, rows: Vec>, } impl Sheet { pub(self) fn new(width: usize, height: usize, id: register::SheetId) -> Self { Self { id, rows: vec![vec![Cell::new_empty(); width]; height], } } pub fn set_cell(&mut self, row: usize, column: usize, cell: Cell) { if row < self.height() && column < self.width() { self.rows[row][column] = cell } } pub fn get_cell(&self, row: usize, column: usize) -> Option<&Cell> { if let Some(r) = self.rows.get(row) { if r.get(column).is_some() { return Some(&self.rows[row][column]); } } None } pub fn get_ref(&self, row: usize, column: usize) -> Option { self.get_cell(row, column) .map(|cell| unsafe { CellRef::new(self.id, row, column, cell.clone()) }) } pub fn height(&self) -> usize { self.rows.len() } pub fn set_height(&mut self, mut height: usize) { height = height.max(1); self.rows .resize(height, vec![Cell::new_empty(); self.width()]) } pub fn width(&self) -> usize { self.rows.first().map(|r| r.len()).unwrap_or(1) } pub fn set_width(&mut self, mut width: usize) { width = width.max(1); for row in self.rows.iter_mut() { row.resize(width, Cell::new_empty()); } } pub fn id(&self) -> register::SheetId { self.id } pub fn apply(&mut self, other: Sheet) { self.rows = other.rows; } } impl Clone for Sheet { fn clone(&self) -> Self { Sheet { id: self.id, rows: self.rows.clone(), } } }