add asset propagation for interior door sprites

This commit is contained in:
Jesse Plamondon-Willard 2021-03-14 14:17:09 -04:00
parent 04388fe7e3
commit 6805c90e2c
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 33 additions and 0 deletions

View File

@ -12,6 +12,7 @@
* Aggressive memory optimization (added in 3.9.2) is now disabled by default. The option reduces errors for a subset of players who use certain mods, but may cause crashes for farmhands in multiplayer. You can edit `smapi-internal/config.json` to enable it if you experience frequent `OutOfMemoryException` errors. * Aggressive memory optimization (added in 3.9.2) is now disabled by default. The option reduces errors for a subset of players who use certain mods, but may cause crashes for farmhands in multiplayer. You can edit `smapi-internal/config.json` to enable it if you experience frequent `OutOfMemoryException` errors.
* For mod authors: * For mod authors:
* Added asset propagation for interior door sprites.
* Fixed assets changed by a mod not reapplied if playing in non-English, the changes are only applicable after the save is loaded, the player returns to title and reloads a save, and the game reloads the target asset before the save is loaded. * Fixed assets changed by a mod not reapplied if playing in non-English, the changes are only applicable after the save is loaded, the player returns to title and reloads a save, and the game reloads the target asset before the save is loaded.
## 3.9.4 ## 3.9.4

View File

@ -366,6 +366,8 @@ namespace StardewModdingAPI.Metadata
foreach (ClickableTextureComponent button in new[] { menu.questButton, menu.zoomInButton, menu.zoomOutButton }) foreach (ClickableTextureComponent button in new[] { menu.questButton, menu.zoomInButton, menu.zoomOutButton })
button.texture = Game1.mouseCursors; button.texture = Game1.mouseCursors;
} }
this.ReloadDoorSprites(content, key);
return true; return true;
case "loosesprites\\cursors2": // Game1.LoadContent case "loosesprites\\cursors2": // Game1.LoadContent
@ -739,6 +741,36 @@ namespace StardewModdingAPI.Metadata
return critters.Length; return critters.Length;
} }
/// <summary>Reload the sprites for interior doors.</summary>
/// <param name="content">The content manager through which to reload the asset.</param>
/// <param name="key">The asset key to reload.</param>
/// <returns>Returns whether any doors were affected.</returns>
private bool ReloadDoorSprites(LocalizedContentManager content, string key)
{
Lazy<Texture2D> texture = new Lazy<Texture2D>(() => content.Load<Texture2D>(key));
foreach (GameLocation location in this.GetLocations())
{
IEnumerable<InteriorDoor> doors = location.interiorDoors?.Doors;
if (doors == null)
continue;
foreach (InteriorDoor door in doors)
{
if (door?.Sprite == null)
continue;
string textureName = this.NormalizeAssetNameIgnoringEmpty(this.Reflection.GetField<string>(door.Sprite, "textureName").GetValue());
if (textureName != key)
continue;
door.Sprite.texture = texture.Value;
}
}
return texture.IsValueCreated;
}
/// <summary>Reload the data for matching farm animals.</summary> /// <summary>Reload the data for matching farm animals.</summary>
/// <returns>Returns whether any farm animals were affected.</returns> /// <returns>Returns whether any farm animals were affected.</returns>
/// <remarks>Derived from the <see cref="FarmAnimal"/> constructor.</remarks> /// <remarks>Derived from the <see cref="FarmAnimal"/> constructor.</remarks>