From 732d66f1fe9c697eadeb05e4e0e05ccc7f3f6794 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 17 May 2019 23:53:49 -0400 Subject: [PATCH] remove reflection no longer needed in newest SDV 1.4 build (#638) --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 47 +++++++++-------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index dbb27b14..4f8f1427 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Reflection; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.Reflection; using StardewValley; @@ -139,21 +138,9 @@ namespace StardewModdingAPI.Metadata { if (!string.IsNullOrWhiteSpace(location.mapPath.Value) && this.GetNormalisedPath(location.mapPath.Value) == key) { - // reload map data - this.Reflection.GetMethod(location, "reloadMap").Invoke(); - this.Reflection.GetMethod(location, "updateWarps").Invoke(); - - // reload doors - { - Type interiorDoorDictType = Type.GetType($"StardewValley.InteriorDoorDictionary, {Constants.GameAssemblyName}", throwOnError: true); - ConstructorInfo constructor = interiorDoorDictType.GetConstructor(new[] { typeof(GameLocation) }); - if (constructor == null) - throw new InvalidOperationException("Can't reset location doors: constructor not found for InteriorDoorDictionary type."); - object instance = constructor.Invoke(new object[] { location }); - - this.Reflection.GetField(location, "interiorDoors").SetValue(instance); - } - + location.reloadMap(); + location.updateWarps(); + this.Reflection.GetField(location, nameof(location.interiorDoors)).SetValue(new InteriorDoorDictionary(location)); anyChanged = true; } } @@ -371,21 +358,25 @@ namespace StardewModdingAPI.Metadata ** Content\Minigames ****/ case "minigames\\clouds": // TitleMenu - if (Game1.activeClickableMenu is TitleMenu) { - reflection.GetField(Game1.activeClickableMenu, "cloudsTexture").SetValue(content.Load(key)); - return true; + if (Game1.activeClickableMenu is TitleMenu titleMenu) + { + titleMenu.cloudsTexture = content.Load(key); + return true; + } } return false; case "minigames\\titlebuttons": // TitleMenu - if (Game1.activeClickableMenu is TitleMenu titleMenu) { - Texture2D texture = content.Load(key); - reflection.GetField(titleMenu, "titleButtonsTexture").SetValue(texture); - foreach (TemporaryAnimatedSprite bird in reflection.GetField>(titleMenu, "birds").GetValue()) - bird.texture = texture; - return true; + if (Game1.activeClickableMenu is TitleMenu titleMenu) + { + Texture2D texture = content.Load(key); + titleMenu.titleButtonsTexture = texture; + foreach (TemporaryAnimatedSprite bird in titleMenu.birds) + bird.texture = texture; + return true; + } } return false; @@ -401,7 +392,7 @@ namespace StardewModdingAPI.Metadata return true; case "tilesheets\\bushes": // new Bush() - reflection.GetField>(typeof(Bush), "texture").SetValue(new Lazy(() => content.Load(key))); + Bush.texture = new Lazy(() => content.Load(key)); return true; case "tilesheets\\craftables": // Game1.loadContent @@ -581,7 +572,7 @@ namespace StardewModdingAPI.Metadata // update fence textures foreach (Fence fence in fences) - this.Reflection.GetField>(fence, "fenceTexture").SetValue(new Lazy(fence.loadFenceTexture)); + fence.fenceTexture = new Lazy(fence.loadFenceTexture); return true; } @@ -746,7 +737,7 @@ namespace StardewModdingAPI.Metadata int lastScheduleTime = villager.Schedule.Keys.Where(p => p <= Game1.timeOfDay).OrderByDescending(p => p).FirstOrDefault(); if (lastScheduleTime != 0) { - this.Reflection.GetField(villager, "scheduleTimeToTry").SetValue(this.Reflection.GetField(typeof(NPC), "NO_TRY").GetValue()); // use time that's passed in to checkSchedule + villager.scheduleTimeToTry = NPC.NO_TRY; // use time that's passed in to checkSchedule villager.checkSchedule(lastScheduleTime); } }