]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/Map.cs
Player inventory.
[chaz/carfire] / CarFire / CarFire / CarFire / Map.cs
index 93dc5ef6ba181c1f678298bf79015a0c62d6c118..0e66b139221bf27d1206517e32461d3993fa879c 100644 (file)
@@ -22,29 +22,6 @@ namespace CarFire
         // DEBUG: Tilesets not implemented at all.\r
         public static Texture2D DefaultTile;\r
 \r
-        #region Public Exceptions\r
-\r
-        /// <summary>\r
-        /// This exception is thrown during the loading of a map if any\r
-        /// part of the map file is inconsistent with the expected format\r
-        /// and order.\r
-        /// </summary>\r
-        public class RuntimeException : System.ApplicationException\r
-        {\r
-            public RuntimeException() { }\r
-\r
-            public RuntimeException(string message) :\r
-                base(message) { }\r
-\r
-            public RuntimeException(string message, System.Exception inner) :\r
-                base(message, inner) { }\r
-\r
-            protected RuntimeException(SerializationInfo info, StreamingContext context) :\r
-                base(info, context) { }\r
-        }\r
-\r
-        #endregion\r
-\r
 \r
         #region Public Constants\r
 \r
@@ -277,21 +254,23 @@ namespace CarFire
         /// Get all the entities loaded from the map file.  Exceptions could be\r
         /// thrown if there are entities without associated classes.\r
         /// </summary>\r
+        /// <param name="game">The game reference to be passed to entities.</param>\r
         /// <returns>List of entity objects loaded.</returns>\r
-        public List<object> GetAllEntities()\r
+        public List<IEntity> GetAllEntities(Game game)\r
         {\r
-            return mData.GetAllEntities();\r
+            return mData.GetAllEntities(game);\r
         }\r
 \r
         /// <summary>\r
         /// Get the entities of a certain type loaded from the map file.  Exceptions\r
         /// could be thrown if there are entities without associated classes.\r
         /// </summary>\r
+        /// <param name="game">The game reference to be passed to entities.</param>\r
         /// <typeparam name="T">Type of the entity you want a list of.</typeparam>\r
         /// <returns>List of entity objects loaded.</returns>\r
-        public List<T> GetEntities<T>()\r
+        public List<T> GetEntities<T>(Game game)\r
         {\r
-            return mData.GetEntities<T>();\r
+            return mData.GetEntities<T>(game);\r
         }\r
 \r
 \r
@@ -426,9 +405,9 @@ namespace CarFire
             }\r
 \r
 \r
-            public List<object> GetAllEntities()\r
+            public List<IEntity> GetAllEntities(Game game)\r
             {\r
-                List<object> list = new List<object>();\r
+                List<IEntity> list = new List<IEntity>();\r
 \r
                 foreach (RawEntity raw in mEntities)\r
                 {\r
@@ -436,23 +415,27 @@ namespace CarFire
                     {\r
                         string typename = raw.Attributes["type"];\r
 \r
-                        object[] args = new object[3];\r
+                        object[] args = new object[4];\r
                         args[0] = raw.Id;\r
                         args[1] = raw.Position;\r
                         args[2] = raw.Attributes;\r
+                        args[3] = game;\r
 \r
                         try\r
                         {\r
-\r
-                            object entity = Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args);\r
-                            if (entity != null) list.Add(entity);\r
-                            else throw new RuntimeException();\r
+                            IEntity entity = (IEntity)Activator.CreateInstance(System.Type.GetType("CarFire." + typename), args);\r
+                            if (entity != null)\r
+                            {\r
+                                entity.LoadContent(game.ContentManager);\r
+                                list.Add(entity);\r
+                            }\r
+                            else throw new Exception();\r
                         }\r
 #pragma warning disable 0168\r
                         catch (System.Exception ex)\r
 #pragma warning restore 0168\r
                         {\r
-                            throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
+                            throw new Exception("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
                         }\r
                     }\r
                     else\r
@@ -464,7 +447,7 @@ namespace CarFire
                 return list;\r
             }\r
 \r
-            public List<T> GetEntities<T>()\r
+            public List<T> GetEntities<T>(Game game)\r
             {\r
                 System.Type type = typeof(T);\r
                 List<T> list = new List<T>();\r
@@ -474,14 +457,19 @@ namespace CarFire
                 {\r
                     if (raw.Attributes.ContainsKey("type") && typename == raw.Attributes["type"])\r
                     {\r
-                        object[] args = new object[3];\r
+                        object[] args = new object[4];\r
                         args[0] = raw.Id;\r
                         args[1] = raw.Position;\r
                         args[2] = raw.Attributes;\r
+                        args[3] = game;\r
 \r
                         T entity = (T)Activator.CreateInstance(type, args);\r
-                        if (entity != null) list.Add(entity);\r
-                        else throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
+                        if (entity != null)\r
+                        {\r
+                            ((IEntity)entity).LoadContent(game.ContentManager);\r
+                            list.Add(entity);\r
+                        }\r
+                        else throw new Exception("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
                     }\r
                 }\r
 \r
This page took 0.024036 seconds and 4 git commands to generate.