@SuppressWarnings("unchecked") public Map<?, ?> read(Json json, JsonValue jsonData) { Map<K, V> values; try { values = (Map<K, V>) map.map().newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new GdxRuntimeException(e); } JsonValue entry = jsonData.getChild(name); while (entry != null) { JsonValue keyValue = entry.get("key"); K key = json.readValue((Class<K>) map.key(), keyValue); JsonValue valueValue = entry.get("value"); V value = json.readValue((Class<V>) map.value(), valueValue); values.put(key, value); entry = entry.next; } return values; }
@Override public void read(Json json, JsonValue jsonData) { userEmail = json.readValue("user_email", String.class, jsonData); if (userEmail == null) userEmail = ""; userPassword = json.readValue("user_password", String.class, jsonData); if (userPassword == null) userPassword = ""; }
@Override public void read(Json json, JsonValue jsonData) { previousAnim = json.readValue("previousFA", String.class, jsonData); responseText = json.readValue("responseText", String.class, jsonData); characterTurn = json.readValue("characterTurn", Boolean.class, jsonData); characterName = json.readValue("characterName", String.class, jsonData); super.read(json, jsonData); }
@Override public void read(Json json, JsonValue jsonData) { actorId = json.readValue("actorId", String.class, jsonData); ip = json.readValue("ip", Integer.class, jsonData); verb = json.readValue("verb", String.class, jsonData); target = json.readValue("target", String.class, jsonData); state = json.readValue("state", String.class, jsonData); super.read(json, jsonData); }
@Override public IntMap read(Json json, JsonValue jsonData, Class type) { IntMap intMap = new IntMap(json.readValue(VALUE_SIZE, int.class, jsonData)); for (JsonValue entry = jsonData.getChild(VALUE_ENTRIES); entry != null; entry = entry.next) { intMap.put(Integer.parseInt(entry.name), json.readValue(entry.name, null, jsonData)); } return intMap; }
@SuppressWarnings("unchecked") @Override public void read(Json json, JsonValue jsonData) { super.read(json, jsonData); walkingPath = json.readValue("path", ArrayList.class, Vector2.class, jsonData); currentStep = json.readValue("currentStep", Integer.class, jsonData); speed = json.readValue("speed", Float.class, jsonData); String walkCbSer = json.readValue("walkCb", String.class, jsonData); walkCb = ActionCallbackSerialization.find(walkCbSer); }
@Override public Vector2 read(Json json, JsonValue jsonData, Class type) { Vector2 vector = new Vector2(0.0f, 0.0f); try { json.readValue(float.class, jsonData); } catch (SerializationException e) { vector.x = json.readValue("x", float.class, 0.0f, jsonData); vector.y = json.readValue("y", float.class, 0.0f, jsonData); } return vector; }
@SuppressWarnings("unchecked") @Override public void read(Json json, JsonValue jsonData) { width = jsonData.getInt("Width"); height = jsonData.getInt("Height"); keys = json.readValue("Keys", ObjectMap.class, jsonData); }
// Serializable implementation @SuppressWarnings("unchecked") @Override public void read(Json json, OrderedMap<String, Object> jsonData) { // read the some basic properties currentLevelId = json.readValue("currentLevelId", Integer.class, jsonData); credits = json.readValue("credits", Integer.class, jsonData); // libgdx handles the keys of JSON formatted HashMaps as Strings, but we // want it to be an integer instead (levelId) Map<String, Integer> highScores = json.readValue("highScores", HashMap.class, Integer.class, jsonData); for (String levelIdAsString : highScores.keySet()) { int levelId = Integer.valueOf(levelIdAsString); Integer highScore = highScores.get(levelIdAsString); this.highScores.put(levelId, highScore); } // finally, read the ship coon = json.readValue("ship", Coon.class, jsonData); }
@SuppressWarnings("unchecked") public <M> M read( Json json, JsonValue jsonData, Supplier<M> newInstance, KeyValueConsumer<M, K, V> put) { M values = newInstance.get(); JsonValue entry = jsonData.getChild(name); while (entry != null) { JsonValue keyValue = entry.get("key"); K key = json.readValue((Class<K>) map.key(), keyValue); JsonValue valueValue = entry.get("value"); V value = json.readValue((Class<V>) map.value(), valueValue); put.accept(values, key, value); entry = entry.next; } return values; }
@Override public RubeImage read(Json json, JsonValue jsonData, Class type) { if (scene.getBodies() == null) return null; RubeImage defaults = RubeDefaults.Image.image; RubeImage image = new RubeImage(); image.angle = json.readValue("angle", float.class, defaults.angle, jsonData); int bodyIndex = json.readValue("body", int.class, jsonData); if (bodyIndex >= 0 && bodyIndex < scene.getBodies().size) image.body = scene.getBodies().get(bodyIndex); image.center.set(json.readValue("center", Vector2.class, defaults.center, jsonData)); RubeVertexArray corners = json.readValue("corners", RubeVertexArray.class, jsonData); if (corners != null) { tmp.set(corners.x[0], corners.y[0]).sub(corners.x[1], corners.y[1]); image.width = tmp.len(); tmp.set(corners.x[1], corners.y[1]).sub(corners.x[2], corners.y[2]); image.height = tmp.len(); } image.file = json.readValue("file", String.class, jsonData); if (stripImageFile) { int fslashIndex = image.file.lastIndexOf('/'); int dotIndex = image.file.lastIndexOf('.'); if (fslashIndex != -1 && dotIndex != -1 && fslashIndex < dotIndex) { image.file = image.file.substring(fslashIndex + 1, dotIndex); } } image.filter = json.readValue("filter", int.class, defaults.filter, jsonData); image.name = json.readValue("name", String.class, jsonData); image.opacity = json.readValue("opacity", float.class, defaults.opacity, jsonData); image.renderOrder = json.readValue("renderOrder", int.class, defaults.renderOrder, jsonData); image.scale = json.readValue("scale", float.class, defaults.scale, jsonData); image.flip = json.readValue("flip", boolean.class, defaults.flip, jsonData); int[] colorArray = json.readValue("colorTint", int[].class, RubeDefaults.Image.colorArray, jsonData); image.color.r = (float) colorArray[0] / 255; image.color.g = (float) colorArray[1] / 255; image.color.b = (float) colorArray[2] / 255; image.color.a = (float) colorArray[3] / 255; RubeCustomProperty customProperty = null; if (json.getSerializer(RubeCustomProperty.class) != null) customProperty = json.readValue("customProperties", RubeCustomProperty.class, jsonData); scene.onAddImage(image, customProperty); return image; }
@SuppressWarnings("unchecked") @Override public void read(Json json, JsonValue jsonData) { layers = json.readValue("layers", ArrayList.class, SceneLayer.class, jsonData); id = json.readValue("id", String.class, jsonData); state = json.readValue("state", String.class, jsonData); verbManager = json.readValue("verbs", VerbManager.class, jsonData); actors = json.readValue("actors", HashMap.class, BaseActor.class, jsonData); player = json.readValue("player", String.class, jsonData); for (BaseActor actor : actors.values()) { actor.setScene(this); SceneLayer layer = getLayer(actor.getLayer()); layer.add(actor); } orderLayersByZIndex(); backgroundAtlas = json.readValue("backgroundAtlas", String.class, jsonData); backgroundRegionId = json.readValue("backgroundRegionId", String.class, jsonData); lightMapAtlas = json.readValue("lightMapAtlas", String.class, jsonData); lightMapRegionId = json.readValue("lightMapRegionId", String.class, jsonData); musicFilename = json.readValue("musicFilename", String.class, jsonData); loopMusic = json.readValue("loopMusic", Boolean.class, jsonData); initialMusicDelay = json.readValue("initialMusicDelay", Float.class, jsonData); repeatMusicDelay = json.readValue("repeatMusicDelay", Float.class, jsonData); 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)); depthVector = json.readValue("depthVector", Vector2.class, jsonData); polygonalNavGraph = json.readValue("polygonalNavGraph", PolygonalNavGraph.class, jsonData); }
@SuppressWarnings("unchecked") @Override public void read(final Json json, final JsonValue jsonData) { leaves = json.readValue("leaves", Array.class, jsonData); }