diff --git a/CJBCheatsMenu/Framework/CJBCheatsMenuAPI.cs b/CJBCheatsMenu/Framework/CJBCheatsMenuAPI.cs new file mode 100644 index 00000000..b651dfa2 --- /dev/null +++ b/CJBCheatsMenu/Framework/CJBCheatsMenuAPI.cs @@ -0,0 +1,42 @@ +using CJBCheatsMenu.Framework.Models; +using StardewModdingAPI; +using StardewModdingAPI.Utilities; +using StardewValley; + +namespace CJBCheatsMenu.Framework; + +/// +public sealed class CJBCheatsMenuAPI : ICJBCheatsMenuAPI +{ + /********* + ** Fields + *********/ + /// Manages the cheat implementations. + private readonly CheatManager Cheats; + + /// The mod configuration. + private readonly ModConfig Config; + + /// Encapsulates monitoring and logging. + private readonly IMonitor Monitor; + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The cheats helper. + /// The mod configuration. + /// Encapsulates monitoring and logging. + internal CJBCheatsMenuAPI(CheatManager cheats, ModConfig config, IMonitor monitor) + { + this.Cheats = cheats; + this.Config = config; + this.Monitor = monitor; + } + + /// + public void OpenCheatsMenu(MenuTab? tab) + { + Game1.activeClickableMenu = new CheatsMenu(tab ?? this.Config.DefaultTab, this.Cheats, this.Monitor, true); + } +} diff --git a/CJBCheatsMenu/ICJBCheatsMenuAPI.cs b/CJBCheatsMenu/ICJBCheatsMenuAPI.cs new file mode 100644 index 00000000..ffbe5bd5 --- /dev/null +++ b/CJBCheatsMenu/ICJBCheatsMenuAPI.cs @@ -0,0 +1,14 @@ +using CJBCheatsMenu.Framework; +using StardewValley; + +namespace CJBCheatsMenu; + +/// The API which lets other mods interact with CJB Cheats Menu. +public interface ICJBCheatsMenuAPI +{ + /// + /// Open the cheats menu. + /// + /// The initial tab to display, or opens the default. + void OpenCheatsMenu(MenuTab? tab); +} diff --git a/CJBCheatsMenu/Framework/MenuTab.cs b/CJBCheatsMenu/MenuTab.cs similarity index 91% rename from CJBCheatsMenu/Framework/MenuTab.cs rename to CJBCheatsMenu/MenuTab.cs index 47358d35..4ffdcaad 100644 --- a/CJBCheatsMenu/Framework/MenuTab.cs +++ b/CJBCheatsMenu/MenuTab.cs @@ -1,7 +1,7 @@ -namespace CJBCheatsMenu.Framework; +namespace CJBCheatsMenu; /// A tab in the cheat menu. -internal enum MenuTab +public enum MenuTab { /// The 'player & tools' tab. PlayerAndTools, diff --git a/CJBCheatsMenu/ModEntry.cs b/CJBCheatsMenu/ModEntry.cs index f9e0acf5..e66eeceb 100644 --- a/CJBCheatsMenu/ModEntry.cs +++ b/CJBCheatsMenu/ModEntry.cs @@ -72,6 +72,11 @@ public override void Entry(IModHelper helper) helper.Events.World.LocationListChanged += this.OnLocationListChanged; } + /// + public override object GetApi() + { + return new CJBCheatsMenuAPI(this.Cheats.Value, this.Config, this.Monitor); + } /********* ** Private methods @@ -141,7 +146,7 @@ private void OnButtonsChanged(object? sender, ButtonsChangedEventArgs e) { this.Monitor.Log("Received menu open key."); CommonHelper.WarnOnGameMenuKeyConflict(this.Helper.Input, this.Monitor, this.Config.OpenMenuKey, "cheats menu"); - Game1.activeClickableMenu = new CheatsMenu(this.Config.DefaultTab, this.Cheats.Value, this.Monitor, isNewMenu: true); + this.OpenCheatsMenu(); } } @@ -216,6 +221,11 @@ private ModData LoadModData() return new ModData(null, null); } + private void OpenCheatsMenu() + { + Game1.activeClickableMenu = new CheatsMenu(this.Config.DefaultTab, this.Cheats.Value, this.Monitor, true); + } + /// Reset the cached location list. private void ResetLocationCache() {