Search in sources :

Example 1 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 2 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 3 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 4 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)

Example 5 with FileHandle

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

the class I18NBundle method loadBundle.

// Tries to load the bundle for the given locale.
private static I18NBundle loadBundle(FileHandle baseFileHandle, String encoding, Locale targetLocale) {
    I18NBundle bundle = null;
    Reader reader = null;
    try {
        FileHandle fileHandle = toFileHandle(baseFileHandle, targetLocale);
        if (checkFileExistence(fileHandle)) {
            // Instantiate the bundle
            bundle = new I18NBundle();
            // Load bundle properties from the stream with the specified encoding
            reader = fileHandle.reader(encoding);
            bundle.load(reader);
        }
    } catch (IOException e) {
        throw new GdxRuntimeException(e);
    } finally {
        StreamUtils.closeQuietly(reader);
    }
    if (bundle != null) {
        bundle.setLocale(targetLocale);
    }
    return bundle;
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException)

Aggregations

FileHandle (com.badlogic.gdx.files.FileHandle)176 File (java.io.File)48 Array (com.badlogic.gdx.utils.Array)39 IOException (java.io.IOException)36 GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)27 TextureAtlasData (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData)16 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)14 Texture (com.badlogic.gdx.graphics.Texture)13 ArrayList (java.util.ArrayList)12 Region (com.badlogic.gdx.graphics.g2d.TextureAtlas.TextureAtlasData.Region)11 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)11 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)9 IntArray (com.badlogic.gdx.utils.IntArray)9 Element (com.badlogic.gdx.utils.XmlReader.Element)9 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)8 Json (com.badlogic.gdx.utils.Json)7 FontData (com.ray3k.skincomposer.data.FontData)7 Pixmap (com.badlogic.gdx.graphics.Pixmap)6 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)6 FreeTypeFontGenerator (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator)6