Ejemplo n.º 1
0
        public void Add(ElementType t, string key, Element e)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("Invalid object name");
            }

            if (m_allElements.ContainsKey(key))
            {
                // An element with this name already exists. This is OK if the new element
                // is of the same type - then it will just override the previous element.

                if (!m_elements[t].ContainsKey(key))
                {
                    throw new Exception(string.Format(
                        "Element '{0}' of type '{1}' cannot override the existing element of type '{2}'",
                        key,
                        t,
                        m_allElements[key].ElemType));
                }

                // element is being overridden, so detach the event handler
                m_allElements[key].Fields.NameChanged -= ElementNameChanged;
            }

            m_allElements[key] = e;
            m_elements[t][key] = e;

            e.Fields.NameChanged += ElementNameChanged;
        }
Ejemplo n.º 2
0
        public EditorDefinition(WorldModel worldModel, Element source)
        {
            m_tabs = new Dictionary<string, IEditorTab>();
            m_controls = new Dictionary<string, IEditorControl>();
            m_appliesTo = source.Fields.GetString("appliesto");
            m_pattern = source.Fields.GetString("pattern");
            m_originalPattern = source.Fields.GetString(FieldDefinitions.OriginalPattern.Property);
            m_description = source.Fields.GetString("description");
            m_create = source.Fields.GetString("create");
            m_expressionType = source.Fields.GetString("expressiontype");

            foreach (Element e in worldModel.Elements.GetElements(ElementType.EditorTab))
            {
                if (e.Parent == source)
                {
                    m_tabs.Add(e.Name, new EditorTab(this, worldModel, e));
                }
            }

            foreach (Element e in worldModel.Elements.GetElements(ElementType.EditorControl))
            {
                if (e.Parent == source)
                {
                    m_controls.Add(e.Name, new EditorControl(this, worldModel, e));
                }
            }
        }
Ejemplo n.º 3
0
 public EditableCommandPattern(EditorController controller, EditorCommandPattern pattern, Element parent, string attribute)
 {
     m_pattern = pattern;
     m_controller = controller;
     m_parent = parent;
     m_attribute = attribute;
 }
Ejemplo n.º 4
0
 public EditableScriptData(Element editor)
 {
     DisplayString = editor.Fields.GetString("display");
     Category = editor.Fields.GetString("category");
     CreateString = editor.Fields.GetString("create");
     AdderDisplayString = editor.Fields.GetString("add");
 }
Ejemplo n.º 5
0
 public EditableObjectReference(EditorController controller, Element obj, Element parent, string attribute)
 {
     m_object = obj;
     m_controller = controller;
     m_parent = parent;
     m_attribute = attribute;
 }
Ejemplo n.º 6
0
        public EditorData(Element element, EditorController controller)
        {
            m_element = element;
            m_controller = controller;

            element.Fields.AttributeChanged += Fields_AttributeChanged;
            element.Fields.AttributeChangedSilent += Fields_AttributeChanged;
        }
Ejemplo n.º 7
0
 public void EndSave(GameXmlWriter writer, Element e)
 {
     IObjectSaver saver;
     if (GetSaver(writer, e, out saver))
     {
         saver.EndSave(writer, e);
     }
 }
Ejemplo n.º 8
0
 public override void Save(GameXmlWriter writer, Element e)
 {
     IObjectSaver saver;
     if (GetSaver(writer, e, out saver))
     {
         saver.StartSave(writer, e);
         saver.EndSave(writer, e);
     }
 }
Ejemplo n.º 9
0
        public void Setup()
        {
            m_worldModel = new WorldModel();

            m_original = m_worldModel.GetElementFactory(ElementType.Object).Create("original");
            m_original.Fields.Set(attributeName, attributeValue);
            m_original.Fields.Set(listAttributeName, new QuestList<string>(listAttributeValue));
            m_original.Fields.Resolve(null);
            Assert.AreEqual(attributeValue, m_original.Fields.GetString(attributeName));
            Assert.AreEqual(3, m_original.Fields.GetAsType<QuestList<string>>(listAttributeName).Count);
        }
Ejemplo n.º 10
0
 public override void Save(GameXmlWriter writer, Element e)
 {
     // only save the delegate definition, not the individual implementations - they are just fields on objects
     if (!e.MetaFields[MetaFieldDefinitions.DelegateImplementation])
     {
         writer.WriteStartElement("delegate");
         writer.WriteAttributeString("name", e.Name);
         writer.WriteAttributeString("parameters", string.Join(", ", e.Fields[FieldDefinitions.ParamNames].ToArray()));
         writer.WriteAttributeString("type", e.Fields[FieldDefinitions.ReturnType]);
         writer.WriteEndElement();
     }
 }
Ejemplo n.º 11
0
 public void Save(GameXmlWriter writer, Element element, string attribute, object value)
 {
     if (value == null) return;
     IFieldSaver saver;
     if (TryGetSaver(value.GetType(), out saver))
     {
         saver.Save(writer, element, attribute, value);
     }
     else
     {
         throw new Exception(string.Format("ERROR: No FieldSaver for attribute {0}, type: {1}", attribute, value.GetType().ToString()));
     }
 }
Ejemplo n.º 12
0
        public EditorTab(EditorDefinition parent, WorldModel worldModel, Element source)
        {
            m_controls = new Dictionary<string, IEditorControl>();
            m_caption = source.Fields.GetString("caption");

            foreach (Element e in worldModel.Elements.GetElements(ElementType.EditorControl))
            {
                if (e.Parent == source)
                {
                    m_controls.Add(e.Name, new EditorControl(parent, worldModel, e));
                }
            }
            m_visibilityHelper = new EditorVisibilityHelper(parent, worldModel, source);
        }
Ejemplo n.º 13
0
            public override void Save(GameXmlWriter writer, Element e)
            {
                writer.WriteStartElement("dynamictemplate");
                writer.WriteAttributeString("name", e.Name);

                if (!GameSaver.m_worldModel.EditMode)
                {
                    writer.WriteString(e.Fields[FieldDefinitions.Function].Save());
                }
                else
                {
                    writer.WriteString(e.Fields[FieldDefinitions.Text]);
                }
                writer.WriteEndElement();
            }
Ejemplo n.º 14
0
        public EditorControl(EditorDefinition parent, WorldModel worldModel, Element source)
        {
            m_parent = parent;
            m_worldModel = worldModel;
            m_source = source;
            m_controlType = source.Fields.GetString("controltype");
            m_caption = source.Fields.GetString("caption");
            m_attribute = source.Fields.GetString("attribute");
            if (source.Fields.HasType<int>("height")) m_height = source.Fields.GetAsType<int>("height");
            if (source.Fields.HasType<int>("width")) m_width = source.Fields.GetAsType<int>("width");
            if (source.Fields.HasType<bool>("expand")) m_expand = source.Fields.GetAsType<bool>("expand");
            m_visibilityHelper = new EditorVisibilityHelper(parent, worldModel, source);

            if (source.Fields.HasString("filtergroup"))
            {
                parent.RegisterFilter(source.Fields.GetString("filtergroup"), source.Fields.GetString("filter"), m_attribute);
            }
        }
Ejemplo n.º 15
0
        public EditorVisibilityHelper(EditorDefinition parent, WorldModel worldModel, Element source)
        {
            m_parent = parent;
            m_worldModel = worldModel;
            m_relatedAttribute = source.Fields.GetString("relatedattribute");
            if (m_relatedAttribute != null) m_alwaysVisible = false;
            m_visibleIfRelatedAttributeIsType = source.Fields.GetString("relatedattributedisplaytype");
            m_visibleIfElementInheritsType = source.Fields.GetString("mustinherit");
            m_notVisibleIfElementInheritsType = source.Fields.GetAsType<QuestList<string>>("mustnotinherit");
            if (m_visibleIfElementInheritsType != null || m_notVisibleIfElementInheritsType != null) m_alwaysVisible = false;
            m_filterGroup = source.Fields.GetString("filtergroup");
            m_filter = source.Fields.GetString("filter");
            if (m_filter != null) m_alwaysVisible = false;

            string expression = source.Fields.GetString("onlydisplayif");
            if (expression != null)
            {
                m_visibilityExpression = new Expression<bool>(Utility.ConvertVariablesToFleeFormat(expression), worldModel);
                m_alwaysVisible = false;
            }
        }
Ejemplo n.º 16
0
        public void Setup()
        {
            const string inheritedTypeName = "inherited";
            const string subInheritedTypeName = "subtype";
            const string defaultObject = "defaultobject";

            m_worldModel = new WorldModel();

            m_defaultType = m_worldModel.GetElementFactory(ElementType.ObjectType).Create(defaultObject);
            m_defaultType.Fields.Set(attributeDefinedByDefaultName, attributeDefinedByDefaultValue);
            m_defaultType.Fields.Set(attributeDefinedByDefault2Name, attributeDefinedByDefault2Value);

            m_subType = m_worldModel.GetElementFactory(ElementType.ObjectType).Create(subInheritedTypeName);
            m_subType.Fields.Set(inheritedAttribute2Name, inheritedAttribute2Value);
            m_subType.Fields.Set(attributeDefinedByDefault2Name, attributeDefinedByDefault2OverriddenValue);

            m_objectType = m_worldModel.GetElementFactory(ElementType.ObjectType).Create(inheritedTypeName);
            m_objectType.Fields.Set(inheritedAttributeName, inheritedAttributeValue);
            m_objectType.Fields.AddType(m_subType);

            m_object = m_worldModel.GetElementFactory(ElementType.Object).Create("object");
            m_object.Fields.Resolve(null);
            m_object.Fields.AddType(m_objectType);
        }
Ejemplo n.º 17
0
 public override void Save(GameXmlWriter writer, Element e)
 {
     writer.WriteStartElement("timer");
     writer.WriteAttributeString("name", e.Name);
     base.SaveFields(writer, e);
     writer.WriteEndElement();
 }
Ejemplo n.º 18
0
 protected virtual bool CanSaveTypeName(GameXmlWriter writer, string type, Element e)
 {
     if (writer.Mode == SaveMode.Package)
     {
         if (e.WorldModel.Elements.Get(ElementType.ObjectType, type).MetaFields[MetaFieldDefinitions.EditorLibrary])
         {
             return false;
         }
     }
     return !WorldModel.DefaultTypeNames.ContainsValue(type);
 }
Ejemplo n.º 19
0
            protected void SaveFields(GameXmlWriter writer, Element e)
            {
                foreach (Element includedType in e.Fields.Types)
                {
                    if (CanSaveTypeName(writer, includedType.Name, e))
                    {
                        writer.WriteStartElement("inherit");
                        writer.WriteAttributeString("name", includedType.Name);
                        writer.WriteEndElement();
                    }
                }

                foreach (string attribute in e.Fields.FieldNames)
                {
                    if (CanSaveAttribute(attribute, e))
                    {
                        object value = e.Fields.Get(attribute);
                        m_fieldSaver.Save(writer, e, attribute, value);
                    }
                }
            }
Ejemplo n.º 20
0
 public abstract void Save(GameXmlWriter writer, Element e);
Ejemplo n.º 21
0
 protected virtual bool CanSaveAttribute(string attribute, Element e)
 {
     return !m_ignoreFields.Contains(attribute);
 }
Ejemplo n.º 22
0
        internal bool IsImpliedType(Element element, string attribute, string type)
        {
            string impliedType;
            string elementType;
            if (element.ElemType == ElementType.Object)
            {
                elementType = element.TypeString;
            }
            else
            {
                elementType = element.ElementTypeString;
            }

            if (m_impliedTypes.TryGetValue(GetImpliedTypeKey(elementType, attribute), out impliedType))
            {
                return (type == impliedType);
            }
            return (type == "string");
        }
Ejemplo n.º 23
0
 private bool CanSave(Element e)
 {
     switch (m_mode)
     {
         case SaveMode.SavedGame:
             return true;
         case SaveMode.Editor:
             return !e.MetaFields[MetaFieldDefinitions.Library];
         case SaveMode.Package:
             if (e.ElemType == ElementType.IncludedLibrary) return false;
             if (e.MetaFields[MetaFieldDefinitions.EditorLibrary]) return false;
             return true;
         default:
             throw new Exception("SaveMode not implemented");
     }
 }
Ejemplo n.º 24
0
 public override void Save(GameXmlWriter writer, Element e)
 {
     // Resource elements should never need to be saved. They can only
     // be defined by the Core library and are there for information only
     // (specifying which additional files to include in a .quest file)
 }
Ejemplo n.º 25
0
        public bool IsVisible(IEditorData data)
        {
            if (m_alwaysVisible) return true;

            if (m_visibilityExpression != null)
            {
                // evaluate <onlydisplayif> expression, with "this" as the current element
                Scripts.Context context = new Scripts.Context();
                context.Parameters = new Scripts.Parameters("this", m_worldModel.Elements.Get(data.Name));
                bool result = m_visibilityExpression.Execute(context);
                if (!result) return false;
            }

            if (m_relatedAttribute != null)
            {
                object relatedAttributeValue = data.GetAttribute(m_relatedAttribute);
                if (relatedAttributeValue is IDataWrapper) relatedAttributeValue = ((IDataWrapper)relatedAttributeValue).GetUnderlyingValue();

                string relatedAttributeType = relatedAttributeValue == null ? "null" : WorldModel.ConvertTypeToTypeName(relatedAttributeValue.GetType());
                return relatedAttributeType == m_visibleIfRelatedAttributeIsType;
            }

            if (m_visibleIfElementInheritsType != null)
            {
                if (m_visibleIfElementInheritsTypeElement == null)
                {
                    m_visibleIfElementInheritsTypeElement = m_worldModel.Elements.Get(ElementType.ObjectType, m_visibleIfElementInheritsType);
                }
                return m_worldModel.Elements.Get(data.Name).Fields.InheritsType(m_visibleIfElementInheritsTypeElement);
            }

            if (m_notVisibleIfElementInheritsType != null)
            {
                if (m_notVisibleIfElementInheritsTypeElement == null)
                {
                    // convert "mustnotinherit" type names list into a list of type elements
                    m_notVisibleIfElementInheritsTypeElement = new List<Element>(
                        m_notVisibleIfElementInheritsType.Select(t => m_worldModel.Elements.Get(ElementType.ObjectType, t))
                    );
                }

                // if the element does inherit any of the "forbidden" types, then this control is not visible

                Element element = m_worldModel.Elements.Get(data.Name);

                foreach (Element forbiddenType in m_notVisibleIfElementInheritsTypeElement)
                {
                    if (element.Fields.InheritsType(forbiddenType))
                    {
                        return false;
                    }
                }

                return true;
            }

            if (m_filterGroup != null)
            {
                // This control is visible if the named filtergroup's current filter selection is this control's filter.
                string selectedFilter = data.GetSelectedFilter(m_filterGroup);

                // Or, if the named filtergroup's current filter selection is not set, infer the current filter value
                // based on which attribute is populated for this data.
                if (selectedFilter == null) selectedFilter = m_parent.GetDefaultFilterName(m_filterGroup, data);

                return (selectedFilter == m_filter);
            }

            return false;
        }
Ejemplo n.º 26
0
 private void SaveElementAndChildren(GameXmlWriter writer, WorldModel worldModel, Element walkThrough)
 {
     m_walkthroughSaver.StartSave(writer, walkThrough);
     foreach (Element child in worldModel.Elements.GetElements(ElementType.Walkthrough).Where(e => e.Parent == walkThrough))
     {
         SaveElementAndChildren(writer, worldModel, child);
     }
     m_walkthroughSaver.EndSave(writer, walkThrough);
 }
Ejemplo n.º 27
0
 public override void Save(GameXmlWriter writer, Element e)
 {
     writer.WriteStartElement("template");
     writer.WriteAttributeString("name", e.Fields[FieldDefinitions.TemplateName]);
     writer.WriteString(e.Fields[FieldDefinitions.Text]);
     writer.WriteEndElement();
 }
Ejemplo n.º 28
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 = GameSaver.GetIndentChars(writer.IndentLevel + 1, writer.IndentChars);

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

                    writer.WriteStartElement("steps");
                    writer.WriteString(result);
                    writer.WriteEndElement();
                }
            }
Ejemplo n.º 29
0
 public override void Save(GameXmlWriter writer, Element e)
 {
     StartSave(writer, e);
     EndSave(writer, e);
 }
Ejemplo n.º 30
0
 public void EndSave(GameXmlWriter writer, Element e)
 {
     writer.WriteEndElement();
 }