@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); }
@Test void getRequest() throws IOException { String expected = TestUtils.getResourceRequestString("testsResources/GetYourUserProfile_request.txt", isDummy ? null : apiKey); GetYourUserProfile getYourUserProfile = new GetYourUserProfile(apiKey); StringWriter writer = new StringWriter(); Json json = new Json(JsonWriter.OutputType.json); json.setWriter(writer); json.writeObjectStart(); getYourUserProfile.getRequest(json); json.writeObjectEnd(); String actual = writer.toString(); //remove "DeviceOperatingSystem" expected = expected.replace("UNKNOWN", GetYourUserProfile.getDeviceOperatingSystem()); assertEquals(expected, actual, "Should be equals"); }
/** * Load a save file. * * @param fileName * The path to the file. */ public void load(FileHandle file) { this.clear(); final Json json = new Json(JsonWriter.OutputType.json); container = json.fromJson(Container.class, file.readString()); String path = file.path(); int lastSlash = path.lastIndexOf("/"); container.basePath = path.substring(0, lastSlash); for (int i = 0; i < container.states.size; i++) { final MusicState state = container.states.get(i); add(state); } }
public Analytics() { sessionId = MathUtils.random(100000) + "-" + MathUtils.random(100000); if (FlippyBird.instance.preferences.contains("user_id")) { userId = FlippyBird.instance.preferences.getString("user_id"); } else { userId = MathUtils.random(100000) + "-" + MathUtils.random(100000); FlippyBird.instance.preferences.putString("user_id", userId); FlippyBird.instance.preferences.flush(); } json = new Json(); json.setOutputType(JsonWriter.OutputType.json); sendUserEvent(FlippyBird.instance.platform); }
public static <T> void flush(T thing, String dir, String name) { try { final String path = dir + "/" + name; final File file = new File(path); if (!file.exists() && !file.createNewFile()) { throw new RuntimeException(String.format("Failed to create file '%s' because <unknown>.", path)); } final PrintWriter writer = new PrintWriter(path); json.setOutputType(JsonWriter.OutputType.minimal); writer.print(json.prettyPrint(thing)); writer.close(); } catch (Exception e) { Debug.warning(e.getMessage()); //??? } }
/** * Call newgrounds.io gateway * * @param component see http://www.newgrounds.io/help/components/ * @param parameters also see NG doc * @param req callback object */ protected void sendToGateway(String component, JsonValue parameters, RequestResultRunnable req) { // if no callback is needed, provide a no-op callback if (req == null) req = new RequestResultRunnable() { @Override public void run(String json) { } }; sendForm("{\"app_id\": \"" + ngAppId + "\",\"session_id\":\"" + sessionId + "\"," + "\"call\": {\"component\": \"" + component + "\",\"parameters\": " + (parameters == null ? "{}" : parameters.toJson(JsonWriter.OutputType.json)) + "}}\n", req); }
@Test public void testDefaultMapping() { ControllerMappings mappings = new ControllerMappings() { @Override public boolean getDefaultMapping(MappedInputs defaultMapping) { defaultMapping.putMapping(new MappedInput(0, new ControllerAxis(5))); defaultMapping.putMapping(new MappedInput(1, new ControllerButton(2))); return true; } }; ConfiguredInput axis = new ConfiguredInput(ConfiguredInput.Type.axis, 0); ConfiguredInput button = new ConfiguredInput(ConfiguredInput.Type.button, 1); mappings.addConfiguredInput(axis); mappings.addConfiguredInput(button); // ok, configuration done... mappings.commitConfig(); // now check MockedController controller = new MockedController(); MappedController mappedController = new MappedController(controller, mappings); controller.pressedButton = 2; assertTrue(mappedController.isButtonPressed(1)); controller.pressedButton = 1; assertFalse(mappedController.isButtonPressed(1)); TestControllerAdapter controllerAdapter = new TestControllerAdapter(mappings); assertTrue(controllerAdapter.buttonDown(controller, 2)); assertEquals(1, controllerAdapter.lastEventId); assertTrue(controllerAdapter.axisMoved(controller, 5, .5f)); assertEquals(0, controllerAdapter.lastEventId); // serialize gives only recorded mappings assertEquals("[]", mappings.toJson().toJson(JsonWriter.OutputType.json)); }
/** * 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); }
/** * @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); }
public void save(FileHandle file) { moveImportedFiles(saveFile, file); if (main.getProjectData().areResourcesRelative()) { makeResourcesRelative(file); } saveFile = file; putRecentFile(file.path()); Json json = new Json(JsonWriter.OutputType.minimal); json.setUsePrototypes(false); file.writeString(json.prettyPrint(this), false, "UTF8"); setChangesSaved(true); }
public void load(FileHandle file) { Json json = new Json(JsonWriter.OutputType.minimal); ProjectData instance = json.fromJson(ProjectData.class, file.reader("UTF8")); newProject = instance.newProject; jsonData.set(instance.jsonData); atlasData.set(instance.atlasData); preferences.clear(); preferences.putAll(instance.preferences); //set main for custom classes, styles, and properties for (CustomClass customClass : jsonData.getCustomClasses()) { customClass.setMain(main); } saveFile = file; putRecentFile(file.path()); setLastOpenSavePath(file.parent().path() + "/"); atlasData.atlasCurrent = false; correctFilePaths(); if (verifyDrawablePaths().size == 0 && verifyFontPaths().size == 0) { main.getRootTable().produceAtlas(); main.getRootTable().populate(); } setChangesSaved(true); }
@Test void getRequest() throws IOException { String expected = TestUtils.getResourceRequestString("testsResources/SearchGcCoordinate_request.txt", isDummy ? null : apiKey); //set MembershipType for tests to Premium GroundspeakAPI.setTestMembershipType(ApiResultState.MEMBERSHIP_TYPE_PREMIUM); byte apiState; if (GroundspeakAPI.isPremiumMember()) { apiState = 2; } else { apiState = 1; } SearchCoordinate searchCoordinate = new SearchCoordinate(apiKey, 50 , LONGRI_HOME_COORDS, 50000, apiState); StringWriter writer = new StringWriter(); Json json = new Json(JsonWriter.OutputType.json); json.setWriter(writer); searchCoordinate.getRequest(json); String actual = writer.toString(); assertEquals(expected, actual); }
@Test void getRequest() throws IOException { String expected = TestUtils.getResourceRequestString("testsResources/SearchGc_request.txt", isDummy ? null : apiKey); SearchGC searchGC = new SearchGC(apiKey, "GC1T33T"); StringWriter writer = new StringWriter(); Json json = new Json(JsonWriter.OutputType.json); json.setWriter(writer); searchGC.getRequest(json); String actual = writer.toString(); assertEquals(expected, actual, "Should be equals"); }
public static void write(PlayerConfig player) { Json json = new Json(); json.setOutputType(JsonWriter.OutputType.json); Path p = Paths.get("player/" + player.getId() + "/config.json"); try (FileWriter fw = new FileWriter(p.toFile())) { fw.write(json.prettyPrint(player)); fw.flush(); } catch (IOException e) { e.printStackTrace(); } }
/** * コースデータを保存する * * @param cd コースデータ */ public void write(String name, CourseData cd) { try { Json json = new Json(); json.setOutputType(JsonWriter.OutputType.json); OutputStreamWriter fw = new OutputStreamWriter(new BufferedOutputStream( new FileOutputStream(coursedir + "/" + name + ".json")), "UTF-8"); fw.write(json.prettyPrint(cd)); fw.flush(); fw.close(); } catch (IOException e) { e.printStackTrace(); } }
@Override public VersionData read(Json json, JsonValue jsonData, Class type) { VersionData data = new VersionData(); data.plainJson = jsonData.prettyPrint(JsonWriter.OutputType.json, 0); for (JsonValue entry = jsonData.child; entry != null; entry = entry.next) { switch (entry.name) { case "id": data.id = entry.asInt(); break; case "html_url": data.url = entry.asString(); break; case "tag_name": String tagName = entry.asString(); data.tag = tagName; data.version = new Version(tagName); break; case "name": data.name = entry.asString(); break; case "body": data.description = entry.asString(); break; } } return data; }
public static ProjectSettings convert(ProjectSettingsDescriptor descriptor) { ProjectSettings settings = new ProjectSettings(); if(descriptor == null) return settings; // export settings settings.getExport().allAssets = descriptor.isExportAllAssets(); settings.getExport().compressScenes = descriptor.isExportCompressScenes(); if(descriptor.getExportOutputFolder() != null && descriptor.getExportOutputFolder().length() > 0) { settings.getExport().outputFolder = new FileHandle(descriptor.getExportOutputFolder()); } settings.getExport().jsonType = JsonWriter.OutputType.valueOf(descriptor.getJsonType()); return settings; }
private String generateJsonTemplate(String shaderName) { StringWriter stringWriter = new StringWriter(); Json json = new Json(JsonWriter.OutputType.javascript); json.setWriter(stringWriter); json.writeObjectStart(); { json.writeValue("class", macbury.forge.shaders.Default.class.getName()); json.writeValue("fragment", shaderName); json.writeValue("vertex", shaderName); json.writeArrayStart("structs"); { } json.writeArrayEnd(); json.writeArrayStart("uniforms"); { json.writeValue("ProjectionMatrix"); json.writeValue("WorldTransform"); } json.writeArrayEnd(); json.writeObjectStart("helpers"); { json.writeArrayStart("vertex"); { } json.writeArrayEnd(); json.writeArrayStart("fragment"); { } json.writeArrayEnd(); } json.writeObjectEnd(); } json.writeObjectEnd(); return stringWriter.toString(); }
@Test public void testButtonMapping() { ControllerMappings mappings = new ControllerMappings(); // We test 4 buttons ConfiguredInput button1 = new ConfiguredInput(ConfiguredInput.Type.button, 1); ConfiguredInput button2 = new ConfiguredInput(ConfiguredInput.Type.button, 2); ConfiguredInput button3 = new ConfiguredInput(ConfiguredInput.Type.button, 3); ConfiguredInput button4 = new ConfiguredInput(ConfiguredInput.Type.button, 4); mappings.addConfiguredInput(button1); mappings.addConfiguredInput(button2); mappings.addConfiguredInput(button3); mappings.addConfiguredInput(button4); // ok, configuration done... mappings.commitConfig(); // now we connect a Controller... and map MockedController controller = new MockedController(); controller.pressedButton = 107; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 1)); //next call too fast assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 2)); controller.pressedButton = 108; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 2)); controller.pressedButton = 1; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 3)); //TODO add assertion for check if record is complete assertFalse(mappings.getControllerMapping(controller).checkCompleted()); controller.pressedButton = 4; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 4)); controller.pressedButton = -1; assertTrue(mappings.getControllerMapping(controller).checkCompleted()); System.out.println(mappings.toJson().toJson(JsonWriter.OutputType.json)); // now check TestControllerAdapter controllerAdapter = new TestControllerAdapter(mappings); assertTrue(controllerAdapter.buttonDown(controller, 108)); assertEquals(2, controllerAdapter.lastEventId); assertTrue(controllerAdapter.buttonDown(controller, 4)); assertEquals(4, controllerAdapter.lastEventId); assertFalse(controllerAdapter.buttonDown(controller, 2)); assertEquals(4, controllerAdapter.lastEventId); MappedController mappedController = new MappedController(controller, mappings); controller.pressedButton = 4; assertTrue(mappedController.isButtonPressed(4)); controller.pressedButton = 108; assertTrue(mappedController.isButtonPressed(2)); controller.pressedButton = 99; assertFalse(mappedController.isButtonPressed(2)); assertFalse(mappedController.isButtonPressed(5)); }
@Test public void testAxisToAxisMapping() { ControllerMappings mappings = new ControllerMappings(); // We test 3 axis ConfiguredInput axis1 = new ConfiguredInput(ConfiguredInput.Type.axis, 5); ConfiguredInput axis2 = new ConfiguredInput(ConfiguredInput.Type.axisAnalog, 6); ConfiguredInput axis3 = new ConfiguredInput(ConfiguredInput.Type.axisDigital, 7); mappings.addConfiguredInput(axis1); mappings.addConfiguredInput(axis2); mappings.addConfiguredInput(axis3); // ok, configuration done... mappings.commitConfig(); // now we connect a Controller... and map MockedController controller = new MockedController(); controller.axisValues = new float[3]; controller.povDirection = PovDirection.center; controller.axisValues[0] = .2f; controller.axisValues[1] = .6f; controller.axisValues[2] = -.2f; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 5)); //next call too fast assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 6)); controller.axisValues[0] = .2f; controller.axisValues[1] = .1f; controller.axisValues[2] = 0; assertEquals(ControllerMappings.RecordResult.nothing_done, mappings.recordMapping(controller, 6)); controller.axisValues[0] = .6f; controller.axisValues[1] = .5f; controller.axisValues[2] = 0; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 6)); controller.axisValues[0] = .6f; controller.axisValues[1] = .5f; controller.axisValues[2] = -1; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 7)); assertTrue(mappings.getControllerMapping(controller).checkCompleted()); System.out.println(mappings.toJson().toJson(JsonWriter.OutputType.json)); // now check TestControllerAdapter controllerAdapter = new TestControllerAdapter(mappings); // the digital assertTrue(controllerAdapter.axisMoved(controller, 2, .8f)); assertEquals(7, controllerAdapter.lastEventId); assertTrue(controllerAdapter.axisMoved(controller, 2, -.8f)); assertEquals(7, controllerAdapter.lastEventId); assertTrue(controllerAdapter.axisMoved(controller, 2, -.2f)); assertEquals(7, controllerAdapter.lastEventId); assertTrue(controllerAdapter.axisMoved(controller, 1, .8f)); assertEquals(5, controllerAdapter.lastEventId); assertTrue(controllerAdapter.axisMoved(controller, 0, -.9f)); assertEquals(6, controllerAdapter.lastEventId); MappedController mappedController = new MappedController(controller, mappings); controller.axisValues[0] = .6f; controller.axisValues[1] = .5f; controller.axisValues[2] = -.7f; assertEquals(.6f, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(.5f, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(-1f, mappedController.getConfiguredAxisValue(7), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(3), .01f); }
@Test public void testButtonToAxisMapping() { ControllerMappings mappings = new ControllerMappings(); // We test 3 axis ConfiguredInput axis1 = new ConfiguredInput(ConfiguredInput.Type.axis, 5); ConfiguredInput axis2 = new ConfiguredInput(ConfiguredInput.Type.axisAnalog, 6); ConfiguredInput axis3 = new ConfiguredInput(ConfiguredInput.Type.axisDigital, 7); mappings.addConfiguredInput(axis1); mappings.addConfiguredInput(axis2); mappings.addConfiguredInput(axis3); // ok, configuration done... mappings.commitConfig(); // now we connect a Controller... and map MockedController controller = new MockedController(); controller.pressedButton = 0; controller.axisValues = new float[3]; assertEquals(ControllerMappings.RecordResult.need_second_button, mappings.recordMapping(controller, 5)); //next call too fast assertEquals(ControllerMappings.RecordResult.not_added_need_button, mappings.recordMapping(controller, 5)); //now an axis is moved controller.axisValues[1] = .5f; controller.pressedButton = -1; assertEquals(ControllerMappings.RecordResult.not_added_need_button, mappings.recordMapping(controller, 5)); controller.pressedButton = 1; controller.axisValues[1] = 0f; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 5)); // analog do not accept buttons controller.pressedButton = 2; assertEquals(ControllerMappings.RecordResult.nothing_done, mappings.recordMapping(controller, 6)); controller.pressedButton = 1; assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 7)); controller.pressedButton = 3; assertEquals(ControllerMappings.RecordResult.need_second_button, mappings.recordMapping(controller, 7)); controller.pressedButton = 4; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 7)); assertFalse(mappings.getControllerMapping(controller).checkCompleted()); System.out.println(mappings.toJson().toJson(JsonWriter.OutputType.json)); // now check TestControllerAdapter controllerAdapter = new TestControllerAdapter(mappings); // the digital assertTrue(controllerAdapter.buttonDown(controller, 0)); assertEquals(5, controllerAdapter.lastEventId); assertTrue(controllerAdapter.buttonDown(controller, 1)); assertEquals(5, controllerAdapter.lastEventId); assertTrue(controllerAdapter.buttonDown(controller, 3)); assertEquals(7, controllerAdapter.lastEventId); assertTrue(controllerAdapter.buttonUp(controller, 1)); assertEquals(5, controllerAdapter.lastEventId); assertFalse(controllerAdapter.buttonUp(controller, 2)); assertEquals(5, controllerAdapter.lastEventId); MappedController mappedController = new MappedController(controller, mappings); controller.pressedButton = 5; assertEquals(0, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(7), .01f); controller.pressedButton = 3; assertEquals(0, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(1, mappedController.getConfiguredAxisValue(7), .01f); controller.pressedButton = 4; assertEquals(0, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(-1, mappedController.getConfiguredAxisValue(7), .01f); }
@Test public void testPovToAxisMapping() { ControllerMappings mappings = new ControllerMappings(); // We test 3 axis ConfiguredInput axis1 = new ConfiguredInput(ConfiguredInput.Type.axis, 5); ConfiguredInput axis2 = new ConfiguredInput(ConfiguredInput.Type.axisAnalog, 6); ConfiguredInput axis3 = new ConfiguredInput(ConfiguredInput.Type.axisDigital, 7); mappings.addConfiguredInput(axis1); mappings.addConfiguredInput(axis2); mappings.addConfiguredInput(axis3); // ok, configuration done... mappings.commitConfig(); // now we connect a Controller... and map MockedController controller = new MockedController(); controller.axisValues = new float[3]; controller.povDirection = PovDirection.east; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 5)); //next call too fast assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 7)); //not two directions controller.povDirection = PovDirection.northWest; assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 7)); //not same direction on different configurations controller.povDirection = PovDirection.west; assertEquals(ControllerMappings.RecordResult.not_added, mappings.recordMapping(controller, 7)); //not for analog axis controller.povDirection = PovDirection.north; assertEquals(ControllerMappings.RecordResult.nothing_done, mappings.recordMapping(controller, 6)); assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 7)); assertFalse(mappings.getControllerMapping(controller).checkCompleted()); System.out.println(mappings.toJson().toJson(JsonWriter.OutputType.json)); // now check TestControllerAdapter controllerAdapter = new TestControllerAdapter(mappings); assertFalse(controllerAdapter.povMoved(controller, 1, PovDirection.center)); // the digital assertTrue(controllerAdapter.povMoved(controller, 0, PovDirection.center)); assertTrue(controllerAdapter.lastEventId == 5 || controllerAdapter.lastEventId == 7); assertTrue(controllerAdapter.povMoved(controller, 0, PovDirection.east)); assertTrue(controllerAdapter.lastEventId == 5 || controllerAdapter.lastEventId == 7); assertTrue(controllerAdapter.povMoved(controller, 0, PovDirection.southEast)); assertTrue(controllerAdapter.lastEventId == 5 || controllerAdapter.lastEventId == 7); assertTrue(controllerAdapter.povMoved(controller, 0, PovDirection.west)); assertTrue(controllerAdapter.lastEventId == 5 || controllerAdapter.lastEventId == 7); MappedController mappedController = new MappedController(controller, mappings); controller.povDirection = PovDirection.center; assertEquals(0, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(7), .01f); controller.povDirection = PovDirection.north; assertEquals(0, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(-1, mappedController.getConfiguredAxisValue(7), .01f); controller.povDirection = PovDirection.east; assertEquals(1, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(7), .01f); controller.povDirection = PovDirection.southWest; assertEquals(-1, mappedController.getConfiguredAxisValue(5), .01f); assertEquals(0, mappedController.getConfiguredAxisValue(6), .01f); assertEquals(1, mappedController.getConfiguredAxisValue(7), .01f); }
@Test public void testJsonSaveLoad() { ControllerMappings mappings = new ControllerMappings(); mappings.addConfiguredInput(new ConfiguredInput(ConfiguredInput.Type.button, 1)); mappings.addConfiguredInput(new ConfiguredInput(ConfiguredInput.Type.axis, 2)); mappings.addConfiguredInput(new ConfiguredInput(ConfiguredInput.Type.axis, 3)); mappings.addConfiguredInput(new ConfiguredInput(ConfiguredInput.Type.axis, 4)); mappings.commitConfig(); // now we connect a Controller... and map MockedController controller = new MockedController(); controller.axisValues = new float[3]; controller.povDirection = PovDirection.center; controller.axisValues[0] = 1f; controller.pressedButton = -1; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 2)); controller.pressedButton = 2; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 1)); controller.pressedButton = 1; assertEquals(ControllerMappings.RecordResult.need_second_button, mappings.recordMapping(controller, 3)); controller.pressedButton = 0; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 3)); controller.pressedButton = -1; controller.povDirection = PovDirection.east; assertEquals(ControllerMappings.RecordResult.recorded, mappings.recordMapping(controller, 4)); JsonValue json = mappings.toJson(); System.out.println(json.toJson(JsonWriter.OutputType.json)); MappedController mappedController = new MappedController(controller, mappings); mappings.resetMappings(controller); mappedController.refreshMappingCache(); assertEquals(0, mappedController.getConfiguredAxisValue(4), 0.1f); mappings.fillFromJson(json); mappedController.refreshMappingCache(); assertEquals(1, mappedController.getConfiguredAxisValue(4), 0.1f); controller.pressedButton = 2; assertTrue(mappedController.isButtonPressed(1)); controller.pressedButton = 1; assertEquals(1, mappedController.getConfiguredAxisValue(3), 0.1f); }
private Object processObject(Json json, JsonValue jsonData) { return json.fromJson(this.contentType, jsonData.toJson(JsonWriter.OutputType.json)); }
protected void post(final GenericCallBack<ApiResultState> readyCallBack, final ICancel iCancel) { CB.postAsync(new Runnable() { @Override public void run() { waitApiCallLimit(iCancel); if (iCancel != null && iCancel.cancel()) readyCallBack.callBack(ApiResultState.CANCELED); String URL = Config.StagingAPI.getValue() ? STAGING_GS_LIVE_URL : GS_LIVE_URL; StringWriter writer = new StringWriter(); Json json = new Json(JsonWriter.OutputType.json); json.setWriter(writer); json.writeObjectStart(); getRequest(json); json.writeObjectEnd(); final Net.HttpRequest httpPost = new Net.HttpRequest(Net.HttpMethods.POST); httpPost.setUrl(URL + getCallUrl()); httpPost.setHeader("format", "json"); httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); httpPost.setContent(writer.toString()); httpPost.setIncludeCredentials(true); final AtomicBoolean checkCancel = new AtomicBoolean(iCancel != null); if (checkCancel.get()) { //start cancel listener CB.postAsync(new Runnable() { @Override public void run() { while (checkCancel.get()) { if (iCancel.cancel()) { Gdx.net.cancelHttpRequest(httpPost); checkCancel.set(false); } try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } } } }); } log.debug("Send Post request"); Gdx.net.sendHttpRequest(httpPost, new Net.HttpResponseListener() { @Override public void handleHttpResponse(Net.HttpResponse httpResponse) { log.debug("Handle Response"); checkCancel.set(false); PostRequest.this.handleHttpResponse(httpResponse, readyCallBack); } @Override public void failed(Throwable t) { log.error("Request failed", t); checkCancel.set(false); readyCallBack.callBack(ApiResultState.API_ERROR); } @Override public void cancelled() { log.debug("Request cancelled"); checkCancel.set(false); readyCallBack.callBack(ApiResultState.CANCELED); } }); } }); }
public KeyMapper() { json.setOutputType(JsonWriter.OutputType.json); }
@Override public void open() throws IOException { close(); syncFileWriter = syncPropertiesFile.writer(false); asyncFileWriter = asyncPropertiesFile.writer(false); syncJsonWriter = new JsonWriter(syncFileWriter); asyncJsonWriter = new JsonWriter(asyncFileWriter); syncJsonWriter.setOutputType(OutputType.minimal); asyncJsonWriter.setOutputType(OutputType.minimal); syncJsonWriter.array(); asyncJsonWriter.array(); }
private static void saveScreenToJSON(String projPath, ScreenData scrData) throws Exception { String path = projPath + PATH_SEPARATOR + scrData.getJsonPath(); File scrFile = new File(path); if (scrFile.exists()) { scrFile.delete(); } scrFile.createNewFile(); StringWriter strWriter = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(strWriter); jsonWriter.object() .object("screen") .set("name", scrData.getName()) .set("width", scrData.getWidth()) .set("height", scrData.getHeight()) .set("xmlPath", scrData.getXmlPath()) .set("jsonPath", scrData.getJsonPath()); if ((scrData.getBgImage() != null)) { jsonWriter.object("bg") .set("name", scrData.getBgImage().name) .set("type", (getWidgetType(scrData.getBgImage()) != null) ? getWidgetType(scrData.getBgImage()).ordinal() : -1) .set("texturePath", FileUtils.getElementRelativePath(projPath, ((GdxImage)scrData.getBgImage()).getTexPath())) .set("scaleX", scrData.getBgImage().scaleX) .set("scaleY", scrData.getBgImage().scaleY) .set("x", scrData.getBgImage().x) .set("y", scrData.getBgImage().y) .set("angle", scrData.getBgImage().rotation) .pop(); } if ((scrData.getPath() != null) && (scrData.getPath().getPath() != null)) { jsonWriter.object("path") .set("xmlPath", scrData.getPath().getXmlPath()) .set("jsonPath", scrData.getPath().getJsonPath()) .pop(); } jsonWriter.pop(); jsonWriter.pop(); jsonWriter.close(); FileWriter writer = new FileWriter(new File(path)); writer.write(strWriter.toString()); writer.close(); }
private static void savePathToJSON(String projPath, GdxPath gdxPath) throws Exception { String path = projPath + gdxPath.getJsonPath(); File pathFile = new File(path); if (pathFile.exists()) { pathFile.delete(); } pathFile.createNewFile(); StringWriter strWriter = new StringWriter(); JsonWriter jsonWriter = new JsonWriter(strWriter); jsonWriter.object() .object("path") .set("name", gdxPath.getName()) .set("pointsCnt", gdxPath.getPointsCnt()) .set("controlColor", gdxPath.getControlColor()) .set("segmentColor", gdxPath.getSegmentColor()) .set("selectColor", gdxPath.getSelectColor()) .set("xmlPath", gdxPath.getXmlPath()) .set("jsonPath", gdxPath.getJsonPath()); if ((gdxPath.getPath() != null) && (gdxPath.getPath().getPathVerticesCount() > 0)) { jsonWriter.array("controlVertices"); Vector3 controlVertex; for (int i=0; i<gdxPath.getControlPath().size(); i++) { controlVertex = gdxPath.getControlPath().get(i); jsonWriter.object() .set("id", i) .set("x", controlVertex.x) .set("y", controlVertex.y) .pop(); } jsonWriter.pop(); jsonWriter.array("vertices"); PathVertex vertex; for (int i=0; i<gdxPath.getPath().getPathVerticesCount(); i++) { vertex = gdxPath.getPath().getPathVertexByIndex(i); jsonWriter.object() .set("id", i) .set("x", vertex.getPosition().x) .set("y", vertex.getPosition().y) .set("tanX", vertex.getTangentNornal().x) .set("tanY", vertex.getTangentNornal().y) .set("angle", vertex.getAngle()) .pop(); } jsonWriter.pop(); } jsonWriter.pop(); jsonWriter.pop(); jsonWriter.close(); FileWriter writer = new FileWriter(new File(path)); writer.write(strWriter.toString()); writer.close(); }
/** * Save to a file. * * @param fileName * The path to the file. */ public void save(FileHandle file) { final Json json = new Json(JsonWriter.OutputType.json); final Container container = new Container(states.values().toArray()); file.writeString(json.prettyPrint(container), false); }