com.badlogic.gdx.utils.XmlReader Java Examples

The following examples show how to use com.badlogic.gdx.utils.XmlReader. 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: UIStage.java    From talos with Apache License 2.0 6 votes vote down vote up
public void initExampleList (PopupMenu examples) {
	FileHandle list = Gdx.files.internal("samples/list.xml");
	XmlReader xmlReader = new XmlReader();
	XmlReader.Element root = xmlReader.parse(list);
	Array<XmlReader.Element> samples = root.getChildrenByName("sample");
	for (XmlReader.Element sample : samples) {
		String name = sample.getAttribute("name");
		final String fileName = sample.getAttribute("file");
		MenuItem item = new MenuItem(name);
		examples.addItem(item);

		item.addListener(new ClickListener() {
			@Override
			public void clicked (InputEvent event, float x, float y) {
				super.clicked(event, x, y);
				//openProject(fileName);
				TalosMain.Instance().ProjectController().lastDirTrackingDisable();
				TalosMain.Instance().ProjectController().setProject(ProjectController.TLS);
				TalosMain.Instance().ProjectController().loadProject(Gdx.files.internal("samples/" + fileName));
				TalosMain.Instance().ProjectController().lastDirTrackingEnable();
				TalosMain.Instance().ProjectController().unbindFromFile();
			}
		});
	}
}
 
Example #2
Source File: ModuleListPopup.java    From talos with Apache License 2.0 6 votes vote down vote up
public ModuleListPopup(XmlReader.Element root) {
    super("Add Module", "module-list");
    setModal(false);
    setMovable(false);
    setKeepWithinParent(false);
    setKeepWithinStage(false);

    padTop(42);
    padBottom(16);
    padLeft(16);
    padRight(16);

    tree = new FilteredTree<>(getSkin());
    searchFilteredTree = new SearchFilteredTree<>(getSkin(), tree, null);

    TalosMain.Instance().moduleNames.clear();

    parseCategory(tree, null, root);

    add(searchFilteredTree).width(300).row();
    add().growY();

    invalidate(); pack();

    createListeners();
}
 
Example #3
Source File: ModuleListPopup.java    From talos with Apache License 2.0 6 votes vote down vote up
private void parseCategory(FilteredTree<String> tree, FilteredTree.Node parent, XmlReader.Element element) {
    Array<XmlReader.Element> categories = element.getChildrenByName("category");
    for(XmlReader.Element category: categories) {
        FilteredTree.Node categoryNode = new FilteredTree.Node(category.getAttribute("name"), new Label(category.getAttribute("name"), getSkin()));

        if(parent != null) parent.add(categoryNode);
        else tree.add(categoryNode);

        parseCategory(tree, categoryNode, category);
    }

    // get modules
    Array<XmlReader.Element> modules = element.getChildrenByName("module");
    for(XmlReader.Element module: modules) {
        FilteredTree.Node node = new FilteredTree.Node(module.getAttribute("name"), new Label(module.getAttribute("name"), getSkin()));
        nameToModuleClass.put(module.getAttribute("name"), module.getText());

        registerModule(module);

        if(parent != null) parent.add(node);
        else tree.add(node);
    }
}
 
Example #4
Source File: ServerMaster.java    From RuinsOfRevenge with MIT License 6 votes vote down vote up
public ServerMaster(String mapfile, String basePath) throws IOException {
	super(basePath);
	this.physics = new Physics(new Vector2(0, 0), true);
	if (RuinsOfRevenge.fileLocation == FileLocation.CLASSPATH)
		this.mapObjects = new TmxObjectsLoader(new XmlReader().parse(
				Thread.currentThread().getContextClassLoader().getResourceAsStream(mapfile)));
	else
		this.mapObjects = new TmxObjectsLoader(new XmlReader().parse(new FileHandle(mapfile)));
	this.connection = new ServerConnection(this, PORT_TCP, PORT_UDP);
	this.controllers = new EntityControllers();

	for (TmxObjectsLoader.TmxObjectGroup group : mapObjects.getObjectGroups()) {
		for (TmxObjectsLoader.TmxObject obj : group.objects) {
			if (!obj.name.equalsIgnoreCase("spawnpoint")) {
				mapObjects.loadToPhysics(obj, physics);
			} else {
				System.out.println("spawnpoint found: " + obj.name);
			}
		}
	}
}
 
Example #5
Source File: UIStage.java    From talos with Apache License 2.0 5 votes vote down vote up
public void init () {
	fullScreenTable = new Table();
	fullScreenTable.setFillParent(true);

	stage.addActor(fullScreenTable);

	defaults();
	constructMenu();
	constructTabPane();
	constructSplitPanes();

	initFileChoosers();

	batchConvertDialog = new BatchConvertDialog();
	settingsDialog = new SettingsDialog();

	FileHandle list = Gdx.files.internal("modules.xml");
	XmlReader xmlReader = new XmlReader();
	XmlReader.Element root = xmlReader.parse(list);
	WrapperRegistry.map.clear();
	moduleListPopup = new ModuleListPopup(root);

	colorPicker = new ColorPicker();
	colorPicker.padTop(32);
	colorPicker.padLeft(16);
	colorPicker.setHeight(330);
	colorPicker.setWidth(430);
	colorPicker.padRight(26);
}
 
Example #6
Source File: ModuleListPopup.java    From talos with Apache License 2.0 5 votes vote down vote up
private void registerModule(XmlReader.Element module) {
    try {
        Class moduleClazz = ClassReflection.forName("com.talosvfx.talos.runtime.modules." + module.getText());
        Class wrapperClazz =ClassReflection.forName("com.talosvfx.talos.editor.wrappers." + module.getAttribute("wrapper"));
        WrapperRegistry.reg(moduleClazz, wrapperClazz);
        TalosMain.Instance().moduleNames.put(wrapperClazz, module.getAttribute("name"));
    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    WrapperRegistry.reg(EmitterModule.class, EmitterModuleWrapper.class);
}
 
Example #7
Source File: ResourceLoader.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
public ResourceLoader(FileLocation fileLocation, FileHandle resourceXml) throws IOException {
	this.fileLocation = fileLocation;
	regions = new ObjectMap<>();
	anims = new ObjectMap<>();
	skins = new ObjectMap<>();

	Element resources = new XmlReader().parse(resourceXml);
	readResourcesTag(resources);
}
 
Example #8
Source File: TmxObjectsLoader.java    From RuinsOfRevenge with MIT License 5 votes vote down vote up
public static void main(String... args) throws IOException {
	GdxNativesLoader.load();
	Physics physics = new Physics(Vector2.Zero, true);
	File mapfile = new File("data/maps/newmap/map005.tmx");
	Element mapXML = new XmlReader().parse(new FileInputStream(mapfile));
	System.out.println(mapXML);

	new TmxObjectsLoader(mapXML)
		.loadToPhysics(physics, 32, 32, 50, 50);
}
 
Example #9
Source File: ProjectDataConverter.java    From libGDX-Path-Editor with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: Map.java    From RuinsOfRevenge with MIT License 4 votes vote down vote up
public Map(FileLocation loc, String mapfile, Physics physics) {
	TmxObjectsLoader objs = null;
	try {
		objs = new TmxObjectsLoader(new XmlReader().parse(loc.getFile(mapfile)));
	} catch (IOException e) {
		e.printStackTrace();
	}
	this.map = new TmxMapLoader(loc.getResolver()).load(mapfile);
	this.renderer = new OrthogonalTiledMapRenderer(map, 1f / objs.getTileWidth());

	fringeLayerIndex = computeEntityLayer();
	if (fringeLayerIndex == 999) {
		belowEntities = new int[map.getLayers().getCount()];
		aboveEntities = new int[0];
		fillCounting(0, belowEntities);
		fringeLayer = null;
	} else {
		belowEntities = new int[fringeLayerIndex];
		aboveEntities = new int[map.getLayers().getCount()-fringeLayerIndex-1];
		fillCounting(0, belowEntities);
		fillCounting(fringeLayerIndex+1, aboveEntities);
		MapLayer mapLayer = map.getLayers().get(fringeLayerIndex);
		if (mapLayer instanceof TiledMapTileLayer) {
			fringeLayer = new FringeLayer(map, (TiledMapTileLayer) mapLayer);
		} else {
			fringeLayer = null;
		}
	}

	if (physics != null) {
		for (TmxObjectsLoader.TmxObjectGroup group : objs.getObjectGroups()) {
			for (TmxObjectsLoader.TmxObject obj : group.objects) {
				if (!obj.name.equalsIgnoreCase("spawnpoint")) {
					objs.loadToPhysics(obj, physics);
				} else {
					spawnpoint.set(obj.x / objs.getTileWidth(), obj.y / objs.getTileHeight());
				}
			}
		}
	}
}
 
Example #11
Source File: ProjectDataConverter.java    From libGDX-Path-Editor with Apache License 2.0 4 votes vote down vote up
private static ScreenData getScreenFromXML(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 w 		= xmlRoot.getInt("width",   -1);
	int h 		= xmlRoot.getInt("height",  -1);
	String xml  = xmlRoot.get("xmlPath",  "");
	String json = xmlRoot.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(w);
	scrData.setHeight(h);
	scrData.setXmlPath(xml);
	scrData.setJsonPath(json);
	
	Element bgRoot = xmlRoot.getChildByName("bg");
	if (bgRoot != null) {
		String bgName    = bgRoot.get("name", "");
		String bgTexPath = bgRoot.get("texturePath", "");
		float bgScaleX 	 = bgRoot.getFloat("scaleX", -1f);
		float bgScaleY 	 = bgRoot.getFloat("scaleY", -1f);
		float bgX 	     = bgRoot.getFloat("x", -1f);
		float bgY 	     = bgRoot.getFloat("y", -1f);
		float bgAngle 	 = bgRoot.getFloat("angle", -1f);
		
		scrData.setBgImage(WidgetManager.createBGImage(bgName, projPath + bgTexPath, bgScaleX, bgScaleY, bgX, bgY, bgAngle));
	}
	
	Element pathRoot = xmlRoot.getChildByName("path");
	if (pathRoot != null) {
		xml = pathRoot.get("xmlPath", "");
		if (xml.length() > 0) {
			scrData.setPath(getPathFromXML(projPath, xml));
		}
	}
	
	return scrData;
}
 
Example #12
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;
}