Search in sources :

Example 31 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project Entitas-Java by Rubentxu.

the class TestFileHandleResolver method resolve.

@Override
public FileHandle resolve(String fileName) {
    URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
    File file = new File(url.getPath());
    return new FileHandle(file);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) File(java.io.File) URL(java.net.URL)

Example 32 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project Entitas-Java by Rubentxu.

the class TestFileHandleResolver method resolve.

@Override
public FileHandle resolve(String fileName) {
    URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
    File file = new File(url.getPath());
    return new FileHandle(file);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) File(java.io.File) URL(java.net.URL)

Example 33 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project Entitas-Java by Rubentxu.

the class ProfileManagerGDX method persist.

@Override
public void persist(P profile) {
    FileHandle profileDataFile = Gdx.files.local(preferencesManager.PROFILE_DATA_FILE);
    Json json = new Json();
    String profileAsText = json.toJson(profile);
    profileAsText = Base64Coder.encodeString(profileAsText);
    profileDataFile.writeString(profileAsText, false);
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Json(com.badlogic.gdx.utils.Json)

Example 34 with FileHandle

use of com.badlogic.gdx.files.FileHandle in project Entitas-Java by Rubentxu.

the class ProfileManagerGDX method retrieveProfile.

@Override
public P retrieveProfile() {
    FileHandle profileDataFile = Gdx.files.local(preferencesManager.PROFILE_DATA_FILE);
    Json json = new Json();
    if (profileDataFile.exists()) {
        try {
            String profileAsText = profileDataFile.readString().trim();
            if (profileAsText.matches("^[A-Za-z0-9/+=]+$")) {
                profileAsText = Base64Coder.decodeString(profileAsText);
            }
            profile = (P) json.fromJson(profile.getClass(), profileAsText);
        } catch (Exception e) {
            FileHandle initProfileDataFile = Gdx.files.internal(preferencesManager.INIT_PROFILE_DATA_FILE);
            profile = (P) json.fromJson(profile.getClass(), initProfileDataFile.readString().trim());
            persist(profile);
        }
    } else {
        FileHandle initProfileDataFile = Gdx.files.internal(preferencesManager.INIT_PROFILE_DATA_FILE);
        profile = (P) json.fromJson(profile.getClass(), initProfileDataFile.readString().trim());
        persist(profile);
    }
    return profile;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Json(com.badlogic.gdx.utils.Json)

Example 35 with FileHandle

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

the class Preloader method list.

public FileHandle[] list(String url, String suffix) {
    Array<FileHandle> files = new Array<FileHandle>();
    for (String path : texts.keys()) {
        if (isChild(path, url) && path.endsWith(suffix)) {
            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)

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