Skip to content
Snippets Groups Projects
Commit b00c5ef0 authored by Luboš Horáček's avatar Luboš Horáček
Browse files

#22 DirecotryAssets tool

parent f303711c
No related branches found
No related tags found
No related merge requests found
package cz.nic.tablexia.util.assetmanager;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import java.util.HashMap;
import cz.nic.tablexia.loader.TablexiaAssetManager;
import cz.nic.tablexia.util.Log;
/**
* Created by lhoracek on 4/3/15.
*/
public abstract class DirectoryAsset extends HashMap<String, String> {
public abstract String getPath();
public DirectoryAsset() {
loadFilesInDir(getPath());
}
private void loadFilesInDir(String path) {
for (FileHandle entry : getDirHandle(path).list()) {
loadFiles("", entry);
}
}
private void loadFiles(String path, FileHandle fh) {
if (fh.isDirectory()) {
Log.info(getClass().getName(), "Is directory: " + fh.name());
for (FileHandle entry : fh.list()) {
loadFiles(path + fh.name() + "/", entry);
}
} else {
add(path, fh);
}
}
private FileHandle getDirHandle(String path) {
FileHandle dirHandle;
dirHandle = Gdx.files.external(TablexiaAssetManager.StorageType.EXTERNAL.getStoragePath() + path);
return dirHandle;
}
public String add(String path, FileHandle fh) {
String fullPath = getPath() + "/" + path + fh.name();
String key = path + fh.nameWithoutExtension();
Log.info(getClass().getName(), "Adding asset: " + key + " : " + fullPath);
return super.put(key, fullPath);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment