Example #1
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);
        }
Example #2
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);
        }
Example #3
0
        public void Resolve(ScriptFactory scriptFactory)
        {
            CheckNotResolved();
            foreach (string typename in m_defaultTypes)
            {
                // It is legitimate for a default type not to exist
                if (m_worldModel.Elements.ContainsKey(ElementType.ObjectType, typename))
                {
                    m_fields.AddType(m_worldModel.GetObjectType(typename));
                }
            }
            m_defaultTypes = null;
            foreach (string typename in m_types)
            {
                try
                {
                    m_fields.AddType(m_worldModel.GetObjectType(typename));
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Error adding type '{0}' to element '{1}': {2}", typename, m_fields.Get("name"), ex.Message), ex);
                }
            }
            m_types = null;
            foreach (string property in m_objectFields.Keys)
            {
                try
                {
                    m_fields.Set(property, m_worldModel.Elements.Get(m_objectFields[property]));
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Error adding attribute '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex);
                }
            }
            m_objectFields = null;
            foreach (string property in m_scripts.Keys)
            {
                try
                {
                    m_fields.Set(property, scriptFactory.CreateScript(m_scripts[property]));
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Error adding script attribute '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex);
                }
            }
            m_scripts = null;
            foreach (string property in m_scriptDictionaries.Keys)
            {
                try
                {
                    m_fields.Set(property, ConvertToScriptDictionary(m_scriptDictionaries[property], scriptFactory));
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Error adding script dictionary '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex);
                }
            }
            m_scriptDictionaries = null;
            foreach (string property in m_objectLists.Keys)
            {
                try
                {
                    m_fields.Set(property, new QuestList <Element>(m_objectLists[property].Select(n => m_worldModel.Elements.Get(n))));
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Error adding object list '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex);
                }
            }
            m_objectLists = null;
            foreach (string property in m_objectDictionaries.Keys)
            {
                try
                {
                    m_fields.Set(property, ConvertToObjectDictionary(m_objectDictionaries[property]));
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("Error adding object dictionary '{0}' to element '{1}': {2}", property, m_fields.Get("name"), ex.Message), ex);
                }
            }
            m_objectDictionaries = null;
            foreach (Action action in m_actions)
            {
                action();
            }
            m_actions = null;
            foreach (var field in m_fields.FieldNames)
            {
                var attribute  = m_fields.Get(field);
                var objectList = attribute as QuestList <object>;
                if (objectList != null)
                {
                    ResolveObjectList(objectList, scriptFactory);
                }

                var objectDictionary = attribute as QuestDictionary <object>;
                if (objectDictionary != null)
                {
                    ResolveObjectDictionary(objectDictionary, scriptFactory);
                }
            }
            m_resolved = true;
        }