From c5e72d545b4eb9cb379dcb92153f612b91fb8eef Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Sat, 22 Jan 2022 10:30:29 +0530 Subject: [PATCH] Added commands for focus mode --- stardew-access/CustomCommands.cs | 125 +++++++++++++++++++++++++------ stardew-access/Features/Radar.cs | 39 +++++++++- stardew-access/ModEntry.cs | 4 +- 3 files changed, 140 insertions(+), 28 deletions(-) diff --git a/stardew-access/CustomCommands.cs b/stardew-access/CustomCommands.cs index 4e45782..d8cf090 100644 --- a/stardew-access/CustomCommands.cs +++ b/stardew-access/CustomCommands.cs @@ -7,53 +7,69 @@ namespace stardew_access internal static void Initialize(IModHelper helper) { - 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.monitor.Log("Read Tile is " + (MainClass.readTile ? "on" : "off"), LogLevel.Info); }); - 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.monitor.Log("Snap Mouse is " + (MainClass.snapMouse ? "on" : "off"), LogLevel.Info); }); - 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.monitor.Log("Radar " + (MainClass.radar ? "on" : "off"), LogLevel.Info); }); - helper.ConsoleCommands.Add("rdebug", "Toggle debugging in radar feature", (string commmand, string[] args) => + #region Radar Feature + helper.ConsoleCommands.Add("rdebug", "Toggle debugging in radar feature.", (string commmand, string[] args) => { MainClass.radarDebug = !MainClass.radarDebug; MainClass.monitor.Log("Radar debugging " + (MainClass.radarDebug ? "on" : "off"), LogLevel.Info); }); - helper.ConsoleCommands.Add("rexclude", "Exclude an object key to radar", (string commmand, string[] args) => + helper.ConsoleCommands.Add("rstereo", "Toggle stereo sound in radar feature.", (string commmand, string[] args) => { - string? keyToAdd = null; + MainClass.radarStereoSound = !MainClass.radarStereoSound; - for (int i = 0; i < args.Count(); i++) { keyToAdd += " " + args[i]; } - - if (keyToAdd != null) - { - keyToAdd = keyToAdd.Trim().ToLower(); - MainClass.radarFeature.exclusions.Add(keyToAdd); - MainClass.monitor.Log($"Added {keyToAdd} key to exclusions.", LogLevel.Info); - } - else - { - MainClass.monitor.Log("Unable to add the key to exclusions.", LogLevel.Info); - } + MainClass.monitor.Log("Stereo sound is " + (MainClass.radarStereoSound ? "on" : "off"), LogLevel.Info); }); - helper.ConsoleCommands.Add("rinclude", "Inlcude an object key to radar", (string commmand, string[] args) => + helper.ConsoleCommands.Add("rfocus", "Toggle focus mode in radar feature.", (string commmand, string[] args) => + { + bool focus = MainClass.radarFeature.toggleFocus(); + + MainClass.monitor.Log("Focus mode is " + (focus? "on" : "off"), LogLevel.Info); + }); + + #region Exclusions + helper.ConsoleCommands.Add("readd", "Add an object key to the exclusions list of radar feature.", (string commmand, string[] args) => + { + string? keyToAdd = null; + + for (int i = 0; i < args.Count(); i++) { keyToAdd += " " + args[i]; } + + if (keyToAdd != null) + { + keyToAdd = keyToAdd.Trim().ToLower(); + MainClass.radarFeature.exclusions.Add(keyToAdd); + MainClass.monitor.Log($"Added {keyToAdd} key to exclusions.", LogLevel.Info); + } + else + { + MainClass.monitor.Log("Unable to add the key to exclusions.", LogLevel.Info); + } + }); + + helper.ConsoleCommands.Add("reremove", "Remove an object key from the exclusions list of radar feature.", (string commmand, string[] args) => { string? keyToAdd = null; @@ -78,7 +94,7 @@ namespace stardew_access } }); - helper.ConsoleCommands.Add("rlist", "List all the exclusions in the radar feature.", (string commmand, string[] args) => + helper.ConsoleCommands.Add("relist", "List all the exclusions in the radar feature.", (string commmand, string[] args) => { if (MainClass.radarFeature.exclusions.Count > 0) { @@ -93,18 +109,79 @@ namespace stardew_access } }); - helper.ConsoleCommands.Add("rcount", "Number of exclusions in the radar feature.", (string commmand, string[] args) => + helper.ConsoleCommands.Add("recount", "Number of exclusions in the radar feature.", (string commmand, string[] args) => { MainClass.monitor.Log($"There are {MainClass.radarFeature.exclusions.Count} exclusiond in the radar feature.", LogLevel.Info); }); + #endregion - helper.ConsoleCommands.Add("rstereo", "Toggle stereo sound in radar feature", (string commmand, string[] args) => + #region Focus + helper.ConsoleCommands.Add("rfadd", "Add an object key to the focus list of radar feature.", (string commmand, string[] args) => + { + string? keyToAdd = null; + + for (int i = 0; i < args.Count(); i++) { keyToAdd += " " + args[i]; } + + if (keyToAdd != null) + { + keyToAdd = keyToAdd.Trim().ToLower(); + MainClass.radarFeature.focus.Add(keyToAdd); + MainClass.monitor.Log($"Added {keyToAdd} key to focus.", LogLevel.Info); + } + else + { + MainClass.monitor.Log("Unable to add the key to focus.", LogLevel.Info); + } + }); + + helper.ConsoleCommands.Add("rfremove", "Remove an object key from the focus list of radar feature.", (string commmand, string[] args) => { - MainClass.radarStereoSound = !MainClass.radarStereoSound; + string? keyToAdd = null; - MainClass.monitor.Log("Stereo sound is " + (MainClass.radarStereoSound ? "on" : "off"), LogLevel.Info); + for (int i = 0; i < args.Count(); i++) { keyToAdd += " " + args[i]; } + + if (keyToAdd != null) + { + keyToAdd = keyToAdd.Trim().ToLower(); + if (MainClass.radarFeature.focus.Contains(keyToAdd)) + { + MainClass.radarFeature.focus.Remove(keyToAdd); + MainClass.monitor.Log($"Removed {keyToAdd} key from focus.", LogLevel.Info); + } + else + { + MainClass.monitor.Log($"Cannot find{keyToAdd} key in focus.", LogLevel.Info); + } + } + else + { + MainClass.monitor.Log("Unable to remove the key from exclusions.", LogLevel.Info); + } }); + helper.ConsoleCommands.Add("rflist", "List all the exclusions in the radar feature.", (string commmand, string[] args) => + { + if (MainClass.radarFeature.focus.Count > 0) + { + for (int i = 0; i < MainClass.radarFeature.focus.Count; i++) + { + MainClass.monitor.Log($"{i + 1}) {MainClass.radarFeature.focus[i]}", LogLevel.Info); + } + } + else + { + MainClass.monitor.Log("No objects found in the focus list.", LogLevel.Info); + } + }); + + helper.ConsoleCommands.Add("rfcount", "Number of exclusions in the radar feature.", (string commmand, string[] args) => + { + MainClass.monitor.Log($"There are {MainClass.radarFeature.focus.Count} objects in the focus list in the radar feature.", LogLevel.Info); + }); + #endregion + + #endregion + helper.ConsoleCommands.Add("refsr", "Refresh screen reader", (string commmand, string[] args) => { MainClass.screenReader.InitializeScreenReader(); diff --git a/stardew-access/Features/Radar.cs b/stardew-access/Features/Radar.cs index 9358638..e21290b 100644 --- a/stardew-access/Features/Radar.cs +++ b/stardew-access/Features/Radar.cs @@ -16,7 +16,10 @@ namespace stardew_access.Game private List furnitures; private List npcs; public List exclusions; + private List temp_exclusions; + public List focus; public bool isRunning; + public bool radarFocus = false; public Radar() { @@ -25,6 +28,8 @@ namespace stardew_access.Game furnitures = new List(); npcs = new List(); exclusions = new List(); + temp_exclusions = new List(); + focus = new List(); exclusions.Add("stone"); exclusions.Add("weed"); @@ -44,7 +49,9 @@ namespace stardew_access.Game public async void run() { - MainClass.monitor.Log($"\n\nRead Tile started", StardewModdingAPI.LogLevel.Debug); + if(MainClass.radarDebug) + MainClass.monitor.Log($"\n\nRead Tile started", StardewModdingAPI.LogLevel.Debug); + isRunning = true; Vector2 currPosition = Game1.player.getTileLocation(); int limit = 5; @@ -54,7 +61,9 @@ namespace stardew_access.Game npcs.Clear(); findTile(currPosition, currPosition, limit); - MainClass.monitor.Log($"\nRead Tile stopped\n\n", StardewModdingAPI.LogLevel.Debug); + if(MainClass.radarDebug) + MainClass.monitor.Log($"\nRead Tile stopped\n\n", StardewModdingAPI.LogLevel.Debug); + await Task.Delay(3000); isRunning = false; } @@ -298,10 +307,36 @@ namespace stardew_access.Game soundName = $"obj{soundName}"; else if (soundType == typeof(ResourceClump)) // Resource CLumps soundName = $"obj{soundName}"; + else if (soundType == typeof(junimoBundle)) // Junimo bundles + soundName = $"obj{soundName}"; else // Default soundName = $"obj{soundName}"; return soundName; } + + public bool toggleFocus() + { + radarFocus = !radarFocus; + + if (radarFocus) + enableFocus(); + else + disableFocus(); + + return radarFocus; + } + + public void enableFocus() + { + temp_exclusions = exclusions; + exclusions.Clear(); + } + + public void disableFocus() + { + exclusions = temp_exclusions; + temp_exclusions.Clear(); + } } } diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 036ae26..e363646 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -15,8 +15,8 @@ namespace stardew_access public static bool readTile = true; public static bool snapMouse = true; public static bool isNarratingHudMessage = false; - public static bool radar = false; - public static bool radarDebug = true; + public static bool radar = true; + public static bool radarDebug = false; public static bool radarStereoSound = true; public static IMonitor? monitor; AutoHotkeyEngine ahk;