From ca8ecd845b6a92f880e5ded95ee10b88ac046042 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Date: Sat, 23 Apr 2022 18:21:50 +0530 Subject: [PATCH] Added category to static tiles --- stardew-access/Features/Radar.cs | 38 --------- stardew-access/Features/StaticTiles.cs | 18 ++-- stardew-access/Features/TileInfo.cs | 112 +++++++++++++++++++++++-- stardew-access/static-tiles.json | 10 +-- 4 files changed, 120 insertions(+), 58 deletions(-) diff --git a/stardew-access/Features/Radar.cs b/stardew-access/Features/Radar.cs index c0b0eaa..8235ebc 100644 --- a/stardew-access/Features/Radar.cs +++ b/stardew-access/Features/Radar.cs @@ -4,44 +4,6 @@ using StardewValley.Objects; namespace stardew_access.Features { - - /// - /// This is a custom enum class and contains the name of groups the objects are divided into for the feature - /// - public class CATEGORY - { - private string _typeKeyWord; - - private CATEGORY(string typeKeyWord) - { - _typeKeyWord = typeKeyWord; - } - - public override string ToString() - { - return _typeKeyWord; - } - - public static CATEGORY Farmers = new CATEGORY("farmer"); - public static CATEGORY FarmAnimals = new CATEGORY("animal"); - public static CATEGORY NPCs = new CATEGORY("npc"); - public static CATEGORY Furnitures = new CATEGORY("furniture"); - public static CATEGORY Flooring = new CATEGORY("flooring"); - public static CATEGORY Debris = new CATEGORY("debris"); - public static CATEGORY Crops = new CATEGORY("crop"); - public static CATEGORY Trees = new CATEGORY("tree"); - public static CATEGORY Bush = new CATEGORY("bush"); - public static CATEGORY Buildings = new CATEGORY("building"); - public static CATEGORY MineItems = new CATEGORY("mine item"); - public static CATEGORY ResourceClumps = new CATEGORY("resource clump"); - public static CATEGORY Chests = new CATEGORY("chest"); - public static CATEGORY JunimoBundle = new CATEGORY("bundle"); - public static CATEGORY Doors = new CATEGORY("door"); // Also includes ladders and elevators - public static CATEGORY Others = new CATEGORY("other"); - public static CATEGORY WaterTiles = new CATEGORY("water"); - - } - public class Radar { private List closed; diff --git a/stardew-access/Features/StaticTiles.cs b/stardew-access/Features/StaticTiles.cs index e8d90ab..ab8d803 100644 --- a/stardew-access/Features/StaticTiles.cs +++ b/stardew-access/Features/StaticTiles.cs @@ -31,10 +31,15 @@ namespace stardew_access.Features return false; } - public string? getStaticTileAt(int x, int y) + public string? getStaticTileInfoAt(int x, int y) + { + return getStaticTileInfoAtWithCategory(x, y).name; + } + + public (string? name, CATEGORY category) getStaticTileInfoAtWithCategory(int x, int y) { if (data == null) - return null; + return (null, CATEGORY.Others); foreach (var location in data) { @@ -49,16 +54,17 @@ namespace stardew_access.Features JToken? tileX = tile.Value["x"]; JToken? tileY = tile.Value["y"]; + JToken? tileType = tile.Value["type"]; - if (tileX == null || tileY == null) + if (tileX == null || tileY == null || tileType == null) continue; - + MainClass.DebugLog($"{tile.Key.ToString()}:\tx{tileX.ToString()}\ty{tileY.ToString()}\ttype{tileType.ToString()}"); if (short.Parse(tileX.ToString()) == x && short.Parse(tileY.ToString()) == y) - return tile.Key; + return (tile.Key, CATEGORY.FromString(tileType.ToString())); } } - return null; + return (null, CATEGORY.Others); } } } \ No newline at end of file diff --git a/stardew-access/Features/TileInfo.cs b/stardew-access/Features/TileInfo.cs index d21b465..d9338da 100644 --- a/stardew-access/Features/TileInfo.cs +++ b/stardew-access/Features/TileInfo.cs @@ -7,6 +7,93 @@ using StardewValley.TerrainFeatures; namespace stardew_access.Features { + + /// + /// This is a custom enum class and contains the name of groups the objects are divided into for the feature + /// + public class CATEGORY + { + private string _typeKeyWord; + + private CATEGORY(string typeKeyWord) + { + _typeKeyWord = typeKeyWord; + } + + public override string ToString() + { + return _typeKeyWord; + } + + public static CATEGORY FromString(string name) + { + if (name == "farmer") + return CATEGORY.Farmers; + else if (name == "animal") + return CATEGORY.FarmAnimals; + else if (name == "npc") + return CATEGORY.NPCs; + else if (name == "furniture") + return CATEGORY.Furnitures; + else if (name == "flooring") + return CATEGORY.Flooring; + else if (name == "debris") + return CATEGORY.Debris; + else if (name == "crop") + return CATEGORY.Crops; + else if (name == "tree") + return CATEGORY.Trees; + else if (name == "bush") + return CATEGORY.Bush; + else if (name == "building") + return CATEGORY.Buildings; + else if (name == "mine item") + return CATEGORY.MineItems; + else if (name == "resource clump") + return CATEGORY.ResourceClumps; + else if (name == "chest") + return CATEGORY.Chests; + else if (name == "bundle") + return CATEGORY.JunimoBundle; + else if (name == "door") + return CATEGORY.Doors; + else if (name == "water") + return CATEGORY.WaterTiles; + else if (name == "interactables") + return CATEGORY.Interactables; + else if (name == "decoration") + return CATEGORY.Decor; + else if (name == "machines") + return CATEGORY.Machines; + else if (name == "other") + return CATEGORY.Others; + + return Others; + } + + public static CATEGORY Farmers = new CATEGORY("farmer"); + public static CATEGORY FarmAnimals = new CATEGORY("animal"); + public static CATEGORY NPCs = new CATEGORY("npc"); + public static CATEGORY Furnitures = new CATEGORY("furniture"); + public static CATEGORY Flooring = new CATEGORY("flooring"); + public static CATEGORY Debris = new CATEGORY("debris"); + public static CATEGORY Crops = new CATEGORY("crop"); + public static CATEGORY Trees = new CATEGORY("tree"); + public static CATEGORY Bush = new CATEGORY("bush"); + public static CATEGORY Buildings = new CATEGORY("building"); + public static CATEGORY MineItems = new CATEGORY("mine item"); + public static CATEGORY ResourceClumps = new CATEGORY("resource clump"); + public static CATEGORY Chests = new CATEGORY("chest"); + public static CATEGORY JunimoBundle = new CATEGORY("bundle"); + public static CATEGORY Doors = new CATEGORY("door"); // Also includes ladders and elevators + public static CATEGORY WaterTiles = new CATEGORY("water"); + public static CATEGORY Interactables = new CATEGORY("interactables"); + public static CATEGORY Decor = new CATEGORY("decoration"); + public static CATEGORY Machines = new CATEGORY("machines"); + public static CATEGORY Others = new CATEGORY("other"); + + } + public enum MachineState { Ready, Busy, Waiting @@ -14,6 +101,8 @@ namespace stardew_access.Features public class TileInfo { + public static string[] trackable_machines = { "bee house", "cask", "press", "keg", "machine", "maker", "preserves jar", "bone mill", "kiln", "crystalarium", "furnace", "geode crusher", "tapper", "lightning rod", "incubator", "wood chipper", "worm bin", "loom" }; + ///Returns the name of the object at tile alongwith it's category's name public static (string? name, string? categoryName) getNameWithCategoryNameAtTile(Vector2 tile) { @@ -47,7 +136,7 @@ namespace stardew_access.Features string? resourceClump = getResourceClumpAtTile(x, y); string? farmAnimal = getFarmAnimalAt(Game1.currentLocation, x, y); string? parrot = getParrotPerchAtTile(x, y); - string? staticTile = MainClass.STiles.getStaticTileAt(x, y); + (string? name, CATEGORY category) staticTile = MainClass.STiles.getStaticTileInfoAtWithCategory(x, y); if (Game1.currentLocation.isCharacterAtTile(tile) != null) { @@ -63,10 +152,10 @@ namespace stardew_access.Features toReturn = farmAnimal; category = CATEGORY.FarmAnimals; } - else if (staticTile != null) + else if (staticTile.name != null) { - toReturn = staticTile; - category = CATEGORY.Others; + toReturn = staticTile.name; + category = staticTile.category; } else if (Game1.currentLocation is VolcanoDungeon && ((VolcanoDungeon)Game1.currentLocation).IsCooledLava(x, y)) { @@ -576,9 +665,20 @@ namespace stardew_access.Features Chest chest = (Chest)obj; toReturn = (chest.DisplayName, CATEGORY.Chests); } - - if (obj is Furniture) + else if (obj is Furniture) toReturn.category = CATEGORY.Furnitures; + else if (obj.type == "Crafting" && obj.bigCraftable) + { + + foreach (string machine in trackable_machines) + { + if (obj.Name.ToLower().Contains(machine)) + { + toReturn.name = obj.DisplayName; + toReturn.category = CATEGORY.Machines; + } + } + } if (toReturn.category == CATEGORY.Others) // Fix for `Harvestable table` and `Busy nodes` { diff --git a/stardew-access/static-tiles.json b/stardew-access/static-tiles.json index cffffe6..8064919 100644 --- a/stardew-access/static-tiles.json +++ b/stardew-access/static-tiles.json @@ -5,19 +5,13 @@ { "x":7, "y":11, - "type":"interactable" + "type":"interactables" }, "Minecart": { "x":4, "y":3, - "type":"interactable" - }, - "Minecart": - { - "x":5, - "y":3, - "type":"interactable" + "type":"interactables" } } } \ No newline at end of file