Inheritance: HandlerInfo
Exemple #1
0
 public StageXmlWriter(StageInfo stageInfo)
 {
     this._stageInfo = stageInfo;
     _writer = new XmlTextWriter(Path.Combine(_stageInfo.StagePath.Absolute, "map.xml"), Encoding.Default);
     _writer.Formatting = Formatting.Indented;
     _writer.Indentation = 1;
     _writer.IndentChar = '\t';
 }
        public StageDocument(ProjectEditor project, string basepath, string filepath)
        {
            Project = project;
            map = new StageInfo(FilePath.FromAbsolute(filepath, basepath));

            // wrap all map screens in screendocuments
            // this should be the only time MegaMan.Screen's are touched directly
            foreach (var pair in map.Screens)
            {
                WrapScreen(pair.Value);
            }
        }
Exemple #3
0
        public StageHandler(StageInfo stage)
        {
            info = stage;
            Info = stage;
            startScreen = info.StartScreen;

            if (string.IsNullOrEmpty(startScreen)) startScreen = info.Screens.Keys.First();
            startX = info.PlayerStartX;
            startY = info.PlayerStartY;

            string intropath = (stage.MusicIntroPath != null) ? stage.MusicIntroPath.Absolute : null;
            string looppath = (stage.MusicLoopPath != null) ? stage.MusicLoopPath.Absolute : null;
            if (intropath != null || looppath != null) music = Engine.Instance.SoundSystem.LoadMusic(intropath, looppath, 1);
        }
        public StageDocument(ProjectDocument project, StageInfo info, StageLinkInfo linkInfo)
        {
            Project = project;
            History = new History();
            _map = info;
            Tileset = new TilesetDocument(_map.Tileset);
            LinkName = linkInfo.Name;

            // wrap all map screens in screendocuments
            // this should be the only time MegaMan.Screen's are touched directly
            foreach (var pair in _map.Screens)
            {
                WrapScreen(pair.Value);
            }
        }
Exemple #5
0
        public StageDocument(ProjectDocument project, StageLinkInfo linkInfo)
        {
            Project = project;
            History = new History();
            var stageReader = new StageXmlReader();
            map = stageReader.LoadStageXml(linkInfo.StagePath);
            Tileset = new TilesetDocument(map.Tileset);
            LinkName = linkInfo.Name;

            // wrap all map screens in screendocuments
            // this should be the only time MegaMan.Screen's are touched directly
            foreach (var pair in map.Screens)
            {
                WrapScreen(pair.Value);
            }
        }
Exemple #6
0
 public StageDocument(ProjectDocument project)
 {
     Project = project;
     map = new StageInfo();
     History = new History();
 }
Exemple #7
0
        public StageInfo LoadStageXml(FilePath path)
        {
            _info = new StageInfo();

            _info.StagePath = path;

            var mapXml = XElement.Load(Path.Combine(_info.StagePath.Absolute, "map.xml"));
            _info.Name = Path.GetFileNameWithoutExtension(_info.StagePath.Absolute);

            string tilePathRel = mapXml.Attribute("tiles").Value;
            var tilePath = FilePath.FromRelative(tilePathRel, _info.StagePath.BasePath);

            var tileset = new TilesetXmlReader().Load(tilePath);
            _info.ChangeTileset(tileset);

            _info.PlayerStartX = 3;
            _info.PlayerStartY = 3;

            LoadMusicXml(mapXml);
            LoadScreens(mapXml);

            XElement start = mapXml.Element("Start");
            if (start != null)
            {
                _info.StartScreen = start.RequireAttribute("screen").Value;
                _info.PlayerStartX = start.GetAttribute<int>("x");
                _info.PlayerStartY = start.GetAttribute<int>("y");
            }

            foreach (XElement contPoint in mapXml.Elements("Continue"))
            {
                string screen = contPoint.GetAttribute<string>("screen");
                int x = contPoint.GetAttribute<int>("x");
                int y = contPoint.GetAttribute<int>("y");
                _info.AddContinuePoint(screen, new Point(x, y));
            }

            foreach (XElement join in mapXml.Elements("Join"))
            {
                string t = join.Attribute("type").Value;
                JoinType type;
                if (t.ToLower() == "horizontal") type = JoinType.Horizontal;
                else if (t.ToLower() == "vertical") type = JoinType.Vertical;
                else throw new GameXmlException(join, "map.xml file contains invalid join type.");

                string s1 = join.RequireAttribute("s1").Value;
                string s2 = join.RequireAttribute("s2").Value;
                int offset1 = join.GetAttribute<int>("offset1");
                int offset2 = join.GetAttribute<int>("offset2");
                int size = join.GetAttribute<int>("size");

                JoinDirection direction;
                XAttribute dirAttr = join.Attribute("direction");
                if (dirAttr == null || dirAttr.Value.ToUpper() == "BOTH") direction = JoinDirection.Both;
                else if (dirAttr.Value.ToUpper() == "FORWARD") direction = JoinDirection.ForwardOnly;
                else if (dirAttr.Value.ToUpper() == "BACKWARD") direction = JoinDirection.BackwardOnly;
                else throw new GameXmlException(dirAttr, "map.xml file contains invalid join direction.");

                string bosstile = null;
                XAttribute bossAttr = join.Attribute("bossdoor");
                bool bossdoor = (bossAttr != null);
                if (bossdoor) bosstile = bossAttr.Value;

                Join j = new Join();
                j.direction = direction;
                j.screenOne = s1;
                j.screenTwo = s2;
                j.offsetOne = offset1;
                j.offsetTwo = offset2;
                j.type = type;
                j.Size = size;
                j.bossDoor = bossdoor;
                j.bossEntityName = bosstile;

                _info.Joins.Add(j);
            }

            return _info;
        }
        public void Save(StageInfo stage)
        {
            this._stageInfo = stage;
            _writer = new XmlTextWriter(Path.Combine(_stageInfo.StoragePath.Absolute, "map.xml"), Encoding.Default);
            _writer.Formatting = Formatting.Indented;
            _writer.Indentation = 1;
            _writer.IndentChar = '\t';

            _writer.WriteStartElement("Map");
            _writer.WriteAttributeString("name", _stageInfo.Name);

            _writer.WriteAttributeString("tiles", _stageInfo.Tileset.FilePath.Relative);

            if (_stageInfo.MusicIntroPath != null || _stageInfo.MusicLoopPath != null || _stageInfo.MusicNsfTrack > 0)
            {
                _writer.WriteStartElement("Music");
                if (_stageInfo.MusicNsfTrack > 0) _writer.WriteAttributeString("nsftrack", _stageInfo.MusicNsfTrack.ToString());
                if (_stageInfo.MusicIntroPath != null && !string.IsNullOrEmpty(_stageInfo.MusicIntroPath.Relative)) _writer.WriteElementString("Intro", _stageInfo.MusicIntroPath.Relative);
                if (_stageInfo.MusicLoopPath != null && !string.IsNullOrEmpty(_stageInfo.MusicLoopPath.Relative)) _writer.WriteElementString("Loop", _stageInfo.MusicLoopPath.Relative);
                _writer.WriteEndElement();
            }

            _writer.WriteStartElement("Start");
            _writer.WriteAttributeString("screen", _stageInfo.StartScreen);
            _writer.WriteAttributeString("x", _stageInfo.PlayerStartX.ToString());
            _writer.WriteAttributeString("y", _stageInfo.PlayerStartY.ToString());
            _writer.WriteEndElement();

            foreach (KeyValuePair<string, Point> pair in _stageInfo.ContinuePoints)
            {
                _writer.WriteStartElement("Continue");
                _writer.WriteAttributeString("screen", pair.Key);
                _writer.WriteAttributeString("x", pair.Value.X.ToString());
                _writer.WriteAttributeString("y", pair.Value.Y.ToString());
                _writer.WriteEndElement();
            }

            foreach (var screen in _stageInfo.Screens.Values)
            {
                SaveScreen(screen);
            }

            foreach (Join join in _stageInfo.Joins)
            {
                _writer.WriteStartElement("Join");
                _writer.WriteAttributeString("type", (join.type == JoinType.Horizontal) ? "horizontal" : "vertical");

                _writer.WriteAttributeString("s1", join.screenOne);
                _writer.WriteAttributeString("s2", join.screenTwo);
                _writer.WriteAttributeString("offset1", join.offsetOne.ToString());
                _writer.WriteAttributeString("offset2", join.offsetTwo.ToString());
                _writer.WriteAttributeString("size", join.Size.ToString());
                switch (join.direction)
                {
                    case JoinDirection.Both: _writer.WriteAttributeString("direction", "both"); break;
                    case JoinDirection.ForwardOnly: _writer.WriteAttributeString("direction", "forward"); break;
                    case JoinDirection.BackwardOnly: _writer.WriteAttributeString("direction", "backward"); break;
                }

                _writer.WriteEndElement();
            }

            _writer.WriteEndElement();
            _writer.Close();
        }
        public StageDocument AddStage(string name, string tilesetPath)
        {
            string stageDir = Path.Combine(BaseDir, "stages");
            if (!Directory.Exists(stageDir))
            {
                Directory.CreateDirectory(stageDir);
            }
            string stagePath = Path.Combine(stageDir, name);
            if (!Directory.Exists(stagePath))
            {
                Directory.CreateDirectory(stagePath);
            }

            var stage = new StageDocument(this)
            {
                Path = FilePath.FromAbsolute(stagePath, this.BaseDir),
                Name = name
            };
            stage.ChangeTileset(tilesetPath);

            stage.Save();

            openStages.Add(name, stage);

            var info = new StageInfo {Name = name, StagePath = FilePath.FromAbsolute(stagePath, BaseDir)};
            Project.AddStage(info);

            Save(); // need to save the reference to the new stage

            if (StageAdded != null) StageAdded(stage);

            return stage;
        }
 public StageDocument(ProjectEditor project)
 {
     Project = project;
     map = new StageInfo();
 }
        public void Load(string path)
        {
            if (!File.Exists(path)) throw new FileNotFoundException("The project file does not exist: " + path);

            GameFile = path;
            BaseDir = Path.GetDirectoryName(path);
            XElement reader = XElement.Load(path);

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

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

            XElement sizeNode = reader.Element("Size");
            if (sizeNode != null)
            {
                int across, down;
                if (int.TryParse(sizeNode.Attribute("x").Value, out across))
                {
                    ScreenWidth = across;
                }
                else ScreenWidth = 0;

                if (int.TryParse(sizeNode.Attribute("y").Value, out down))
                {
                    ScreenHeight = down;
                }
                else ScreenHeight = 0;
            }

            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 StageInfo();
                    info.Name = stageNode.RequireAttribute("name").Value;
                    info.StagePath = FilePath.FromRelative(stageNode.RequireAttribute("path").Value, this.BaseDir);

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

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

                    stages.Add(info);
                }
            }

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

            foreach (var stageSelectNode in reader.Elements("StageSelect"))
            {
                stageSelects.Add(new StageSelect(stageSelectNode, this.BaseDir));
            }

            XElement pauseNode = reader.Element("PauseScreen");
            if (pauseNode != null) PauseScreen = new PauseScreen(pauseNode, this.BaseDir);

            foreach (XElement entityNode in reader.Elements("Entities"))
            {
                if (!string.IsNullOrEmpty(entityNode.Value.Trim())) includeFiles.Add(entityNode.Value);
            }
            foreach (XElement entityNode in reader.Elements("Include"))
            {
                if (!string.IsNullOrEmpty(entityNode.Value.Trim())) includeFiles.Add(entityNode.Value);
            }
        }
 public void AddStage(StageInfo stage)
 {
     this.stages.Add(stage);
 }