From 64facdd439b4d924d7214bb2d9f6fd72e009dd42 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 23 Jul 2017 20:44:04 -0400 Subject: [PATCH] add support for reloading more singleton assets (#335) --- src/StardewModdingAPI/Metadata/CoreAssets.cs | 39 ++++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/StardewModdingAPI/Metadata/CoreAssets.cs b/src/StardewModdingAPI/Metadata/CoreAssets.cs index c350b0da..3818314d 100644 --- a/src/StardewModdingAPI/Metadata/CoreAssets.cs +++ b/src/StardewModdingAPI/Metadata/CoreAssets.cs @@ -9,6 +9,7 @@ using StardewValley.Buildings; using StardewValley.Locations; using StardewValley.Objects; using StardewValley.Projectiles; +using StardewValley.TerrainFeatures; namespace StardewModdingAPI.Metadata { @@ -21,8 +22,8 @@ namespace StardewModdingAPI.Metadata /// Normalises an asset key to match the cache key. protected readonly Func GetNormalisedPath; - /// The static asset setters. - private readonly IDictionary> StaticSetters; + /// Setters which update static or singleton texture fields indexed by normalised asset key. + private readonly IDictionary> SingletonSetters; /********* @@ -33,12 +34,11 @@ namespace StardewModdingAPI.Metadata public CoreAssets(Func getNormalisedPath) { this.GetNormalisedPath = getNormalisedPath; - this.StaticSetters = + this.SingletonSetters = new Dictionary> { // from Game1.loadContent ["LooseSprites\\daybg"] = (content, key) => Game1.daybg = content.Load(key), - ["LooseSprites\\daybg"] = (content, key) => Game1.daybg = content.Load(key), ["LooseSprites\\nightbg"] = (content, key) => Game1.nightbg = content.Load(key), ["Maps\\MenuTiles"] = (content, key) => Game1.menuTexture = content.Load(key), ["LooseSprites\\Lighting\\lantern"] = (content, key) => Game1.lantern = content.Load(key), @@ -75,7 +75,21 @@ namespace StardewModdingAPI.Metadata ["TileSheets\\weapons"] = (content, key) => Tool.weaponsTexture = content.Load(key), ["TileSheets\\Projectiles"] = (content, key) => Projectile.projectileSheet = content.Load(key), - // from Farmer constructor + // from Bush + ["TileSheets\\bushes"] = (content, key) => Bush.texture = content.Load(key), + + // from Critter + ["TileSheets\\critters"] = (content, key) => Critter.critterTexture = content.Load(key), + + // from Farm + ["Buildings\\houses"] = (content, key) => + { + Farm farm = Game1.getFarm(); + if (farm != null) + farm.houseTextures = content.Load(key); + }, + + // from Farmer ["Characters\\Farmer\\farmer_base"] = (content, key) => { if (Game1.player != null && Game1.player.isMale) @@ -87,7 +101,18 @@ namespace StardewModdingAPI.Metadata Game1.player.FarmerRenderer = new FarmerRenderer(content.Load(key)); }, - // from Wallpaper constructor + // from Flooring + ["TerrainFeatures\\Flooring"] = (content, key) => Flooring.floorsTexture = content.Load(key), + + // from FruitTree + ["TileSheets\\fruitTrees"] = (content, key) => FruitTree.texture = content.Load(key), + + // from HoeDirt + ["TerrainFeatures\\hoeDirt"] = (content, key) => HoeDirt.lightTexture = content.Load(key), + ["TerrainFeatures\\hoeDirtDark"] = (content, key) => HoeDirt.darkTexture = content.Load(key), + ["TerrainFeatures\\hoeDirtSnow"] = (content, key) => HoeDirt.snowTexture = content.Load(key), + + // from Wallpaper ["Maps\\walls_and_floors"] = (content, key) => Wallpaper.wallpaperTexture = content.Load(key) } .ToDictionary(p => getNormalisedPath(p.Key), p => p.Value); @@ -100,7 +125,7 @@ namespace StardewModdingAPI.Metadata public bool ReloadForKey(SContentManager content, string key) { // static assets - if (this.StaticSetters.TryGetValue(key, out Action reload)) + if (this.SingletonSetters.TryGetValue(key, out Action reload)) { reload(content, key); return true;