|
1 | 1 | extern crate clap;
|
| 2 | +extern crate glob; |
2 | 3 | extern crate image;
|
3 | 4 | extern crate ron;
|
4 | 5 | extern crate serde;
|
5 | 6 | extern crate sheep;
|
6 | 7 |
|
7 | 8 | use clap::{App, AppSettings, Arg, SubCommand};
|
| 9 | +use glob::glob; |
8 | 10 | use serde::Serialize;
|
9 | 11 | use sheep::{
|
10 | 12 | AmethystFormat, AmethystNamedFormat, InputSprite, MaxrectsOptions, MaxrectsPacker,
|
11 | 13 | SimplePacker, SpriteSheet,
|
12 | 14 | };
|
| 15 | +use std::path::{PathBuf, Path}; |
13 | 16 | use std::str::FromStr;
|
14 | 17 | use std::{fs::File, io::prelude::*};
|
15 | 18 |
|
@@ -93,7 +96,16 @@ fn main() {
|
93 | 96 | ("pack", Some(matches)) => {
|
94 | 97 | let input = matches
|
95 | 98 | .values_of("INPUT")
|
96 |
| - .map(|values| values.map(|it| String::from(it)).collect::<Vec<String>>()) |
| 99 | + .map(|values| { |
| 100 | + values |
| 101 | + .flat_map(|path_pattern| { |
| 102 | + glob(path_pattern) |
| 103 | + .expect("Invalid path pattern") |
| 104 | + .map(|path| path.expect("Invalid path")) |
| 105 | + .collect::<Vec<PathBuf>>() |
| 106 | + }) |
| 107 | + .collect::<Vec<PathBuf>>() |
| 108 | + }) |
97 | 109 | .unwrap_or(Vec::new());
|
98 | 110 |
|
99 | 111 | let out = matches
|
@@ -171,20 +183,22 @@ fn main() {
|
171 | 183 | }
|
172 | 184 | }
|
173 | 185 |
|
174 |
| -fn get_filenames(input: &[String]) -> Vec<String> { |
| 186 | +fn get_filenames(input: &[PathBuf]) -> Vec<String> { |
175 | 187 | input
|
176 | 188 | .iter()
|
177 | 189 | .map(|path| {
|
178 |
| - std::path::PathBuf::from(&path) |
179 |
| - .file_stem() |
| 190 | + path.file_stem() |
180 | 191 | .and_then(|name| name.to_str())
|
181 | 192 | .map(|name| String::from_str(name).expect("could not parse string from file name"))
|
182 | 193 | .expect("Failed to extract file name")
|
183 | 194 | })
|
184 | 195 | .collect()
|
185 | 196 | }
|
186 | 197 |
|
187 |
| -fn load_images(input: &[String]) -> Vec<InputSprite> { |
| 198 | +fn load_images<T>(input: &[T]) -> Vec<InputSprite> |
| 199 | +where |
| 200 | + T: AsRef<Path>, |
| 201 | +{ |
188 | 202 | input
|
189 | 203 | .iter()
|
190 | 204 | .map(|path| {
|
|
0 commit comments