remove reflection no longer needed in newest SDV 1.4 build (#638)

This commit is contained in:
Jesse Plamondon-Willard 2019-05-17 23:53:49 -04:00
parent 2b12bb32f6
commit 732d66f1fe
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
1 changed files with 19 additions and 28 deletions

View File

@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Framework.Reflection; using StardewModdingAPI.Framework.Reflection;
using StardewValley; using StardewValley;
@ -139,21 +138,9 @@ namespace StardewModdingAPI.Metadata
{ {
if (!string.IsNullOrWhiteSpace(location.mapPath.Value) && this.GetNormalisedPath(location.mapPath.Value) == key) if (!string.IsNullOrWhiteSpace(location.mapPath.Value) && this.GetNormalisedPath(location.mapPath.Value) == key)
{ {
// reload map data location.reloadMap();
this.Reflection.GetMethod(location, "reloadMap").Invoke(); location.updateWarps();
this.Reflection.GetMethod(location, "updateWarps").Invoke(); this.Reflection.GetField<InteriorDoorDictionary>(location, nameof(location.interiorDoors)).SetValue(new InteriorDoorDictionary(location));
// 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<object>(location, "interiorDoors").SetValue(instance);
}
anyChanged = true; anyChanged = true;
} }
} }
@ -371,21 +358,25 @@ namespace StardewModdingAPI.Metadata
** Content\Minigames ** Content\Minigames
****/ ****/
case "minigames\\clouds": // TitleMenu case "minigames\\clouds": // TitleMenu
if (Game1.activeClickableMenu is TitleMenu)
{ {
reflection.GetField<Texture2D>(Game1.activeClickableMenu, "cloudsTexture").SetValue(content.Load<Texture2D>(key)); if (Game1.activeClickableMenu is TitleMenu titleMenu)
return true; {
titleMenu.cloudsTexture = content.Load<Texture2D>(key);
return true;
}
} }
return false; return false;
case "minigames\\titlebuttons": // TitleMenu case "minigames\\titlebuttons": // TitleMenu
if (Game1.activeClickableMenu is TitleMenu titleMenu)
{ {
Texture2D texture = content.Load<Texture2D>(key); if (Game1.activeClickableMenu is TitleMenu titleMenu)
reflection.GetField<Texture2D>(titleMenu, "titleButtonsTexture").SetValue(texture); {
foreach (TemporaryAnimatedSprite bird in reflection.GetField<List<TemporaryAnimatedSprite>>(titleMenu, "birds").GetValue()) Texture2D texture = content.Load<Texture2D>(key);
bird.texture = texture; titleMenu.titleButtonsTexture = texture;
return true; foreach (TemporaryAnimatedSprite bird in titleMenu.birds)
bird.texture = texture;
return true;
}
} }
return false; return false;
@ -401,7 +392,7 @@ namespace StardewModdingAPI.Metadata
return true; return true;
case "tilesheets\\bushes": // new Bush() case "tilesheets\\bushes": // new Bush()
reflection.GetField<Lazy<Texture2D>>(typeof(Bush), "texture").SetValue(new Lazy<Texture2D>(() => content.Load<Texture2D>(key))); Bush.texture = new Lazy<Texture2D>(() => content.Load<Texture2D>(key));
return true; return true;
case "tilesheets\\craftables": // Game1.loadContent case "tilesheets\\craftables": // Game1.loadContent
@ -581,7 +572,7 @@ namespace StardewModdingAPI.Metadata
// update fence textures // update fence textures
foreach (Fence fence in fences) foreach (Fence fence in fences)
this.Reflection.GetField<Lazy<Texture2D>>(fence, "fenceTexture").SetValue(new Lazy<Texture2D>(fence.loadFenceTexture)); fence.fenceTexture = new Lazy<Texture2D>(fence.loadFenceTexture);
return true; return true;
} }
@ -746,7 +737,7 @@ namespace StardewModdingAPI.Metadata
int lastScheduleTime = villager.Schedule.Keys.Where(p => p <= Game1.timeOfDay).OrderByDescending(p => p).FirstOrDefault(); int lastScheduleTime = villager.Schedule.Keys.Where(p => p <= Game1.timeOfDay).OrderByDescending(p => p).FirstOrDefault();
if (lastScheduleTime != 0) if (lastScheduleTime != 0)
{ {
this.Reflection.GetField<int>(villager, "scheduleTimeToTry").SetValue(this.Reflection.GetField<int>(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); villager.checkSchedule(lastScheduleTime);
} }
} }