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(XmlReader root, MapTileCollision map) {
Check.notNull(root);
Check.notNull(map);
final Collection<XmlReader> children = root.getChildren(TileGroupsConfig.NODE_GROUP);
final Collection<CollisionGroup> groups = new ArrayList<>(children.size());
for (final XmlReader groupNode : children) {
final String groupName = groupNode.getText();
map.getCollisionGroup(groupName).ifPresent(groups::add);
}
children.clear();
final String axisName = root.getString(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.getInteger(ATT_X);
final int y = root.getInteger(ATT_Y);
final boolean glue = root.getBoolean(true, ATT_GLUE);
final String name = root.getString(ATT_NAME);
return new CollisionCategory(name, axis, x, y, glue, groups);
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class MapTileAppenderModel method append.
@Override
public void append(Collection<MapTile> maps, int offsetX, int offsetY, int randX, int randY) {
int newWidth = map.getInTileWidth();
int newHeight = map.getInTileHeight();
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 current : maps) {
randsX[i] = UtilRandom.getRandomInteger(randX);
randsY[i] = UtilRandom.getRandomInteger(randY);
newWidth += current.getInTileWidth() + randsX[i];
newHeight += current.getInTileHeight() + randsY[i];
if (tw == 0) {
tw = current.getTileWidth();
th = current.getTileHeight();
} else if (tw != current.getTileWidth() || th != current.getTileHeight()) {
throw new LionEngineException(ERROR_APPEND_MAP_TILE_SIZE + current.getTileWidth() + Constant.SPACE + current.getTileHeight());
}
i++;
}
if (!map.isCreated()) {
map.create(tw, th, 1, 1);
}
map.resize(newWidth, newHeight);
int ox = 0;
int oy = 0;
i = 0;
for (final MapTile current : maps) {
appendMap(current, ox, oy);
ox += current.getInTileWidth() * offsetX + randsX[i];
oy += current.getInTileHeight() * offsetY + randsY[i];
i++;
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class FactoryGraphicAwt 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 Transparency transparency = images[0].getTransparency();
final int multDistance = (int) Math.ceil(width * images.length / (double) height) / 4;
final int[] mult = UtilMath.getClosestSquareMult(images.length, multDistance);
final ImageBuffer tile = new ImageBufferAwt(ToolsAwt.createImage(width * mult[1], height * mult[0], ToolsAwt.getTransparency(transparency)));
int x = 0;
int y = 0;
int line = 0;
final Graphic g = tile.createGraphic();
for (final ImageBuffer b : images) {
g.drawImage(b, x, y);
x += b.getWidth();
line++;
if (line == mult[1]) {
x = 0;
y += b.getHeight();
line = 0;
}
}
g.dispose();
saveImage(tile, media);
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class UtilSequence method create.
/**
* Create a sequence from its class.
*
* @param nextSequence The next sequence class (must not be <code>null</code>).
* @param context The context reference (must not be <code>null</code>).
* @param arguments The arguments list (must not be <code>null</code>).
* @return The sequence instance.
* @throws LionEngineException If not able to create the sequence for any reason.
*/
public static Sequencable create(Class<? extends Sequencable> nextSequence, Context context, Object... arguments) {
Check.notNull(nextSequence);
Check.notNull(context);
Check.notNull(arguments);
try {
final Class<?>[] params = getParamTypes(context, arguments);
return UtilReflection.create(nextSequence, params, getParams(context, arguments));
} catch (final NoSuchMethodException exception) {
throw new LionEngineException(exception);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class AudioFactory method loadAudio.
/**
* Load an audio file and prepare it to be played.
*
* @param <A> The audio type.
* @param media The audio media (must not be <code>null</code>).
* @param type The expected audio type (must not be <code>null</code>).
* @return The loaded audio.
* @throws LionEngineException If invalid arguments or invalid audio.
*/
public static synchronized <A extends Audio> A loadAudio(Media media, Class<A> type) {
Check.notNull(media);
Check.notNull(type);
final String extension = UtilFile.getExtension(media.getPath());
try {
return type.cast(Optional.ofNullable(FACTORIES.get(extension)).orElseThrow(() -> new LionEngineException(media, ERROR_FORMAT)).loadAudio(media));
} catch (final ClassCastException exception) {
throw new LionEngineException(exception, media, ERROR_FORMAT);
}
}
Aggregations