Search in sources :

Example 31 with Animation

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);
}
Also used : HashMap(java.util.HashMap) Animation(com.b3dgs.lionengine.Animation) XmlReader(com.b3dgs.lionengine.XmlReader)

Example 32 with Animation

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());
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.Xml) Collision(com.b3dgs.lionengine.game.feature.collidable.Collision) Media(com.b3dgs.lionengine.Media) Collection(java.util.Collection) Animation(com.b3dgs.lionengine.Animation) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 33 with Animation

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());
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.Xml) Collision(com.b3dgs.lionengine.game.feature.collidable.Collision) Media(com.b3dgs.lionengine.Media) Collection(java.util.Collection) Animation(com.b3dgs.lionengine.Animation) Configurer(com.b3dgs.lionengine.game.Configurer) Test(org.junit.jupiter.api.Test)

Example 34 with Animation

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);
}
Also used : HashMap(java.util.HashMap) Xml(com.b3dgs.lionengine.Xml) Collision(com.b3dgs.lionengine.game.feature.collidable.Collision) FactoryGraphicMock(com.b3dgs.lionengine.graphic.FactoryGraphicMock) Collection(java.util.Collection) Animation(com.b3dgs.lionengine.Animation) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 35 with Animation

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));
}
Also used : Animator(com.b3dgs.lionengine.Animator) AnimatableModel(com.b3dgs.lionengine.game.feature.AnimatableModel) TransformableModel(com.b3dgs.lionengine.game.feature.TransformableModel) Animation(com.b3dgs.lionengine.Animation) AnimatorModel(com.b3dgs.lionengine.AnimatorModel)

Aggregations

Animation (com.b3dgs.lionengine.Animation)41 Test (org.junit.jupiter.api.Test)19 Test (org.junit.Test)13 Animator (com.b3dgs.lionengine.Animator)9 SpriteAnimated (com.b3dgs.lionengine.graphic.SpriteAnimated)6 HashMap (java.util.HashMap)5 Xml (com.b3dgs.lionengine.Xml)4 AnimatorModel (com.b3dgs.lionengine.AnimatorModel)3 Media (com.b3dgs.lionengine.Media)3 AnimatableModel (com.b3dgs.lionengine.game.feature.AnimatableModel)3 TransformableModel (com.b3dgs.lionengine.game.feature.TransformableModel)3 Collision (com.b3dgs.lionengine.game.feature.collidable.Collision)3 Collection (java.util.Collection)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 AnimState (com.b3dgs.lionengine.AnimState)2 AnimatorListener (com.b3dgs.lionengine.AnimatorListener)2 LionEngineException (com.b3dgs.lionengine.LionEngineException)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 Configurer (com.b3dgs.lionengine.game.Configurer)2 Animatable (com.b3dgs.lionengine.game.feature.Animatable)2