public StageDocument Load(ProjectDocument project, StageLinkInfo linkInfo)
 {
     var reader = _core.Reader.GetStageReader(linkInfo.StagePath);
     var stage = reader.Load(linkInfo.StagePath);
     var document = new StageDocument(project, stage, linkInfo);
     return document;
 }
示例#2
0
 public void Load(StageLinkInfo info)
 {
     try
     {
         TryLoad(info);
     }
     catch (XmlException e)
     {
         throw new GameRunException(String.Format("The map file for stage {0} has badly formatted XML:\n\n{1}", info.Name, e.Message));
     }
 }
示例#3
0
        public void TryLoad(StageLinkInfo info)
        {
            var stageReader = new StageXmlReader();
            StageInfo map = stageReader.LoadStageXml(info.StagePath);

            var handler = new StageHandler(map);

            var joins = new Dictionary<ScreenInfo, Dictionary<Join, JoinHandler>>();

            foreach (var screen in map.Screens.Values)
            {
                joins[screen] = new Dictionary<Join, JoinHandler>();
            }

            foreach (Join join in map.Joins)
            {
                var screenOne = map.Screens[join.screenOne];
                var screenTwo = map.Screens[join.screenTwo];

                JoinHandler handlerOne = CreateJoin(join, handler, screenOne);

                joins[screenOne].Add(join, handlerOne);

                JoinHandler handlerTwo = CreateJoin(join, handler, screenTwo);

                joins[screenTwo].Add(join, handlerTwo);
            }

            var screens = new Dictionary<string, ScreenHandler>();
            foreach (var screen in map.Screens.Values)
            {
                screens[screen.Name] = CreateScreen(handler, screen, joins[screen].Values.ToList());
            }

            handler.InitScreens(screens);

            handler.WinHandler = info.WinHandler;

            if (info.LoseHandler == null)
            {
                // repeat this stage
                handler.LoseHandler = new HandlerTransfer { Fade = true, Type = HandlerType.Stage, Name = info.Name };
            }
            else
            {
                handler.LoseHandler = info.LoseHandler;
            }

            _loadedStages[info.Name] = handler;
        }
        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);
            }
        }
示例#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);
            }
        }
示例#6
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;
        }
示例#7
0
        public StageDocument AddStage(string name)
        {
            var stagePath = FileStructure.CreateStagePath(name);

            var stage = new StageDocument(this) {
                Path = stagePath,
                Name = name
            };

            openStages.Add(name, stage);

            var info = new StageLinkInfo { Name = name, StagePath = stagePath };
            Project.AddStage(info);

            ViewModelMediator.Current.GetEvent<StageAddedEventArgs>().Raise(this, new StageAddedEventArgs() { Stage = info });

            Dirty = true;

            return stage;
        }
示例#8
0
 public StageTreeItemViewModel(TreeViewItemViewModel parent, StageLinkInfo stage)
     : base(parent)
 {
     _stage = stage;
 }
        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 StageLinkInfo {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;
        }
示例#10
0
 public void AddStage(StageLinkInfo stage)
 {
     this.stages.Add(stage);
 }
示例#11
0
 public void AddStage(StageLinkInfo stage)
 {
     this.stages.Add(stage);
 }