From ffe74869ca626883f3f65116fd19af2d4951156e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 20 Dec 2020 22:34:59 -0500 Subject: update patches and asset propagation --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 104 ++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 28 deletions(-) (limited to 'src/SMAPI/Metadata/CoreAssetPropagator.cs') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 307bb11b..b82dedfd 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -138,12 +138,20 @@ namespace StardewModdingAPI.Metadata { if (!string.IsNullOrWhiteSpace(location.mapPath.Value) && this.NormalizeAssetNameIgnoringEmpty(location.mapPath.Value) == key) { - // reset town caches - if (location is Town town) + // reset patch caches + switch (location) { - this.Reflection.GetField(town, "ccRefurbished").SetValue(false); - this.Reflection.GetField(town, "isShowingDestroyedJoja").SetValue(false); - this.Reflection.GetField(town, "isShowingUpgradedPamHouse").SetValue(false); + case Town _: + this.Reflection.GetField(location, "ccRefurbished").SetValue(false); + this.Reflection.GetField(location, "isShowingDestroyedJoja").SetValue(false); + this.Reflection.GetField(location, "isShowingUpgradedPamHouse").SetValue(false); + break; + + case Beach _: + case BeachNightMarket _: + case Forest _: + this.Reflection.GetField(location, "hasShownCCUpgrade").SetValue(false); + break; } // general updates @@ -271,6 +279,9 @@ namespace StardewModdingAPI.Metadata case "data\\farmanimals": // FarmAnimal constructor return this.ReloadFarmAnimalData(); + case "data\\hairdata": // Farmer.GetHairStyleMetadataFile + return this.ReloadHairData(); + case "data\\moviesreactions": // MovieTheater.GetMovieReactions this.Reflection .GetField>(typeof(MovieTheater), "_genericReactions") @@ -388,13 +399,19 @@ namespace StardewModdingAPI.Metadata Game1.shadowTexture = content.Load(key); return true; + case "loosesprites\\suspensionbridge": // SuspensionBridge constructor + return this.ReloadSuspensionBridges(content, key); + /**** ** Content\TileSheets ****/ - case "tilesheets\\critters": // Critter constructor - this.ReloadCritterTextures(content, key); + case "tilesheets\\chairtiles": // Game1.LoadContent + MapSeat.mapChairTexture = content.Load(key); return true; + case "tilesheets\\critters": // Critter constructor + return this.ReloadCritterTextures(content, key) > 0; + case "tilesheets\\crops": // Game1.LoadContent Game1.cropSpriteSheet = content.Load(key); return true; @@ -411,6 +428,10 @@ namespace StardewModdingAPI.Metadata Furniture.furnitureTexture = content.Load(key); return true; + case "tilesheets\\furniturefront": // Game1.LoadContent + Furniture.furnitureFrontTexture = content.Load(key); + return true; + case "tilesheets\\projectiles": // Game1.LoadContent Projectile.projectileSheet = content.Load(key); return true; @@ -612,7 +633,7 @@ namespace StardewModdingAPI.Metadata // update sprites Texture2D texture = content.Load(key); foreach (TAnimal animal in animals) - this.SetSpriteTexture(animal.Sprite, texture); + animal.Sprite.spriteTexture = texture; return true; } @@ -642,7 +663,7 @@ namespace StardewModdingAPI.Metadata // reload asset if (expectedKey == key) - this.SetSpriteTexture(animal.Sprite, texture.Value); + animal.Sprite.spriteTexture = texture.Value; } return texture.IsValueCreated; } @@ -682,9 +703,8 @@ namespace StardewModdingAPI.Metadata Critter[] critters = ( from location in this.GetLocations() - let locCritters = this.Reflection.GetField>(location, "critters").GetValue() - where locCritters != null - from Critter critter in locCritters + where location.critters != null + from Critter critter in location.critters where this.NormalizeAssetNameIgnoringEmpty(critter.sprite?.Texture?.Name) == key select critter ) @@ -695,7 +715,7 @@ namespace StardewModdingAPI.Metadata // update sprites Texture2D texture = content.Load(key); foreach (var entry in critters) - this.SetSpriteTexture(entry.sprite, texture); + entry.sprite.spriteTexture = texture; return critters.Length; } @@ -752,10 +772,7 @@ namespace StardewModdingAPI.Metadata ( from location in this.GetLocations() from grass in location.terrainFeatures.Values.OfType() - let textureName = this.NormalizeAssetNameIgnoringEmpty( - this.Reflection.GetMethod(grass, "textureName").Invoke() - ) - where textureName == key + where this.NormalizeAssetNameIgnoringEmpty(grass.textureName()) == key select grass ) .ToArray(); @@ -764,13 +781,28 @@ namespace StardewModdingAPI.Metadata { Lazy texture = new Lazy(() => content.Load(key)); foreach (Grass grass in grasses) - this.Reflection.GetField>(grass, "texture").SetValue(texture); + grass.texture = texture; return true; } return false; } + /// Reload hair style metadata. + /// Returns whether any assets were reloaded. + /// Derived from the and . + private bool ReloadHairData() + { + if (Farmer.hairStyleMetadataFile == null) + return false; + + Farmer.hairStyleMetadataFile = null; + Farmer.allHairStyleIndices = null; + Farmer.hairStyleMetadata.Clear(); + + return true; + } + /// Reload the disposition data for matching NPCs. /// The content manager through which to reload the asset. /// The asset key to reload. @@ -813,7 +845,7 @@ namespace StardewModdingAPI.Metadata // update sprite foreach (var target in characters) { - this.SetSpriteTexture(target.Npc.Sprite, content.Load(target.Key)); + target.Npc.Sprite.spriteTexture = content.Load(target.Key); propagated[target.Key] = true; } } @@ -877,6 +909,29 @@ namespace StardewModdingAPI.Metadata return players.Any(); } + /// Reload suspension bridge textures. + /// The content manager through which to reload the asset. + /// The asset key to reload. + /// Returns whether any textures were reloaded. + private bool ReloadSuspensionBridges(LocalizedContentManager content, string key) + { + Lazy texture = new Lazy(() => content.Load(key)); + + foreach (GameLocation location in this.GetLocations(buildingInteriors: false)) + { + // get suspension bridges field + var field = this.Reflection.GetField>(location, nameof(IslandNorth.suspensionBridges), required: false); + if (field == null || !typeof(IEnumerable).IsAssignableFrom(field.FieldInfo.FieldType)) + continue; + + // update textures + foreach (SuspensionBridge bridge in field.GetValue()) + this.Reflection.GetField(bridge, "_texture").SetValue(texture.Value); + } + + return texture.IsValueCreated; + } + /// Reload tree textures. /// The content manager through which to reload the asset. /// The asset key to reload. @@ -958,7 +1013,8 @@ namespace StardewModdingAPI.Metadata int lastScheduleTime = villager.Schedule.Keys.Where(p => p <= Game1.timeOfDay).OrderByDescending(p => p).FirstOrDefault(); if (lastScheduleTime != 0) { - villager.scheduleTimeToTry = NPC.NO_TRY; // use time that's passed in to checkSchedule + villager.queuedSchedulePaths.Clear(); + villager.lastAttemptedSchedule = 0; villager.checkSchedule(lastScheduleTime); } } @@ -969,14 +1025,6 @@ namespace StardewModdingAPI.Metadata /**** ** Helpers ****/ - /// Reload the texture for an animated sprite. - /// The animated sprite to update. - /// The texture to set. - private void SetSpriteTexture(AnimatedSprite sprite, Texture2D texture) - { - this.Reflection.GetField(sprite, "spriteTexture").SetValue(texture); - } - /// Get all NPCs in the game (excluding farm animals). private IEnumerable GetCharacters() { -- cgit