Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        private void _readAME()
        {
            XmlDocument XMLfile = new XmlDocument();

            XMLfile.Load(ProjectSource + "\\" + ProjectFilename);

            XmlNode root = XMLfile.SelectSingleNode("assets/resources");

            #region to_remove

            /*foreach (XmlNode n in root)
             * {
             *  addUsedRes(n.InnerText);
             * }*/

            // don't use PlaceableElement definitions anymore, they are converted from Objects now

            /*try
             * {
             *  root = XMLfile.SelectSingleNode("assets/placeables");
             *  foreach (XmlNode n in root)
             *  {
             *      PlaceableElement e = new PlaceableElement()
             *      {
             *          Name = n.Attributes["name"].Value,
             *          Sprite = n.SelectSingleNode("sprite").InnerText,
             *          Mask = n.SelectSingleNode("mask").InnerText,
             *          Depth = int.Parse(n.SelectSingleNode("depth").InnerText),
             *          ShadowSize = int.Parse(n.SelectSingleNode("shadowsize").InnerText),
             *          Solid = (n.SelectSingleNode("solid").InnerText == "1"),
             *          Wind = (n.SelectSingleNode("wind").InnerText == "1"),
             *          MultiDraw = (n.SelectSingleNode("multidraw").InnerText == "1"),
             *          Shadow = (n.SelectSingleNode("shadow").InnerText == "1"),
             *          Visible = (n.SelectSingleNode("visible").InnerText == "1") ? true : false,
             *          Parent = tryReadingNode(n, "parent", ""),
             *          useDefaultObjectDepth = tryReadingNode(n, "defdepth", false),
             *          useDefaultObjectMask = tryReadingNode(n, "defmask", false),
             *          useDefaultObjectSolid = tryReadingNode(n, "defsolid", false),
             *          useDefaultObjectSprite = tryReadingNode(n, "defsprite", false),
             *          useDefaultObjectVisible = tryReadingNode(n, "defvisible", false)
             *      };
             *
             *      PlaceableList.Add(e);
             *  }
             * }
             * catch
             * {
             *
             * }*/

            // read rooms

            /*try
             * {
             *  root = XMLfile.SelectSingleNode("assets/rooms");
             *  foreach (XmlNode n in root)
             *  {
             *      MapRoom map = new MapRoom()
             *      {
             *          Width = int.Parse(n.Attributes["width"].Value),
             *          Height = int.Parse(n.Attributes["height"].Value),
             *          LinkedWith = n.Attributes["linked"].Value,
             *          LastUsedLayer = (n.Attributes["lastLayer"] == null) ? -1 : int.Parse(n.Attributes["lastLayer"].Value)//,
             *          //InternalCounter = (n.Attributes["internalCounter"].Value == null) ? 0 : int.Parse(n.Attributes["internalCounter"].Value)
             *      };
             *
             *      RoomList.Add(map);
             *      _readAMERoom(map, ProjectSource + "\\amedata\\" + map.LinkedWith + ".room.ame");
             *  }
             * }
             * catch (Exception e)
             * {
             *  MessageBox.Show("reading room node from AME file failed: " + e.Message);
             * }*/
            #endregion

            // read brushes
            try
            {
                root = XMLfile.SelectSingleNode("assets/brushgroups");
                foreach (XmlNode n in root)
                {
                    string     name = n.Attributes["name"].Value;
                    BrushGroup brush;
                    brush = BrushGroups.Where(item => item.GroupName == name).FirstOrDefault();
                    if (brush == null)
                    {
                        brush = new BrushGroup()
                        {
                            GroupName = name
                        };
                        BrushGroups.Add(brush);
                    }

                    foreach (XmlNode obj in n.SelectSingleNode("objects"))
                    {
                        brush.objects.Add(obj.Attributes["name"].Value);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Reading brush node from AME file failed: " + e.Message);
            }

            // read layers
            root = XMLfile.SelectSingleNode("assets/layers");
            foreach (XmlNode n in root)
            {
                RoomLayers.Add(new MapLayers()
                {
                    LayerDepth = int.Parse(n.Attributes["depth"].Value),
                    LayerName  = n.Attributes["name"].Value
                });
            }
        }