import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.nio.file.*; import javax.imageio.ImageIO; /** Deterministic game-build sizing. Keep the full generated artwork untouched. */ public class BuildInventoryTextures { public static void main(String[] args) throws Exception { Path source=Path.of(args[0]),out=Path.of(args[1]); Files.createDirectories(out); int count=0; try(var stream=Files.list(source)){ for(Path p:stream.filter(x->x.getFileName().toString().endsWith(".png")).sorted().toList()){ BufferedImage image=ImageIO.read(p.toFile()); if(image==null)throw new IllegalArgumentException("Invalid sprite: "+p); if(!image.getColorModel().hasAlpha()||((image.getRGB(0,0)>>>24)&255)!=0){System.out.println("ALPHA_FAIL "+p.getFileName());continue;} BufferedImage small=new BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB); Graphics2D g=small.createGraphics();g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); double scale=32.0/Math.max(image.getWidth(),image.getHeight()); int w=Math.max(1,(int)Math.round(image.getWidth()*scale)),h=Math.max(1,(int)Math.round(image.getHeight()*scale)); g.drawImage(image,(32-w)/2,(32-h)/2,w,h,null);g.dispose(); boolean visible=false;for(int y=0;y<32;y++)for(int x=0;x<32;x++)if((small.getRGB(x,y)>>>24)!=0)visible=true; if(!visible)throw new IllegalArgumentException("Empty texture: "+p); ImageIO.write(small,"png",out.resolve(p.getFileName()).toFile());count++; } } System.out.println("Validated and sized "+count+" transparent inventory sprites to 32x32; originals unchanged."); } }