public void ProcessHandler(HandlerTransfer handler)
        {
            switch (handler.Mode)
            {
                case HandlerMode.Next:
                    new EndStateTransition(handler).Apply(this);
                    break;

                case HandlerMode.Push:
                    new PushStateTransition(handler).Apply(this);
                    break;

                case HandlerMode.Pop:
                    new PopStateTransition(handler).Apply(this);
                    break;
            }
        }
Exemple #2
0
        public static HandlerTransfer LoadHandlerTransfer(XElement node)
        {
            HandlerTransfer transfer = new HandlerTransfer();

            var modeAttr = node.Attribute("mode");
            var mode = HandlerMode.Next;
            if (modeAttr != null)
            {
                Enum.TryParse<HandlerMode>(modeAttr.Value, true, out mode);
            }

            transfer.Mode = mode;

            if (mode == HandlerMode.Push)
            {
                transfer.Pause = node.TryAttribute<bool>("pause");
            }

            if (mode != HandlerMode.Pop)
            {
                switch (node.RequireAttribute("type").Value.ToLower())
                {
                    case "stage":
                        transfer.Type = HandlerType.Stage;
                        break;

                    case "scene":
                        transfer.Type = HandlerType.Scene;
                        break;

                    case "menu":
                        transfer.Type = HandlerType.Menu;
                        break;
                }

                transfer.Name = node.RequireAttribute("name").Value;
            }

            transfer.Fade = node.TryAttribute<bool>("fade");

            return transfer;
        }
        public void Write(HandlerTransfer info, XmlWriter writer)
        {
            writer.WriteStartElement("Next");

            if (info.Mode != HandlerMode.Next)
            {
                writer.WriteAttributeString("mode", info.Mode.ToString());
            }

            if (info.Mode == HandlerMode.Push)
            {
                writer.WriteAttributeString("pause", info.Pause.ToString());
            }

            if (info.Mode != HandlerMode.Pop)
            {
                writer.WriteAttributeString("type", Enum.GetName(typeof(HandlerType), info.Type));
                writer.WriteAttributeString("name", info.Name);
            }

            writer.WriteAttributeString("fade", info.Fade.ToString());

            writer.WriteEndElement();
        }
 public void StartScene(HandlerTransfer handler)
 {
     var scene = Scene.Get(handler.Name);
     StartAndPushToStack(scene);
 }
 public void StartMenu(HandlerTransfer handler)
 {
     var menu = Menu.Get(handler.Name);
     StartAndPushToStack(menu);
 }
        public void StartHandler(HandlerTransfer handler)
        {
            if (handler != null)
            {
                switch (handler.Type)
                {
                    case HandlerType.Scene:
                        StartScene(handler);
                        break;

                    case HandlerType.Stage:
                        StartStage(handler.Name);
                        break;

                    case HandlerType.Menu:
                        StartMenu(handler);
                        break;
                }
            }
        }
Exemple #7
0
 protected void Finish(HandlerTransfer transfer)
 {
     if (End != null)
     {
         End(transfer);
     }
 }
Exemple #8
0
 public void ProcessHandler(HandlerTransfer handler)
 {
     _stateMachine.ProcessHandler(handler);
 }
 public PushStateTransition(HandlerTransfer transfer)
 {
     _transfer = transfer;
 }
Exemple #10
0
        private void WriteHandlerTransfer(HandlerTransfer handlerTransfer)
        {
            _writer.WriteStartElement("Next");

            if (handlerTransfer.Mode != HandlerMode.Next)
            {
                _writer.WriteAttributeString("mode", handlerTransfer.Mode.ToString());
            }

            if (handlerTransfer.Mode == HandlerMode.Push)
            {
                _writer.WriteAttributeString("pause", handlerTransfer.Pause.ToString());
            }

            if (handlerTransfer.Mode != HandlerMode.Pop)
            {
                _writer.WriteAttributeString("type", Enum.GetName(typeof(HandlerType), handlerTransfer.Type));
                _writer.WriteAttributeString("name", handlerTransfer.Name);
            }

            _writer.WriteAttributeString("fade", handlerTransfer.Fade.ToString());

            _writer.WriteEndElement();
        }
        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 EndStateTransition(HandlerTransfer transfer)
 {
     _transfer = transfer;
 }
        protected override void Load(XElement node, string basePath)
        {
            base.Load(node, basePath);

            this.Duration = node.GetInteger("duration");

            bool canSkip = false;
            node.TryBool("canskip", out canSkip);
            this.CanSkip = canSkip;

            foreach (var keyNode in node.Elements("Keyframe"))
            {
                this.KeyFrames.Add(KeyFrameInfo.FromXml(keyNode, basePath));
            }

            var transferNode = node.Element("Next");
            if (transferNode != null)
            {
                this.NextHandler = HandlerTransfer.FromXml(transferNode);
            }
        }