]> Dogcows Code - chaz/carfire/blobdiff - CarFire/CarFire/CarFire/Map.cs
Map shouldn't keep a reference to the game as if it were a property, but it is needed...
[chaz/carfire] / CarFire / CarFire / CarFire / Map.cs
index 2440f121ac6014a16cfdff81984e1348081afe44..f4d7ea4fa61a2637b90abff61392efcf52d58ce1 100644 (file)
@@ -156,6 +156,10 @@ namespace CarFire
             set { mView.CenterCell = value; }\r
         }\r
 \r
+        /// <summary>\r
+        /// Get and set the zoom of the map view.  The default zoom is\r
+        /// Map.PixelsToUnitSquares.\r
+        /// </summary>\r
         public float Zoom\r
         {\r
             get { return mView.Zoom; }\r
@@ -176,7 +180,7 @@ namespace CarFire
         public Map(Metadata metadata, char[,] grid, char defaultTile,\r
             List<RawEntity> entities, Point[] playerPositions)\r
         {\r
-            mData = new Modal(metadata, grid, defaultTile, entities, playerPositions);\r
+            mData = new Model(metadata, grid, defaultTile, entities, playerPositions);\r
             mView = new View(mData);\r
         }\r
 \r
@@ -273,21 +277,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
@@ -347,7 +353,7 @@ namespace CarFire
 \r
         #region Private Types\r
 \r
-        class Modal\r
+        class Model\r
         {\r
             public Metadata Metadata { get { return mMetadata; } }\r
             public List<RawEntity> Entities { get { return mEntities; } }\r
@@ -355,7 +361,7 @@ namespace CarFire
             public bool[,] Grid { get { return mBooleanGrid; } }\r
 \r
 \r
-            public Modal(Metadata metadata, char[,] grid, char defaultTile,\r
+            public Model(Metadata metadata, char[,] grid, char defaultTile,\r
                 List<RawEntity> entities, Point[] playerPositions)\r
             {\r
                 Debug.Assert(metadata != null);\r
@@ -422,9 +428,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
@@ -432,16 +438,20 @@ 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
+                            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 RuntimeException();\r
                         }\r
 #pragma warning disable 0168\r
@@ -460,7 +470,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
@@ -470,13 +480,18 @@ 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
+                        if (entity != null)\r
+                        {\r
+                            ((IEntity)entity).LoadContent(game.ContentManager);\r
+                            list.Add(entity);\r
+                        }\r
                         else throw new RuntimeException("Entity of type " + typename + " not loaded because an entity class can't be found.");\r
                     }\r
                 }\r
@@ -500,7 +515,7 @@ namespace CarFire
             public float Zoom;\r
 \r
 \r
-            public View(Modal data)\r
+            public View(Model data)\r
             {\r
                 Debug.Assert(data != null);\r
                 mData = data;\r
@@ -581,7 +596,7 @@ namespace CarFire
             }\r
 \r
 \r
-            Modal mData;\r
+            Model mData;\r
             Viewport mViewport;\r
         }\r
 \r
@@ -590,7 +605,7 @@ namespace CarFire
 \r
         #region Private Variables\r
 \r
-        Modal mData;\r
+        Model mData;\r
         View mView;\r
 \r
         #endregion\r
This page took 0.027984 seconds and 4 git commands to generate.