public static MeterInfo LoadMeter(XElement meterNode, string basePath)
        {
            MeterInfo meter = new MeterInfo();

            meter.Name = meterNode.TryAttribute <string>("name") ?? "";

            meter.Position = new PointF(meterNode.GetAttribute <float>("x"), meterNode.GetAttribute <float>("y"));

            XAttribute imageAttr = meterNode.RequireAttribute("image");

            meter.TickImage = FilePath.FromRelative(imageAttr.Value, basePath);

            XAttribute backAttr = meterNode.Attribute("background");

            if (backAttr != null)
            {
                meter.Background = FilePath.FromRelative(backAttr.Value, basePath);
            }

            bool       horiz   = false;
            XAttribute dirAttr = meterNode.Attribute("orientation");

            if (dirAttr != null)
            {
                horiz = (dirAttr.Value == "horizontal");
            }
            meter.Orient = horiz ? MegaMan.Common.MeterInfo.Orientation.Horizontal : MegaMan.Common.MeterInfo.Orientation.Vertical;

            int x = meterNode.TryAttribute <int>("tickX");
            int y = meterNode.TryAttribute <int>("tickY");

            meter.TickOffset = new Point(x, y);

            XElement soundNode = meterNode.Element("Sound");

            if (soundNode != null)
            {
                meter.Sound = IncludeFileXmlReader.LoadSound(soundNode, basePath);
            }

            XElement bindingNode = meterNode.Element("Binding");

            if (bindingNode != null)
            {
                meter.Binding = LoadSceneBinding(bindingNode);
            }

            return(meter);
        }
Esempio n. 2
0
        public Project Load(string filePath)
        {
            if (!File.Exists(filePath)) throw new FileNotFoundException("The project file does not exist: " + filePath);

            _project = new Project();

            _project.GameFile = FilePath.FromAbsolute(filePath, Path.GetDirectoryName(filePath));

            XElement reader = XElement.Load(filePath);

            XAttribute nameAttr = reader.Attribute("name");
            if (nameAttr != null) _project.Name = nameAttr.Value;

            XAttribute authAttr = reader.Attribute("author");
            if (authAttr != null) _project.Author = authAttr.Value;

            XElement sizeNode = reader.Element("Size");
            if (sizeNode != null)
            {
                _project.ScreenWidth = sizeNode.TryAttribute<int>("x");
                _project.ScreenHeight = sizeNode.TryAttribute<int>("y");
            }

            XElement nsfNode = reader.Element("NSF");
            if (nsfNode != null)
            {
                LoadNSFInfo(nsfNode);
            }

            XElement stagesNode = reader.Element("Stages");
            if (stagesNode != null)
            {
                foreach (XElement stageNode in stagesNode.Elements("Stage"))
                {
                    var info = new StageLinkInfo();
                    info.Name = stageNode.RequireAttribute("name").Value;
                    info.StagePath = FilePath.FromRelative(stageNode.RequireAttribute("path").Value, _project.BaseDir);

                    var winNode = stageNode.Element("Win");
                    if (winNode != null)
                    {
                        var winHandlerNode = winNode.Element("Next");
                        if (winHandlerNode != null)
                        {
                            info.WinHandler = LoadHandlerTransfer(winHandlerNode);
                        }
                    }

                    var loseNode = stageNode.Element("Lose");
                    if (loseNode != null)
                    {
                        var loseHandlerNode = loseNode.Element("Next");
                        if (loseHandlerNode != null)
                        {
                            info.LoseHandler = LoadHandlerTransfer(loseHandlerNode);
                        }
                    }

                    _project.AddStage(info);
                }
            }

            XElement startNode = reader.Element("Next");
            if (startNode != null)
            {
                _project.StartHandler = LoadHandlerTransfer(startNode);
            }

            _project.AddIncludeFiles(reader.Elements("Include")
                .Select(e => e.Value)
                .Where(v => !string.IsNullOrEmpty(v.Trim())));

            _project.AddIncludeFolders(reader.Elements("IncludeFolder")
                .Select(e => e.Value)
                .Where(v => !string.IsNullOrEmpty(v.Trim())));

            var includeReader = new IncludeFileXmlReader();

            foreach (var includePath in _project.Includes)
            {
                string includefile = includePath.Absolute;
                includeReader.LoadIncludedFile(_project, includefile);
            }

            return _project;
        }
        public Project Load(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("The project file does not exist: " + filePath);
            }

            _project = new Project();

            _project.GameFile = FilePath.FromAbsolute(filePath, Path.GetDirectoryName(filePath));

            XElement reader = XElement.Load(filePath);

            XAttribute nameAttr = reader.Attribute("name");

            if (nameAttr != null)
            {
                _project.Name = nameAttr.Value;
            }

            XAttribute authAttr = reader.Attribute("author");

            if (authAttr != null)
            {
                _project.Author = authAttr.Value;
            }

            XElement sizeNode = reader.Element("Size");

            if (sizeNode != null)
            {
                _project.ScreenWidth  = sizeNode.TryAttribute <int>("x");
                _project.ScreenHeight = sizeNode.TryAttribute <int>("y");
            }

            XElement nsfNode = reader.Element("NSF");

            if (nsfNode != null)
            {
                LoadNSFInfo(nsfNode);
            }

            XElement stagesNode = reader.Element("Stages");

            if (stagesNode != null)
            {
                foreach (XElement stageNode in stagesNode.Elements("Stage"))
                {
                    var info = new StageLinkInfo();
                    info.Name      = stageNode.RequireAttribute("name").Value;
                    info.StagePath = FilePath.FromRelative(stageNode.RequireAttribute("path").Value, _project.BaseDir);

                    var winNode = stageNode.Element("Win");
                    if (winNode != null)
                    {
                        var winHandlerNode = winNode.Element("Next");
                        if (winHandlerNode != null)
                        {
                            info.WinHandler = LoadHandlerTransfer(winHandlerNode);
                        }
                    }

                    var loseNode = stageNode.Element("Lose");
                    if (loseNode != null)
                    {
                        var loseHandlerNode = loseNode.Element("Next");
                        if (loseHandlerNode != null)
                        {
                            info.LoseHandler = LoadHandlerTransfer(loseHandlerNode);
                        }
                    }

                    _project.AddStage(info);
                }
            }

            XElement startNode = reader.Element("Next");

            if (startNode != null)
            {
                _project.StartHandler = LoadHandlerTransfer(startNode);
            }

            _project.AddIncludeFiles(reader.Elements("Include")
                                     .Select(e => e.Value)
                                     .Where(v => !string.IsNullOrEmpty(v.Trim())));

            _project.AddIncludeFolders(reader.Elements("IncludeFolder")
                                       .Select(e => e.Value)
                                       .Where(v => !string.IsNullOrEmpty(v.Trim())));

            var includeReader = new IncludeFileXmlReader();

            foreach (var includePath in _project.Includes)
            {
                string includefile = includePath.Absolute;
                includeReader.LoadIncludedFile(_project, includefile);
            }

            return(_project);
        }
Esempio n. 4
0
        public Project Load()
        {
            _project = new Project();

            var gameFilePath = _dataSource.GetGameFile();

            _project.GameFile = gameFilePath;

            var      stream = _dataSource.GetData(gameFilePath);
            XElement reader = XElement.Load(stream);

            XAttribute nameAttr = reader.Attribute("name");

            if (nameAttr != null)
            {
                _project.Name = nameAttr.Value;
            }

            XAttribute authAttr = reader.Attribute("author");

            if (authAttr != null)
            {
                _project.Author = authAttr.Value;
            }

            XElement sizeNode = reader.Element("Size");

            if (sizeNode != null)
            {
                _project.ScreenWidth  = sizeNode.TryAttribute <int>("x");
                _project.ScreenHeight = sizeNode.TryAttribute <int>("y");
            }

            XElement nsfNode = reader.Element("NSF");

            if (nsfNode != null)
            {
                LoadNSFInfo(nsfNode);
            }

            XElement stagesNode = reader.Element("Stages");

            if (stagesNode != null)
            {
                foreach (XElement stageNode in stagesNode.Elements("Stage"))
                {
                    var info = new StageLinkInfo();
                    info.Name      = stageNode.RequireAttribute("name").Value;
                    info.StagePath = FilePath.FromRelative(stageNode.RequireAttribute("path").Value, _project.BaseDir);

                    var winNode = stageNode.Element("Win");
                    if (winNode != null)
                    {
                        var winHandlerNode = winNode.Element("Next");
                        if (winHandlerNode != null)
                        {
                            info.WinHandler = _transferReader.Load(winHandlerNode);
                        }
                    }

                    var loseNode = stageNode.Element("Lose");
                    if (loseNode != null)
                    {
                        var loseHandlerNode = loseNode.Element("Next");
                        if (loseHandlerNode != null)
                        {
                            info.LoseHandler = _transferReader.Load(loseHandlerNode);
                        }
                    }

                    _project.AddStage(info);
                }
            }

            XElement startNode = reader.Element("Next");

            if (startNode != null)
            {
                _project.StartHandler = _transferReader.Load(startNode);
            }

            _project.AddIncludeFiles(reader.Elements("Include")
                                     .Select(e => e.Value)
                                     .Where(v => !string.IsNullOrEmpty(v.Trim())));

            _project.AddIncludeFolders(reader.Elements("IncludeFolder")
                                       .Select(e => e.Value)
                                       .Where(v => !string.IsNullOrEmpty(v.Trim())));

            var includeReader = new IncludeFileXmlReader();

            foreach (var includePath in _project.Includes)
            {
                string includefile = includePath.Absolute;
                includeReader.LoadIncludedFile(_project, includefile);
            }

            stream.Close();

            return(_project);
        }