summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/ContentManagers/BaseContentManager.cs6
-rw-r--r--src/SMAPI/Metadata/CoreAssetPropagator.cs28
2 files changed, 14 insertions, 20 deletions
diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
index de39dbae..5283340e 100644
--- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
@@ -6,6 +6,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework.Content;
+using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Framework.Content;
using StardewModdingAPI.Framework.Exceptions;
using StardewModdingAPI.Framework.Reflection;
@@ -264,6 +265,11 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <param name="language">The language code for which to inject the asset.</param>
protected virtual void Inject<T>(string assetName, T value, LanguageCode language)
{
+ // track asset key
+ if (value is Texture2D texture)
+ texture.Name = assetName;
+
+ // cache asset
assetName = this.AssertAndNormalizeAssetName(assetName);
this.Cache[assetName] = value;
}
diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs
index 66e6ed14..c0d57f4b 100644
--- a/src/SMAPI/Metadata/CoreAssetPropagator.cs
+++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs
@@ -507,6 +507,7 @@ namespace StardewModdingAPI.Metadata
// find matches
TAnimal[] animals = this.GetCharacters()
.OfType<TAnimal>()
+ .Where(p => key == this.GetNormalizedPath(p.Sprite?.Texture?.Name))
.ToArray();
if (!animals.Any())
return false;
@@ -587,7 +588,7 @@ namespace StardewModdingAPI.Metadata
let locCritters = this.Reflection.GetField<List<Critter>>(location, "critters").GetValue()
where locCritters != null
from Critter critter in locCritters
- where this.GetNormalizedPath(critter.sprite.textureName) == key
+ where this.GetNormalizedPath(critter.sprite?.Texture?.Name) == key
select critter
)
.ToArray();
@@ -673,7 +674,7 @@ namespace StardewModdingAPI.Metadata
// get NPCs
HashSet<string> lookup = new HashSet<string>(keys, StringComparer.InvariantCultureIgnoreCase);
NPC[] characters = this.GetCharacters()
- .Where(npc => npc.Sprite != null && lookup.Contains(this.GetNormalizedPath(npc.Sprite.textureName.Value)))
+ .Where(npc => npc.Sprite != null && lookup.Contains(this.GetNormalizedPath(npc.Sprite?.Texture?.Name)))
.ToArray();
if (!characters.Any())
return 0;
@@ -697,36 +698,23 @@ namespace StardewModdingAPI.Metadata
{
// get NPCs
HashSet<string> lookup = new HashSet<string>(keys, StringComparer.InvariantCultureIgnoreCase);
- var villagers =
- (
- from npc in this.GetCharacters()
- where npc.isVillager()
- let textureKey = this.GetNormalizedPath($"Portraits\\{this.getTextureName(npc)}")
- where lookup.Contains(textureKey)
- select new { npc, textureKey }
- )
+ var villagers = this
+ .GetCharacters()
+ .Where(npc => npc.isVillager() && lookup.Contains(this.GetNormalizedPath(npc.Portrait?.Name)))
.ToArray();
if (!villagers.Any())
return 0;
// update portrait
int reloaded = 0;
- foreach (var entry in villagers)
+ foreach (NPC npc in villagers)
{
- entry.npc.resetPortrait();
- entry.npc.Portrait = content.Load<Texture2D>(entry.textureKey);
+ npc.Portrait = content.Load<Texture2D>(npc.Portrait.Name);
reloaded++;
}
return reloaded;
}
- private string getTextureName(NPC npc)
- {
- string name = npc.Name;
- string str = name == "Old Mariner" ? "Mariner" : (name == "Dwarf King" ? "DwarfKing" : (name == "Mister Qi" ? "MrQi" : (name == "???" ? "Monsters\\Shadow Guy" : name)));
- return str;
- }
-
/// <summary>Reload tree textures.</summary>
/// <param name="content">The content manager through which to reload the asset.</param>
/// <param name="key">The asset key to reload.</param>