Search in sources :

Example 71 with LionEngineException

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

the class ScreenAbstract method awaitReady.

@Override
public final void awaitReady() {
    final Timing timeout = new Timing();
    timeout.start();
    while (!isReady()) {
        if (timeout.elapsed(getReadyTimeOut())) {
            throw new LionEngineException(ERROR_SCREEN_READY);
        }
        try {
            Thread.sleep(Constant.DECADE);
        } catch (final InterruptedException exception) {
            Thread.currentThread().interrupt();
            throw new LionEngineException(exception, ERROR_SCREEN_READY);
        }
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Timing(com.b3dgs.lionengine.Timing)

Example 72 with LionEngineException

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

the class ImageInfo method read.

/**
 * Read image header.
 *
 * @param media The media to read (must not be <code>null</code>).
 * @param reader The header reader (must not be <code>null</code>).
 * @return The header read.
 * @throws LionEngineException If invalid arguments or cannot be read.
 */
private static ImageHeader read(Media media, ImageHeaderReader reader) {
    Check.notNull(media);
    Check.notNull(reader);
    try (InputStream input = media.getInputStream()) {
        return reader.readHeader(input);
    } catch (final IOException exception) {
        throw new LionEngineException(exception, media, ERROR_READ);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 73 with LionEngineException

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

the class Features method add.

/**
 * Add a feature. Stores its interface, and all sub interfaces which describe also a {@link Feature} annotated by
 * {@link FeatureInterface}.
 *
 * @param feature The feature to add.
 * @param overwrite <code>true</code> to overwrite existing feature, <code>false</code> else.
 * @throws LionEngineException If feature is not annotated by {@link FeatureInterface} or already referenced.
 */
public void add(Feature feature, boolean overwrite) {
    if (!isAnnotated(feature)) {
        throw new LionEngineException(ERROR_FEATURE_NOT_ANNOTATED + feature.getClass());
    }
    final Feature old;
    // CHECKSTYLE IGNORE LINE: InnerAssignment
    if ((old = typeToFeature.put(feature.getClass(), feature)) != null) {
        throw new LionEngineException(ERROR_FEATURE_EXISTS + feature.getClass() + WITH + old.getClass());
    }
    checkTypeDepth(feature, feature.getClass(), overwrite);
    features.add(feature);
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Feature(com.b3dgs.lionengine.game.Feature)

Example 74 with LionEngineException

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

the class Factory method createSetup.

/**
 * Create a setup from its media.
 *
 * @param media The media reference.
 * @param standard <code>true</code> for standard setup, <code>false</code> else.
 * @return The setup instance.
 */
@SuppressWarnings("unchecked")
private Setup createSetup(Media media, boolean standard) {
    final Configurer configurer = new Configurer(media);
    try {
        final FeaturableConfig config = FeaturableConfig.imports(configurer);
        final String setup = config.getSetupName();
        final Class<? extends Setup> setupClass;
        if (standard) {
            setupClass = Setup.class;
        } else if (setup.isEmpty()) {
            final Class<?> clazz = classLoader.loadClass(config.getClassName());
            final Constructor<?> constructor = UtilReflection.getCompatibleConstructorParent(clazz, new Class<?>[] { Services.class, Setup.class });
            setupClass = (Class<? extends Setup>) constructor.getParameterTypes()[SETUP_INDEX];
        } else {
            setupClass = (Class<? extends Setup>) classLoader.loadClass(config.getSetupName());
        }
        return UtilReflection.create(setupClass, new Class<?>[] { Media.class }, media);
    } catch (final ClassNotFoundException exception) {
        throw new LionEngineException(exception, media, ERROR_SETUP_CLASS);
    } catch (final NoSuchMethodException exception) {
        throw new LionEngineException(exception, ERROR_CONSTRUCTOR_MISSING + media.getPath());
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Constructor(java.lang.reflect.Constructor) Configurer(com.b3dgs.lionengine.game.Configurer)

Example 75 with LionEngineException

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

the class StateHandler method create.

/**
 * Create state from its type.
 *
 * @param state The state to create (must not be <code>null</code>).
 * @return The created state.
 * @throws LionEngineException If unable to create state.
 */
@SuppressWarnings("unchecked")
private State create(Class<? extends State> state) {
    Check.notNull(state);
    try {
        if (setup.hasNode(AnimationConfig.NODE_ANIMATIONS)) {
            final AnimationConfig configAnimations = AnimationConfig.imports(setup);
            final String name = converter.apply(state);
            final Animation animation = configAnimations.getAnimation(name);
            final Class<? extends Feature> feature;
            feature = (Class<? extends Feature>) UtilReflection.getCompatibleConstructor(state, FeatureProvider.class, Animation.class).getParameters()[PARAM_FEATURE_INDEX].getType();
            return UtilReflection.create(state, UtilReflection.getParamTypes(feature, animation), getFeature(feature), animation);
        }
        return UtilReflection.createReduce(state);
    } catch (final LionEngineException exception) {
        throw new LionEngineException(exception, setup.getMedia());
    } catch (final NoSuchMethodException exception) {
        throw new LionEngineException(exception);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Animation(com.b3dgs.lionengine.Animation) FeatureProvider(com.b3dgs.lionengine.game.FeatureProvider) AnimationConfig(com.b3dgs.lionengine.game.AnimationConfig)

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