Skip to content

Commit

Permalink
update rewriters for Stardew Valley 1.6.4
Browse files Browse the repository at this point in the history
1.6.4 adds an optional 'includeEventActor' argument to Game1 methods for searching NPCs.

This also drops support for 1.6.0–1.6.3, since it'd be tricky to rewrite for both without introducing potential regressions (and since 1.6.4 fixes NPC duplication issues).
  • Loading branch information
Pathoschild committed Apr 6, 2024
1 parent bebf4ce commit 79e2c16
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Release notes
## Upcoming release
* For players:
* Updated for Stardew Valley 1.6.4. **This drops compatibility with Stardew Valley 1.6.0–1.6.3.**
* The installer now deletes obsolete files from very old SMAPI versions again. (This was removed in SMAPI 4.0, but many players still had very old versions.)
* The installer now deletes Error Handler automatically if it's at the default path.

Expand Down
2 changes: 1 addition & 1 deletion src/SMAPI/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static class Constants
public static ISemanticVersion ApiVersion { get; } = new Toolkit.SemanticVersion(EarlyConstants.RawApiVersion);

/// <summary>The minimum supported version of Stardew Valley.</summary>
public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.6.0");
public static ISemanticVersion MinimumGameVersion { get; } = new GameVersion("1.6.4");

/// <summary>The maximum supported version of Stardew Valley, if any.</summary>
public static ISemanticVersion? MaximumGameVersion { get; } = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Xna.Framework;
Expand Down Expand Up @@ -116,11 +117,26 @@ public static void drawObjectQuestionDialogue(string dialogue, List<Response>? c
Game1.drawObjectQuestionDialogue(dialogue, choices?.ToArray());
}

public static NPC getCharacterFromName(string name, bool mustBeVillager = true, bool useLocationsListOnly = false)
public new static NPC? getCharacterFromName(string name, bool mustBeVillager = true)
{
return Game1.getCharacterFromName(name, mustBeVillager);
}

public static T? getCharacterFromName<T>(string name, bool mustBeVillager = true) where T : NPC
{
return Game1.getCharacterFromName<T>(name, mustBeVillager);
}

public static T? GetCharacterOfType<T>() where T : NPC
{
return Game1.GetCharacterOfType<T>();
}

public static T? GetCharacterWhere<T>(Func<T, bool> check) where T : NPC
{
return Game1.GetCharacterWhere(check);
}

public static int getModeratelyDarkTime()
{
return Game1.getModeratelyDarkTime(Game1.currentLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Framework.ModLoading.Framework;
using StardewValley;
Expand Down Expand Up @@ -47,30 +46,6 @@ public static void ForAllLocations(Action<GameLocation> action)
});
}

public new static void ForEachCharacter(Func<NPC, bool> action, bool includeEventActors = false)
{
// Stardew Valley 1.6.3 added an optional parameter to ForEachCharacter, so mods compiled in 1.6.3 won't
// run in 1.6.2 and earlier. We can't just call the method directly either since SMAPI itself is compiled
// for 1.6.3+ too.

MethodInfo method =
typeof(Utility).GetMethod(nameof(Utility.ForEachCharacter))
?? throw new InvalidOperationException($"Can't find method {nameof(Utility)}.{nameof(Utility.ForEachCharacter)} for compatibility rewrite.");
method.Invoke(null, new object[] { action });
}

public new static void ForEachVillager(Func<NPC, bool> action, bool includeEventActors = false)
{
// Stardew Valley 1.6.3 added an optional parameter to ForEachVillager, so mods compiled in 1.6.3 won't
// run in 1.6.2 and earlier. We can't just call the method directly either since SMAPI itself is compiled
// for 1.6.3+ too.

MethodInfo method =
typeof(Utility).GetMethod(nameof(Utility.ForEachVillager))
?? throw new InvalidOperationException($"Can't find method {nameof(Utility)}.{nameof(Utility.ForEachVillager)} for compatibility rewrite.");
method.Invoke(null, new object[] { action });
}

public new static DisposableList<NPC> getAllCharacters()
{
return new DisposableList<NPC>(Utility.getAllCharacters());
Expand Down

0 comments on commit 79e2c16

Please sign in to comment.