fix default new rule

This commit is contained in:
Crispy 2024-05-03 23:56:39 +02:00
parent 33f706928c
commit e2869af4a7
2 changed files with 18 additions and 10 deletions

View file

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

View file

@ -186,7 +186,7 @@ impl eframe::App for UScope {
} }
ui.separator(); ui.separator();
if ui.button("add rule").clicked() { if ui.button("add rule").clicked() {
self.dish.rules.push(Rule::default()); self.dish.rules.push(Rule::new());
} }
}); });
}); });