List of usage examples for com.badlogic.gdx.files FileHandle list
public FileHandle[] list(String suffix)
From source file:com.agateau.pixelwheels.tools.MapScreenshotGenerator.java
License:Apache License
public static void main(String[] args) { new CommandLineApplication("MapScreenshotGenerator", args) { @Override//from ww w. ja v a 2 s . c o m int run(String[] arguments) { if (arguments.length == 2) { String shotFileName = arguments[0]; String tmxFileName = arguments[1]; processFile(shotFileName, tmxFileName); } else { FileHandle tmxDir = Gdx.files.absolute("android/assets/maps"); FileHandle shotDir = Gdx.files.absolute("core/assets/ui/map-screenshots"); for (FileHandle tmxFile : tmxDir.list(".tmx")) { String shotFileName = shotDir.path() + "/" + tmxFile.nameWithoutExtension() + ".png"; processFile(shotFileName, tmxFile.path()); } } return 0; } }; }
From source file:com.dongbat.invasion.registry.AtlasRegistry.java
public static void load() { FileHandle internal = Gdx.files.internal("./atlas"); for (FileHandle file : internal.list(".atlas")) { String name = file.nameWithoutExtension(); registry.put(name, new TextureAtlas(file)); }/*from w ww . ja v a 2 s.c om*/ SkeletonJson json; for (FileHandle file : internal.list(".json")) { String name = file.nameWithoutExtension(); TextureAtlas atlas = getAtlas(name); if (atlas != null) { json = new SkeletonJson(atlas); // TODO scale for each enemy type or base on size json.setScale(0.5f); SkeletonData ske = json.readSkeletonData(file); skeReg.put(name, ske); } } }
From source file:com.kotcrab.vis.editor.module.editor.PluginLoaderModule.java
License:Apache License
private void loadPluginsDescriptors(Array<FileHandle> pluginsFolders) throws IOException { for (FileHandle folder : pluginsFolders) { FileHandle[] files = folder.list((dir, name) -> name.endsWith("jar")); if (files.length > 1 || files.length == 0) { Log.error(TAG, "Failed (invalid directory structure): " + folder.name()); failedPlugins.add(new FailedPluginDescriptor(folder, new IllegalStateException( "Plugin directory must contain only one jar (required libs must be stored in 'lib' subdirectory"))); continue; }//w w w . j a v a 2s .c o m FileHandle pluginJar = files[0]; try { JarInputStream jarStream = new JarInputStream(new FileInputStream(pluginJar.file())); Manifest mf = jarStream.getManifest(); jarStream.close(); PluginDescriptor desc = new PluginDescriptor(pluginJar, mf); allPlugins.add(desc); } catch (IOException e) { Log.error(TAG, "Failed (IO exception): " + folder.name()); failedPlugins.add(new FailedPluginDescriptor(folder, e)); Log.exception(e); } catch (EditorException e) { Log.error(TAG, "Failed: " + folder.name()); failedPlugins.add(new FailedPluginDescriptor(folder, e)); Log.exception(e); } } }
From source file:com.kotcrab.vis.editor.module.project.assetsmanager.AssetsUIModule.java
License:Apache License
public void changeCurrentDirectory(FileHandle directory, HistoryPolicy historyPolicy) { clearSelection();//from ww w. j ava 2 s. c o m if (historyPolicy == HistoryPolicy.ADD) fileHistoryManager.historyAdd(); this.currentDirectory = directory; if (metadata != null) metadata.lastDirectory = directory.path(); mainFilesView.clearChildren(); miscFilesView.clearChildren(); updateContextGeneratorContainer(directory); currentDirectoryDescriptor = assetsMetadata.getAsDirectoryDescriptorRecursively(directory); if (currentDirectory.equals(assetsFolder)) navigateToParentButton.setDisabled(true); else navigateToParentButton.setDisabled(false); FileHandle[] files = directory.list(file -> { if (searchField.getText().equals("")) return true; return file.getName().contains(searchField.getText()); }); fileSorter = null; String relativePath = fileAccess.relativizeToAssetsFolder(directory); for (AssetsFileSorter sorter : extensionStorage.getAssetsFileSorters()) { if (sorter.isSupported(assetsMetadata, directory, relativePath)) { fileSorter = sorter; break; } } Array<FileHandle> sortedFiles = FileUtils.sortFiles(files); filesDisplayed = 0; boolean miscFileViewUsed = false; boolean mainFileViewUsed = false; for (FileHandle file : sortedFiles) { String ext = file.extension(); if (file.name().equals(".vis")) continue; if (relativePath.startsWith("atlas") && (ext.equals("png") || ext.equals("jpg") || ext.equals("jpeg"))) continue; boolean isMain = fileSorter == null ? true : fileSorter.isMainFile(file); FileItem item = createFileItem(file, isMain); if (isMain) { mainFilesView.addActor(item); mainFileViewUsed = true; } else { miscFilesView.addActor(item); miscFileViewUsed = true; } filesDisplayed++; } assetDragAndDrop.rebuild(mainFilesView.getChildren(), miscFilesView.getChildren(), atlasViews.values()); filesView.clearChildren(); filesView.top(); ScrollPaneScrollWidthValue scrollWidthValue = new ScrollPaneScrollWidthValue(filesViewScrollPane); if (miscFileViewUsed) { if (mainFileViewUsed) { filesView.add(mainFilesView).width(scrollWidthValue).growX(); filesView.row(); } filesView.add(new VisLabel("Other files")).padLeft(mainFilesView.getSpacing()).left().row(); filesView.add(miscFilesView).width(scrollWidthValue).growX(); } else { filesView.add(mainFilesView).width(scrollWidthValue).growX(); } String currentPath = directory.path().substring(visFolder.path().length() + 1); contentTitleLabel.setText("Content [" + currentPath + "]"); if (currentDirectoryDescriptor != null) { dirDescriptorTitleLabel.setText("[" + currentDirectoryDescriptor.getUIName() + "]"); } else { dirDescriptorTitleLabel.setText(""); } highlightDir(directory); if (historyPolicy == HistoryPolicy.CLEAR) fileHistoryManager.historyClear(); }
From source file:com.kotcrab.vis.editor.module.project.assetsmanager.AssetsUIModule.java
License:Apache License
private void processFolder(Node node, FileHandle dir) { FileHandle[] files = dir.list(DirectoriesOnlyFileFilter.FILTER); for (FileHandle file : files) { if (file.name().startsWith(".")) continue; //hide folders starting with dot Node currentNode = new Node(new FolderItem(file)); node.add(currentNode);// w w w .java 2 s . c o m processFolder(currentNode, file); } }
From source file:com.kotcrab.vis.ui.widget.file.internal.DirsSuggestionPopup.java
License:Apache License
private void createDirSuggestions(final Stage stage, final float width) { final String pathFieldText = pathField.getText(); //quiet period before listing files takes too long and popup will be removed addAction(Actions.sequence(Actions.delay(0.2f, Actions.removeActor()))); if (listDirFuture != null) listDirFuture.cancel(true);// ww w . j a va 2s . c o m listDirFuture = listDirExecutor.submit(new Runnable() { @Override public void run() { FileHandle enteredDir = Gdx.files.absolute(pathFieldText); final FileHandle listDir; final String partialPath; if (enteredDir.exists()) { listDir = enteredDir; partialPath = ""; } else { listDir = enteredDir.parent(); partialPath = enteredDir.name(); } final FileHandle[] files = listDir.list(chooser.getFileFilter()); if (Thread.currentThread().isInterrupted()) return; Gdx.app.postRunnable(new Runnable() { @Override public void run() { clearChildren(); clearActions(); int suggestions = 0; for (final FileHandle file : files) { if (file.exists() == false || file.isDirectory() == false) continue; if (file.name().startsWith(partialPath) == false || file.name().equals(partialPath)) continue; MenuItem item = createMenuItem(file.path()); item.getLabel().setEllipsis(true); item.getLabelCell().width(width - 20); addItem(item); item.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { chooser.setDirectory(file, FileChooser.HistoryPolicy.ADD); } }); suggestions++; if (suggestions == MAX_SUGGESTIONS) { break; } } if (suggestions == 0) { remove(); return; } showMenu(stage, pathField); setWidth(width); layout(); } }); } }); }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
License:Apache License
private void checkForConsistancy() { // check if current project requires cleanup // Cleanup unused meshes // 1. open all scenes make list of mesh_id's and then remove all unused meshes HashSet<String> uniqueMeshIds = new HashSet<String>(); FileHandle sourceDir = new FileHandle(currentWorkingPath + "/" + currentProjectVO.projectName + "/scenes/"); for (FileHandle entry : sourceDir.list(Overlap2DUtils.DT_FILTER)) { if (!entry.file().isDirectory()) { Json json = new Json(); json.setIgnoreUnknownFields(true); SceneVO sceneVO = json.fromJson(SceneVO.class, entry); if (sceneVO.composite == null) continue; ArrayList<MainItemVO> items = sceneVO.composite.getAllItems(); for (CompositeItemVO libraryItem : currentProjectInfoVO.libraryItems.values()) { if (libraryItem.composite == null) continue; items = libraryItem.composite.getAllItems(); }/*from ww w. ja va2 s . c om*/ } } }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
License:Apache License
public void importSpriteAnimationsIntoProject(final Array<FileHandle> fileHandles, ProgressHandler progressHandler) { if (fileHandles == null) { return;/* w w w. j av a 2 s. c o m*/ } handler = progressHandler; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { String newAnimName = null; String rawFileName = fileHandles.get(0).name(); String fileExtension = FilenameUtils.getExtension(rawFileName); if (fileExtension.equals("png")) { Settings settings = new Settings(); settings.square = true; settings.flattenPaths = true; TexturePacker texturePacker = new TexturePacker(settings); FileHandle pngsDir = new FileHandle(fileHandles.get(0).parent().path()); for (FileHandle entry : pngsDir.list(Overlap2DUtils.PNG_FILTER)) { texturePacker.addImage(entry.file()); } String fileNameWithoutExt = FilenameUtils.removeExtension(rawFileName); String fileNameWithoutFrame = fileNameWithoutExt.replaceAll("\\d*$", ""); String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutFrame; File targetDir = new File(targetPath); if (targetDir.exists()) { try { FileUtils.deleteDirectory(targetDir); } catch (IOException e) { e.printStackTrace(); } } texturePacker.pack(targetDir, fileNameWithoutFrame); newAnimName = fileNameWithoutFrame; } else { for (FileHandle fileHandle : fileHandles) { try { Array<File> imgs = getAtlasPages(fileHandle); String fileNameWithoutExt = FilenameUtils.removeExtension(fileHandle.name()); String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutExt; File targetDir = new File(targetPath); if (targetDir.exists()) { FileUtils.deleteDirectory(targetDir); } for (File img : imgs) { FileUtils.copyFileToDirectory(img, targetDir); } FileUtils.copyFileToDirectory(fileHandle.file(), targetDir); newAnimName = fileNameWithoutExt; } catch (IOException e) { e.printStackTrace(); } } } if (newAnimName != null) { ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME); resolutionManager.resizeSpriteAnimationForAllResolutions(newAnimName, currentProjectInfoVO); } }); executor.execute(() -> { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); }); executor.shutdown(); }
From source file:com.o2d.pkayjava.editor.proxy.ResolutionManager.java
License:Apache License
private int resizeTextures(String path, ResolutionEntryVO resolution) { ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME); float ratio = getResolutionRatio(resolution, projectManager.getCurrentProjectInfoVO().originalResolution); FileHandle targetDir = new FileHandle(path); FileHandle[] entries = targetDir.list(Overlap2DUtils.PNG_FILTER); float perResizePercent = 95.0f / entries.length; int resizeWarnings = 0; for (FileHandle entry : entries) { try {//from w ww. j a v a2s . c o m File file = entry.file(); File destinationFile = new File(path + "/" + file.getName()); BufferedImage resizedImage = ResolutionManager.imageResize(file, ratio); if (resizedImage == null) { resizeWarnings++; ImageIO.write(ImageIO.read(file), "png", destinationFile); } else { ImageIO.write(ResolutionManager.imageResize(file, ratio), "png", destinationFile); } } catch (IOException e) { e.printStackTrace(); } changePercentBy(perResizePercent); } return resizeWarnings; }
From source file:com.o2d.pkayjava.editor.proxy.ResolutionManager.java
License:Apache License
private void copyTexturesFromTo(String fromPath, String toPath) { FileHandle sourceDir = new FileHandle(fromPath); FileHandle[] entries = sourceDir.list(Overlap2DUtils.PNG_FILTER); float perCopyPercent = 10.0f / entries.length; for (FileHandle entry : entries) { File file = entry.file(); String filename = file.getName(); File target = new File(toPath + "/" + filename); try {//from w w w .j av a 2 s .c om FileUtils.copyFile(file, target); } catch (IOException e) { e.printStackTrace(); } } changePercentBy(perCopyPercent); }