Skip to content

Commit

Permalink
Clean up starting room handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalobi committed Apr 16, 2024
1 parent e1915cf commit f00f528
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions Celeste.Mod.mm/Patches/Level.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,8 @@ private IEnumerator TransitionRoutine(LevelData next, Vector2 direction) {
playerIntro = introType;

try {
if (Session.Level == "") {
if (string.IsNullOrEmpty(Session.Level)) {
patch_LevelEnter.ErrorMessage = Dialog.Get("postcard_levelnorooms");
Logger.Log(LogLevel.Error, "MapData", "Current map has no rooms!");
throw new NullReferenceException("Current map has no rooms.");
}
Logger.Log(LogLevel.Verbose, "LoadLevel", $"Loading room {Session.LevelData.Name} of {Session.Area.GetSID()}");
Expand Down
13 changes: 8 additions & 5 deletions Celeste.Mod.mm/Patches/MapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,24 @@ private void Load() {
public new LevelData StartLevel() {
MapMetaModeProperties meta = Meta;
LevelData level;
if (meta != null && !string.IsNullOrEmpty(meta.StartLevel)) {
level = Levels.FirstOrDefault(_ => _.Name == meta.StartLevel);
if (!string.IsNullOrEmpty(meta?.StartLevel)) {
level = Levels.FirstOrDefault(lvl => lvl.Name == meta.StartLevel);
if (level != null)
return level;

Logger.Log(LogLevel.Warn, "MapData", $"The starting room defined in metadata, \"{meta.StartLevel}\", does not exist!");
Logger.Log(LogLevel.Warn, "MapData", $"The starting room defined in metadata, \"{meta.StartLevel}\", does not exist for map {((patch_AreaData) Data)?.SID}!");
}

level = orig_StartLevel();
if (level != null)
return level;

Logger.Log(LogLevel.Debug, "MapData", $"There is no room at (0,0), falling back to the first room.");
level = Levels.Count > 0 ? Levels[0] : null;
Logger.Log(LogLevel.Debug, "MapData", $"There is no room at (0,0) in map {((patch_AreaData) Data)?.SID}, attempting fallback to the first room.");
level = Levels.FirstOrDefault();

if (level == null) {
Logger.Log(LogLevel.Warn, "MapData", $"Map {((patch_AreaData) Data)?.SID} has no rooms!");
}
return level;
}

Expand Down

0 comments on commit f00f528

Please sign in to comment.