|
@@ -4,21 +4,20 @@ use serde::{Deserialize, Serialize};
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
#[serde(rename_all = "PascalCase")]
|
|
|
-pub struct PatchPen {
|
|
|
- pub id: u8,
|
|
|
- pub color: Option<(u8, u8, u8)>,
|
|
|
- pub enabled: Option<bool>,
|
|
|
- pub loop_count: Option<u32>,
|
|
|
- pub speed: Option<f64>,
|
|
|
- pub power: Option<f64>,
|
|
|
- pub frequency: Option<u32>,
|
|
|
+pub struct Patch {
|
|
|
+ color: Option<(u8, u8, u8)>,
|
|
|
+ enabled: Option<bool>,
|
|
|
+ loop_count: Option<u32>,
|
|
|
+ speed: Option<f64>,
|
|
|
+ power: Option<f64>,
|
|
|
+ frequency: Option<u32>,
|
|
|
}
|
|
|
|
|
|
-impl PatchPen {
|
|
|
- fn patch(&self, target: &mut Vec<Pen>) {
|
|
|
- trace!("Patching settings for pen #{}", self.id);
|
|
|
+impl Patch {
|
|
|
+ fn patch(&self, id: usize, target: &mut Vec<Pen>) {
|
|
|
+ trace!("Patching settings for pen #{}", id);
|
|
|
|
|
|
- let to_patch = target.get_mut(self.id as usize).unwrap();
|
|
|
+ let to_patch = target.get_mut(id).unwrap();
|
|
|
|
|
|
if let Some(color) = self.color {
|
|
|
*to_patch.color = Rgba {
|
|
@@ -53,27 +52,48 @@ impl PatchPen {
|
|
|
}
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
+#[serde(rename_all = "PascalCase")]
|
|
|
+pub struct PatchPen {
|
|
|
+ pen: u8,
|
|
|
+ patch: Patch,
|
|
|
+}
|
|
|
+
|
|
|
+impl PatchPen {
|
|
|
+ fn patch(&self, target: &mut Vec<Pen>) {
|
|
|
+ self.patch.patch(self.pen as usize, target);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+#[derive(Debug, Serialize, Deserialize)]
|
|
|
+#[serde(rename_all = "PascalCase")]
|
|
|
pub struct ClonePen {
|
|
|
- source_id: u8,
|
|
|
- destination_id: u8,
|
|
|
+ from: u8,
|
|
|
+ to: u8,
|
|
|
+ patch: Option<Patch>,
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
+ 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();
|
|
|
+ *dst = src;
|
|
|
+
|
|
|
+ if let Some(patch) = &self.patch {
|
|
|
+ patch.patch(self.to as usize, target);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
+#[serde(rename_all = "PascalCase")]
|
|
|
pub struct PatternPen {}
|
|
|
|
|
|
+impl PatternPen {
|
|
|
+ fn pattern(&self, target: &mut Vec<Pen>) {}
|
|
|
+}
|
|
|
+
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
pub enum PenOperation {
|
|
|
Patch(PatchPen),
|