@Override public void write(Json json) { super.write(json); StringBuilder sb = new StringBuilder(); for(int x = 0; x < pixmap.getWidth(); x++) { for(int y = 0; y < pixmap.getHeight(); y++) { int color = pixmap.getPixel(x, y); if(color == Color.rgba8888(47f / 255f, 86f / 255f, 118f / 255f, 1f)) { sb.append("d"); } else if(color == Color.rgba8888(62f / 255f, 120f / 255f, 160f / 255f, 1f)) { sb.append("o"); } else if(color == Color.rgba8888(146f / 255f, 209f / 255f, 135f / 255f, 1f)) { sb.append("l"); } } } json.writeValue("texture", sb.toString()); }
/** * Converts json string into java object. * * @param wantedType Wanted type * @param genericTypeKeeper Object with wanted type inside generic argument * @param jsonString Json string data * @param <R> Return type * @return */ public static <R> R process(Class<?> wantedType, Object genericTypeKeeper, String jsonString) { Json json = new Json(); json.setIgnoreUnknownFields(true); json.setTypeName(null); R result = null; if (ClassReflection.isAssignableFrom(List.class, wantedType) || ClassReflection.isAssignableFrom(Map.class, wantedType)) { NestedGenericType nestedGenericType = AnnotationProcessor.getNestedGenericTypeAnnotation(genericTypeKeeper); if (nestedGenericType == null) throw new NestedGenericTypeAnnotationMissingException(); json.setDefaultSerializer(new JsonListMapDeserializer(wantedType, nestedGenericType.value())); result = (R) json.fromJson(wantedType, jsonString); } else { result = (R) json.fromJson(wantedType, jsonString); } return result; }
@Override public void write (Json json) { json.writeValue("name", name); json.writeArrayStart("components"); for (int i = 0; i < components.size; i++) if (components.get(i) instanceof Rigidbody) { Rigidbody rigidbody = (Rigidbody)components.get(i); components.removeIndex(i); components.insert(1, rigidbody); } for (int i = 0; i < components.size; i++) { GameComponent component = components.get(i); json.writeObjectStart(); json.writeValue("componentType", component.getType()); component.write(json); json.writeObjectEnd(); } json.writeArrayEnd(); }
@Override public void read(Json json, JsonValue jsonValue) { try { name = jsonValue.getString("name"); optional = jsonValue.getBoolean("optional"); if (jsonValue.get("value").isNumber()) { type = Float.TYPE; value = Double.parseDouble(jsonValue.getString("value")); } else { type = ClassReflection.forName(jsonValue.getString("type")); if (jsonValue.get("value").isNull()) { value = null; } else { value = jsonValue.getString("value"); } } } catch (ReflectionException ex) { Gdx.app.error(getClass().toString(), "Error reading from serialized object" , ex); DialogFactory.showDialogErrorStatic("Read Error...","Error reading from serialized object.\n\nOpen log?"); } }
@Override public void read(Json json, JsonValue jsonData) { try { colors = json.readValue("colors", Array.class, jsonData); fonts = json.readValue("fonts", Array.class, jsonData); classStyleMap = new OrderedMap<>(); for (JsonValue data : jsonData.get("classStyleMap").iterator()) { classStyleMap.put(ClassReflection.forName(data.name), json.readValue(Array.class, data)); } for (Array<StyleData> styleDatas : classStyleMap.values()) { for (StyleData styleData : styleDatas) { styleData.jsonData = this; } } customClasses = json.readValue("customClasses", Array.class, CustomClass.class, new Array<>(), jsonData); for (CustomClass customClass : customClasses) { customClass.setMain(main); } } catch (ReflectionException e) { Gdx.app.log(getClass().getName(), "Error parsing json data during file read", e); main.getDialogFactory().showDialogError("Error while reading file...", "Error while attempting to read save file.\nPlease ensure that file is not corrupted.\n\nOpen error log?"); } }
@Override public ScaleFactorModel read(Json json, JsonValue jsonData, Class type) { String suffix = ""; float factor = 1f; JsonValue.JsonIterator iterator = jsonData.iterator(); while (iterator.hasNext()) { JsonValue value = iterator.next(); switch (value.name) { case "suffix": suffix = value.asString(); break; case "factor": factor = value.asFloat(); break; } } return new ScaleFactorModel(suffix, factor); }
@Override protected void getRequest(Json json) { boolean hasStart = false; try { json.writeObjectStart(); } catch (IllegalStateException e) { hasStart = true; } //write GC codes json.writeObjectStart("CacheCode"); json.writeArrayStart("CacheCodes"); for (String gcCode : gcCodes) { json.writeValue(gcCode); } json.writeArrayEnd(); json.writeObjectEnd(); super.getRequest(json); if (!hasStart) json.writeObjectEnd(); }
@Override protected void getRequest(Json json) { boolean hasStart = false; try { json.writeObjectStart(); } catch (IllegalStateException e) { hasStart = true; } json.writeObjectStart("PointRadius"); json.writeValue("DistanceInMeters", this.distanceInMeters); json.writeObjectStart("Point"); json.writeValue("Latitude", pos.getLatitude()); json.writeValue("Longitude", pos.getLongitude()); json.writeObjectEnd(); json.writeObjectEnd(); super.getRequest(json); if (!hasStart) json.writeObjectEnd(); }
@Test void getRequest() throws IOException { String expected = TestUtils.getResourceRequestString("testsResources/SearchGcOwner_request.txt", isDummy ? null : apiKey); Coordinate searchCoord = new CoordinateGPS(52.581892, 13.398128); // Home of Katipa(like Longri) SearchGCOwner searchGC = new SearchGCOwner(apiKey, 30, searchCoord, 50000, "bros", (byte) 2); StringWriter writer = new StringWriter(); Json json = new Json(JsonWriter.OutputType.json); json.setWriter(writer); searchGC.getRequest(json); String actual = writer.toString(); assertEquals(expected, actual); }
/** * リプレイデータを読み込む * * @param model * 対象のBMS * @param lnmode * LNモード * @return リプレイデータ */ public ReplayData readReplayData(BMSModel model, int lnmode, int index) { if (existsReplayData(model, lnmode, index)) { Json json = new Json(); json.setIgnoreUnknownFields(true); try { String path = this.getReplayDataFilePath(model, lnmode, index); if (Files.exists(Paths.get(path + ".brd"))) { return json.fromJson(ReplayData.class, new BufferedInputStream( new GZIPInputStream(Files.newInputStream(Paths.get(path + ".brd"))))); } if (Files.exists(Paths.get(path + ".json"))) { return json.fromJson(ReplayData.class, new FileReader(path + ".json")); } } catch (IOException e) { e.printStackTrace(); } } return null; }
/** * コースリプレイデータを読み込む * * @param hash * 対象のBMSハッシュ群 * @param lnmode * LNモード * @return リプレイデータ */ public ReplayData[] readReplayData(String[] hash, boolean ln, int lnmode, int index, CourseData.CourseDataConstraint[] constraint) { if (existsReplayData(hash, ln, lnmode, index, constraint)) { Json json = new Json(); json.setIgnoreUnknownFields(true); try { String path = this.getReplayDataFilePath(hash, ln, lnmode, index, constraint); if (Files.exists(Paths.get(path + ".brd"))) { return json.fromJson(ReplayData[].class, new BufferedInputStream( new GZIPInputStream(Files.newInputStream(Paths.get(path + ".brd"))))); } if (Files.exists(Paths.get(path + ".json"))) { return json.fromJson(ReplayData[].class, new FileReader(path + ".json")); } } catch (IOException e) { e.printStackTrace(); } } return null; }
@Override public void read (Json json, JsonValue jsonData) { for (int i = 0; i < jsonData.get("animations").size; i++) { JsonValue animationValue = jsonData.get("animations").get(i); Animation animation = new TweenAnimation(); animation.setAnimator(this); animations.put(animationValue.name, animation); animation.read(json, animationValue); } if (animations.size == 0) { animations.put("Default", new TweenAnimation()); setAnimation("Default"); currentAnimation.setAnimator(this); } else setAnimation(jsonData.getString("currentAnimation")); }
@Override public void read (Json json, JsonValue jsonData) { if (jsonData.has("time")) time = jsonData.getInt("time"); if (jsonData.get("value").isNumber()) value = jsonData.getFloat("value"); else value = new Color(); JsonValue curveValue = jsonData.get("curve"); JsonValue constraintsValue = curveValue.get("constraints"); int c1, c2, c3, c4; c1 = constraintsValue.getInt("c1"); c2 = constraintsValue.getInt("c2"); c3 = constraintsValue.getInt("c3"); c4 = constraintsValue.getInt("c4"); curve = new Curve(); curve.constraints.set(c1, c2, c3, c4); if (curveValue.has("type")) curve.setType(json.readValue(Type.class, curveValue.get("type"))); }
@SuppressWarnings("unchecked") public void reload () { RavTech.files.loadAsset("keybindings.json", String.class); RavTech.files.finishLoading(); if ((!RavTech.settings.has("keybindings"))) RavTech.settings.setValue("keybindings", RavTech.files.getAsset("keybindings.json", String.class)); this.actionMaps.clear(); Json json = new Json(); ObjectMap<String, JsonValue> serializedActionMaps = json.fromJson(ObjectMap.class, RavTech.settings.getString("keybindings")); for (ObjectMap.Entry<String, JsonValue> entry : serializedActionMaps.entries()) { ActionMap actionMap = new ActionMap(); actionMap.read(json, entry.value); this.actionMaps.put(entry.key, actionMap); } this.actionMaps.putAll(actionMaps); this.players.clear(); Player player = new Player(); for (int i = 0; i < inputDevices.size; i++) player.assignDevice(inputDevices.get(i), this.getActionMapForDevice(inputDevices.get(i))); players.add(player); }
@Override public void undo () { JsonValue jsonData = new JsonReader().parse(gameComponent); Json json = new Json(); GameObject tempObject = new GameObject(); tempObject.readValue(json, jsonData); GameComponent toAddComponent = tempObject.getComponentByName(componentType); tempObject.getComponents().removeValue(tempObject.getComponentByName(componentType), true); tempObject.destroy(); if (pathToComponent.lastIndexOf('/') == 0) { toAddComponent.setParent(null); RavTech.currentScene.addGameObject((GameObject)toAddComponent); } else { GameObject component = (GameObject)GameObjectTraverseUtil .gameComponentFromPath(pathToComponent.substring(0, pathToComponent.lastIndexOf('/'))); toAddComponent.setParent(component); component.addComponent(toAddComponent); } }
@Override public void redo () { GameComponent parent = GameObjectTraverseUtil.gameComponentFromPath(pathToComponent); JsonValue jsonData = new JsonReader().parse(gameComponent); Json json = new Json(); if (parent != null) { ((GameObject)parent).readValue(json, jsonData); removePath = GameObjectTraverseUtil .pathFromGameComponent(((GameObject)parent).getComponents().get(((GameObject)parent).getComponents().size - 1)); } else { GameObject object = new GameObject(); object.readValue(json, jsonData); GameObject newObject = (GameObject)object.getComponents().get(1); newObject.setParent(null); removePath = GameObjectTraverseUtil.pathFromGameComponent(newObject); RavTech.currentScene.addGameObject(newObject); } componentType = jsonData.getString("componenttype"); }
@Override public void write (Json json) { super.write(json); json.writeValue("width", width); json.writeValue("height", height); json.writeValue("texture", texturePath); if (regionName != null) json.writeValue(regionName); json.writeValue("srcX", srcX); json.writeValue("srcY", srcY); json.writeValue("srcWidth", srcWidth); json.writeValue("srcHeight", srcHeight); json.writeValue("originX", originX); json.writeValue("originY", originY); json.writeValue("minFilter", minFilter == TextureFilter.Linear ? "Linear" : "Nearest"); json.writeValue("magFilter", magFilter == TextureFilter.Linear ? "Linear" : "Nearest"); JsonUtil.writeColorToJson(json, color, "tint"); json.writeValue("uWrap", uWrap == TextureWrap.ClampToEdge ? "ClampToEdge" : uWrap == TextureWrap.Repeat ? "Repeat" : "MirroredRepeat"); json.writeValue("vWrap", vWrap == TextureWrap.ClampToEdge ? "ClampToEdge" : vWrap == TextureWrap.Repeat ? "Repeat" : "MirroredRepeat"); }
@Override public void write(Json json) { json.writeValue("minimumRadius", minRadius); json.writeValue("maximumRadius", maxRadius); json.writeValue("angularVelocity", angularVelocity); json.writeValue("zTilt", zTilt); json.writeValue("xTilt", xTilt); json.writeValue("objectCount", objects.size); json.writeValue("colorGroup", colors); }
@Override public void read(Json json, JsonValue jsonData) { minRadius = json.readValue("minimumRadius", Float.class, jsonData); maxRadius = json.readValue("maximumRadius", Float.class, jsonData); angularVelocity = json.readValue("angularVelocity", Float.class, jsonData); zTilt = json.readValue("zTilt", Float.class, jsonData); xTilt = json.readValue("xTilt", Float.class, jsonData); colors = json.readValue("colorGroup", ColorGroup.class, jsonData); this.baseObjectCount = json.readValue("objectCount", Integer.class, jsonData); objects = new Array<>(baseObjectCount); }
@Override public void read(Json json, JsonValue jsonData) { super.read(json, jsonData); setSprite(new Sprite()); int size = json.readValue("size", Integer.class, jsonData); getSprite().setSize(size, size); int x = json.readValue("xPos", Integer.class, jsonData); int y = json.readValue("yPos", Integer.class, jsonData); getSprite().setPosition(x, y); }
@Override public void write(Json json) { super.write(json); json.writeValue("angularVelocity", angularVelocity); json.writeValue("zTilt", zTilt); json.writeValue("xTilt", xTilt); json.writeValue("radius", radius); json.writeValue("angle", angle); json.writeValue("yOffset", yOffset); }
@Override public void read(Json json, JsonValue jsonData) { super.read(json, jsonData); angularVelocity = json.readValue("angularVelocity", Float.class, jsonData); zTilt = json.readValue("zTilt", Float.class, jsonData); xTilt = json.readValue("xTilt", Float.class, jsonData); radius = json.readValue("radius", Float.class, jsonData); angle = json.readValue("angle", Float.class, jsonData); yOffset = json.readValue("yOffset", Float.class, jsonData); initializeMatrices(); }
@Override public void read(Json json, JsonValue jsonData) { super.read(json, jsonData); texture = json.readValue("texture", String.class, jsonData); getSprite().setSize(getSize(), getSize()); radius = getSprite().getWidth()/2; }
@Override public void create() { instance = this; G.settings = (new Json()).fromJson(Settings.class, Gdx.files.internal("settings.json")); restart(); }
private void loadSprites() { final Json json = new Json(); spriteLibrary = json.fromJson(SpriteLibrary.class, Gdx.files.internal("sprites.json")); for (SpriteData sprite : spriteLibrary.sprites) { Animation animation = add(sprite.id, sprite.x, sprite.y, sprite.width, sprite.height, sprite.countX, sprite.countY, this.tileset, sprite.milliseconds * 0.001f); } }
@Override public void write(Json json) { json.writeArrayStart("tiles"); for (T t : this) { json.writeValue(t); } json.writeArrayEnd(); }
@Override public void write(Json json) { json.writeObjectStart("tile"); json.writeValue("region", region); json.writeValue("index", index); json.writeValue("owner", owner.getId()); json.writeValue("troops", troops); json.writeObjectEnd(); }
@Override public void write(Json json) { json.writeObjectStart("player"); json.writeValue("id", getId()); json.writeValue("color", getColor().toString()); json.writeObjectEnd(); }
public PreferencesBasedStorage(Preferences preferences, String name, Json json, Class<T> type) { super(); this.preferences = preferences; this.name = name; this.json = json; this.type = type; }
/** * Returns JSON string representation of object. * <p> * It using libgdx {@link Json} class. * * @param object Any object * @return JSON string representation of {@code object} */ public static String dataToString(Object object) { if (isPrimitiveType(object)) return object.toString(); Json json = new Json(); json.setTypeName(null); json.setQuoteLongValues(true); json.setIgnoreUnknownFields(true); json.setOutputType(JsonWriter.OutputType.json); return json.toJson(object); }
protected Object processJsonValue(Json json, JsonValue jsonData) { if (jsonData.isObject()) { return processObject(json, jsonData); } else if (jsonData.isValue()) { return processValue(json, jsonData); } else { return null; } }
protected Object processValue(Json json, JsonValue jsonData) { if (jsonData.isBoolean()) return jsonData.asBoolean(); else if (jsonData.isDouble()) return jsonData.asDouble(); else if (jsonData.isLong()) return jsonData.asLong(); else if (jsonData.isNull()) return null; else if (jsonData.isString()) return jsonData.asString(); return null; }
/** * @param map Map, not null * @return JSON representation of given map */ public static String mapToJSON(Map<String, Object> map) { Json json = new Json(); json.setTypeName(null); json.setQuoteLongValues(true); json.setIgnoreUnknownFields(true); json.setOutputType(JsonWriter.OutputType.json); return json.toJson(map, HashMap.class); }
/** * Returns modified json data. * * @param oldJsonData Old data as json string. * @return New data as json string */ public String modify(String oldJsonData) { R oldData = JsonProcessor.process(wantedType, transactionCallback, oldJsonData); R newData = transactionCallback.run(oldData); Json json = new Json(); json.setTypeName(null); json.setQuoteLongValues(true); json.setIgnoreUnknownFields(true); json.setOutputType(JsonWriter.OutputType.json); return json.toJson(newData, wantedType); }
@SuppressWarnings("unchecked") public static NSDictionary toNSDictionary(Object object) { if (object instanceof Map) { return toNSDictionary((Map) object); } else { String objectJsonData = new Json().toJson(object); Json json = new Json(); json.setIgnoreUnknownFields(true); Map objectMap = json.fromJson(HashMap.class, objectJsonData); return toNSDictionary(objectMap); } }
private void loadSprites() { final Json json = new Json(); spriteLibrary = json.fromJson(SpriteLibrary.class, Gdx.files.internal("sprites.json")); for (SpriteData sprite : spriteLibrary.sprites) { add(sprite.id, sprite.x, sprite.y, sprite.width, sprite.height, sprite.countX, sprite.countY); } }
private void loadPlanets() { final Json json = new Json(); planetLibrary = json.fromJson(PlanetLibrary.class, Gdx.files.internal("planets.json")); net.mostlyoriginal.game.component.PlanetData planet = planetLibrary.planets[1]; { planetEntity = E.E(); Planet planetE = planetEntity .renderLayer(G.LAYER_PLANET) .planet() .tag("planet") .pos(0, 0) .getPlanet(); planetE.data = planet; for (net.mostlyoriginal.game.component.PlanetData.CellType type : planet.types) { Color color = Color.valueOf(type.color); Color colorArid = type.colorSecondary != null ? Color.valueOf(type.colorSecondary) : color; planetE.cellColor[type.type.ordinal()] = type.intColor = Color.rgba8888(color); planetE.cellColorSecondary[type.type.ordinal()] = type.intColorSecondary = Color.rgba8888(colorArid); } populate(planet, planetE); gravity(planetE); height(planetE); } }
@Override public void handleHttpResponse(Net.HttpResponse httpResponse) { String result = httpResponse.getResultAsString(); Json json = new Json(); ArrayList list = json.fromJson(ArrayList.class, result); Array<LeaderBoardEntry> leaderBoardEntries = new Array<LeaderBoardEntry>(); if (list != null) { for (Object entry : list) { if (entry != null && entry instanceof JsonValue) { JsonValue jsonEntry = (JsonValue) entry; // the reflection does not seem to work on iOS // LeaderBoardEntry leaderBoardEntry = json.readValue( // LeaderBoardEntry.class, (JsonValue)entry); LeaderBoardEntry leaderBoardEntry = new LeaderBoardEntry(); try { leaderBoardEntry.name = jsonEntry.getString("name"); leaderBoardEntry.rank = jsonEntry.getInt("rank"); leaderBoardEntry.score = jsonEntry.getInt("score"); } catch (IllegalArgumentException e) { Gdx.app.log(TAG, "failed to read json: " + e.toString()); return; } leaderBoardEntries.add(leaderBoardEntry); } } } mListener.onSuccess(leaderBoardEntries); }
@Override public void write(Json json, Bounds object, Class knownType) { json.writeObjectStart(); json.writeValue("width", object.width); json.writeValue("height", object.height); json.writeObjectEnd(); }
@Override public Bounds read(Json json, JsonValue jsonData, Class type) { int width = jsonData.getInt("width"); int height = jsonData.getInt("height"); Bounds bounds = new Bounds(width, height); return bounds; }