Package com.aqpproject.tools.preprocessor

Source Code of com.aqpproject.tools.preprocessor.Preprocessor

/*
* AQP Project
* http://http://code.google.com/p/aqp-project/
* Alexandre Gomez - Clément Troesch - Fabrice Latterner
*/
package com.aqpproject.tools.preprocessor;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.backends.jogl.JoglApplication;
import com.badlogic.gdx.tiledmappacker.TiledMapPacker;
import com.badlogic.gdx.tools.imagepacker.TexturePacker;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Clement
*/
public class Preprocessor {

    public Preprocessor() {
        m_generated = false;
    }

    public void generateMap() {

        File tmxFile, inputDir, outputDir;

        inputDir = new File(MAP_INPUT_FOLDER);
        outputDir = new File(MAP_OUTPUT_FOLDER);

        if (outputDir.exists()) {
            System.out.println("MAP ALREADY GENERATED !");
            m_generated = true;
            m_newMap = false;
            return;
        }

        System.out.println("GENERATING MAPS !");
        if (!outputDir.mkdirs()) {
            System.out.println("FATAL ERROR: UNABLE TO GENERATE MAP !");
            System.exit(1);
        }


        TexturePacker.Settings settings = new TexturePacker.Settings();
        settings.maxWidth = 2048;
        settings.maxHeight = 2048;


        // Create a new JoglApplication so that Gdx stuff works properly
        JoglApplication application = new JoglApplication(new ApplicationListener() {

            @Override
            public void create() {
            }

            @Override
            public void dispose() {
                m_generated = true;

            }

            @Override
            public void pause() {
            }

            @Override
            public void render() {
            }

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

            @Override
            public void resume() {
            }
        }, "", 0, 0, false);

        TiledMapPacker packer = new TiledMapPacker();

        if (!inputDir.exists()) {
            throw new RuntimeException("Input directory does not exist");
        }
        try {
            packer.processMap(inputDir, outputDir, settings);
        } catch (IOException ex) {
            Logger.getLogger(JPacker.class.getName()).log(Level.SEVERE, null, ex);
        }

        application.exit();
        m_newMap = true;

    }

    public boolean isMapGenerated() {
        return m_generated;
    }

    public boolean hasNewMap() {
        return m_newMap;
    }
    public static String MAP_OUTPUT_FOLDER = "data/maps";
    public static String MAP_INPUT_FOLDER = "data/others/TiledMaps";
    private boolean m_generated;
    private boolean m_newMap;
}
TOP

Related Classes of com.aqpproject.tools.preprocessor.Preprocessor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.