use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class MapAreaMapObjectLoader method load.
@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
if (MapObjectType.get(mapObject.getType()) != MapObjectType.AREA) {
throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + MapAreaMapObjectLoader.class);
}
Collection<IEntity> entities = super.load(environment, mapObject);
MapArea mapArea = this.createMapArea(mapObject);
loadDefaultProperties(mapArea, mapObject);
entities.add(mapArea);
return entities;
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class TriggerMapObjectLoader method load.
@Override
public Collection<IEntity> load(IEnvironment environment, IMapObject mapObject) {
if (MapObjectType.get(mapObject.getType()) != MapObjectType.TRIGGER) {
throw new IllegalArgumentException("Cannot load a mapobject of the type " + mapObject.getType() + " with a loader of the type " + TriggerMapObjectLoader.class);
}
final String message = mapObject.getCustomProperty(MapObjectProperty.TRIGGER_MESSAGE);
final TriggerActivation act = mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION) != null ? TriggerActivation.valueOf(mapObject.getCustomProperty(MapObjectProperty.TRIGGER_ACTIVATION)) : TriggerActivation.COLLISION;
final boolean oneTime = mapObject.getCustomPropertyBool(MapObjectProperty.TRIGGER_ONETIME);
final int coolDown = mapObject.getCustomPropertyInt(MapObjectProperty.TRIGGER_COOLDOWN);
final Trigger trigger = this.createTrigger(mapObject, act, message, oneTime, coolDown, mapObject);
loadDefaultProperties(trigger, mapObject);
this.loadTargets(mapObject, trigger);
this.loadActivators(mapObject, trigger);
Collection<IEntity> entities = super.load(environment, mapObject);
entities.add(trigger);
return entities;
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class MapComponent method handleEntityDrag.
private void handleEntityDrag(int snappedDeltaX, int snappedDeltaY) {
for (IMapObject selected : this.getSelectedMapObjects()) {
selected.setX(selected.getX() + snappedDeltaX);
selected.setY(selected.getY() + snappedDeltaY);
IEntity entity = Game.getEnvironment().get(selected.getId());
if (entity != null) {
entity.setX(selected.getLocation().getX());
entity.setY(selected.getLocation().getY());
} else {
Game.getEnvironment().reloadFromMap(selected.getId());
}
if (selected.equals(this.getFocusedMapObject())) {
EditorScreen.instance().getMapObjectPanel().bind(selected);
this.updateTransformControls();
}
}
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class EnvironmentEventTests method testOnAdded.
@Test
public void testOnAdded() {
ICombatEntity combatEntity = mock(ICombatEntity.class);
when(combatEntity.getMapId()).thenReturn(123);
when(combatEntity.getRenderType()).thenReturn(RenderType.NORMAL);
Consumer<IEntity> addedConsumer = (Consumer<IEntity>) mock(Consumer.class);
this.testEnvironment.onEntityAdded(addedConsumer);
this.testEnvironment.add(combatEntity);
verify(addedConsumer, times(1)).accept(combatEntity);
}
use of de.gurkenlabs.litiengine.entities.IEntity in project litiengine by gurkenlabs.
the class MapObjectLoaderTests method testLightSourceMapObjectLoader.
@Test
public void testLightSourceMapObjectLoader() {
LightSourceMapObjectLoader loader = new LightSourceMapObjectLoader();
IEnvironment environment = mock(IEnvironment.class);
IMapObject mapObject = mock(IMapObject.class);
when(mapObject.getType()).thenReturn(MapObjectType.LIGHTSOURCE.name());
when(mapObject.getId()).thenReturn(111);
when(mapObject.getName()).thenReturn("testLight");
when(mapObject.getLocation()).thenReturn(new Point(100, 100));
when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
when(mapObject.getCustomPropertyInt(MapObjectProperty.LIGHT_ALPHA)).thenReturn(100);
when(mapObject.getCustomPropertyInt(MapObjectProperty.LIGHT_INTENSITY, 100)).thenReturn(100);
when(mapObject.getCustomPropertyColor(MapObjectProperty.LIGHT_COLOR)).thenReturn(Color.WHITE);
when(mapObject.getCustomPropertyBool(MapObjectProperty.LIGHT_ACTIVE, true)).thenReturn(true);
when(mapObject.getCustomProperty(MapObjectProperty.LIGHT_SHAPE)).thenReturn(LightSource.ELLIPSE);
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(), "testLight");
assertEquals(entity.getLocation().getX(), 100, 0.0001);
assertEquals(entity.getLocation().getY(), 100, 0.0001);
LightSource light = (LightSource) entity;
assertTrue(light.isActive());
assertEquals(Color.WHITE.getRed(), light.getColor().getRed());
assertEquals(Color.WHITE.getBlue(), light.getColor().getBlue());
assertEquals(Color.WHITE.getGreen(), light.getColor().getGreen());
assertEquals(100, light.getColor().getAlpha());
assertEquals(100, light.getIntensity());
assertEquals(LightSource.ELLIPSE, light.getLightShapeType());
}
Aggregations