use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class AnimationConfig method imports.
/**
* Create the animation data from configurer.
*
* @param root The root reference (must not be <code>null</code>).
* @return The animations configuration instance.
* @throws LionEngineException If unable to read data.
*/
public static AnimationConfig imports(XmlReader root) {
Check.notNull(root);
final Map<String, Animation> animations = new HashMap<>(0);
if (root.hasNode(NODE_ANIMATIONS)) {
final Collection<XmlReader> children = root.getChild(NODE_ANIMATIONS).getChildren(NODE_ANIMATION);
for (final XmlReader node : children) {
final String anim = node.getString(ANIMATION_NAME);
final Animation animation = createAnimation(node);
animations.put(anim, animation);
}
children.clear();
}
return new AnimationConfig(animations);
}
use of com.b3dgs.lionengine.Animation 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.Animation 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.Animation 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);
}
use of com.b3dgs.lionengine.Animation in project lionengine by b3dgs.
the class UtilAttackable method prepare.
/**
* Create the featurable.
*
* @param featurable The featurable to prepare.
* @param services The services reference.
* @param setup The setup reference.
*/
public static void prepare(Featurable featurable, Services services, Setup setup) {
final Animator animator = new AnimatorModel();
animator.play(new Animation("test", 1, 1, 1.0, false, false));
featurable.addFeature(new AnimatableModel(services, setup, animator));
featurable.addFeature(new TransformableModel(services, setup));
}
Aggregations