use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class MapTileGame method append.
@Override
public void append(Collection<MapTile> maps, int offsetX, int offsetY, int randX, int randY) {
int newWidth = widthInTile;
int newHeight = heightInTile;
final int[] randsX = new int[maps.size()];
final int[] randsY = new int[randsX.length];
int i = 0;
int tw = 0;
int th = 0;
for (final MapTile map : maps) {
randsX[i] = UtilRandom.getRandomInteger(randX);
randsY[i] = UtilRandom.getRandomInteger(randY);
newWidth += map.getInTileWidth() + randsX[i];
newHeight += map.getInTileHeight() + randsY[i];
if (tw == 0) {
tw = map.getTileWidth();
th = map.getTileHeight();
} else if (tw != map.getTileWidth() || th != map.getTileHeight()) {
throw new LionEngineException(ERROR_APPEND_MAP_TILE_SIZE + map.getTileWidth() + Constant.SPACE + map.getTileHeight());
}
i++;
}
if (!isCreated()) {
create(tw, th, 1, 1);
}
resize(newWidth, newHeight);
int ox = 0;
int oy = 0;
i = 0;
for (final MapTile map : maps) {
appendMap(map, ox, oy);
ox += map.getInTileWidth() * offsetX + randsX[i];
oy += map.getInTileHeight() * offsetY + randsY[i];
i++;
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class MapTileGame method loadSheets.
@Override
public void loadSheets(Collection<SpriteTiled> sheets) {
int sheetId = 0;
for (final SpriteTiled sheet : sheets) {
this.sheets.put(Integer.valueOf(sheetId), sheet);
if ((tileWidth != 0 || tileHeight != 0) && tileWidth != sheet.getTileWidth() && tileHeight != sheet.getTileHeight()) {
throw new LionEngineException(ERROR_TILE_SIZE);
}
tileWidth = sheet.getTileWidth();
tileHeight = sheet.getTileHeight();
sheetId++;
}
}
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(Xml parent) {
Check.notNull(parent);
final Xml node = parent.getChild(FUNCTION);
final String name = node.readString(TYPE);
try {
final CollisionFunctionType type = CollisionFunctionType.valueOf(name);
switch(type) {
case LINEAR:
return new CollisionFunctionLinear(node.readDouble(A), node.readDouble(B));
default:
throw new LionEngineException(ERROR_TYPE + name);
}
} catch (final IllegalArgumentException exception) {
throw new LionEngineException(exception, ERROR_TYPE + name);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class Configurer method getImplementation.
/**
* Get the class implementation from its name by using a custom constructor.
*
* @param <T> The instance type.
* @param loader The class loader to use.
* @param type The class type.
* @param paramsType The parameters type.
* @param paramsValue The parameters value.
* @param className The class name.
* @return The typed class instance.
* @throws LionEngineException If invalid class.
*/
public static final <T> T getImplementation(ClassLoader loader, Class<T> type, Class<?>[] paramsType, Collection<?> paramsValue, String className) {
try {
if (!CLASS_CACHE.containsKey(className)) {
final Class<?> clazz = loader.loadClass(className);
CLASS_CACHE.put(className, clazz);
}
final Class<?> clazz = CLASS_CACHE.get(className);
final Constructor<?> constructor = UtilReflection.getCompatibleConstructor(clazz, paramsType);
if (!constructor.isAccessible()) {
UtilReflection.setAccessible(constructor, true);
}
return type.cast(constructor.newInstance(paramsValue.toArray()));
} catch (final InstantiationException | IllegalArgumentException | InvocationTargetException exception) {
throw new LionEngineException(exception, ERROR_CLASS_INSTANCE + className);
} catch (final NoSuchMethodException exception) {
throw new LionEngineException(exception, ERROR_CLASS_CONSTRUCTOR + className);
} catch (final IllegalAccessException exception) {
throw new LionEngineException(exception, ERROR_CLASS_ACCESSIBILITY + className);
} 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 DocumentFactoryTest method testMissingFeature.
/**
* Test missing feature.
*
* @throws Exception If error.
*/
@Test
public void testMissingFeature() throws Exception {
final Object old = UtilReflection.getField(DocumentFactory.class, "documentBuilder");
final Field field = DocumentFactory.class.getDeclaredField("documentBuilder");
UtilReflection.setAccessible(field, true);
field.set(DocumentFactory.class, null);
final String oldFactory = System.getProperty(DocumentBuilderFactory.class.getName());
System.setProperty(DocumentBuilderFactory.class.getName(), Factory.class.getName());
try {
Verbose.info("*********************************** EXPECTED VERBOSE ***********************************");
try {
Assert.assertNull(DocumentFactory.createDocument());
Assert.fail();
} catch (final LionEngineException exception) {
Assert.assertTrue(exception.getCause() instanceof ParserConfigurationException);
}
Verbose.info("****************************************************************************************");
} finally {
if (oldFactory != null) {
System.setProperty(DocumentBuilderFactory.class.getName(), oldFactory);
} else {
System.setProperty(DocumentBuilderFactory.class.getName(), "");
}
field.set(DocumentFactory.class, old);
UtilReflection.setAccessible(field, false);
}
}
Aggregations