use std::process;
use clap::{Parser, Subcommand};
use omt::atlas::Atlas;
use omt::atlas::AtlasPreviewer;
#[derive(Debug, Parser)]
#[clap(name = "omt-atlas")]
#[clap(author, version)]
#[clap(about = "Part of the OMT suite of game tools. Handles texture atlases.", long_about = None)]
struct Cli {
#[clap(subcommand)]
command: Option<Commands>,
}
#[derive(Debug, Subcommand)]
enum Commands {
Combine {
#[clap(short, long, action)]
output: std::path::PathBuf,
#[clap(short, long, action)]
size: u32,
#[clap(short, long, action, default_value_t = 0)]
border: u32,
#[clap(short, long, min_values = 1, required = true)]
input: Vec<std::path::PathBuf>,
#[clap(short = 'r', long, action)]
reference_path: Option<std::path::PathBuf>,
},
Info {
#[clap(short, long, action)]
input: String, },
Preview {
#[clap(short, long, action)]
input: String, },
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
match cli.command {
Some(command) => {
match command {
Commands::Combine {
output,
size,
border,
input,
reference_path,
} => {
println!("combine");
println!("output : {:?}", output);
println!("size : {:?}", size);
println!("border : {:?}", border);
if let Some(rp) = &reference_path {
println!("reference_path : {}", rp.display());
}
println!("input : [");
for i in &input {
println!("\t{:?}", i);
}
println!("]");
match Atlas::combine(
&output,
size,
border,
&input,
reference_path.as_ref(),
) {
Ok(1) => {
println!("1 atlas created");
process::exit(0);
},
Ok(n) => {
println!("{:?} atlases created", n);
process::exit(0);
},
Err(e) => {
println!("Error combining atlas >{:?}>", e);
process::exit(-1);
},
}
},
Commands::Info { input } => {
println!("info");
println!("input : {:?}", input);
match Atlas::info(&input) {
Ok(_) => {
process::exit(0);
},
Err(e) => {
println!("Error getting info from atlas: {}", &e);
process::exit(-1);
},
}
},
Commands::Preview { input } => {
println!("preview");
println!("input : {:?}", input);
match AtlasPreviewer::preview(&input) {
Ok(_) => {
process::exit(0);
},
Err(e) => {
println!("Error getting info from atlas: {}", &e);
process::exit(-1);
},
}
},
};
},
None => {},
};
Ok(())
}