use crate::prelude::*;
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug)]
pub struct TheCodeBundle {
pub name: String,
pub id: Uuid,
pub selected_grid_id: Option<Uuid>,
pub grids: FxHashMap<Uuid, TheCodeGrid>,
}
impl Default for TheCodeBundle {
fn default() -> Self {
TheCodeBundle::new()
}
}
impl TheCodeBundle {
pub fn new() -> Self {
let grids = FxHashMap::default();
Self {
name: "Unnamed".to_string(),
id: Uuid::new_v4(),
selected_grid_id: None,
grids,
}
}
pub fn insert_grid(&mut self, grid: TheCodeGrid) {
self.grids.insert(grid.id, grid);
}
pub fn get_grid(&self, id: &Uuid) -> Option<&TheCodeGrid> {
self.grids.get(id)
}
pub fn get_grid_mut(&mut self, id: &Uuid) -> Option<&mut TheCodeGrid> {
self.grids.get_mut(id)
}
pub fn sorted(&self) -> Vec<Uuid> {
let mut entries: Vec<(Uuid, String)> = self
.grids
.iter()
.map(|(uuid, data)| (*uuid, data.name.clone()))
.collect();
entries.sort_by(|a, b| a.1.cmp(&b.1));
entries.into_iter().map(|(uuid, _)| uuid).collect()
}
pub fn move_positions_by(&mut self, move_by: Vec2<i32>) {
for grid in self.grids.values_mut() {
grid.move_positions_by(move_by);
}
}
}