Search in sources :

Example 21 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class LauncherModel method fired.

/**
 * Called when fire is performed.
 *
 * @param initial The fire launch initial speed for force transfer.
 * @throws LionEngineException If the fired object is not a {@link Launchable}.
 */
private void fired(Direction initial) {
    for (int i = 0; i < listenable.size(); i++) {
        listenable.get(i).notifyFired();
    }
    for (final LaunchableConfig launchableConfig : launchables) {
        final Media media = Medias.create(launchableConfig.getMedia());
        final Featurable featurable = factory.create(media);
        try {
            final Launchable launchable = featurable.getFeature(Launchable.class);
            if (launchableConfig.getDelay() > 0) {
                delayed.add(new DelayedLaunch(source, launchableConfig, initial, featurable, launchable));
            } else {
                launch(launchableConfig, initial, featurable, launchable);
            }
        } catch (final LionEngineException exception) {
            featurable.getFeature(Identifiable.class).destroy();
            throw exception;
        }
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Media(com.b3dgs.lionengine.Media) Featurable(com.b3dgs.lionengine.game.feature.Featurable)

Example 22 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class CollisionFunctionConfig method imports.

/**
 * Create the collision function from node.
 *
 * @param parent The parent reference (must not be <code>null</code>).
 * @return The collision function data.
 * @throws LionEngineException If error when reading node.
 */
public static CollisionFunction imports(XmlReader parent) {
    Check.notNull(parent);
    final XmlReader node = parent.getChild(FUNCTION);
    final CollisionFunctionType type = node.getEnum(CollisionFunctionType.class, TYPE);
    try {
        switch(type) {
            case LINEAR:
                return new CollisionFunctionLinear(node.getDouble(A), node.getDouble(B));
            // $CASES-OMITTED$
            default:
                throw new LionEngineException(type);
        }
    } catch (final IllegalArgumentException | NullPointerException exception) {
        throw new LionEngineException(exception, ERROR_TYPE + type);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 23 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class Minimap method prepare.

/**
 * Fill minimap surface with tile color configuration.
 *
 * @throws LionEngineException If surface has not been loaded ({@link #load()} may have not been called).
 */
@Override
public void prepare() {
    if (surface == null) {
        throw new LionEngineException(ERROR_SURFACE);
    }
    final Graphic g = surface.createGraphic();
    final int v = map.getInTileHeight();
    final int h = map.getInTileWidth();
    for (int ty = 0; ty < v; ty++) {
        for (int tx = 0; tx < h; tx++) {
            final Tile tile = map.getTile(tx, ty);
            final ColorRgba color = getTileColor(tile);
            if (!NO_TILE.equals(color)) {
                g.setColor(color);
                g.drawRect(tx, v - ty - 1, 0, 0, false);
            }
        }
    }
    g.dispose();
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) LionEngineException(com.b3dgs.lionengine.LionEngineException) Graphic(com.b3dgs.lionengine.graphic.Graphic) Tile(com.b3dgs.lionengine.game.feature.tile.Tile)

Example 24 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class ToolsAwt method getImage.

/**
 * Get an image from an input stream.
 *
 * @param input The image input stream.
 * @return The loaded image.
 * @throws IOException If error when reading image.
 * @see #setLoadStrategy(ImageLoadStrategy)
 */
public static BufferedImage getImage(InputStream input) throws IOException {
    final BufferedImage buffer = ImageIO.read(input);
    if (buffer == null) {
        throw new IOException("Invalid image !");
    }
    final BufferedImage copy;
    switch(imageLoadStragegy) {
        case FAST_LOADING:
            copy = buffer;
            break;
        case FAST_RENDERING:
            copy = copyImageDraw(buffer);
            break;
        case LOW_MEMORY:
            copy = copyImage(buffer);
            break;
        default:
            throw new LionEngineException(imageLoadStragegy);
    }
    return copy;
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 25 with LionEngineException

use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.

the class FactoryGraphicTest method afterAll.

/**
 * Terminate engine.
 */
@AfterAll
static void afterAll() {
    try {
        UtilFile.deleteFile(new File(System.getProperty("java.io.tmpdir"), FactoryGraphicTest.class.getSimpleName()));
    } catch (final LionEngineException exception) {
        Verbose.exception(exception);
    }
    Medias.setLoadFromJar(null);
    Graphics.setFactoryGraphic(null);
    Engine.terminate();
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) File(java.io.File) UtilFile(com.b3dgs.lionengine.UtilFile) AfterAll(org.junit.jupiter.api.AfterAll)

Aggregations

LionEngineException (com.b3dgs.lionengine.LionEngineException)75 IOException (java.io.IOException)13 File (java.io.File)8 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7 XmlReader (com.b3dgs.lionengine.XmlReader)6 Field (java.lang.reflect.Field)6 Test (org.junit.Test)6 Media (com.b3dgs.lionengine.Media)5 Configurer (com.b3dgs.lionengine.game.Configurer)4 UtilFile (com.b3dgs.lionengine.UtilFile)3 Graphic (com.b3dgs.lionengine.graphic.Graphic)3 UtilFile (com.b3dgs.lionengine.util.UtilFile)3 DisplayMode (java.awt.DisplayMode)3 BufferedImage (java.awt.image.BufferedImage)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 AfterAll (org.junit.jupiter.api.AfterAll)3 Animation (com.b3dgs.lionengine.Animation)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 Feature (com.b3dgs.lionengine.game.Feature)2