public static MapObject GetTemplate(JmpType type) { switch (type) { case JmpType.Character: //return new Character(); break; case JmpType.Enemy: return(new Enemy()); case JmpType.Event: //return new Event(); break; case JmpType.Furniture: //return new Furniture(); break; case JmpType.Generator: //return new Generator(); break; case JmpType.None: throw new Exception("MapObjectTemplateManager received JmpTyp.None!"); default: return(null); } return(null); }
/// <summary> /// Adds the given object to the appropriate list of MapObjects. /// </summary> /// <param name="obj">MapObject to add</param> public void AddObject(MapObject obj) { JmpType type = TypeToEnum(obj.GetType()); List <MapObject> objList = MapObjects[(int)type]; // If the list is null, instantiate it if (objList == null) { objList = new List <MapObject>(); } objList.Add(obj); }
/// <summary> /// Converts the given JmpType to its corresponding Type. Returns null if no match is found. /// </summary> /// <param name="enumType">The JmpType to convert</param> /// <returns>The Type corresponding to the given JmpType</returns> public Type EnumToType(JmpType enumType) { if (enumType == JmpType.Enemy) { return(typeof(Enemy)); } else if (enumType == JmpType.Room) { return(typeof(Room)); } else { return(null); } }
/// <summary> /// Removes the given object from the appropriate list of MapObjects, given that the list is not null and contains the object. /// </summary> /// <param name="obj">MapObject to remove</param> public void RemoveObject(MapObject obj) { JmpType type = TypeToEnum(obj.GetType()); List <MapObject> objList = MapObjects[(int)type]; // Error out if the list is null if (objList == null) { Console.WriteLine($"Failed to remove object. Object list for type { type.ToString() } is null!"); return; } // Error out if the list doesn't contain the object we want to remove else if (!objList.Contains(obj)) { Console.WriteLine($"Failed to remove object. Object list for type { type.ToString() } doesn't contain the object to remove!"); return; } objList.Remove(obj); }