From 41715cefcde3c838bb079cb37aac5a3b2dcb1004 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 11 Mar 2018 19:09:08 -0400 Subject: add initial compatibility with Stardew Valley 1.3 (#453) --- src/SMAPI/Metadata/CoreAssets.cs | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src/SMAPI/Metadata') diff --git a/src/SMAPI/Metadata/CoreAssets.cs b/src/SMAPI/Metadata/CoreAssets.cs index 5a98da4b..c027df25 100644 --- a/src/SMAPI/Metadata/CoreAssets.cs +++ b/src/SMAPI/Metadata/CoreAssets.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework; +using StardewModdingAPI.Framework.Reflection; using StardewValley; using StardewValley.BellsAndWhistles; using StardewValley.Buildings; @@ -31,7 +32,8 @@ namespace StardewModdingAPI.Metadata *********/ /// Initialise the core asset data. /// Normalises an asset key to match the cache key. - public CoreAssets(Func getNormalisedPath) + /// Simplifies access to private code. + public CoreAssets(Func getNormalisedPath, Reflector reflection) { this.GetNormalisedPath = getNormalisedPath; this.SingletonSetters = @@ -82,6 +84,25 @@ namespace StardewModdingAPI.Metadata // from Game1.ResetToolSpriteSheet ["TileSheets\\tools"] = (content, key) => Game1.ResetToolSpriteSheet(), +#if STARDEW_VALLEY_1_3 + // from Bush + ["TileSheets\\bushes"] = (content, key) => reflection.GetField>(typeof(Bush), "texture").SetValue(new Lazy(() => content.Load(key))), + + // from Farm + ["Buildings\\houses"] = (content, key) => reflection.GetField(typeof(Farm), nameof(Farm.houseTextures)).SetValue(content.Load(key)), + + // from Farmer + ["Characters\\Farmer\\farmer_base"] = (content, key) => + { + if (Game1.player != null && Game1.player.isMale) + Game1.player.FarmerRenderer = new FarmerRenderer(key); + }, + ["Characters\\Farmer\\farmer_girl_base"] = (content, key) => + { + if (Game1.player != null && !Game1.player.isMale) + Game1.player.FarmerRenderer = new FarmerRenderer(key); + }, +#else // from Bush ["TileSheets\\bushes"] = (content, key) => Bush.texture = content.Load(key), @@ -107,6 +128,7 @@ namespace StardewModdingAPI.Metadata if (Game1.player != null && !Game1.player.isMale) Game1.player.FarmerRenderer = new FarmerRenderer(content.Load(key)); }, +#endif // from Flooring ["TerrainFeatures\\Flooring"] = (content, key) => Flooring.floorsTexture = content.Load(key), @@ -144,9 +166,15 @@ namespace StardewModdingAPI.Metadata Building[] buildings = this.GetAllBuildings().Where(p => key == this.GetNormalisedPath($"Buildings\\{p.buildingType}")).ToArray(); if (buildings.Any()) { +#if STARDEW_VALLEY_1_3 + foreach (Building building in buildings) + building.texture = new Lazy(() => content.Load(key)); +#else Texture2D texture = content.Load(key); foreach (Building building in buildings) building.texture = texture; +#endif + return true; } return false; @@ -162,9 +190,11 @@ namespace StardewModdingAPI.Metadata /// Get all player-constructed buildings in the world. private IEnumerable GetAllBuildings() { - return Game1.locations - .OfType() - .SelectMany(p => p.buildings); + foreach (BuildableGameLocation location in Game1.locations.OfType()) + { + foreach (Building building in location.buildings) + yield return building; + } } } } -- cgit