Java Code Examples for com.badlogic.gdx.utils.XmlReader.Element#getChildCount()

The following examples show how to use com.badlogic.gdx.utils.XmlReader.Element#getChildCount() . 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: ResourceLoader.java    From RuinsOfRevenge with MIT License 6 votes vote down vote up
private void readResourcesTag(Element resources) throws RuntimeException {
	for (int i = 0; i < resources.getChildCount(); i++) {
		Element child = resources.getChild(i);

		switch (child.getName()) {
		case "images":
			readImagesTag(child);
			break;
		case "skins":
			readSkinsTag(child);
			break;
		default:
			throw new RuntimeException("Expected <images> or <skins> tag");
		}
	}
}
 
Example 2
Source File: ResourceLoader.java    From RuinsOfRevenge with MIT License 6 votes vote down vote up
private void readImageTag(Element image) throws RuntimeException {
	if (!image.getAttributes().containsKey("file"))
		throw new RuntimeException("need file=\"...\" attribute");

	Texture tex = new Texture(fileLocation.getFile(image.get("file")));

	for (int i = 0; i < image.getChildCount(); i++) {
		Element child = image.getChild(i);

		switch (child.getName()) {
		case "region":
			readRegionTag(tex, child);
			break;
		case "animation":
			readAnimationTag(tex, child);
			break;
		default:
			throw new RuntimeException("Expected <region> or <animation> tag");
		}
	}
}
 
Example 3
Source File: ResourceLoader.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
private void readImagesTag(Element images) throws RuntimeException {
	for (int i = 0; i < images.getChildCount(); i++) {
		Element child = images.getChild(i);

		switch (child.getName()) {
		case "image":
			readImageTag(child);
			break;
		default:
			throw new RuntimeException("Expected <image> tag");
		}
	}
}
 
Example 4
Source File: ResourceLoader.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
private void readSkinsTag(Element resources) {
	for (int i = 0; i < resources.getChildCount(); i++) {
		Element child = resources.getChild(i);

		switch (child.getName()) {
		case "skin":
			readSkinTag(child);
			break;
		default:
			throw new RuntimeException("Expected <skin /> tag");
		}
	}
}
 
Example 5
Source File: TmxObjectsLoader.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
public TmxObjectGroup parseObjectgroup(Element element) {
	TmxObjectGroup group = new TmxObjectGroup(
			element.get("name", ""),
			element.getFloat("width", 0),
			element.getFloat("height", 0));

	Array<Element> objs = element.getChildrenByName("object");
	for (Element obj : objs) {
		Type type = null;
		String points = "";
		if (obj.getChildCount() == 0) type = Type.RECTANGLE;
		else {
			switch (obj.getChild(0).getName().toLowerCase()) {
			case "polygon": type = Type.POLYGON; break;
			case "polyline": type = Type.POLYLINE; break;
			case "ellipse": type = Type.ELLIPSE; break;
			default: type = Type.RECTANGLE; break;
			}
			if (type == Type.POLYGON || type == Type.POLYLINE) {
				points = obj.getChild(0).getAttribute("points", "0,0");
			}
		}

		group.objects.add(new TmxObject(
				obj.get("name", ""),
				obj.get("type", ""),
				points,
				type,
				obj.getFloat("x", 0),
				obj.getFloat("y", 0),
				obj.getFloat("width", 0),
				obj.getFloat("height", 0)));
	}

	return group;
}
 
Example 6
Source File: SpriteAnimation.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
public SpriteAnimation(Texture texture, Element elem) throws RuntimeException {
	this.tex = texture;
	this.name = elem.get("name", "noname");
	int frames = elem.getChildCount();

	if (frames == 0)
		throw new RuntimeException("animation is empty");

	delays = new float[frames];
	keyframes = new TextureRegion[frames];

	if (elem.getAttributes().containsKey("delay")) {
		setDelay(elem.getFloat("delay"));
	}

	for (int i = 0; i < elem.getChildCount(); i++) {
		Element child = elem.getChild(i);

		keyframes[i] = XmlUtils.getTexReg(tex, child.getAttribute("bounds"));

		if (child.getAttributes().containsKey("delay")) {
			delays[i] = child.getFloat("delay");
		}
	}
	float totalDelay = 0;
	for (float delay : delays) {
		totalDelay += delay;
	}
	totalDelays = totalDelay;
}
 
Example 7
Source File: UAtlasTmxMapLoader.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
protected TiledMap loadMap (Element root, FileHandle tmxFile, AtlasResolver resolver, AtlasTiledMapLoaderParameters parameter) {
	TiledMap map = new TiledMap();

	String mapOrientation = root.getAttribute("orientation", null);
	int mapWidth = root.getIntAttribute("width", 0);
	int mapHeight = root.getIntAttribute("height", 0);
	int tileWidth = root.getIntAttribute("tilewidth", 0);
	int tileHeight = root.getIntAttribute("tileheight", 0);
	String mapBackgroundColor = root.getAttribute("backgroundcolor", null);

	MapProperties mapProperties = map.getProperties();
	if (mapOrientation != null) {
		mapProperties.put("orientation", mapOrientation);
	}
	mapProperties.put("width", mapWidth);
	mapProperties.put("height", mapHeight);
	mapProperties.put("tilewidth", tileWidth);
	mapProperties.put("tileheight", tileHeight);
	if (mapBackgroundColor != null) {
		mapProperties.put("backgroundcolor", mapBackgroundColor);
	}

	mapTileWidth = tileWidth;
	mapTileHeight = tileHeight;
	mapWidthInPixels = mapWidth * tileWidth;
	mapHeightInPixels = mapHeight * tileHeight;

	for (int i = 0, j = root.getChildCount(); i < j; i++) {
		Element element = root.getChild(i);
		String elementName = element.getName();
		if (elementName.equals("properties")) {
			loadProperties(map.getProperties(), element);
		} else if (elementName.equals("tileset")) {
			loadTileset(map, element, tmxFile, resolver, parameter);
		} else if (elementName.equals("layer")) {
			loadTileLayer(map, element);
		} else if (elementName.equals("objectgroup")) {
			loadObjectGroup(map, element);
		}
	}
	return map;
}
 
Example 8
Source File: ProjectDataConverter.java    From libGDX-Path-Editor with Apache License 2.0 4 votes vote down vote up
private static GdxPath getPathFromXML(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"));
	
	XmlReader xmlReader = new XmlReader();
	Element xmlRoot = xmlReader.parse(br);
	
	String name		= xmlRoot.get("name", "");
	int pointsCnt 	= xmlRoot.getInt("pointsCnt", -1);
	String controlColor = xmlRoot.get("controlColor", "");
	String segmentColor = xmlRoot.get("segmentColor", "");
	String selectColor  = xmlRoot.get("selectColor", "");
	String xml  = xmlRoot.get("xmlPath",  "");
	String json = xmlRoot.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);
	
	Element cvRoot = xmlRoot.getChildByName("controlVertices");
	if (cvRoot == null) { throw new Exception(); }
	
	ArrayList<Vector3> controlVertices = new ArrayList<Vector3>();
	Element cvertexRoot;
	for (int i=0; i<cvRoot.getChildCount(); i++) {
		cvertexRoot = cvRoot.getChild(i);
		controlVertices.add(new Vector3(cvertexRoot.getFloat("x", 0f), cvertexRoot.getFloat("y", 0f), 0f));
	}
	gdxPath.setControlPath(controlVertices);
	
	Element vRoot = xmlRoot.getChildByName("vertices");
	if (vRoot == null) { throw new Exception(); }
	
	Path vertices = new Path();
	Element vertexRoot;
	for (int i=0; i<vRoot.getChildCount(); i++) {
		vertexRoot = vRoot.getChild(i);
		vertices.addPathVertex(vertexRoot.getFloat("x", 0f),
							   vertexRoot.getFloat("y", 0f),
							   vertexRoot.getFloat("tanX", 0f),
							   vertexRoot.getFloat("tanY", 0f));
	}
	gdxPath.setPath(vertices);
	
	return gdxPath;
}