summaryrefslogtreecommitdiff
path: root/src/SMAPI/Metadata
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-05-27 22:59:06 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-05-27 22:59:06 -0400
commit03f8777afd4f0707dc8e61eae6e5eae73a88d738 (patch)
treee00307fbb9ef94936928f502db3b6c257e85a212 /src/SMAPI/Metadata
parentbe93327a80efdc6d592854f7c552c45cbb43b569 (diff)
downloadSMAPI-03f8777afd4f0707dc8e61eae6e5eae73a88d738.tar.gz
SMAPI-03f8777afd4f0707dc8e61eae6e5eae73a88d738.tar.bz2
SMAPI-03f8777afd4f0707dc8e61eae6e5eae73a88d738.zip
add asset propagation for paint masks
Diffstat (limited to 'src/SMAPI/Metadata')
-rw-r--r--src/SMAPI/Metadata/CoreAssetPropagator.cs50
1 files changed, 42 insertions, 8 deletions
diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs
index 623c65d5..5641f90f 100644
--- a/src/SMAPI/Metadata/CoreAssetPropagator.cs
+++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs
@@ -233,6 +233,16 @@ namespace StardewModdingAPI.Metadata
return true;
}
+ case "buildings\\houses_paintmask": // Farm
+ {
+ bool removedFromCache = this.RemoveFromPaintMaskCache(key);
+
+ Farm farm = Game1.getFarm();
+ farm?.ApplyHousePaint();
+
+ return removedFromCache || farm != null;
+ }
+
/****
** Content\Characters\Farmer
****/
@@ -613,7 +623,7 @@ namespace StardewModdingAPI.Metadata
return this.ReloadFarmAnimalSprites(content, key);
if (this.IsInFolder(key, "Buildings"))
- return this.ReloadBuildings(content, key);
+ return this.ReloadBuildings(key);
if (this.KeyStartsWith(key, "LooseSprites\\Fence"))
return this.ReloadFenceTextures(key);
@@ -717,28 +727,39 @@ namespace StardewModdingAPI.Metadata
}
/// <summary>Reload building textures.</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 textures were reloaded.</returns>
- private bool ReloadBuildings(LocalizedContentManager content, string key)
+ private bool ReloadBuildings(string key)
{
- // get buildings
+ // get paint mask info
+ const string paintMaskSuffix = "_PaintMask";
+ bool isPaintMask = key.EndsWith(paintMaskSuffix, StringComparison.OrdinalIgnoreCase);
+
+ // get building type
string type = Path.GetFileName(key);
+ if (isPaintMask)
+ type = type.Substring(0, type.Length - paintMaskSuffix.Length);
+
+ // get buildings
Building[] buildings = this.GetLocations(buildingInteriors: false)
.OfType<BuildableGameLocation>()
.SelectMany(p => p.buildings)
.Where(p => p.buildingType.Value == type)
.ToArray();
- // reload buildings
+ // remove from paint mask cache
+ bool removedFromCache = this.RemoveFromPaintMaskCache(key);
+
+ // reload textures
if (buildings.Any())
{
- Lazy<Texture2D> texture = new Lazy<Texture2D>(() => content.Load<Texture2D>(key));
foreach (Building building in buildings)
- building.texture = texture;
+ building.resetTexture();
+
return true;
}
- return false;
+
+ return removedFromCache;
}
/// <summary>Reload map seat textures.</summary>
@@ -1295,5 +1316,18 @@ namespace StardewModdingAPI.Metadata
// else just (re)load it from the main content manager
return this.MainContentManager.Load<Texture2D>(key);
}
+
+ /// <summary>Remove a case-insensitive key from the paint mask cache.</summary>
+ /// <param name="key">The paint mask asset key.</param>
+ private bool RemoveFromPaintMaskCache(string key)
+ {
+ // make cache case-insensitive
+ // This is needed for cache invalidation since mods may specify keys with a different capitalization
+ if (!object.ReferenceEquals(BuildingPainter.paintMaskLookup.Comparer, StringComparer.OrdinalIgnoreCase))
+ BuildingPainter.paintMaskLookup = new Dictionary<string, List<List<int>>>(BuildingPainter.paintMaskLookup, StringComparer.OrdinalIgnoreCase);
+
+ // remove key from cache
+ return BuildingPainter.paintMaskLookup.Remove(key);
+ }
}
}