minor tweaks

This commit is contained in:
Jesse Plamondon-Willard 2020-08-24 22:23:02 -04:00
parent 3a89040876
commit 915e6d22f1
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
3 changed files with 30 additions and 20 deletions

View File

@ -84,7 +84,7 @@ namespace StardewModdingAPI.Framework
private readonly CommandManager CommandManager = new CommandManager(); private readonly CommandManager CommandManager = new CommandManager();
/// <summary>The underlying game instance.</summary> /// <summary>The underlying game instance.</summary>
private SGame GameInstance; private SGame Game;
/// <summary>Manages input visible to the game.</summary> /// <summary>Manages input visible to the game.</summary>
private SInputState Input => SGame.Input; private SInputState Input => SGame.Input;
@ -249,7 +249,7 @@ namespace StardewModdingAPI.Framework
var multiplayer = new SMultiplayer(this.Monitor, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, this.Reflection, this.OnModMessageReceived, this.Settings.LogNetworkTraffic); var multiplayer = new SMultiplayer(this.Monitor, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, this.Reflection, this.OnModMessageReceived, this.Settings.LogNetworkTraffic);
var modHooks = new SModHooks(this.OnNewDayAfterFade); var modHooks = new SModHooks(this.OnNewDayAfterFade);
SGame.CreateContentManagerImpl = this.CreateContentManager; // must be static since the game accesses it before the SGame constructor is called SGame.CreateContentManagerImpl = this.CreateContentManager; // must be static since the game accesses it before the SGame constructor is called
this.GameInstance = new SGame( this.Game = new SGame(
monitor: this.Monitor, monitor: this.Monitor,
reflection: this.Reflection, reflection: this.Reflection,
eventManager: this.EventManager, eventManager: this.EventManager,
@ -259,12 +259,12 @@ namespace StardewModdingAPI.Framework
); );
// hook game events // hook game events
this.GameInstance.OnGameContentLoaded += this.OnLoadContent; this.Game.OnGameContentLoaded += this.OnLoadContent;
this.GameInstance.OnGameUpdating += this.OnGameUpdating; this.Game.OnGameUpdating += this.OnGameUpdating;
this.GameInstance.OnGameExiting += this.OnGameExiting; this.Game.OnGameExiting += this.OnGameExiting;
this.Translator.SetLocale(this.ContentCore.GetLocale(), this.ContentCore.Language); this.Translator.SetLocale(this.ContentCore.GetLocale(), this.ContentCore.Language);
StardewValley.Program.gamePtr = this.GameInstance; StardewValley.Program.gamePtr = this.Game;
// apply game patches // apply game patches
new GamePatcher(this.Monitor).Apply( new GamePatcher(this.Monitor).Apply(
@ -283,12 +283,12 @@ namespace StardewModdingAPI.Framework
if (this.IsGameRunning) if (this.IsGameRunning)
{ {
this.LogManager.WriteCrashLog(); this.LogManager.WriteCrashLog();
this.GameInstance.Exit(); this.Game.Exit();
} }
}).Start(); }).Start();
// set window titles // set window titles
this.GameInstance.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion}"; this.Game.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion}";
this.LogManager.SetConsoleTitle($"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}"); this.LogManager.SetConsoleTitle($"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}");
} }
catch (Exception ex) catch (Exception ex)
@ -303,7 +303,7 @@ namespace StardewModdingAPI.Framework
this.LogManager.LogSettingsHeader(this.Settings.DeveloperMode, this.Settings.CheckForUpdates); this.LogManager.LogSettingsHeader(this.Settings.DeveloperMode, this.Settings.CheckForUpdates);
// set window titles // set window titles
this.GameInstance.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion}"; this.Game.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion}";
this.LogManager.SetConsoleTitle($"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}"); this.LogManager.SetConsoleTitle($"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion}");
// start game // start game
@ -312,7 +312,7 @@ namespace StardewModdingAPI.Framework
{ {
this.IsGameRunning = true; this.IsGameRunning = true;
StardewValley.Program.releaseBuild = true; // game's debug logic interferes with SMAPI opening the game window StardewValley.Program.releaseBuild = true; // game's debug logic interferes with SMAPI opening the game window
this.GameInstance.Run(); this.Game.Run();
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -351,7 +351,7 @@ namespace StardewModdingAPI.Framework
this.IsGameRunning = false; this.IsGameRunning = false;
this.ContentCore?.Dispose(); this.ContentCore?.Dispose();
this.CancellationToken?.Dispose(); this.CancellationToken?.Dispose();
this.GameInstance?.Dispose(); this.Game?.Dispose();
this.LogManager?.Dispose(); // dispose last to allow for any last-second log messages this.LogManager?.Dispose(); // dispose last to allow for any last-second log messages
// end game (moved from Game1.OnExiting to let us clean up first) // end game (moved from Game1.OnExiting to let us clean up first)
@ -409,7 +409,7 @@ namespace StardewModdingAPI.Framework
// update window titles // update window titles
int modsLoaded = this.ModRegistry.GetAll().Count(); int modsLoaded = this.ModRegistry.GetAll().Count();
this.GameInstance.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion} with {modsLoaded} mods"; this.Game.Window.Title = $"Stardew Valley {Constants.GameVersion} - running SMAPI {Constants.ApiVersion} with {modsLoaded} mods";
this.LogManager.SetConsoleTitle($"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion} with {modsLoaded} mods"); this.LogManager.SetConsoleTitle($"SMAPI {Constants.ApiVersion} - running Stardew Valley {Constants.GameVersion} with {modsLoaded} mods");
} }
@ -420,7 +420,7 @@ namespace StardewModdingAPI.Framework
this.Input.TrueUpdate(); this.Input.TrueUpdate();
// init watchers // init watchers
this.Watchers = new WatcherCore(this.Input); this.Watchers = new WatcherCore(this.Input, this.Game.GetObservableLocations());
// validate XNB integrity // validate XNB integrity
if (!this.ValidateContentIntegrity()) if (!this.ValidateContentIntegrity())
@ -477,7 +477,7 @@ namespace StardewModdingAPI.Framework
// this too. For example, doing this after mod event suppression would prevent the // this too. For example, doing this after mod event suppression would prevent the
// user from doing anything on the overnight shipping screen. // user from doing anything on the overnight shipping screen.
SInputState inputState = this.Input; SInputState inputState = this.Input;
if (this.GameInstance.IsActive) if (this.Game.IsActive)
inputState.TrueUpdate(); inputState.TrueUpdate();
/********* /*********
@ -760,7 +760,7 @@ namespace StardewModdingAPI.Framework
/********* /*********
** Input events (if window has focus) ** Input events (if window has focus)
*********/ *********/
if (this.GameInstance.IsActive) if (this.Game.IsActive)
{ {
// raise events // raise events
bool isChatInput = Game1.IsChatting || (Context.IsMultiplayer && Context.IsWorldReady && Game1.activeClickableMenu == null && Game1.currentMinigame == null && inputState.IsAnyDown(Game1.options.chatButton)); bool isChatInput = Game1.IsChatting || (Context.IsMultiplayer && Context.IsWorldReady && Game1.activeClickableMenu == null && Game1.currentMinigame == null && inputState.IsAnyDown(Game1.options.chatButton));
@ -1071,7 +1071,6 @@ namespace StardewModdingAPI.Framework
private LocalizedContentManager CreateContentManager(IServiceProvider serviceProvider, string rootDirectory) private LocalizedContentManager CreateContentManager(IServiceProvider serviceProvider, string rootDirectory)
{ {
// Game1._temporaryContent initializing from SGame constructor // Game1._temporaryContent initializing from SGame constructor
// NOTE: this method is called before the SGame constructor runs. Don't depend on anything being initialized at this point.
if (this.ContentCore == null) if (this.ContentCore == null)
{ {
this.ContentCore = new ContentCoordinator(serviceProvider, rootDirectory, Thread.CurrentThread.CurrentUICulture, this.Monitor, this.Reflection, this.Toolkit.JsonHelper, this.InitializeBeforeFirstAssetLoaded); this.ContentCore = new ContentCoordinator(serviceProvider, rootDirectory, Thread.CurrentThread.CurrentUICulture, this.Monitor, this.Reflection, this.Toolkit.JsonHelper, this.InitializeBeforeFirstAssetLoaded);

View File

@ -69,7 +69,7 @@ namespace StardewModdingAPI.Framework
/********* /*********
** Protected methods ** Public methods
*********/ *********/
/// <summary>Construct an instance.</summary> /// <summary>Construct an instance.</summary>
/// <param name="monitor">Encapsulates monitoring and logging for SMAPI.</param> /// <param name="monitor">Encapsulates monitoring and logging for SMAPI.</param>
@ -78,7 +78,7 @@ namespace StardewModdingAPI.Framework
/// <param name="modHooks">Handles mod hooks provided by the game.</param> /// <param name="modHooks">Handles mod hooks provided by the game.</param>
/// <param name="multiplayer">The core multiplayer logic.</param> /// <param name="multiplayer">The core multiplayer logic.</param>
/// <param name="exitGameImmediately">Immediately exit the game without saving. This should only be invoked when an irrecoverable fatal error happens that risks save corruption or game-breaking bugs.</param> /// <param name="exitGameImmediately">Immediately exit the game without saving. This should only be invoked when an irrecoverable fatal error happens that risks save corruption or game-breaking bugs.</param>
internal SGame(Monitor monitor, Reflector reflection, EventManager eventManager, SModHooks modHooks, SMultiplayer multiplayer, Action<string> exitGameImmediately) public SGame(Monitor monitor, Reflector reflection, EventManager eventManager, SModHooks modHooks, SMultiplayer multiplayer, Action<string> exitGameImmediately)
{ {
// init XNA // init XNA
Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef; Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef;
@ -96,6 +96,16 @@ namespace StardewModdingAPI.Framework
this.ExitGameImmediately = exitGameImmediately; this.ExitGameImmediately = exitGameImmediately;
} }
/// <summary>Get the observable location list.</summary>
public ObservableCollection<GameLocation> GetObservableLocations()
{
return (ObservableCollection<GameLocation>)Game1.locations;
}
/*********
** Protected methods
*********/
/// <summary>Load content when the game is launched.</summary> /// <summary>Load content when the game is launched.</summary>
protected override void LoadContent() protected override void LoadContent()
{ {

View File

@ -56,7 +56,8 @@ namespace StardewModdingAPI.Framework
*********/ *********/
/// <summary>Construct an instance.</summary> /// <summary>Construct an instance.</summary>
/// <param name="inputState">Manages input visible to the game.</param> /// <param name="inputState">Manages input visible to the game.</param>
public WatcherCore(SInputState inputState) /// <param name="gameLocations">The observable list of game locations.</param>
public WatcherCore(SInputState inputState, ObservableCollection<GameLocation> gameLocations)
{ {
// init watchers // init watchers
this.CursorWatcher = WatcherFactory.ForEquatable(() => inputState.CursorPosition); this.CursorWatcher = WatcherFactory.ForEquatable(() => inputState.CursorPosition);
@ -65,7 +66,7 @@ namespace StardewModdingAPI.Framework
this.WindowSizeWatcher = WatcherFactory.ForEquatable(() => new Point(Game1.viewport.Width, Game1.viewport.Height)); this.WindowSizeWatcher = WatcherFactory.ForEquatable(() => new Point(Game1.viewport.Width, Game1.viewport.Height));
this.TimeWatcher = WatcherFactory.ForEquatable(() => Game1.timeOfDay); this.TimeWatcher = WatcherFactory.ForEquatable(() => Game1.timeOfDay);
this.ActiveMenuWatcher = WatcherFactory.ForReference(() => Game1.activeClickableMenu); this.ActiveMenuWatcher = WatcherFactory.ForReference(() => Game1.activeClickableMenu);
this.LocationsWatcher = new WorldLocationsTracker((ObservableCollection<GameLocation>)Game1.locations, MineShaft.activeMines); this.LocationsWatcher = new WorldLocationsTracker(gameLocations, MineShaft.activeMines);
this.LocaleWatcher = WatcherFactory.ForGenericEquality(() => LocalizedContentManager.CurrentLanguageCode); this.LocaleWatcher = WatcherFactory.ForGenericEquality(() => LocalizedContentManager.CurrentLanguageCode);
this.Watchers.AddRange(new IWatcher[] this.Watchers.AddRange(new IWatcher[]
{ {