| 
					
				 | 
			
			
				@@ -1,12 +1,122 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use ezcad::{pen::Pen, types::Rgba}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use log::trace; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 use serde::{Deserialize, Serialize}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 #[derive(Debug, Serialize, Deserialize)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-pub struct Pen { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#[serde(rename_all = "PascalCase")] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+pub struct PatchPen { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pub id: u8, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pub color: Option<(u8, u8, u8)>, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    pub disabled: Option<bool>, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    pub enabled: Option<bool>, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pub loop_count: Option<u32>, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pub speed: Option<f64>, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pub power: Option<f64>, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     pub frequency: Option<u32>, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+impl PatchPen { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fn patch(&self, target: &mut Vec<Pen>) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        trace!("Patching settings for pen #{}", self.id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let to_patch = target.get_mut(self.id as usize).unwrap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if let Some(color) = self.color { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            *to_patch.color = Rgba { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                red: color.0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                green: color.1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                blue: color.2, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                alpha: 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if let Some(enabled) = self.enabled { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            *to_patch.disabled = !enabled as u32; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if let Some(loop_count) = self.loop_count { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            *to_patch.loop_count = loop_count; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if let Some(speed) = self.speed { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            *to_patch.speed = speed; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if let Some(power) = self.power { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            *to_patch.power = power; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if let Some(frequency) = self.frequency { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            *to_patch.frequency = frequency; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            *to_patch.frequency_2 = frequency.try_into().unwrap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#[derive(Debug, Serialize, Deserialize)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+pub struct ClonePen { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    source_id: u8, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    destination_id: u8, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+impl ClonePen { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fn clone(&self, target: &mut Vec<Pen>) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        trace!( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            "Cloning pen #{} to #{}", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            self.source_id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            self.destination_id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        let source = target.get(self.source_id as usize).unwrap().clone(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        *target.get_mut(self.destination_id as usize).unwrap() = source; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#[derive(Debug, Serialize, Deserialize)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+pub struct PatternPen {} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#[derive(Debug, Serialize, Deserialize)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+pub enum PenOperation { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Patch(PatchPen), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Clone(ClonePen), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    Pattern(PatternPen), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+pub trait PatchPens { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fn patch(&self, target: &mut Vec<Pen>); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+impl PatchPens for Vec<PenOperation> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    fn patch(&self, target: &mut Vec<Pen>) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for op in self { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            match op { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                PenOperation::Patch(x) => x.patch(target), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                PenOperation::Clone(x) => x.clone(target), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                PenOperation::Pattern(_) => todo!(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#[derive(Debug, Serialize, Deserialize)] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+#[serde(rename_all = "PascalCase")] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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!() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// } 
			 |