Skip to content

Commit

Permalink
fix(optimize): detect images in folder without recursion mode active
Browse files Browse the repository at this point in the history
  • Loading branch information
fgardt committed Jan 16, 2025
1 parent 3dcb787 commit 70900ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spritter"
version = "1.2.1"
version = "1.2.2"
edition = "2021"
authors = ["fgardt <me@fgardt.dev>"]
description = "Spritesheet generator for factorio"
Expand Down
20 changes: 12 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,11 @@ fn generate_gif(args: &GifArgs) -> Result<(), CommandError> {

fn optimize(args: &OptimizeArgs) -> Result<(), CommandError> {
let mut paths = Vec::new();
if args.recursive {
if args.target.is_dir() {
paths.extend(pngs_in_folder(&args.target)?);

if args.target.is_dir() {
paths.extend(pngs_in_folder(&args.target)?);

if args.recursive {
let folders = recursive_folders(&args.target)?;

for folder in &folders {
Expand All @@ -856,13 +858,15 @@ fn optimize(args: &OptimizeArgs) -> Result<(), CommandError> {
paths.len(),
folders.len()
);
} else {
}
} else {
if args.recursive {
warn!("target is not a directory, recursive search disabled");
}
}

if args.target.is_file() && args.target.extension().is_some_and(|ext| ext == "png") {
paths.push(args.target.clone());
if args.target.extension().is_some_and(|ext| ext == "png") {
paths.push(args.target.clone());
}
}

if paths.is_empty() {
Expand Down Expand Up @@ -1040,7 +1044,7 @@ fn pngs_in_folder(path: impl AsRef<Path>) -> std::io::Result<Box<[PathBuf]>> {
let entry = entry?;
let path = entry.path();

if path.is_file() && path.extension().map_or(false, |ext| ext == "png") {
if path.is_file() && path.extension().is_some_and(|ext| ext == "png") {
pngs.push(path);
}
}
Expand Down

0 comments on commit 70900ba

Please sign in to comment.