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);
}
}
}
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);
}
}
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);
}
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());
}
}
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);
}
}
Aggregations