Java Code Examples for com.badlogic.gdx.files.FileHandle#list()
The following examples show how to use
com.badlogic.gdx.files.FileHandle#list() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileChooser.java From gdx-soundboard with MIT License | 6 votes |
private void changeDirectory(FileHandle directory) { currentDir = directory; fileListLabel.setText(currentDir.path()); final Array<FileListItem> items = new Array<FileListItem>(); final FileHandle[] list = directory.list(filter); for (final FileHandle handle : list) { items.add(new FileListItem(handle)); } items.sort(dirListComparator); if (directory.file().getParentFile() != null) { items.insert(0, new FileListItem("..", directory.parent())); } fileList.setSelected(null); fileList.setItems(items); }
Example 2
Source File: LegacyCompareTest.java From talos with Apache License 2.0 | 5 votes |
private void traverseFolder (FileHandle folder, Array<String> fileList, String extension, int depth) { for (FileHandle file : folder.list()) { if (file.isDirectory() && depth < 10) { traverseFolder(file, fileList, extension, depth + 1); } if (file.extension().equals(extension)) { fileList.add(file.path()); } } }
Example 3
Source File: BatchConvertDialog.java From talos with Apache License 2.0 | 5 votes |
private void traverseFolder(FileHandle folder, Array<String> fileList, String extension, int depth) { for(FileHandle file : folder.list()) { if(file.isDirectory() && depth < 10) { traverseFolder(file, fileList, extension, depth + 1); } if(file.extension().equals(extension)) { fileList.add(file.path()); } } }
Example 4
Source File: GameLevels.java From uracer-kotd with Apache License 2.0 | 5 votes |
public static final boolean init () { // setup map loader mapLoaderParams.forceTextureFilters = true; mapLoaderParams.textureMinFilter = TextureFilter.Linear; mapLoaderParams.textureMagFilter = TextureFilter.Linear; mapLoaderParams.yUp = false; // check invalid FileHandle dirLevels = Gdx.files.internal(Storage.Levels); if (dirLevels == null || !dirLevels.isDirectory()) { throw new URacerRuntimeException("Path not found (" + Storage.Levels + "), cannot check for available game levels."); } // check for any level FileHandle[] tracks = dirLevels.list("tmx"); if (tracks.length == 0) { throw new URacerRuntimeException("Cannot find game levels."); } // build internal maps for (int i = 0; i < tracks.length; i++) { GameLevelDescriptor desc = computeDescriptor(tracks[i].name()); levels.add(desc); // build lookup table levelIdToDescriptor.put(desc.getId(), desc); Gdx.app.log("GameLevels", "Found level \"" + desc.getName() + "\" (" + desc.getId() + ")"); } // sort tracks Collections.sort(levels); return true; }
Example 5
Source File: InstallationTable.java From skin-composer with MIT License | 5 votes |
private Array<FileHandle> findFilesRecursively(FileHandle begin, Array<FileHandle> handles) { var newHandles = begin.list(); for (var f : newHandles) { if (f.isDirectory()) { findFilesRecursively(f, handles); } else { handles.add(f); } } return handles; }
Example 6
Source File: WorldIO.java From TerraLegion with MIT License | 5 votes |
public static LoadedWorldInfo loadWorld(World world) { String basePath = "worlds/" + world.getWorldName(); FileHandle baseDir = Gdx.files.external(basePath); if (baseDir.exists()) { FileHandle worldDef = Gdx.files.external(basePath + "/world.save"); String[] lines = worldDef.readString().split("\n"); //Load seed long seed = Long.parseLong(lines[0]); //Load Chunk Dimensions String[] dim = lines[1].split(" "); int worldChunkSizeWidth = Integer.parseInt(dim[0]); int worldChunkSizeHeight = Integer.parseInt(dim[1]); //Load player Player player = loadPlayer(); LoadedWorldInfo worldInfo = new LoadedWorldInfo(player, seed, worldChunkSizeWidth, worldChunkSizeHeight); //Go through directory and find all chunks. Load them. for (FileHandle handle : baseDir.list()) { if (handle.name().startsWith("chunk")) { String[] chunkName = handle.name().split("chunk"); String[] chunkPos = chunkName[1].replace(".save", "").split("_"); int x = Integer.parseInt(chunkPos[0]); int y = Integer.parseInt(chunkPos[1]); Chunk chunk = loadChunk(world, handle, x, y); world.getChunkManager().setChunk(chunk, x, y); } } return worldInfo; } return null; }
Example 7
Source File: ClassFinder.java From libgdx-snippets with MIT License | 5 votes |
private void processDirectory(FileHandle root, FileHandle directory, Predicate<String> filter, Consumer<Class<?>> processor) { FileHandle[] files = directory.list(); for (FileHandle file : files) { if (file.isDirectory()) { processDirectory(root, new FileHandle(new File(directory.file(), file.name())), filter, processor); } else { process(root, file, filter, processor); } } }
Example 8
Source File: FormValidator.java From vis-ui with Apache License 2.0 | 5 votes |
@Override protected boolean validate (String input) { FileHandle file = Gdx.files.absolute(input); if (file.exists() == false || file.isDirectory() == false) return false; if (mustBeEmpty) { return file.list().length == 0; } else { return file.list().length != 0; } }
Example 9
Source File: ClientSaveManager.java From Cubes with MIT License | 5 votes |
public static Save[] getSaves() { FileHandle clientSavesFolder = getSavesFolder(); if (!clientSavesFolder.isDirectory()) return new Save[0]; FileHandle[] list = clientSavesFolder.list(); Save[] saves = new Save[list.length]; for (int i = 0; i < list.length; i++) { saves[i] = new Save(list[i].name(), list[i]); } return saves; }
Example 10
Source File: ModInputStream.java From Cubes with MIT License | 5 votes |
public FolderModInputStream(FileHandle file) { root = file; for (FileHandle f : file.list()) { if (f.isDirectory()) { folders.add(f); } else { files.add(f); } } }
Example 11
Source File: ModInputStream.java From Cubes with MIT License | 5 votes |
@Override public ModFile getNextModFile() throws IOException { FileHandle file = files.pollFirst(); if (file != null) return new FolderModFile(file); FileHandle folder = folders.pollFirst(); if (folder == null) return null; for (FileHandle f : folder.list()) { if (f.isDirectory()) { folders.add(f); } else { files.add(f); } } return new FolderModFile(folder); }
Example 12
Source File: SinglePlayer.java From uracer-kotd with Apache License 2.0 | 4 votes |
/** Load from disk all the replays for the specified trackId, pruning while loading respecting the ReplayManager.MaxReplays * constant. Any previous Replay will be cleared from the lapManager instance. */ private int loadReplaysFromDiskFor (String trackId) { lapManager.removeAllReplays(); int reloaded = 0; for (FileHandle userdir : Gdx.files.external(Storage.ReplaysRoot + gameWorld.getLevelId()).list()) { if (userdir.isDirectory()) { for (FileHandle userreplay : userdir.list()) { Replay replay = Replay.load(userreplay.path()); if (replay != null) { // add replays even if slower ReplayResult ri = lapManager.addReplay(replay); if (ri.is_accepted) { ReplayUtils.pruneReplay(ri.pruned); // prune if needed reloaded++; Gdx.app.log("SinglePlayer", "Loaded replay #" + ri.accepted.getShortId()); } else { String msg = ""; switch (ri.reason) { case Null: msg = "null replay (" + userreplay.path() + ")"; break; case InvalidMinDuration: msg = "invalid lap (" + ri.discarded.getSecondsStr() + "s < " + GameplaySettings.ReplayMinDurationSecs + "s) (#" + ri.discarded.getShortId() + ")"; break; case Invalid: msg = "the specified replay is not valid. (" + userreplay.path() + ")"; break; case WrongTrack: msg = "the specified replay belongs to another game track (#" + ri.discarded.getShortId() + ")"; break; case Slower: msg = "too slow! (#" + ri.discarded.getShortId() + ")"; ReplayUtils.pruneReplay(ri.discarded); break; case Accepted: break; } Gdx.app.log("SinglePlayer", "Discarded at loading time, " + msg); } } } } } Gdx.app.log("SinglePlayer", "Building opponents list:"); rebindAllReplays(); int pos = 1; for (Replay r : lapManager.getReplays()) { Gdx.app.log("SinglePlayer", "#" + pos + ", #" + r.getShortId() + ", secs=" + r.getSecondsStr() + ", ct=" + r.getCreationTimestamp()); pos++; } Gdx.app.log("SinglePlayer", "Reloaded " + reloaded + " opponents."); return reloaded; }
Example 13
Source File: JsonData.java From skin-composer with MIT License | 4 votes |
@Override public void read(Json json, JsonValue jsonData) { try { colors = json.readValue("colors", Array.class, jsonData); fonts = json.readValue("fonts", Array.class, jsonData); freeTypeFonts = json.readValue("freeTypeFonts", Array.class, new Array<FreeTypeFontData>(),jsonData); FileHandle previewFontsPath = Main.appFolder.child("preview fonts"); var fontsList = previewFontsPath.list(); for (var freeTypeFont : freeTypeFonts) { if (freeTypeFont.previewTTF != null) { boolean foundMatch = false; for (var previewFile : fontsList) { if (freeTypeFont.previewTTF.equals(previewFile.nameWithoutExtension())) { foundMatch = true; break; } } if (!foundMatch) { freeTypeFont.previewTTF = previewFontsPath.list()[0].nameWithoutExtension(); } } } classStyleMap = new OrderedMap<>(); for (JsonValue data : jsonData.get("classStyleMap").iterator()) { classStyleMap.put(ClassReflection.forName(data.name), json.readValue(Array.class, data)); } for (Array<StyleData> styleDatas : classStyleMap.values()) { for (StyleData styleData : styleDatas) { styleData.jsonData = this; } } customClasses = json.readValue("customClasses", Array.class, CustomClass.class, new Array<>(), jsonData); for (CustomClass customClass : customClasses) { customClass.setMain(main); } } catch (ReflectionException e) { Gdx.app.log(getClass().getName(), "Error parsing json data during file read", e); main.getDialogFactory().showDialogError("Error while reading file...", "Error while attempting to read save file.\nPlease ensure that file is not corrupted.\n\nOpen error log?"); } }
Example 14
Source File: MenuBar.java From gdx-skineditor with Apache License 2.0 | 4 votes |
protected void showExportDialog() { final Preferences prefs = Gdx.app.getPreferences("skin_editor_project_" + game.screenMain.getcurrentProject()); final TextField textDirectory = new TextField(prefs.getString("export_to_directory"),game.skin); Dialog dlg = new Dialog("Export to Directory", game.skin) { @Override protected void result(Object object) { if ((Boolean) object == true) { if (textDirectory.getText().isEmpty() == true) { game.showNotice("Warning", "Directory field is empty!", game.screenMain.stage); return; } FileHandle targetDirectory = new FileHandle(textDirectory.getText()); if (targetDirectory.exists() == false) { game.showNotice("Warning", "Directory not found!", game.screenMain.stage); return; } // Copy uiskin.* and *.fnt FileHandle projectFolder = Gdx.files.local("projects").child(game.screenMain.getcurrentProject()); for(FileHandle file : projectFolder.list()) { if (file.name().startsWith("uiskin.") || (file.extension().equalsIgnoreCase("fnt"))) { Gdx.app.log("MenuBar","Copying file: " + file.name() + " ..."); FileHandle target = targetDirectory.child(file.name()); file.copyTo(target); } } game.showNotice("Operation Completed", "Project successfully exported!", game.screenMain.stage); } } }; dlg.pad(20); Table table = dlg.getContentTable(); table.padTop(20); table.add("Directory:"); table.add(textDirectory).width(320); TextButton buttonChoose = new TextButton("...", game.skin); buttonChoose.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { // Need to steal focus first with this hack (Thanks to Z-Man) Frame frame = new Frame(); frame.setUndecorated(true); frame.setOpacity(0); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.toFront(); frame.setVisible(false); frame.dispose(); JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int ret = chooser.showOpenDialog(null); if (ret == JFileChooser.APPROVE_OPTION) { File f = chooser.getSelectedFile(); textDirectory.setText(f.getAbsolutePath()); // Store to file prefs.putString("export_to_directory", f.getAbsolutePath()); prefs.flush(); } } }); table.add(buttonChoose); table.row(); table.padBottom(20); dlg.button("Export", true); dlg.button("Cancel", false); dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true); dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false); dlg.show(getStage()); }