/// <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> /// Gets an array of all quests matching the specified state bitmask. /// </summary> /// <returns> /// The titles of all quests matching the specified state bitmask. /// </returns> /// <param name='flags'> /// A bitmask of QuestState values. /// </param> /// <example> /// string[] completedQuests = QuestLog.GetAllQuests( QuestState.Success | QuestState.Failure ); /// </example> public static string[] GetAllQuests(QuestState flags) { List <string> titles = new List <string>(); LuaTableWrapper itemTable = Lua.Run("return Item").AsTable; if (!itemTable.IsValid) { if (DialogueDebug.LogWarnings) { Debug.LogWarning(string.Format("{0}: Quest Log couldn't access Lua Item[] table. Has the Dialogue Manager loaded a database yet?", new System.Object[] { DialogueDebug.Prefix })); } return(titles.ToArray()); } foreach (LuaTableWrapper fields in itemTable.Values) { string title = null; bool isItem = false; try { object titleObject = fields["Name"]; title = (titleObject != null) ? titleObject.ToString() : string.Empty; isItem = false; object isItemObject = fields["Is_Item"]; if (isItemObject != null) { if (isItemObject.GetType() == typeof(bool)) { isItem = (bool)isItemObject; } else { isItem = Tools.StringToBool(isItemObject.ToString()); } } } catch {} if (!isItem) { if (string.IsNullOrEmpty(title)) { if (DialogueDebug.LogWarnings) { Debug.LogWarning(string.Format("{0}: A quest title (item name in Item[] table) is null or empty", new System.Object[] { DialogueDebug.Prefix })); } } else if (IsQuestInStateMask(title, flags)) { titles.Add(title); } } } titles.Sort(); return(titles.ToArray()); }
/// <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) { Debug.Log("Reading 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: while (!(IsSourceAtEnd() || AssetTypeHeadings.Contains(PeekNextSourceLine()))) { string[] values = GetValues(GetNextSourceLine()); // 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.DefaultMenuText = values[6]; entry.DefaultDialogueText = values[7]; entry.isGroup = Tools.StringToBool(values[8]); entry.falseConditionAction = values[9]; entry.conditionPriority = ConditionPriorityTools.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); // 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> /// A static utility method that looks up a field in a list and returns its bool value. /// </summary> /// <param name='fields'> /// A list of fields. /// </param> /// <param name='title'> /// Title of the field. /// </param> /// <returns> /// The value of the field, or <c>false</c> if the field doesn't exist or isn't a bool. /// </returns> public static bool LookupBool(List <Field> fields, string title) { return(Tools.StringToBool(LookupValue(fields, title))); }