Search in sources :

Example 66 with FileHandle

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

the class TideMapLoader method getRelativeFileHandle.

private static FileHandle getRelativeFileHandle(FileHandle file, String path) {
    StringTokenizer tokenizer = new StringTokenizer(path, "\\/");
    FileHandle result = file.parent();
    while (tokenizer.hasMoreElements()) {
        String token = tokenizer.nextToken();
        if (token.equals(".."))
            result = result.parent();
        else {
            result = result.child(token);
        }
    }
    return result;
}
Also used : StringTokenizer(java.util.StringTokenizer) FileHandle(com.badlogic.gdx.files.FileHandle)

Example 67 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 68 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 69 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 70 with FileHandle

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

the class ResolutionFileResolver method resolve.

@Override
public FileHandle resolve(String fileName) {
    Resolution bestResolution = choose(descriptors);
    FileHandle originalHandle = new FileHandle(fileName);
    FileHandle handle = baseResolver.resolve(resolve(originalHandle, bestResolution.folder));
    if (!handle.exists())
        handle = baseResolver.resolve(fileName);
    return handle;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle)

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