com.badlogic.gdx.utils.OrderedMap Java Examples

The following examples show how to use com.badlogic.gdx.utils.OrderedMap. 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: JsonDOM.java    From RuinsOfRevenge with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void readJsonObject(JsonObject element, OrderedMap<String, Object> jsonData) {
	Entries<String, Object> entries = jsonData.entries();
	for (Entry<String, Object> entry : entries) {
		if (entry.value instanceof OrderedMap) {
			JsonObject obj = new JsonObject();
			element.elements.put(entry.key, obj);

			// unchecked, but safe:
			readJsonObject(obj, (OrderedMap<String, Object>) entry.value);
		} else if (entry.value instanceof Array) {
			JsonArray arr = new JsonArray();
			element.elements.put(entry.key, arr);

			// unchecked, but safe:
			readJsonArray(arr, (Array<OrderedMap<String, Object>>) entry.value);
		} else {
			element.values.put(entry.key, entry.value.toString());
		}
	}
}
 
Example #2
Source File: StyleData.java    From skin-composer with MIT License 5 votes vote down vote up
public StyleData(StyleData styleData, String styleName, Main main) {
    name = styleName;
    this.main = main;

    clazz = styleData.clazz;
    properties = new OrderedMap<>();
    for (Entry<String, StyleProperty> entry : styleData.properties.entries()) {
        properties.put(entry.key, new StyleProperty(entry.value));
    }
    deletable = true;
}
 
Example #3
Source File: StyleData.java    From skin-composer with MIT License 5 votes vote down vote up
public StyleData (Class clazz, String styleName, Main main) {
    name = styleName;
    this.main = main;

    this.clazz = clazz;
    properties = new OrderedMap<>();
    deletable = true;
    
    resetProperties();
}
 
Example #4
Source File: JsonDOM.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
public void readJsonArray(JsonArray array, Array<OrderedMap<String, Object>> jsonArray) {
	for (OrderedMap<String, Object> jsonObject : jsonArray) {
		JsonObject obj = new JsonObject();
		array.elements.add(obj);
		readJsonObject(obj, jsonObject);
	}
}
 
Example #5
Source File: JsonDOM.java    From RuinsOfRevenge with MIT License 4 votes vote down vote up
@Override
public void read(Json json, OrderedMap<String, Object> jsonData) {
	readJsonObject(root, jsonData);
}
 
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;
}