Search in sources :

Example 91 with GdxRuntimeException

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!");
        }
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Type(java.lang.reflect.Type) Method(java.lang.reflect.Method)

Example 92 with GdxRuntimeException

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());
    }
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) Music(com.badlogic.gdx.audio.Music)

Example 93 with GdxRuntimeException

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;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException)

Example 94 with GdxRuntimeException

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());
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) NinePatch(com.badlogic.gdx.graphics.g2d.NinePatch) AtlasSprite(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) AtlasRegion(com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable)

Example 95 with GdxRuntimeException

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;
}
Also used : GdxRuntimeException(com.badlogic.gdx.utils.GdxRuntimeException) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable) TextureRegionDrawable(com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) NinePatchDrawable(com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable) TiledDrawable(com.badlogic.gdx.scenes.scene2d.utils.TiledDrawable)

Aggregations

GdxRuntimeException (com.badlogic.gdx.utils.GdxRuntimeException)202 IOException (java.io.IOException)40 FileHandle (com.badlogic.gdx.files.FileHandle)14 Array (com.badlogic.gdx.utils.Array)13 Texture (com.badlogic.gdx.graphics.Texture)12 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)11 AtlasRegion (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion)9 InputStream (java.io.InputStream)9 Pixmap (com.badlogic.gdx.graphics.Pixmap)8 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)8 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)7 AtlasSprite (com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite)7 BufferedInputStream (java.io.BufferedInputStream)7 File (java.io.File)7 OutputStream (java.io.OutputStream)7 VertexAttribute (com.badlogic.gdx.graphics.VertexAttribute)6 LifecycleListener (com.badlogic.gdx.LifecycleListener)5 ByteBuffer (java.nio.ByteBuffer)5 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4 NinePatch (com.badlogic.gdx.graphics.g2d.NinePatch)4