From 0db51a1e3fc10d0701ce05818cc006c24fb57e01 Mon Sep 17 00:00:00 2001 From: nofilenamed Date: Thu, 16 May 2024 22:03:27 +0200 Subject: [PATCH] Updated to use 1.6.x --- ModEntry.cs | 471 +++++++++++++++++++------------------ Properties/AssemblyInfo.cs | 36 --- manifest.json | 4 +- packages.config | 2 +- 4 files changed, 241 insertions(+), 272 deletions(-) delete mode 100644 Properties/AssemblyInfo.cs diff --git a/ModEntry.cs b/ModEntry.cs index 27294c3..2e62f01 100644 --- a/ModEntry.cs +++ b/ModEntry.cs @@ -1,261 +1,266 @@ -using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; + +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; + using Netcode; + using StardewModdingAPI; using StardewModdingAPI.Events; + using StardewValley; using StardewValley.Buildings; using StardewValley.Characters; +using StardewValley.GameData.Buildings; using StardewValley.Network; -using StardewValley.Tools; -using System; -using System.Collections.Generic; -using System.Linq; namespace AnimalObserver { public class ModEntry : Mod - { - private bool m_Registered; + { + private bool m_Registered; - private ModConfig Config; + private ModConfig Config; - private EntitiesSetting Entities; + private EntitiesSetting Entities; - public override void Entry(IModHelper helper) - { - LoadConfig(); + public override void Entry(IModHelper helper) + { + LoadConfig(); - helper.Events.Input.ButtonsChanged += OnButtonsChanged; + helper.Events.Input.ButtonsChanged += OnButtonsChanged; - RegisterEvent(); - } + RegisterEvent(); + } private void LoadConfig() { - Config = Helper.ReadConfig(); + Config = Helper.ReadConfig(); - Entities = Config.Entities; - } + Entities = Config.Entities; + } - private void OnButtonsChanged(object sender, ButtonsChangedEventArgs e) - { - if (Config.Keys.Reload.JustPressed()) - { - LoadConfig(); - } + private void OnButtonsChanged(object sender, ButtonsChangedEventArgs e) + { + if (Config.Keys.Reload.JustPressed()) + { + LoadConfig(); + } - if (Config.Keys.Toggle.JustPressed()) + if (Config.Keys.Toggle.JustPressed()) { - RegisterEvent(); - } - } - - private List GetAnimals(object currentLocation) - { - List list = null; - if (currentLocation is Farm farm) - { - if (farm.animals == null || farm.animals.Count() <= 0) - { - return list; - } - list = new List(); - using (NetDictionary, SerializableDictionary, NetLongDictionary>>.ValuesCollection.Enumerator enumerator = farm.animals.Values.GetEnumerator()) - { - while (enumerator.MoveNext()) - { - FarmAnimal item = enumerator.Current; - list.Add(item); - } - return list; - } - } - if (currentLocation is AnimalHouse animalHouse) - { - if (animalHouse.animals != null && animalHouse.animals.Count() > 0) - { - list = new List(); - foreach (FarmAnimal item2 in animalHouse.animals.Values) - { - list.Add(item2); - } - } - } - return list; - - - } - - private Pet GetPet(GameLocation currentLocation) - { - foreach (NPC npc in currentLocation.characters) - { - if (npc is Pet pet) - { - return pet; - } - } - - return null; - } - - - public Vector2 GetOffsetForAnimal(Building home) - { - if (home == null) - return Config.Offsets.Pet; - - if (home is Coop) - { - return Config.Offsets.CoopAnimal; - } - else if (home is Barn) - { - return Config.Offsets.BarnAnimal; - } - - return default; - } - - private void RegisterEvent() - { - if (!m_Registered) - { - m_Registered = true; - Helper.Events.Display.RenderedWorld += OnRenderedWorld; - - } + RegisterEvent(); + } + } + + private static List GetAnimals(object currentLocation) + { + List list = null; + if (currentLocation is Farm farm) + { + if (farm.animals == null || farm.animals.Count() <= 0) + { + return list; + } + list = new List(); + using (NetDictionary, SerializableDictionary, NetLongDictionary>>.ValuesCollection.Enumerator enumerator = farm.animals.Values.GetEnumerator()) + { + while (enumerator.MoveNext()) + { + FarmAnimal item = enumerator.Current; + list.Add(item); + } + return list; + } + } + if (currentLocation is AnimalHouse animalHouse) + { + if (animalHouse.animals != null && animalHouse.animals.Count() > 0) + { + list = new List(); + foreach (FarmAnimal item2 in animalHouse.animals.Values) + { + list.Add(item2); + } + } + } + return list; + + + } + + private static Pet GetPet(GameLocation currentLocation) + { + foreach (NPC npc in currentLocation.characters) + { + if (npc is Pet pet) + { + return pet; + } + } + + return null; + } + + + public Vector2 GetOffsetForAnimal(BuildingData data) + { + if (data == null) + return Config.Offsets.Pet; + + if (data.ValidOccupantTypes[0] == "Coop") + { + return Config.Offsets.CoopAnimal; + } + else if (data.ValidOccupantTypes[0] == "Barn") + { + return Config.Offsets.BarnAnimal; + } + + return default; + } + + private void RegisterEvent() + { + if (!m_Registered) + { + m_Registered = true; + Helper.Events.Display.RenderedWorld += OnRenderedWorld; + + } else { - m_Registered = false; - Helper.Events.Display.RenderedWorld -= OnRenderedWorld; - } - } - - private double m_ShowProductTimeout; - private double m_ShowProductTime; - - private void SetupTime(ref double ms) - { - m_ShowProductTime = ms + Config.ShowIsHarvestableTime * 1000; - m_ShowProductTimeout = ms + Config.ShowIsHarvestableTime * 2000; - } - - private void OnRenderedWorld(object sender, EventArgs e) - { - if (!Context.IsWorldReady) - return; - - GameLocation currentLocation = Game1.currentLocation; - List animals = GetAnimals(currentLocation); - - double ms = Game1.currentGameTime.TotalGameTime.TotalMilliseconds; - float yOffsetFactor = 4f * (float)Math.Round(Math.Sin(ms / 250.0), 2); - - if (animals != null) - { - bool showProduct = false; - if (Config.ShowIsHarvestable) - { - if (m_ShowProductTime == default) - { - SetupTime(ref ms); - } - - showProduct = ms <= m_ShowProductTime; - } - - foreach (FarmAnimal animal in animals) - { - if (Config.ShowIsHarvestable) - { - if (showProduct && animal.currentProduce > 0 && animal.age >= animal.ageWhenMature) - { - switch (animal.currentProduce) - { - case 184://Milk Cow ID - case 186://Milk Cow ID - DrawEntity(Game1.objectSpriteSheet, Entities.CowMilk, animal, animal.home, ref yOffsetFactor); - break; - - case 436://Milk Goat ID - case 438://Milk Goat ID - DrawEntity(Game1.objectSpriteSheet, Entities.GoatMilk, animal, animal.home, ref yOffsetFactor); - break; - - case 430: //Truffle ID - if (Config.ShowTruffle) - { - DrawEntity(Game1.objectSpriteSheet, Entities.Truffle, animal, animal.home, ref yOffsetFactor); - } - break; - - - - case 440://Wool ID - DrawEntity(Game1.objectSpriteSheet, Entities.Wool, animal, animal.home, ref yOffsetFactor); - break; - } - - continue; - } - - if (ms >= m_ShowProductTimeout) - { - SetupTime(ref ms); - } - } - - if (!animal.wasPet && !animal.wasAutoPet) - { - DrawEntity(Game1.mouseCursors, Entities.Heart, animal, animal.home, ref yOffsetFactor); - } - } - } - - if (Config.PetToo) - { - Pet pet = GetPet(currentLocation); - if (pet != null && !pet.lastPetDay.Values.Any(x => x == Game1.Date.TotalDays)) - { - DrawEntity(Game1.mouseCursors, Entities.Heart, pet, null, ref yOffsetFactor); - } - } - - - - } - - - - private void DrawEntity(Texture2D spriteSheet, EntitiesConfig config, Character character, Building building, ref float yOffsetFactor) - { - Vector2 offset = GetOffsetForAnimal(building); - offset += character.position; - - offset += new Vector2(character.Sprite.getWidth() / 2, yOffsetFactor); - - DrawEntity(Game1.mouseCursors, Entities.Bubble, ref offset); - - offset += config.Offset; - - DrawEntity(spriteSheet, config, ref offset); - } - - private void DrawEntity(Texture2D spriteSheet, EntitiesConfig config, ref Vector2 offset) - { - Game1.spriteBatch.Draw( - spriteSheet, - Game1.GlobalToLocal(Game1.uiViewport, offset), - new Rectangle(config.X, config.Y, config.Width, config.Height), - config.Color, - config.Rotation, - config.Origin, - config.Scale, - config.SpriteEffects, - 0f); - } - } + m_Registered = false; + Helper.Events.Display.RenderedWorld -= OnRenderedWorld; + } + } + + private double m_ShowProductTimeout; + private double m_ShowProductTime; + + private void SetupTime(ref double ms) + { + m_ShowProductTime = ms + Config.ShowIsHarvestableTime * 1000; + m_ShowProductTimeout = ms + Config.ShowIsHarvestableTime * 2000; + } + + private void OnRenderedWorld(object sender, EventArgs e) + { + if (!Context.IsWorldReady) + return; + + GameLocation currentLocation = Game1.currentLocation; + List animals = GetAnimals(currentLocation); + + double ms = Game1.currentGameTime.TotalGameTime.TotalMilliseconds; + float yOffsetFactor = 4f * (float)Math.Round(Math.Sin(ms / 250.0), 2); + + if (animals != null) + { + bool showProduct = false; + if (Config.ShowIsHarvestable) + { + if (m_ShowProductTime == default) + { + SetupTime(ref ms); + } + + showProduct = ms <= m_ShowProductTime; + } + + foreach (FarmAnimal animal in animals) + { + if (Config.ShowIsHarvestable) + { + if (showProduct && !string.IsNullOrEmpty(animal.currentProduce.Value) && animal.isAdult()) + { + switch (animal.currentProduce.Value) + { + case "(O)184"://Milk Cow ID + case "(O)186"://Milk Cow ID + { + DrawEntity(Game1.objectSpriteSheet, Entities.CowMilk, animal, animal.home, ref yOffsetFactor); + break; + } + + case "(O)436"://Milk Goat ID + case "(O)438"://Milk Goat ID + { + DrawEntity(Game1.objectSpriteSheet, Entities.GoatMilk, animal, animal.home, ref yOffsetFactor); + break; + } + + case "(O)430": //Truffle ID + { + if (Config.ShowTruffle) + { + DrawEntity(Game1.objectSpriteSheet, Entities.Truffle, animal, animal.home, ref yOffsetFactor); + } + break; + } + + case "(O)440"://Wool ID + { + DrawEntity(Game1.objectSpriteSheet, Entities.Wool, animal, animal.home, ref yOffsetFactor); + break; + } + } + + continue; + } + + if (ms >= m_ShowProductTimeout) + { + SetupTime(ref ms); + } + } + + if (!animal.wasPet.Value && !animal.wasAutoPet.Value) + { + DrawEntity(Game1.mouseCursors, Entities.Heart, animal, animal.home, ref yOffsetFactor); + } + } + } + + if (Config.PetToo) + { + Pet pet = GetPet(currentLocation); + if (pet != null && !pet.lastPetDay.Values.Any(x => x == Game1.Date.TotalDays)) + { + DrawEntity(Game1.mouseCursors, Entities.Heart, pet, null, ref yOffsetFactor); + } + } + } + + private void DrawEntity(Texture2D spriteSheet, EntitiesConfig config, Character character, Building building, ref float yOffsetFactor) + { + Vector2 offset = GetOffsetForAnimal(building.GetData()); + offset += character.position.Value; + + offset += new Vector2(character.Sprite.getWidth() / 2, yOffsetFactor); + + DrawEntity(Game1.mouseCursors, Entities.Bubble, ref offset); + + offset += config.Offset; + + DrawEntity(spriteSheet, config, ref offset); + } + + private static void DrawEntity(Texture2D spriteSheet, EntitiesConfig config, ref Vector2 offset) + { + Game1.spriteBatch.Draw( + spriteSheet, + Game1.GlobalToLocal(Game1.uiViewport, offset), + new Rectangle(config.X, config.Y, config.Width, config.Height), + config.Color, + config.Rotation, + config.Origin, + config.Scale, + config.SpriteEffects, + 0f); + } + } } diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs deleted file mode 100644 index 4fab947..0000000 --- a/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("AnimalObserver")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("smapi.stardew.animalobserver")] -[assembly: AssemblyCopyright("Copyright © 2021 nofilenamed")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("17cff380-bed4-4c89-8ea4-71470af45fdf")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/manifest.json b/manifest.json index 51495a0..e901f98 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { "Name": "AnimalObserver", "Author": "nofilenamed", - "Version": "1.0.3", + "Version": "1.0.4", "Description": "Visual status and product of your animals.", "UniqueID": "NFN.ANIMOBS", "EntryDll": "AnimalObserver.dll", - "MinimumApiVersion": "3.9.5", + "MinimumApiVersion": "4.1.1", "UpdateKeys": ["Nexus:8653"] } \ No newline at end of file diff --git a/packages.config b/packages.config index 3727d0d..7ecfd0f 100644 --- a/packages.config +++ b/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file