public static TmxProperties GetPropertiesWithTypeDefaults(TmxHasProperties hasProperties, TmxObjectTypes objectTypes) { TmxProperties tmxProperties = new TmxProperties(); string key = null; if (hasProperties is TmxObject) { key = (hasProperties as TmxObject).Type; } TmxObjectType valueOrNull = objectTypes.GetValueOrNull(key); if (valueOrNull != null) { foreach (TmxObjectTypeProperty value in valueOrNull.Properties.Values) { tmxProperties.PropertyMap[value.Name] = new TmxProperty { Name = value.Name, Type = value.Type, Value = value.Default }; } } foreach (TmxProperty value2 in hasProperties.Properties.PropertyMap.Values) { tmxProperties.PropertyMap[value2.Name] = value2; } return(tmxProperties); }
public static TmxObjectType FromXml(XElement xml) { TmxObjectType tmxObjectType = new TmxObjectType(); tmxObjectType.Name = TmxHelper.GetAttributeAsString(xml, "name", ""); tmxObjectType.Color = TmxHelper.GetAttributeAsColor(xml, "color", Color.Gray); tmxObjectType.Properties = TmxObjectTypeProperty.FromObjectTypeXml(xml); return(tmxObjectType); }
public static TmxObjectType FromXml(XElement xml) { TmxObjectType tmxObjectType = new TmxObjectType(); tmxObjectType.Name = TmxHelper.GetAttributeAsString(xml, "name", ""); tmxObjectType.Color = TmxHelper.GetAttributeAsColor(xml, "color", Color.Gray); tmxObjectType.Properties = TmxObjectTypeProperty.FromObjectTypeXml(xml); return tmxObjectType; }
public static TmxObjectTypes FromXmlFile(string xmlPath) { TmxObjectTypes tmxObjectTypes = new TmxObjectTypes(); foreach (XElement item in XDocument.Load(xmlPath).Element("objecttypes").Elements("objecttype")) { TmxObjectType tmxObjectType = TmxObjectType.FromXml(item); tmxObjectTypes.TmxObjectTypeMapping[tmxObjectType.Name] = tmxObjectType; } return(tmxObjectTypes); }
public static TmxObjectTypes FromXmlFile(string xmlPath) { TmxObjectTypes xmlObjectTypes = new TmxObjectTypes(); XDocument doc = XDocument.Load(xmlPath); foreach (var xml in doc.Element("objecttypes").Elements("objecttype")) { TmxObjectType tmxObjectType = TmxObjectType.FromXml(xml); xmlObjectTypes.TmxObjectTypeMapping[tmxObjectType.Name] = tmxObjectType; } return(xmlObjectTypes); }
private void DrawColliders(Graphics g) { for (int l = 0; l < this.tmxMap.Layers.Count; ++l) { TmxLayer layer = this.tmxMap.Layers[l]; if (layer.Visible == true && layer.Ignore != TmxLayer.IgnoreSettings.Collision) { foreach (TmxLayer collisionLayer in layer.CollisionLayers) { TmxObjectType type = this.tmxMap.ObjectTypes.GetValueOrDefault(collisionLayer.Name); Color lineColor = type.Color; Color polyColor = Color.FromArgb(128, lineColor); DrawLayerColliders(g, collisionLayer, polyColor, lineColor); } } } }
public static TmxProperties GetPropertiesWithTypeDefaults(TmxHasProperties hasProperties, TmxObjectTypes objectTypes) { TmxProperties tmxProperties = new TmxProperties(); // Fill in all the default properties first // (Note: At the moment, only TmxObject has default properties it inherits from TmxObjectType) string objectTypeName = null; if (hasProperties is TmxObject) { TmxObject tmxObject = hasProperties as TmxObject; objectTypeName = tmxObject.Type; } else if (hasProperties is TmxLayer) { TmxLayer tmxLayer = hasProperties as TmxLayer; objectTypeName = tmxLayer.Name; } // If an object type has been found then copy over all the default values for properties TmxObjectType tmxObjectType = objectTypes.GetValueOrNull(objectTypeName); if (tmxObjectType != null) { foreach (TmxObjectTypeProperty tmxTypeProp in tmxObjectType.Properties.Values) { tmxProperties.PropertyMap[tmxTypeProp.Name] = new TmxProperty() { Name = tmxTypeProp.Name, Type = tmxTypeProp.Type, Value = tmxTypeProp.Default }; } } // Now add all the object properties (which may override some of the default properties) foreach (TmxProperty tmxProp in hasProperties.Properties.PropertyMap.Values) { tmxProperties.PropertyMap[tmxProp.Name] = tmxProp; } return(tmxProperties); }