List of usage examples for com.badlogic.gdx.utils JsonValue JsonValue
public JsonValue(boolean value)
From source file:com.esotericsoftware.spine.JsonRollback.java
License:Open Source License
static public void main(String[] args) throws Exception { if (args.length == 0) { System.out.println("Usage: <inputFile> [outputFile]"); System.exit(0);/*w ww. ja v a 2 s . com*/ } JsonValue root = new Json().fromJson(null, new FileHandle(args[0])); // In 3.2 skinnedmesh was renamed to weightedmesh. setValue(root, "skinnedmesh", "skins", "*", "*", "*", "type", "weightedmesh"); // In 3.2 shear was added. delete(root, "animations", "*", "bones", "*", "shear"); // In 3.3 ffd was renamed to deform. rename(root, "ffd", "animations", "*", "deform"); // In 3.3 mesh is now a single type, previously they were skinnedmesh if they had weights. for (JsonValue value : find(root, new Array(), 0, "skins", "*", "*", "*", "type", "mesh")) if (value.parent.get("uvs").size != value.parent.get("vertices").size) value.set("skinnedmesh"); // In 3.3 linkedmesh is now a single type, previously they were linkedweightedmesh if they had weights. for (JsonValue value : find(root, new Array(), 0, "skins", "*", "*", "*", "type", "linkedmesh")) { String slot = value.parent.parent.name.replaceAll("", ""); String skinName = value.parent.getString("skin", "default"); String parentName = value.parent.getString("parent"); if (find(root, new Array(), 0, ("skins~~" + skinName + "~~" + slot + "~~" + parentName + "~~type~~skinnedmesh") .split("~~")).size > 0) value.set("weightedlinkedmesh"); } // In 3.3 bounding boxes can be weighted. for (JsonValue value : find(root, new Array(), 0, "skins", "*", "*", "*", "type", "boundingbox")) if (value.parent.getInt("vertexCount") * 2 != value.parent.get("vertices").size) value.parent.parent.remove(value.parent.name); // In 3.3 paths were added. for (JsonValue value : find(root, new Array(), 0, "skins", "*", "*", "*", "type", "path")) { String attachment = value.parent.name; value.parent.parent.remove(attachment); String slot = value.parent.parent.name; // Also remove path deform timelines. delete(root, "animations", "*", "ffd", "*", slot, attachment); } // In 3.3 IK constraint timelines no longer require bendPositive. for (JsonValue value : find(root, new Array(), 0, "animations", "*", "ik", "*")) for (JsonValue child = value.child; child != null; child = child.next) if (!child.has("bendPositive")) child.addChild("bendPositive", new JsonValue(true)); // In 3.3 transform constraints can have more than 1 bone. for (JsonValue child = root.getChild("transform"); child != null; child = child.next) { JsonValue bones = child.remove("bones"); if (bones != null) child.addChild("bone", new JsonValue(bones.child.asString())); } if (args.length > 1) new FileHandle(args[1]).writeString(root.prettyPrint(OutputType.json, 130), false, "UTF-8"); else System.out.println(root.prettyPrint(OutputType.json, 130)); }
From source file:com.trgk.touchwave.GameLogger.java
License:Open Source License
/** * Save game data//from www.j a v a2 s. c o m */ public void saveGameLog() { FileHandle gamelog = Gdx.files.local("gamelog.json"); JsonValue value = new JsonValue(JsonValue.ValueType.object); ArrayList<JsonValue> fields = new ArrayList<JsonValue>(); // Add values to fields for (Field field : GameLogger.class.getFields()) { try { String fieldName = field.getName(); // Support for android incremental build if (fieldName.equals("$change")) continue; JsonValue v; if (field.getType() == boolean.class) v = new JsonValue(field.getBoolean(this)); else if (field.getType() == int.class) v = new JsonValue(field.getInt(this)); else if (field.getType() == long.class) v = new JsonValue(field.getLong(this)); else { MessageBox.alert("GameLogger", "Reflection error for member \"" + fieldName + "\" (type " + field.getType().toString() + ")"); return; } v.setName(fieldName); fields.add(v); } catch (IllegalAccessException e) { MessageBox.alert("GameLogger", "IllegalAccessException : " + e.getMessage()); return; // Save failed } } // Link value.child = fields.get(0); for (int i = 0; i < fields.size() - 1; i++) { fields.get(i).setNext(fields.get(i + 1)); } gamelog.writeString(value.toJson(JsonWriter.OutputType.json), false); }
From source file:com.trgk.touchwave.menuscene.RankingLoadScene.java
License:Open Source License
@Override public void act(float dt) { super.act(dt); final TGWindow rankingWindow = parent.rankingWindow; final FBService fb = FBService.getInstance(); final GameLogger logger = GameLogger.getInstance(); // Get user permission if (currentState == -1) { currentState = 0;// w w w .j a v a2 s.co m if (!logger.notifiedRankingRealName) { getSceneManager().setCurrentScene(new FBAlertScene(this)); logger.notifiedRankingRealName = true; logger.saveGameLog(); return; } } // Get user ID if (currentState == 0) { if (logger.maxScore == -1) currentState = 6; else { if (fb.isLogonRead()) currentState = 2; else { fb.loginRead(); currentState = 1; } } } // Wait for fb read login if (currentState == 1) { if (!fb.isBusy()) { if (fb.getLastActionResult() != FBService.Result.SUCCESS) { postErrorMsg("?? ?? .", 0); currentState = 6; // Skip user status } else currentState = 2; } } // Post user data if (currentState == 2) { String reqURL = serverDomain + "ranking/"; HttpRequestBuilder requestBuilder = new HttpRequestBuilder(); JsonValue requestBodyJson = new JsonValue(JsonValue.ValueType.object); JsonValue fbIDValue = new JsonValue(fb.userID); JsonValue fbNicknameValue = new JsonValue(fb.username); JsonValue maxScoreValue = new JsonValue(GameLogger.getInstance().maxScore); JsonValue accessToken = new JsonValue(fb.getAccessToken()); fbIDValue.setName("fbID"); fbNicknameValue.setName("fbNickname"); maxScoreValue.setName("maxScore"); accessToken.setName("accessToken"); requestBodyJson.child = fbIDValue; fbIDValue.setNext(fbNicknameValue); fbNicknameValue.setNext(maxScoreValue); maxScoreValue.setNext(accessToken); String requestBody = requestBodyJson.toJson(JsonWriter.OutputType.json); final Net.HttpRequest httpRequest = requestBuilder.newRequest().method(Net.HttpMethods.PUT).url(reqURL) .header(HttpRequestHeader.ContentType, "application/json").content(requestBody).build(); currentState = 3; // Wait for http request to complete Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { currentState = 4; } @Override public void failed(Throwable t) { postErrorMsg(" ?? .", 0); currentState = 6; } @Override public void cancelled() { postErrorMsg(" ?? .", 0); currentState = 6; } }); } // Get user ranking if (currentState == 4) { String reqURL = String.format(Locale.ENGLISH, serverDomain + "ranking/%d", fb.userID); HttpRequestBuilder requestBuilder = new HttpRequestBuilder(); final Net.HttpRequest httpRequest = requestBuilder.newRequest().method(Net.HttpMethods.GET).url(reqURL) .build(); currentState = 5; Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { JsonReader reader = new JsonReader(); JsonValue result = reader.parse(httpResponse.getResultAsString()); if (result.isObject() && result.get("userRank") != null) { int userRank = result.getInt("userRank"); int maxScore = result.getInt("maxScore"); rankingWindow.addActor( new RankingScene.RankingEntry(userRank, fb.username, maxScore, Color.BLUE, 0)); currentState = 6; } else { postErrorMsg(" ?? .", 0); currentState = 6; } } @Override public void failed(Throwable t) { postErrorMsg(" ?? .", 0); currentState = 6; } @Override public void cancelled() { postErrorMsg(" ?? .", 0); currentState = 6; } }); } // Get total ranking if (currentState == 6) { String reqURL = serverDomain + "ranking/"; HttpRequestBuilder requestBuilder = new HttpRequestBuilder(); final Net.HttpRequest httpRequest = requestBuilder.newRequest().method(Net.HttpMethods.GET).url(reqURL) .build(); currentState = 7; Gdx.net.sendHttpRequest(httpRequest, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { JsonReader reader = new JsonReader(); JsonValue result = reader.parse(httpResponse.getResultAsString()); if (result.isObject() && result.get("rankings") != null) { JsonValue rankingArray = result.get("rankings"); JsonValue rankingEntry = rankingArray.child; int entryID = 1; while (rankingEntry != null) { rankingWindow.addActor( new RankingScene.RankingEntry(entryID, rankingEntry.getString("fbNickname"), rankingEntry.getInt("maxScore"), Color.BLACK, entryID)); rankingEntry = rankingEntry.next; entryID++; if (entryID == 20) break; } currentState = 8; } else { postErrorMsg("? ? .", 1); currentState = 8; } } @Override public void failed(Throwable t) { postErrorMsg("? ? .", 1); currentState = 8; } @Override public void cancelled() { postErrorMsg("? ? .", 1); currentState = 8; } }); } if (currentState == 8) { fb.logout(); gotoParent(); currentState = 9; } }
From source file:com.tussle.main.Utility.java
License:Open Source License
public static JsonValue exceptionToJson(Throwable ex) { JsonValue topValue = new JsonValue(JsonValue.ValueType.object); JsonValue exceptionClass = new JsonValue(ex.getClass().toString()); topValue.addChild("Exception Class", exceptionClass); if (ex.getLocalizedMessage() != null) { JsonValue exceptionMessage = new JsonValue(ex.getLocalizedMessage()); topValue.addChild("Exception Message", exceptionMessage); }// ww w .j av a2s.co m if (ex.getCause() != null) { JsonValue exceptionCause = new JsonValue(ex.getCause().toString()); topValue.addChild("Exception Cause", exceptionCause); } JsonValue stackTrace = new JsonValue(JsonValue.ValueType.array); for (StackTraceElement element : ex.getStackTrace()) stackTrace.addChild(new JsonValue(element.toString())); topValue.addChild("Stack Trace", stackTrace); return topValue; }
From source file:com.tussle.stream.JsonCollectingWriter.java
License:Open Source License
public JsonValue read() { JsonValue toReturn = new JsonValue(JsonValue.ValueType.object); for (Map.Entry<Entity, Reader> entry : readers.entrySet()) { NameComponent nameComp = Components.nameMapper.get(entry.getKey()); String name;/*w ww .ja v a 2 s . co m*/ if (nameComp == null) { name = "?" + entry.getKey().hashCode(); } else { name = nameComp.getName(); } try { if (entry.getValue().ready()) { String str = Utility.readAll(entry.getValue()); toReturn.addChild(name, new JsonValue(str)); } } catch (IOException ex) { toReturn.addChild(name, Utility.exceptionToJson(ex)); } } //Now read the error stream try { if (errorReader.ready()) { String str = Utility.readAll(errorReader); toReturn.addChild("Error", new JsonValue(str)); } } catch (IOException ex) { toReturn.addChild("Error", Utility.exceptionToJson(ex)); } return toReturn; }
From source file:com.tussle.stream.JsonDistributingWriter.java
License:Open Source License
public void write(JsonValue jsonVal) { try {/* ww w . j a va 2 s. c o m*/ for (JsonValue i : jsonVal) { //Not a typo, we're iterating over the jsonValue we were handed if (writers.containsKey(i.name())) { try { writers.get(i.name()) .write(i.prettyPrint(JsonWriter.OutputType.json, Integer.MAX_VALUE) + "\n"); } catch (IOException ex) { JsonValue value = Utility.exceptionToJson(ex); value.addChild("Invalid String", i); errorWriter.write(value.toString()); } } else { JsonValue value = new JsonValue(JsonValue.ValueType.object); value.addChild("Invalid String", i); errorWriter.write(value.toString()); } } } catch (IOException ex) { throw new SerializationException(ex); } }
From source file:com.tussle.stream.JsonParsingWriter.java
License:Apache License
protected void startObject(String name) { JsonValue value = new JsonValue(ValueType.object); if (current != null) addChild(name, value);// www . j a v a 2 s .c om elements.push(value); current = value; }
From source file:com.tussle.stream.JsonParsingWriter.java
License:Apache License
protected void startArray(String name) { JsonValue value = new JsonValue(ValueType.array); if (current != null) addChild(name, value);//ww w . j av a 2s . com elements.push(value); current = value; }
From source file:com.tussle.stream.JsonParsingWriter.java
License:Apache License
protected void addString(String value) { addChild(names.poll(), new JsonValue(unescape(value))); }
From source file:com.tussle.stream.JsonParsingWriter.java
License:Apache License
protected void addNull() { addChild(names.poll(), new JsonValue(JsonValue.ValueType.nullValue)); }