|
@@ -1,4 +1,4 @@
|
|
|
-use ezcad::{pen::Pen, types::Rgba};
|
|
|
+use ezcad::pen::Pen;
|
|
|
use log::trace;
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
@@ -17,15 +17,10 @@ impl Patch {
|
|
|
fn patch(&self, id: usize, target: &mut Vec<Pen>) {
|
|
|
trace!("Patching settings for pen #{}", id);
|
|
|
|
|
|
- let to_patch = target.get_mut(id).unwrap();
|
|
|
+ let to_patch = target.get_mut(id).expect("Invalid pen index");
|
|
|
|
|
|
if let Some(color) = self.color {
|
|
|
- *to_patch.color = Rgba {
|
|
|
- red: color.0,
|
|
|
- green: color.1,
|
|
|
- blue: color.2,
|
|
|
- alpha: 0,
|
|
|
- };
|
|
|
+ *to_patch.color = color.into()
|
|
|
}
|
|
|
|
|
|
if let Some(enabled) = self.enabled {
|
|
@@ -54,44 +49,78 @@ impl Patch {
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
#[serde(rename_all = "PascalCase")]
|
|
|
pub struct PatchPen {
|
|
|
- pen: u8,
|
|
|
+ pen: usize,
|
|
|
+ #[serde(flatten)]
|
|
|
patch: Patch,
|
|
|
}
|
|
|
|
|
|
impl PatchPen {
|
|
|
fn patch(&self, target: &mut Vec<Pen>) {
|
|
|
- self.patch.patch(self.pen as usize, target);
|
|
|
+ self.patch.patch(self.pen, target);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
#[serde(rename_all = "PascalCase")]
|
|
|
pub struct ClonePen {
|
|
|
- from: u8,
|
|
|
- to: u8,
|
|
|
+ from: usize,
|
|
|
+ to: usize,
|
|
|
+ #[serde(flatten)]
|
|
|
patch: Option<Patch>,
|
|
|
}
|
|
|
|
|
|
impl ClonePen {
|
|
|
fn clone(&self, target: &mut Vec<Pen>) {
|
|
|
trace!("Cloning pen #{} to #{}", self.from, self.to);
|
|
|
-
|
|
|
- let src = target.get(self.from as usize).unwrap().clone();
|
|
|
- let dst = target.get_mut(self.to as usize).unwrap();
|
|
|
+ assert!(
|
|
|
+ self.to > self.from,
|
|
|
+ "Target pen must be greater than source pen"
|
|
|
+ );
|
|
|
+
|
|
|
+ // Clone pen
|
|
|
+ let src = target.get(self.from).expect("Invalid pen index").clone();
|
|
|
+ let dst = target.get_mut(self.to).expect("Invalid pen index");
|
|
|
*dst = src;
|
|
|
|
|
|
+ // Patch pen if needed
|
|
|
if let Some(patch) = &self.patch {
|
|
|
- patch.patch(self.to as usize, target);
|
|
|
+ patch.patch(self.to, target);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#[derive(Debug, Serialize, Deserialize)]
|
|
|
+pub enum PatternField {
|
|
|
+ Loops(i32),
|
|
|
+ Speed(f64),
|
|
|
+ Power(f64),
|
|
|
+ Frequency(i32),
|
|
|
+}
|
|
|
+
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
#[serde(rename_all = "PascalCase")]
|
|
|
-pub struct PatternPen {}
|
|
|
+pub struct PatternPen {
|
|
|
+ from: usize,
|
|
|
+ to: usize,
|
|
|
+ field: PatternField,
|
|
|
+}
|
|
|
|
|
|
impl PatternPen {
|
|
|
- fn pattern(&self, target: &mut Vec<Pen>) {}
|
|
|
+ fn pattern(&self, target: &mut Vec<Pen>) {
|
|
|
+ trace!("Patterning from pen #{} to #{}", self.from, self.to);
|
|
|
+ assert!(
|
|
|
+ self.to > self.from,
|
|
|
+ "Target pen(s) must be greater than source pen"
|
|
|
+ );
|
|
|
+
|
|
|
+ // Obtain settings from first pen
|
|
|
+ let src = target.get(self.from).expect("Invalid pen index").clone();
|
|
|
+
|
|
|
+ // Clone to target pen and patch pattern setting
|
|
|
+ for dst in (self.from..=self.to).skip(1) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
@@ -111,7 +140,7 @@ impl PatchPens for Vec<PenOperation> {
|
|
|
match op {
|
|
|
PenOperation::Patch(x) => x.patch(target),
|
|
|
PenOperation::Clone(x) => x.clone(target),
|
|
|
- PenOperation::Pattern(_) => todo!(),
|
|
|
+ PenOperation::Pattern(x) => x.pattern(target),
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -122,21 +151,3 @@ impl PatchPens for Vec<PenOperation> {
|
|
|
pub struct Config {
|
|
|
pub pens: Vec<PenOperation>,
|
|
|
}
|
|
|
-
|
|
|
-// #[test]
|
|
|
-// fn test() {
|
|
|
-// let config = Config {
|
|
|
-// modify_pens: vec![ModifyPen {
|
|
|
-// id: 0,
|
|
|
-// color: None,
|
|
|
-// disabled: None,
|
|
|
-// loop_count: None,
|
|
|
-// speed: None,
|
|
|
-// power: None,
|
|
|
-// frequency: None,
|
|
|
-// }],
|
|
|
-// };
|
|
|
-
|
|
|
-// dbg!(serde_yaml::to_string(&config).unwrap());
|
|
|
-// panic!()
|
|
|
-// }
|