Exemple #1
0
 /// <summary>
 /// Initializes a new DialogueEntry copied from a Chat Mapper DialogEntry.
 /// </summary>
 /// <param name='chatMapperDialogEntry'>
 /// The Chat Mapper dialog entry to copy.
 /// </param>
 public DialogueEntry(ChatMapper.DialogEntry chatMapperDialogEntry)
 {
     if (chatMapperDialogEntry != null)
     {
         id     = chatMapperDialogEntry.ID;
         fields = Field.CreateListFromChatMapperFields(chatMapperDialogEntry.Fields);
         UseCanvasRectField();
         //--- Removed in Chat Mapper 1.7: conversationID = chatMapperDialogEntry.ConversationID;
         isRoot  = chatMapperDialogEntry.IsRoot;
         isGroup = chatMapperDialogEntry.IsGroup;
         if (isGroup)
         {
             currentSequence = "Continue()";
         }
         nodeColor            = chatMapperDialogEntry.NodeColor;
         delaySimStatus       = chatMapperDialogEntry.DelaySimStatus;
         falseConditionAction = chatMapperDialogEntry.FalseCondtionAction;
         conditionPriority    = ConditionPriorityUtility.StringToConditionPriority(chatMapperDialogEntry.ConditionPriority);
         foreach (var chatMapperLink in chatMapperDialogEntry.OutgoingLinks)
         {
             outgoingLinks.Add(new Link(chatMapperLink));
         }
         conditionsString = chatMapperDialogEntry.ConditionsString;
         userScript       = chatMapperDialogEntry.UserScript;
     }
 }
        /// <summary>
        /// Reads the DialogueEntries section. DialogueEntry is not a subclass of Asset,
        /// so we can't reuse the ReadAssets() code above.
        /// </summary>
        /// <param name="database">Dialogue database.</param>
        private void ReadDialogueEntries(DialogueDatabase database, bool add)
        {
            Debug.Log("Dialogue System CSV Importer: " + (add ? "Reading" : "Skipping") + " DialogueEntries section");

            // Read field names and types:
            string[] fieldNames = GetValues(GetNextSourceLine());
            string[] fieldTypes = GetValues(GetNextSourceLine());

            // Keep reading until we reach another asset type heading or end of file:
            int safeguard = 0;

            while (!(IsSourceAtEnd() || AssetTypeHeadings.Contains(GetFirstField(PeekNextSourceLine()))))
            {
                safeguard++;
                if (safeguard > MaxIterations)
                {
                    break;
                }

                string[] values = GetValues(GetNextSourceLine());

                if (add)
                {
                    // Create the dialogue entry:
                    DialogueEntry entry = new DialogueEntry();
                    entry.fields = new List <Field>();
                    // We can ignore value[0] (entrytag).
                    entry.conversationID       = Tools.StringToInt(values[1]);
                    entry.id                   = Tools.StringToInt(values[2]);
                    entry.ActorID              = Tools.StringToInt(values[3]);
                    entry.ConversantID         = Tools.StringToInt(values[4]);
                    entry.Title                = values[5];
                    entry.MenuText             = values[6];
                    entry.DialogueText         = values[7];
                    entry.isGroup              = Tools.StringToBool(values[8]);
                    entry.falseConditionAction = values[9];
                    entry.conditionPriority    = ConditionPriorityUtility.StringToConditionPriority(values[10]);
                    entry.conditionsString     = values[11];
                    entry.userScript           = values[12];

                    // Read the remaining values and assign them to the asset's fields:
                    ReadAssetFields(fieldNames, fieldTypes, DialogueEntrySpecialValues, values, entry.fields);

                    // Convert canvasRect field to entry position on node editor canvas:
                    entry.UseCanvasRectField();

                    // Finally, add the asset:
                    var conversation = database.GetConversation(entry.conversationID);
                    if (conversation == null)
                    {
                        throw new InvalidDataException(string.Format("Conversation {0} referenced in entry {1} not found", entry.conversationID, entry.id));
                    }
                    conversation.dialogueEntries.Add(entry);
                }
            }
        }
        /// <summary>
        /// Reads the OutgoingLinks section. Again, Link is not a subclass of Asset,
        /// so we can't reuse the ReadAssets() method.
        /// </summary>
        /// <param name="database">Dialogue database.</param>
        private void ReadOutgoingLinks(DialogueDatabase database, bool add)
        {
            Debug.Log("Dialogue System CSV Importer: " + (add ? "Reading" : "Skipping") + " OutgoingLinks section");
            GetNextSourceLine(); // Headings
            GetNextSourceLine(); // Types

            // Keep reading until we reach another asset type heading or end of file:
            int safeguard = 0;

            while (!(IsSourceAtEnd() || AssetTypeHeadings.Contains(GetFirstField(PeekNextSourceLine()))))
            {
                safeguard++;
                if (safeguard > MaxIterations)
                {
                    break;
                }
                string[] values = GetValues(GetNextSourceLine());

                if (add)
                {
                    var link = new Link(Tools.StringToInt(values[0]), Tools.StringToInt(values[1]),
                                        Tools.StringToInt(values[2]), Tools.StringToInt(values[3]));
                    link.priority = ConditionPriorityUtility.StringToConditionPriority(values[4]);
                    var entry = database.GetDialogueEntry(link.originConversationID, link.originDialogueID);
                    if (entry == null)
                    {
                        Debug.LogWarning(string.Format("Dialogue System: CSV import error: dialogue entry {0}.{1} referenced in an outgoing link was not found.", link.originConversationID, link.originDialogueID));
                        numWarnings++;
                    }
                    else
                    {
                        entry.outgoingLinks.Add(link);
                    }
                }
            }
        }