浏览代码

Documentation

Kevin Lee 1 年之前
父节点
当前提交
d04a39d9b2
共有 3 个文件被更改,包括 67 次插入6 次删除
  1. 46 2
      README.md
  2. 7 0
      config.yml
  3. 14 4
      src/config/object.rs

+ 46 - 2
README.md

@@ -17,7 +17,11 @@ Options:
   -h, --help             Print help
 ```
 
-## Patching Pen Settings
+## Configuration File
+
+Operations defined in the configuration file are applied in order of definition.
+
+### Patching Pen
 
 Three operations are supported for patching pen settings:
 
@@ -63,4 +67,44 @@ Ops:
     # Field: !Frequency 1000  # Choose one
 ```
 
-Patching operations will be applied in the order that they are defined.
+### Import/Export
+
+Individual pens and objects can be exported via operations:
+
+1. Exporting a pen to a file:
+
+``` yaml
+Ops:
+  - !ExportPen
+    Index: 0
+    Path: "exported_pen.bin"
+```
+
+2. Importing a pen from a file:
+
+``` yaml
+Ops:
+  - !ImportPen
+    Index: 0
+    Path: "exported_pen.bin"
+```
+
+3. Exporting an object to a file:
+
+``` yaml
+Ops:
+  - !ExportObject
+    Layer: 0
+    Object: 0
+    Path: "exported_object.bin"
+```
+
+3. Importing an object from a file:
+
+``` yaml
+Ops:
+  - !ImportObject
+    Layer: 0
+    Object: 0 # Optional, will append to object list if not provided
+    Path: "exported_object.bin"
+```

+ 7 - 0
config.yml

@@ -7,24 +7,31 @@ Ops:
   #   Speed: 20.0
   #   Power: 55.0
   #   Frequency: 10000
+
   # - !ClonePen
   #   From: 0
   #   To: 1
   #   LoopCount: 2
+
   # - !PatternPen
   #   From: 1
   #   To: 5
   #   Field: !Speed 10
+
   - !ExportPen
     Index: 0
     Path: export_pen.bin
+
   - !ImportPen
     Index: 1
     Path: export_pen.bin
+
   - !ExportObject
     Layer: 0
     Object: 0
     Path: export_object.bin
+
   - !ImportObject
     Layer: 0
+    Object: 0
     Path: export_object.bin

+ 14 - 4
src/config/object.rs

@@ -20,9 +20,9 @@ pub struct ExportObject {
 impl ExportObject {
     pub fn export(&self, layers: &ArrayOf<Layer>) {
         debug!(
-            "Exporting object {} in layer {} to '{}'",
-            self.object,
+            "Exporting layer #{} object #{} to '{}'",
             self.layer,
+            self.object,
             self.path.to_string_lossy()
         );
 
@@ -46,14 +46,19 @@ impl ExportObject {
 #[serde(rename_all = "PascalCase")]
 pub struct ImportObject {
     layer: usize,
+    object: Option<usize>,
     path: PathBuf,
 }
 
 impl ImportObject {
     pub fn import(&self, layers: &mut ArrayOf<Layer>) {
         debug!(
-            "Importing object to layer {} from '{}'",
+            "Importing layer #{}{} from '{}'",
             self.layer,
+            match &self.object {
+                Some(object) => format!(" object #{}", object),
+                None => String::new(),
+            },
             self.path.to_string_lossy(),
         );
 
@@ -69,6 +74,11 @@ impl ImportObject {
 
         let layer: &mut Layer = layers.get_mut(self.layer).expect("Invalid layer index");
 
-        (*layer.objects).push(object);
+        if let Some(index) = self.object {
+            let dst: &mut Object = layer.objects.get_mut(index).expect("Invalid object index");
+            *dst = object;
+        } else {
+            (*layer.objects).push(object);
+        }
     }
 }