From fcd2243cc544b6341e24d647193745e532ddae08 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Date: Thu, 17 Mar 2022 20:04:20 +0530 Subject: [PATCH] Made reading floorings toggleable | Added names to tuples making it more readable --- stardew-access/CustomCommands.cs | 7 ++++ stardew-access/Features/Radar.cs | 26 +++++++-------- stardew-access/Features/ReadTile.cs | 52 ++++++++++++++--------------- stardew-access/ModEntry.cs | 1 + 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/stardew-access/CustomCommands.cs b/stardew-access/CustomCommands.cs index e26cc67..d589ea2 100644 --- a/stardew-access/CustomCommands.cs +++ b/stardew-access/CustomCommands.cs @@ -27,6 +27,13 @@ namespace stardew_access MainClass.GetMonitor().Log("Snap Mouse is " + (MainClass.snapMouse ? "on" : "off"), LogLevel.Info); }); + helper.ConsoleCommands.Add("flooring", "Toggle flooring in read tile.", (string commmand, string[] args) => + { + MainClass.readFlooring = !MainClass.readFlooring; + + MainClass.GetMonitor().Log("Flooring is " + (MainClass.readFlooring ? "on" : "off"), LogLevel.Info); + }); + helper.ConsoleCommands.Add("radar", "Toggle radar feature.", (string commmand, string[] args) => { MainClass.radar = !MainClass.radar; diff --git a/stardew-access/Features/Radar.cs b/stardew-access/Features/Radar.cs index 3419927..ba9ebde 100644 --- a/stardew-access/Features/Radar.cs +++ b/stardew-access/Features/Radar.cs @@ -191,14 +191,14 @@ namespace stardew_access.Features public (bool, string?, string) CheckTile(Vector2 position) { - (string?, CATEGORY?) tileDetail = ReadTile.getNameWithCategoryAtTile(position); - if (tileDetail.Item1 == null) + (string? name, CATEGORY? category) tileDetail = ReadTile.getNameWithCategoryAtTile(position); + if (tileDetail.name == null) return (false, null, CATEGORY.Others.ToString()); - if (tileDetail.Item2 == null) - tileDetail.Item2 = CATEGORY.Others; + if (tileDetail.category == null) + tileDetail.category = CATEGORY.Others; - return (true, tileDetail.Item1, tileDetail.Item2.ToString()); + return (true, tileDetail.name, tileDetail.category.ToString()); } @@ -208,9 +208,9 @@ namespace stardew_access.Features { if (Game1.currentLocation.isObjectAtTile((int)position.X, (int)position.Y)) { - (string?, CATEGORY) objDetails = ReadTile.getObjectAtTile((int)position.X, (int)position.Y); - string? objectName = objDetails.Item1; - CATEGORY category = objDetails.Item2; + (string? name, CATEGORY category) objDetails = ReadTile.getObjectAtTile((int)position.X, (int)position.Y); + string? objectName = objDetails.name; + CATEGORY category = objDetails.category; StardewValley.Object obj = Game1.currentLocation.getObjectAtTile((int)position.X, (int)position.Y); if (objectName != null) @@ -232,13 +232,13 @@ namespace stardew_access.Features } else { - (string?, CATEGORY?) tileDetail = ReadTile.getNameWithCategoryAtTile(position); - if (tileDetail.Item1 != null) + (string? name, CATEGORY? category) tileDetail = ReadTile.getNameWithCategoryAtTile(position); + if (tileDetail.name != null) { - if (tileDetail.Item2 == null) - tileDetail.Item2 = CATEGORY.Others; + if (tileDetail.category == null) + tileDetail.category = CATEGORY.Others; - PlaySoundAt(position, tileDetail.Item1, tileDetail.Item2); + PlaySoundAt(position, tileDetail.name, tileDetail.category); } } } diff --git a/stardew-access/Features/ReadTile.cs b/stardew-access/Features/ReadTile.cs index 0ab8422..7118d8c 100644 --- a/stardew-access/Features/ReadTile.cs +++ b/stardew-access/Features/ReadTile.cs @@ -72,18 +72,18 @@ namespace stardew_access.Features } ///Returns the name of the object at tile alongwith it's category's name - public static (string?, string?) getNameWithCategoryNameAtTile(Vector2 tile) + public static (string? name, string? categoryName) getNameWithCategoryNameAtTile(Vector2 tile) { - (string?, CATEGORY?) tileDetail = getNameWithCategoryAtTile(tile); + (string? name, CATEGORY? category) tileDetail = getNameWithCategoryAtTile(tile); - if (tileDetail.Item2 == null) - tileDetail.Item2 = CATEGORY.Others; + if (tileDetail.category == null) + tileDetail.category = CATEGORY.Others; - return (tileDetail.Item1, tileDetail.Item2.ToString()); + return (tileDetail.name, tileDetail.category.ToString()); } ///Returns the name of the object at tile alongwith it's category - public static (string?, CATEGORY?) getNameWithCategoryAtTile(Vector2 tile) + public static (string? name, CATEGORY? category) getNameWithCategoryAtTile(Vector2 tile) { int x = (int)tile.X; int y = (int)tile.Y; @@ -93,7 +93,7 @@ namespace stardew_access.Features bool isColliding = isCollidingAtTile(x, y); Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; string? door = getDoorAtTile(x, y); - (CATEGORY?, string?) tileInfo = getTileInfo(x, y); + (CATEGORY? category, string? name) tileInfo = getTileInfo(x, y); string? junimoBundle = getJunimoBundleAt(x, y); string? resourceClump = getResourceClumpAtTile(x, y); string? farmAnimal = getFarmAnimalAt(Game1.currentLocation, x, y); @@ -119,18 +119,18 @@ namespace stardew_access.Features } else if (Game1.currentLocation.isObjectAtTile(x, y)) { - (string?, CATEGORY?) obj = getObjectAtTile(x, y); - toReturn = obj.Item1; - category = obj.Item2; + (string? name, CATEGORY? category) obj = getObjectAtTile(x, y); + toReturn = obj.name; + category = obj.category; } else if (terrainFeature.ContainsKey(tile)) { - (string?, CATEGORY) tf = getTerrainFeatureAtTile(terrainFeature[tile]); - string? terrain = tf.Item1; + (string? name, CATEGORY category) tf = getTerrainFeatureAtTile(terrainFeature[tile]); + string? terrain = tf.name; if (terrain != null) { toReturn = terrain; - category = tf.Item2; + category = tf.category; } } @@ -164,10 +164,10 @@ namespace stardew_access.Features toReturn = "Elevator"; category = CATEGORY.Doors; } - else if (tileInfo.Item2 != null) + else if (tileInfo.name != null) { - toReturn = tileInfo.Item2; - category = tileInfo.Item1; + toReturn = tileInfo.name; + category = tileInfo.category; } else if (junimoBundle != null) { @@ -191,7 +191,7 @@ namespace stardew_access.Features bool isColliding = isCollidingAtTile(x, y); Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; string? door = getDoorAtTile(x, y); - (CATEGORY?, string?) tileInfo = getTileInfo(x, y); + (CATEGORY? category, string? name) tileInfo = getTileInfo(x, y); string? junimoBundle = getJunimoBundleAt(x, y); string? resourceClump = getResourceClumpAtTile(x, y); string? farmAnimal = getFarmAnimalAt(Game1.currentLocation, x, y); @@ -211,7 +211,7 @@ namespace stardew_access.Features } else if (Game1.currentLocation.isObjectAtTile(x, y)) { - toReturn = getObjectAtTile(x, y).Item1; + toReturn = getObjectAtTile(x, y).name; } else if (terrainFeature.ContainsKey(tile)) { @@ -243,9 +243,9 @@ namespace stardew_access.Features { toReturn = "Elevator"; } - else if (tileInfo.Item2 != null) + else if (tileInfo.name != null) { - toReturn = tileInfo.Item2; + toReturn = tileInfo.name; } else if (junimoBundle != null) { @@ -391,9 +391,9 @@ namespace stardew_access.Features /// /// /// - /// Item1: This is the category of the tile. Default to Furnitures. - ///
Item2: This is the name of the tile. Default to null if the tile tile has nothing on it.
- public static (CATEGORY?, string?) getTileInfo(int x, int y) + /// category: This is the category of the tile. Default to Furnitures. + ///
name: This is the name of the tile. Default to null if the tile tile has nothing on it.
+ public static (CATEGORY? category, string? name) getTileInfo(int x, int y) { int? index = null; @@ -449,7 +449,7 @@ namespace stardew_access.Features return (null, null); } - public static (string?, CATEGORY) getTerrainFeatureAtTile(Netcode.NetRef terrain) + public static (string? name, CATEGORY category) getTerrainFeatureAtTile(Netcode.NetRef terrain) { string? toReturn = null; CATEGORY category = CATEGORY.Others; @@ -518,7 +518,7 @@ namespace stardew_access.Features if (toReturn.Contains("feature")) toReturn.Replace("feature", ""); } - else if (terrain.Get() is Flooring) + else if (terrain.Get() is Flooring && MainClass.readFlooring) { category = CATEGORY.Flooring; Flooring flooring = (Flooring)terrain.Get(); @@ -639,7 +639,7 @@ namespace stardew_access.Features return seedName; } - public static (string?, CATEGORY) getObjectAtTile(int x, int y) + public static (string? name, CATEGORY category) getObjectAtTile(int x, int y) { string? toReturn = null; diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index cd89f7e..dde56a1 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -19,6 +19,7 @@ namespace stardew_access 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;