Example usage for com.badlogic.gdx.backends.lwjgl LwjglFiles absolute

List of usage examples for com.badlogic.gdx.backends.lwjgl LwjglFiles absolute

Introduction

In this page you can find the example usage for com.badlogic.gdx.backends.lwjgl LwjglFiles absolute.

Prototype

@Override
    public FileHandle absolute(String path) 

Source Link

Usage

From source file:es.eucm.ead.maven.GenerateSkinMojo.java

License:Open Source License

public void execute() throws MojoExecutionException {

    if (!sourceDir.exists()) {
        throw new MojoExecutionException("[generate-skins] Source directory does not exists: " + sourceDir);
    }/* w w  w .  ja  v  a2 s .  c om*/

    if (!outputDir.exists()) {
        if (!outputDir.mkdir()) {
            throw new MojoExecutionException("[generate-skins] Cannot create output directory: " + outputDir);
        }
    }

    Settings settings = new Settings();
    settings.limitMemory = false;

    LwjglFiles files = new LwjglFiles();
    LwjglNativesLoader.load();
    FileHandle rawRoot = files.absolute(sourceDir.getAbsolutePath());
    FileHandle skinsRoot = new FileHandle(files.internal(outputDir.getAbsolutePath()).file());

    getLog().info("[generate-skins] Removing old skins (if any)");
    for (FileHandle folder : skinsRoot.list()) {
        folder.deleteDirectory();
    }

    Array<FileHandle> tempFolders = new Array<FileHandle>();
    for (FileHandle skinRaw : rawRoot.list()) {
        if (skinRaw.isDirectory()) {
            FileHandle skinFolder = skinsRoot.child(skinRaw.name());

            if (!skinFolder.exists()) {

                if (skinRaw.child("common").exists()) {
                    generateMultipleSkins(skinRaw, skinsRoot);
                } else {
                    getLog().info("[generate-skins] Generating: " + skinRaw.name());
                    skinFolder.mkdirs();
                    FileHandle imagesFolder = skinRaw.child("images");

                    FileHandle fonts = skinRaw.child("ttf2fnt");
                    if (fonts.exists()) {
                        FileHandle config = fonts.child("fonts.config");
                        // fonts.config defines which .ttf will be
                        // transformed
                        // to what .fnt and with what size.
                        if (!config.exists()) {
                            fonts.copyTo(skinFolder);
                        } else {
                            String[] lines = config.readString().split("\n");
                            for (String line : lines) {
                                String[] props = line.split(" ");
                                String ttfFontName = props[0];
                                String fontSize = props[1];
                                fontSize = fontSize.replace("\r", "");

                                FileHandle child = fonts.child(ttfFontName);
                                if (child.exists()) {
                                    String fontName = child.nameWithoutExtension() + "-" + fontSize;
                                    FileHandle dstFolder = imagesFolder.child(fontName);
                                    dstFolder.mkdirs();
                                    dstFolder.child("pack.json").writeString(defaultPack, false);
                                    tempFolders.add(dstFolder);
                                    generateFiles(fontName, child, Integer.valueOf(fontSize), dstFolder);
                                    dstFolder.child(fontName + ".fnt").copyTo(skinFolder);
                                }
                            }
                        }
                    }
                    fonts = skinRaw.child("fonts");
                    if (fonts.exists()) {
                        fonts.copyTo(skinFolder);
                    }

                    TexturePacker.process(settings, imagesFolder.file().getAbsolutePath(),
                            skinFolder.file().getAbsolutePath(), "skin");

                    skinRaw.child("skin.json").copyTo(skinFolder);

                    for (FileHandle tempFolder : tempFolders) {
                        tempFolder.deleteDirectory();
                    }
                }
            } else {
                getLog().info("[generate-skins] skin already exists, skipping: " + skinRaw.name());
            }
        }
    }

}