Skip to content

Commit

Permalink
feat: improve help & output (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgardt authored Mar 13, 2024
1 parent 05221fc commit 0503dc5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[![release](https://github.com/fgardt/factorio-spritter/actions/workflows/release.yml/badge.svg)](https://github.com/fgardt/factorio-spritter/releases)

# Spritter

A simple CLI tool to combine individual sprites into spritesheets for factorio.
4 changes: 2 additions & 2 deletions src/image_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn crop_images(images: &mut Vec<RgbaImage>) -> Result<(i32, i32)> {
let cropped_width = max_x - min_x + 1;
let cropped_height = max_y - min_y + 1;

println!("cropping from {raw_width}x{raw_height} to {cropped_width}x{cropped_height}");
// println!("cropping from {raw_width}x{raw_height} to {cropped_width}x{cropped_height}");

// crop images
for image in images {
Expand All @@ -147,7 +147,7 @@ pub fn crop_images(images: &mut Vec<RgbaImage>) -> Result<(i32, i32)> {
let shift_x = i32::try_from(cropped_right_by).unwrap() - i32::try_from(min_x).unwrap();
let shift_y = i32::try_from(cropped_bottom_by).unwrap() - i32::try_from(min_y).unwrap();

println!("shifted by ({shift_x}, {shift_y})");
// println!("shifted by ({shift_x}, {shift_y})");

Ok((shift_x, shift_y))
}
23 changes: 21 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ enum GenerationCommand {
args: SpritesheetArgs,
},

/// Generate mipmap icon from a single image or a folder of images
/// Generate a mipmap icon from a folder of images
///
/// The individual images are used as the respective mip levels and combined into a single image
Icon {
// args
#[clap(flatten)]
Expand Down Expand Up @@ -261,7 +263,7 @@ fn generate_spritesheet(args: &SpritesheetArgs) {
return;
}

let (_shift_x, _shift_y) = if args.no_crop {
let (shift_x, shift_y) = if args.no_crop {
(0, 0)
} else {
image_util::crop_images(&mut images).unwrap()
Expand Down Expand Up @@ -364,6 +366,23 @@ fn generate_spritesheet(args: &SpritesheetArgs) {
.save_with_format(path, image::ImageFormat::Png)
.unwrap();
}

print!(
"completed {}",
output_name(&source, &args.output, None, "")
.file_name()
.unwrap()
.to_str()
.unwrap()
);

if args.no_crop {
println!();
} else {
println!(
", size: ({sprite_width}px, {sprite_height}px), shift: ({shift_x}px, {shift_y}px)"
);
}
}
}

Expand Down

0 comments on commit 0503dc5

Please sign in to comment.