List of usage examples for com.badlogic.gdx.files FileHandle file
File file
To view the source code for com.badlogic.gdx.files FileHandle file.
Click Source Link
From source file:com.a2client.Cursor.java
License:Open Source License
public void setCursor(String name) { if (Utils.isEmpty(name)) name = "arrow"; FileHandle file = Gdx.files.internal(CURSORS_DIR + name + ".png"); if (!file.file().exists()) { setCursor(""); return;/*ww w .j ava 2s . co m*/ } CursorData fd = null; for (CursorData data : _cursors) { if (data.name.equalsIgnoreCase(name)) { fd = data; } } Pixmap pm = new Pixmap(file); com.badlogic.gdx.graphics.Cursor cursor = Gdx.graphics.newCursor(pm, fd != null ? fd.x : 0, fd != null ? fd.y : 0); Gdx.graphics.setCursor(cursor); pm.dispose(); }
From source file:com.badlogic.gdx.spriter.demo.SpriterDemoFileHandle.java
public SpriterDemoFileHandle(FileHandle handle, AssetManager manager) { super(handle.file()); this.manager = manager; String[] parts = path().split("/"); int count = parts.length; this.displayString = count > 1 ? parts[count - 2] + "/" + parts[count - 1] : parts[count - 1]; }
From source file:com.bagon.matchteam.mtx.managers.FileManager.java
License:Apache License
/** * Write new lines in text file/* w w w. ja v a2 s .c om*/ * * @param strFile * file to write * @param value * value to write to new line * @param fileType * the type of file to retrieve file (INTERNAL, LOCAL, EXTERNAL) * */ public static void writeLine(String strFile, String value, FileType fileType) { try { FileHandle file = getFile(strFile, fileType); FileWriter fw = new FileWriter(file.file(), true); BufferedWriter bw = new BufferedWriter(fw); bw.write(value); bw.newLine(); bw.close(); MtxLogger.log(logActive, true, logTag, "Write New Line: File: " + strFile + ", value: " + value); } catch (IOException e) { MtxLogger.log(logActive, true, logTag, "CANT WRITE LINE: File: " + strFile); e.printStackTrace(); } }
From source file:com.bagon.matchteam.mtx.managers.FileManager.java
License:Apache License
/** * Re-Write an existing line in a text file without effecting other lines * /* w ww .j a v a2 s. com*/ * @param strFile * file to write * @param lineNumber * line number to write * @param newValue * the new value to write over existing line * @param fileType * the type of file to retrieve file (INTERNAL, LOCAL, EXTERNAL) * */ public static void writeExistingLine(String strFile, int lineNumber, String newValue, FileType fileType) { try { FileHandle file = getFile(strFile, fileType); ArrayList<String> lineByLineTextList = getUpdatedTextInfo(strFile, lineNumber, newValue); FileWriter fw = new FileWriter(file.file(), false); BufferedWriter bw = new BufferedWriter(fw); for (int i = 0; i < lineByLineTextList.size(); i++) { if (lineByLineTextList.get(i) != null) { bw.write(lineByLineTextList.get(i)); bw.newLine(); } } bw.close(); } catch (IOException e) { MtxLogger.log(logActive, true, logTag, "CANT WRITE LINE: File: " + strFile + ", Line Number: " + lineNumber); e.printStackTrace(); } }
From source file:com.blastedstudios.gdxworld.util.ui.TreeFileChooser.java
License:Apache License
/** creates an anonymous subclass of {@link Node} that recursively adds the children of the given file to it when being {@link Node#setExpanded(boolean) expanded} for the first time * @param file the file to put in {@link Node#setObject(Object)} * @param filter Filters children from being added. May be null to accept all files. * @param labelSupplier supplies labels to use * @param nodeConsumer Does something with nodes after they were created. May be null. * @return the created Node *//*from w w w. jav a 2 s. co m*/ public static Node fileNode(final FileHandle file, final FileFilter filter, final Accessor<Label, FileHandle> labelSupplier, final Accessor<Void, Node> nodeConsumer) { Label label = labelSupplier.access(file); Node node; if (file.isDirectory()) { final Node dummy = new Node(new Actor()); node = new Node(label) { private boolean childrenAdded; @Override public void setExpanded(boolean expanded) { if (expanded == isExpanded()) return; if (expanded && !childrenAdded) { if (filter != null) for (File child : file.file().listFiles(filter)) add(fileNode(file.child(child.getName()), filter, labelSupplier, nodeConsumer)); else for (FileHandle child : file.list()) add(fileNode(child, filter, labelSupplier, nodeConsumer)); childrenAdded = true; remove(dummy); } super.setExpanded(expanded); } }; node.add(dummy); if (nodeConsumer != null) nodeConsumer.access(dummy); } else node = new Node(label); node.setObject(file); if (nodeConsumer != null) nodeConsumer.access(node); return node; }
From source file:com.forerunnergames.peril.client.assets.LocalAssetUpdater.java
License:Open Source License
@Override public void updateAssets() { if (!AssetSettings.UPDATE_ASSETS) { log.warn("Assets are not being updated.\nTo change this behavior, change {} in {} from false to true.\n" + "Make sure to back up any customizations you made to any assets first, as your changes " + "will be overwritten.", ClientApplicationProperties.UPDATE_ASSETS_KEY, ClientApplicationProperties.PROPERTIES_FILE_PATH_AND_NAME); return;/*from w ww . j a va2 s . c om*/ } assetUpdatingFuture = executorService.submit(new Runnable() { @Override public void run() { final FileHandle destAssetsDir = Gdx.files .external(AssetSettings.RELATIVE_EXTERNAL_ASSETS_DIRECTORY); try { final FileHandle sourceAssetsDir = Gdx.files .absolute(AssetSettings.ABSOLUTE_UPDATED_ASSETS_LOCATION); log.info("Attempting to update assets in [{}] from [{}]...", destAssetsDir.file(), sourceAssetsDir); if (Thread.currentThread().isInterrupted()) { log.warn("Asset updating was cancelled before beginning."); return; } log.info("Removing old assets..."); destAssetsDir.deleteDirectory(); if (Thread.currentThread().isInterrupted()) { log.warn( "Asset updating was cancelled after removing old assets, but before copying new assets."); return; } log.info("Copying new assets..."); sourceAssetsDir.copyTo(destAssetsDir); log.info("Successfully updated assets."); } catch (final Exception e) { final String errorMessage = "Failed to update assets from: [" + AssetSettings.ABSOLUTE_UPDATED_ASSETS_LOCATION + "].\n" + "Make sure that " + ClientApplicationProperties.UPDATED_ASSETS_LOCATION_KEY + " is properly set in [" + ClientApplicationProperties.PROPERTIES_FILE_PATH_AND_NAME + "].\n" + "Also, " + ClientApplicationProperties.UPDATE_ASSETS_KEY + " must be set to true (in the same file) the first time you run the game.\n" + "If you already tried all of that, you can set " + ClientApplicationProperties.UPDATE_ASSETS_KEY + " to false.\nIn that case, you still need to make sure that you have a copy of all assets in " + destAssetsDir.file() + ".\n\n" + "Nerdy developer details:\n"; log.error(errorMessage, e); throw new RuntimeException(errorMessage, e); } } }); }
From source file:com.forerunnergames.peril.client.assets.MultiSourceAssetManager.java
License:Open Source License
@Override @SuppressWarnings("rawtypes") public synchronized <T> void load(final String fileName, final Class<T> type, @Nullable final AssetLoaderParameters<T> parameters) { Arguments.checkIsNotNull(fileName, "fileName"); Arguments.checkIsNotNull(type, "type"); for (final com.badlogic.gdx.assets.AssetManager assetManager : libGdxAssetManagers) { String resolvedPathDescription = "?"; try {/*from www . j a v a 2s .c o m*/ final AssetLoader loader = assetManager.getLoader(type); if (loader == null) continue; final FileHandle fileHandle = loader.resolve(fileName); final File file = fileHandle.file(); if (fileHandle.type() == Files.FileType.Internal && !file.exists()) { resolvedPathDescription = "classpath:/" + fileHandle.path(); } else { resolvedPathDescription = file.getAbsolutePath(); } log.debug("Queuing asset [{}] for loading as [{}]...", fileName, resolvedPathDescription); if (!fileHandle.exists()) { log.debug("Failed (file doesn't exist)."); continue; } assetManager.load(fileName, type, parameters); fileNamesToManagers.put(fileName, assetManager); log.debug("Success."); return; } catch (final GdxRuntimeException e) { log.error("Cannot queue asset [{}] for loading as [{}]. Reason:\n\n{}", fileName, resolvedPathDescription, e); } } log.error(Strings.format("Failed to queue asset [{}] for loading.", fileName)); }
From source file:com.forerunnergames.peril.client.assets.S3AssetUpdater.java
License:Open Source License
@Override public void updateAssets() { if (!AssetSettings.UPDATE_ASSETS) { log.warn("Assets are not being updated.\nTo change this behavior, change {} in {} from false to true.\n" + "Make sure to back up any customizations you made to any assets first, as your changes " + "will be overwritten.", ClientApplicationProperties.UPDATE_ASSETS_KEY, ClientApplicationProperties.PROPERTIES_FILE_PATH_AND_NAME); return;/*from ww w. j a v a 2 s .com*/ } assetUpdatingFuture = executorService.submit(new Runnable() { @Override public void run() { final FileHandle destAssetsDir = Gdx.files .external(AssetSettings.RELATIVE_EXTERNAL_ASSETS_DIRECTORY); try { log.info("Attempting to update assets in [{}] from [{}]...", destAssetsDir.file(), AssetSettings.ABSOLUTE_UPDATED_ASSETS_LOCATION); if (Thread.currentThread().isInterrupted()) { log.warn("Asset updating was cancelled before beginning."); return; } log.info("Removing old assets..."); destAssetsDir.deleteDirectory(); if (Thread.currentThread().isInterrupted()) { log.warn( "Asset updating was cancelled after removing old assets, but before downloading new assets."); return; } final File destinationDirectory = destAssetsDir.file(); log.info("Downloading new assets to [{}]...", destinationDirectory); downloadInProgress = transferManager.downloadDirectory(bucketName, AssetSettings.INITIAL_S3_ASSETS_DOWNLOAD_SUBDIRECTORY, destinationDirectory); log.info("Successfully updated assets."); } catch (final Exception e) { final String errorMessage = "Failed to update assets from: [" + bucketName + "].\n" + "Make sure that " + ClientApplicationProperties.UPDATED_ASSETS_LOCATION_KEY + " is properly set in [" + ClientApplicationProperties.PROPERTIES_FILE_PATH_AND_NAME + "].\n" + "Also, " + ClientApplicationProperties.UPDATE_ASSETS_KEY + " must be set to true (in the same file) the first time you run the game.\n" + "If you already tried all of that, you can set " + ClientApplicationProperties.UPDATE_ASSETS_KEY + " to false.\nIn that case, you still need to make sure that you have a copy of all assets in " + destAssetsDir.file() + ".\n\n" + "Nerdy developer details:\n"; log.error(errorMessage, e); throw new RuntimeException(errorMessage, e); } } }); }
From source file:com.github.fauu.helix.manager.AreaManager.java
License:Open Source License
public void create(String name, int width, int length) { Json json = new Json(); IntVector2 dimensions = new IntVector2(width, length); FileHandle file = Gdx.files.internal("area/" + name + ".json"); try {//w w w . java 2 s.c o m json.setWriter(new JsonWriter(new FileWriter(file.file()))); } catch (IOException e) { e.printStackTrace(); } json.writeObjectStart(); json.writeValue("width", dimensions.x); json.writeValue("length", dimensions.y); json.writeArrayStart("tiles"); for (int y = 0; y < dimensions.y; y++) { for (int x = 0; x < dimensions.x; x++) { json.writeObjectStart(); json.writeValue("permissions", TilePermission.LEVEL0.toString()); json.writeObjectEnd(); } } json.writeArrayEnd(); json.writeObjectEnd(); try { json.getWriter().close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.github.fauu.helix.manager.AreaManager.java
License:Open Source License
public void save() { Json json = new Json(); String name = nameMapper.get(area).get(); FileHandle file = Gdx.files.internal("area/" + name + ".json"); IntVector2 dimensions = dimensionsMapper.get(area).get(); AreaType type = areaTypeMapper.get(area).get(); try {/* w ww. j a v a 2 s. co m*/ json.setWriter(new JsonWriter(new FileWriter(file.file()))); } catch (IOException e) { e.printStackTrace(); } json.writeObjectStart(); json.writeValue("width", dimensions.x); json.writeValue("length", dimensions.y); json.writeValue("type", type); json.writeArrayStart("tiles"); Tile[][] tiles = tilesMapper.get(area).get(); for (int y = 0; y < dimensions.y; y++) { for (int x = 0; x < dimensions.x; x++) { Tile tile = tiles[y][x]; json.writeObjectStart(); json.writeValue("permissions", tile.getPermissions().toString()); if (tile.getAreaPassage() != null) { TileAreaPassage passage = tile.getAreaPassage(); json.writeObjectStart("passage"); json.writeValue("area", passage.getTargetAreaName()); json.writeObjectStart("position"); json.writeValue("x", passage.getTargetCoords().x); json.writeValue("y", passage.getTargetCoords().y); json.writeObjectEnd(); json.writeObjectEnd(); } json.writeObjectEnd(); } } json.writeArrayEnd(); json.writeObjectEnd(); try { json.getWriter().close(); } catch (IOException e) { e.printStackTrace(); } }