From e8648e217a3c0e45bf78e903623e6f250f92e88d Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 23 Jul 2017 20:22:33 -0400 Subject: add support for reloading wallpaper and building textures (#335) --- src/StardewModdingAPI/Metadata/CoreAssets.cs | 33 +++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'src/StardewModdingAPI/Metadata') diff --git a/src/StardewModdingAPI/Metadata/CoreAssets.cs b/src/StardewModdingAPI/Metadata/CoreAssets.cs index 256a911a..c350b0da 100644 --- a/src/StardewModdingAPI/Metadata/CoreAssets.cs +++ b/src/StardewModdingAPI/Metadata/CoreAssets.cs @@ -5,6 +5,8 @@ using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework; using StardewValley; using StardewValley.BellsAndWhistles; +using StardewValley.Buildings; +using StardewValley.Locations; using StardewValley.Objects; using StardewValley.Projectiles; @@ -83,7 +85,10 @@ namespace StardewModdingAPI.Metadata { if (Game1.player != null && !Game1.player.isMale) Game1.player.FarmerRenderer = new FarmerRenderer(content.Load(key)); - } + }, + + // from Wallpaper constructor + ["Maps\\walls_and_floors"] = (content, key) => Wallpaper.wallpaperTexture = content.Load(key) } .ToDictionary(p => getNormalisedPath(p.Key), p => p.Value); } @@ -101,7 +106,33 @@ namespace StardewModdingAPI.Metadata return true; } + // building textures + if (key.StartsWith(this.GetNormalisedPath("Buildings\\"))) + { + Building[] buildings = this.GetAllBuildings().Where(p => key == this.GetNormalisedPath($"Buildings\\{p.buildingType}")).ToArray(); + if (buildings.Any()) + { + Texture2D texture = content.Load(key); + foreach (Building building in buildings) + building.texture = texture; + return true; + } + return false; + } + return false; } + + + /********* + ** Private methods + *********/ + /// Get all player-constructed buildings in the world. + private IEnumerable GetAllBuildings() + { + return Game1.locations + .OfType() + .SelectMany(p => p.buildings); + } } } -- cgit