Search in sources :

Example 1 with IMapObject

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.

the class MapObjectLoaderTests method testEmitterMapObjectLoader.

@Test
public void testEmitterMapObjectLoader() {
    EmitterMapObjectLoader loader = new EmitterMapObjectLoader();
    IEnvironment environment = mock(IEnvironment.class);
    IMapObject mapObject = mock(IMapObject.class);
    when(mapObject.getType()).thenReturn(MapObjectType.EMITTER.name());
    when(mapObject.getId()).thenReturn(111);
    when(mapObject.getName()).thenReturn("testEmitter");
    when(mapObject.getLocation()).thenReturn(new Point(100, 100));
    when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
    Collection<IEntity> entities = loader.load(environment, mapObject);
    Optional<IEntity> opt = entities.stream().findFirst();
    assertTrue(opt.isPresent());
    IEntity entity = entities.stream().findFirst().get();
    assertNotNull(entity);
    assertEquals(entity.getMapId(), 111);
    assertEquals(entity.getName(), "testEmitter");
    assertEquals(entity.getLocation().getX(), 100, 0.0001);
    assertEquals(entity.getLocation().getY(), 100, 0.0001);
}
Also used : IEntity(de.gurkenlabs.litiengine.entities.IEntity) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Point(java.awt.Point) Dimension(java.awt.Dimension) Test(org.junit.jupiter.api.Test)

Example 2 with IMapObject

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.

the class MapObjectLoaderTests method testTriggerMapObjectLoader.

@Test
public void testTriggerMapObjectLoader() {
    TriggerMapObjectLoader loader = new TriggerMapObjectLoader();
    IEnvironment environment = mock(IEnvironment.class);
    IMapObject mapObject = mock(IMapObject.class);
    when(mapObject.getType()).thenReturn(MapObjectType.TRIGGER.name());
    when(mapObject.getId()).thenReturn(111);
    when(mapObject.getName()).thenReturn("testTrigger");
    when(mapObject.getLocation()).thenReturn(new Point(100, 100));
    when(mapObject.getWidth()).thenReturn(200);
    when(mapObject.getHeight()).thenReturn(200);
    when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
    when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_MESSAGE)).thenReturn("message");
    when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION)).thenReturn(TriggerActivation.INTERACT.name());
    when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_TARGETS)).thenReturn("1,2,3");
    when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATORS)).thenReturn("4,5,6");
    when(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ONETIME)).thenReturn("false");
    Collection<IEntity> entities = loader.load(environment, mapObject);
    Optional<IEntity> opt = entities.stream().findFirst();
    assertTrue(opt.isPresent());
    IEntity entity = entities.stream().findFirst().get();
    assertNotNull(entity);
    assertEquals(entity.getMapId(), 111);
    assertEquals(entity.getName(), "testTrigger");
    assertEquals(entity.getLocation().getX(), 100, 0.0001);
    assertEquals(entity.getLocation().getY(), 100, 0.0001);
    Trigger trigger = (Trigger) entity;
    assertFalse(trigger.isOneTimeTrigger());
    assertEquals(TriggerActivation.INTERACT, trigger.getActivationType());
    assertArrayEquals(new Integer[] { 1, 2, 3 }, trigger.getTargets().toArray());
    assertArrayEquals(new Integer[] { 4, 5, 6 }, trigger.getActivators().toArray());
    assertEquals(200.0, trigger.getCollisionBoxWidth(), 0.0001);
    assertEquals(200.0, trigger.getCollisionBoxHeight(), 0.0001);
}
Also used : Trigger(de.gurkenlabs.litiengine.entities.Trigger) IEntity(de.gurkenlabs.litiengine.entities.IEntity) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) Point(java.awt.Point) Dimension(java.awt.Dimension) Test(org.junit.jupiter.api.Test)

Example 3 with IMapObject

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.

the class UndoManager method clone.

private static IMapObject clone(IMapObject mapObject) {
    MapObject clonedObject = new MapObject();
    clonedObject.setId(mapObject.getId());
    clonedObject.setName(mapObject.getName() != null ? mapObject.getName() : "");
    clonedObject.setType(mapObject.getType() != null ? mapObject.getType() : "");
    clonedObject.setX(mapObject.getX());
    clonedObject.setY(mapObject.getY());
    clonedObject.setWidth(mapObject.getWidth());
    clonedObject.setHeight(mapObject.getHeight());
    clonedObject.setCustomProperties(mapObject.getAllCustomProperties().stream().collect(Collectors.toList()));
    return clonedObject;
}
Also used : MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 4 with IMapObject

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.

the class MapComponent method delete.

public void delete() {
    UndoManager.instance().beginOperation();
    try {
        for (IMapObject deleteObject : this.getSelectedMapObjects()) {
            if (deleteObject == null) {
                continue;
            }
            this.delete(deleteObject);
            UndoManager.instance().mapObjectDeleted(deleteObject);
        }
    } finally {
        UndoManager.instance().endOperation();
    }
}
Also used : IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 5 with IMapObject

use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.

the class MapComponent method setFocus.

public void setFocus(IMapObject mapObject, boolean clearSelection) {
    if (this.isFocussing) {
        return;
    }
    this.isFocussing = true;
    try {
        final IMapObject currentFocus = this.getFocusedMapObject();
        if (mapObject != null && currentFocus != null && mapObject.equals(currentFocus) || mapObject == null && currentFocus == null) {
            return;
        }
        if (Game.getEnvironment() == null || Game.getEnvironment().getMap() == null) {
            return;
        }
        if (this.isMoving || this.isTransforming) {
            return;
        }
        EditorScreen.instance().getMapObjectPanel().bind(mapObject);
        EditorScreen.instance().getMapSelectionPanel().focus(mapObject);
        if (mapObject == null) {
            this.focusedObjects.remove(Game.getEnvironment().getMap().getFileName());
        } else {
            this.focusedObjects.put(Game.getEnvironment().getMap().getFileName(), mapObject);
        }
        for (Consumer<IMapObject> cons : this.focusChangedConsumer) {
            cons.accept(mapObject);
        }
        this.updateTransformControls();
        this.setSelection(mapObject, clearSelection);
    } finally {
        this.isFocussing = false;
    }
}
Also used : IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Aggregations

IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)23 IEntity (de.gurkenlabs.litiengine.entities.IEntity)7 Dimension (java.awt.Dimension)6 Point (java.awt.Point)5 Test (org.junit.jupiter.api.Test)5 MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)4 Point2D (java.awt.geom.Point2D)4 Rectangle2D (java.awt.geom.Rectangle2D)4 IMapObjectLayer (de.gurkenlabs.litiengine.environment.tilemap.IMapObjectLayer)3 MapObjectType (de.gurkenlabs.litiengine.environment.tilemap.MapObjectType)3 BasicStroke (java.awt.BasicStroke)3 CollisionBox (de.gurkenlabs.litiengine.entities.CollisionBox)2 Prop (de.gurkenlabs.litiengine.entities.Prop)2 Trigger (de.gurkenlabs.litiengine.entities.Trigger)2 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)2 LightSource (de.gurkenlabs.litiengine.graphics.LightSource)2 Color (java.awt.Color)2 Stroke (java.awt.Stroke)2 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2