Java Code Examples for com.badlogic.gdx.utils.XmlReader.Element#getChildrenByName()
The following examples show how to use
com.badlogic.gdx.utils.XmlReader.Element#getChildrenByName() .
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: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 6 votes |
@Override public Array<AssetDescriptor> getDependencies (String fileName, FileHandle tmxFile, AtlasTiledMapLoaderParameters parameter) { Array<AssetDescriptor> dependencies = new Array<AssetDescriptor>(); try { root = xml.parse(tmxFile); Element properties = root.getChildByName("properties"); if (properties != null) { for (Element property : properties.getChildrenByName("property")) { String name = property.getAttribute("name"); String value = property.getAttribute("value"); if (name.startsWith("atlas")) { FileHandle atlasHandle = getRelativeFileHandle(tmxFile, value); dependencies.add(new AssetDescriptor(atlasHandle, TextureAtlas.class)); } } } } catch (IOException e) { throw new GdxRuntimeException("Unable to parse .tmx file."); } return dependencies; }
Example 2
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 6 votes |
protected void loadObjectGroup (TiledMap map, Element element) { if (element.getName().equals("objectgroup")) { String name = element.getAttribute("name", null); MapLayer layer = new MapLayer(); layer.setName(name); Element properties = element.getChildByName("properties"); if (properties != null) { loadProperties(layer.getProperties(), properties); } for (Element objectElement : element.getChildrenByName("object")) { loadObject(layer, objectElement); } map.getLayers().add(layer); } }
Example 3
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 5 votes |
/** May return null. */ protected FileHandle loadAtlas (Element root, FileHandle tmxFile) throws IOException { Element e = root.getChildByName("properties"); if (e != null) { for (Element property : e.getChildrenByName("property")) { String name = property.getAttribute("name", null); String value = property.getAttribute("value", null); if (name.equals("atlas")) { if (value == null) { value = property.getText(); } if (value == null || value.length() == 0) { // keep trying until there are no more atlas properties continue; } return getRelativeFileHandle(tmxFile, value); } } } else { FileHandle atlasFile = tmxFile.sibling(tmxFile.nameWithoutExtension() + ".atlas"); return atlasFile.exists() ? atlasFile : null; } return null; }
Example 4
Source File: UAtlasTmxMapLoader.java From uracer-kotd with Apache License 2.0 | 5 votes |
protected void loadProperties (MapProperties properties, Element element) { if (element.getName().equals("properties")) { for (Element property : element.getChildrenByName("property")) { String name = property.getAttribute("name", null); String value = property.getAttribute("value", null); if (value == null) { value = property.getText(); } properties.put(name, value); } } }
Example 5
Source File: TmxObjectsLoader.java From RuinsOfRevenge with MIT License | 5 votes |
public TmxObjectsLoader(Element tmxRootElement) { this.groups = new ArrayList<>(); Array<Element> objectgroups = tmxRootElement.getChildrenByName("objectgroup"); for (Element objectgroupElement : objectgroups) { groups.add(parseObjectgroup(objectgroupElement)); } this.tileWidth = tmxRootElement.getFloat("tilewidth", 32); this.tileHeight = tmxRootElement.getFloat("tileheight", 32); this.mapwidth = tmxRootElement.getInt("width", 50); this.mapheight = tmxRootElement.getInt("height", 50); }
Example 6
Source File: TmxObjectsLoader.java From RuinsOfRevenge with MIT License | 5 votes |
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 7
Source File: ProjectDataConverter.java From libGDX-Path-Editor with Apache License 2.0 | 5 votes |
public static ProjectData openProject(String path) throws Exception { File projectFile = new File(path); if (!projectFile.exists()) { throw new Exception(); } File xmlFile = new File(path); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(xmlFile), "utf8")); XmlReader xmlReader = new XmlReader(); Element xmlRoot = xmlReader.parse(br); if (xmlRoot == null) { throw new Exception(); } String projName = xmlRoot.get("name", ""); String projPath = new File(path).getParent(); //xmlRoot.get("path", ""); //TODO if ((projName.length() <= 0) || (projPath.length() <= 0)) { throw new Exception(); } ProjectData projData = new ProjectData(); projData.setName(projName); projData.setPath(projPath); Array<Element> screensRoot = xmlRoot.getChildrenByName("screen"); if ((screensRoot == null) || (screensRoot.size <= 0)) { return projData; } String xmlPath; String jsonPath; for (int i=0; i<screensRoot.size; i++) { xmlPath = screensRoot.get(i).get("xml", ""); jsonPath = screensRoot.get(i).get("json", ""); if ((xmlPath.length() <= 0) || (jsonPath.length() <= 0)) { throw new Exception(); } ScreenData scrData = getScreenFromJSON(projPath, jsonPath); //ScreenData scrData = getScreenFromXML(projPath, xmlPath); if (scrData == null) { throw new Exception(); } projData.getScreens().add(scrData); } return projData; }