示例#1
0
        public QuestList <T> MergeLists(QuestList <T> list2)
        {
            var result = new QuestList <T>(this);

            result.AddRange(list2);
            return(result);
        }
示例#2
0
            public override void Save(GameXmlWriter writer, Element element, string attribute, object value)
            {
                QuestList <Element> list = (QuestList <Element>)value;
                string saveString        = String.Join("; ", list.Select(e => e.Name).ToArray());

                base.WriteAttribute(writer, element, attribute, "objectlist", saveString);
            }
示例#3
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);
            }
        }
示例#4
0
            public override void Save(GameWriter writer, Element element, string attribute, object value, bool isFinal)
            {
                QuestList <string> list       = (QuestList <string>)value;
                string             saveString = "[" + String.Join(", ", list.Select(s => Utility.EscapeString(s)).ToArray()) + "]";

                base.WriteAttribute(writer, element, attribute, saveString, isFinal);
            }
示例#5
0
        public static QuestList <T> operator -(QuestList <T> list, T element)
        {
            //System.Diagnostics.Debug.Assert(false, "Operators on lists are deprecated");
            QuestList <T> result = new QuestList <T>(list);

            result.Remove(element);
            return(result);
        }
示例#6
0
 public EditableList(EditorController controller, QuestList <T> source)
 {
     m_controller      = controller;
     m_source          = source;
     m_source.Added   += m_source_Added;
     m_source.Removed += m_source_Removed;
     PopulateWrappedItems();
 }
示例#7
0
        /// <summary>
        /// Add an element to the beginning of a list
        /// </summary>
        /// <param name="element"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public static QuestList <T> operator +(T element, QuestList <T> list)
        {
            //System.Diagnostics.Debug.Assert(false, "Operators on lists are deprecated");
            QuestList <T> result = new QuestList <T>();

            result.Add(element);
            result.AddRange(list);
            return(result);
        }
示例#8
0
        private IEditableList <T> CloneInternal(Element parent, string attribute)
        {
            QuestList <T> newSource = (QuestList <T>)m_source.Clone();

            newSource.Locked = false;
            parent.Fields.Set(attribute, newSource);
            newSource = (QuestList <T>)parent.Fields.Get(attribute);
            return(EditableList <T> .GetNewInstance(m_controller, newSource));
        }
示例#9
0
        /// <summary>
        /// Concatenates lists. Appends all items in list2 onto list1, except for any items in list2 which already appear in list1.
        /// </summary>
        /// <param name="list1"></param>
        /// <param name="list2"></param>
        /// <returns></returns>
        public static QuestList <T> operator *(QuestList <T> list1, QuestList <T> list2)
        {
            QuestList <T> result = new QuestList <T>(list1);

            foreach (T item in list2)
            {
                if (!list1.Contains(item))
                {
                    result.Add(item);
                }
            }
            return(result);
        }
示例#10
0
            private QuestList <object> LoadQuestList(XElement xml)
            {
                var result = new QuestList <object>();

                foreach (var xmlValue in xml.Elements("value"))
                {
                    var    typeAttr = xmlValue.Attribute("type");
                    string type     = typeAttr != null ? typeAttr.Value : null;
                    var    value    = GameLoader.ReadXmlValue(type, xmlValue);

                    result.Add(value);
                }
                return(result);
            }
示例#11
0
        internal void RemoveReferencesTo(Element e)
        {
            List <string> nullifyAttributes = new List <string>();

            foreach (var attribute in m_attributes)
            {
                Element elementValue = attribute.Value as Element;
                if (elementValue != null)
                {
                    if (elementValue == e)
                    {
                        nullifyAttributes.Add(attribute.Key);
                    }
                    continue;
                }

                QuestList <Element> listValue = attribute.Value as QuestList <Element>;
                if (listValue != null)
                {
                    while (listValue.Contains(e))
                    {
                        listValue.Remove(e);
                    }
                    continue;
                }

                QuestDictionary <Element> dictionaryValue = attribute.Value as QuestDictionary <Element>;
                if (dictionaryValue != null)
                {
                    List <string> keysToRemove = new List <string>();
                    foreach (var item in dictionaryValue)
                    {
                        if (item.Value == e)
                        {
                            keysToRemove.Add(item.Key);
                        }
                    }
                    foreach (string key in keysToRemove)
                    {
                        dictionaryValue.Remove(key);
                    }
                    continue;
                }
            }

            foreach (string attribute in nullifyAttributes)
            {
                Set(attribute, null);
            }
        }
示例#12
0
            public override void Save(GameXmlWriter writer, Element element, string attribute, object value)
            {
                writer.WriteStartElement(attribute);
                if (element == null || !GameSaver.IsImpliedType(element, attribute, "list"))
                {
                    writer.WriteAttributeString("type", "list");
                }

                QuestList <object> list = (QuestList <object>)value;

                foreach (var item in list)
                {
                    FieldSaver.SaveValue(writer, "value", item);
                }
                writer.WriteEndElement();
            }
示例#13
0
        private void ResolveObjectList(QuestList <object> list, ScriptFactory scriptFactory)
        {
            for (int i = 0; i < list.Count; i++)
            {
                var value = list[i];

                object replacement;
                var    replace = ReplaceValue(value, scriptFactory, out replacement);

                if (replace)
                {
                    list.RemoveAt(i);
                    list.Insert(i, replacement);
                }
            }
        }
            private QuestList <object> LoadQuestList(XElement xml)
            {
                var result = new QuestList <object>();

                foreach (var xmlValue in xml.Elements("value"))
                {
                    var typeAttribute = xmlValue.Attribute("type");
                    if (typeAttribute == null)
                    {
                        throw new Exception("Type not specified for value " + xmlValue);
                    }
                    string type  = typeAttribute.Value;
                    var    value = GameLoader.ReadXmlValue(type, xmlValue);

                    result.Add(value);
                }
                return(result);
            }
示例#15
0
            public override void Save(GameWriter writer, Element element, string attribute, object value, bool isFinal)
            {
                QuestList <Element> list = (QuestList <Element>)value;

                if (list.Count == 0)
                {
                    // Just write a blank list
                    base.WriteAttribute(writer, element, attribute, "new Array()", isFinal);
                }

                foreach (Element item in list)
                {
                    writer.AddPostElementScript(element, string.Format(
                                                    "objectListReferences.push([\"object_{0}\", \"{1}\", \"object_{2}\"]);",
                                                    element.MetaFields[MetaFieldDefinitions.MappedName],
                                                    attribute,
                                                    item.Name));
                }
            }
        protected override object ConvertField(Element e, string fieldName, object value)
        {
            if (fieldName == "steps")
            {
                QuestList <string> steps  = (QuestList <string>)value;
                QuestList <string> result = new QuestList <string>();

                foreach (string step in steps)
                {
                    if (step.StartsWith("assert:"))
                    {
                        string     expr       = step.Substring(7);
                        Expression expression = new Expression(expr, e.Loader);
                        result.Add("assert:" + expression.Save(new Context()));
                    }
                    else
                    {
                        result.Add(step);
                    }
                }
                return(result);
            }
            return(value);
        }
示例#17
0
            public void StartSave(GameXmlWriter writer, Element e)
            {
                writer.WriteStartElement("walkthrough");
                writer.WriteAttributeString("name", e.Name);

                QuestList <string> steps = e.Fields[FieldDefinitions.Steps];

                if (steps != null && steps.Count > 0)
                {
                    string result = string.Empty;
                    string indent = Utility.GetIndentChars(writer.IndentLevel + 1, writer.IndentChars);

                    foreach (string step in steps)
                    {
                        result += Environment.NewLine + indent + step;
                    }
                    result += Environment.NewLine;

                    writer.WriteStartElement("steps");
                    writer.WriteAttributeString("type", GameSaver.Version <= WorldModelVersion.v530 ? "list" : "simplestringlist");
                    writer.WriteString(result);
                    writer.WriteEndElement();
                }
            }
示例#18
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);
        }
示例#19
0
 private static EditableList <T> GetNewInstance(EditorController controller, QuestList <T> list)
 {
     return(new EditableList <T>(controller, list));
 }
示例#20
0
 public static EditableList <T> GetInstance(EditorController controller, QuestList <T> list)
 {
     return(s_wrapper.GetInstance(controller, list));
 }
示例#21
0
        public IExtendableField Merge(IExtendableField parent)
        {
            QuestList <T> parentList = parent as QuestList <T>;

            return(parentList.MergeLists(this));
        }
示例#22
0
        public QuestList <T> Exclude(QuestList <T> excludeList)
        {
            var enumerable = this.Where(x => !excludeList.Contains(x));

            return(new QuestList <T>(enumerable));
        }