Java Code Examples for com.badlogic.gdx.utils.JsonReader#parse()

The following examples show how to use com.badlogic.gdx.utils.JsonReader#parse() . 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 vote down vote up
@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: JsonResultUnitTests.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
@Test
public void setGetJsonValue() {
    JsonReader writer = new JsonReader();
    JsonValue value = writer.parse("{testValue:2}");
    fixture.setJsonValue(value);
    assertEquals(value, fixture.getJsonValue());
}
 
Example 3
Source File: JsonResultUnitTests.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
@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 4
Source File: SceneLoader.java    From Mundus with Apache License 2.0 5 votes vote down vote up
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 5
Source File: JsonResultUnitTests.java    From gdx-facebook with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    JsonReader writer = new JsonReader();
    JsonValue value = writer.parse("{testValue:1}");
    fixture = new JsonResult(value);
}
 
Example 6
Source File: ProjectDataConverter.java    From libGDX-Path-Editor with Apache License 2.0 4 votes vote down vote up
@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 7
Source File: ProjectDataConverter.java    From libGDX-Path-Editor with Apache License 2.0 4 votes vote down vote up
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;
}