summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/SCore.cs31
-rw-r--r--src/SMAPI/Framework/SGame.cs14
-rw-r--r--src/SMAPI/Framework/WatcherCore.cs5
3 files changed, 30 insertions, 20 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index c4fb3b5d..a6067867 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -84,7 +84,7 @@ namespace StardewModdingAPI.Framework
private readonly CommandManager CommandManager = new CommandManager();
/// <summary>The underlying game instance.</summary>
- private SGame GameInstance;
+ private SGame Game;
/// <summary>Manages input visible to the game.</summary>
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 modHooks = new SModHooks(this.OnNewDayAfterFade);
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,
reflection: this.Reflection,
eventManager: this.EventManager,
@@ -259,12 +259,12 @@ namespace StardewModdingAPI.Framework
);
// hook game events
- this.GameInstance.OnGameContentLoaded += this.OnLoadContent;
- this.GameInstance.OnGameUpdating += this.OnGameUpdating;
- this.GameInstance.OnGameExiting += this.OnGameExiting;
+ this.Game.OnGameContentLoaded += this.OnLoadContent;
+ this.Game.OnGameUpdating += this.OnGameUpdating;
+ this.Game.OnGameExiting += this.OnGameExiting;
this.Translator.SetLocale(this.ContentCore.GetLocale(), this.ContentCore.Language);
- StardewValley.Program.gamePtr = this.GameInstance;
+ StardewValley.Program.gamePtr = this.Game;
// apply game patches
new GamePatcher(this.Monitor).Apply(
@@ -283,12 +283,12 @@ namespace StardewModdingAPI.Framework
if (this.IsGameRunning)
{
this.LogManager.WriteCrashLog();
- this.GameInstance.Exit();
+ this.Game.Exit();
}
}).Start();
// 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}");
}
catch (Exception ex)
@@ -303,7 +303,7 @@ namespace StardewModdingAPI.Framework
this.LogManager.LogSettingsHeader(this.Settings.DeveloperMode, this.Settings.CheckForUpdates);
// 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}");
// start game
@@ -312,7 +312,7 @@ namespace StardewModdingAPI.Framework
{
this.IsGameRunning = true;
StardewValley.Program.releaseBuild = true; // game's debug logic interferes with SMAPI opening the game window
- this.GameInstance.Run();
+ this.Game.Run();
}
catch (Exception ex)
{
@@ -351,7 +351,7 @@ namespace StardewModdingAPI.Framework
this.IsGameRunning = false;
this.ContentCore?.Dispose();
this.CancellationToken?.Dispose();
- this.GameInstance?.Dispose();
+ this.Game?.Dispose();
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)
@@ -409,7 +409,7 @@ namespace StardewModdingAPI.Framework
// update window titles
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");
}
@@ -420,7 +420,7 @@ namespace StardewModdingAPI.Framework
this.Input.TrueUpdate();
// init watchers
- this.Watchers = new WatcherCore(this.Input);
+ this.Watchers = new WatcherCore(this.Input, this.Game.GetObservableLocations());
// validate XNB integrity
if (!this.ValidateContentIntegrity())
@@ -477,7 +477,7 @@ namespace StardewModdingAPI.Framework
// this too. For example, doing this after mod event suppression would prevent the
// user from doing anything on the overnight shipping screen.
SInputState inputState = this.Input;
- if (this.GameInstance.IsActive)
+ if (this.Game.IsActive)
inputState.TrueUpdate();
/*********
@@ -760,7 +760,7 @@ namespace StardewModdingAPI.Framework
/*********
** Input events (if window has focus)
*********/
- if (this.GameInstance.IsActive)
+ if (this.Game.IsActive)
{
// raise events
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)
{
// 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)
{
this.ContentCore = new ContentCoordinator(serviceProvider, rootDirectory, Thread.CurrentThread.CurrentUICulture, this.Monitor, this.Reflection, this.Toolkit.JsonHelper, this.InitializeBeforeFirstAssetLoaded);
diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs
index 966fbcdd..9f8a07e6 100644
--- a/src/SMAPI/Framework/SGame.cs
+++ b/src/SMAPI/Framework/SGame.cs
@@ -69,7 +69,7 @@ namespace StardewModdingAPI.Framework
/*********
- ** Protected methods
+ ** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <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="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>
- 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
Game1.graphics.GraphicsProfile = GraphicsProfile.HiDef;
@@ -96,6 +96,16 @@ namespace StardewModdingAPI.Framework
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>
protected override void LoadContent()
{
diff --git a/src/SMAPI/Framework/WatcherCore.cs b/src/SMAPI/Framework/WatcherCore.cs
index c89efa44..2a5d1ee6 100644
--- a/src/SMAPI/Framework/WatcherCore.cs
+++ b/src/SMAPI/Framework/WatcherCore.cs
@@ -56,7 +56,8 @@ namespace StardewModdingAPI.Framework
*********/
/// <summary>Construct an instance.</summary>
/// <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
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.TimeWatcher = WatcherFactory.ForEquatable(() => Game1.timeOfDay);
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.Watchers.AddRange(new IWatcher[]
{