Example #1
0
 public void Execute(IConversationFile conversation, IErrorCheckerUtilities <IConversationNode> util)
 {
     using (SaveFileDialog sfd = new SaveFileDialog())
     {
         sfd.DefaultExt   = "ssv";
         sfd.AddExtension = true;
         if (sfd.ShowDialog() == DialogResult.OK)
         {
             Stream stream = null;
             try
             {
                 stream = sfd.OpenFile();
                 using (StreamWriter sw = new StreamWriter(stream))
                 {
                     stream = null;
                     CsvData.WriteTitle(Separator, sw, false);
                     WriteConversation(conversation, sw, false, util);
                 }
             }
             finally
             {
                 if (stream != null)
                 {
                     stream.Dispose();
                 }
             }
         }
     }
 }
Example #2
0
        public void Execute(IConversationFile conversation)
        {
            using (SaveFileDialog sfd = new SaveFileDialog())
            {
                sfd.DefaultExt   = "csv";
                sfd.AddExtension = true;
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    var nodes = conversation.Nodes;

                    var playerSpeechNodes = conversation.Nodes.Where(n => n.Type == PLAYER_SPEECH);
                    var npcSpeechNodes    = conversation.Nodes.Where(n => n.Type == NPC_SPEECH);
                    var radioSpeechNodes  = conversation.Nodes.Where(n => n.Type == RADIO_SPEECH);
                    var optionNodes       = conversation.Nodes.Where(n => n.Type == OPTION);

                    IEnumerable <CsvData> rows = playerSpeechNodes.Select(GetSpeechData)
                                                 .Concat(npcSpeechNodes.Select(GetSpeechData))
                                                 .Concat(radioSpeechNodes.Select(GetSpeechData))
                                                 .Concat(optionNodes.Select(GetOptionData));

                    using (var stream = sfd.OpenFile())
                    {
                        using (StreamWriter sw = new StreamWriter(stream))
                        {
                            sw.WriteLine("Character, Script, Subtitle, Direction");
                            foreach (CsvData row in rows)
                            {
                                sw.WriteLine(String.Format("{0}, {1}, {2}, {3}", row.Character, row.Script, row.Subtitle, row.Direction));
                            }
                        }
                    }
                }
            }
        }
Example #3
0
 public void Execute(IConversationFile conversation, IErrorCheckerUtilities <IConversationNode> util)
 {
     using (var sfd = new SaveFileDialog())
     {
         sfd.DefaultExt      = "*.ssv";
         sfd.AddExtension    = true;
         sfd.CreatePrompt    = false;
         sfd.OverwritePrompt = true;
         sfd.ValidateNames   = true;
         sfd.Title           = "Export to C# source file";
         sfd.DefaultExt      = ".ssv";
         if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             using (var sw = new StreamWriter(sfd.FileName, false))
             {
                 foreach (var node in conversation.Nodes)
                 {
                     foreach (var parameter in node.Data.Parameters.OfType <ILocalizedStringParameter>())
                     {
                         var id = parameter.Value;
                         sw.WriteLine("<Localize id =\"" + id.Serialized() + "\" localized =\"" + localizer(id).Item2.Ticks.ToString() + "\">" + localizer(id).Item1 + "</Localize>");
                     }
                 }
             }
         }
     }
 }
Example #4
0
 public void Execute(IConversationFile conversation)
 {
     using (SaveFileDialog sfd = new SaveFileDialog())
     {
         sfd.DefaultExt   = "ssv";
         sfd.AddExtension = true;
         if (sfd.ShowDialog() == DialogResult.OK)
         {
             using (var stream = sfd.OpenFile())
             {
                 using (StreamWriter sw = new StreamWriter(stream))
                 {
                     WriteTitle(sw, false);
                     WriteConversation(conversation, sw, false);
                 }
             }
         }
     }
 }
 public void Execute(IConversationFile conversation, IErrorCheckerUtilities <IConversationNode> util)
 {
     using (SaveFileDialog sfd = new SaveFileDialog())
     {
         sfd.DefaultExt   = "xml";
         sfd.AddExtension = true;
         if (sfd.ShowDialog() == DialogResult.OK)
         {
             Stream stream = null;
             try
             {
                 stream = sfd.OpenFile();
                 WriteLocalizationFile(stream, conversation.Only());
             }
             finally
             {
                 if (stream != null)
                 {
                     stream.Dispose();
                 }
             }
         }
     }
 }
Example #6
0
        public void WriteConversation(IConversationFile conversation, StreamWriter sw, bool includeName)
        {
            var nodes = conversation.Nodes;

            var playerSpeechNodes = conversation.Nodes.Where(n => n.Type == PLAYER_SPEECH);
            var npcSpeechNodes    = conversation.Nodes.Where(n => n.Type == NPC_SPEECH);
            var radioSpeechNodes  = conversation.Nodes.Where(n => n.Type == RADIO_SPEECH);
            var optionNodes       = conversation.Nodes.Where(n => n.Type == OPTION);

            IEnumerable <CsvData> rows = playerSpeechNodes.Select(GetPlayerSpeechData)
                                         .Concat(npcSpeechNodes.Select(GetSpeechData))
                                         .Concat(radioSpeechNodes.Select(GetSpeechData))
                                         .Concat(optionNodes.Select(GetOptionData));

            foreach (CsvData row in rows)
            {
                var data = String.Format("{0}; {1}; {2}; {3}", row.Character, row.Script, row.Subtitle, row.Direction);
                if (includeName)
                {
                    data = conversation.File.File.Name + "; " + data;
                }
                sw.WriteLine(data);
            }
        }
Example #7
0
        public void WriteConversation(IConversationFile conversation, StreamWriter sw, bool includeName, IErrorCheckerUtilities <IConversationNode> util)
        {
            if (conversation == null)
            {
                throw new ArgumentNullException(nameof(conversation));
            }

            var nodes = conversation.Nodes;

            Stack <IConversationNodeData> startNodes = new Stack <IConversationNodeData>(nodes.Where(n => Clandestine.Util.IsStartNode(n.Data.NodeTypeId, util)).Select(n => n.Data));

            var conversationInfo  = conversation.Nodes.Where(n => n.Data.NodeTypeId == CsvData.CONVERSATIONINFO).FirstOrDefault();
            var playerSpeechNodes = conversation.Nodes.Where(n => n.Data.NodeTypeId == CsvData.PLAYER_SPEECH).Select(n => new { Key = n, Value = CsvData.GetPlayerSpeechData(n, conversationInfo, m_localize) });
            var npcSpeechNodes    = conversation.Nodes.Where(n => n.Data.NodeTypeId == CsvData.NPC_SPEECH).Select(n => new { Key = n, Value = CsvData.GetSpeechData(n, conversationInfo, m_localize) });
            var radioSpeechNodes  = conversation.Nodes.Where(n => n.Data.NodeTypeId == CsvData.RADIO_SPEECH).Select(n => new { Key = n, Value = CsvData.GetSpeechData(n, conversationInfo, m_localize) });
            var optionNodes       = conversation.Nodes.Where(n => n.Data.NodeTypeId == CsvData.OPTION).Select(n => new { Key = n, Value = CsvData.GetOptionData(n, conversationInfo, m_localize) });

            var allcontent = playerSpeechNodes.Concat(npcSpeechNodes).Concat(radioSpeechNodes).Concat(optionNodes).ToDictionary(kvp => kvp.Key.Data, kvp => kvp.Value);
            HashSet <IConversationNodeData> processed = new HashSet <IConversationNodeData>();

            //Depth first iterate through the conversation starting at start nodes
            while (startNodes.Any())
            {
                var start = startNodes.Pop();

                if (!processed.Contains(start))
                {
                    foreach (var output in start.Connectors.Where(c => c.Definition.Id == SpecialConnectors.Output.Id))
                    {
                        foreach (var connection in output.Connections)
                        {
                            var connected = connection.Parent;
                            startNodes.Push(connected);
                        }
                    }

                    if (allcontent.ContainsKey(start))
                    {
                        var row = allcontent[start];
                        row.Write(Separator, includeName ? conversation.File.File.Name : null, sw);
                        allcontent.Remove(start);
                    }
                }

                processed.Add(start);
            }

            //Pick up any leftover nodes that are not connected to a start node
            foreach (var node in nodes.Select(n => n.Data))
            {
                if (!processed.Contains(node))
                {
                    if (allcontent.ContainsKey(node))
                    {
                        var row = allcontent[node];
                        row.Write(Separator, includeName ? conversation.File.File.Name : null, sw);
                        allcontent.Remove(node);
                    }
                    processed.Add(node);
                }
            }
        }