diff --git a/stardew-access/CustomCommands.cs b/stardew-access/CustomCommands.cs index a3f748a..557d7bf 100644 --- a/stardew-access/CustomCommands.cs +++ b/stardew-access/CustomCommands.cs @@ -11,6 +11,7 @@ namespace stardew_access { internal static void Initialize() { + //TODO organise this, create separate method for all commands IModHelper? helper = MainClass.ModHelper; if (helper == null) return; @@ -349,35 +350,7 @@ namespace stardew_access helper.ConsoleCommands.Add("buildlist", "List all buildings for selection for upgrading/demolishing/painting", (string commmand, string[] args) => { - if ((Game1.activeClickableMenu is not CarpenterMenu && Game1.activeClickableMenu is not PurchaseAnimalsMenu && Game1.activeClickableMenu is not AnimalQueryMenu) || !BuildingNAnimalMenuPatches.isOnFarm) - { - MainClass.InfoLog($"Cannot list buildings."); - return; - } - - string toPrint = ""; - Farm farm = (Farm)Game1.getLocationFromName("Farm"); - Netcode.NetCollection buildings = farm.buildings; - int buildingIndex = 0; - - for (int i = 0; i < buildings.Count; i++) - { - string? name = buildings[i].nameOfIndoorsWithoutUnique; - name = (name == "null") ? buildings[i].buildingType.Value : name; - - BuildingNAnimalMenuPatches.availableBuildings[buildingIndex] = buildings[i]; - toPrint = $"{toPrint}\nIndex {buildingIndex}: {name}: At {buildings[i].tileX}x and {buildings[i].tileY}y"; - ++buildingIndex; - } - - if (toPrint == "") - { - MainClass.InfoLog("No appropriate buildings to list"); - } - else - { - MainClass.InfoLog($"Available buildings:{toPrint}\nOpen command menu and use pageup and pagedown to check the list"); - } + onBuildListCalled(); }); helper.ConsoleCommands.Add("buildsel", "Select the building index which you want to upgrade/demolish/paint", (string commmand, string[] args) => @@ -531,6 +504,33 @@ namespace stardew_access }); #endregion } + + internal static void onBuildListCalled() + { + string toPrint = ""; + Farm farm = (Farm)Game1.getLocationFromName("Farm"); + Netcode.NetCollection buildings = farm.buildings; + int buildingIndex = 0; + + for (int i = 0; i < buildings.Count; i++) + { + string? name = buildings[i].nameOfIndoorsWithoutUnique; + name = (name == "null") ? buildings[i].buildingType.Value : name; + + BuildingNAnimalMenuPatches.availableBuildings[buildingIndex] = buildings[i]; + toPrint = $"{toPrint}\nIndex {buildingIndex}: {name}: At {buildings[i].tileX}x and {buildings[i].tileY}y"; + ++buildingIndex; + } + + if (toPrint == "") + { + MainClass.InfoLog("No appropriate buildings to list"); + } + else + { + MainClass.InfoLog($"Available buildings:{toPrint}\nOpen command menu and use pageup and pagedown to check the list"); + } + } } } diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index a6683e5..a7009f9 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -14,6 +14,7 @@ namespace stardew_access { #region Global Vars & Properties #pragma warning disable CS8603 + private static int prevDate = -99; private static ModConfig? config; private Harmony? harmony; private static IMonitor? monitor; @@ -27,6 +28,7 @@ namespace stardew_access internal static ModConfig Config { get => config; set => config = value; } public static IModHelper? ModHelper { get => modHelper; } + public static StaticTiles STiles { get @@ -190,6 +192,16 @@ namespace stardew_access Other.narrateHudMessages(); Task.Delay(300).ContinueWith(_ => { isNarratingHudMessage = false; }); } + + if (Game1.player != null) + { + if (Game1.timeOfDay >= 600 && prevDate != CurrentPlayer.Date) + { + prevDate = CurrentPlayer.Date; + DebugLog("Refreshing buildlist..."); + CustomCommands.onBuildListCalled(); + } + } } private void OnButtonPressed(object? sender, ButtonPressedEventArgs? e)