Compare commits

..

No commits in common. "3d9fd8d311dbba5c4f4d88c830a6e3237a836219" and "33f706928cce574aa6909921db642d2756ee3f0c" have entirely different histories.

2 changed files with 13 additions and 32 deletions

View file

@ -18,10 +18,8 @@ pub struct Chunk {
pub contents: Box<[[Cell; CHUNK_SIZE]; CHUNK_SIZE]>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Rule {
#[serde(default)]
pub name: String,
base: SubRule,
#[serde(skip)]
variants: Vec<SubRule>,
@ -63,6 +61,12 @@ pub enum RuleCellTo {
Copy(usize),
}
impl std::default::Default for SubRule {
fn default() -> Self {
Self::new()
}
}
impl SubRule {
fn new() -> Self {
Self {
@ -115,18 +119,6 @@ impl Rule {
pub const SHRINK_UP: ResizeParam = (0, -1, 0, 1);
pub const SHRINK_DOWN: ResizeParam = (0, -1, 0, 0);
pub fn new() -> Self {
Self {
name: "new rule".into(),
enabled: false,
base: SubRule::new(),
variants: vec![SubRule::new()],
flip_h: false,
flip_v: false,
rotate: false,
}
}
pub fn get(&self, x: usize, y: usize) -> (RuleCellFrom, RuleCellTo) {
self.base.get(x, y)
}
@ -288,7 +280,7 @@ impl Dish {
(RuleCellFrom::One(Cell(0)), RuleCellTo::One(Cell(1))),
],
},
..Rule::new()
..Rule::default()
},
Rule {
enabled: true,
@ -303,7 +295,7 @@ impl Dish {
],
},
flip_h: true,
..Rule::new()
..Rule::default()
},
];

View file

@ -174,30 +174,19 @@ impl eframe::App for UScope {
ui.heading("Rules");
let mut to_remove = None;
let mut to_clone = None;
for (i, rule) in self.dish.rules.iter_mut().enumerate() {
ui.separator();
rule_editor(ui, rule, &self.cell_types, &self.dish.cell_groups);
ui.horizontal(|ui| {
if ui.button("delete").clicked() {
to_remove = Some(i);
}
if ui.button("copy").clicked() {
to_clone = Some(i);
}
});
if ui.button("delete").clicked() {
to_remove = Some(i);
}
}
if let Some(i) = to_remove {
self.dish.rules.remove(i);
}
if let Some(i) = to_clone {
let mut new_rule = self.dish.rules[i].clone();
new_rule.enabled = false;
self.dish.rules.push(new_rule);
}
ui.separator();
if ui.button("add rule").clicked() {
self.dish.rules.push(Rule::new());
self.dish.rules.push(Rule::default());
}
});
});