diff --git a/petri/src/lib.rs b/petri/src/lib.rs index 225926f..bbf8f76 100644 --- a/petri/src/lib.rs +++ b/petri/src/lib.rs @@ -362,7 +362,7 @@ impl Dish { let mut old_state = Vec::new(); for dy in 0..height { for dx in 0..width { - old_state.push(self.get_cell(dx, dy).unwrap()); + old_state.push(self.get_cell(x + dx, y + dy).unwrap()); } } diff --git a/uscope/src/main.rs b/uscope/src/main.rs index 6a75ab3..850e432 100644 --- a/uscope/src/main.rs +++ b/uscope/src/main.rs @@ -10,10 +10,7 @@ use eframe::{ epaint::Hsva, NativeOptions, }; -use egui::{ - menu::{SubMenu, SubMenuButton}, - popup, Layout, PointerButton, -}; +use egui::PointerButton; use native_dialog::FileDialog; use rand::prelude::*; use serde::{Deserialize, Serialize}; @@ -68,6 +65,7 @@ impl UScope { let out = json!({ "cell_types": self.cell_types, "rules": self.dish.rules, + "groups": self.dish.cell_groups, }); let out = serde_json::to_string(&out).ok()?; let mut file = File::create(path).ok()?; @@ -85,9 +83,11 @@ impl UScope { let s = fs::read_to_string(path).ok()?; let data: Value = serde_json::from_str(&s).ok()?; let cell_types = serde_json::from_value(data["cell_types"].clone()).ok()?; + let groups = serde_json::from_value(data["groups"].clone()).ok()?; let rules = serde_json::from_value(data["rules"].clone()).ok()?; self.cell_types = cell_types; self.dish.rules = rules; + self.dish.cell_groups = groups; self.dish.update_rules(); } Some(()) @@ -215,6 +215,8 @@ fn paint_chunk(painter: Painter, chunk: &Chunk, cells: &[CellData], grid: bool) } const CSIZE: f32 = 24.; +const RESIZE_BUTTON_WIDTH: f32 = 8.; + const OUTLINE: (f32, Color32) = (2., Color32::GRAY); fn rule_editor(ui: &mut Ui, rule: &mut Rule, cells: &[CellData], groups: &[Vec]) { ui.checkbox(&mut rule.enabled, "enable rule"); @@ -233,31 +235,41 @@ fn rule_editor(ui: &mut Ui, rule: &mut Rule, cells: &[CellData], groups: &[Vec], + (rule_width, rule_height): (usize, usize), + overlay_lines: &mut Vec<(Pos2, Pos2)>, ) -> bool { let mut changed = false; let rect = Rect::from_min_size( @@ -420,7 +447,15 @@ fn rule_cell_edit_to( let group = &groups[*group_id]; draw_group(ui, rect, group, cells); } - RuleCellTo::Copy(_) => todo!(), + RuleCellTo::Copy(index) => { + let this = rect.center(); + let x = *index % rule_width; + let y = *index / rule_width; + let target = origin + Vec2::from((x as f32, y as f32)) * CSIZE + - Vec2::X * (CSIZE * (rule_width as f32 + 1.) + RESIZE_BUTTON_WIDTH * 2.) + + Vec2::splat(CSIZE) * 0.5; + overlay_lines.push((this, target)); + } } if cycle_colors { @@ -436,7 +471,10 @@ fn rule_cell_edit_to( *group_id %= groups.len(); changed = true; } - RuleCellTo::Copy(_) => todo!(), + RuleCellTo::Copy(index) => { + *index = (*index + 1) % (rule_width * rule_height); + changed = true; + } } } @@ -450,9 +488,11 @@ fn rule_cell_edit_to( *rule = RuleCellTo::GroupRandom(0); } RuleCellTo::GroupRandom(_) => { + *rule = RuleCellTo::Copy(0); + } + RuleCellTo::Copy(_) => { *rule = RuleCellTo::None; } - RuleCellTo::Copy(_) => todo!(), } } changed