示例#1
0
        // TO DO: Public methods shouldn't be starting/ending transactions here - that should be up to the caller

        public void Add(string key, TWrapped value)
        {
            string undoEntry = null;

            undoEntry = string.Format("Add '{0}={1}'", key, value == null ? string.Empty : value.DisplayString());

            m_controller.WorldModel.UndoLogger.StartTransaction(undoEntry);
            m_source.Add(key, UnwrapValue(value), UpdateSource.User);
            m_controller.WorldModel.UndoLogger.EndTransaction();
        }
示例#2
0
        public void Resolve(GameLoader loader)
        {
            foreach (string typeName in m_typeNames)
            {
                if (loader.Elements.ContainsKey(typeName))
                {
                    m_types.Push(loader.Elements[typeName]);
                }
            }

            foreach (var objectRef in m_objectReferences)
            {
                Set(objectRef.Key, loader.Elements[objectRef.Value]);
            }

            foreach (var objectList in m_objectLists)
            {
                QuestList <Element> newList = new QuestList <Element>(objectList.Value.Select(l => loader.Elements[l]));
                Set(objectList.Key, newList);
            }

            foreach (var objectDict in m_objectDictionaries)
            {
                QuestDictionary <Element> newDict = new QuestDictionary <Element>();
                foreach (var item in objectDict.Value)
                {
                    newDict.Add(item.Key, loader.Elements[item.Value]);
                }
                Set(objectDict.Key, newDict);
            }
        }
示例#3
0
        public void Add(string key, T value)
        {
            string undoEntry = null;

            if (typeof(T) == typeof(string))
            {
                undoEntry = string.Format("Add '{0}={1}'", key, value as string);
            }

            if (undoEntry == null)
            {
                throw new InvalidOperationException("Unknown dictionary type");
            }

            m_controller.WorldModel.UndoLogger.StartTransaction(undoEntry);
            m_source.Add(key, value, UpdateSource.User);
            m_controller.WorldModel.UndoLogger.EndTransaction();
        }
示例#4
0
        private QuestDictionary <Element> ConvertToObjectDictionary(IDictionary <string, string> dictionary)
        {
            QuestDictionary <Element> newDictionary = new QuestDictionary <Element>();

            foreach (var item in dictionary)
            {
                Element element = m_worldModel.Elements.Get(item.Value);
                newDictionary.Add(item.Key, element);
            }
            return(newDictionary);
        }
示例#5
0
        private QuestDictionary <IScript> ConvertToScriptDictionary(IDictionary <string, string> dictionary, ScriptFactory scriptFactory)
        {
            QuestDictionary <IScript> newDictionary = new QuestDictionary <IScript>();

            foreach (var item in dictionary)
            {
                IScript newScript = scriptFactory.CreateScript(item.Value);
                newDictionary.Add(item.Key, newScript);
            }
            return(newDictionary);
        }
示例#6
0
        private static QuestDictionary <string> PopulateInternal(Regex regex, string input)
        {
            if (!regex.IsMatch(input))
            {
                throw new Exception(string.Format("String '{0}' is not a match for Regex '{1}'", input, regex.ToString()));
            }

            QuestDictionary <string> result = new QuestDictionary <string>();

            foreach (string groupName in regex.GetGroupNames())
            {
                if (!TextAdventures.Utility.Strings.IsNumeric(groupName))
                {
                    string groupMatch = regex.Match(input).Groups[groupName].Value;
                    result.Add(groupName, groupMatch);
                }
            }

            return(result);
        }
示例#7
0
        public static QuestDictionary <string> Populate(string regexPattern, string input)
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(regexPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            if (!regex.IsMatch(input))
            {
                throw new Exception(string.Format("String '{0}' is not a match for Regex '{1}'", input, regexPattern));
            }

            QuestDictionary <string> result = new QuestDictionary <string>();

            foreach (string groupName in regex.GetGroupNames())
            {
                if (!TextAdventures.Utility.Strings.IsNumeric(groupName))
                {
                    string groupMatch = regex.Match(input).Groups[groupName].Value;
                    result.Add(groupName, groupMatch);
                }
            }

            return(result);
        }
示例#8
0
            public override void Load(Element element, string attribute, string value)
            {
                QuestDictionary <string> result = new QuestDictionary <string>();

                string[] values = Utility.ListSplit(value);
                foreach (string pair in values)
                {
                    if (pair.Length > 0)
                    {
                        string trimmedPair = pair.Trim();
                        int    splitPos    = trimmedPair.IndexOf('=');
                        if (splitPos == -1)
                        {
                            GameLoader.AddError(string.Format("Missing '=' in dictionary element '{0}' in '{1}.{2}'", trimmedPair, element.Name, attribute));
                            return;
                        }
                        string key       = trimmedPair.Substring(0, splitPos).Trim();
                        string dictValue = trimmedPair.Substring(splitPos + 1).Trim();
                        result.Add(key, dictValue);
                    }
                }

                element.Fields.Set(attribute, result);
            }
示例#9
0
        private bool ReplaceValue(object value, ScriptFactory scriptFactory, out object replacement)
        {
            replacement = null;

            var genericList = value as QuestList <object>;

            if (genericList != null)
            {
                ResolveObjectList(genericList, scriptFactory);
                return(false);
            }

            var genericDictionary = value as QuestDictionary <object>;

            if (genericDictionary != null)
            {
                ResolveObjectDictionary(genericDictionary, scriptFactory);
                return(false);
            }

            var objRef = value as Types.LazyObjectReference;

            if (objRef != null)
            {
                replacement = m_worldModel.Elements.Get(objRef.ObjectName);
                return(true);
            }

            var objList = value as Types.LazyObjectList;

            if (objList != null)
            {
                replacement = new QuestList <Element>(objList.Objects.Select(o => m_worldModel.Elements.Get(o)));
                return(true);
            }

            var objDictionary = value as Types.LazyObjectDictionary;

            if (objDictionary != null)
            {
                var newDictionary = new QuestDictionary <Element>();
                foreach (var kvp in objDictionary.Dictionary)
                {
                    newDictionary.Add(kvp.Key, m_worldModel.Elements.Get(kvp.Value));
                }
                replacement = newDictionary;
                return(true);
            }

            var script = value as Types.LazyScript;

            if (script != null)
            {
                replacement = scriptFactory.CreateScript(script.Script);
                return(true);
            }

            var scriptDictionary = value as Types.LazyScriptDictionary;

            if (scriptDictionary != null)
            {
                replacement = ConvertToScriptDictionary(scriptDictionary.Dictionary, scriptFactory);
                return(true);
            }

            return(false);
        }