示例#1
0
        private void ProcessFieldIDs(DialogueDatabase database, List <Field> fields, MasterIDs masterIDs)
        {
            foreach (var field in fields)
            {
                int oldID = Tools.StringToInt(field.value);
                switch (field.type)
                {
                case FieldType.Actor:
                    Actor actor = database.GetActor(oldID);
                    if (actor != null)
                    {
                        field.value = FindIDConversion(actor.Name, masterIDs.actors, oldID).ToString();
                    }
                    break;

                case FieldType.Item:
                    Item item = database.GetItem(oldID);
                    if (item != null)
                    {
                        field.value = FindIDConversion(item.Name, masterIDs.items, oldID).ToString();
                    }
                    break;

                case FieldType.Location:
                    Location location = database.GetLocation(oldID);
                    if (location != null)
                    {
                        field.value = FindIDConversion(location.Name, masterIDs.locations, oldID).ToString();
                    }
                    break;
                }
            }
        }
        private static void ExportConversations(DialogueDatabase database, EntrytagFormat entrytagFormat, StreamWriter file)
        {
            file.WriteLine(string.Empty);
            file.WriteLine("---Conversations---");

            // Find all languages: (TO BE IMPLEMENTED LATER)
            //List<string> otherDialogueText = new List<string>();
            //foreach (var conversation in database.conversations) {
            //	foreach (var entry in conversation.dialogueEntries) {
            //		foreach (var field in entry.fields) {
            //		}
            //	}
            //}

            // Cache actor names:
            Dictionary <int, string> actorNames = new Dictionary <int, string>();

            // Export all conversations:
            foreach (var conversation in database.conversations)
            {
                file.WriteLine(string.Empty);
                file.WriteLine(string.Format("Conversation {0},{1}", conversation.id, CleanField(conversation.Title)));
                file.WriteLine(string.Format("Description,{0}", CleanField(conversation.Description)));
                StringBuilder sb = new StringBuilder("entrytag,Actor,Dialogue Text");
                //foreach (var fieldTitle in otherDialogueText) {
                //	sb.AppendFormat(",{0}", CleanField(fieldTitle));
                //}
                file.WriteLine(sb.ToString());
                foreach (var entry in conversation.dialogueEntries)
                {
                    if (entry.id > 0)
                    {
                        if (!actorNames.ContainsKey(entry.ActorID))
                        {
                            Actor actor = database.GetActor(entry.ActorID);
                            actorNames.Add(entry.ActorID, (actor != null) ? CleanField(actor.Name) : "ActorNotFound");
                        }
                        string actorName = actorNames[entry.ActorID];
                        string entrytag  = database.GetEntrytag(conversation, entry, entrytagFormat);
                        string lineText  = CleanField(entry.SubtitleText);
                        file.WriteLine(string.Format("{0},{1},{2}", entrytag, actorName, lineText));
                    }
                }
            }
        }
示例#3
0
        private static void ExportConversations(DialogueDatabase database, string language, EntrytagFormat entrytagFormat, StreamWriter file)
        {
            file.WriteLine(string.Empty);
            file.WriteLine("---Conversations---");

            // Cache actor names:
            Dictionary <int, string> actorNames = new Dictionary <int, string>();

            // Export all conversations:
            foreach (var conversation in database.conversations)
            {
                file.WriteLine(string.Empty);
                file.WriteLine(string.Format("Conversation {0},{1}", conversation.id, CleanField(conversation.Title)));
                file.WriteLine(string.Format("Description,{0}", CleanField(conversation.Description)));
                StringBuilder sb = new StringBuilder("entrytag,Actor,Description,");
                sb.Append(string.IsNullOrEmpty(language) ? "Dialogue Text" : CleanField(language));
                file.WriteLine(sb.ToString());
                foreach (var entry in conversation.dialogueEntries)
                {
                    if (entry.id > 0)
                    {
                        sb = new StringBuilder();
                        if (!actorNames.ContainsKey(entry.ActorID))
                        {
                            Actor actor = database.GetActor(entry.ActorID);
                            actorNames.Add(entry.ActorID, (actor != null) ? CleanField(actor.Name) : "ActorNotFound");
                        }
                        string actorName   = actorNames[entry.ActorID];
                        string description = Field.LookupValue(entry.fields, "Description");
                        string entrytag    = database.GetEntrytag(conversation, entry, entrytagFormat);
                        var    lineText    = string.IsNullOrEmpty(language) ? entry.subtitleText : Field.LookupValue(entry.fields, language);
                        sb.AppendFormat("{0},{1},{2},{3}", CleanField(entrytag), CleanField(actorName), CleanField(description), CleanField(lineText));
                        file.WriteLine(sb.ToString());
                    }
                }
            }
        }
示例#4
0
 private void EvaluateLinksAtPriority(ConditionPriority priority, DialogueEntry entry, List <Response> npcResponses, List <Response> pcResponses, List <DialogueEntry> visited)
 {
     if (entry != null)
     {
         foreach (Link link in entry.outgoingLinks)
         {
             DialogueEntry destinationEntry = database.GetDialogueEntry(link);
             if ((destinationEntry != null) && ((destinationEntry.conditionPriority == priority) || (link.priority == priority)))
             {
                 CharacterType characterType = database.GetCharacterType(destinationEntry.ActorID);
                 bool          isValid       = Lua.IsTrue(destinationEntry.conditionsString, DialogueDebug.LogInfo, allowLuaExceptions) &&
                                               ((IsDialogueEntryValid == null) || IsDialogueEntryValid(destinationEntry));
                 if (isValid)
                 {
                     // Condition is true (or blank), so add this link:
                     if (destinationEntry.isGroup)
                     {
                         // For groups, evaluate their links (after running the group node's Lua code):
                         if (DialogueDebug.LogInfo)
                         {
                             Debug.Log(string.Format("{0}: Add Group ({1}): ID={2}:{3} '{4}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, destinationEntry.Title }));
                         }
                         Lua.Run(destinationEntry.userScript, DialogueDebug.LogInfo, allowLuaExceptions);
                         for (int i = (int)ConditionPriority.High; i >= 0; i--)
                         {
                             int originalResponseCount = npcResponses.Count + pcResponses.Count;;
                             EvaluateLinksAtPriority((ConditionPriority)i, destinationEntry, npcResponses, pcResponses, visited);
                             if ((npcResponses.Count + pcResponses.Count) > originalResponseCount)
                             {
                                 break;
                             }
                         }
                     }
                     else
                     {
                         // For regular entries, just add them:
                         if (DialogueDebug.LogInfo)
                         {
                             Debug.Log(string.Format("{0}: Add Link ({1}): ID={2}:{3} '{4}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry) }));
                         }
                         if (characterType == CharacterType.NPC)
                         {
                             // Add NPC response:
                             npcResponses.Add(new Response(FormattedText.Parse(destinationEntry.SubtitleText, database.emphasisSettings), destinationEntry));
                         }
                         else
                         {
                             // Add PC response, wrapping old responses in em tags if specified:
                             string text = destinationEntry.ResponseButtonText;
                             if (emTagForOldResponses != EmTag.None)
                             {
                                 string simStatus     = Lua.Run(string.Format("return Conversation[{0}].Dialog[{1}].SimStatus", new System.Object[] { destinationEntry.conversationID, destinationEntry.id })).AsString;
                                 bool   isOldResponse = string.Equals(simStatus, "WasDisplayed");
                                 if (isOldResponse)
                                 {
                                     text = string.Format("[em{0}]{1}[/em{0}]", (int)emTagForOldResponses, text);
                                 }
                             }
                             pcResponses.Add(new Response(FormattedText.Parse(text, database.emphasisSettings), destinationEntry));
                             DialogueLua.MarkDialogueEntryOffered(destinationEntry);
                         }
                     }
                 }
                 else
                 {
                     // Condition is false, so block or pass through according to destination entry's setting:
                     if (LinkTools.IsPassthroughOnFalse(destinationEntry))
                     {
                         if (DialogueDebug.LogInfo)
                         {
                             Debug.Log(string.Format("{0}: Passthrough on False Link ({1}): ID={2}:{3} '{4}' Condition='{5}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry), destinationEntry.conditionsString }));
                         }
                         List <Response> linkNpcResponses = new List <Response>();
                         List <Response> linkPcResponses  = new List <Response>();
                         EvaluateLinks(destinationEntry, linkNpcResponses, linkPcResponses, visited);
                         npcResponses.AddRange(linkNpcResponses);
                         pcResponses.AddRange(linkPcResponses);
                     }
                     else
                     {
                         if (DialogueDebug.LogInfo)
                         {
                             Debug.Log(string.Format("{0}: Block on False Link ({1}): ID={2}:{3} '{4}' Condition='{5}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry), destinationEntry.conditionsString }));
                         }
                     }
                 }
             }
         }
     }
 }
 private void EvaluateLinksAtPriority(ConditionPriority priority, DialogueEntry entry, List <Response> npcResponses,
                                      List <Response> pcResponses, List <DialogueEntry> visited,
                                      bool stopAtFirstValid = false)
 {
     if (entry != null)
     {
         for (int ol = 0; ol < entry.outgoingLinks.Count; ol++)
         {
             var           link             = entry.outgoingLinks[ol];
             DialogueEntry destinationEntry = m_database.GetDialogueEntry(link);
             if ((destinationEntry != null) && (/*(destinationEntry.conditionPriority == priority) ||*/ (link.priority == priority))) // Note: Only observe link priority. Why does Chat Mapper even have conditionPriority?
             {
                 CharacterType characterType = m_database.GetCharacterType(destinationEntry.ActorID);
                 Lua.Run("thisID = " + destinationEntry.id);
                 bool isValid = Lua.IsTrue(destinationEntry.conditionsString, DialogueDebug.logInfo, m_allowLuaExceptions) &&
                                ((isDialogueEntryValid == null) || isDialogueEntryValid(destinationEntry));
                 if (isValid || (m_includeInvalidEntries && (characterType == CharacterType.PC)))
                 {
                     // Condition is true (or blank), so add this link:
                     if (destinationEntry.isGroup)
                     {
                         // For groups, evaluate their links (after running the group node's Lua code and OnExecute() event):
                         if (DialogueDebug.logInfo)
                         {
                             Debug.Log(string.Format("{0}: Add Group ({1}): ID={2}:{3} '{4}' ({5})", new System.Object[] { DialogueDebug.Prefix, GetActorName(m_database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, destinationEntry.Title, isValid }));
                         }
                         Lua.Run(destinationEntry.userScript, DialogueDebug.logInfo, m_allowLuaExceptions);
                         destinationEntry.onExecute.Invoke();
                         for (int i = (int)ConditionPriority.High; i >= 0; i--)
                         {
                             int originalResponseCount = npcResponses.Count + pcResponses.Count;;
                             EvaluateLinksAtPriority((ConditionPriority)i, destinationEntry, npcResponses, pcResponses, visited);
                             if ((npcResponses.Count + pcResponses.Count) > originalResponseCount)
                             {
                                 break;
                             }
                         }
                     }
                     else
                     {
                         // For regular entries, just add them:
                         if (DialogueDebug.logInfo)
                         {
                             Debug.Log(string.Format("{0}: Add Link ({1}): ID={2}:{3} '{4}' ({5})", new System.Object[] { DialogueDebug.Prefix, GetActorName(m_database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry), isValid }));
                         }
                         if (characterType == CharacterType.NPC)
                         {
                             // Add NPC response:
                             npcResponses.Add(new Response(FormattedText.Parse(destinationEntry.subtitleText, m_database.emphasisSettings), destinationEntry, isValid));
                         }
                         else
                         {
                             // Add PC response, wrapping old responses in em tags if specified:
                             string text = destinationEntry.responseButtonText;
                             if (m_emTagForOldResponses != EmTag.None)
                             {
                                 string simStatus     = Lua.Run(string.Format("return Conversation[{0}].Dialog[{1}].SimStatus", new System.Object[] { destinationEntry.conversationID, destinationEntry.id })).asString;
                                 bool   isOldResponse = string.Equals(simStatus, DialogueLua.WasDisplayed);
                                 if (isOldResponse)
                                 {
                                     text = string.Format("[em{0}]{1}[/em{0}]", (int)m_emTagForOldResponses, text);
                                 }
                             }
                             if (m_emTagForInvalidResponses != EmTag.None)
                             {
                                 if (!isValid)
                                 {
                                     text = string.Format("[em{0}]{1}[/em{0}]", (int)m_emTagForInvalidResponses, text);
                                 }
                             }
                             pcResponses.Add(new Response(FormattedText.Parse(text, m_database.emphasisSettings), destinationEntry, isValid));
                             DialogueLua.MarkDialogueEntryOffered(destinationEntry);
                         }
                     }
                     if (stopAtFirstValid)
                     {
                         return;
                     }
                 }
                 else
                 {
                     // Condition is false, so block or pass through according to destination entry's setting:
                     if (LinkUtility.IsPassthroughOnFalse(destinationEntry))
                     {
                         if (DialogueDebug.logInfo)
                         {
                             Debug.Log(string.Format("{0}: Passthrough on False Link ({1}): ID={2}:{3} '{4}' Condition='{5}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(m_database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry), destinationEntry.conditionsString }));
                         }
                         List <Response> linkNpcResponses = new List <Response>();
                         List <Response> linkPcResponses  = new List <Response>();
                         EvaluateLinks(destinationEntry, linkNpcResponses, linkPcResponses, visited);
                         npcResponses.AddRange(linkNpcResponses);
                         pcResponses.AddRange(linkPcResponses);
                     }
                     else
                     {
                         if (DialogueDebug.logInfo)
                         {
                             Debug.Log(string.Format("{0}: Block on False Link ({1}): ID={2}:{3} '{4}' Condition='{5}'", new System.Object[] { DialogueDebug.Prefix, GetActorName(m_database.GetActor(destinationEntry.ActorID)), link.destinationConversationID, link.destinationDialogueID, GetLinkText(characterType, destinationEntry), destinationEntry.conditionsString }));
                         }
                     }
                 }
             }
         }
     }
 }
        private static void ExportSubtree(DialogueDatabase database, string language, Dictionary <int, string> actorNames, Dictionary <int, int> numLinksToEntry, List <DialogueEntry> visited, DialogueEntry entry, int siblingIndex, StreamWriter file)
        {
            if (entry == null)
            {
                return;
            }
            visited.Add(entry);
            if (entry.id > 0)
            {
                var omit = omitNoneOrContinueEntries && (entry.Sequence == "None()" || entry.Sequence == "Continue()");
                var show = !omit;

                // Write this entry (the root of the subtree).

                // Write entry ID if necessary:
                if (siblingIndex == -1)
                {
                    if (show)
                    {
                        file.WriteLine(string.Format("\tUnconnected entry [{0}]:", entry.id));
                    }
                    if (show)
                    {
                        file.WriteLine(string.Empty);
                    }
                }
                else if ((siblingIndex == 0 && !string.IsNullOrEmpty(entry.conditionsString)) ||
                         (siblingIndex > 0) ||
                         (numLinksToEntry.ContainsKey(entry.id) && numLinksToEntry[entry.id] > 1))
                {
                    if (string.IsNullOrEmpty(entry.conditionsString))
                    {
                        if (show)
                        {
                            file.WriteLine(string.Format("\tEntry [{0}]:", entry.id));
                        }
                    }
                    else
                    {
                        if (show)
                        {
                            file.WriteLine(string.Format("\tEntry [{0}]: ({1})", entry.id, entry.conditionsString));
                        }
                    }
                    if (show)
                    {
                        file.WriteLine(string.Empty);
                    }
                }
                if (!actorNames.ContainsKey(entry.ActorID))
                {
                    Actor actor = database.GetActor(entry.ActorID);
                    actorNames.Add(entry.ActorID, (actor != null) ? actor.Name.ToUpper() : "ACTOR");
                }
                if (show)
                {
                    file.WriteLine(string.Format("\t\t\t\t{0}", actorNames[entry.ActorID]));
                }
                var description = Field.LookupValue(entry.fields, "Description");
                if (!string.IsNullOrEmpty(description))
                {
                    if (show)
                    {
                        file.WriteLine(string.Format("\t\t\t({0})", description));
                    }
                }
                var lineText = string.IsNullOrEmpty(language) ? entry.subtitleText : Field.LookupValue(entry.fields, language);
                if (entry.isGroup)
                {
                    // Group entries use Title:
                    lineText = Field.LookupValue(entry.fields, "Title");
                    lineText = !string.IsNullOrEmpty(lineText) ? ("(" + lineText + ")") : "(Group entry; no dialogue)";
                }
                if (show)
                {
                    file.WriteLine(string.Format("\t\t{0}", lineText));
                }
                if (show)
                {
                    file.WriteLine(string.Empty);
                }
            }

            // Handle link summary:
            if (entry.outgoingLinks.Count == 0)
            {
                file.WriteLine("\t\t\t\t[END]");
                file.WriteLine(string.Empty);
            }
            else if (entry.outgoingLinks.Count > 1)
            {
                var s     = "\tResponses: ";
                var first = true;
                for (int i = 0; i < entry.outgoingLinks.Count; i++)
                {
                    if (!first)
                    {
                        s += ", ";
                    }
                    first = false;
                    var link = entry.outgoingLinks[i];
                    if (link.destinationConversationID == entry.conversationID)
                    {
                        s += "[" + link.destinationDialogueID + "]";
                    }
                    else
                    {
                        var destConversation = database.GetConversation(link.destinationConversationID);
                        if (destConversation != null)
                        {
                            s += "[" + destConversation.Title.ToUpper() + ":" + link.destinationDialogueID + "]";
                        }
                        else
                        {
                            s += "[Other Conversation]";
                        }
                    }
                }
                file.WriteLine(s);
                file.WriteLine(string.Empty);
            }

            // Follow each outgoing link as a subtree:
            for (int i = 0; i < entry.outgoingLinks.Count; i++)
            {
                var child = database.GetDialogueEntry(entry.outgoingLinks[i]);
                if (!visited.Contains(child))
                {
                    ExportSubtree(database, language, actorNames, numLinksToEntry, visited, child, i, file);
                }
            }
        }