use of com.b3dgs.lionengine.game.feature.collidable.Collision in project lionengine by b3dgs.
the class CollidableFramedModel method recycle.
/*
* CollidableFramed
*/
@Override
public void recycle() {
for (final Collision collision : config.getCollisions()) {
collidable.addCollision(collision);
collidable.setEnabled(false, collision);
}
animatable.addListener((AnimatorFrameListener) frame -> {
for (final Collision collision : last) {
collidable.setEnabled(false, collision);
}
last = config.getCollision(Integer.valueOf(frame));
for (final Collision collision : last) {
collidable.setEnabled(true, collision);
collidable.forceUpdate();
}
});
}
use of com.b3dgs.lionengine.game.feature.collidable.Collision in project lionengine by b3dgs.
the class CollidableFramedConfig method importFrame.
/**
* Import frame collision data.
*
* @param node The node root reference.
* @param framed The framed node reference.
* @param start The collision start number.
* @param collisions The imported collisions.
*/
private static void importFrame(XmlReader node, XmlReader framed, int start, Map<Integer, Collection<Collision>> collisions) {
final String name = getFrameName(node, framed);
if (framed.hasAttribute(ATT_NUMBER)) {
final int number = start + framed.getInteger(ATT_NUMBER);
final Collision collision = createCollision(name, framed, number - start);
final Integer key = Integer.valueOf(number - 1);
collisions.computeIfAbsent(key, k -> new ArrayList<>()).add(collision);
} else {
final int end = node.getInteger(AnimationConfig.ANIMATION_END);
for (int number = start; number <= end; number++) {
final Collision collision = createCollision(name, framed, number - start + 1);
final Integer key = Integer.valueOf(number);
collisions.computeIfAbsent(key, k -> new ArrayList<>()).add(collision);
}
}
}
use of com.b3dgs.lionengine.game.feature.collidable.Collision in project lionengine by b3dgs.
the class CollidableFramedConfigTest method testExportsImports.
/**
* Test exports imports.
*/
@Test
void testExportsImports() {
final Map<Integer, Collection<Collision>> collisions = new HashMap<>();
collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("anim%1", 0, 1, 2, 3, true)));
final CollidableFramedConfig config = new CollidableFramedConfig(collisions);
final Xml root = new Xml("test");
final Animation animation = new Animation("anim", 1, 2, 3.0, false, true);
AnimationConfig.exports(root, animation);
final Xml framed = root.getChildXml(AnimationConfig.NODE_ANIMATIONS).getChildXml(AnimationConfig.NODE_ANIMATION);
CollidableFramedConfig.exports(framed, collisions);
final Media media = Medias.create("Object.xml");
root.save(media);
assertEquals(config, CollidableFramedConfig.imports(new Configurer(media)));
assertEquals(collisions.values().iterator().next(), config.getCollisions());
assertEquals(collisions.get(Integer.valueOf(1)), config.getCollision(Integer.valueOf(1)));
assertTrue(config.getCollision(Integer.valueOf(2)).isEmpty());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.collidable.Collision in project lionengine by b3dgs.
the class CollidableFramedConfigTest method testExportsImportsNumber.
/**
* Test exports imports with number.
*/
@Test
void testExportsImportsNumber() {
final Map<Integer, Collection<Collision>> collisions = new HashMap<>();
collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("coll%anim%1", 0, 1, 2, 3, true)));
final Xml root = new Xml("test");
final Animation animation = new Animation("anim", 1, 2, 3.0, false, true);
AnimationConfig.exports(root, animation);
final Xml framed = root.getChildXml(AnimationConfig.NODE_ANIMATIONS).getChildXml(AnimationConfig.NODE_ANIMATION);
CollidableFramedConfig.exports(framed, collisions);
framed.getChildXml(CollidableFramedConfig.NODE_COLLISION_FRAMED).removeAttribute(CollidableFramedConfig.ATT_NUMBER);
framed.getChildXml(CollidableFramedConfig.NODE_COLLISION_FRAMED).writeString(CollidableFramedConfig.ATT_PREFIX, "coll");
final Media media = Medias.create("Object.xml");
root.save(media);
final CollidableFramedConfig imported = CollidableFramedConfig.imports(new Configurer(media));
assertEquals(collisions.get(Integer.valueOf(1)), imported.getCollision(Integer.valueOf(1)));
assertFalse(imported.getCollision(Integer.valueOf(2)).isEmpty());
assertTrue(media.getFile().delete());
}
use of com.b3dgs.lionengine.game.feature.collidable.Collision in project lionengine by b3dgs.
the class CollidableFramedModelTest method beforeTests.
/**
* Prepare test.
*/
@BeforeAll
public static void beforeTests() {
Graphics.setFactoryGraphic(new FactoryGraphicMock());
Medias.setResourcesDirectory(System.getProperty("java.io.tmpdir"));
config = UtilSetup.createConfig(CollidableFramedModelTest.class);
final Map<Integer, Collection<Collision>> collisions = new HashMap<>();
collisions.put(Integer.valueOf(1), Arrays.asList(new Collision("anim%1", 0, 0, 2, 2, false)));
final Xml root = new Xml(config);
AnimationConfig.exports(root, new Animation("anim", 1, 2, 1.0, false, false));
final Xml framed = root.getChildXml(AnimationConfig.NODE_ANIMATIONS).getChildXml(AnimationConfig.NODE_ANIMATION);
CollidableFramedConfig.exports(framed, collisions);
root.save(config);
}
Aggregations