List of usage examples for com.badlogic.gdx.files FileHandle list
public FileHandle[] list()
From source file:at.therefactory.jewelthief.JewelThief.java
License:Open Source License
/** * Either continues the music playback of a previously paused music file or proceeds to the next music file depending on the proceedToNext flag. * If there was no previous music file, a new music file is chosen randomly. * @param proceedToNext If set to true, a new music file is chosen randomly. If set to false, the previously paused file is being resumed. *//* w ww. ja v a 2 s .com*/ public void playMusicFile(boolean proceedToNext) { // remember all available music files if (musicFiles == null) { FileHandle dirHandle = Gdx.files.internal("audio/music"); FileHandle[] fileList = dirHandle.list(); musicFiles = new String[fileList.length]; for (int i = 0; i < musicFiles.length; i++) { musicFiles[i] = fileList[i].path(); Gdx.app.log(getClass().getName(), "Found '" + fileList[i].path() + "'"); } } if (musicFiles.length == 0) { Gdx.app.error(getClass().getName(), "Could not find any music files!"); } else { // select a music file to play if (currentMusicFile == -1) { // if there is no previous music file, choose a new one randomly currentMusicFile = (short) Utils.randomWithin(0, musicFiles.length - 1); music = loadMusicAsset(musicFiles[currentMusicFile]); } else if (proceedToNext) { // switch to the next music file randomly int previousMusicFile = currentMusicFile; do { currentMusicFile = (short) Utils.randomWithin(0, musicFiles.length - 1); } while (previousMusicFile == currentMusicFile); assetManager.unload(musicFiles[previousMusicFile]); // free the resources of the previous music file if (music != null) { music.dispose(); music = null; } music = loadMusicAsset(musicFiles[currentMusicFile]); } else { // resume previously paused music file } // play the selected music file music.play(); music.setOnCompletionListener(new Music.OnCompletionListener() { @Override public void onCompletion(Music music) { playMusicFile(true); } }); } }
From source file:br.com.questingsoftware.libgdx.g3db.G3DBConverter.java
License:Apache License
/** <p> * Convert all G3DJ files inside a folder to G3DB format (binary JSON). * </p>//from w w w.j a v a2 s . c o m * * * @param g3djFolder Folder containing files with the {@code g3dj} extension. Ths method will not recursively navigate folders. * * @param overwrite If {@code true} and there's already a file with the same name and the {@code g3db} extension, the file will * be overwritten. Otherwise a counter will be appended at the end of the file. * * @throws IOException If there's an exception while reading the input file or writing the output file. */ public void convertFolder(FileHandle g3djFolder, boolean overwrite) throws IOException { ArrayList<FileHandle> g3djFiles = new ArrayList<FileHandle>(); if (g3djFolder != null) { if (g3djFolder.isDirectory()) { for (FileHandle handle : g3djFolder.list()) { if (handle.name().toLowerCase().endsWith(".g3dj")) { g3djFiles.add(handle); } } } else if (g3djFolder.name().toLowerCase().endsWith(".g3dj")) { FileHandle g3djFile = g3djFolder; g3djFolder = g3djFolder.parent(); g3djFiles.add(g3djFile); } } for (FileHandle handle : g3djFiles) { convert(handle, overwrite); } }
From source file:CB_Core.DAO.CacheListDAO.java
License:Open Source License
public void delCacheImagesByPath(String path, ArrayList<String> list) { for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) { final String GcCode = iterator.next().toLowerCase(); String directory = path + "/" + GcCode.substring(0, 4); if (!FileIO.DirectoryExists(directory)) continue; FileHandle dir = new FileHandle(directory); FileHandle[] files = dir.list(); for (int i = 0; i < files.length; i++) { // simplyfied for startswith gccode, thumbs_gccode + ooverwiewthumbs_gccode if (!files[i].name().toLowerCase().contains(GcCode)) continue; String filename = directory + "/" + files[i].name(); FileHandle file = new FileHandle(filename); if (file.exists()) { if (!file.delete()) Log.err(log, "Error deleting : " + filename); }// w w w .j a va 2s. c om } } }
From source file:CB_Translation_Base.TranslationEngine.Translation.java
License:Open Source License
private ArrayList<Lang> getLangs(String FilePath) { ArrayList<Lang> Temp = new ArrayList<Lang>(); FileHandle Dir = Gdx.files.getFileHandle(FilePath, mFiletype); final FileHandle[] files; if (Dir.type() == FileType.Classpath) { // Cannot list a classpath directory // so we hardcoded the lang path files = new FileHandle[] { // Gdx.files.classpath("data/lang/cs"), // Gdx.files.classpath("data/lang/de"), // Gdx.files.classpath("data/lang/en-GB"), // Gdx.files.classpath("data/lang/fr"), // Gdx.files.classpath("data/lang/hu"), // Gdx.files.classpath("data/lang/nl"), // Gdx.files.classpath("data/lang/pl"), // Gdx.files.classpath("data/lang/pt-PT"),// };/*w ww. j a va2s .co m*/ } else { files = Dir.list(); } for (FileHandle tmp : files) { try { String stringFile = tmp + "/strings.ini"; FileHandle langFile = Gdx.files.getFileHandle(stringFile, mFiletype); if (langFile.exists()) { String tmpName = getLangNameFromFile(stringFile); Temp.add(new Lang(tmpName, stringFile)); } } catch (IOException e) { e.printStackTrace(); } } return Temp; }
From source file:com.andgate.ikou.io.LevelDatabaseService.java
License:Open Source License
public static LevelData[] getOldLevelDatas() { ProgressDatabase progressDB = ProgressDatabaseService.read(); FileHandle[] levelsDirFolders = Gdx.files.internal(Constants.LEVELS_INTERNAL_PATH + "old/").list(); LevelData[] levels = new LevelData[levelsDirFolders.length]; for (int i = 0; i < levelsDirFolders.length; i++) { FileHandle level = levelsDirFolders[i]; if (level.isDirectory()) { String levelName = level.name(); int totalFloors = level.list().length; int completedFloors = progressDB.getFloorsCompleted(levelName); levels[i] = new LevelData(levelName, totalFloors, completedFloors); }//from w ww. ja v a2s . co m } return levels; }
From source file:com.android.ringfly.common.Assets.java
License:Apache License
/** * /*from w ww .j a v a 2 s . c om*/ * * @return */ private static float calculatePixelDensity() { FileHandle textureDir = Gdx.files.internal("data/textures"); FileHandle[] availableDensities = textureDir.list(); FloatArray densities = new FloatArray(); for (int i = 0; i < availableDensities.length; i++) { try { float density = Float.parseFloat(availableDensities[i].name()); densities.add(density); } catch (NumberFormatException ex) { // Ignore anything non-numeric, such as ".svn" folders. } } densities.shrink(); // Remove empty slots to get rid of zeroes. densities.sort(); // Now the lowest density comes first. return CameraHelper.bestDensity(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, densities.items); }
From source file:com.badlogic.gdx.spriter.demo.SpriterDemoUtils.java
static void findFiles(Array<FileHandle> files, FileHandle fileHandle, String[] acceptedExtensions) { if (fileHandle.isDirectory()) { for (FileHandle child : fileHandle.list()) findFiles(files, child, acceptedExtensions); } else {//from ww w . j a v a 2 s .co m String extension = fileHandle.extension(); for (String acceptedExtension : acceptedExtensions) { if (acceptedExtension.equalsIgnoreCase(extension)) { files.add(fileHandle); break; } } } }
From source file:com.badlogic.gdx.tests.utils.AssetsFileGenerator.java
License:Apache License
private static final void traverse(FileHandle directory, String base, StringBuffer list) { if (directory.name().equals(".svn")) return;//from w w w .j a v a 2 s . c o m String dirName = directory.toString().replace("\\", "/").replace(base, "") + "/"; System.out.println(dirName); for (FileHandle file : directory.list()) { if (file.isDirectory()) { traverse(file, base, list); } else { String fileName = file.toString().replace("\\", "/").replace(base, ""); if (fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".jpeg")) { list.append("i:" + fileName + "\n"); System.out.println(fileName); } else if (fileName.endsWith(".glsl") || fileName.endsWith(".fnt") || fileName.endsWith(".pack") || fileName.endsWith(".obj") || file.extension().equals("") || fileName.endsWith("txt")) { list.append("t:" + fileName + "\n"); System.out.println(fileName); } else { if (fileName.endsWith(".mp3") || fileName.endsWith(".ogg") || fileName.endsWith(".wav")) continue; list.append("b:" + fileName + "\n"); System.out.println(fileName); } } } }
From source file:com.badlydrawngames.veryangryrobots.Assets.java
License:Apache License
private static float calculatePixelDensity() { FileHandle textureDir = Gdx.files.internal("data/textures"); FileHandle[] availableDensities = textureDir.list(); FloatArray densities = new FloatArray(); for (int i = 0; i < availableDensities.length; i++) { try {//from w ww. ja v a2 s . c o m float density = Float.parseFloat(availableDensities[i].name()); densities.add(density); } catch (NumberFormatException ex) { // Ignore anything non-numeric, such as ".svn" folders. } } densities.shrink(); // Remove empty slots to get rid of zeroes. densities.sort(); // Now the lowest density comes first. return CameraHelper.bestDensity(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, densities.items); }
From source file:com.badlydrawngames.veryangryrobots.Assets.java
License:Apache License
private static Sound[] loadSounds(String dir) { FileHandle dh = Gdx.files.internal("data/sounds/" + dir); FileHandle[] fhs = dh.list(); List<Sound> sounds = new ArrayList<Sound>(); for (int i = 0; i < fhs.length; i++) { String name = fhs[i].name(); if (name.endsWith(".ogg")) { sounds.add(loadSound(dir + "/" + name)); }/*from w ww . j ava 2 s .c om*/ } Sound[] result = new Sound[0]; return sounds.toArray(result); }