// 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
/// 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
}\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
{\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
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
{\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