Search in sources :

Example 6 with MapObject

use of de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject in project litiengine by gurkenlabs.

the class UndoManager method restoreState.

private static void restoreState(IMapObject target, IMapObject restore) {
    target.setId(restore.getId());
    target.setName(restore.getName());
    target.setType(restore.getType());
    target.setX(restore.getX());
    target.setY(restore.getY());
    target.setWidth(restore.getWidth());
    target.setHeight(restore.getHeight());
    target.getAllCustomProperties().clear();
    for (Property prop : restore.getAllCustomProperties()) {
        target.setCustomProperty(prop.getName(), prop.getValue());
    }
    Game.getEnvironment().reloadFromMap(target.getId());
    if (MapObjectType.get(target.getType()) == MapObjectType.LIGHTSOURCE) {
        Game.getEnvironment().getAmbientLight().updateSection(MapObject.getBounds2D((MapObject) target, (MapObject) restore));
    }
    if (EditorScreen.instance().getMapComponent().getFocusedMapObject() != null && EditorScreen.instance().getMapComponent().getFocusedMapObject().getId() == target.getId()) {
        EditorScreen.instance().getMapObjectPanel().bind(target);
        EditorScreen.instance().getMapSelectionPanel().focus(target);
    }
}
Also used : Property(de.gurkenlabs.litiengine.environment.tilemap.xml.Property) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 7 with MapObject

use of de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject in project litiengine by gurkenlabs.

the class MapComponent method createNewMapObject.

private IMapObject createNewMapObject(MapObjectType type) {
    IMapObject mo = new MapObject();
    mo.setType(type.toString());
    mo.setX((int) this.newObjectArea.getX());
    mo.setY((int) this.newObjectArea.getY());
    mo.setWidth((int) this.newObjectArea.getWidth());
    mo.setHeight((int) this.newObjectArea.getHeight());
    mo.setId(Game.getEnvironment().getNextMapId());
    mo.setName("");
    switch(type) {
        case PROP:
            mo.setCustomProperty(MapObjectProperty.COLLISIONBOX_WIDTH, (this.newObjectArea.getWidth() * 0.4) + "");
            mo.setCustomProperty(MapObjectProperty.COLLISIONBOX_HEIGHT, (this.newObjectArea.getHeight() * 0.4) + "");
            mo.setCustomProperty(MapObjectProperty.COLLISION, "true");
            mo.setCustomProperty(MapObjectProperty.PROP_INDESTRUCTIBLE, "false");
            mo.setCustomProperty(MapObjectProperty.PROP_ADDSHADOW, "true");
            break;
        case LIGHTSOURCE:
            mo.setCustomProperty(MapObjectProperty.LIGHT_ALPHA, "180");
            mo.setCustomProperty(MapObjectProperty.LIGHT_COLOR, "#ffffff");
            mo.setCustomProperty(MapObjectProperty.LIGHT_SHAPE, LightSource.ELLIPSE);
            mo.setCustomProperty(MapObjectProperty.LIGHT_ACTIVE, "true");
            break;
        case SPAWNPOINT:
        default:
            break;
    }
    this.add(mo);
    return mo;
}
Also used : IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) IMapObject(de.gurkenlabs.litiengine.environment.tilemap.IMapObject)

Example 8 with MapObject

use of de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject in project litiengine by gurkenlabs.

the class AssetPanel method loadBlueprints.

public void loadBlueprints(List<Blueprint> blueprints) {
    this.load(blueprints, () -> {
        Collections.sort(blueprints);
        for (MapObject blueprint : blueprints) {
            AssetPanelItem panelItem = new AssetPanelItem(Icons.DOC_BLUEPRINT, blueprint.getName(), blueprint);
            this.add(panelItem);
            panelItem.validate();
        }
    });
}
Also used : MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)

Example 9 with MapObject

use of de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject in project litiengine by gurkenlabs.

the class AssetPanelItem method addEntity.

private boolean addEntity() {
    // TODO: experimental code... this needs to be refactored with issue #66
    if (this.getOrigin() instanceof SpriteSheetInfo) {
        SpriteSheetInfo info = (SpriteSheetInfo) this.getOrigin();
        String propName = PropPanel.getNameBySpriteName(info.getName());
        if (propName == null) {
            return false;
        }
        MapObject mo = new MapObject();
        mo.setType(MapObjectType.PROP.name());
        mo.setX((int) Game.getCamera().getFocus().getX() - info.getWidth() / 2);
        mo.setY((int) Game.getCamera().getFocus().getY() - info.getHeight() / 2);
        mo.setWidth((int) info.getWidth());
        mo.setHeight((int) info.getHeight());
        mo.setId(Game.getEnvironment().getNextMapId());
        mo.setName("");
        mo.setCustomProperty(MapObjectProperty.COLLISIONBOX_WIDTH, (info.getWidth() * 0.4) + "");
        mo.setCustomProperty(MapObjectProperty.COLLISIONBOX_HEIGHT, (info.getHeight() * 0.4) + "");
        mo.setCustomProperty(MapObjectProperty.COLLISION, "true");
        mo.setCustomProperty(MapObjectProperty.PROP_INDESTRUCTIBLE, "false");
        mo.setCustomProperty(MapObjectProperty.PROP_ADDSHADOW, "true");
        mo.setCustomProperty(MapObjectProperty.SPRITESHEETNAME, propName);
        EditorScreen.instance().getMapComponent().add(mo);
        return true;
    } else if (this.getOrigin() instanceof EmitterData) {
        MapObject newEmitter = (MapObject) EmitterMapObjectLoader.createMapObject((EmitterData) this.getOrigin());
        newEmitter.setX((int) (Game.getCamera().getFocus().getX() - newEmitter.getWidth()));
        newEmitter.setY((int) (Game.getCamera().getFocus().getY() - newEmitter.getHeight()));
        newEmitter.setId(Game.getEnvironment().getNextMapId());
        EditorScreen.instance().getMapComponent().add(newEmitter);
    } else if (this.getOrigin() instanceof Blueprint) {
        Blueprint blueprint = (Blueprint) this.getOrigin();
        UndoManager.instance().beginOperation();
        try {
            List<MapObject> newObjects = blueprint.build((int) Game.getCamera().getFocus().getX() - blueprint.getWidth() / 2, (int) Game.getCamera().getFocus().getY() - blueprint.getHeight() / 2);
            for (MapObject newMapObject : newObjects) {
                EditorScreen.instance().getMapComponent().add(newMapObject);
            }
            // gets added
            for (MapObject newMapObject : newObjects) {
                EditorScreen.instance().getMapComponent().setSelection(newMapObject, false);
            }
        } finally {
            UndoManager.instance().endOperation();
        }
    }
    return false;
}
Also used : SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) EmitterData(de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData)

Example 10 with MapObject

use of de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject in project litiengine by gurkenlabs.

the class AssetPanelItem method canAdd.

private boolean canAdd() {
    if (this.getOrigin() != null && this.getOrigin() instanceof SpriteSheetInfo) {
        SpriteSheetInfo info = (SpriteSheetInfo) this.getOrigin();
        String propName = PropPanel.getNameBySpriteName(info.getName());
        return propName != null && !propName.isEmpty();
    }
    return this.getOrigin() instanceof MapObject || this.getOrigin() instanceof EmitterData;
}
Also used : SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) MapObject(de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject) EmitterData(de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData)

Aggregations

MapObject (de.gurkenlabs.litiengine.environment.tilemap.xml.MapObject)10 IMapObject (de.gurkenlabs.litiengine.environment.tilemap.IMapObject)7 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)3 SpriteSheetInfo (de.gurkenlabs.litiengine.SpriteSheetInfo)2 EmitterData (de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData)2 Property (de.gurkenlabs.litiengine.environment.tilemap.xml.Property)1