Added mod config

master
Mohammad Shoaib 2022-03-21 11:13:55 +05:30
parent 3b4bea69f2
commit 9607a008e0
5 changed files with 34 additions and 28 deletions

View File

@ -15,30 +15,30 @@ namespace stardew_access
helper.ConsoleCommands.Add("readtile", "Toggle read tile feature.", (string commmand, string[] args) => 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) => 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) => 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) => 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 #region Radar Feature
@ -51,9 +51,9 @@ namespace stardew_access
helper.ConsoleCommands.Add("rstereo", "Toggle stereo sound in radar feature.", (string commmand, string[] args) => 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) => helper.ConsoleCommands.Add("rfocus", "Toggle focus mode in radar feature.", (string commmand, string[] args) =>

View File

@ -330,7 +330,7 @@ namespace stardew_access.Features
{ {
string soundName = $"_{post}"; string soundName = $"_{post}";
if (!MainClass.radarStereoSound) if (!MainClass.Config.RadarStereoSound)
soundName = $"_mono{soundName}"; soundName = $"_mono{soundName}";
if (category == CATEGORY.Farmers) // Villagers and farmers if (category == CATEGORY.Farmers) // Villagers and farmers

View File

@ -543,7 +543,7 @@ namespace stardew_access.Features
if (toReturn.Contains("feature")) if (toReturn.Contains("feature"))
toReturn.Replace("feature", ""); toReturn.Replace("feature", "");
} }
else if (terrain.Get() is Flooring && MainClass.readFlooring) else if (terrain.Get() is Flooring && MainClass.Config.ReadFlooring)
{ {
category = CATEGORY.Flooring; category = CATEGORY.Flooring;
Flooring flooring = (Flooring)terrain.Get(); Flooring flooring = (Flooring)terrain.Get();

View File

@ -1,7 +1,13 @@
namespace stardew_access namespace stardew_access
{ {
class ModConfig internal class ModConfig
{ {
public Boolean VerboseCoordinates { get; set; } = true; 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;
} }
} }

View File

@ -12,24 +12,23 @@ namespace stardew_access
{ {
public class MainClass : Mod public class MainClass : Mod
{ {
private ModConfig config; #region Global Vars
private static ModConfig config;
private Harmony? harmony; 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; private static IMonitor monitor;
public static string hudMessageQueryKey = "";
private static Radar radarFeature; private static Radar radarFeature;
private static IScreenReader? screenReader; private static IScreenReader? screenReader;
private static IModHelper modHelper; private static IModHelper modHelper;
internal static ModConfig Config { get => config; set => config = value; }
public static IModHelper ModHelper { get => modHelper; } public static IModHelper ModHelper { get => modHelper; }
public static Radar RadarFeature { get => radarFeature; set => radarFeature = value; } 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() public static IScreenReader GetScreenReader()
{ {
if (screenReader == null) if (screenReader == null)
@ -55,7 +54,8 @@ namespace stardew_access
public override void Entry(IModHelper helper) public override void Entry(IModHelper helper)
{ {
#region Initializations #region Initializations
this.config = helper.ReadConfig<ModConfig>(); Config = helper.ReadConfig<ModConfig>();
SetMonitor(base.Monitor); // Inititalize monitor SetMonitor(base.Monitor); // Inititalize monitor
modHelper = helper; modHelper = helper;
@ -116,13 +116,13 @@ namespace stardew_access
Other.narrateCurrentLocation(); Other.narrateCurrentLocation();
if (snapMouse) if (Config.SnapMouse)
Other.SnapMouseToPlayer(); Other.SnapMouseToPlayer();
if (!ReadTile.isReadingTile && readTile) if (!ReadTile.isReadingTile && Config.ReadTile)
ReadTile.run(); ReadTile.run();
if (!RadarFeature.isRunning && radar) if (!RadarFeature.isRunning && Config.Radar)
RadarFeature.Run(); RadarFeature.Run();
if (!isNarratingHudMessage) if (!isNarratingHudMessage)
@ -179,7 +179,7 @@ namespace stardew_access
if (Equals(e.Button, SButton.K) && !isLeftAltPressed) if (Equals(e.Button, SButton.K) && !isLeftAltPressed)
{ {
string toSpeak; string toSpeak;
if (this.config.VerboseCoordinates) if (Config.VerboseCoordinates)
{ {
toSpeak = $"X: {CurrentPlayer.getPositionX()}, Y: {CurrentPlayer.getPositionY()}"; toSpeak = $"X: {CurrentPlayer.getPositionX()}, Y: {CurrentPlayer.getPositionY()}";
} }
@ -187,7 +187,7 @@ namespace stardew_access
{ {
toSpeak = $"{CurrentPlayer.getPositionX()}, {CurrentPlayer.getPositionY()}"; toSpeak = $"{CurrentPlayer.getPositionX()}, {CurrentPlayer.getPositionY()}";
} }
MainClass.GetScreenReader().Say(toSpeak, true); MainClass.GetScreenReader().Say(toSpeak, true);
} }