From 4d61184edd131e4b5295a63e218bde6fff2b2156 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 4 May 2024 16:56:06 +0200 Subject: [PATCH] add rule fail rate property --- petri/src/lib.rs | 9 ++++++++- uscope/src/main.rs | 13 ++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/petri/src/lib.rs b/petri/src/lib.rs index cbc32b4..c2d82d5 100644 --- a/petri/src/lib.rs +++ b/petri/src/lib.rs @@ -36,7 +36,8 @@ pub struct Rule { pub flip_x: bool, pub flip_y: bool, pub rotate: bool, - // probability: u8 + #[serde(default)] + pub failrate: u8, } #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] @@ -131,6 +132,7 @@ impl Rule { flip_x: false, flip_y: false, rotate: false, + failrate: 0, } } @@ -383,6 +385,11 @@ impl Dish { return; } + let fail: u8 = random(); + if rule.failrate > fail { + return; + } + let width = variant.width; let height = variant.height; let mut old_state = Vec::new(); diff --git a/uscope/src/main.rs b/uscope/src/main.rs index f0f0efd..65f4cdb 100644 --- a/uscope/src/main.rs +++ b/uscope/src/main.rs @@ -10,7 +10,7 @@ use eframe::{ epaint::Hsva, NativeOptions, }; -use egui::{collapsing_header::CollapsingState, PointerButton}; +use egui::{collapsing_header::CollapsingState, DragValue, PointerButton}; use native_dialog::FileDialog; use rand::prelude::*; use serde::{Deserialize, Serialize}; @@ -272,10 +272,13 @@ fn rule_editor( rule.generate_variants(); } }); - if ui.checkbox(&mut rule.rotate, "rotate").changed() { - rule.generate_variants(); - } - + ui.horizontal(|ui| { + if ui.checkbox(&mut rule.rotate, "rotate").changed() { + rule.generate_variants(); + } + ui.label("fail rate"); + ui.add(DragValue::new(&mut rule.failrate)); + }); let cells_y = rule.height(); let cells_x = rule.width(); let patt_width = CSIZE * cells_x as f32;