Skip to content
Snippets Groups Projects
Verified Commit 92e90b8a authored by Louis's avatar Louis :fire:
Browse files

Make info file output optional, don't include tile properties when not specifying tile size

parent e215f858
No related branches found
No related tags found
No related merge requests found
......@@ -126,10 +126,16 @@ impl Args {
Args::Info(info) => {
let image_data = load_image(&info.input, None)?;
let output = info.run(&image_data)?;
{
let file = std::fs::File::create(&info.output)?;
if let Some(out_path) = &info.output {
let file = std::fs::File::create(out_path)?;
serde_json::to_writer_pretty(file, &output)?;
} else {
let stdout = std::io::stdout();
let stdout_handle = stdout.lock();
serde_json::to_writer_pretty(stdout_handle, &output)?;
}
Ok(())
}
}
......
......@@ -2,16 +2,16 @@ use clap::Parser;
use image::{GenericImage, ImageFormat, Pixel};
use serde::{Deserialize, Serialize};
/// Extract Information About An Image
/// Extract Information About An Image or Spritesheet
#[derive(Debug, Clone, Parser, Serialize, Deserialize)]
#[clap(author, version = "0.7.0")]
pub struct Info {
/// The path to the image file
#[serde(default)]
pub input: String,
/// The path to write the flipped image
/// The output path for a JSON formatted information file. Omit to print to stdout
#[serde(default)]
pub output: String,
pub output: Option<String>,
/// The size of each tile in the spritesheet. Assumed to be square tiles
#[clap(short, long, default_value = None)]
#[serde(default)]
......@@ -23,9 +23,13 @@ pub struct ImageInfo {
image_width: u32,
image_height: u32,
image_format: String,
#[serde(skip_serializing_if = "Option::is_none")]
tile_width: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
tile_height: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
rows: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
columns: Option<u32>,
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment