示例#1
0
        public void AddContinuePoint(ScreenDocument screenDocument, Point location)
        {
            if (_map.ContinuePoints.ContainsKey(screenDocument.Name))
            {
                _map.ContinuePoints[screenDocument.Name] = location;
            }
            else
            {
                _map.AddContinuePoint(screenDocument.Name, location);
            }

            Dirty = true;
            if (EntryPointsChanged != null)
            {
                EntryPointsChanged();
            }
        }
        public StageInfo Load(FilePath path)
        {
            _info = new StageInfo();

            _info.StoragePath = path;

            var mapPath = Path.Combine(_info.StoragePath.Absolute, "map.xml");
            var stream  = _dataSource.GetData(FilePath.FromAbsolute(mapPath, _info.StoragePath.BasePath));
            var mapXml  = XElement.Load(stream);

            _info.Name = Path.GetFileNameWithoutExtension(_info.StoragePath.Absolute);

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

            var tileReader = _readerProvider.GetTilesetReader(tilePath);
            var tileset    = tileReader.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);
            }

            stream.Close();

            return(_info);
        }