예제 #1
0
        // Load an Object Type Xml file for this map's objects to reference
        public void LoadObjectTypeXml(string xmlPath)
        {
            if (String.IsNullOrEmpty(xmlPath))
            {
                Logger.WriteInfo("Object Type XML file is not being used.");
                return;
            }

            Logger.WriteInfo("Loading Object Type Xml file: '{0}'", xmlPath);

            try
            {
                this.ObjectTypes = TmxObjectTypes.FromXmlFile(xmlPath);
            }
            catch (FileNotFoundException)
            {
                Logger.WriteError("Object Type Xml file was not found: {0}", xmlPath);
                this.ObjectTypes = new TmxObjectTypes();
            }
            catch (Exception e)
            {
                Logger.WriteError("Error parsing Object Type Xml file: {0}\n{1}", xmlPath, e.Message);
                Logger.WriteError("Stack:\n{0}", e.StackTrace);
                this.ObjectTypes = new TmxObjectTypes();
            }

            Logger.WriteInfo("Tiled Object Type count = {0}", this.ObjectTypes.TmxObjectTypeMapping.Count());
        }
예제 #2
0
        // Load an Object Type Xml file for this map's objects to reference
        public void LoadObjectTypeXml(string xmlPath)
        {
            if (String.IsNullOrEmpty(xmlPath))
            {
                Program.WriteLine("No Object Type Xml file loaded.");
                this.ObjectTypes = new TmxObjectTypes();
            }
            else
            {
                Program.WriteLine("Loading Object Type Xml file: '{0}'", xmlPath);

                try
                {
                    this.ObjectTypes = TmxObjectTypes.FromXmlFile(xmlPath);
                }
                catch (FileNotFoundException)
                {
                    Program.WriteError("Object Type Xml file was not found: {0}", xmlPath);
                }
                catch (Exception e)
                {
                    Program.WriteError("Error parsing Object Type Xml file: {0}\n{1}", xmlPath, e.Message);
                }
            }

            Program.WriteLine("Tiled Object Type count = {0}", this.ObjectTypes.TmxObjectTypeMapping.Count());
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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;
        }
예제 #6
0
        // Load an Object Type Xml file for this map's objects to reference
        public void LoadObjectTypeXml(string xmlPath)
        {
            Logger.WriteLine("Loading Object Type Xml file: '{0}'", xmlPath);

            try
            {
                this.ObjectTypes = TmxObjectTypes.FromXmlFile(xmlPath);
            }
            catch (FileNotFoundException)
            {
                Logger.WriteError("Object Type Xml file was not found: {0}", xmlPath);
                this.ObjectTypes = new TmxObjectTypes();
            }
            catch (Exception e)
            {
                Logger.WriteError("Error parsing Object Type Xml file: {0}\n{1}", xmlPath, e.Message);
                this.ObjectTypes = new TmxObjectTypes();
            }

            Logger.WriteLine("Tiled Object Type count = {0}", this.ObjectTypes.TmxObjectTypeMapping.Count());
        }
예제 #7
0
 public void ClearObjectTypeXml()
 {
     Logger.WriteLine("Removing Object Types from map.");
     this.ObjectTypes = new TmxObjectTypes();
 }
예제 #8
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;
            }

            // 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);
        }
예제 #9
0
        // Load an Object Type Xml file for this map's objects to reference
        public void LoadObjectTypeXml(string xmlPath)
        {
            if (String.IsNullOrEmpty(xmlPath))
            {
                Program.WriteLine("No Object Type Xml file loaded.");
                this.ObjectTypes = new TmxObjectTypes();
            }
            else
            {
                Program.WriteLine("Loading Object Type Xml file: '{0}'", xmlPath);

                try
                {
                    this.ObjectTypes = TmxObjectTypes.FromXmlFile(xmlPath);
                }
                catch (FileNotFoundException)
                {
                    Program.WriteError("Object Type Xml file was not found: {0}", xmlPath);
                }
                catch (Exception e)
                {
                    Program.WriteError("Error parsing Object Type Xml file: {0}\n{1}", xmlPath, e.Message);
                }
            }

            Program.WriteLine("Tiled Object Type count = {0}", this.ObjectTypes.TmxObjectTypeMapping.Count());
        }
예제 #10
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);
        }
예제 #11
0
 public void ClearObjectTypeXml()
 {
     Logger.WriteInfo("Removing Object Types from map.");
     ObjectTypes = new TmxObjectTypes();
 }