fix backwards compatible rule fields

This commit is contained in:
Crispy 2024-05-04 12:53:34 +02:00
parent 07cbd88618
commit 5af7cc0cb1
2 changed files with 6 additions and 3 deletions

View file

@ -27,7 +27,9 @@ pub struct Rule {
variants: Vec<SubRule>, variants: Vec<SubRule>,
pub enabled: bool, pub enabled: bool,
// probability: u8 // probability: u8
#[serde(alias = "flip_h")]
pub flip_x: bool, pub flip_x: bool,
#[serde(alias = "flip_v")]
pub flip_y: bool, pub flip_y: bool,
pub rotate: bool, pub rotate: bool,
} }

View file

@ -82,9 +82,10 @@ impl UScope {
{ {
let s = fs::read_to_string(path).ok()?; let s = fs::read_to_string(path).ok()?;
let data: Value = serde_json::from_str(&s).ok()?; let data: Value = serde_json::from_str(&s).ok()?;
let cell_types = serde_json::from_value(data["cell_types"].clone()).ok()?; // TODO: show errors to user
let groups = serde_json::from_value(data["groups"].clone()).ok()?; let cell_types = serde_json::from_value(data["cell_types"].clone()).unwrap();
let rules = serde_json::from_value(data["rules"].clone()).ok()?; let groups = serde_json::from_value(data["groups"].clone()).unwrap();
let rules = serde_json::from_value(data["rules"].clone()).unwrap();
self.cell_types = cell_types; self.cell_types = cell_types;
self.dish.rules = rules; self.dish.rules = rules;
self.dish.cell_groups = groups; self.dish.cell_groups = groups;