use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class BitmapFontLoader method loadSync.
@Override
public BitmapFont loadSync(AssetManager manager, String fileName, FileHandle file, BitmapFontParameter parameter) {
if (parameter != null && parameter.atlasName != null) {
TextureAtlas atlas = manager.get(parameter.atlasName, TextureAtlas.class);
String name = file.sibling(data.imagePaths[0]).nameWithoutExtension().toString();
AtlasRegion region = atlas.findRegion(name);
if (region == null)
throw new GdxRuntimeException("Could not find font region " + name + " in atlas " + parameter.atlasName);
return new BitmapFont(file, region);
} else {
int n = data.getImagePaths().length;
Array<TextureRegion> regs = new Array(n);
for (int i = 0; i < n; i++) {
regs.add(new TextureRegion(manager.get(data.getImagePath(i), Texture.class)));
}
return new BitmapFont(data, regs, true);
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class TextureArray method reload.
@Override
protected void reload() {
if (!isManaged())
throw new GdxRuntimeException("Tried to reload an unmanaged TextureArray");
glHandle = Gdx.gl.glGenTexture();
load(data);
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class FileHandle method moveTo.
/** Moves this file to the specified file, overwriting the file if it already exists.
* @throws GdxRuntimeException if the source or destination file handle is a {@link FileType#Classpath} or
* {@link FileType#Internal} file. */
public void moveTo(FileHandle dest) {
if (type == FileType.Classpath)
throw new GdxRuntimeException("Cannot move a classpath file: " + file);
if (type == FileType.Internal)
throw new GdxRuntimeException("Cannot move an internal file: " + file);
copyTo(dest);
delete();
if (exists() && isDirectory())
deleteDirectory();
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class FileHandle method write.
/** Reads the remaining bytes from the specified stream and writes them to this file. The stream is closed. Parent directories
* will be created if necessary.
* @param append If false, this file will be overwritten if it exists, otherwise it will be appended.
* @throws GdxRuntimeException if this file handle represents a directory, if it is a {@link FileType#Classpath} or
* {@link FileType#Internal} file, or if it could not be written. */
public void write(InputStream input, boolean append) {
OutputStream output = null;
try {
output = write(append);
StreamUtils.copyStream(input, output);
} catch (Exception ex) {
throw new GdxRuntimeException("Error stream writing to file: " + file + " (" + type + ")", ex);
} finally {
StreamUtils.closeQuietly(input);
StreamUtils.closeQuietly(output);
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project libgdx by libgdx.
the class FileHandle method readBytes.
/** Reads the entire file into the byte array. The byte array must be big enough to hold the file's data.
* @param bytes the array to load the file into
* @param offset the offset to start writing bytes
* @param size the number of bytes to read, see {@link #length()}
* @return the number of read bytes */
public int readBytes(byte[] bytes, int offset, int size) {
InputStream input = read();
int position = 0;
try {
while (true) {
int count = input.read(bytes, offset + position, size - position);
if (count <= 0)
break;
position += count;
}
} catch (IOException ex) {
throw new GdxRuntimeException("Error reading file: " + this, ex);
} finally {
StreamUtils.closeQuietly(input);
}
return position - offset;
}
Aggregations