com.badlogic.gdx.utils.JsonReader Java Examples
The following examples show how to use
com.badlogic.gdx.utils.JsonReader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AzurLaneSpineCharacterDecoder.java From AzurLaneSpineCharacterDecoder with MIT License | 6 votes |
@Override public void create() { batch = new SpriteBatch(); img = new Texture("core/assets/WatchDog.png"); camera = new OrthographicCamera(); camera.setToOrtho(false); spineKeeperArray = new Array<PerSpineKeeper>(); if (jsonType) { JsonReader reader = new JsonReader(); JsonValue jsonValue = reader.parse(Gdx.files.absolute(args.get(0))); System.out.println(); array = jsonValue.asStringArray(); size = array.length; } path = System.getProperty("user.dir"); scale=Float.parseFloat(Gdx.files.internal("core/assets/scale.txt").readString()); }
Example #2
Source File: BodyEditorLoader.java From uracer-kotd with Apache License 2.0 | 5 votes |
private Model readJson (String str) { Model m = new Model(); JsonValue root = new JsonReader().parse(str); JsonValue bodies = root.get("rigidBodies"); for (JsonValue body = bodies.child(); body != null; body = body.next()) { RigidBodyModel rbModel = readRigidBody(body); m.rigidBodies.put(rbModel.name, rbModel); } return m; }
Example #3
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
/** * Helper method when just interested if GameJolt request was successful */ protected boolean parseSuccessFromResponse(String json) { JsonValue response = null; boolean success; try { response = new JsonReader().parse(json).get("response"); success = response != null && response.getBoolean("success"); } catch (Throwable t) { Gdx.app.error(GAMESERVICE_ID, "Cannot parse GameJolt response: " + json, t); success = false; } return success; }
Example #4
Source File: BodyEditorLoader.java From ninja-rabbit with GNU General Public License v2.0 | 5 votes |
private Model readJson(final String str) { Model m = new Model(); JsonValue rootElem = new JsonReader().parse(str); JsonValue bodiesElems = rootElem.get("rigidBodies"); for (int i = 0; i < bodiesElems.size; i++) { JsonValue bodyElem = bodiesElems.get(i); RigidBodyModel rbModel = readRigidBody(bodyElem); m.rigidBodies.put(rbModel.name, rbModel); } return m; }
Example #5
Source File: JsonResultUnitTests.java From gdx-facebook with Apache License 2.0 | 5 votes |
@Test public void setGetJsonValue() { JsonReader writer = new JsonReader(); JsonValue value = writer.parse("{testValue:2}"); fixture.setJsonValue(value); assertEquals(value, fixture.getJsonValue()); }
Example #6
Source File: JsonResultUnitTests.java From gdx-facebook with Apache License 2.0 | 5 votes |
@Test public void constructorWithJsonValue() { JsonReader writer = new JsonReader(); JsonValue value = writer.parse("{testValue:5}"); fixture = new JsonResult(value); assertEquals(value, fixture.getJsonValue()); assertTrue(fixture.getJsonValue().has("testValue")); assertEquals(5, fixture.getJsonValue().getInt("testValue")); }
Example #7
Source File: SceneLoader.java From Mundus with Apache License 2.0 | 5 votes |
public Scene load(String name) { final JsonReader reader = new JsonReader(); final JsonValue json = reader.parse(root.child(name)); Scene scene = new Scene(); scene.setId(json.getInt(JsonScene.ID)); scene.setName(json.getString(JsonScene.NAME)); // game objects for(JsonValue go : json.get(JsonScene.GAME_OBJECTS)) { scene.sceneGraph.addGameObject(convertGameObject(scene.sceneGraph, go)); } return scene; }
Example #8
Source File: WorldSerialization.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
/** * Load the world description in 'world.json'. * * @throws IOException */ public void loadWorldDesc() throws IOException { String worldFilename = EngineAssetManager.WORLD_FILENAME; if (!EngineAssetManager.getInstance().getModelFile(worldFilename).exists()) { // Search the world file with ".json" ext if not found. worldFilename = EngineAssetManager.WORLD_FILENAME + ".json"; if (!EngineAssetManager.getInstance().getModelFile(worldFilename).exists()) { EngineLogger.error("ERROR LOADING WORLD: world file not found."); w.dispose(); throw new IOException("ERROR LOADING WORLD: world file not found."); } } JsonValue root = new JsonReader() .parse(EngineAssetManager.getInstance().getModelFile(worldFilename).reader("UTF-8")); Json json = new BladeJson(w, Mode.MODEL); json.setIgnoreUnknownFields(true); int width = json.readValue("width", Integer.class, root); int height = json.readValue("height", Integer.class, root); // We know the world width, so we can set the scale EngineAssetManager.getInstance().setScale(width, height); float scale = EngineAssetManager.getInstance().getScale(); w.setWidth((int) (width * scale)); w.setHeight((int) (height * scale)); w.setInitChapter(json.readValue("initChapter", String.class, root)); w.getVerbManager().read(json, root); w.getI18N().loadWorld(EngineAssetManager.MODEL_DIR + EngineAssetManager.WORLD_FILENAME); }
Example #9
Source File: ModelTools.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public static void readableInkDialogs(String story, String lang) throws IOException { String file = Ctx.project.getModelPath() + "/" + story + EngineAssetManager.INK_EXT; BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); StringBuilder sb = new StringBuilder(); try { String line = br.readLine(); // Replace the BOM mark if (line != null) line = line.replace('\uFEFF', ' '); while (line != null) { sb.append(line); sb.append("\n"); line = br.readLine(); } } finally { br.close(); } JsonValue root = new JsonReader().parse(sb.toString()); // TODO: Add lang and check if default File propFile = new File(Ctx.project.getModelPath() + "/" + story + "-ink.properties"); OrderedProperties langProp = new OrderedPropertiesBuilder().withSuppressDateInComment(true).withOrdering() .build(); langProp.load(new InputStreamReader(new FileInputStream(propFile), I18N.ENCODING)); // .md generation to have a better readable document of texts StringBuilder mdString = new StringBuilder(); readableInkDialogsInternal(root, mdString, langProp); FileUtils.writeStringToFile(new File(Ctx.project.getModelPath() + "/" + story + "-DIALOGS.txt"), mdString.toString()); }
Example #10
Source File: DisableActionAction.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public Action getAction() { if(action == null) { Json json = new Json(); JsonValue root = new JsonReader().parse(serializedAction); action = ActionUtils.readJson(w, json, root); } return action; }
Example #11
Source File: ProjectDataConverter.java From libGDX-Path-Editor with Apache License 2.0 | 4 votes |
private static GdxPath getPathFromJSON(String projPath, String path) throws Exception { File scrFile = new File(projPath + path); if (!scrFile.exists()) { throw new Exception(); } File xmlFile = new File(projPath + path); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(xmlFile), "utf8")); JsonReader jsonReader = new JsonReader(); OrderedMap<String, Object> jsonData = (OrderedMap<String, Object>) jsonReader.parse(br); if (jsonData.get("path") == null) { throw new Exception(); } OrderedMap<String, Object> pathData = (OrderedMap<String, Object>) jsonData.get("path"); String name = (String) pathData.get("name"); int pointsCnt = Math.round((Float) pathData.get("pointsCnt")); String controlColor = (String) pathData.get("controlColor"); String segmentColor = (String) pathData.get("segmentColor"); String selectColor = (String) pathData.get("selectColor"); String xml = (String) pathData.get("xmlPath"); String json = (String) pathData.get("jsonPath"); if ((name.length() <= 0) || (pointsCnt < 0) || (controlColor.length() <= 0) || (segmentColor.length() <= 0) || (selectColor.length() <= 0) || (xml.length() <= 0) || (json.length() <= 0)) { throw new Exception(); } GdxPath gdxPath = new GdxPath(); gdxPath.setName(name); gdxPath.setPointsCnt(pointsCnt); gdxPath.setControlColor(controlColor); gdxPath.setSegmentColor(segmentColor); gdxPath.setSelectColor(selectColor); gdxPath.setXmlPath(xml); gdxPath.setJsonPath(json); if (pathData.get("controlVertices") != null) { Array<OrderedMap<String, Object>> controlVerticesData = (Array<OrderedMap<String, Object>>) pathData.get("controlVertices"); ArrayList<Vector3> controlVertices = new ArrayList<Vector3>(); OrderedMap<String, Object> cvertexData; for (int i=0; i<controlVerticesData.size; i++) { cvertexData = controlVerticesData.get(i); controlVertices.add(new Vector3((Float) cvertexData.get("x"), (Float) cvertexData.get("y"), 0f)); } gdxPath.setControlPath(controlVertices); } else { throw new Exception(); } if (pathData.get("vertices") != null) { Array<OrderedMap<String, Object>> verticesData = (Array<OrderedMap<String, Object>>) pathData.get("vertices"); Path vertices = new Path(); OrderedMap<String, Object> vertexData; for (int i=0; i<verticesData.size; i++) { vertexData = verticesData.get(i); vertices.addPathVertex((Float) vertexData.get("x"), (Float) vertexData.get("y"), (Float) vertexData.get("tanX"), (Float) vertexData.get("tanY")); } gdxPath.setPath(vertices); } else { throw new Exception(); } return gdxPath; }
Example #12
Source File: ProjectDataConverter.java From libGDX-Path-Editor with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private static ScreenData getScreenFromJSON(String projPath, String path) throws Exception { File scrFile = new File(projPath + path); if (!scrFile.exists()) { throw new Exception(); } File xmlFile = new File(projPath + path); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(xmlFile), "utf8")); JsonReader jsonReader = new JsonReader(); OrderedMap<String, Object> jsonData = (OrderedMap<String, Object>) jsonReader.parse(br); if (jsonData.get("screen") == null) { throw new Exception(); } OrderedMap<String, Object> screenData = (OrderedMap<String, Object>) jsonData.get("screen"); String name = (String) screenData.get("name"); float w = (Float) screenData.get("width"); float h = (Float) screenData.get("height"); String xml = (String) screenData.get("xmlPath"); String json = (String) screenData.get("jsonPath"); if ((name.length() <= 0) || (xml.length() <= 0) || (json.length() <= 0) || (w <= 0) || (h <= 0)) { throw new Exception(); } ScreenData scrData = new ScreenData(); scrData.setName(name); scrData.setWidth((int)w); scrData.setHeight((int)h); scrData.setXmlPath(xml); scrData.setJsonPath(json); if (screenData.get("bg") != null) { OrderedMap<String, Object> bgData = (OrderedMap<String, Object>) screenData.get("bg"); String bgName = (String) bgData.get("name"); String bgTexPath = (String) bgData.get("texturePath"); float bgScaleX = (Float) bgData.get("scaleX"); float bgScaleY = (Float) bgData.get("scaleY"); float bgX = (Float) bgData.get("x"); float bgY = (Float) bgData.get("y"); float bgAngle = (Float) bgData.get("angle"); scrData.setBgImage(WidgetManager.createBGImage(bgName, projPath + bgTexPath, bgScaleX, bgScaleY, bgX, bgY, bgAngle)); } if (screenData.get("path") != null) { OrderedMap<String, Object> pathData = (OrderedMap<String, Object>) screenData.get("path"); json = (String) pathData.get("jsonPath"); if (xml.length() > 0) { scrData.setPath(getPathFromJSON(projPath, json)); } } return scrData; }
Example #13
Source File: ModelTools.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
public static void extractInkTexts(String file, String lang) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); StringBuilder sb = new StringBuilder(); try { String line = br.readLine(); // Replace the BOM mark if (line != null) line = line.replace('\uFEFF', ' '); while (line != null) { sb.append(line); sb.append("\n"); line = br.readLine(); } } finally { br.close(); } JsonValue root = new JsonReader().parse(sb.toString()); // .tsv generation to help in translation StringBuilder tsvString = new StringBuilder(); // .md generation to have a better readable document of texts StringBuilder mdString = new StringBuilder(); OrderedPropertiesBuilder builder = new OrderedPropertiesBuilder(); builder.withSuppressDateInComment(true); OrderedProperties prop = builder.build(); extractInkTextsInternal(root, tsvString, mdString, prop); FileUtils.writeStringToFile(new File(file + ".tsv"), tsvString.toString()); FileUtils.writeStringToFile(new File(file + ".txt"), mdString.toString()); String json = root.toJson(OutputType.json); FileUtils.writeStringToFile(new File(file), json); try { String file2 = file.substring(0, file.length() - EngineAssetManager.INK_EXT.length()); if (lang == null || lang.isEmpty() || lang.equals("default")) file2 += "-ink.properties"; else file2 += "-ink" + "_" + lang + ".properties"; FileOutputStream os = new FileOutputStream(file2); Writer out = new OutputStreamWriter(os, I18N.ENCODING); prop.store(out, null); } catch (IOException e) { EditorLogger.error("ERROR WRITING BUNDLE: " + file + ".properties"); } }
Example #14
Source File: WorldSerialization.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
public void loadGameState(FileHandle savedFile) throws IOException { EngineLogger.debug("LOADING GAME STATE"); if (savedFile.exists()) { JsonValue root = new JsonReader().parse(savedFile.reader("UTF-8")); Json json = new BladeJson(w, Mode.STATE); json.setIgnoreUnknownFields(true); read(json, root); } else { throw new IOException("LOADGAMESTATE: no saved game exists"); } }
Example #15
Source File: WorldSerialization.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
/** * Loads a JSON chapter file. * * @param chapterName filename without path and extension. * @param scene the init scene. null to use the chapter defined init * scene. * @param initScene false only when it comes from loading a saved game. * @throws IOException */ public void loadChapter(String chapterName, String scene, boolean initScene) throws IOException { if (!w.isDisposed()) w.dispose(); long initTime = System.currentTimeMillis(); if (chapterName == null) chapterName = w.getInitChapter(); w.setChapter(chapterName); if (EngineAssetManager.getInstance().getModelFile(chapterName + EngineAssetManager.CHAPTER_EXT).exists()) { JsonValue root = new JsonReader().parse(EngineAssetManager.getInstance() .getModelFile(chapterName + EngineAssetManager.CHAPTER_EXT).reader("UTF-8")); Json json = new BladeJson(w, Mode.MODEL, initScene); json.setIgnoreUnknownFields(true); read(json, root); if (scene == null) w.setCurrentScene(w.getScenes().get(w.getInitScene()), initScene, null); else w.setCurrentScene(w.getScenes().get(scene), initScene, null); w.getI18N().loadChapter(EngineAssetManager.MODEL_DIR + chapterName); w.getCustomProperties().put(WorldProperties.CURRENT_CHAPTER.toString(), chapterName); w.getCustomProperties().put(WorldProperties.PLATFORM.toString(), Gdx.app.getType().toString()); } else { EngineLogger.error( "ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager.CHAPTER_EXT + " doesn't exists."); w.dispose(); throw new IOException( "ERROR LOADING CHAPTER: " + chapterName + EngineAssetManager.CHAPTER_EXT + " doesn't exists."); } EngineLogger.debug("MODEL LOADING TIME (ms): " + (System.currentTimeMillis() - initTime)); }
Example #16
Source File: JsonResultUnitTests.java From gdx-facebook with Apache License 2.0 | 4 votes |
@Before public void setup() { JsonReader writer = new JsonReader(); JsonValue value = writer.parse("{testValue:1}"); fixture = new JsonResult(value); }
Example #17
Source File: Theme.java From Klooni1010 with GNU General Public License v3.0 | 4 votes |
private Theme update(final FileHandle handle) { if (skin == null) { throw new NullPointerException("A Theme.skin must be set before updating any Theme instance"); } final JsonValue json = new JsonReader().parse(handle.readString()); name = handle.nameWithoutExtension(); displayName = json.getString("name"); price = json.getInt("price"); JsonValue colors = json.get("colors"); // Java won't allow unsigned integers, we need to use Long background = new Color((int) Long.parseLong(colors.getString("background"), 16)); foreground = new Color((int) Long.parseLong(colors.getString("foreground"), 16)); JsonValue buttonColors = colors.get("buttons"); Color[] buttons = new Color[buttonColors.size]; for (int i = 0; i < buttons.length; ++i) { buttons[i] = new Color((int) Long.parseLong(buttonColors.getString(i), 16)); if (buttonStyles[i] == null) { buttonStyles[i] = new ImageButton.ImageButtonStyle(); } // Update the style. Since every button uses an instance from this // array, the changes will appear on screen automatically. buttonStyles[i].up = skin.newDrawable("button_up", buttons[i]); buttonStyles[i].down = skin.newDrawable("button_down", buttons[i]); } currentScore = new Color((int) Long.parseLong(colors.getString("current_score"), 16)); highScore = new Color((int) Long.parseLong(colors.getString("high_score"), 16)); bonus = new Color((int) Long.parseLong(colors.getString("bonus"), 16)); bandColor = new Color((int) Long.parseLong(colors.getString("band"), 16)); textColor = new Color((int) Long.parseLong(colors.getString("text"), 16)); emptyCell = new Color((int) Long.parseLong(colors.getString("empty_cell"), 16)); JsonValue cellColors = colors.get("cells"); cells = new Color[cellColors.size]; for (int i = 0; i < cells.length; ++i) { cells[i] = new Color((int) Long.parseLong(cellColors.getString(i), 16)); } String cellTextureFile = json.getString("cell_texture"); cellTexture = SkinLoader.loadPng("cells/" + cellTextureFile); return this; }
Example #18
Source File: BvbProject.java From talos with Apache License 2.0 | 4 votes |
@Override public void loadProject(String data) { Json json = new Json(); JsonValue jsonValue = new JsonReader().parse(data); bvBAddon.workspace.read(json, jsonValue); }