/// <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> /// 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); }