示例#1
0
        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);
        }
示例#2
0
        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);
        }