Code cleanup

master
Mohammad Shoaib 2022-03-29 19:57:38 +05:30
parent 5d8912ae7c
commit d24c224d1d
10 changed files with 113 additions and 115 deletions

View File

@ -67,9 +67,8 @@ namespace stardew_access.Features
Game1.setMousePosition(x, y); Game1.setMousePosition(x, y);
} }
public static async void narrateHudMessages() public static void narrateHudMessages()
{ {
MainClass.isNarratingHudMessage = true;
try try
{ {
if (Game1.hudMessages.Count > 0) if (Game1.hudMessages.Count > 0)
@ -99,8 +98,6 @@ namespace stardew_access.Features
MainClass.ErrorLog($"Unable to narrate hud messages:\n{e.Message}\n{e.StackTrace}"); MainClass.ErrorLog($"Unable to narrate hud messages:\n{e.Message}\n{e.StackTrace}");
} }
await Task.Delay(300);
MainClass.isNarratingHudMessage = false;
} }
} }
} }

View File

@ -96,12 +96,11 @@ namespace stardew_access.Features
*/ */
} }
public async void Run() public void Run()
{ {
if (MainClass.radarDebug) if (MainClass.radarDebug)
MainClass.DebugLog($"\n\nRead Tile started"); MainClass.DebugLog($"\n\nRead Tile started");
isRunning = true;
Vector2 currPosition = Game1.player.getTileLocation(); Vector2 currPosition = Game1.player.getTileLocation();
closed.Clear(); closed.Clear();
@ -112,9 +111,6 @@ namespace stardew_access.Features
if (MainClass.radarDebug) if (MainClass.radarDebug)
MainClass.DebugLog($"\nRead Tile stopped\n\n"); MainClass.DebugLog($"\nRead Tile stopped\n\n");
await Task.Delay(delay);
isRunning = false;
} }
/// <summary> /// <summary>

View File

@ -22,10 +22,8 @@ namespace stardew_access.Features
isReadingTile = false; isReadingTile = false;
} }
public static async void run(bool manuallyTriggered = false, bool playersPosition = false) public static void run(bool manuallyTriggered = false, bool playersPosition = false)
{ {
isReadingTile = true;
try try
{ {
Vector2 tile; Vector2 tile;
@ -82,9 +80,6 @@ namespace stardew_access.Features
{ {
MainClass.ErrorLog($"Error in Read Tile:\n{e.Message}\n{e.StackTrace}"); MainClass.ErrorLog($"Error in Read Tile:\n{e.Message}\n{e.StackTrace}");
} }
await Task.Delay(100);
isReadingTile = false;
} }
///<summary>Returns the name of the object at tile alongwith it's category's name</summary> ///<summary>Returns the name of the object at tile alongwith it's category's name</summary>

View File

@ -170,7 +170,7 @@ namespace stardew_access
#region Chat Menu Patches #region Chat Menu Patches
harmony.Patch( harmony.Patch(
original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }), original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }),
postfix: new HarmonyMethod(typeof(ChatManuPatches), nameof(ChatManuPatches.ChatBoxPatch)) postfix: new HarmonyMethod(typeof(ChatMenuPatches), nameof(ChatMenuPatches.ChatBoxPatch))
); );
#endregion #endregion

View File

@ -120,14 +120,24 @@ namespace stardew_access
Other.SnapMouseToPlayer(); Other.SnapMouseToPlayer();
if (!ReadTile.isReadingTile && Config.ReadTile) if (!ReadTile.isReadingTile && Config.ReadTile)
{
ReadTile.isReadingTile = true;
ReadTile.run(); ReadTile.run();
Task.Delay(100).ContinueWith(_ => { ReadTile.isReadingTile = false; });
}
if (!RadarFeature.isRunning && Config.Radar) if (!RadarFeature.isRunning && Config.Radar)
{
RadarFeature.isRunning = true;
RadarFeature.Run(); RadarFeature.Run();
Task.Delay(RadarFeature.delay).ContinueWith(_ => { RadarFeature.isRunning = false; });
}
if (!isNarratingHudMessage) if (!isNarratingHudMessage)
{ {
isNarratingHudMessage = true;
Other.narrateHudMessages(); Other.narrateHudMessages();
Task.Delay(300).ContinueWith(_ => { isNarratingHudMessage = false; });
} }
} }

View File

@ -1,10 +1,9 @@
using StardewModdingAPI; using StardewValley;
using StardewValley;
using StardewValley.Menus; using StardewValley.Menus;
namespace stardew_access.Patches namespace stardew_access.Patches
{ {
internal class ChatManuPatches internal class ChatMenuPatches
{ {
private static int currentChatMessageIndex = 0; private static int currentChatMessageIndex = 0;
private static bool isChatRunning = false; private static bool isChatRunning = false;
@ -25,11 +24,15 @@ namespace stardew_access.Patches
#region To narrate previous and next chat messages #region To narrate previous and next chat messages
if (isNextArrowPressed && !isChatRunning) if (isNextArrowPressed && !isChatRunning)
{ {
isChatRunning = true;
CycleThroughChatMessages(true, ___messages); CycleThroughChatMessages(true, ___messages);
Task.Delay(200).ContinueWith(_ => { isChatRunning = false; });
} }
else if (isPrevArrowPressed && !isChatRunning) else if (isPrevArrowPressed && !isChatRunning)
{ {
isChatRunning = true;
CycleThroughChatMessages(false, ___messages); CycleThroughChatMessages(false, ___messages);
Task.Delay(200).ContinueWith(_ => { isChatRunning = false; });
} }
#endregion #endregion
} }
@ -52,9 +55,8 @@ namespace stardew_access.Patches
} }
} }
private static async void CycleThroughChatMessages(bool increase, List<ChatMessage> ___messages) private static void CycleThroughChatMessages(bool increase, List<ChatMessage> ___messages)
{ {
isChatRunning = true;
string toSpeak = " "; string toSpeak = " ";
if (increase) if (increase)
{ {
@ -78,8 +80,6 @@ namespace stardew_access.Patches
}); });
MainClass.GetScreenReader().Say(toSpeak, true); MainClass.GetScreenReader().Say(toSpeak, true);
await Task.Delay(200);
isChatRunning = false;
} }
} }
} }

View File

@ -1,5 +1,4 @@
using StardewModdingAPI; using StardewValley;
using StardewValley;
using StardewValley.Locations; using StardewValley.Locations;
using StardewValley.Menus; using StardewValley.Menus;
using StardewValley.Objects; using StardewValley.Objects;
@ -104,15 +103,21 @@ namespace stardew_access.Patches
if (isIPressed && !isUsingCustomButtons) if (isIPressed && !isUsingCustomButtons)
{ {
isUsingCustomButtons = true;
JunimoNoteCustomButtons(__instance, ___currentPageBundle, 0, isLeftShiftPressed); JunimoNoteCustomButtons(__instance, ___currentPageBundle, 0, isLeftShiftPressed);
Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; });
} }
else if (isVPressed && !isUsingCustomButtons) else if (isVPressed && !isUsingCustomButtons)
{ {
isUsingCustomButtons = true;
JunimoNoteCustomButtons(__instance, ___currentPageBundle, 1, isLeftShiftPressed); JunimoNoteCustomButtons(__instance, ___currentPageBundle, 1, isLeftShiftPressed);
Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; });
} }
else if (isCPressed && !isUsingCustomButtons) else if (isCPressed && !isUsingCustomButtons)
{ {
isUsingCustomButtons = true;
JunimoNoteCustomButtons(__instance, ___currentPageBundle, 2, isLeftShiftPressed); JunimoNoteCustomButtons(__instance, ___currentPageBundle, 2, isLeftShiftPressed);
Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; });
} }
else if (isBackPressed && __instance.backButton != null && !__instance.backButton.containsPoint(x, y)) else if (isBackPressed && __instance.backButton != null && !__instance.backButton.containsPoint(x, y))
{ {
@ -133,9 +138,8 @@ namespace stardew_access.Patches
} }
} }
private static async void JunimoNoteCustomButtons(JunimoNoteMenu __instance, Bundle ___currentPageBundle, int signal, bool isLeftShiftPressed = false) private static void JunimoNoteCustomButtons(JunimoNoteMenu __instance, Bundle ___currentPageBundle, int signal, bool isLeftShiftPressed = false)
{ {
isUsingCustomButtons = true;
try try
{ {
@ -291,9 +295,6 @@ namespace stardew_access.Patches
{ {
MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}");
} }
await Task.Delay(200);
isUsingCustomButtons = false;
} }
internal static void SocialPagePatch(SocialPage __instance, List<ClickableTextureComponent> ___sprites, int ___slotPosition, List<string> ___kidsNames) internal static void SocialPagePatch(SocialPage __instance, List<ClickableTextureComponent> ___sprites, int ___slotPosition, List<string> ___kidsNames)
@ -955,7 +956,9 @@ namespace stardew_access.Patches
} }
else if (isCPressed && !isSelectingRecipe) else if (isCPressed && !isSelectingRecipe)
{ {
_ = CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); isSelectingRecipe = true;
CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance);
Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; });
} }
#region Narrate buttons in the menu #region Narrate buttons in the menu
@ -1103,19 +1106,14 @@ namespace stardew_access.Patches
} }
} }
private static async Task CycleThroughRecipies(List<Dictionary<ClickableTextureComponent, CraftingRecipe>> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance) private static void CycleThroughRecipies(List<Dictionary<ClickableTextureComponent, CraftingRecipe>> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance)
{ {
isSelectingRecipe = true;
currentSelectedCraftingRecipe++; currentSelectedCraftingRecipe++;
if (currentSelectedCraftingRecipe < 0 || currentSelectedCraftingRecipe >= pagesOfCraftingRecipes[0].Count) if (currentSelectedCraftingRecipe < 0 || currentSelectedCraftingRecipe >= pagesOfCraftingRecipes[0].Count)
currentSelectedCraftingRecipe = 0; currentSelectedCraftingRecipe = 0;
__instance.setCurrentlySnappedComponentTo(pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.myID); __instance.setCurrentlySnappedComponentTo(pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.myID);
pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.snapMouseCursorToCenter(); pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.snapMouseCursorToCenter();
await Task.Delay(200);
isSelectingRecipe = false;
} }
// This method is used to get the inventory items to check if the player has enough ingredients for a recipe // This method is used to get the inventory items to check if the player has enough ingredients for a recipe

View File

@ -481,41 +481,12 @@ namespace stardew_access.Patches
} }
} }
#region Cleanup on exitting a menu
internal static void Game1ExitActiveMenuPatch() internal static void Game1ExitActiveMenuPatch()
{ {
try try
{ {
if (Game1.activeClickableMenu is GameMenu) Cleanup(Game1.activeClickableMenu);
{
GameMenuPatches.gameMenuQueryKey = "";
GameMenuPatches.craftingPageQueryKey = "";
GameMenuPatches.inventoryPageQueryKey = "";
GameMenuPatches.exitPageQueryKey = "";
GameMenuPatches.optionsPageQueryKey = "";
GameMenuPatches.socialPageQuery = "";
GameMenuPatches.currentSelectedCraftingRecipe = -1;
GameMenuPatches.isSelectingRecipe = false;
}
if (Game1.activeClickableMenu is JunimoNoteMenu)
{
GameMenuPatches.currentIngredientListItem = -1;
GameMenuPatches.currentIngredientInputSlot = -1;
GameMenuPatches.currentInventorySlot = -1;
GameMenuPatches.junimoNoteMenuQuery = "";
}
if (Game1.activeClickableMenu is ShopMenu)
{
GameMenuPatches.shopMenuQueryKey = "";
}
if (Game1.activeClickableMenu is ItemGrabMenu)
{
GameMenuPatches.itemGrabMenuQueryKey = "";
}
GameMenuPatches.hoveredItemQueryKey = "";
} }
catch (Exception e) catch (Exception e)
{ {
@ -527,46 +498,7 @@ namespace stardew_access.Patches
{ {
try try
{ {
if (__instance is GeodeMenu) Cleanup(__instance);
{
GameMenuPatches.geodeMenuQueryKey = "";
}
if (__instance is ItemGrabMenu)
{
GameMenuPatches.itemGrabMenuQueryKey = "";
}
if (__instance is ShopMenu)
{
GameMenuPatches.shopMenuQueryKey = "";
}
if (__instance is CarpenterMenu)
{
BuildingNAnimalMenuPatches.carpenterMenuQuery = "";
BuildingNAnimalMenuPatches.isUpgrading = false;
BuildingNAnimalMenuPatches.isDemolishing = false;
BuildingNAnimalMenuPatches.isPainting = false;
BuildingNAnimalMenuPatches.isMoving = false;
BuildingNAnimalMenuPatches.isConstructing = false;
BuildingNAnimalMenuPatches.carpenterMenu = null;
}
if (__instance is PurchaseAnimalsMenu)
{
BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = "";
BuildingNAnimalMenuPatches.firstTimeInNamingMenu = true;
BuildingNAnimalMenuPatches.purchaseAnimalsMenu = null;
}
if (__instance is DialogueBox)
{
DialoguePatches.isDialogueAppearingFirstTime = true;
DialoguePatches.currentDialogue = " ";
}
GameMenuPatches.hoveredItemQueryKey = "";
} }
catch (Exception e) catch (Exception e)
{ {
@ -574,6 +506,71 @@ namespace stardew_access.Patches
} }
} }
private static void Cleanup(IClickableMenu menu)
{
if (menu is GameMenu)
{
GameMenuPatches.gameMenuQueryKey = "";
GameMenuPatches.craftingPageQueryKey = "";
GameMenuPatches.inventoryPageQueryKey = "";
GameMenuPatches.exitPageQueryKey = "";
GameMenuPatches.optionsPageQueryKey = "";
GameMenuPatches.socialPageQuery = "";
GameMenuPatches.currentSelectedCraftingRecipe = -1;
GameMenuPatches.isSelectingRecipe = false;
}
if (menu is JunimoNoteMenu)
{
GameMenuPatches.currentIngredientListItem = -1;
GameMenuPatches.currentIngredientInputSlot = -1;
GameMenuPatches.currentInventorySlot = -1;
GameMenuPatches.junimoNoteMenuQuery = "";
}
if (menu is ShopMenu)
{
GameMenuPatches.shopMenuQueryKey = "";
}
if (menu is ItemGrabMenu)
{
GameMenuPatches.itemGrabMenuQueryKey = "";
}
if (menu is GeodeMenu)
{
GameMenuPatches.geodeMenuQueryKey = "";
}
if (menu is CarpenterMenu)
{
BuildingNAnimalMenuPatches.carpenterMenuQuery = "";
BuildingNAnimalMenuPatches.isUpgrading = false;
BuildingNAnimalMenuPatches.isDemolishing = false;
BuildingNAnimalMenuPatches.isPainting = false;
BuildingNAnimalMenuPatches.isMoving = false;
BuildingNAnimalMenuPatches.isConstructing = false;
BuildingNAnimalMenuPatches.carpenterMenu = null;
}
if (menu is PurchaseAnimalsMenu)
{
BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = "";
BuildingNAnimalMenuPatches.firstTimeInNamingMenu = true;
BuildingNAnimalMenuPatches.purchaseAnimalsMenu = null;
}
if (menu is DialogueBox)
{
DialoguePatches.isDialogueAppearingFirstTime = true;
DialoguePatches.currentDialogue = " ";
}
GameMenuPatches.hoveredItemQueryKey = "";
}
#endregion
internal static void ExitEventPatch() internal static void ExitEventPatch()
{ {
if (MainClass.GetScreenReader() != null) if (MainClass.GetScreenReader() != null)

View File

@ -178,11 +178,15 @@ namespace stardew_access.Patches
if (isNextArrowPressed && !isRunning) if (isNextArrowPressed && !isRunning)
{ {
_ = CycleThroughItems(true, __instance, ___skipIntro); isRunning = true;
CycleThroughItems(true, __instance, ___skipIntro);
Task.Delay(200).ContinueWith(_ => { isRunning = false; });
} }
else if (isPrevArrowPressed && !isRunning) else if (isPrevArrowPressed && !isRunning)
{ {
_ = CycleThroughItems(false, __instance, ___skipIntro); isRunning = true;
CycleThroughItems(false, __instance, ___skipIntro);
Task.Delay(200).ContinueWith(_ => { isRunning = false; });
} }
} }
catch (Exception e) catch (Exception e)
@ -191,9 +195,8 @@ namespace stardew_access.Patches
} }
} }
private static async Task CycleThroughItems(bool increase, CharacterCustomization __instance, bool ___skipIntro) private static void CycleThroughItems(bool increase, CharacterCustomization __instance, bool ___skipIntro)
{ {
isRunning = true;
string toSpeak = " "; string toSpeak = " ";
if (increase) if (increase)
@ -650,9 +653,6 @@ namespace stardew_access.Patches
{ {
MainClass.GetScreenReader().Say(toSpeak, true); MainClass.GetScreenReader().Say(toSpeak, true);
} }
await Task.Delay(200);
isRunning = false;
} }
private static string getFarmHoverText(ClickableTextureComponent farm) private static string getFarmHoverText(ClickableTextureComponent farm)

View File

@ -1,3 +1,8 @@
/*
Linux speech dispatcher library used:
https://github.com/shoaib11120/libspeechdwrapper
*/
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace stardew_access.ScreenReader namespace stardew_access.ScreenReader