Search in sources :

Example 61 with LionEngineException

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

the class ScreenAwtTest method testFullscreen.

/**
 * Test full screen.
 */
@Test
void testFullscreen() {
    Medias.setLoadFromJar(ScreenAwtTest.class);
    final DisplayMode res = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayModes()[0];
    final Config config = new Config(new Resolution(res.getWidth(), res.getHeight(), res.getRefreshRate()), res.getBitDepth(), false, Medias.create("image.png"));
    try {
        testScreen(config);
    } catch (final LionEngineException exception) {
        // Skip test
        if (!ScreenFullAwt.ERROR_SWITCH.equals(exception.getMessage())) {
            throw exception;
        }
    }
}
Also used : DisplayMode(java.awt.DisplayMode) LionEngineException(com.b3dgs.lionengine.LionEngineException) Config(com.b3dgs.lionengine.Config) Resolution(com.b3dgs.lionengine.Resolution) Test(org.junit.jupiter.api.Test)

Example 62 with LionEngineException

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

the class FactoryGraphicHeadless method generateTileset.

@Override
public void generateTileset(ImageBuffer[] images, Media media) {
    Check.notNull(images);
    Check.notNull(media);
    if (images.length == 0) {
        throw new LionEngineException("No images found !");
    }
    final int width = images[0].getWidth();
    final int height = images[0].getHeight();
    final int multDistance = (int) Math.ceil(width * images.length / (double) height) / 4;
    final int[] mult = UtilMath.getClosestSquareMult(images.length, multDistance);
    try (OutputStream output = media.getOutputStream()) {
        output.write(UtilConversion.intToByteArray(width * mult[1]));
        output.write(UtilConversion.intToByteArray(height * mult[0]));
    } catch (final IOException exception) {
        throw new LionEngineException(exception, media, ERROR_IMAGE_SAVE);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 63 with LionEngineException

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

the class FactoryGraphicHeadless method saveImage.

@Override
public void saveImage(ImageBuffer image, Media media) {
    Check.notNull(media);
    try (OutputStream output = media.getOutputStream()) {
        output.write(UtilConversion.intToByteArray(image.getWidth()));
        output.write(UtilConversion.intToByteArray(image.getHeight()));
    } catch (final IOException exception) {
        throw new LionEngineException(exception, media, ERROR_IMAGE_SAVE);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 64 with LionEngineException

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

the class ServerUdp method handleType.

private void handleType(DatagramPacket packet) throws IOException {
    final ByteBuffer buffer = UtilNetwork.getBuffer(packet);
    bandwidthDownSum.addAndGet(buffer.capacity());
    final MessageType type = MessageType.from(buffer);
    switch(type) {
        case CONNECT:
            connect(packet, buffer);
            break;
        case DISCONNECT:
            disconnect(packet, buffer);
            break;
        case ALIVE:
            alive(packet, buffer);
            break;
        case PING:
            ping(packet, buffer);
            break;
        case DIRECT:
            direct(packet, buffer);
            break;
        case DATA:
            data(packet, buffer);
            break;
        case CLIENTS_LIST:
        case UNKNOWN:
            break;
        default:
            throw new LionEngineException(type);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) ByteBuffer(java.nio.ByteBuffer) MessageType(com.b3dgs.lionengine.network.MessageType)

Example 65 with LionEngineException

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

the class RasterImageTest method afterAll.

/**
 * Terminate engine.
 */
@AfterAll
static void afterAll() {
    try {
        UtilFile.deleteFile(new File(System.getProperty("java.io.tmpdir"), RasterImageTest.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