fix maps not recognising custom tilesheets added through the SMAPI content API

This commit is contained in:
Jesse Plamondon-Willard 2017-05-16 19:15:28 -04:00
parent f4a2d8100f
commit 11569dac31
2 changed files with 19 additions and 3 deletions

View File

@ -22,13 +22,14 @@ For players:
* Updated mod compatibility list for Stardew Valley 1.2.
For mod developers:
* SMAPI now logs basic context info to simplify troubleshooting.
* Added a `Context.IsWorldReady` flag.
_<small>This is set to `true` when the player has loaded a save and the world is finished initialising. This is set at the same point that `SaveEvents.AfterLoad` and `TimeEvents.AfterDayStarted` are raised, and is mainly useful with events which can be raised before the world is loaded.</small>_
* Added log entries for basic context changes (e.g. loaded save) to simplify troubleshooting.
_<small>This flag is true when a save is loaded and the world is finished initialising, which starts at the same point that `SaveEvents.AfterLoad` and `TimeEvents.AfterDayStarted` are raised. This is mainly useful with events which can be raised before the world is loaded (like update tick).</small>_
* Added a `debug` console command to TrainerMod which lets you pass debug commands to the game (e.g. `debug warp FarmHouse 1 1` warps the player to the farmhouse).
* Added a deprecation warning for mods that don't set the `Name`, `Version`, or `UniqueID` manifest fields. These will be required in SMAPI 2.0.
* Mods can now override `Dispose` if they need to release unmanaged resources.
* Deprecated `GameEvents.GameLoaded` and `GameEvents.FirstUpdateTick`, since any logic in the mod's `Entry` method will happen after the game is loaded.
* Fixed maps not recognising custom tilesheets added through the SMAPI content API.
## 1.12
See [log](https://github.com/Pathoschild/SMAPI/compare/1.11...1.12).

View File

@ -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);
}