summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-05-16 19:15:28 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-05-16 19:15:28 -0400
commit11569dac318a60bedd460b29a3a7991d21db32d3 (patch)
tree081d244fc7bfc5e998e9315b9b833de2d83bd2a8 /src/StardewModdingAPI/Framework
parentf4a2d8100fa6553b79d3f91dfd7b2011ce453b79 (diff)
downloadSMAPI-11569dac318a60bedd460b29a3a7991d21db32d3.tar.gz
SMAPI-11569dac318a60bedd460b29a3a7991d21db32d3.tar.bz2
SMAPI-11569dac318a60bedd460b29a3a7991d21db32d3.zip
fix maps not recognising custom tilesheets added through the SMAPI content API
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-rw-r--r--src/StardewModdingAPI/Framework/SGame.cs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs
index 4f3a29fc..a340b995 100644
--- a/src/StardewModdingAPI/Framework/SGame.cs
+++ b/src/StardewModdingAPI/Framework/SGame.cs
@@ -168,7 +168,7 @@ namespace StardewModdingAPI.Framework
private static Stopwatch _fpsStopwatch => SGame.Reflection.GetPrivateField<Stopwatch>(typeof(Game1), nameof(SGame._fpsStopwatch)).GetValue();
private static float _fps
{
- set { SGame.Reflection.GetPrivateField<float>(typeof(Game1), nameof(_fps)).SetValue(value); }
+ set => SGame.Reflection.GetPrivateField<float>(typeof(Game1), nameof(_fps)).SetValue(value);
}
private static Task _newDayTask => SGame.Reflection.GetPrivateField<Task>(typeof(Game1), nameof(_newDayTask)).GetValue();
private Color bgColor => SGame.Reflection.GetPrivateField<Color>(this, nameof(bgColor)).GetValue();
@@ -202,6 +202,15 @@ namespace StardewModdingAPI.Framework
SGame.Reflection = reflection;
Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; // required by Stardew Valley
+
+ // The game uses the default content manager instead of Game1.CreateContentManager in
+ // several cases (See http://community.playstarbound.com/threads/130058/page-27#post-3159274).
+ // The workaround is...
+ // 1. Override the default content manager.
+ // 2. Since Game1.content isn't initialised yet, and we need one main instance to
+ // support custom map tilesheets, detect when Game1.content is being initialised
+ // and use the same instance.
+ this.Content = new SContentManager(this.Content.ServiceProvider, this.Content.RootDirectory, this.Monitor);
}
/****
@@ -212,6 +221,12 @@ namespace StardewModdingAPI.Framework
/// <param name="rootDirectory">The root directory to search for content.</param>
protected override LocalizedContentManager CreateContentManager(IServiceProvider serviceProvider, string rootDirectory)
{
+ // When Game1.content is being initialised, use SMAPI's main content manager instance.
+ // See comment in SGame constructor.
+ if (Game1.content == null && this.Content is SContentManager mainContentManager)
+ return mainContentManager;
+
+ // build new instance
return new SContentManager(this.Content.ServiceProvider, this.Content.RootDirectory, this.Monitor);
}