Pārlūkot izejas kodu

Add support for object range

Kevin Lee 6 mēneši atpakaļ
vecāks
revīzija
0f2fdd7e01
1 mainītis faili ar 25 papildinājumiem un 16 dzēšanām
  1. 25 16
      src/main.rs

+ 25 - 16
src/main.rs

@@ -57,7 +57,8 @@ struct QueryCmd {
 
     /// Print info for objects
     #[arg(short, long)]
-    object: Option<usize>,
+    #[arg(value_parser = parse_range)]
+    object: Option<RangeInclusive<usize>>,
 
     /// Object layer to query object on
     #[arg(short = 'b', long)]
@@ -220,26 +221,34 @@ fn main() {
             });
 
             // Process object query
-            args.object.map(|obj_index| {
+            args.object.map(|obj_range| {
+                warn!("Object origin/width/height values may be incorrect if skewed or rotated");
+
                 let layer_index: usize = args.object_layer.unwrap_or(0);
                 let layer: &Layer = file
                     .layers_offset
                     .get(layer_index)
                     .expect("Invalid layer index");
-                let object: &Object = layer.objects.get(obj_index).expect("Invalid object index");
-                let pen_index: u32 = *object.core().pen;
-                info!(
-                    "Layer {}, Object {}:\n{}\nPen: #{}: {}",
-                    layer_index,
-                    obj_index,
-                    object,
-                    pen_index,
-                    file.pens_offset
-                        .data
-                        .pens
-                        .get(pen_index as usize)
-                        .expect("Invalid pen index in object")
-                );
+
+                for object_index in obj_range {
+                    let object: &Object = layer
+                        .objects
+                        .get(object_index)
+                        .expect("Invalid object index");
+                    let pen_index: u32 = *object.core().pen;
+                    info!(
+                        "Layer #{}, Object #{}:\n{}\nPen: #{}: {}",
+                        layer_index,
+                        object_index,
+                        object,
+                        pen_index,
+                        file.pens_offset
+                            .data
+                            .pens
+                            .get(pen_index as usize)
+                            .expect("Invalid pen index in object")
+                    );
+                }
             });
         }
         SubCommands::Apply(args) => {