private Element AddDelegate(XmlReader reader) { Dictionary <string, string> data = GameLoader.GetRequiredAttributes(reader, RequiredAttributes); Element del = WorldModel.AddDelegate(data["name"]); SetupProcedure(del, data["type"], GameLoader.GetTemplateContents(reader), data["name"], data["parameters"]); return(del); }
private Element AddProcedure(XmlReader reader) { Dictionary <string, string> data = GameLoader.GetRequiredAttributes(reader, RequiredAttributes); Element proc = ElementFactory.CreateFunction(data["name"]); SetupProcedure(proc, data["type"], GameLoader.GetTemplateContents(reader), data["name"], data["parameters"]); return(proc); }
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); }