Skip to content

Commit

Permalink
Try adding error handling to birthday icons
Browse files Browse the repository at this point in the history
  • Loading branch information
Annosz committed Jun 6, 2022
1 parent a8edf42 commit 1aa87cd
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions UIInfoSuite2/UIElements/ShowBirthdayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ private void CheckForGiftGiven(UpdateTickedEventArgs e)
{
if (e.IsOneSecond && _birthdayNPC != null && Game1.player?.friendshipData != null)
{
Game1.player.friendshipData.FieldDict.TryGetValue(_birthdayNPC.Name, out var netRef);
Friendship birthdayNPCDetails = netRef;
if (birthdayNPCDetails != null)
Friendship friendship = GetFriendshipWithNPC(_birthdayNPC.Name);
if (friendship != null && friendship.GiftsToday == 1)
{
if (birthdayNPCDetails.GiftsToday == 1)
_birthdayNPC = null;
_birthdayNPC = null;
}
}
}
Expand All @@ -110,9 +108,15 @@ private void CheckForBirthday()
foreach (var character in location.characters)
{
if (character.isBirthday(Game1.currentSeason, Game1.dayOfMonth) &&
!(!Game1.player.friendshipData.ContainsKey(character.Name) &&
Game1.NPCGiftTastes.ContainsKey(character.Name)))
Game1.player.friendshipData.FieldDict.ContainsKey(character.Name))
{
if (HideBirthdayIfFullFriendShip)
{
Friendship friendship = GetFriendshipWithNPC(character.Name);
if (friendship != null && friendship.Points >= 2000)
break;
}

_birthdayNPC = character;
break;
}
Expand All @@ -123,14 +127,24 @@ private void CheckForBirthday()
}
}

private void DrawBithdayIcon()
private static Friendship GetFriendshipWithNPC(string name)
{
if (HideBirthdayIfFullFriendShip
&& Game1.player.friendshipData.TryGetValue(_birthdayNPC.Name, out Friendship friendship)
&& friendship.Points >= 2000)
try
{
Game1.player.friendshipData.FieldDict.TryGetValue(name, out var netRef);
Friendship birthdayNPCDetails = netRef;
return birthdayNPCDetails;
}
catch (Exception ex)
{
return;
ModEntry.MonitorObject.Log("Error while getting information about the birthday of " + name + ": " + ex.Message + Environment.NewLine + ex.StackTrace, LogLevel.Error);
}

return null;
}

private void DrawBithdayIcon()
{
Rectangle headShot = _birthdayNPC.GetHeadShot();
Point iconPosition = IconHandler.Handler.GetNewIconPosition();
float scale = 2.9f;
Expand Down

0 comments on commit 1aa87cd

Please sign in to comment.