Пример #1
0
        /// <summary>
        /// Associates tags in a tag dictionary with values from a primary text table
        /// (i.e., quest giver's text table), or failing that QuestMachine's default text
        /// table, or failing that the tag name itself. Leaves ID tags such as {QUESTERID}
        /// untouched.
        /// </summary>
        /// <param name="tagDictionary">The tag dictionary containing tags that need values assigned.</param>
        /// <param name="textTable">The primary text table from which to look up values.</param>
        public static void AddTagValuesToDictionary(TagDictionary tagDictionary, TextTable textTable)
        {
            if (tagDictionary == null)
            {
                return;
            }
            var newDict = new Dictionary <string, string>();

            foreach (var kvp in tagDictionary.dict)
            {
                var tag = kvp.Key;
                if (string.IsNullOrEmpty(tag) || tag.Length <= 2)
                {
                    continue;
                }
                if (IsIDTag(tag))
                {
                    // Leave ID tags untouched:
                    newDict.Add(tag, kvp.Value);
                    continue;
                }
                var fieldName = tag.Substring(1, tag.Length - 2).Trim();
                if (textTable != null && textTable.HasField(fieldName))
                {
                    // Check in current text table;
                    newDict.Add(tag, PrepareFieldText(textTable.GetFieldText(fieldName)));
                }
                else if (QuestMachine.textTable != null && QuestMachine.textTable.HasField(fieldName))
                {
                    // Otherwise look in QuestMachine's text table:
                    newDict.Add(tag, PrepareFieldText(QuestMachine.textTable.GetFieldText(fieldName)));
                }
                else
                {
                    // Otherwise use the tag's text:
                    newDict.Add(tag, fieldName);
                }
            }
            tagDictionary.dict = newDict;
        }