private object extractValue(IAttributeLoader attributeLoader, XmlNode node) { switch (node.Name) { case "bool": bool b = bool.Parse(node.InnerText); return(b); case "string": return(node.InnerText); case "int": int i = int.Parse(node.InnerText); return(i); case "float": float f = float.Parse(node.InnerText, NumberStyles.Number, CultureInfo.InvariantCulture.NumberFormat); return(f); case "double": double d = double.Parse(node.InnerText, NumberStyles.Number, CultureInfo.InvariantCulture.NumberFormat); return(d); default: return(attributeLoader.Load(node)); } }
internal void Load(IAttributeLoader attributeLoader, string xmlFile) { XmlDocument xml = new XmlDocument(); xml.Load(xmlFile); XmlNode behaviorNode = xml.GetElementsByTagName("behaviors")[0]; foreach (XmlNode node in behaviorNode.ChildNodes) { Type t = System.Type.GetType(typeof(IBehavior).Namespace + "." + node.Name); object[] param = new object[] { this }; IBehavior b = Activator.CreateInstance(t, param) as IBehavior; AddBehavior(b); } XmlNode attributeNode = xml.GetElementsByTagName("attributes")[0]; foreach (XmlNode node in attributeNode.ChildNodes) { if (node.Attributes != null) // used to handle comment nodes { if (!HasAttribute(node.Attributes["key"].Value)) { continue; } dynamic value = extractValue(attributeLoader, node); this[node.Attributes["key"].Value] = value; } } }
public CollectionLoader(ICollectionRepo collectionRepo, ICollectionRelationshipRepo collectionRelationshipRepo, IAttributeLoader attributeLoader, IImageLoader imageLoader, IItemLoader itemLoader) { _collectionRelationshipRepo = collectionRelationshipRepo; _collectionRepo = collectionRepo; _attributeLoader = attributeLoader; _imageLoader = imageLoader; _itemLoader = itemLoader; }
private void AddLoader(IAttributeLoader loader, LoadMode mode) { if (loader.SupportsMode(mode)) { m_attributeLoaders.Add(loader.AppliesTo, loader); loader.GameLoader = this; } }
public EntityFactory(GameLogic game) { this.game = game; this.eventManager = game.EventManager; attributeLoader = new DefaultAttributeLoader(game.ResourceManager); }
private void AddLoader(IAttributeLoader loader) { m_attributeLoaders.Add(loader.AppliesTo, loader); loader.GameLoader = this; }
public DependencyLoader(IAttributeLoader attributeLoader) { AttributeLoader = attributeLoader; }
public ItemLoader(IItemRepo repo, IAttributeLoader attributeLoader, IImageLoader imageLoader) { _itemRepo = repo; _attributeLoader = attributeLoader; _imageLoader = imageLoader; }