@Override public void dispose() { throw new SilenceException("Sub-Textures cannot be disposed! Just ignore them!"); }
@Override public void deleteOnExit() { throw new SilenceException("Cannot delete a resource upon exit."); }
@Override public void deleteOnExit() { throw new SilenceException("Cannot delete an in-jar resource upon exit."); }
/** * Turns the OpenAL Format integer constant into a ALFormat enum. * * @param value The integer constant * * @return The equivalent ALFormat enum */ public static ALFormat getEnum(int value) { switch (value) { case AL_FORMAT_MONO8: return MONO_8; case AL_FORMAT_MONO16: return MONO_16; case AL_FORMAT_STEREO8: return STEREO_8; case AL_FORMAT_STEREO16: return STEREO_16; } throw new SilenceException("Unknown format value: " + value); }
/** * Rethrows a Throwable as a SilenceException. This method is useful if you want to turn any exception into a * runtime SilenceException. Use this method if you want to quit the game with a fatal error. * * @param throwable The thrown object containing the stacktrace. */ public static void reThrow(Throwable throwable) { // Just pass on if the throwable is of type SilenceException if (throwable instanceof SilenceException) throw (SilenceException) throwable; else throw new SilenceException(throwable.toString()); } }
private List<JarEntry> getJarEntries() throws IOException { // Get the JAR file of the resource URL url = LwjglResourceFilePath.class.getClassLoader().getResource(getPath()); if (url == null) throw new SilenceException("Error, resource doesn't exist."); String jarUrl = url.toString(); String jarPath = URLDecoder.decode(jarUrl.substring(jarUrl.indexOf('/'), jarUrl.indexOf('!')), "UTF-8"); // Now get the JarEntry for this path JarFile jarFile = new JarFile(new File(jarPath)); List<JarEntry> entries = jarFile.stream().filter(e -> e.getName().startsWith(path)) .collect(Collectors.toList()); jarFile.close(); if (entries != null) return entries; throw new IOException("Cannot find the JAR entry for " + getPath() + " in JAR file " + jarPath); }
/** * Constructs a cursor object that uses a predefined cursor defined by the operating system. * * @param standardType The type of the default cursor that this cursor object should look like. */ public Cursor(Type standardType) { handle = glfwCreateStandardCursor(standardType.getType()); if (handle == NULL) throw new SilenceException("Unable to load cursor from texture"); }
@Override public Promise<List<FilePath>> listFiles() { return new Promise<>((resolve, reject) -> isDirectory().then(isDirectory -> exists().then(exists -> { if (!isDirectory) throw new SilenceException("Cannot list files in a path which is not a directory."); if (!exists) throw new SilenceException("Cannot list files in a non existing directory."); List<FilePath> list = new ArrayList<>(); File file = new File(path); File[] children = file.listFiles(); if (children != null) for (File child : children) list.add(new LwjglExternalFilePath(path + SEPARATOR + child.getPath().replace(file.getPath(), ""))); resolve.invoke(Collections.unmodifiableList(list)); }, reject), reject)); }
@Override public Promise<List<FilePath>> listFiles() { return new Promise<>((resolve, reject) -> isDirectory().then(isDirectory -> exists().then(exists -> { if (!isDirectory) throw new SilenceException("Cannot list files in a path which is not a directory."); if (!exists) throw new SilenceException("Cannot list files in a non existing directory."); List<FilePath> list = new ArrayList<>(); File[] children = file.listFiles(); if (children != null) for (File child : children) list.add(new AndroidExternalFilePath(path + SEPARATOR + child.getPath().replace(file.getPath(), ""))); resolve.invoke(Collections.unmodifiableList(list)); }, reject), reject)); }
public void dispose() { if (disposed) throw new SilenceException("Cannot dispose an already disposed object"); instances--; renderer.dispose(); if (instances == 0) { program.dispose(); program = null; } disposed = true; } }
@Override public Promise<Void> createFile() { return new Promise<>((resolve, reject) -> isDirectory().then(isDirectory -> { if (isDirectory) throw new SilenceException("Cannot convert a directory to a file"); try { file.createNewFile(); resolve.invoke(null); } catch (IOException e) { reject.invoke(e); } })); }
@Override public Promise<List<FilePath>> listFiles() { return new Promise<>((resolve, reject) -> isDirectory().then(isDirectory -> exists().then(exists -> { try { if (!isDirectory) throw new SilenceException("Cannot list files in a path which is not a directory."); if (!exists) throw new SilenceException("Cannot list files in a non existing directory."); List<FilePath> filePaths = new ArrayList<>(); for (String s : assetManager.list(getPath())) filePaths.add(new AndroidResourceFilePath(getPath() + SEPARATOR + s)); resolve.invoke(Collections.unmodifiableList(filePaths)); } catch (IOException e) { reject.invoke(e); } }, reject), reject)); }
public void dispose() { if (isDisposed()) throw new SilenceException("This texture is already disposed."); SilenceEngine.graphics.glDeleteTextures(id); GLError.check(); disposed = true; EMPTY.bind(activeUnit); }
@Override public void readImage(DirectBuffer memory, UniCallback<Image> onComplete, UniCallback<Throwable> onError) { getImage(((ArrayBufferView) memory.nativeBuffer()).buffer(), onComplete, e -> onError.invoke(new SilenceException(e))); }
@Override public void readToALBuffer(AudioFormat format, DirectBuffer data, UniCallback<ALBuffer> onDecoded, UniCallback<Throwable> onError) { try { if (!isSupported(format)) throw new SilenceException("Audio format " + format + " is not supported."); AudioDecoder.decodeAudio(((ArrayBufferView) data.nativeBuffer()).buffer(), alBufferID -> onDecoded.invoke(new ALBuffer(alBufferID)), reason -> { throw new SilenceException("Error decoding: " + reason); }); } catch (Throwable e) { onError.invoke(e); } }
public static void create(TmxMap map, UniCallback<TmxMapRenderer> callback) { switch (map.getOrientation()) { case ISOMETRIC: TmxIsometricMapRenderer.create(map, callback); break; case ORTHOGONAL: TmxOrthogonalMapRenderer.create(map, callback); break; default: throw new SilenceException("A TmxMapRenderer has not yet been implemented for " + map.getOrientation() + " orientation"); } }
@Override public Promise<Boolean> delete() { return new Promise<>((resolve, reject) -> exists().then(exists -> isDirectory().then(isDirectory -> { if (!exists) throw new SilenceException("Cannot delete non existing file."); if (isDirectory) { listFiles().then(files -> { // Delete all the children first for (FilePath filePath : files) filePath.delete(); }); } resolve.invoke(file.delete()); }, reject), reject)); }
@Override public void readTextFile(FilePath file, UniCallback<String> onComplete, UniCallback<Throwable> onError) { // Create a XMLHttpRequest to load the file into a direct buffer XMLHttpRequest request = XMLHttpRequest.create(); request.open("GET", file.getAbsolutePath()); // Set to read as default mode and attach a handler request.setResponseType(XMLHttpRequest.ResponseType.Default); request.setOnReadyStateChange(xhr -> { if (request.getReadyState() == XMLHttpRequest.DONE) { if (request.getStatus() == 200) // Invoke the onComplete handler onComplete.invoke(request.getResponseText()); else onError.invoke(new SilenceException("Error fetching the file: " + request.getStatusText())); } }); // Send the request request.send(); } }
@Override public void readBinaryFile(FilePath file, UniCallback<DirectBuffer> onComplete, UniCallback<Throwable> onError) { // Create a XMLHttpRequest to load the file into a direct buffer XMLHttpRequest request = XMLHttpRequest.create(); request.open("GET", file.getAbsolutePath()); // Set to read as ArrayBuffer and attach a handler request.setResponseType(XMLHttpRequest.ResponseType.ArrayBuffer); request.setOnReadyStateChange(xhr -> { if (request.getReadyState() == XMLHttpRequest.DONE) { if (request.getStatus() == 200) // Invoke the onComplete handler onComplete.invoke(new GwtDirectBuffer(request.getResponseArrayBuffer())); else onError.invoke(new SilenceException("Error fetching the file: " + request.getStatusText())); } }); // Send the request request.send(); }
@Override public void readToALBuffer(AudioFormat format, DirectBuffer data, UniCallback<ALBuffer> onDecoded, UniCallback<Throwable> onError) { try { if (!isSupported(format)) throw new SilenceException("Cannot parse sound. The format is unsupported: " + format); if (format == AudioFormat.WAV) AsyncRunner.runAsync(() -> { WavReader reader = new WavReader(data); ALBuffer alBuffer = new ALBuffer(); alBuffer.uploadData(new AndroidDirectBuffer(reader.data), reader.alFormat, reader.sampleRate); return () -> TaskManager.runOnUpdate(() -> onDecoded.invoke(alBuffer)); }); else if (format == AudioFormat.OGG) AsyncRunner.runAsync(() -> { OggReader reader = new OggReader(data); ALBuffer alBuffer = new ALBuffer(); alBuffer.uploadData(new AndroidDirectBuffer(reader.getData()), reader.getFormat(), reader.getSampleRate()); return () -> TaskManager.runOnUpdate(() -> onDecoded.invoke(alBuffer)); }); } catch (Throwable e) { onError.invoke(e); } }