Search in sources :

Example 1 with Collision

use of de.gurkenlabs.litiengine.physics.Collision in project litiengine by gurkenlabs.

the class MapObjectSerializerTests method testSerialization.

@Test
void testSerialization() {
    Prop p = new Prop("something");
    // general entity fields
    p.setName("testname");
    p.setX(10);
    p.setY(10.5);
    p.setMapId(123);
    p.addTag("test");
    p.addTag("test2");
    // combat fields
    p.setIndestructible(true);
    p.setTeam(2);
    // collision fields
    p.setCollisionBoxAlign(Align.CENTER_LEFT);
    p.setCollisionBoxValign(Valign.MIDDLE_DOWN);
    p.setCollision(true);
    p.setCollisionBoxHeight(5);
    p.setCollisionBoxWidth(5);
    // prop fields
    p.setMaterial(Material.CERAMIC);
    p.setCollisionType(Collision.STATIC);
    p.setAddShadow(true);
    p.setSpriteRotation(Rotation.ROTATE_270);
    p.setFlipHorizontally(true);
    p.setFlipVertically(true);
    p.setScaling(true);
    IMapObject mapObject = MapObjectSerializer.serialize(p);
    assertEquals("testname", mapObject.getName());
    assertEquals(10, mapObject.getX());
    assertEquals(10.5, mapObject.getY());
    assertEquals(123, mapObject.getId());
    assertEquals("test,test2", mapObject.getStringValue(MapObjectProperty.TAGS));
    assertEquals(true, mapObject.getBoolValue(MapObjectProperty.COMBAT_INDESTRUCTIBLE));
    assertEquals(2, mapObject.getIntValue(MapObjectProperty.COMBAT_TEAM));
    assertEquals(Align.CENTER_LEFT, mapObject.getEnumValue(MapObjectProperty.COLLISION_ALIGN, Align.class));
    assertEquals(Valign.MIDDLE_DOWN, mapObject.getEnumValue(MapObjectProperty.COLLISION_VALIGN, Valign.class));
    assertEquals(true, mapObject.getBoolValue(MapObjectProperty.COLLISION));
    assertEquals(5, mapObject.getFloatValue(MapObjectProperty.COLLISIONBOX_WIDTH));
    assertEquals(5, mapObject.getFloatValue(MapObjectProperty.COLLISIONBOX_HEIGHT));
    assertEquals(Material.CERAMIC, Material.get(mapObject.getStringValue(MapObjectProperty.PROP_MATERIAL)));
    assertEquals(Collision.STATIC, mapObject.getEnumValue(MapObjectProperty.COLLISION_TYPE, Collision.class));
    assertEquals(true, mapObject.getBoolValue(MapObjectProperty.PROP_ADDSHADOW));
    assertEquals(Rotation.ROTATE_270, mapObject.getEnumValue(MapObjectProperty.PROP_ROTATION, Rotation.class));
    assertEquals(true, mapObject.getBoolValue(MapObjectProperty.PROP_FLIPHORIZONTALLY));
    assertEquals(true, mapObject.getBoolValue(MapObjectProperty.PROP_FLIPVERTICALLY));
    assertEquals(true, mapObject.getBoolValue(MapObjectProperty.SCALE_SPRITE));
}
Also used : Align(de.gurkenlabs.litiengine.Align) Valign(de.gurkenlabs.litiengine.Valign) Collision(de.gurkenlabs.litiengine.physics.Collision) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Align (de.gurkenlabs.litiengine.Align)1 Valign (de.gurkenlabs.litiengine.Valign)1 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)1 Collision (de.gurkenlabs.litiengine.physics.Collision)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1