Search in sources :

Example 61 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class TmxMapLoader method getDependencies.

/** Retrieves TiledMap resource dependencies
	 * 
	 * @param fileName
	 * @param parameter not used for now
	 * @return dependencies for the given .tmx file */
@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle tmxFile, Parameters parameter) {
    Array<AssetDescriptor> dependencies = new Array<AssetDescriptor>();
    try {
        root = xml.parse(tmxFile);
        boolean generateMipMaps = (parameter != null ? parameter.generateMipMaps : false);
        TextureLoader.TextureParameter texParams = new TextureParameter();
        texParams.genMipMaps = generateMipMaps;
        if (parameter != null) {
            texParams.minFilter = parameter.textureMinFilter;
            texParams.magFilter = parameter.textureMagFilter;
        }
        for (FileHandle image : loadTilesets(root, tmxFile)) {
            dependencies.add(new AssetDescriptor(image, Texture.class, texParams));
        }
        for (FileHandle image : loadImages(root, tmxFile)) {
            dependencies.add(new AssetDescriptor(image, Texture.class, texParams));
        }
        return dependencies;
    } catch (IOException e) {
        throw new GdxRuntimeException("Couldn't load tilemap '" + fileName + "'", e);
    }
}
Also used : Array(com.badlogic.gdx.utils.Array) IntArray(com.badlogic.gdx.utils.IntArray) GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TextureLoader(com.badlogic.gdx.assets.loaders.TextureLoader) FileHandle(com.badlogic.gdx.files.FileHandle) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter) TextureParameter(com.badlogic.gdx.assets.loaders.TextureLoader.TextureParameter) IOException(java.io.IOException) Texture(com.badlogic.gdx.graphics.Texture) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 62 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class Preloader method list.

public FileHandle[] list(String url, FilenameFilter filter) {
    Array<FileHandle> files = new Array<FileHandle>();
    for (String path : texts.keys()) {
        if (isChild(path, url) && filter.accept(new File(url), path.substring(url.length() + 1))) {
            files.add(new GwtFileHandle(this, path, FileType.Internal));
        }
    }
    FileHandle[] list = new FileHandle[files.size];
    System.arraycopy(files.items, 0, list, 0, list.length);
    return list;
}
Also used : Array(com.badlogic.gdx.utils.Array) GwtFileHandle(com.badlogic.gdx.backends.gwt.GwtFileHandle) FileHandle(com.badlogic.gdx.files.FileHandle) GwtFileHandle(com.badlogic.gdx.backends.gwt.GwtFileHandle) File(java.io.File)

Example 63 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class Preloader method list.

public FileHandle[] list(String url, FileFilter filter) {
    Array<FileHandle> files = new Array<FileHandle>();
    for (String path : texts.keys()) {
        if (isChild(path, url) && filter.accept(new File(path))) {
            files.add(new GwtFileHandle(this, path, FileType.Internal));
        }
    }
    FileHandle[] list = new FileHandle[files.size];
    System.arraycopy(files.items, 0, list, 0, list.length);
    return list;
}
Also used : Array(com.badlogic.gdx.utils.Array) GwtFileHandle(com.badlogic.gdx.backends.gwt.GwtFileHandle) FileHandle(com.badlogic.gdx.files.FileHandle) GwtFileHandle(com.badlogic.gdx.backends.gwt.GwtFileHandle) File(java.io.File)

Example 64 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class TextureUnpacker method main.

public static void main(String[] args) {
    TextureUnpacker unpacker = new TextureUnpacker();
    String atlasFile = null, imageDir = null, outputDir = null;
    // parse the arguments and display the help text if there is a problem with the command line arguments
    switch(unpacker.parseArguments(args)) {
        case 0:
            System.out.println(HELP);
            return;
        case 3:
            outputDir = args[2];
        case 2:
            imageDir = args[1];
        case 1:
            atlasFile = args[0];
    }
    File atlasFileHandle = new File(atlasFile);
    String atlasParentPath = atlasFileHandle.getParentFile().getAbsolutePath();
    // Set the directory variables to a default when they weren't given in the variables
    if (imageDir == null)
        imageDir = atlasParentPath;
    if (outputDir == null)
        outputDir = (new File(atlasParentPath, DEFAULT_OUTPUT_PATH)).getAbsolutePath();
    // Opens the atlas file from the specified filename
    TextureAtlasData atlas = new TextureAtlasData(new FileHandle(atlasFile), new FileHandle(imageDir), false);
    unpacker.splitAtlas(atlas, outputDir);
}
Also used : TextureAtlasData(com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData) FileHandle(com.badlogic.gdx.files.FileHandle) File(java.io.File)

Example 65 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project libgdx by libgdx.

the class BitmapFontLoader method getDependencies.

@Override
public Array<AssetDescriptor> getDependencies(String fileName, FileHandle file, BitmapFontParameter parameter) {
    Array<AssetDescriptor> deps = new Array();
    if (parameter != null && parameter.bitmapFontData != null) {
        data = parameter.bitmapFontData;
        return deps;
    }
    data = new BitmapFontData(file, parameter != null ? parameter.flip : false);
    if (parameter != null && parameter.atlasName != null) {
        deps.add(new AssetDescriptor(parameter.atlasName, TextureAtlas.class));
    } else {
        for (int i = 0; i < data.getImagePaths().length; i++) {
            String path = data.getImagePath(i);
            FileHandle resolved = resolve(path);
            TextureLoader.TextureParameter textureParams = new TextureLoader.TextureParameter();
            if (parameter != null) {
                textureParams.genMipMaps = parameter.genMipMaps;
                textureParams.minFilter = parameter.minFilter;
                textureParams.magFilter = parameter.magFilter;
            }
            AssetDescriptor descriptor = new AssetDescriptor(resolved, Texture.class, textureParams);
            deps.add(descriptor);
        }
    }
    return deps;
}
Also used : Array(com.badlogic.gdx.utils.Array) BitmapFontData(com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData) FileHandle(com.badlogic.gdx.files.FileHandle) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

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