Skip to content

Commit 74e969e

Browse files
committed
Added some additional error handling
1 parent 082ec3c commit 74e969e

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

ScheduleViewer/Schedule.cs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,20 +384,35 @@ public static void LoadTileAreas()
384384

385385
public static void UpdateScheduleEntriesCanAccess(NPCSchedule schedule)
386386
{
387-
if (schedule.Entries == null) return;
387+
if (schedule.Entries == null || !schedule.Entries.Any()) return;
388388

389-
List<TileArea> tileAreasForNpc = AccessTileAreas.FindAll(tileArea => tileArea.Npcs.Contains(schedule.NPC.Name));
390-
if (!tileAreasForNpc.Any()) return;
389+
List<TileArea> tileAreasForNpc = null;
390+
try
391+
{
392+
tileAreasForNpc = AccessTileAreas.FindAll(tileArea => tileArea.Npcs.Contains(schedule.NPC.Name));
393+
}
394+
catch (Exception ex)
395+
{
396+
ModEntry.Console.Log($"Error checking AccessTileAreas for {schedule.DisplayName}'s schedule. See details below:\n{ex}", LogLevel.Error);
397+
}
398+
if (tileAreasForNpc == null || !tileAreasForNpc.Any()) return;
391399

392400
foreach (var entry in schedule.Entries)
393401
{
394-
TileArea location = tileAreasForNpc.Find(tileArea => entry.Location.Equals(tileArea.Location));
395-
if (location == null) continue;
402+
try
403+
{
404+
TileArea location = tileAreasForNpc.Find(tileArea => entry.Location.Equals(tileArea.Location));
405+
if (location == null) continue;
396406

397-
if (IsScheduleEntryInTileArea(location, entry))
407+
if (IsScheduleEntryInTileArea(location, entry))
408+
{
409+
bool hasTwoHearts = location.Npcs.Any(name => Game1.player.getFriendshipHeartLevelForNPC(name) >= 2);
410+
entry.CanAccess = hasTwoHearts;
411+
}
412+
}
413+
catch (Exception ex)
398414
{
399-
bool hasTwoHearts = location.Npcs.Any(name => Game1.player.getFriendshipHeartLevelForNPC(name) >= 2);
400-
entry.CanAccess = hasTwoHearts;
415+
ModEntry.Console.Log($"Error checking AccessTileAreas for {schedule.DisplayName}'s schedule entry: {entry}. See details below:\n{ex}", LogLevel.Error);
401416
}
402417
}
403418
}

ScheduleViewer/modEntry.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ private void OnButtonsChanged(object sender, ButtonsChangedEventArgs e)
229229
}
230230
catch (Exception ex)
231231
{
232-
Console.Log("Error opening the Schedule Viewer. See details below:", LogLevel.Error);
233-
Console.Log(ex.ToString(), LogLevel.Error);
232+
Console.Log($"Error opening the Schedule Viewer. See details below:\n{ex}", LogLevel.Error);
234233
}
235234
}
236235

0 commit comments

Comments
 (0)