+\r
+\r
+ public List<object> GetAllEntities()\r
+ {\r
+ List<object> list = new List<object>();\r
+\r
+ foreach (RawEntity raw in mEntities)\r
+ {\r
+ if (raw.Attributes.ContainsKey("type"))\r
+ {\r
+ string typename = raw.Attributes["type"];\r
+\r
+ object[] args = new object[3];\r
+ args[0] = raw.Id;\r
+ args[1] = raw.Position;\r
+ args[2] = raw.Attributes;\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
+ }\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
+ }\r
+ }\r
+ else\r
+ {\r
+ Console.WriteLine("Ignoring entity with identifier " + raw.Id + " since it has no type key.");\r
+ }\r
+ }\r
+\r
+ return list;\r
+ }\r
+\r
+ public List<T> GetEntities<T>()\r
+ {\r
+ System.Type type = typeof(T);\r
+ List<T> list = new List<T>();\r
+\r
+ string typename = typeof(T).Name;\r
+ foreach (RawEntity raw in mEntities)\r
+ {\r
+ if (raw.Attributes.ContainsKey("type") && typename == raw.Attributes["type"])\r
+ {\r
+ object[] args = new object[3];\r
+ args[0] = raw.Id;\r
+ args[1] = raw.Position;\r
+ args[2] = raw.Attributes;\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
+ }\r
+ }\r
+\r
+ return list;\r
+ }\r