diff --git a/stardew-access/Game/Radar.cs b/stardew-access/Game/Radar.cs index 631f7d9..3e3a8cb 100644 --- a/stardew-access/Game/Radar.cs +++ b/stardew-access/Game/Radar.cs @@ -78,112 +78,119 @@ namespace stardew_access.Game public void checkTile(Vector2 position) { - Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; + try + { + Dictionary> terrainFeature = Game1.currentLocation.terrainFeatures.FieldDict; - // Check for npcs - if (Game1.currentLocation.isCharacterAtTile(position) != null && !exclusions.Contains("npc")) - { - NPC npc = Game1.currentLocation.isCharacterAtTile(position); - if (!npcs.Contains(npc)) + // Check for npcs + if (Game1.currentLocation.isCharacterAtTile(position) != null && !exclusions.Contains("npc")) { - playSoundAt(position, npc.displayName); - } - } - // Check for water - else if (Game1.currentLocation.isWaterTile((int)position.X, (int)position.Y) && !exclusions.Contains("water")) - { - playSoundAt(position, null); - } - // Check for objects - else if (Game1.currentLocation.isObjectAtTile((int)position.X, (int)position.Y)) - { - string? objectName = ReadTile.getObjectNameAtTile((int)position.X, (int)position.Y); - StardewValley.Object obj = Game1.currentLocation.getObjectAtTile((int)position.X, (int)position.Y); - - if (objectName != null) - { - if (obj is Furniture && !exclusions.Contains("furniture")) + NPC npc = Game1.currentLocation.isCharacterAtTile(position); + if (!npcs.Contains(npc)) { - if (!furnitures.Contains(obj as Furniture)) + playSoundAt(position, npc.displayName); + } + } + // Check for water + else if (Game1.currentLocation.isWaterTile((int)position.X, (int)position.Y) && !exclusions.Contains("water")) + { + playSoundAt(position, null); + } + // Check for objects + else if (Game1.currentLocation.isObjectAtTile((int)position.X, (int)position.Y)) + { + string? objectName = ReadTile.getObjectNameAtTile((int)position.X, (int)position.Y); + StardewValley.Object obj = Game1.currentLocation.getObjectAtTile((int)position.X, (int)position.Y); + + if (objectName != null) + { + if (obj is Furniture && !exclusions.Contains("furniture")) + { + if (!furnitures.Contains(obj as Furniture)) + { + furnitures.Add(obj as Furniture); + playSoundAt(position, objectName); + } + } + else { - furnitures.Add(obj as Furniture); playSoundAt(position, objectName); } } - else - { - playSoundAt(position, objectName); - } } - } - // Check for terrain features - else if (terrainFeature.ContainsKey(position)) - { - Netcode.NetRef tr = terrainFeature[position]; - string? terrain = ReadTile.getTerrainFeatureAtTile(tr).ToLower(); - if (terrain != null) + // Check for terrain features + else if (terrainFeature.ContainsKey(position)) { - if(tr.Get() is HoeDirt && !exclusions.Contains("crop")) + Netcode.NetRef tr = terrainFeature[position]; + string? terrain = ReadTile.getTerrainFeatureAtTile(tr).ToLower(); + if (terrain != null) { - playSoundAt(position, terrain); - } - else if(tr.Get() is GiantCrop && !exclusions.Contains("giant crop")) - { - playSoundAt(position, terrain); - } - else if (tr.Get() is Bush && !exclusions.Contains("bush")) - { - playSoundAt(position, terrain); - } - else if (tr.Get() is CosmeticPlant && !exclusions.Contains("cosmetic plant")) - { - playSoundAt(position, terrain); - } - else if (tr.Get() is Flooring && !exclusions.Contains("flooring")) - { - playSoundAt(position, terrain); - } - else if (tr.Get() is FruitTree && !exclusions.Contains("fruit tree")) - { - playSoundAt(position, terrain); - } - else if (tr.Get() is Grass && !exclusions.Contains("grass")) - { - playSoundAt(position, terrain); - } - else if (tr.Get() is Tree && !exclusions.Contains("tree")) - { - playSoundAt(position, terrain); - } - else if (tr.Get() is Quartz && !exclusions.Contains("quartz")) - { - playSoundAt(position, terrain); - } - else if (tr.Get() is Leaf && !exclusions.Contains("leaf")) - { - playSoundAt(position, terrain); + if (tr.Get() is HoeDirt && !exclusions.Contains("crop")) + { + playSoundAt(position, terrain); + } + else if (tr.Get() is GiantCrop && !exclusions.Contains("giant crop")) + { + playSoundAt(position, terrain); + } + else if (tr.Get() is Bush && !exclusions.Contains("bush")) + { + playSoundAt(position, terrain); + } + else if (tr.Get() is CosmeticPlant && !exclusions.Contains("cosmetic plant")) + { + playSoundAt(position, terrain); + } + else if (tr.Get() is Flooring && !exclusions.Contains("flooring")) + { + playSoundAt(position, terrain); + } + else if (tr.Get() is FruitTree && !exclusions.Contains("fruit tree")) + { + playSoundAt(position, terrain); + } + else if (tr.Get() is Grass && !exclusions.Contains("grass")) + { + playSoundAt(position, terrain); + } + else if (tr.Get() is Tree && !exclusions.Contains("tree")) + { + playSoundAt(position, terrain); + } + else if (tr.Get() is Quartz && !exclusions.Contains("quartz")) + { + playSoundAt(position, terrain); + } + else if (tr.Get() is Leaf && !exclusions.Contains("leaf")) + { + playSoundAt(position, terrain); + } } } + // Check for Mine ladders + else if (ReadTile.isMineLadderAtTile((int)position.X, (int)position.Y) && !exclusions.Contains("ladder")) + { + playSoundAt(position, null); + } + // Check for doors + else if (ReadTile.isDoorAtTile((int)position.X, (int)position.Y) && !exclusions.Contains("door")) + { + playSoundAt(position, null); + } + // Check for buildings on maps + else if (ReadTile.getBuildingAtTile((int)position.X, (int)position.Y) != null) + { + playSoundAt(position, ReadTile.getBuildingAtTile((int)position.X, (int)position.Y)); + } + // Check for resource clumps + else if (ReadTile.getResourceClumpAtTile((int)position.X, (int)position.Y) != null) + { + playSoundAt(position, ReadTile.getResourceClumpAtTile((int)position.X, (int)position.Y)); + } } - // Check for Mine ladders - else if (ReadTile.isMineLadderAtTile((int)position.X, (int)position.Y) && !exclusions.Contains("ladder")) + catch (Exception e) { - playSoundAt(position, null); - } - // Check for doors - else if (ReadTile.isDoorAtTile((int)position.X, (int)position.Y) && !exclusions.Contains("door")) - { - playSoundAt(position, null); - } - // Check for buildings on maps - else if (ReadTile.getBuildingAtTile((int)position.X, (int)position.Y) != null) - { - playSoundAt(position, ReadTile.getBuildingAtTile((int)position.X, (int)position.Y)); - } - // Check for resource clumps - else if (ReadTile.getResourceClumpAtTile((int)position.X, (int)position.Y) != null) - { - playSoundAt(position, ReadTile.getResourceClumpAtTile((int)position.X, (int)position.Y)); + MainClass.monitor.Log($"{e.Message}\n{e.StackTrace}\n{e.Source}", StardewModdingAPI.LogLevel.Error); } } @@ -191,7 +198,7 @@ namespace stardew_access.Game { if (searchQuery == null || !exclusions.Contains(searchQuery)) { - MainClass.monitor.Log($"{searchQuery}:X={position.X} Y={position.Y}", StardewModdingAPI.LogLevel.Debug); + MainClass.monitor.Log($"Object:{searchQuery}\tPosition: X={position.X} Y={position.Y}", StardewModdingAPI.LogLevel.Debug); Game1.currentLocation.localSoundAt("sa_poi", position); } } diff --git a/stardew-access/Game/ReadTile.cs b/stardew-access/Game/ReadTile.cs index dca5abe..f19fae4 100644 --- a/stardew-access/Game/ReadTile.cs +++ b/stardew-access/Game/ReadTile.cs @@ -104,41 +104,47 @@ namespace stardew_access.Game public static string? getBuildingAtTile(int x, int y) { string? toReturn = null; - int? index = Game1.currentLocation.Map.GetLayer("Buildings").Tiles[x, y].TileIndex; - /* Add More - MainClass.monitor.Log(index.ToString(), LogLevel.Debug); - */ - if (index != null) + + // It throws error if it can't find the index, do something else to fix this + try { - switch (index) + int? index = Game1.currentLocation.Map.GetLayer("Buildings").Tiles[x, y].TileIndex; + /* Add More + MainClass.monitor.Log(index.ToString(), LogLevel.Debug); + */ + if (index != null) { - case 1955: - case 41: - toReturn = "Mail Box"; - break; - case 173: - toReturn = "Fridge"; - break; - case 169: - case 170: - case 171: - case 172: - toReturn = "Kitchen"; - break; - case 1003: - toReturn = "Street lamp"; - break; - case 78: - toReturn = "Trash bin"; - break; - case 617: - toReturn = "Daily quest"; - break; - case 616: - toReturn = "Calender"; - break; + switch (index) + { + case 1955: + case 41: + toReturn = "Mail Box"; + break; + case 173: + toReturn = "Fridge"; + break; + case 169: + case 170: + case 171: + case 172: + toReturn = "Kitchen"; + break; + case 1003: + toReturn = "Street lamp"; + break; + case 78: + toReturn = "Trash bin"; + break; + case 617: + toReturn = "Daily quest"; + break; + case 616: + toReturn = "Calender"; + break; + } } } + catch (Exception) {} return toReturn; } diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index f3ce949..405aa16 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -222,35 +222,46 @@ namespace stardew_access #endregion #region Custom Commands - helper.ConsoleCommands.Add("read_tile", "Toggle read tile feature", (string arg1, string[] arg2) => + helper.ConsoleCommands.Add("read_tile", "Toggle read tile feature", (string commmand, string[] args) => { readTile = !readTile; monitor.Log("Read Tile is " + (readTile ? "on" : "off"), LogLevel.Info); }); - helper.ConsoleCommands.Add("snap_mouse", "Toggle snap mouse feature", (string arg1, string[] arg2) => + helper.ConsoleCommands.Add("snap_mouse", "Toggle snap mouse feature", (string commmand, string[] args) => { snapMouse = !snapMouse; monitor.Log("Snap Mouse is " + (snapMouse ? "on" : "off"), LogLevel.Info); }); - helper.ConsoleCommands.Add("radar", "Toggle radar feature", (string arg1, string[] arg2) => + helper.ConsoleCommands.Add("radar", "Toggle radar feature", (string commmand, string[] args) => { radar = !radar; monitor.Log("Radar " + (snapMouse ? "on" : "off"), LogLevel.Info); }); - helper.ConsoleCommands.Add("r_in", "Include an object to radar", (string arg1, string[] arg2) => + helper.ConsoleCommands.Add("r_in", "Include an object to radar", (string commmand, string[] args) => { - radar = !radar; + string? keyToAdd = null; - monitor.Log("Radar " + (snapMouse ? "on" : "off"), LogLevel.Info); + for (int i = 0; i < args.Count(); i++) { keyToAdd += " " + args[i]; } + + if (keyToAdd != null) + { + keyToAdd = keyToAdd.Trim().ToLower(); + radarFeature.exclusions.Add(keyToAdd); + monitor.Log($"Added {keyToAdd} key to exclusions.", LogLevel.Info); + } + else + { + monitor.Log("Unable to add the key to exclusions.", LogLevel.Info); + } }); - helper.ConsoleCommands.Add("ref_sr", "Refresh screen reader", (string arg1, string[] arg2) => + helper.ConsoleCommands.Add("ref_sr", "Refresh screen reader", (string commmand, string[] args) => { ScreenReader.initializeScreenReader();