SHARE
TWEET

Untitled

a guest Nov 18th, 2016 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     package com.boringville.td.tdtest04.core.tools;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.nio.file.Files;
  6. import java.nio.file.StandardCopyOption;
  7.  
  8. import com.badlogic.gdx.graphics.Texture.TextureFilter;
  9. import com.badlogic.gdx.tools.imagepacker.TexturePacker2;
  10. import com.badlogic.gdx.tools.imagepacker.TexturePacker2.Settings;
  11.  
  12. public class TexturePacker {
  13.     private static void delete(final File delete) {
  14.         if (delete.isDirectory()) {
  15.             for (final File file : delete.listFiles()) {
  16.                 delete(file);
  17.             }
  18.         }
  19.         delete.delete();
  20.     }
  21.  
  22.     public static void main(final String[] args) throws Exception {
  23.         final Settings settings = new Settings();
  24.         settings.maxWidth = 1024;
  25.         settings.maxHeight = 1024;
  26.         settings.pot = true;
  27.         settings.forceSquareOutput = true;
  28.         settings.filterMin = TextureFilter.MipMapLinearLinear;
  29.         settings.filterMag = TextureFilter.Linear;
  30.         TexturePacker2.process(settings, "../assets-raw/mobs", "../assets/gfx", "mobs");
  31.         TexturePacker2.process("../assets-raw/ui", "../assets/ui", "ui");
  32.  
  33.         settings.edgePadding = true;
  34.         settings.paddingX = 2;
  35.         settings.paddingY = 2;
  36.         settings.duplicatePadding = true;
  37.         packMap(settings, "../../../", "grasslands", "../assets/gfx/maps/", 32);
  38.         packMap(settings, "../../../", "grasslands", "../assets/gfx/maps/", 48);
  39.         packMap(settings, "../../../", "grasslands", "../assets/gfx/maps/", 64);
  40.         packMap(settings, "../../../", "grasslands", "../assets/gfx/maps/", 96);
  41.     }
  42.  
  43.     private static void packMap(final Settings settings, final String root, final String in,
  44.             final String out, final int resolution) throws Exception {
  45.         final String inPath = root + "/" + in + "/pieces/";
  46.         sort(inPath, "" + resolution);
  47.         TexturePacker2.process(settings, inPath + resolution, out + "/" + in + "/" + resolution,
  48.                 "grasslands");
  49.     }
  50.  
  51.     private static void sort(final String root, final String resolution) throws IOException {
  52.         final File outDir = new File(root + "/" + resolution);
  53.         delete(outDir);
  54.         outDir.mkdirs();
  55.  
  56.         for (final File file : new File(root).listFiles()) {
  57.             if (file.getName().endsWith("-" + resolution + ".png")) {
  58.                 Files.copy(file.toPath(),
  59.                         new File(outDir, file.getName().replace("-" + resolution, "")).toPath(),
  60.                         StandardCopyOption.REPLACE_EXISTING);
  61.             }
  62.         }
  63.     }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top