Search in sources :

Example 1 with Settings

use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project libgdx by libgdx.

the class TiledMapPacker method main.

/** Processes a directory of Tile Maps, compressing each tile set contained in any map once.
	 * 
	 * @param args args[0]: the input directory containing the tmx files (and tile sets, relative to the path listed in the tmx
	 *           file). args[1]: The output directory for the tmx files, should be empty before running. args[2-4] options */
public static void main(String[] args) {
    final Settings texturePackerSettings = new Settings();
    texturePackerSettings.paddingX = 2;
    texturePackerSettings.paddingY = 2;
    texturePackerSettings.edgePadding = true;
    texturePackerSettings.duplicatePadding = true;
    texturePackerSettings.bleed = true;
    texturePackerSettings.alias = true;
    texturePackerSettings.useIndexes = true;
    final TiledMapPackerSettings packerSettings = new TiledMapPackerSettings();
    if (args.length == 0) {
        printUsage();
        System.exit(0);
    } else if (args.length == 1) {
        inputDir = new File(args[0]);
        outputDir = new File(inputDir, "../output/");
    } else if (args.length == 2) {
        inputDir = new File(args[0]);
        outputDir = new File(args[1]);
    } else {
        inputDir = new File(args[0]);
        outputDir = new File(args[1]);
        processExtraArgs(args, packerSettings);
    }
    TiledMapPacker packer = new TiledMapPacker(packerSettings);
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    config.forceExit = false;
    config.width = 100;
    config.height = 50;
    config.title = "TiledMapPacker";
    new LwjglApplication(new ApplicationListener() {

        @Override
        public void resume() {
        }

        @Override
        public void resize(int width, int height) {
        }

        @Override
        public void render() {
        }

        @Override
        public void pause() {
        }

        @Override
        public void dispose() {
        }

        @Override
        public void create() {
            TiledMapPacker packer = new TiledMapPacker(packerSettings);
            if (!inputDir.exists()) {
                System.out.println(inputDir.getAbsolutePath());
                throw new RuntimeException("Input directory does not exist: " + inputDir);
            }
            try {
                packer.processInputDir(texturePackerSettings);
            } catch (IOException e) {
                throw new RuntimeException("Error processing map: " + e.getMessage());
            }
            System.out.println("Finished processing.");
            Gdx.app.exit();
        }
    }, config);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) LwjglApplication(com.badlogic.gdx.backends.lwjgl.LwjglApplication) ApplicationListener(com.badlogic.gdx.ApplicationListener) LwjglApplicationConfiguration(com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration) IOException(java.io.IOException) File(java.io.File) Settings(com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings)

Example 2 with Settings

use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project libgdx by libgdx.

the class TexturePackerFileProcessor method process.

public ArrayList<Entry> process(File[] files, File outputRoot) throws Exception {
    // Delete pack file and images.
    if (outputRoot.exists()) {
        // Load root settings to get scale.
        File settingsFile = new File(root, "pack.json");
        Settings rootSettings = defaultSettings;
        if (settingsFile.exists()) {
            rootSettings = new Settings(rootSettings);
            merge(rootSettings, settingsFile);
        }
        String atlasExtension = rootSettings.atlasExtension == null ? "" : rootSettings.atlasExtension;
        atlasExtension = Pattern.quote(atlasExtension);
        for (int i = 0, n = rootSettings.scale.length; i < n; i++) {
            FileProcessor deleteProcessor = new FileProcessor() {

                protected void processFile(Entry inputFile) throws Exception {
                    inputFile.inputFile.delete();
                }
            };
            deleteProcessor.setRecursive(false);
            String scaledPackFileName = rootSettings.getScaledPackFileName(packFileName, i);
            File packFile = new File(scaledPackFileName);
            String prefix = packFile.getName();
            int dotIndex = prefix.lastIndexOf('.');
            if (dotIndex != -1)
                prefix = prefix.substring(0, dotIndex);
            deleteProcessor.addInputRegex("(?i)" + prefix + "\\d*\\.(png|jpg|jpeg)");
            deleteProcessor.addInputRegex("(?i)" + prefix + atlasExtension);
            String dir = packFile.getParent();
            if (dir == null)
                deleteProcessor.process(outputRoot, null);
            else if (//
            new File(outputRoot + "/" + dir).exists())
                deleteProcessor.process(outputRoot + "/" + dir, null);
        }
    }
    return super.process(files, outputRoot);
}
Also used : FileProcessor(com.badlogic.gdx.tools.FileProcessor) File(java.io.File) Settings(com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings)

Example 3 with Settings

use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project libgdx by libgdx.

the class TexturePackerFileProcessor method process.

public ArrayList<Entry> process(File inputFile, File outputRoot) throws Exception {
    root = inputFile;
    // Collect pack.json setting files.
    final ArrayList<File> settingsFiles = new ArrayList();
    FileProcessor settingsProcessor = new FileProcessor() {

        protected void processFile(Entry inputFile) throws Exception {
            settingsFiles.add(inputFile.inputFile);
        }
    };
    settingsProcessor.addInputRegex("pack\\.json");
    settingsProcessor.process(inputFile, null);
    // Sort parent first.
    Collections.sort(settingsFiles, new Comparator<File>() {

        public int compare(File file1, File file2) {
            return file1.toString().length() - file2.toString().length();
        }
    });
    for (File settingsFile : settingsFiles) {
        // Find first parent with settings, or use defaults.
        Settings settings = null;
        File parent = settingsFile.getParentFile();
        while (true) {
            if (parent.equals(root))
                break;
            parent = parent.getParentFile();
            settings = dirToSettings.get(parent);
            if (settings != null) {
                settings = new Settings(settings);
                break;
            }
        }
        if (settings == null)
            settings = new Settings(defaultSettings);
        // Merge settings from current directory.
        merge(settings, settingsFile);
        dirToSettings.put(settingsFile.getParentFile(), settings);
    }
    // Do actual processing.
    return super.process(inputFile, outputRoot);
}
Also used : FileProcessor(com.badlogic.gdx.tools.FileProcessor) ArrayList(java.util.ArrayList) File(java.io.File) Settings(com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings)

Example 4 with Settings

use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project ultimate-java by pantinor.

the class PackImagesUtil method main.

public static void main(String[] argv) throws Exception {
    Settings settings = new Settings();
    settings.maxWidth = 192 * 8;
    settings.maxHeight = 192 * 8;
    settings.paddingX = 0;
    settings.paddingY = 0;
    settings.fast = true;
    settings.pot = false;
    settings.grid = true;
    TexturePacker tp = new TexturePacker(settings);
    File file = new File("C:\\Users\\Paul\\Desktop\\water\\Exp_type_B.png");
    BufferedImage fr = ImageIO.read(file);
    int count = 0;
    for (int x = 0; x < fr.getWidth(); x += 192) {
        count++;
        BufferedImage sub = fr.getSubimage(x, 0, 192, 192);
        tp.addImage(sub, "expl" + count);
    }
    tp.pack(new File("."), "Exp_type_B");
    System.out.println("done");
}
Also used : TexturePacker(com.badlogic.gdx.tools.texturepacker.TexturePacker) File(java.io.File) Settings(com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings) BufferedImage(java.awt.image.BufferedImage)

Example 5 with Settings

use of com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings in project ultimate-java by pantinor.

the class PackImagesUtil method main1.

public static void main1(String[] argv) throws Exception {
    List<File> files = listFileTree(new File("C:\\Users\\Paul\\Desktop\\crawl-tiles Oct-5-2010\\dc-dngn"));
    Collections.sort(files);
    Map<String, BufferedImage> imgMap = new TreeMap<String, BufferedImage>();
    for (File file : files) {
        if (file.isDirectory() || !file.getName().endsWith("png")) {
            continue;
        }
        String name = file.getName();
        BufferedImage fr = ImageIO.read(file);
        imgMap.put(name, fr);
    }
    Settings settings = new Settings();
    settings.maxWidth = 768;
    settings.maxHeight = 768;
    settings.paddingX = 0;
    settings.paddingY = 0;
    settings.fast = true;
    settings.pot = false;
    settings.grid = true;
    TexturePacker tp = new TexturePacker(settings);
    for (String name : imgMap.keySet()) {
        BufferedImage image = imgMap.get(name);
        tp.addImage(image, name);
    }
    System.out.println("Writing: number of res: " + imgMap.size());
    tp.pack(new File("."), "utumno-dngn");
    System.out.println("done");
}
Also used : TexturePacker(com.badlogic.gdx.tools.texturepacker.TexturePacker) TreeMap(java.util.TreeMap) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Settings(com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings)

Aggregations

Settings (com.badlogic.gdx.tools.texturepacker.TexturePacker.Settings)22 File (java.io.File)17 FileProcessor (com.badlogic.gdx.tools.FileProcessor)9 ArrayList (java.util.ArrayList)7 TexturePacker (com.badlogic.gdx.tools.texturepacker.TexturePacker)5 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)4 BufferedImage (java.awt.image.BufferedImage)4 TreeMap (java.util.TreeMap)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 Page (com.badlogic.gdx.tools.texturepacker.TexturePacker.Page)2 Rect (com.badlogic.gdx.tools.texturepacker.TexturePacker.Rect)2 Array (com.badlogic.gdx.utils.Array)2 IOException (java.io.IOException)2 Random (java.util.Random)2 ApplicationListener (com.badlogic.gdx.ApplicationListener)1 LwjglApplication (com.badlogic.gdx.backends.lwjgl.LwjglApplication)1 LwjglApplicationConfiguration (com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 Json (com.badlogic.gdx.utils.Json)1