List of usage examples for com.badlogic.gdx.utils JsonValue get
public JsonValue get(String name)
From source file:be.ac.ucl.lfsab1509.bouboule.game.physicEditor.BodyEditorLoader.java
License:Open Source License
private RigidBodyModel readRigidBody(JsonValue bodyElem) { RigidBodyModel rbModel = new RigidBodyModel(); rbModel.name = bodyElem.getString("name"); rbModel.imagePath = bodyElem.getString("imagePath"); JsonValue originElem = bodyElem.get("origin"); rbModel.origin.x = originElem.getFloat("x"); rbModel.origin.y = originElem.getFloat("y"); // polygons//from ww w. j a v a2 s . co m JsonValue polygonsElem = bodyElem.getChild("polygons"); for (; polygonsElem != null; polygonsElem = polygonsElem.next()) { PolygonModel polygon = new PolygonModel(); rbModel.polygons.add(polygon); JsonValue vertexElem = polygonsElem.child(); for (; vertexElem != null; vertexElem = vertexElem.next()) { float x = vertexElem.getFloat("x"); float y = vertexElem.getFloat("y"); polygon.vertices.add(new Vector2(x, y)); } polygon.buffer = new Vector2[polygon.vertices.size()]; } // circles JsonValue circleElem = bodyElem.getChild("circles"); for (; circleElem != null; circleElem = circleElem.next()) { CircleModel circle = new CircleModel(); rbModel.circles.add(circle); circle.center.x = circleElem.getFloat("cx"); circle.center.y = circleElem.getFloat("cy"); circle.radius = circleElem.getFloat("r"); } return rbModel; }
From source file:com.ahsgaming.valleyofbones.map.TileLayer.java
License:Apache License
public static TileLayer createFromJson(JsonValue value) { TileLayer tileLayer = new TileLayer(); tileLayer.traversible = value.getBoolean("traversible", true); tileLayer.collidable = value.getBoolean("collidable", false); tileLayer.visible = value.getBoolean("visible", true); tileLayer.opacity = value.getFloat("opacity", 1); tileLayer.data = new Array<Integer>(); for (JsonValue v : value.get("data")) { tileLayer.data.add(v.asInt());//from ww w.j av a 2 s . c o m } return tileLayer; }
From source file:com.ahsgaming.valleyofbones.map.TileSet.java
License:Apache License
public TileSet(JsonValue json) { firstgid = json.getInt("firstgid"); name = json.getString("name", ""); atlas = json.getString("atlas"); images = new Array<String>(); tiles = new Array<TextureRegion>(); depths = new Array<TextureRegion>(); for (JsonValue v : json.get("tiles")) { images.add(v.asString());/*from w w w .ja v a 2 s . c o m*/ tiles.add(VOBGame.instance.getTextureManager().getSpriteFromAtlas(atlas, v.asString())); depths.add(VOBGame.instance.getTextureManager().getSpriteFromAtlas(atlas, v.asString() + "-depth")); } }
From source file:com.bladecoder.engine.model.CharacterActor.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w ww . j a v a2s . c om public void read(Json json, JsonValue jsonData) { super.read(json, jsonData); if (SerializationHelper.getInstance().getMode() == Mode.MODEL) { dialogs = json.readValue("dialogs", HashMap.class, Dialog.class, jsonData); if (dialogs != null) { for (Dialog d : dialogs.values()) d.setActor(id); } } else { if (dialogs != null) { JsonValue dialogsValue = jsonData.get("dialogs"); for (Dialog d : dialogs.values()) { String id = d.getId(); JsonValue dValue = dialogsValue.get(id); if (dValue != null) d.read(json, dValue); } } standAnim = json.readValue("standAnim", String.class, jsonData); walkAnim = json.readValue("walkAnim", String.class, jsonData); talkAnim = json.readValue("talkAnim", String.class, jsonData); } walkingSpeed = json.readValue("walkingSpeed", float.class, walkingSpeed, jsonData); textColor = json.readValue("textColor", Color.class, jsonData); }
From source file:com.bladecoder.engine.model.Dialog.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w ww . ja v a 2 s . c o m public void read(Json json, JsonValue jsonData) { if (SerializationHelper.getInstance().getMode() == Mode.MODEL) { id = json.readValue("id", String.class, jsonData); // actor = json.readValue("actor", String.class, jsonData); options = json.readValue("options", ArrayList.class, DialogOption.class, jsonData); } else { JsonValue optionsValue = jsonData.get("options"); int i = 0; for (DialogOption o : options) { JsonValue jsonValue = optionsValue.get(i); if (jsonValue == null) break; o.read(json, jsonValue); i++; } } }
From source file:com.bladecoder.engine.model.Inventory.java
License:Apache License
@Override public void read(Json json, JsonValue jsonData) { visible = json.readValue("visible", Boolean.class, jsonData); items.clear();/*from w w w. j ava2 s . co m*/ 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); } // READ ACTOR STATE. // 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); } }
From source file:com.bladecoder.engine.model.Scene.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*from w w w . jav a 2 s. c o m*/ 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); musicFilename = json.readValue("musicFilename", String.class, jsonData); if (musicFilename != null) { loopMusic = json.readValue("loopMusic", Boolean.class, jsonData); initialMusicDelay = json.readValue("initialMusicDelay", Float.class, jsonData); repeatMusicDelay = json.readValue("repeatMusicDelay", Float.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); } } // READ ACTOR STATE. // 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); BaseActor actor = getActor(actorRef.getActorId(), false); if (actor != null) actor.read(json, jsonValueAct); else EngineLogger.debug("Actor not found: " + actorRef); } orderLayersByZIndex(); if (musicFilename != null) { isPlayingSer = json.readValue("isPlaying", Boolean.class, jsonData); musicPosSer = json.readValue("musicPos", Float.class, jsonData); } camera = json.readValue("camera", SceneCamera.class, jsonData); String followActorId = json.readValue("followActor", String.class, jsonData); setCameraFollowActor((SpriteActor) actors.get(followActorId)); } verbs.read(json, jsonData); state = json.readValue("state", String.class, jsonData); player = json.readValue("player", String.class, jsonData); }
From source file:com.bladecoder.engine.model.SpriteActor.java
License:Apache License
@Override public void read(Json json, JsonValue jsonData) { super.read(json, jsonData); if (SerializationHelper.getInstance().getMode() == Mode.MODEL) { renderer = json.readValue("renderer", ActorRenderer.class, jsonData); } else {//from www . ja v a 2s.c o m posTween = json.readValue("posTween", SpritePosTween.class, jsonData); scaleTween = json.readValue("scaleTween", SpriteScaleTween.class, jsonData); renderer.read(json, jsonData.get("renderer")); } scale = json.readValue("scale", float.class, scale, jsonData); depthType = json.readValue("depthType", DepthType.class, depthType, jsonData); bboxFromRenderer = json.readValue("bboxFromRenderer", boolean.class, bboxFromRenderer, jsonData); if (bboxFromRenderer) renderer.updateBboxFromRenderer(bbox); setScale(scale); }
From source file:com.bladecoder.engine.model.Verb.java
License:Apache License
@Override public void read(Json json, JsonValue jsonData) { if (SerializationHelper.getInstance().getMode() == Mode.MODEL) { id = json.readValue("id", String.class, jsonData); target = json.readValue("target", String.class, jsonData); state = json.readValue("state", String.class, jsonData); icon = json.readValue("icon", String.class, jsonData); actions.clear();/*from w w w . j a v a2 s .c o m*/ JsonValue actionsValue = jsonData.get("actions"); for (int i = 0; i < actionsValue.size; i++) { JsonValue aValue = actionsValue.get(i); Action a = ActionUtils.readJson(json, aValue); actions.add(a); } } else { // MUTABLE ip = json.readValue("ip", Integer.class, jsonData); JsonValue actionsValue = jsonData.get("actions"); int i = 0; for (Action a : actions) { if (a instanceof Serializable && i < actionsValue.size) { if (actionsValue.get(i) == null) break; ((Serializable) a).read(json, actionsValue.get(i)); i++; } } } }
From source file:com.bladecoder.engine.model.VerbManager.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*from w ww. j a va 2 s . c om*/ public void read(Json json, JsonValue jsonData) { if (SerializationHelper.getInstance().getMode() == Mode.MODEL) { verbs = json.readValue("verbs", HashMap.class, Verb.class, jsonData); } else { for (String v : verbs.keySet()) { Verb verb = verbs.get(v); JsonValue jsonValue = jsonData.get("verbs").get(v); if (jsonValue != null) verb.read(json, jsonValue); else EngineLogger.debug("LOAD WARNING: Verb not found in saved game: " + jsonData.name + "." + v); } } }