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);
}
}
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);
}
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);
}
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();
}
Aggregations