private void _readResourceTree(XmlNode root, string resourceType, GmsResourceGroup parent) { foreach (XmlNode node in root) { if (node.Attributes["name"] != null) { //group GmsResourceGroup group = new GmsResourceGroup(node.Attributes["name"].InnerText); _readResourceTree(node, resourceType, group); parent.subitems.Add(group); } else { GmsResource resource; string name = Path.GetFileName(node.InnerText); switch (resourceType) { case "sprites": resource = new GmsSprite(name); GmsResourceSpriteList.Add((GmsSprite)resource); break; case "backgrounds": resource = new GmsBackground(name); GmsResourceBackgroundList.Add((GmsBackground)resource); break; case "objects": resource = new GmsObject(name); GmsResourceObjectList.Add((GmsObject)resource); break; case "rooms": resource = new GmsRoom(name); GmsResourceRoomList.Add((GmsRoom)resource); break; default: resource = new GmsResource(name); break; } resource.name = Path.GetFileName(node.InnerText); parent.subitems.Add(resource); } } }
private void _readGMX() { XmlDocument XMLfile = new XmlDocument(); try { XMLfile.Load(ProjectSource + "\\" + GmxFilename); } catch (Exception e) { MessageBox.Show(e.Message); Manager.Project = null; return; } //string nodeElementsName; XmlNode root; //allItems = new GMItem(Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(GmxFilename))); string[] resTree = new string[] { "sprites", "backgrounds", "scripts", "objects", "rooms" }; // none sprite add //GMItem noneSprite = new GMItem(GmsResource.undefined) { ResourceType = GMItemType.Sprite, isGroup = false }; //GMXSprites.Add(new GMSpriteData() { offsetX = 0, offsetY = 0, firstFramePath = "", owner = noneSprite }); foreach (string resourceType in resTree) { try { root = XMLfile.SelectSingleNode("assets/" + resourceType); if (root == null) { continue; } GmsResourceGroup resource = new GmsResourceGroup(resourceType); GmsResourceTree.Add(resource); _readResourceTree(root, resourceType, resource); } catch (Exception e) { MessageBox.Show("Not found NODE for resource type : " + resourceType + Environment.NewLine + e.Message + Environment.NewLine + e.StackTrace.ToString()); } } //foreach (string nodeName in resTree) //{ // try // { // root = XMLfile.SelectSingleNode("assets/" + nodeName); // if (root == null) // { // return; // } // nodeElementsName = nodeName;//root.Attributes["name"].InnerText; // //TreeNode main = treeViewGMX.Nodes.Paint(fup(nodeElementsName), fup(nodeElementsName)); // //GMItem main = new GMItem(nodeElementsName); // //allItems.add(main); // _readSubNode(root, nodeName, nodeElementsName, main); // } // catch (Exception e) // { // MessageBox.Show(nodeName + ": " + e.Message); // } //} BrushGroups = new ObservableCollection <BrushGroup>(); BrushGroup defaultBrushGroup = new BrushGroup() { GroupName = "Default", isDefault = true }; BrushGroups.Add(defaultBrushGroup); //List<string> objects = Manager.Project.renderItemsList("objects"); //addUsedRes(GmsResource.undefined); //foreach (GMObjectData obj in GMXObjects) //{ // PlaceableElement el = new PlaceableElement() // { // Name = obj.Name, // Sprite = (obj.sprite != null) ? obj.sprite.Name : GmsResource.undefined, // Parent = "", // }; // PlaceableList.Add(el); // if (obj.sprite != null) // { // //addUsedRes(obj.sprite.Name); // } //} // prepare rooms data root = XMLfile.SelectSingleNode("assets/rooms"); if (root != null) { _readRoomsNode(root); } }