summaryrefslogtreecommitdiff
path: root/src/SMAPI/Metadata
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-03-11 19:09:08 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-03-11 19:09:08 -0400
commit41715cefcde3c838bb079cb37aac5a3b2dcb1004 (patch)
tree88d5d6c035acb9a2b48fb60f635ccb2156788e9f /src/SMAPI/Metadata
parent80315ec46695d9c2b1121a0a6208105d7e165e89 (diff)
downloadSMAPI-41715cefcde3c838bb079cb37aac5a3b2dcb1004.tar.gz
SMAPI-41715cefcde3c838bb079cb37aac5a3b2dcb1004.tar.bz2
SMAPI-41715cefcde3c838bb079cb37aac5a3b2dcb1004.zip
add initial compatibility with Stardew Valley 1.3 (#453)
Diffstat (limited to 'src/SMAPI/Metadata')
-rw-r--r--src/SMAPI/Metadata/CoreAssets.cs38
1 files changed, 34 insertions, 4 deletions
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
*********/
/// <summary>Initialise the core asset data.</summary>
/// <param name="getNormalisedPath">Normalises an asset key to match the cache key.</param>
- public CoreAssets(Func<string, string> getNormalisedPath)
+ /// <param name="reflection">Simplifies access to private code.</param>
+ public CoreAssets(Func<string, string> 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<Lazy<Texture2D>>(typeof(Bush), "texture").SetValue(new Lazy<Texture2D>(() => content.Load<Texture2D>(key))),
+
+ // from Farm
+ ["Buildings\\houses"] = (content, key) => reflection.GetField<Texture2D>(typeof(Farm), nameof(Farm.houseTextures)).SetValue(content.Load<Texture2D>(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<Texture2D>(key),
@@ -107,6 +128,7 @@ namespace StardewModdingAPI.Metadata
if (Game1.player != null && !Game1.player.isMale)
Game1.player.FarmerRenderer = new FarmerRenderer(content.Load<Texture2D>(key));
},
+#endif
// from Flooring
["TerrainFeatures\\Flooring"] = (content, key) => Flooring.floorsTexture = content.Load<Texture2D>(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<Texture2D>(() => content.Load<Texture2D>(key));
+#else
Texture2D texture = content.Load<Texture2D>(key);
foreach (Building building in buildings)
building.texture = texture;
+#endif
+
return true;
}
return false;
@@ -162,9 +190,11 @@ namespace StardewModdingAPI.Metadata
/// <summary>Get all player-constructed buildings in the world.</summary>
private IEnumerable<Building> GetAllBuildings()
{
- return Game1.locations
- .OfType<BuildableGameLocation>()
- .SelectMany(p => p.buildings);
+ foreach (BuildableGameLocation location in Game1.locations.OfType<BuildableGameLocation>())
+ {
+ foreach (Building building in location.buildings)
+ yield return building;
+ }
}
}
}