List of usage examples for com.badlogic.gdx.utils JsonValue toString
public String toString()
From source file:com.jupiter.europa.EuropaGame.java
License:Open Source License
private void loadSettings() { Json json = new Json(); try (BufferedReader reader = Files.newBufferedReader(SETTINGS_FILE)) { JsonValue value = new JsonReader().parse(reader); this.settings = json.fromJson(Settings.class, value.toString()); } catch (Exception ex) { this.settings = new Settings(); this.saveSettings(); }/*from w ww. j a v a2 s .co m*/ // Load the settings to their respective systems this.audio.setMusicVolume(this.settings.musicVolume.get()); }
From source file:com.jupiter.europa.screen.MainMenuScreen.java
License:Open Source License
private void loadGame() { Path saveFile = FileLocations.SAVE_DIRECTORY .resolve(this.loadGameDialog.getGameToLoad() + "." + SaveGame.SAVE_EXTENSION); if (!Files.exists(saveFile)) { return;// w w w . j a v a 2 s .c om } try (BufferedReader reader = Files.newBufferedReader(saveFile)) { Json json = new Json(); JsonValue value = new JsonReader().parse(reader); SaveGame save = json.fromJson(SaveGame.class, value.toString()); EuropaGame.game.startGame(save); } catch (IOException ex) { } }
From source file:com.tussle.stream.JsonDistributingWriter.java
License:Open Source License
public void write(JsonValue jsonVal) { try {//from w w w. ja v a 2 s. c om 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:de.tomgrill.gdxfacebook.core.GDXFacebookBasic.java
License:Apache License
protected void startSilentSignIn() { if (accessToken != null) { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Starting silent sign in."); GDXFacebookGraphRequest request = new GDXFacebookGraphRequest(); request.setMethod(Net.HttpMethods.POST); request.setNode(""); request.putField("batch", "[{\"method\":\"GET\", \"relative_url\":\"me\"},{\"method\":\"GET\", \"relative_url\":\"me/permissions\"}]"); request.putField("include_headers", "false"); request.useCurrentAccessToken(); newGraphRequest(request, new GDXFacebookCallback<JsonResult>() { @Override//from w w w . jav a 2 s .c om public void onSuccess(JsonResult result) { JsonValue value = result.getJsonValue(); if (value != null && value.isArray()) { JsonValue meValue = value.get(0); JsonValue permissionsValue = value.get(1); if (jsonHasCode200AndBody(meValue) && jsonHasCode200AndBody(permissionsValue)) { JsonReader reader = new JsonReader(); JsonValue permissionBodyValue = reader.parse(permissionsValue.getString("body")); JsonValue permissionArray = permissionBodyValue.get("data"); Array<String> grantedPermissions = new Array<String>(); for (int i = 0; i < permissionArray.size; i++) { JsonValue permission = permissionArray.get(i); if (permission.getString("status").equals("granted")) { grantedPermissions.add(permission.getString("permission").toLowerCase()); } } if (arePermissionsGranted(grantedPermissions)) { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in successful. Current token is still valid."); callback.onSuccess(new SignInResult(accessToken, "Silent sign in successful. Current token is still valid.")); } else { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Used access_token is valid but new permissions need to be granted. Need GUI sign in."); callback.onError(new GDXFacebookError( "Used access_token is valid but new permissions need to be granted. Need GUI sign in.")); startGUISignIn(); } } else { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in parse error: " + value.toString()); callback.onError(new GDXFacebookError(value.toString())); startGUISignIn(); } } else { callback.onError(new GDXFacebookError( "Unexpected error occurred while trying to sign in. Error unknown, possible timeout.")); } } private boolean arePermissionsGranted(Array<String> grantedPermissions) { for (int i = 0; i < permissions.size; i++) { if (!grantedPermissions.contains(permissions.get(i).toLowerCase(), false)) { return false; } } return true; } @Override public void onError(GDXFacebookError error) { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in request error: " + error.getErrorMessage()); callback.onError(error); startGUISignIn(); } @Override public void onFail(Throwable t) { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in failed: " + t); callback.onFail(t); startGUISignIn(); } @Override public void onCancel() { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in fail"); callback.onCancel(); startGUISignIn(); } }); } else { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in fail. No existing access token."); } }
From source file:de.tomgrill.gdxfacebook.core.JsonResult.java
License:Apache License
public JsonResult(JsonValue jsonValue) { super(jsonValue.toString()); this.jsonValue = jsonValue; }
From source file:Facebook.GDXFacebookBasic.java
License:Apache License
protected void startSilentSignIn() { if (accessToken != null) { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Starting silent sign in."); GDXFacebookGraphRequest request = new GDXFacebookGraphRequest(); request.setMethod(Net.HttpMethods.POST); request.setNode(""); request.putField("batch", "[{\"method\":\"GET\", \"relative_url\":\"me\"},{\"method\":\"GET\", \"relative_url\":\"me/permissions\"}]"); request.putField("include_headers", "false"); request.useCurrentAccessToken(); newGraphRequest(request, new GDXFacebookCallback<JsonResult>() { @Override/*from w w w.j a v a2 s . c o m*/ public void onSuccess(JsonResult result) { JsonValue value = result.getJsonValue(); if (value != null && value.isArray()) { JsonValue meValue = value.get(0); JsonValue permissionsValue = value.get(1); if (jsonHasCode200AndBody(meValue) && jsonHasCode200AndBody(permissionsValue)) { JsonReader reader = new JsonReader(); JsonValue permissionBodyValue = reader.parse(permissionsValue.getString("body")); JsonValue permissionArray = permissionBodyValue.get("data"); Array<String> grantedPermissions = new Array<String>(); for (int i = 0; i < permissionArray.size; i++) { JsonValue permission = permissionArray.get(i); if (permission.getString("status").equals("granted")) { grantedPermissions.add(permission.getString("permission").toLowerCase()); } } if (arePermissionsGranted(grantedPermissions)) { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in successful. Current token is still valid."); callback.onSuccess(new SignInResult(accessToken, "Silent sign in successful. Current token is still valid.")); } else { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Used access_token is valid but new permissions need to be granted. Need GUI sign in."); callback.onError(new GDXFacebookError( "Used access_token is valid but new permissions need to be granted. Need GUI sign in.")); startGUISignIn(); } } else { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in error: " + value.toString()); callback.onError(new GDXFacebookError(value.toString())); startGUISignIn(); } } else { callback.onError(new GDXFacebookError( "Unexpected error occurred while trying to sign in. Error unknown, possible timeout.")); } } private boolean arePermissionsGranted(Array<String> grantedPermissions) { for (int i = 0; i < permissions.size; i++) { if (!grantedPermissions.contains(permissions.get(i).toLowerCase(), false)) { return false; } } return true; } @Override public void onError(GDXFacebookError error) { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in error: " + error.getErrorMessage()); callback.onError(error); startGUISignIn(); } @Override public void onFail(Throwable t) { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in failed: " + t); callback.onFail(t); startGUISignIn(); } @Override public void onCancel() { signOut(); Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in fail"); callback.onCancel(); startGUISignIn(); } }); } else { Gdx.app.debug(GDXFacebookVars.LOG_TAG, "Silent sign in fail. No existing access token."); } }