use of com.badlogic.gdx.utils.GdxRuntimeException in project Catacomb-Snatch by Catacomb-Snatch.
the class EventManager method registerListener.
@SuppressWarnings("unchecked")
public static void registerListener(Object listener) {
for (Method method : listener.getClass().getMethods()) {
EventHandler handler = method.getAnnotation(EventHandler.class);
if (handler == null)
continue;
Type returnType = method.getReturnType();
if (returnType != Void.TYPE) {
throw new GdxRuntimeException("Unsupported return type: " + returnType.toString());
}
if (method.getParameterTypes().length != 1) {
throw new GdxRuntimeException("Method " + method.getName() + " needs exactly 1 parameter!");
}
Class<?> eventParam = method.getParameterTypes()[0];
if (Event.class.isAssignableFrom(eventParam)) {
EventRegistry entry = registry.get(eventParam);
if (entry == null) {
entry = new EventRegistry();
registry.put((Class<? extends Event>) eventParam, entry);
}
entry.addEntry(new Listener(handler.priority(), handler.ignoreCancelled(), method, listener));
} else {
throw new GdxRuntimeException("Method " + method.getName() + " does not have a proper event parameter!");
}
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project Catacomb-Snatch by Catacomb-Snatch.
the class GdxSoundPlayer method loadMusic.
private void loadMusic(Sounds music) {
try {
Gdx.app.log(TAG, Gdx.files.internal("music/" + music.name + ".ogg").file().getAbsolutePath());
Music file = Gdx.audio.newMusic(Gdx.files.internal("music/" + music.name + ".ogg"));
// If background track, add to playlist
if (music.name.toLowerCase().startsWith("background"))
backgroundMusicList.add(file);
musicMap.put(music.name, file);
} catch (GdxRuntimeException e) {
Gdx.app.log(TAG, "Error loading musicfile: " + music.name + ": " + e.getMessage());
}
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project gdx-skineditor by cobolfoo.
the class Skin method get.
public <T> T get(String name, Class<T> type) {
if (name == null)
throw new IllegalArgumentException("name cannot be null.");
if (type == null)
throw new IllegalArgumentException("type cannot be null.");
if (type == Drawable.class)
return (T) getDrawable(name);
if (type == TextureRegion.class)
return (T) getRegion(name);
if (type == NinePatch.class)
return (T) getPatch(name);
if (type == Sprite.class)
return (T) getSprite(name);
ObjectMap<String, Object> typeResources = resources.get(type);
if (typeResources == null)
throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
Object resource = typeResources.get(name);
if (resource == null)
throw new GdxRuntimeException("No " + type.getName() + " registered with name: " + name);
return (T) resource;
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project gdx-skineditor by cobolfoo.
the class Skin method newDrawable.
/**
* Returns a tinted copy of a drawable found in the skin via
* {@link #getDrawable(String)}.
*/
public Drawable newDrawable(Drawable drawable, Color tint) {
if (drawable instanceof TextureRegionDrawable) {
TextureRegion region = ((TextureRegionDrawable) drawable).getRegion();
Sprite sprite;
if (region instanceof AtlasRegion)
sprite = new AtlasSprite((AtlasRegion) region);
else
sprite = new Sprite(region);
sprite.setColor(tint);
return new SpriteDrawable(sprite);
}
if (drawable instanceof NinePatchDrawable) {
NinePatchDrawable patchDrawable = new NinePatchDrawable((NinePatchDrawable) drawable);
patchDrawable.setPatch(new NinePatch(patchDrawable.getPatch(), tint));
return patchDrawable;
}
if (drawable instanceof SpriteDrawable) {
SpriteDrawable spriteDrawable = new SpriteDrawable((SpriteDrawable) drawable);
Sprite sprite = spriteDrawable.getSprite();
if (sprite instanceof AtlasSprite)
sprite = new AtlasSprite((AtlasSprite) sprite);
else
sprite = new Sprite(sprite);
sprite.setColor(tint);
spriteDrawable.setSprite(sprite);
return spriteDrawable;
}
throw new GdxRuntimeException("Unable to copy, unknown drawable type: " + drawable.getClass());
}
use of com.badlogic.gdx.utils.GdxRuntimeException in project gdx-skineditor by cobolfoo.
the class Skin method getTiledDrawable.
/**
* Returns a registered tiled drawable. If no tiled drawable is found but a
* region exists with the name, a tiled drawable is created from the region
* and stored in the skin.
*/
public TiledDrawable getTiledDrawable(String name) {
TiledDrawable tiled = optional(name, TiledDrawable.class);
if (tiled != null)
return tiled;
Drawable drawable = optional(name, Drawable.class);
if (drawable != null) {
if (!(drawable instanceof TiledDrawable)) {
throw new GdxRuntimeException("Drawable found but is not a TiledDrawable: " + name + ", " + drawable.getClass().getName());
}
return (TiledDrawable) drawable;
}
tiled = new TiledDrawable(getRegion(name));
add(name, tiled, TiledDrawable.class);
return tiled;
}
Aggregations