From 7cf5ff9c3bf3e8a032d707617848a7d6c7cf43de Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Thu, 30 Oct 2025 00:26:41 -0400 Subject: [PATCH] Can process a directory, force the build, and almost detect if there's a change. Color indexing is wrong in posterization and needs to enforce result width/height. --- config.json | 2 +- main.go | 2 +- processing.go | 26 ++++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index 288059f..53c85e5 100644 --- a/config.json +++ b/config.json @@ -12,7 +12,7 @@ "Exceptions": { "temp/painted_*.png": { "PixelWidth": 8, - "ColorDepth": 4, + "ColorDepth": 16, "DitherType": 2, "Width": 256, "Height": 256 diff --git a/main.go b/main.go index 5d84f4b..ff44126 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ func main() { opts := ParseOpts() config := LoadSettings(opts.Config) - err := RenderImages(config) + err := RenderImages(config, opts.Force) if err != nil { log.Fatalf("failed to walk dir %s: %v", config.Source, err) diff --git a/processing.go b/processing.go index 0cb976e..85ccd3d 100644 --- a/processing.go +++ b/processing.go @@ -2,6 +2,7 @@ package main import ( "os" + "errors" "io/fs" "fmt" "path/filepath" @@ -124,7 +125,20 @@ func GetConversion(config Settings, path string) Conversion { return config.Base } -func RenderImages(config Settings) error { +func HasChanged(old_info fs.FileInfo, new_path string) bool { + new_info, err := os.Stat(new_path) + + if errors.Is(err, fs.ErrNotExist) { + return true + } else if err != nil { + log.Printf("!!!! can't stat target: %s: %v", new_path, err) + return false + } + + return old_info.ModTime().After(new_info.ModTime()) +} + +func RenderImages(config Settings, force bool) error { err := filepath.WalkDir(config.Source, func(path string, d fs.DirEntry, err error) error { if !d.IsDir() && Included(config, path) { @@ -137,7 +151,15 @@ func RenderImages(config Settings) error { fmt.Println("FILE: ", path, "TARGET:", target) convert := GetConversion(config, path) - JankImage(convert, path, target) + + path_info, err := d.Info() + if err != nil { + log.Fatalf("failed to stat %s: %v", path, err) + } + + if force || HasChanged(path_info, target) { + JankImage(convert, path, target) + } } else { fmt.Println("SKIP:", path) }