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);
}
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);
}
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;
}
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();
}
}
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;
}
}
Aggregations