From 9607a008e01fad51500bcdecce6d1b19b42ca41d Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Date: Mon, 21 Mar 2022 11:13:55 +0530 Subject: [PATCH] Added mod config --- stardew-access/CustomCommands.cs | 20 +++++++++---------- stardew-access/Features/Radar.cs | 2 +- stardew-access/Features/ReadTile.cs | 2 +- stardew-access/ModConfig.cs | 8 +++++++- stardew-access/ModEntry.cs | 30 ++++++++++++++--------------- 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/stardew-access/CustomCommands.cs b/stardew-access/CustomCommands.cs index db08520..eb00255 100644 --- a/stardew-access/CustomCommands.cs +++ b/stardew-access/CustomCommands.cs @@ -15,30 +15,30 @@ namespace stardew_access helper.ConsoleCommands.Add("readtile", "Toggle read tile feature.", (string commmand, string[] args) => { - MainClass.readTile = !MainClass.readTile; + MainClass.Config.ReadTile = !MainClass.Config.ReadTile; - MainClass.DebugLog("Read Tile is " + (MainClass.readTile ? "on" : "off")); + MainClass.DebugLog("Read Tile is " + (MainClass.Config.ReadTile ? "on" : "off")); }); helper.ConsoleCommands.Add("snapmouse", "Toggle snap mouse feature.", (string commmand, string[] args) => { - MainClass.snapMouse = !MainClass.snapMouse; + MainClass.Config.SnapMouse = !MainClass.Config.SnapMouse; - MainClass.DebugLog("Snap Mouse is " + (MainClass.snapMouse ? "on" : "off")); + MainClass.DebugLog("Snap Mouse is " + (MainClass.Config.SnapMouse ? "on" : "off")); }); helper.ConsoleCommands.Add("flooring", "Toggle flooring in read tile.", (string commmand, string[] args) => { - MainClass.readFlooring = !MainClass.readFlooring; + MainClass.Config.ReadFlooring = !MainClass.Config.ReadFlooring; - MainClass.DebugLog("Flooring is " + (MainClass.readFlooring ? "on" : "off")); + MainClass.DebugLog("Flooring is " + (MainClass.Config.ReadFlooring ? "on" : "off")); }); helper.ConsoleCommands.Add("radar", "Toggle radar feature.", (string commmand, string[] args) => { - MainClass.radar = !MainClass.radar; + MainClass.Config.Radar = !MainClass.Config.Radar; - MainClass.DebugLog("Radar " + (MainClass.radar ? "on" : "off")); + MainClass.DebugLog("Radar " + (MainClass.Config.Radar ? "on" : "off")); }); #region Radar Feature @@ -51,9 +51,9 @@ namespace stardew_access helper.ConsoleCommands.Add("rstereo", "Toggle stereo sound in radar feature.", (string commmand, string[] args) => { - MainClass.radarStereoSound = !MainClass.radarStereoSound; + MainClass.Config.RadarStereoSound = !MainClass.Config.RadarStereoSound; - MainClass.DebugLog("Stereo sound is " + (MainClass.radarStereoSound ? "on" : "off")); + MainClass.DebugLog("Stereo sound is " + (MainClass.Config.RadarStereoSound ? "on" : "off")); }); helper.ConsoleCommands.Add("rfocus", "Toggle focus mode in radar feature.", (string commmand, string[] args) => diff --git a/stardew-access/Features/Radar.cs b/stardew-access/Features/Radar.cs index 4fcba88..e0a708e 100644 --- a/stardew-access/Features/Radar.cs +++ b/stardew-access/Features/Radar.cs @@ -330,7 +330,7 @@ namespace stardew_access.Features { string soundName = $"_{post}"; - if (!MainClass.radarStereoSound) + if (!MainClass.Config.RadarStereoSound) soundName = $"_mono{soundName}"; if (category == CATEGORY.Farmers) // Villagers and farmers diff --git a/stardew-access/Features/ReadTile.cs b/stardew-access/Features/ReadTile.cs index 44537cf..56446aa 100644 --- a/stardew-access/Features/ReadTile.cs +++ b/stardew-access/Features/ReadTile.cs @@ -543,7 +543,7 @@ namespace stardew_access.Features if (toReturn.Contains("feature")) toReturn.Replace("feature", ""); } - else if (terrain.Get() is Flooring && MainClass.readFlooring) + else if (terrain.Get() is Flooring && MainClass.Config.ReadFlooring) { category = CATEGORY.Flooring; Flooring flooring = (Flooring)terrain.Get(); diff --git a/stardew-access/ModConfig.cs b/stardew-access/ModConfig.cs index e671468..a02a089 100644 --- a/stardew-access/ModConfig.cs +++ b/stardew-access/ModConfig.cs @@ -1,7 +1,13 @@ namespace stardew_access { - class ModConfig + internal class ModConfig { public Boolean VerboseCoordinates { get; set; } = true; + public Boolean ReadTile { get; set; } = true; + public Boolean SnapMouse { get; set; } = true; + public Boolean Radar { get; set; } = false; + public Boolean RadarStereoSound { get; set; } = true; + public Boolean ReadFlooring { get; set; } = false; + } } diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 117524a..2ec6c4d 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -12,24 +12,23 @@ namespace stardew_access { public class MainClass : Mod { - private ModConfig config; + #region Global Vars + private static ModConfig config; private Harmony? harmony; - public static bool readTile = true; - public static bool snapMouse = true; - public static bool isNarratingHudMessage = false; - public static bool radar = false; - public static bool radarDebug = false; - public static bool radarStereoSound = true; - public static bool readFlooring = false; private static IMonitor monitor; - public static string hudMessageQueryKey = ""; private static Radar radarFeature; private static IScreenReader? screenReader; private static IModHelper modHelper; + internal static ModConfig Config { get => config; set => config = value; } public static IModHelper ModHelper { get => modHelper; } public static Radar RadarFeature { get => radarFeature; set => radarFeature = value; } + public static string hudMessageQueryKey = ""; + public static bool isNarratingHudMessage = false; + public static bool radarDebug = false; + #endregion + public static IScreenReader GetScreenReader() { if (screenReader == null) @@ -55,7 +54,8 @@ namespace stardew_access public override void Entry(IModHelper helper) { #region Initializations - this.config = helper.ReadConfig(); + Config = helper.ReadConfig(); + SetMonitor(base.Monitor); // Inititalize monitor modHelper = helper; @@ -116,13 +116,13 @@ namespace stardew_access Other.narrateCurrentLocation(); - if (snapMouse) + if (Config.SnapMouse) Other.SnapMouseToPlayer(); - if (!ReadTile.isReadingTile && readTile) + if (!ReadTile.isReadingTile && Config.ReadTile) ReadTile.run(); - if (!RadarFeature.isRunning && radar) + if (!RadarFeature.isRunning && Config.Radar) RadarFeature.Run(); if (!isNarratingHudMessage) @@ -179,7 +179,7 @@ namespace stardew_access if (Equals(e.Button, SButton.K) && !isLeftAltPressed) { string toSpeak; - if (this.config.VerboseCoordinates) + if (Config.VerboseCoordinates) { toSpeak = $"X: {CurrentPlayer.getPositionX()}, Y: {CurrentPlayer.getPositionY()}"; } @@ -187,7 +187,7 @@ namespace stardew_access { toSpeak = $"{CurrentPlayer.getPositionX()}, {CurrentPlayer.getPositionY()}"; } - + MainClass.GetScreenReader().Say(toSpeak, true); }