From 6c6c7bdecf9a00f7104387f6b9e446a7ab28d67e Mon Sep 17 00:00:00 2001 From: shoaib11120 Date: Wed, 15 Dec 2021 22:58:49 +0530 Subject: [PATCH] Fix snap mouse and read tile bug --- stardew-access/ModEntry.cs | 114 ++++++++++++++++++++++++++--------- stardew-access/manifest.json | 2 +- 2 files changed, 88 insertions(+), 28 deletions(-) diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 9525a81..adffb0c 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -176,50 +176,110 @@ namespace stardew_access int x = Game1.player.GetBoundingBox().Center.X - Game1.viewport.X; int y = Game1.player.GetBoundingBox().Center.Y - Game1.viewport.Y; + int offset = 64; + + switch (Game1.player.FacingDirection) + { + case 0: + y -= offset; + break; + case 1: + x += offset; + break; + case 2: + y += offset; + break; + case 3: + x -= offset; + break; + } + Game1.setMousePosition(x, y); } private static async void ReadTile() { isReadingTile = true; - if (Context.IsPlayerFree) + + try { - Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; - Vector2 gt = Game1.player.GetGrabTile(); - StardewValley.Object obj = Game1.currentLocation.getObjectAtTile((int)gt.X, (int)gt.Y); - if (!Equals(gt, prevTile)) + #region Get Correct Grab Tile + int x = Game1.player.GetBoundingBox().Center.X; + int y = Game1.player.GetBoundingBox().Center.Y; + + int offset = 64; + + switch (Game1.player.FacingDirection) { - prevTile = gt; - if (obj != null) + case 0: + y -= offset; + break; + case 1: + x += offset; + break; + case 2: + y += offset; + break; + case 3: + x -= offset; + break; + } + + x /= Game1.tileSize; + y /= Game1.tileSize; + Vector2 gt = new Vector2(x, y); + #endregion + + if (Context.IsPlayerFree) + { + Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; + + StardewValley.Object obj = Game1.currentLocation.getObjectAtTile((int)gt.X, (int)gt.Y); + if (!Equals(gt, prevTile)) { - string name = obj.name; - - string checkQuery = $"x:{gt.X} y:{gt.Y}"; - - ScreenReader.say(name, true); - - } - else if (terrainFeature.ContainsKey(gt)) - { - Netcode.NetRef terrain = terrainFeature[gt]; - - if (terrain.Get() is HoeDirt) + prevTile = gt; + if (obj != null) { - HoeDirt dirt = (HoeDirt)terrain.Get(); - if (dirt.crop != null) - { - string cropName = Game1.objectInformation[dirt.crop.indexOfHarvest]; - cropName = cropName.Substring(0, cropName.IndexOf("/")); + string name = obj.name; + + ScreenReader.say(name, true); - string toSpeak = $"{cropName}"; - ScreenReader.say(toSpeak, true); - } } + else if (terrainFeature.ContainsKey(gt)) + { + Netcode.NetRef terrain = terrainFeature[gt]; + if (terrain.Get() is HoeDirt) + { + HoeDirt dirt = (HoeDirt)terrain.Get(); + if (dirt.crop != null) + { + string cropName = Game1.objectInformation[dirt.crop.indexOfHarvest]; + cropName = cropName.Substring(0, cropName.IndexOf("/")); + string toSpeak = $"{cropName}"; + + bool isWatered = dirt.state.Value == HoeDirt.watered; + bool isHarvestable = dirt.crop.fullyGrown.Get(); + + if(isWatered) + toSpeak = "Watered " + toSpeak; + + if (isHarvestable) + toSpeak = "Harvestable " + toSpeak; + + ScreenReader.say(toSpeak, true); + } + } + + } } } } + catch (Exception e) + { + monitor.Log($"Error in Read Tile:\n{e.Message}\n{e.StackTrace}"); + } await Task.Delay(100); isReadingTile = false; diff --git a/stardew-access/manifest.json b/stardew-access/manifest.json index 12523a8..58efbaf 100644 --- a/stardew-access/manifest.json +++ b/stardew-access/manifest.json @@ -1,7 +1,7 @@ { "Name": "Stardew Access", "Author": "Mohammad Shoaib", - "Version": "1.0.3-beta", + "Version": "1.0.4-beta", "Description": "An accessibility mod with screen reader support!", "UniqueID": "shoaib.stardewaccess", "EntryDll": "stardew-access.dll",