From 8346f4d5b5158c8330a885ce0428c15a8acc575e Mon Sep 17 00:00:00 2001 From: LeeWannacott Date: Sat, 16 Mar 2024 19:32:11 +1300 Subject: [PATCH] Resized frames now have original name of the image; made commands less verbose now. --- main.go | 8 ++++---- src/gontage.go | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 013e310..ec8154f 100644 --- a/main.go +++ b/main.go @@ -41,10 +41,10 @@ func main() { os.Exit(1) } sprite_source_folder := flag.String("f", "", "Folder name that contains sprites.") - hframes := flag.Int("hframes", 8, "Amount of horizontal sprites you want in your spritesheet: default 8.") - sprite_resize_px := flag.Int("sprite_resize", 0, "Resize each tile/sprite in spritesheet to the pixel value provided.") - single_sprites := flag.Bool("single_sprites", false, "Instead of spritesheet outputs single sprites into a folder used with -sprite_resize flag") - parent_folder_path := flag.String("mf", "", "multiple folders: path should be parent folder containing sub folders that contain folders with sprites/images in them. Refer to test_multi for example structure.") + hframes := flag.Int("hf", 8, "Horizontal Frames: Amount of horizontal frames you want in your spritesheet: default 8.") + sprite_resize_px := flag.Int("sr", 0, "Sprite Resize: Resize each sprite to the pixel value provided.") + single_sprites := flag.Bool("ss", false, "Single Sprites: Output sprites rather than spritesheet use with -sr flag") + parent_folder_path := flag.String("mf", "", "Multiple Folders: path should be parent folder containing sub folders that contain folders with sprites/images in them. Refer to test_multi for example structure.") useMontage := flag.Bool("montage", false, "Use montage with -mf instead of gontage (if installed)") help := flag.Bool("h", false, "Display help") flag.Parse() diff --git a/src/gontage.go b/src/gontage.go index a9a5f05..9febc2b 100644 --- a/src/gontage.go +++ b/src/gontage.go @@ -55,6 +55,7 @@ func Gontage(sprite_source_folder string, hframes *int, sprite_resize_px int, si var chunk_images_waitgroup sync.WaitGroup all_decoded_images := make([]image.Image, len(sprites_folder)) + all_decoded_images_names := make([]string, len(sprites_folder)) for i := 0; i < len(sprites_folder); i += chunkSize { start := i end := start + chunkSize @@ -65,9 +66,10 @@ func Gontage(sprite_source_folder string, hframes *int, sprite_resize_px int, si chunk_images_waitgroup.Add(1) go func(start int, end int) { // Ideally decodeImages would write into all_decoded_images directly. - one_chunk_of_decoded_images := decodeImages(sprites_folder[start:end], sprite_source_folder, pwd, &chunk_images_waitgroup) + one_chunk_of_decoded_images, decoded_image_names := decodeImages(sprites_folder[start:end], sprite_source_folder, pwd, &chunk_images_waitgroup) for j, decoded_image := range one_chunk_of_decoded_images { all_decoded_images[start+j] = decoded_image + all_decoded_images_names[start+j] = decoded_image_names[j] } }(start, end) } @@ -79,7 +81,7 @@ func Gontage(sprite_source_folder string, hframes *int, sprite_resize_px int, si os.Mkdir(sprite_source_folder_resized_name, 0755) encoder := png.Encoder{CompressionLevel: png.BestSpeed} for i, decoded_image := range all_decoded_images { - resized_sprite_name := fmt.Sprintf("/%v_%v.png", i, "resized") + resized_sprite_name := fmt.Sprintf("/%v", all_decoded_images_names[i]) f, err := os.Create(sprite_source_folder_resized_name + resized_sprite_name) if err != nil { panic(err) @@ -137,9 +139,10 @@ func Gontage(sprite_source_folder string, hframes *int, sprite_resize_px int, si } } -func decodeImages(sprites_folder []fs.DirEntry, targetFolder string, pwd string, wg *sync.WaitGroup) []image.Image { +func decodeImages(sprites_folder []fs.DirEntry, targetFolder string, pwd string, wg *sync.WaitGroup) ([]image.Image, []string) { defer wg.Done() var sprites_array []image.Image + var sprites_names []string for _, sprite := range sprites_folder { if reader, err := os.Open(filepath.Join(pwd, targetFolder, sprite.Name())); err == nil { m, _, err := image.Decode(reader) @@ -147,10 +150,11 @@ func decodeImages(sprites_folder []fs.DirEntry, targetFolder string, pwd string, log.Fatal(err) } sprites_array = append(sprites_array, m) + sprites_names = append(sprites_names, sprite.Name()) reader.Close() } } - return sprites_array + return sprites_array, sprites_names } func drawSpritesheet(drawing drawingInfo) {