Search in sources :

Example 1 with PolygonalNavGraph

use of com.bladecoder.engine.polygonalpathfinder.PolygonalNavGraph 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)

Aggregations

Vector2 (com.badlogic.gdx.math.Vector2)1 JsonValue (com.badlogic.gdx.utils.JsonValue)1 SceneActorRef (com.bladecoder.engine.actions.SceneActorRef)1 PolygonalNavGraph (com.bladecoder.engine.polygonalpathfinder.PolygonalNavGraph)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1