From 7334389b4e7f24961ee795c3b5adcef5e0f90e2f Mon Sep 17 00:00:00 2001 From: gered Date: Sat, 5 Oct 2013 18:47:43 -0400 Subject: [PATCH] add file loading and path string extraction helper methods --- src/com/blarg/gdx/io/FileHelpers.java | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/com/blarg/gdx/io/FileHelpers.java diff --git a/src/com/blarg/gdx/io/FileHelpers.java b/src/com/blarg/gdx/io/FileHelpers.java new file mode 100644 index 0000000..dfbed56 --- /dev/null +++ b/src/com/blarg/gdx/io/FileHelpers.java @@ -0,0 +1,37 @@ +package com.blarg.gdx.io; + +import com.badlogic.gdx.Files; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.files.FileHandle; + +public final class FileHelpers { + public static String getPath(FileHandle file) { + return getPath(file.path()); + } + + public static String getPath(String filename) { + int pos = filename.lastIndexOf('/'); + if (pos == -1) + return ""; + else + return filename.substring(0, pos + 1); + } + + public static boolean hasPath(String filename) { + return filename.contains("/"); + } + + public static FileHandle open(Files.FileType type, String path) { + if (path == null) + throw new IllegalArgumentException("path can not be null."); + + switch (type) { + case Classpath: return Gdx.files.classpath(path); + case Internal: return Gdx.files.internal(path); + case External: return Gdx.files.external(path); + case Absolute: return Gdx.files.absolute(path); + case Local: return Gdx.files.local(path); + default: throw new UnsupportedOperationException(); + } + } +}