use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class MapComponent method renderMapObjectBounds.
private void renderMapObjectBounds(Graphics2D g) {
// render all entities
for (final IMapObjectLayer layer : Game.getEnvironment().getMap().getMapObjectLayers()) {
if (layer == null) {
continue;
}
if (!EditorScreen.instance().getMapSelectionPanel().isVisibleMapObjectLayer(layer.getName())) {
continue;
}
Color colorBoundingBoxFill;
if (layer.getColor() != null) {
colorBoundingBoxFill = new Color(layer.getColor().getRed(), layer.getColor().getGreen(), layer.getColor().getBlue(), 15);
} else {
colorBoundingBoxFill = DEFAULT_COLOR_BOUNDING_BOX_FILL;
}
for (final IMapObject mapObject : layer.getMapObjects()) {
if (mapObject == null) {
continue;
}
MapObjectType type = MapObjectType.get(mapObject.getType());
final BasicStroke shapeStroke = new BasicStroke(1f / Game.getCamera().getRenderScale());
// render spawn points
if (type == MapObjectType.SPAWNPOINT) {
g.setColor(COLOR_SPAWNPOINT);
Game.getRenderEngine().renderShape(g, new Rectangle2D.Double(mapObject.getBoundingBox().getCenterX() - 1, mapObject.getBoundingBox().getCenterY() - 1, 2, 2));
} else if (type == MapObjectType.PATH) {
if (mapObject.getPolyline() == null || mapObject.getPolyline().getPoints().isEmpty()) {
continue;
}
// found the path for the rat
final Path2D path = MapUtilities.convertPolylineToPath(mapObject);
if (path == null) {
continue;
}
g.setColor(COLOR_LANE);
Game.getRenderEngine().renderOutline(g, path, shapeStroke);
Point2D start = new Point2D.Double(mapObject.getLocation().getX(), mapObject.getLocation().getY());
Game.getRenderEngine().renderShape(g, new Ellipse2D.Double(start.getX() - 1, start.getY() - 1, 3, 3));
Game.getRenderEngine().renderText(g, "#" + mapObject.getId() + "(" + mapObject.getName() + ")", start.getX(), start.getY() - 5);
}
if (type != MapObjectType.COLLISIONBOX) {
this.renderBoundingBox(g, mapObject, colorBoundingBoxFill, shapeStroke);
}
this.renderCollisionBox(g, mapObject, shapeStroke);
}
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject 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.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class MapComponent method ensureUniqueIds.
private void ensureUniqueIds(IMap map) {
int maxMapId = MapUtilities.getMaxMapId(map);
List<Integer> usedIds = new ArrayList<>();
for (IMapObject obj : map.getMapObjects()) {
if (usedIds.contains(obj.getId())) {
obj.setId(++maxMapId);
}
usedIds.add(obj.getId());
}
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject 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());
}
use of de.gurkenlabs.litiengine.environment.tilemap.IMapObject in project litiengine by gurkenlabs.
the class MapObjectLoaderTests method testPropMapObjectLoader.
@Test
public void testPropMapObjectLoader() {
PropMapObjectLoader loader = new PropMapObjectLoader();
IEnvironment environment = mock(IEnvironment.class);
IMapObject mapObject = mock(IMapObject.class);
when(mapObject.getType()).thenReturn(MapObjectType.PROP.name());
when(mapObject.getId()).thenReturn(111);
when(mapObject.getName()).thenReturn("testProp");
when(mapObject.getLocation()).thenReturn(new Point(100, 100));
when(mapObject.getDimension()).thenReturn(new Dimension(200, 200));
when(mapObject.getCustomProperty(MapObjectProperty.PROP_MATERIAL)).thenReturn(Material.PLASTIC.name());
when(mapObject.getCustomPropertyBool(MapObjectProperty.PROP_INDESTRUCTIBLE)).thenReturn(true);
when(mapObject.getCustomPropertyBool(MapObjectProperty.COLLISION)).thenReturn(true);
when(mapObject.getCustomPropertyInt(MapObjectProperty.HEALTH)).thenReturn(100);
when(mapObject.getCustomPropertyFloat(MapObjectProperty.COLLISIONBOX_WIDTH)).thenReturn(100.0f);
when(mapObject.getCustomPropertyFloat(MapObjectProperty.COLLISIONBOX_HEIGHT)).thenReturn(100.0f);
when(mapObject.getCustomProperty(MapObjectProperty.COLLISION_ALGIN)).thenReturn("LEFT");
when(mapObject.getCustomProperty(MapObjectProperty.COLLISION_VALGIN)).thenReturn("MIDDLE");
when(mapObject.getCustomPropertyInt(MapObjectProperty.TEAM)).thenReturn(1);
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(), "testProp");
assertEquals(entity.getLocation().getX(), 100, 0.0001);
assertEquals(entity.getLocation().getY(), 100, 0.0001);
Prop prop = (Prop) entity;
assertEquals(prop.getMaterial(), Material.PLASTIC);
assertTrue(prop.isIndestructible());
assertTrue(prop.hasCollision());
assertEquals(prop.getAttributes().getHealth().getMaxValue().intValue(), 100);
assertEquals(prop.getAttributes().getHealth().getCurrentValue().intValue(), 100);
assertEquals(prop.getCollisionBoxWidth(), 100.0, 0.0001);
assertEquals(prop.getCollisionBoxHeight(), 100.0, 0.0001);
assertEquals(prop.getCollisionBoxAlign(), Align.LEFT);
assertEquals(prop.getCollisionBoxValign(), Valign.MIDDLE);
assertEquals(prop.getTeam(), 1);
}
Aggregations