Ejemplo n.º 1
0
        static public void ExportDialoguesToCsv(string directory, Project project, List <Dialogue> dialogues, List <Language> languages, DateTime dateFrom, ExporterStats.ProjectStats projectStats)
        {
            //Ensure no export of a Workstring language
            //languages.Remove(EditorCore.LanguageWorkstring);

            string path = Path.Combine(directory, "Loca_" + project.GetName() + ".csv");

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, false, Encoding.UTF8))
            {
                //Dialogue, Node ID, Timestamp, Voicing ID, Index, Package, SceneType, Context, Voicing, Voice Intensity, Speaker, Workstring Text, Words, ...Languages..., comments
                {
                    ExporterCsv.CsvLineWriter header = new ExporterCsv.CsvLineWriter();
                    header.AddField("Dialogue");
                    header.AddField("Node ID");
                    header.AddField("Timestamp");
                    header.AddField("Voicing ID");
                    header.AddField("Index");
                    header.AddField("Package");
                    header.AddField("Scene Type");
                    header.AddField("Context");
                    header.AddField("Voicing");
                    header.AddField("Voice Intensity");
                    header.AddField("Speaker");
                    header.AddField("Workstring Text");
                    //TODO: old workstring for updated texts ?
                    header.AddField("Words");
                    //TODO: characters count ?
                    foreach (var language in languages)
                    {
                        header.AddField(language.Name + " State");
                        header.AddField(language.Name + " Text");
                        header.AddField(language.Name + " Words");
                        //TODO: characters count ?
                    }
                    header.AddField("Comments");
                    header.WriteLine(file);
                }

                //file.Write("\n");

                foreach (Dialogue dialogue in dialogues)
                {
                    int index = 0;

                    var orderedListNodes = new List <DialogueNode>();
                    dialogue.GetOrderedNodes(ref orderedListNodes);

                    //Process global Dialogue information
                    {
                        string package   = dialogue.Package.Name;
                        string sceneType = dialogue.SceneType;
                        string context   = dialogue.Context;

                        ExporterCsv.CsvLineWriter line = new ExporterCsv.CsvLineWriter();
                        //Dialogue, Node ID, Timestamp, Voicing ID, Index, Package, SceneType, Context, Voicing, Voicing Intensity, Speaker, Workstring Text, Words, ...Languages..., comments
                        line.AddField(dialogue.GetName());
                        line.AddField(TranslationTable.DialogueNodePrefix + dialogue.RootNodeID);
                        line.AddEmptyField();
                        line.AddEmptyField();
                        line.AddField(index);
                        line.AddField(package);
                        line.AddField(sceneType);
                        line.AddField(context);
                        line.AddEmptyField();
                        line.AddEmptyField();
                        line.AddEmptyField();
                        line.AddEmptyField();
                        line.AddEmptyField();

                        //Locas
                        line.AddEmptyField();
                        line.AddEmptyField();
                        line.AddEmptyField();
                        line.AddEmptyField();

                        line.WriteLine(file);
                    }

                    foreach (DialogueNode dialogueNode in orderedListNodes)
                    {
                        if (dialogueNode is DialogueNodeSentence || dialogueNode is DialogueNodeReply)
                        {
                            ++index;

                            string   context    = "";
                            string   speaker    = "";
                            string   workstring = "";
                            DateTime workstringTimestamp;
                            bool     todo = false;
                            string   voicingID;
                            string   voicing;
                            string   voiceIntensity;

                            if (dialogueNode is DialogueNodeSentence)
                            {
                                var dialogueNodeSentence = dialogueNode as DialogueNodeSentence;

                                context             = dialogueNodeSentence.Context;
                                workstring          = dialogueNodeSentence.Sentence;
                                workstringTimestamp = dialogueNodeSentence.LastEditDate;

                                speaker = project.GetActorName(dialogueNodeSentence.SpeakerID);
                                if (speaker == "")
                                {
                                    speaker = "<Undefined>";
                                }

                                voicingID      = EditorHelper.GetPrettyNodeVoicingID(dialogue, dialogueNodeSentence);
                                voicing        = dialogueNodeSentence.Comment;
                                voiceIntensity = dialogueNodeSentence.VoiceIntensity;
                            }
                            else
                            {
                                var dialogueNodeReply = dialogueNode as DialogueNodeReply;

                                context             = "<User Interface>";
                                speaker             = "<UI>";
                                workstring          = dialogueNodeReply.Reply;
                                workstringTimestamp = dialogueNodeReply.LastEditDate;
                                voicingID           = "";
                                voicing             = "";
                                voiceIntensity      = "";
                            }

                            string[] split = workstring.Split(ExporterStats.DelimiterChars, StringSplitOptions.RemoveEmptyEntries);
                            int      words = split.Length;

                            //Dialogue, Node ID, Timestamp, Voicing ID, Index, Package, SceneType, Context, Voicing, Voicing Intensity, Speaker, Workstring Text, Words, ...Languages..., comments
                            ExporterCsv.CsvLineWriter line = new ExporterCsv.CsvLineWriter();
                            line.AddField(dialogue.GetName());
                            line.AddField(TranslationTable.DialogueNodePrefix + dialogueNode.ID);
                            line.AddField(workstringTimestamp);
                            line.AddField(voicingID);
                            line.AddField(index);
                            line.AddEmptyField();
                            line.AddEmptyField();
                            line.AddField(context);
                            line.AddField(voicing);
                            line.AddField(voiceIntensity);
                            line.AddField(speaker);
                            line.AddField(workstring);
                            line.AddField(words);

                            foreach (var language in languages)
                            {
                                var entry = dialogue.Translations.GetNodeEntry(dialogueNode, language);
                                if (entry != null)
                                {
                                    if (entry.SourceDate < workstringTimestamp)
                                    {
                                        todo = true;
                                        line.AddField("UPDATE");
                                    }
                                    else
                                    {
                                        line.AddField("OK");
                                    }
                                    line.AddField(entry.Text);
                                    line.AddEmptyField();
                                }
                                else
                                {
                                    todo = true;
                                    line.AddField("NEW");
                                    line.AddEmptyField();
                                    line.AddEmptyField();
                                }
                            }

                            line.AddEmptyField();
                            line.WriteLine(file);

                            if (todo)
                            {
                                if (dialogueNode is DialogueNodeSentence)
                                {
                                    var dialogueNodeSentence = dialogueNode as DialogueNodeSentence;
                                    projectStats.AddSentence(dialogue, dialogueNodeSentence.SpeakerID, workstring);
                                }
                                else
                                {
                                    var dialogueNodeReply = dialogueNode as DialogueNodeReply;
                                    projectStats.AddReply(dialogue, workstring);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------------------------------------------------
        // Exports

        static public bool ExportToCsv()
        {
            var project = ResourcesHandler.Project;

            string projectDirectory = EditorHelper.GetProjectDirectory();
            string exportDirectory  = Path.Combine(projectDirectory, EditorCore.Settings.DirectoryExportDialogues);

            var dialog = new DialogExport("Export Dialogues",
                                          exportDirectory,
                                          true, false,
                                          true, false,
                                          true, DateTime.MinValue);
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                return(false);
            }

            EditorCore.Settings.DirectoryExportDialogues = Utility.GetRelativePath(dialog.ExportPath, projectDirectory);

            exportDirectory = dialog.ExportPath;
            if (dialog.UseDateDirectory)
            {
                exportDirectory = Path.Combine(exportDirectory, Utility.GetCurrentDateAsString());
            }

            if (!Directory.Exists(exportDirectory))
            {
                Directory.CreateDirectory(exportDirectory);
            }

            var packageGroups = new List <List <Package> >();

            if (dialog.UsePackagesDirectory)
            {
                foreach (var package in dialog.ListPackages)
                {
                    packageGroups.Add(new List <Package>()
                    {
                        package
                    });
                }
            }
            else
            {
                packageGroups.Add(dialog.ListPackages);
            }

            ExporterStats.ProjectStats projectStats = new ExporterStats.ProjectStats();

            //Ensure no export of a Workstring language
            var listLanguages = new List <Language>();   // { EditorCore.LanguageWorkstring };

            if (!dialog.WorkstringOnly)
            {
                listLanguages = dialog.ListLanguages;
            }

            foreach (var packageGroup in packageGroups)     //Either a list of individual packages, or 1 entry with all the packages
            {
                var packageDirectory = exportDirectory;
                if (dialog.UsePackagesDirectory)
                {
                    packageDirectory = Path.Combine(packageDirectory, packageGroup[0].Name);
                }

                if (!Directory.Exists(packageDirectory))
                {
                    Directory.CreateDirectory(packageDirectory);
                }

                var dialogues = dialog.SelectedDialogues;
                if (!dialog.UseCustomSelection)
                {
                    dialogues = ResourcesHandler.GetAllDialoguesFromPackages(packageGroup);
                }

                ExportDialoguesToCsv(packageDirectory, project, dialogues, listLanguages, dialog.DateFrom, projectStats);

                ExporterStats.Export("TodoTranslationsCount", projectStats, packageDirectory, packageGroup, listLanguages, dialog.WorkstringOnly, dialog.WorkstringFallback);
            }

            if (dialog.Constants)
            {
                ExportConstantsToCsv(exportDirectory, project, listLanguages);
            }

            System.Diagnostics.Process.Start(exportDirectory);

            return(true);
        }
Ejemplo n.º 3
0
        static public void ExportLocasToCSVFile(string directory, Project project, List <Dialogue> dialogues, Language language, bool workstringOnly, bool workstringFallback, DateTime dateFrom, ExporterStats.ProjectStats projectStats)
        {
            string path = Path.Combine(directory, "Loca_" + project.GetName() + "_" + language.VoicingCode + ".csv");

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, false, Encoding.UTF8))
            {
                //status, scene, voicing id, index, speaker, context, voicing comments, intensity, sentence, comments
                {
                    ExporterCsv.CsvLineWriter header = new ExporterCsv.CsvLineWriter();
                    header.AddField("Status");
                    header.AddField("Dialogue");
                    header.AddField("Voicing ID");
                    header.AddField("Index");
                    header.AddField("Speaker");
                    header.AddField("Context");
                    header.AddField("Voicing Comments");
                    header.AddField("Voicing Intensity");
                    header.AddField("Sentence");
                    header.AddField("Comments");
                    header.WriteLine(file);
                }

                foreach (Dialogue dialogue in dialogues)
                {
                    int index = 1;

                    var orderedListNodes = new List <DialogueNode>();
                    dialogue.GetOrderedNodes(ref orderedListNodes);
                    foreach (DialogueNode dialogueNode in orderedListNodes)
                    {
                        if (dialogueNode is DialogueNodeSentence)
                        {
                            DialogueNodeSentence dialogueNodeSentence = dialogueNode as DialogueNodeSentence;

                            bool done = false;
                            if (dialogueNodeSentence.LastEditDate < dateFrom)
                            {
                                done = true;
                            }

                            string nodeID    = EditorHelper.GetPrettyNodeVoicingID(dialogue, dialogueNodeSentence);
                            string speaker   = project.GetActorName(dialogueNodeSentence.SpeakerID);
                            string scene     = dialogue.GetName();
                            string context   = dialogueNodeSentence.Context;
                            string comment   = dialogueNodeSentence.Comment;
                            string intensity = dialogueNodeSentence.VoiceIntensity;
                            string status    = (done) ? "OK" : "TODO";

                            string voicedText = dialogueNodeSentence.Sentence;
                            if (!workstringOnly)
                            {
                                TranslationEntry entry = dialogue.Translations.GetNodeEntry(dialogueNode, language);
                                if (entry == null)
                                {
                                    if (!workstringFallback)
                                    {
                                        voicedText = "<Missing Translation>";
                                    }
                                }
                                else
                                {
                                    voicedText = entry.Text;
                                }
                            }

                            // use null as langage to force constant replacement in csv file
                            voicedText = EditorHelper.FormatTextEntry(voicedText, null);  //language = workstring if workstringOnly

                            //voicedText = voicedText.Replace("’", "'");
                            //voicedText = voicedText.Replace("…", "...");

                            if (speaker == "")
                            {
                                speaker = "<Undefined>";
                            }

                            //status, scene, node id, index, speaker, context, voicing comments, intensity, sentence, comments
                            ExporterCsv.CsvLineWriter line = new ExporterCsv.CsvLineWriter();
                            line.AddField(status);
                            line.AddField(scene);
                            line.AddField(nodeID);
                            line.AddField(index);
                            line.AddField(speaker);
                            line.AddField(context);
                            line.AddField(comment);
                            line.AddField(intensity);
                            line.AddField(voicedText);
                            line.AddEmptyField();
                            line.WriteLine(file);

                            ++index;

                            if (!done)
                            {
                                projectStats.AddSentence(dialogue, dialogueNodeSentence.SpeakerID, voicedText);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        //--------------------------------------------------------------------------------------------------------------
        // Exports

        static public bool ExportAll()
        {
            Project project = ResourcesHandler.Project;

            string projectDirectory = EditorHelper.GetProjectDirectory();
            string exportDirectory  = Path.Combine(projectDirectory, EditorCore.Settings.DirectoryExportVoicing);

            var dialog = new DialogExport("Export Voicing",
                                          exportDirectory,
                                          true, false,
                                          false, true,
                                          true, project.LastVoicingExportDate);
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                return(false);
            }

            EditorCore.Settings.DirectoryExportVoicing = Utility.GetRelativePath(dialog.ExportPath, projectDirectory);

            DateTime dateNow = Utility.GetCurrentTime();

            project.LastVoicingExportDate = dateNow;
            project.Dirty = true;

            exportDirectory = dialog.ExportPath;
            if (dialog.UseDateDirectory)
            {
                exportDirectory = Path.Combine(exportDirectory, Utility.GetDateAsString(dateNow));
            }

            if (!Directory.Exists(exportDirectory))
            {
                Directory.CreateDirectory(exportDirectory);
            }

            var packageGroups = new List <List <Package> >();

            if (dialog.UsePackagesDirectory)
            {
                foreach (var package in dialog.ListPackages)
                {
                    packageGroups.Add(new List <Package>()
                    {
                        package
                    });
                }
            }
            else
            {
                packageGroups.Add(dialog.ListPackages);
            }

            var listLanguages = new List <Language>()
            {
                EditorCore.LanguageWorkstring
            };

            if (!dialog.WorkstringOnly)
            {
                listLanguages = dialog.ListLanguages;
            }

            ExporterStats.ProjectStats projectStats = new ExporterStats.ProjectStats();

            foreach (var packageGroup in packageGroups)     //Either a list of individual packages, or 1 entry with all the packages
            {
                var packageDirectory = exportDirectory;
                if (dialog.UsePackagesDirectory)
                {
                    packageDirectory = Path.Combine(packageDirectory, packageGroup[0].Name);
                }

                var dialogues = dialog.SelectedDialogues;
                if (!dialog.UseCustomSelection)
                {
                    dialogues = ResourcesHandler.GetAllDialoguesFromPackages(packageGroup);
                }

                var dateFrom = dialog.DateFrom;

                foreach (var language in listLanguages)
                {
                    string languageDirectory = Path.Combine(packageDirectory, language.VoicingCode);

                    if (!Directory.Exists(languageDirectory))
                    {
                        Directory.CreateDirectory(languageDirectory);
                    }

                    ExportLocasToCSVFile(languageDirectory, project, dialogues, language, dialog.WorkstringOnly, dialog.WorkstringFallback, dateFrom, projectStats);
                    ExportDialoguesToCSVFile(languageDirectory, project, dialogues, language, dateFrom);
                    ExportActorsToCSVFile(languageDirectory, project, dialogues, language, dateFrom);
                    ExportDialoguesToWwiseTextFile(languageDirectory, project, dialogues, language, dateFrom);
                }
            }

            ExporterStats.Export("TodoVoicingCount", projectStats, exportDirectory, dialog.ListPackages, listLanguages, dialog.WorkstringOnly, dialog.WorkstringFallback);

            System.Diagnostics.Process.Start(exportDirectory);

            return(true);
        }
Ejemplo n.º 5
0
        static public bool ExportToAriaCode()
        {
            var project = ResourcesHandler.Project;

            string projectDirectory = EditorHelper.GetProjectDirectory();
            string exportDirectory  = Properties.Settings.Default.ModPath;

            var dialog = new CodeExport("Export Dialogues",
                                        exportDirectory);
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                return(false);
            }

            EditorCore.Settings.DirectoryExportDialogues = Utility.GetRelativePath(dialog.ExportPath, projectDirectory);

            exportDirectory = dialog.ExportPath;

            if (!Directory.Exists(exportDirectory))
            {
                Directory.CreateDirectory(exportDirectory);
            }

            ExporterStats.ProjectStats projectStats = new ExporterStats.ProjectStats();

            string outputDirectory = Path.Combine(exportDirectory, "scripts", "globals", "static_data", "generated_dialog");

            if (!Directory.Exists(outputDirectory))
            {
                Directory.CreateDirectory(outputDirectory);
            }

            foreach (var package in dialog.ListPackages)     //Either a list of individual packages, or 1 entry with all the packages
            {
                var packageDirectory = Path.Combine(outputDirectory, package.Name);

                if (!Directory.Exists(packageDirectory))
                {
                    Directory.CreateDirectory(packageDirectory);
                }

                var dialogues = dialog.SelectedDialogues;
                if (!dialog.UseCustomSelection)
                {
                    dialogues = ResourcesHandler.GetAllDialoguesFromPackages(new List <Package>()
                    {
                        package
                    });
                }

                foreach (var singleDialog in dialogues)
                {
                    string luaContents = BuildLuaFile(singleDialog);
                    File.WriteAllText(Path.Combine(packageDirectory, singleDialog.GetName() + ".lua"), luaContents);
                }

                //Make generated_dialog/<package>/main.lua
                StringBuilder packageMainBuilder = new StringBuilder();
                AddAutogenerateHeader(packageMainBuilder);
                packageMainBuilder.AppendFormat("GeneratedDialog.{0} = {{}}{1}", package.Name, Environment.NewLine);

                foreach (var requireDialog in ResourcesHandler.GetAllDialoguesFromPackages(new List <Package>()
                {
                    package
                }))
                {
                    string dialogFile = Path.Combine(packageDirectory, requireDialog.GetName() + ".lua");
                    if (File.Exists(dialogFile))
                    {
                        packageMainBuilder.AppendFormat("require 'globals.static_data.generated_dialog.{0}.{1}'{2}", package.Name, requireDialog.GetName(), Environment.NewLine);
                    }
                }

                File.WriteAllText(Path.Combine(packageDirectory, "main.lua"), packageMainBuilder.ToString());
            }

            //Make generated_dialog/main.lua
            StringBuilder builder = new StringBuilder();

            AddAutogenerateHeader(builder);
            builder.AppendLine("GeneratedDialog = {}");
            foreach (var package in project.ListPackages)
            {
                if (File.Exists(Path.Combine(outputDirectory, package.Name, "main.lua")))
                {
                    builder.AppendFormat("require 'globals.static_data.generated_dialog.{0}.main'{1}", package.Name, Environment.NewLine);
                }
            }

            File.WriteAllText(Path.Combine(outputDirectory, "main.lua"), builder.ToString());

            System.Diagnostics.Process.Start(exportDirectory);

            Properties.Settings.Default.ModPath = exportDirectory;
            Properties.Settings.Default.Save();

            return(true);
        }