public void TestListExtension_InheritingIndirectly() { WorldModel worldModel = new WorldModel(); Element type1 = worldModel.GetElementFactory(ElementType.ObjectType).Create("type1"); type1.Fields.AddFieldExtension("listfield", new QuestList <string>(new[] { "a" }, true)); Element type2 = worldModel.GetElementFactory(ElementType.ObjectType).Create("type2"); type2.Fields.AddType(type1); type2.Fields.AddFieldExtension("listfield", new QuestList <string>(new[] { "b" }, true)); Element type3 = worldModel.GetElementFactory(ElementType.ObjectType).Create("type3"); type3.Fields.AddType(type2); Element obj = worldModel.GetElementFactory(ElementType.Object).Create("object"); obj.Fields.AddType(type3); var result = obj.Fields.GetAsType <QuestList <string> >("listfield"); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains("a")); Assert.IsTrue(result.Contains("b")); }
internal Element AddTemplate(string templateName, string text, bool isCommandTemplate, bool isBaseTemplate = false) { // if a template is marked as IsBaseTemplate, it's from the base .aslx file so shouldn't be overwritten // by an equivalent library definition Element existingTemplate; if (m_templateLookup.TryGetValue(templateName, out existingTemplate)) { if (existingTemplate.Fields[FieldDefinitions.IsBaseTemplate]) { return(null); } } string elementName = m_worldModel.GetUniqueID("template"); Element template = m_worldModel.GetElementFactory(ElementType.Template).Create(elementName); template.Fields[FieldDefinitions.TemplateName] = templateName; template.Fields[FieldDefinitions.Text] = text; template.Fields[FieldDefinitions.Anonymous] = true; template.Fields[FieldDefinitions.IsBaseTemplate] = isBaseTemplate; if (isCommandTemplate) { template.Fields[FieldDefinitions.IsVerb] = true; } m_templateLookup[templateName] = template; return(template); }
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"); }
public void Setup() { m_worldModel = new WorldModel(); m_object = m_worldModel.GetElementFactory(ElementType.Object).Create("object"); m_object.Fields.Set(attributeName, attributeValue); m_object.Fields.Set(intAttributeName, intAttributeValue); m_child = m_worldModel.GetElementFactory(ElementType.Object).Create("child"); m_child.Parent = m_object; m_child.Fields.Set(attributeName, childAttributeValue); }
public void Save(string html) { var element = m_worldModel.Elements.GetSingle(ElementType.Output) ?? m_worldModel.GetElementFactory(ElementType.Output).Create(); element.Fields.Set("html", html); }
protected override object LoadInternal(string file) { Element include = WorldModel.GetElementFactory(ElementType.IncludedLibrary).Create(); include.Fields[FieldDefinitions.Filename] = file; include.Fields[FieldDefinitions.Anonymous] = true; return(include); }
protected override object LoadInternal(string element, string property, string type) { Element e = WorldModel.GetElementFactory(ElementType.ImpliedType).Create(); e.Fields[FieldDefinitions.Element] = element; e.Fields[FieldDefinitions.Property] = property; e.Fields[FieldDefinitions.Type] = type; return(e); }
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); }
public void Save(string html) { Element element = m_worldModel.Elements.GetSingle(ElementType.Output); if (element == null) { element = m_worldModel.GetElementFactory(ElementType.Output).Create(); } element.Fields.Set("text", m_text.ToString()); }
public override object Load(XmlReader reader, ref Element current) { Element resourceRef = WorldModel.GetElementFactory(ElementType.Resource).Create(); resourceRef.Fields[FieldDefinitions.Anonymous] = true; string file = GameLoader.GetTemplateAttribute(reader, "src"); resourceRef.Fields[FieldDefinitions.Src] = file; return(resourceRef); }
public void Setup() { m_worldModel = new WorldModel(); // a // - b // - c // - d // - e // f Element a = m_worldModel.GetElementFactory(ElementType.Object).Create("a"); Element b = m_worldModel.GetElementFactory(ElementType.Object).Create("b"); b.Parent = a; Element c = m_worldModel.GetElementFactory(ElementType.Object).Create("c"); c.Parent = b; Element d = m_worldModel.GetElementFactory(ElementType.Object).Create("d"); d.Parent = b; Element e = m_worldModel.GetElementFactory(ElementType.Object).Create("e"); e.Parent = a; Element f = m_worldModel.GetElementFactory(ElementType.Object).Create("f"); }
public override object Load(XmlReader reader, ref Element current) { string name = reader.GetAttribute("name"); if (string.IsNullOrEmpty(name)) { name = WorldModel.GetUniqueID(IDPrefix); } Element newElement = WorldModel.GetElementFactory(CreateElementType).Create(name); newElement.Parent = current; return(newElement); }
public override void Execute(Context c) { string elementName = m_expr.Execute(c); Element element = m_worldModel.Elements.Get(elementName); if (element.ElemType == ElementType.Object || element.ElemType == ElementType.Timer) { m_worldModel.GetElementFactory(element.ElemType).DestroyElement(elementName); } else { throw new InvalidOperationException(string.Format("Unable to destroy element of type {0}", element.ElemType)); } }
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); }
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); }
public void TestObjectCreationUndo() { m_worldModel.UndoLogger.StartTransaction("Create new object"); m_worldModel.GetElementFactory(ElementType.Object).Create("newobj"); m_worldModel.UndoLogger.EndTransaction(); // There should be 3 elements now - game, object, newobj Assert.AreEqual(3, m_worldModel.Elements.GetElements(ElementType.Object).Count()); m_worldModel.UndoLogger.Undo(); // Now we should have 2 elements again Assert.AreEqual(2, m_worldModel.Elements.GetElements(ElementType.Object).Count()); }
public Element Clone(Func <Element, bool> canCloneChild) { Element newElement = m_worldModel.GetElementFactory(m_elemType).CloneElement(this, m_worldModel.GetUniqueElementName(Name)); if (this.MetaFields[MetaFieldDefinitions.Library]) { newElement.MetaFields[MetaFieldDefinitions.Library] = false; newElement.MetaFields[MetaFieldDefinitions.Filename] = null; } // Pre-fetch all children of this element var children = m_worldModel.Elements.GetDirectChildren(this).ToList(); foreach (Element child in children.Where(e => canCloneChild(e))) { Element cloneChild = child.Clone(); cloneChild.Parent = newElement; } return(newElement); }
public override object Load(XmlReader reader, ref Element current) { Element jsRef = WorldModel.GetElementFactory(ElementType.Javascript).Create(); jsRef.Fields[FieldDefinitions.Anonymous] = true; string file = GameLoader.GetTemplateAttribute(reader, "src"); if (file.Length == 0) { return(null); } if (WorldModel.Version == WorldModelVersion.v500) { // Quest 5.0 would incorrectly save a full path name. We only want the filename. file = System.IO.Path.GetFileName(file); } jsRef.Fields[FieldDefinitions.Src] = file; return(jsRef); }
public void TestCloneElementWithChildren() { // Create a child object of the original const string childAttrName = "childattribute"; const string childAttrValue = "childvalue"; Element child = m_worldModel.GetElementFactory(ElementType.Object).Create("child"); child.Fields.Set(childAttrName, childAttrValue); child.Parent = m_original; int originalElementCount = m_worldModel.Elements.Count(ElementType.Object); // Clone the original object. The cloned object should have a cloned child too. m_worldModel.UndoLogger.StartTransaction("Create clone"); Element clone = m_original.Clone(); m_worldModel.UndoLogger.EndTransaction(); // We should now have 2 more objects Assert.AreEqual(originalElementCount + 2, m_worldModel.Elements.Count(ElementType.Object)); List <Element> cloneChildren = new List <Element>(m_worldModel.Elements.GetChildElements(clone)); List <Element> originalChildren = new List <Element>(m_worldModel.Elements.GetChildElements(m_original)); // Check the original and the clone now each have one child Assert.AreEqual(1, cloneChildren.Count); Assert.AreEqual(1, originalChildren.Count); // Check the children are not the same, but that the cloned child has the correct attributes Assert.AreNotSame(originalChildren[0], cloneChildren[0]); Assert.AreNotEqual(originalChildren[0].Name, cloneChildren[0].Name); Assert.AreSame(child, originalChildren[0]); Assert.AreEqual("child", originalChildren[0].Name); Assert.AreEqual("child1", cloneChildren[0].Name); Assert.AreEqual(childAttrValue, cloneChildren[0].Fields.GetString(childAttrName)); // Now undo, and verify we have the original number of objects again m_worldModel.UndoLogger.Undo(); Assert.AreEqual(originalElementCount, m_worldModel.Elements.Count(ElementType.Object)); }
public override void Execute(Context c) { m_worldModel.GetElementFactory(ElementType.Timer).Create(m_expr.Execute(c)); }
public override object Load(XmlReader reader, ref Element current) { Element newElement = WorldModel.GetElementFactory(ElementType.ObjectType).Create(reader.GetAttribute("name")); return(newElement); }
public override object Load(XmlReader reader, ref Element current) { string attribute = reader.Name; if (attribute == "attr") { attribute = reader.GetAttribute("name"); } string type = reader.GetAttribute("type"); WorldModel.AddAttributeName(attribute); if (type == null) { string currentElementType = current.Fields.GetString("type"); if (string.IsNullOrEmpty(currentElementType)) { // the type property is the object type, so is not set for other element types. currentElementType = current.Fields.GetString("elementtype"); } type = GameLoader.m_implicitTypes.Get(currentElementType, attribute); } // map old to new type names if necessary (but not in included library files) if (type != null && WorldModel.Version <= WorldModelVersion.v530 && !current.MetaFields[MetaFieldDefinitions.Library] && s_legacyTypeMappings.ContainsKey(type)) { type = s_legacyTypeMappings[type]; } if (type != null && GameLoader.ExtendedAttributeLoaders.ContainsKey(type)) { GameLoader.ExtendedAttributeLoaders[type].Load(reader, current); } else { string value; try { value = GameLoader.GetTemplateContents(reader); } catch (XmlException) { RaiseError(string.Format("Error loading XML data for '{0}.{1}' - ensure that it contains no nested XML", current.Name, attribute)); return(null); } if (type == null) { if (value.Length > 0) { type = "string"; } else { type = "boolean"; } } if (GameLoader.AttributeLoaders.ContainsKey(type)) { GameLoader.AttributeLoaders[type].Load(current, attribute, value); } else { Element del; if (WorldModel.Elements.TryGetValue(ElementType.Delegate, type, out del)) { Element proc = WorldModel.GetElementFactory(ElementType.Delegate).Create(); proc.MetaFields[MetaFieldDefinitions.DelegateImplementation] = true; proc.Fields.LazyFields.AddScript(FieldDefinitions.Script.Property, value); current.Fields.Set(attribute, new DelegateImplementation(type, del, proc)); } else { RaiseError(string.Format("Unrecognised attribute type '{0}' in '{1}.{2}'", type, current.Name, attribute)); } } } return(null); }