Exemplo n.º 1
0
 public EditableCommandPattern(EditorController controller, EditorCommandPattern pattern, Element parent, string attribute)
 {
     m_pattern = pattern;
     m_controller = controller;
     m_parent = parent;
     m_attribute = attribute;
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
0
 public override void Save(GameXmlWriter writer, Element e)
 {
     writer.WriteStartElement("type");
     writer.WriteAttributeString("name", e.Name);
     SaveFields(writer, e);
     writer.WriteEndElement();
 }
Exemplo n.º 4
0
 public EditableObjectReference(EditorController controller, Element obj, Element parent, string attribute)
 {
     m_object = obj;
     m_controller = controller;
     m_parent = parent;
     m_attribute = attribute;
 }
Exemplo n.º 5
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;

                // remove old element from ordered elements list
                m_elementsLists[t].Remove(m_elements[t][key]);
            }

            m_allElements[key] = e;
            m_elements[t][key] = e;
            m_elementsLists[t].Add(e);

            e.Fields.NameChanged += ElementNameChanged;
        }
Exemplo n.º 6
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));
                }
            }
        }
Exemplo n.º 7
0
 public Element CreateObject(string name, Element parent, ObjectType type)
 {
     Element result = CreateElement(ElementType.Object, name);
     result.Parent = parent;
     result.Type = type;
     result.Fields.AddTypeName(m_defaultTypeNames[type]);
     return result;
 }
Exemplo n.º 8
0
 public string GetPostElementScript(Element element)
 {
     if (!postElementScript.ContainsKey(element))
     {
         return string.Empty;
     }
     return postElementScript[element];
 }
Exemplo n.º 9
0
        public EditorData(Element element, EditorController controller)
        {
            m_element = element;
            m_controller = controller;

            element.Fields.AttributeChanged += Fields_AttributeChanged;
            element.Fields.AttributeChangedSilent += Fields_AttributeChanged;
        }
Exemplo n.º 10
0
        public void Setup()
        {
            m_worldModel = new WorldModel();

            a = m_worldModel.GetElementFactory(ElementType.Object).Create("a");
            b = m_worldModel.GetElementFactory(ElementType.Object).Create("b");
            c = m_worldModel.GetElementFactory(ElementType.Object).Create("c");
        }
Exemplo n.º 11
0
 public Element CreateElement(ElementType type, string name)
 {
     string mappedName = m_loader.NameMapper.AddToMap(name);
     Element result = new Element(type, m_loader);
     result.Name = name;
     result.MetaFields[MetaFieldDefinitions.MappedName] = mappedName;
     m_loader.AddElement(result);
     return result;
 }
Exemplo n.º 12
0
 public void Save(Element e, GameWriter writer)
 {
     string paramNames = string.Join(", ", e.Fields[FieldDefinitions.ParamNames]);
     paramNames = Utility.ReplaceReservedVariableNames(paramNames);
     writer.AddLine("function " + e.Name.Replace(" ", Utility.SpaceReplacementString) + "(" + paramNames + ")");
     writer.AddLine("{");
     writer.AddLine(e.Fields[FieldDefinitions.Script].Save());
     writer.AddLine("}");
 }
Exemplo n.º 13
0
        public void AddPostElementScript(Element element, string script)
        {
            string result = string.Empty;
            if (postElementScript.ContainsKey(element))
            {
                result = postElementScript[element] + Environment.NewLine;
            }
            result += script;

            postElementScript[element] = result;
        }
Exemplo n.º 14
0
        public void Setup()
        {
            m_worldModel = new WorldModel();

            m_object = m_worldModel.GetElementFactory(ElementType.Object).Create("object");
            var list = new QuestList<object> {"string1"};
            var dictionary = new QuestDictionary<object> {{"key1", "nested string"}};
            list.Add(dictionary);
            m_object.Fields.Set("list", list);
            m_object.Fields.Resolve(null);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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();
     }
 }
Exemplo n.º 17
0
 public EditableScriptData(Element editor, WorldModel worldModel)
 {
     DisplayString = editor.Fields.GetString("display");
     Category = editor.Fields.GetString("category");
     CreateString = editor.Fields.GetString("create");
     AdderDisplayString = editor.Fields.GetString("add");
     IsVisibleInSimpleMode = !editor.Fields.GetAsType<bool>("advanced");
     IsDesktopOnly = editor.Fields.GetAsType<bool>("desktop");
     CommonButton = editor.Fields.GetString("common");
     var expression = editor.Fields.GetString("onlydisplayif");
     if (expression != null)
     {
         m_visibilityExpression = new Expression<bool>(Utility.ConvertVariablesToFleeFormat(expression), new ScriptContext(worldModel, true));
     }
 }
Exemplo n.º 18
0
            private void SaveObjectAndChildren(GameXmlWriter writer, IEnumerable<Element> allObjects, Element e, ObjectSaver saver)
            {
                saver.StartSave(writer, e);
                IEnumerable<Element> orderedChildren = from child in allObjects
                                                       where child.Parent == e
                                                       orderby child.MetaFields[MetaFieldDefinitions.SortIndex]
                                                       select child;

                foreach (Element child in orderedChildren)
                {
                    SaveObjectAndChildren(writer, allObjects, child, saver);
                }

                saver.EndSave(writer, e);
            }
Exemplo n.º 19
0
        public EditorTab(EditorDefinition parent, WorldModel worldModel, Element source)
        {
            m_controls = new Dictionary<string, IEditorControl>();
            m_caption = source.Fields.GetString("caption");
            IsTabVisibleInSimpleMode = !source.Fields.GetAsType<bool>("advanced");

            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);
            m_source = source;
        }
Exemplo n.º 20
0
 public override void Save(GameXmlWriter writer, Element e)
 {
     writer.WriteStartElement("function");
     writer.WriteAttributeString("name", e.Name);
     if (e.Fields[FieldDefinitions.ParamNames] != null && e.Fields[FieldDefinitions.ParamNames].Count > 0)
     {
         writer.WriteAttributeString("parameters", string.Join(", ", e.Fields[FieldDefinitions.ParamNames].ToArray()));
     }
     if (!string.IsNullOrEmpty(e.Fields[FieldDefinitions.ReturnType]))
     {
         writer.WriteAttributeString("type", e.Fields[FieldDefinitions.ReturnType]);
     }
     if (e.Fields[FieldDefinitions.Script] != null)
     {
         writer.WriteString(GameSaver.SaveScript(writer, e.Fields[FieldDefinitions.Script], 0));
     }
     writer.WriteEndElement();
 }
Exemplo n.º 21
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);
            IsControlVisibleInSimpleMode = !source.Fields.GetAsType<bool>("advanced");
            m_id = source.Name;

            if (source.Fields.HasString("filtergroup"))
            {
                parent.RegisterFilter(source.Fields.GetString("filtergroup"), source.Fields.GetString("filter"), m_attribute);
            }
        }
Exemplo n.º 22
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.GetAsType<QuestList<string>>("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), new TextAdventures.Quest.Scripts.ScriptContext(worldModel, true));
                m_alwaysVisible = false;
            }
        }
Exemplo n.º 23
0
        protected void SaveElementFields(string name, Element e, GameWriter writer)
        {
            string mappedName = e.MetaFields[MetaFieldDefinitions.MappedName];

            writer.AddLine(mappedName + " = {");
            e.Fields.Set("_js_name", mappedName);
            e.Fields.Set("_types", new QuestList<string>(e.Fields.TypeNames));

            int count = 0;
            int length = e.Fields.FieldNames.Count();

            foreach (string field in e.Fields.FieldNames)
            {
                count++;
                object value = ConvertField(e, field, e.Fields.Get(field));
                fieldSaver.Save(writer, e, field, value, count == length);
            }

            writer.AddLine("};");
            writer.AddLine(string.Format("elementsNameMap[\"{0}\"] = {1};", e.Name, e.MetaFields[MetaFieldDefinitions.MappedName]));
            writer.MarkElementWritten(e);
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
0
        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());
                    }
                    else
                    {
                        result.Add(step);
                    }
                }
                return result;
            }
            return value;
        }
Exemplo n.º 26
0
 public void RunScript(IScript script, Parameters parameters, Element thisElement)
 {
     RunScript(script, parameters, false, thisElement);
 }
Exemplo n.º 27
0
 /// <summary>
 /// Use this version of RunScript when executing an object action. Set thisElement to the object whose action it is.
 /// </summary>
 /// <param name="script"></param>
 /// <param name="thisElement"></param>
 public void RunScript(IScript script, Element thisElement)
 {
     RunScript(script, null, false, thisElement);
 }
Exemplo n.º 28
0
 public object RunDelegateScript(IScript script, Parameters parameters, Element thisElement)
 {
     return RunScript(script, parameters, true, thisElement);
 }
Exemplo n.º 29
0
 public bool ObjectContains(Element parent, Element searchObj)
 {
     if (searchObj.Parent == null) return false;
     if (searchObj.Parent == parent) return true;
     return ObjectContains(parent, searchObj.Parent);
 }
Exemplo n.º 30
0
 internal ElementRefreshEventArgs(Element element)
 {
     Element = element;
 }