From 9c49d090a06c96ff2c1f4978da67e864177c2a2e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 11 Mar 2018 20:03:52 -0400 Subject: reorganise and update core content logic for Stardew Valley 1.3 (#453) --- src/SMAPI/Framework/SGame.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/SMAPI/Framework/SGame.cs') diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index acb3e794..aeaab9ea 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -161,7 +161,7 @@ namespace StardewModdingAPI.Framework ** Accessors *********/ /// SMAPI's content manager. - public SContentManager SContentManager { get; } + public ContentCore ContentCore { get; } /// Whether SMAPI should log more information about the game context. public bool VerboseLogging { get; set; } @@ -190,10 +190,12 @@ namespace StardewModdingAPI.Framework // override content manager this.Monitor?.Log("Overriding content manager...", LogLevel.Trace); - this.SContentManager = new SContentManager(this.Content.ServiceProvider, this.Content.RootDirectory, Thread.CurrentThread.CurrentUICulture, null, this.Monitor, reflection); - this.Content = new ContentManagerShim(this.SContentManager, "SGame.Content"); - Game1.content = new ContentManagerShim(this.SContentManager, "Game1.content"); - reflection.GetField(typeof(Game1), "_temporaryContent").SetValue(new ContentManagerShim(this.SContentManager, "Game1._temporaryContent")); // regenerate value with new content manager + this.ContentCore = new ContentCore(this.Content.ServiceProvider, this.Content.RootDirectory, Thread.CurrentThread.CurrentUICulture, null, this.Monitor, reflection); + this.Content = this.ContentCore.CreateContentManager("SGame.Content"); + Game1.content = this.ContentCore.CreateContentManager("Game1.content"); + + // replace already-created temporary content managers + reflection.GetField(typeof(Game1), "_temporaryContent").SetValue(this.ContentCore.CreateContentManager("Game1._temporaryContent")); // regenerate value with new content manager } /**** @@ -205,7 +207,7 @@ namespace StardewModdingAPI.Framework protected override LocalizedContentManager CreateContentManager(IServiceProvider serviceProvider, string rootDirectory) { // return default if SMAPI's content manager isn't initialised yet - if (this.SContentManager == null) + if (this.ContentCore == null) { this.Monitor?.Log("SMAPI's content manager isn't initialised; skipping content manager interception.", LogLevel.Trace); return base.CreateContentManager(serviceProvider, rootDirectory); @@ -216,7 +218,7 @@ namespace StardewModdingAPI.Framework throw new InvalidOperationException("SMAPI uses a single content manager internally. You can't get a new content manager with a different service provider."); if (rootDirectory != this.Content.RootDirectory) throw new InvalidOperationException($"SMAPI uses a single content manager internally. You can't get a new content manager with a different root directory (current is {this.Content.RootDirectory}, requested {rootDirectory})."); - return new ContentManagerShim(this.SContentManager, "(generated instance)"); + return this.ContentCore.CreateContentManager("(generated instance)"); } /// The method called when the game is updating its state. This happens roughly 60 times per second. -- cgit