Search in sources :

Example 6 with SceneActorRef

use of com.bladecoder.engine.actions.SceneActorRef in project bladecoder-adventure-engine by bladecoder.

the class Inventory method read.

@Override
public void read(Json json, JsonValue jsonData) {
    visible = json.readValue("visible", Boolean.class, jsonData);
    items.clear();
    JsonValue jsonValueActors = jsonData.get("items");
    SceneActorRef actorRef;
    // GET ACTORS FROM HIS INIT SCENE.
    for (int i = 0; i < jsonValueActors.size; i++) {
        JsonValue jsonValueAct = jsonValueActors.get(i);
        actorRef = new SceneActorRef(jsonValueAct.name);
        Scene sourceScn = World.getInstance().getScene(actorRef.getSceneId());
        BaseActor actor = sourceScn.getActor(actorRef.getActorId(), false);
        sourceScn.removeActor(actor);
        addItem((SpriteActor) actor);
    }
    // The state must be retrieved after getting actors from his init scene to restore verb cb properly.
    for (int i = 0; i < jsonValueActors.size; i++) {
        JsonValue jsonValueAct = jsonValueActors.get(i);
        actorRef = new SceneActorRef(jsonValueAct.name);
        SpriteActor actor = items.get(i);
        actor.read(json, jsonValueAct);
    }
}
Also used : SceneActorRef(com.bladecoder.engine.actions.SceneActorRef) JsonValue(com.badlogic.gdx.utils.JsonValue)

Example 7 with SceneActorRef

use of com.bladecoder.engine.actions.SceneActorRef in project bladecoder-adventure-engine by bladecoder.

the class Scene method read.

@SuppressWarnings("unchecked")
@Override
public void read(Json json, JsonValue jsonData) {
    if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
        id = json.readValue("id", String.class, jsonData);
        layers = json.readValue("layers", ArrayList.class, SceneLayer.class, jsonData);
        actors = json.readValue("actors", HashMap.class, BaseActor.class, jsonData);
        for (BaseActor actor : actors.values()) {
            actor.setScene(this);
            actor.setInitScene(id);
            if (actor instanceof InteractiveActor) {
                InteractiveActor ia = (InteractiveActor) actor;
                SceneLayer layer = getLayer(ia.getLayer());
                layer.add(ia);
            }
        }
        orderLayersByZIndex();
        backgroundAtlas = json.readValue("backgroundAtlas", String.class, jsonData);
        backgroundRegionId = json.readValue("backgroundRegionId", String.class, jsonData);
        musicDesc = json.readValue("musicDesc", MusicDesc.class, jsonData);
        depthVector = json.readValue("depthVector", Vector2.class, jsonData);
        polygonalNavGraph = json.readValue("polygonalNavGraph", PolygonalNavGraph.class, jsonData);
        sceneSize = json.readValue("sceneSize", Vector2.class, jsonData);
    } else {
        JsonValue jsonValueActors = jsonData.get("actors");
        SceneActorRef actorRef;
        // GET ACTORS FROM HIS INIT SCENE AND MOVE IT TO THE LOADING SCENE.
        for (int i = 0; i < jsonValueActors.size; i++) {
            JsonValue jsonValueAct = jsonValueActors.get(i);
            actorRef = new SceneActorRef(jsonValueAct.name);
            Scene sourceScn = World.getInstance().getScene(actorRef.getSceneId());
            if (sourceScn != this) {
                BaseActor actor = sourceScn.getActor(actorRef.getActorId(), false);
                sourceScn.removeActor(actor);
                addActor(actor);
            }
        }
        // scene to restore verb cb properly.
        for (int i = 0; i < jsonValueActors.size; i++) {
            JsonValue jsonValueAct = jsonValueActors.get(i);
            actorRef = new SceneActorRef(jsonValueAct.name);
            BaseActor actor = getActor(actorRef.getActorId(), false);
            if (actor != null)
                actor.read(json, jsonValueAct);
            else
                EngineLogger.debug("Actor not found: " + actorRef);
        }
        orderLayersByZIndex();
        camera = json.readValue("camera", SceneCamera.class, jsonData);
        String followActorId = json.readValue("followActor", String.class, jsonData);
        setCameraFollowActor((SpriteActor) actors.get(followActorId));
        soundManager.read(json, jsonData);
    }
    verbs.read(json, jsonData);
    state = json.readValue("state", String.class, jsonData);
    player = json.readValue("player", String.class, jsonData);
}
Also used : HashMap(java.util.HashMap) SceneActorRef(com.bladecoder.engine.actions.SceneActorRef) ArrayList(java.util.ArrayList) JsonValue(com.badlogic.gdx.utils.JsonValue) PolygonalNavGraph(com.bladecoder.engine.polygonalpathfinder.PolygonalNavGraph) Vector2(com.badlogic.gdx.math.Vector2)

Example 8 with SceneActorRef

use of com.bladecoder.engine.actions.SceneActorRef in project bladecoder-adventure-engine by bladecoder.

the class Scene method write.

@Override
public void write(Json json) {
    if (SerializationHelper.getInstance().getMode() == Mode.MODEL) {
        json.writeValue("id", id);
        json.writeValue("layers", layers, layers.getClass(), SceneLayer.class);
        json.writeValue("actors", actors);
        if (backgroundAtlas != null) {
            json.writeValue("backgroundAtlas", backgroundAtlas);
            json.writeValue("backgroundRegionId", backgroundRegionId);
        }
        json.writeValue("musicDesc", musicDesc);
        if (depthVector != null)
            json.writeValue("depthVector", depthVector);
        if (polygonalNavGraph != null)
            json.writeValue("polygonalNavGraph", polygonalNavGraph);
        if (sceneSize != null)
            json.writeValue("sceneSize", sceneSize);
    } else {
        SceneActorRef actorRef;
        json.writeObjectStart("actors");
        for (BaseActor a : actors.values()) {
            actorRef = new SceneActorRef(a.getInitScene(), a.getId());
            json.writeValue(actorRef.toString(), a);
        }
        json.writeObjectEnd();
        json.writeValue("camera", camera);
        if (followActor != null)
            json.writeValue("followActor", followActor.getId());
        soundManager.write(json);
    }
    verbs.write(json);
    if (state != null)
        json.writeValue("state", state);
    if (player != null)
        json.writeValue("player", player);
}
Also used : SceneActorRef(com.bladecoder.engine.actions.SceneActorRef)

Example 9 with SceneActorRef

use of com.bladecoder.engine.actions.SceneActorRef in project bladecoder-adventure-engine by bladecoder.

the class UIActors method write.

@Override
public void write(Json json) {
    SceneActorRef actorRef;
    json.writeObjectStart("actors");
    for (InteractiveActor a : actors) {
        actorRef = new SceneActorRef(a.getInitScene(), a.getId());
        json.writeValue(actorRef.toString(), a);
    }
    json.writeObjectEnd();
}
Also used : SceneActorRef(com.bladecoder.engine.actions.SceneActorRef)

Aggregations

SceneActorRef (com.bladecoder.engine.actions.SceneActorRef)9 Vector2 (com.badlogic.gdx.math.Vector2)3 JsonValue (com.badlogic.gdx.utils.JsonValue)3 Color (com.badlogic.gdx.graphics.Color)2 ActorAnimationRef (com.bladecoder.engine.actions.ActorAnimationRef)2 Field (java.lang.reflect.Field)2 ActionProperty (com.bladecoder.engine.actions.ActionProperty)1 PolygonalNavGraph (com.bladecoder.engine.polygonalpathfinder.PolygonalNavGraph)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1