protected static FileHandle getRelativeFileHandle (FileHandle file, String path) { StringTokenizer tokenizer = new StringTokenizer(path, "\\/"); FileHandle result = file.parent(); while (tokenizer.hasMoreElements()) { String token = tokenizer.nextToken(); if (token.equals("..")) result = result.parent(); else { result = result.child(token); } } return result; }
protected static FileHandle getRelativeFileHandle (FileHandle file, String path) { StringTokenizer tokenizer = new StringTokenizer(path, "\\/"); FileHandle result = file.parent(); while (tokenizer.hasMoreElements()) { String token = tokenizer.nextToken(); if (token.equals("..")) result = result.parent(); else { result = result.child(token); } } return result; }
private static FileHandle getRelativeFileHandle (FileHandle file, String path) { StringTokenizer tokenizer = new StringTokenizer(path, "\\/"); FileHandle result = file.parent(); while (tokenizer.hasMoreElements()) { String token = tokenizer.nextToken(); if (token.equals("..")) result = result.parent(); else { result = result.child(token); } } return result; }
private static FileHandle getRelativeFileHandle (FileHandle file, String path) { StringTokenizer tokenizer = new StringTokenizer(path, "\\/"); FileHandle result = file.parent(); while (tokenizer.hasMoreElements()) { String token = tokenizer.nextToken(); if (token.equals("..")) result = result.parent(); else { result = result.child(token); } } return result; }
/** Returns the paths to the children of this directory. Returns an empty list if this file handle represents a file and not a * directory. On the desktop, an {@link FileType#Internal} handle to a directory on the classpath will return a zero length * array. * @throws GdxRuntimeException if this file is an {@link FileType#Classpath} file. */ public FileHandle[] list () { if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot list a classpath directory: " + file); String[] relativePaths = file().list(); if (relativePaths == null) return new FileHandle[0]; FileHandle[] handles = new FileHandle[relativePaths.length]; for (int i = 0, n = relativePaths.length; i < n; i++) handles[i] = child(relativePaths[i]); return handles; }
/** Returns the paths to the children of this directory. Returns an empty list if this file handle represents a file and not a * directory. On the desktop, an {@link FileType#Internal} handle to a directory on the classpath will return a zero length * array. * @throws GdxRuntimeException if this file is an {@link FileType#Classpath} file. */ public FileHandle[] list () { if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot list a classpath directory: " + file); String[] relativePaths = file().list(); if (relativePaths == null) return new FileHandle[0]; FileHandle[] handles = new FileHandle[relativePaths.length]; for (int i = 0, n = relativePaths.length; i < n; i++) handles[i] = child(relativePaths[i]); return handles; }
/** Returns the paths to the children of this directory with the specified suffix. Returns an empty list if this file handle * represents a file and not a directory. On the desktop, an {@link FileType#Internal} handle to a directory on the classpath * will return a zero length array. * @throws GdxRuntimeException if this file is an {@link FileType#Classpath} file. */ public FileHandle[] list (String suffix) { if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot list a classpath directory: " + file); String[] relativePaths = file().list(); if (relativePaths == null) return new FileHandle[0]; FileHandle[] handles = new FileHandle[relativePaths.length]; int count = 0; for (int i = 0, n = relativePaths.length; i < n; i++) { String path = relativePaths[i]; if (!path.endsWith(suffix)) continue; handles[count] = child(path); count++; } if (count < relativePaths.length) { FileHandle[] newHandles = new FileHandle[count]; System.arraycopy(handles, 0, newHandles, 0, count); handles = newHandles; } return handles; }
/** Returns the paths to the children of this directory with the specified suffix. Returns an empty list if this file handle * represents a file and not a directory. On the desktop, an {@link FileType#Internal} handle to a directory on the classpath * will return a zero length array. * @throws GdxRuntimeException if this file is an {@link FileType#Classpath} file. */ public FileHandle[] list (String suffix) { if (type == FileType.Classpath) throw new GdxRuntimeException("Cannot list a classpath directory: " + file); String[] relativePaths = file().list(); if (relativePaths == null) return new FileHandle[0]; FileHandle[] handles = new FileHandle[relativePaths.length]; int count = 0; for (int i = 0, n = relativePaths.length; i < n; i++) { String path = relativePaths[i]; if (!path.endsWith(suffix)) continue; handles[count] = child(path); count++; } if (count < relativePaths.length) { FileHandle[] newHandles = new FileHandle[count]; System.arraycopy(handles, 0, newHandles, 0, count); handles = newHandles; } return handles; }
public FileHandle sibling (String name) { return parent().child(fixSlashes(name)); }
public FileHandle sibling (String name) { return parent().child(fixSlashes(name)); }
protected void load (final StringBuilder out, final String name) { final int idx = name.lastIndexOf(':'); final String fileName = idx < 0 ? name : name.substring(0, idx); final String snipName = idx < 0 || (idx >= name.length() - 1) ? "" : name.substring(idx + 1); ObjectMap<String, String> snips = snippets.get(fileName, null); if (snips == null) { snips = parse(root.child(fileName)); snippets.put(fileName, snips); } String result = snips.get(snipName, null); if (result == null) throw new GdxRuntimeException("No snippet [" + snipName + "] in file " + root.child(fileName).path()); parse(out, fileName, result); }
public void setEnvironment (String name) { if (name == null) return; if (cubemap != null) { cubemap.dispose(); cubemap = null; } if (name.equals("<none>")) { if (environment.has(CubemapAttribute.EnvironmentMap)) { environment.remove(CubemapAttribute.EnvironmentMap); shaderProvider.clear(); } } else { FileHandle root = Gdx.files.internal("data/g3d/environment"); FacedCubemapData faces = new FacedCubemapData(root.child(name + "_PX.png"), root.child(name+"_NX.png"), root.child(name + "_PY.png"), root.child(name + "_NY.png"), root.child(name + "_PZ.png"), root.child(name + "_NZ.png"), false); // FIXME mipmapping on desktop cubemap = new Cubemap(faces); faces.load(CubemapSide.NegativeX, root.child(name + "_NX.png")); cubemap.load(faces); if (!environment.has(CubemapAttribute.EnvironmentMap)) shaderProvider.clear(); environment.set(new CubemapAttribute(CubemapAttribute.EnvironmentMap, cubemap)); } }
@Override protected Shader createShader (Renderable renderable) { if (config.vertexShader != null && config.fragmentShader != null && tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) { String prefix = DefaultShader.createPrefix(renderable, config); Gdx.files.absolute(tempFolder).child(name + ".vertex.glsl").writeString(prefix + config.vertexShader, false); Gdx.files.absolute(tempFolder).child(name + ".fragment.glsl").writeString(prefix + config.fragmentShader, false); } BaseShader result = new MultiPassShader(renderable, config); if (tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) Gdx.files.absolute(tempFolder).child(name + ".log.txt").writeString(result.program.getLog(), false); return result; } }
@Override public Shader getShader (Renderable renderable) { try { return super.getShader(renderable); } catch (Throwable e) { if (tempFolder != null && Gdx.app.getType() == ApplicationType.Desktop) Gdx.files.absolute(tempFolder).child(name + ".log.txt").writeString(e.getMessage(), false); if (!revert()) { Gdx.app.error("ShaderCollectionTest", e.getMessage()); throw new GdxRuntimeException("Error creating shader, cannot revert to default shader", e); } error = true; Gdx.app.error("ShaderTest", "Could not create shader, reverted to default shader.", e); return super.getShader(renderable); } }
public void loadEmitterImages (FileHandle imagesDir) { ownsTexture = true; ObjectMap<String, Sprite> loadedSprites = new ObjectMap<String, Sprite>(emitters.size); for (int i = 0, n = emitters.size; i < n; i++) { ParticleEmitter emitter = emitters.get(i); if (emitter.getImagePaths().size == 0) continue; Array<Sprite> sprites = new Array<Sprite>(); for (String imagePath : emitter.getImagePaths()) { String imageName = new File(imagePath.replace('\\', '/')).getName(); Sprite sprite = loadedSprites.get(imageName); if (sprite == null) { sprite = new Sprite(loadTexture(imagesDir.child(imageName))); loadedSprites.put(imageName, sprite); } sprites.add(sprite); } emitter.setSprites(sprites); } }
static private void copyDirectory (FileHandle sourceDir, FileHandle destDir) { destDir.mkdirs(); FileHandle[] files = sourceDir.list(); for (int i = 0, n = files.length; i < n; i++) { FileHandle srcFile = files[i]; FileHandle destFile = destDir.child(srcFile.name()); if (srcFile.isDirectory()) copyDirectory(srcFile, destFile); else copyFile(srcFile, destFile); } } }
static private void copyDirectory (FileHandle sourceDir, FileHandle destDir) { destDir.mkdirs(); FileHandle[] files = sourceDir.list(); for (int i = 0, n = files.length; i < n; i++) { FileHandle srcFile = files[i]; FileHandle destFile = destDir.child(srcFile.name()); if (srcFile.isDirectory()) copyDirectory(srcFile, destFile); else copyFile(srcFile, destFile); } } }
public void loadEmitterImages (FileHandle imagesDir) { ownsTexture = true; ObjectMap<String, Sprite> loadedSprites = new ObjectMap<String, Sprite>(emitters.size); for (int i = 0, n = emitters.size; i < n; i++) { ParticleEmitter emitter = emitters.get(i); if (emitter.getImagePaths().size == 0) continue; Array<Sprite> sprites = new Array<Sprite>(); for (String imagePath : emitter.getImagePaths()) { String imageName = new File(imagePath.replace('\\', '/')).getName(); Sprite sprite = loadedSprites.get(imageName); if (sprite == null) { sprite = new Sprite(loadTexture(imagesDir.child(imageName))); loadedSprites.put(imageName, sprite); } sprites.add(sprite); } emitter.setSprites(sprites); } }
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a * file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination * doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If * this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is * a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't * exist, {@link #mkdirs()} is called on the destination and this directory is copied into it recursively. * @throws GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} * file, or copying failed. */ public void copyTo (FileHandle dest) { if (!isDirectory()) { if (dest.isDirectory()) dest = dest.child(name()); copyFile(this, dest); return; } if (dest.exists()) { if (!dest.isDirectory()) throw new GdxRuntimeException("Destination exists but is not a directory: " + dest); } else { dest.mkdirs(); if (!dest.isDirectory()) throw new GdxRuntimeException("Destination directory cannot be created: " + dest); } copyDirectory(this, dest.child(name())); }
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a * file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination * doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If * this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is * a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't * exist, {@link #mkdirs()} is called on the destination and this directory is copied into it recursively. * @throws GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal} * file, or copying failed. */ public void copyTo (FileHandle dest) { if (!isDirectory()) { if (dest.isDirectory()) dest = dest.child(name()); copyFile(this, dest); return; } if (dest.exists()) { if (!dest.isDirectory()) throw new GdxRuntimeException("Destination exists but is not a directory: " + dest); } else { dest.mkdirs(); if (!dest.isDirectory()) throw new GdxRuntimeException("Destination directory cannot be created: " + dest); } copyDirectory(this, dest.child(name())); }