diff --git a/Cargo.lock b/Cargo.lock index 35301df..5cff651 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -608,6 +608,7 @@ name = "sheep_cli" version = "0.3.0" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "image 0.20.1 (registry+https://github.com/rust-lang/crates.io-index)", "oxipng 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "png 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/sheep/src/format/amethyst.rs b/sheep/src/format/amethyst.rs index 4988094..4d7295b 100644 --- a/sheep/src/format/amethyst.rs +++ b/sheep/src/format/amethyst.rs @@ -19,8 +19,13 @@ pub struct SerializedSpriteSheet { pub sprites: Vec, } +#[derive(Clone, Debug, PartialEq, Serialize)] +pub enum Wrapper { + List(T), +} + impl Format for AmethystFormat { - type Data = SerializedSpriteSheet; + type Data = Wrapper; type Options = (); fn encode( @@ -39,10 +44,10 @@ impl Format for AmethystFormat { }) .collect::>(); - SerializedSpriteSheet { + Wrapper::List(SerializedSpriteSheet { texture_width: dimensions.0 as f32, texture_height: dimensions.1 as f32, sprites: sprite_positions, - } + }) } } diff --git a/sheep_cli/Cargo.toml b/sheep_cli/Cargo.toml index 93d02f3..51c10ce 100644 --- a/sheep_cli/Cargo.toml +++ b/sheep_cli/Cargo.toml @@ -23,6 +23,7 @@ clap = "2.32" ron = "0.4" oxipng = "2.2" png = "0.15" +glob = "0.3" [[bin]] name = "sheep" diff --git a/sheep_cli/src/main.rs b/sheep_cli/src/main.rs index 78d4f91..9471d09 100644 --- a/sheep_cli/src/main.rs +++ b/sheep_cli/src/main.rs @@ -1,15 +1,18 @@ extern crate clap; +extern crate glob; extern crate image; extern crate ron; extern crate serde; extern crate sheep; use clap::{App, AppSettings, Arg, SubCommand}; +use glob::glob; use serde::Serialize; use sheep::{ AmethystFormat, AmethystNamedFormat, InputSprite, MaxrectsOptions, MaxrectsPacker, SimplePacker, SpriteSheet, }; +use std::path::{PathBuf, Path}; use std::str::FromStr; use std::{fs::File, io::prelude::*}; @@ -93,7 +96,16 @@ fn main() { ("pack", Some(matches)) => { let input = matches .values_of("INPUT") - .map(|values| values.map(|it| String::from(it)).collect::>()) + .map(|values| { + values + .flat_map(|path_pattern| { + glob(path_pattern) + .expect("Invalid path pattern") + .map(|path| path.expect("Invalid path")) + .collect::>() + }) + .collect::>() + }) .unwrap_or(Vec::new()); let out = matches @@ -171,12 +183,11 @@ fn main() { } } -fn get_filenames(input: &[String]) -> Vec { +fn get_filenames(input: &[PathBuf]) -> Vec { input .iter() .map(|path| { - std::path::PathBuf::from(&path) - .file_stem() + path.file_stem() .and_then(|name| name.to_str()) .map(|name| String::from_str(name).expect("could not parse string from file name")) .expect("Failed to extract file name") @@ -184,7 +195,10 @@ fn get_filenames(input: &[String]) -> Vec { .collect() } -fn load_images(input: &[String]) -> Vec { +fn load_images(input: &[T]) -> Vec +where + T: AsRef, +{ input .iter() .map(|path| {