use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class AttackerModelTest method testEnumFail.
/**
* Test with enum fail.
*
* @throws NoSuchFieldException If error.
* @throws IllegalArgumentException If error.
* @throws IllegalAccessException If error.
*/
@Test
public void testEnumFail() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
final AttackerModel attacker = new AttackerModel();
final Field field = attacker.getClass().getDeclaredField("state");
UtilReflection.setAccessible(field, true);
field.set(attacker, AttackState.values()[3]);
try {
attacker.update(1.0);
Assert.fail();
} catch (final LionEngineException exception) {
Assert.assertEquals("Unknown enum: FAIL", exception.getMessage());
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class CollisionCategoryConfig method imports.
/**
* Create the category data from node.
*
* @param root The root reference (must not be <code>null</code>).
* @param map The map reference (must not be <code>null</code>).
* @return The category node instance.
* @throws LionEngineException If unable to read node.
*/
public static CollisionCategory imports(Xml root, MapTileCollision map) {
Check.notNull(root);
Check.notNull(map);
final Collection<Xml> children = root.getChildren(TileGroupsConfig.NODE_GROUP);
final Collection<CollisionGroup> groups = new ArrayList<>(children.size());
for (final Xml groupNode : children) {
final String groupName = groupNode.getText();
final CollisionGroup group = map.getCollisionGroup(groupName);
groups.add(group);
}
final String axisName = root.readString(ATT_AXIS);
final Axis axis;
try {
axis = Axis.valueOf(axisName);
} catch (final IllegalArgumentException exception) {
throw new LionEngineException(exception, ERROR_AXIS + axisName);
}
final int x = root.readInteger(ATT_X);
final int y = root.readInteger(ATT_Y);
final String name = root.readString(ATT_NAME);
return new CollisionCategory(name, axis, x, y, groups);
}
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.
* @return The setup instance.
*/
@SuppressWarnings("unchecked")
private Setup createSetup(Media media) {
final Configurer configurer = new Configurer(media);
try {
final FeaturableConfig config = FeaturableConfig.imports(configurer);
final String setup = config.getSetupName();
final Class<? extends Setup> setupClass;
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, 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 FeaturableModel method getClass.
/**
* Get the class reference from its name using cache.
*
* @param <T> The class type.
* @param className The class name.
* @return The typed class instance.
* @throws LionEngineException If invalid class.
*/
@SuppressWarnings("unchecked")
private static <T> Class<T> getClass(String className) {
if (CLASS_CACHE.containsKey(className)) {
return (Class<T>) CLASS_CACHE.get(className);
}
try {
final Class<?> clazz = LOADER.loadClass(className);
CLASS_CACHE.put(className, clazz);
return (Class<T>) clazz;
} catch (final ClassNotFoundException exception) {
throw new LionEngineException(exception, ERROR_CLASS_PRESENCE + className);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class FeaturableModel method getFeatures.
/**
* Get all available features.
* Default constructor of each feature must be available or with {@link Setup} as single parameter.
*
* @param services The services reference.
* @param setup The setup reference.
* @return The available features.
* @throws LionEngineException If invalid class.
*/
private static List<Feature> getFeatures(Services services, Setup setup) {
final Collection<Xml> children = setup.getRoot().getChildren(FeaturableConfig.NODE_FEATURE);
final List<Feature> features = new ArrayList<>(children.size());
for (final Xml featureNode : children) {
final String className = featureNode.getText();
final Feature feature;
try {
final Class<? extends Feature> clazz = getClass(className);
feature = UtilReflection.createReduce(clazz, services, setup);
} catch (final NoSuchMethodException exception) {
throw new LionEngineException(exception);
}
features.add(feature);
}
return features;
}
Aggregations