Search in sources :

Example 41 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project gdx-skineditor by cobolfoo.

the class WelcomeScreen method createProject.

/**
	 * 
	 * @param projectName
	 */
public void createProject(String projectName) {
    FileHandle projectFolder = Gdx.files.local("projects").child(projectName);
    if (projectFolder.exists() == true) {
        game.showNotice("Error", "Project name already in use!", stage);
        return;
    }
    projectFolder.mkdirs();
    projectFolder.child("assets").mkdirs();
    projectFolder.child("backups").mkdirs();
    game.skin.save(projectFolder.child("uiskin.json"));
    // Copy assets
    FileHandle assetsFolder = Gdx.files.local("resources/raw");
    assetsFolder.copyTo(projectFolder.child("assets"));
    // Rebuild from raw resources
    TexturePacker.Settings settings = new TexturePacker.Settings();
    settings.combineSubdirectories = true;
    TexturePacker.process(settings, "projects/" + projectName + "/assets/", "projects/" + projectName, "uiskin");
    game.showNotice("Operation completed", "New project successfully created.", stage);
    refreshProjects();
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) TexturePacker(com.badlogic.gdx.tools.texturepacker.TexturePacker)

Example 42 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project bdx by GoranM.

the class Sounds method available.

public ArrayList<String> available() {
    ArrayList<String> tracks = new ArrayList<String>();
    FileHandle[] files = Gdx.files.internal("bdx/audio/sounds/").list("");
    for (FileHandle file : files) tracks.add(file.nameWithoutExtension());
    return tracks;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) ArrayList(java.util.ArrayList)

Example 43 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project bdx by GoranM.

the class DesktopLauncher method main.

public static void main(String[] arg) {
    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    config.title = "FontWriter";
    config.width = 666;
    config.height = 444;
    final ArrayList<String[]> files = new ArrayList<>();
    for (String a : arg) files.add(a.split("---"));
    new LwjglApplication(new ApplicationAdapter() {

        public void create() {
            for (String[] commands : files) {
                boolean properlyCreated = false;
                int resX = 256;
                int resY = 256;
                while (!properlyCreated) {
                    // Supply the full path
                    String inputFontPath = commands[0];
                    FileHandle outputFolder = Gdx.files.absolute(commands[1]);
                    String fileName = outputFolder.nameWithoutExtension();
                    outputFolder = outputFolder.parent();
                    int fontSize = Integer.valueOf(commands[2]);
                    int shadowOffsetX = Integer.valueOf(commands[3]);
                    int shadowOffsetY = Integer.valueOf(commands[4]);
                    Color shadowColor = new Color(Float.valueOf(commands[5]), Float.valueOf(commands[6]), Float.valueOf(commands[7]), Float.valueOf(commands[8]));
                    int outlineThickness = Integer.valueOf(commands[9]);
                    Color outlineColor = new Color(Float.valueOf(commands[10]), Float.valueOf(commands[11]), Float.valueOf(commands[12]), Float.valueOf(commands[13]));
                    boolean outlineRounded = Boolean.valueOf(commands[14]);
                    BitmapFontWriter.FontInfo fontInfo = new BitmapFontWriter.FontInfo();
                    fontInfo.padding = new BitmapFontWriter.Padding(1, 1, 1, 1);
                    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.absolute(inputFontPath));
                    FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
                    parameter.color = new Color(Float.valueOf(commands[15]), Float.valueOf(commands[16]), Float.valueOf(commands[17]), Float.valueOf(commands[18]));
                    parameter.borderColor = outlineColor;
                    parameter.borderWidth = outlineThickness;
                    parameter.borderStraight = !outlineRounded;
                    parameter.shadowOffsetX = shadowOffsetX;
                    parameter.shadowOffsetY = shadowOffsetY;
                    parameter.shadowColor = shadowColor;
                    parameter.size = fontSize;
                    parameter.packer = new PixmapPacker(resX, resY, Pixmap.Format.RGBA8888, 2, false, new PixmapPacker.SkylineStrategy());
                    FreeTypeFontGenerator.FreeTypeBitmapFontData data = generator.generateData(parameter);
                    // Writes the .fnt file, I guess
                    BitmapFontWriter.writeFont(data, new String[] { fileName + ".png" }, outputFolder.child(fileName + ".fnt"), fontInfo, resX, resY);
                    BitmapFontWriter.writePixmaps(parameter.packer.getPages(), outputFolder, fileName);
                    generator.dispose();
                    FileHandle path = outputFolder.child(fileName + ".png");
                    if (path.exists())
                        properlyCreated = true;
                    else {
                        // BitmapFontWriter generated multiple bitmaps; can't use them.
                        // We re-run with higher source texture res so they should fit
                        resX *= 2;
                        // on a single texture, continuously as necessary.
                        resY *= 2;
                        for (FileHandle f : outputFolder.list()) {
                            if (f.nameWithoutExtension().contains(fileName + "_") && f.extension().equals("png"))
                                f.delete();
                        }
                    }
                }
            }
            Gdx.app.exit();
        }
    }, config);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Color(com.badlogic.gdx.graphics.Color) ArrayList(java.util.ArrayList) LwjglApplicationConfiguration(com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration) BitmapFontWriter(com.badlogic.gdx.tools.bmfont.BitmapFontWriter) FreeTypeFontGenerator(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator) LwjglApplication(com.badlogic.gdx.backends.lwjgl.LwjglApplication) PixmapPacker(com.badlogic.gdx.graphics.g2d.PixmapPacker) ApplicationAdapter(com.badlogic.gdx.ApplicationAdapter)

Example 44 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project bdx by GoranM.

the class AudioStore method findFile.

protected FileHandle findFile(String name) {
    String[] supported = { ".wav", ".mp3", ".ogg" };
    String files = "";
    for (String ext : supported) {
        FileHandle f = Gdx.files.internal(pathRoot + name + ext);
        if (f.exists())
            return f;
        files += name + ext + (ext.equals(".ogg") ? "" : " or ");
    }
    throw new GdxRuntimeException("Could not find " + files + " in " + pathRoot);
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) FileHandle(com.badlogic.gdx.files.FileHandle)

Example 45 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project bdx by GoranM.

the class Music method available.

public ArrayList<String> available() {
    ArrayList<String> tracks = new ArrayList<String>();
    FileHandle[] files = Gdx.files.internal("bdx/audio/music/").list("");
    for (FileHandle file : files) tracks.add(file.nameWithoutExtension());
    return tracks;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) ArrayList(java.util.ArrayList)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)79 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)23 IOException (java.io.IOException)22 Array (com.badlogic.gdx.utils.Array)18 File (java.io.File)18 Element (com.badlogic.gdx.utils.XmlReader.Element)9 Texture (com.badlogic.gdx.graphics.Texture)8 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)7 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 IntArray (com.badlogic.gdx.utils.IntArray)7 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)6 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)5 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)4 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)4 Json (com.badlogic.gdx.utils.Json)4 GwtFileHandle (com.badlogic.gdx.backends.gwt.GwtFileHandle)3 Color (com.badlogic.gdx.graphics.Color)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 Writer (java.io.Writer)3