diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..5bfc44bd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,67 @@ +# topmost editorconfig +root: true + +########## +## General formatting +## documentation: https://editorconfig.org +########## +[*] +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 + +[*.{csproj,json,nuspec,targets}] +indent_size = 2 + +[*.csproj] +insert_final_newline = false + +########## +## C# formatting +## documentation: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference +########## +[*.cs] + +#sort 'system' usings first +dotnet_sort_system_directives_first = true + +# use 'this.' qualifier +dotnet_style_qualification_for_field = true:error +dotnet_style_qualification_for_property = true:error +dotnet_style_qualification_for_method = true:error +dotnet_style_qualification_for_event = true:error + +# use language keywords (like int) instead of type (like Int32) +dotnet_style_predefined_type_for_locals_parameters_members = true:error +dotnet_style_predefined_type_for_member_access = true:error + +# don't use 'var' for language keywords +csharp_style_var_for_built_in_types = false:error + +# suggest modern C# features where simpler +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_explicit_tuple_names = true:suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true:suggestion +csharp_style_conditional_delegate_call = true:suggestion +csharp_prefer_simple_default_expression = true:suggestion + +# prefer method block bodies +csharp_style_expression_bodied_methods = false:suggestion +csharp_style_expression_bodied_constructors = false:suggestion + +# prefer property expression bodies +csharp_style_expression_bodied_properties = true:suggestion +csharp_style_expression_bodied_indexers = true:suggestion +csharp_style_expression_bodied_accessors = true:suggestion + +# prefer inline out variables +csharp_style_inlined_variable_declaration = true:warning + +# avoid superfluous braces +csharp_prefer_braces = false:suggestion diff --git a/GeneralMods/AdvancedSaveBackup/AdvancedSaveBackup.csproj b/GeneralMods/AdvancedSaveBackup/AdvancedSaveBackup.csproj index eeae3c37..46bf2a7a 100644 --- a/GeneralMods/AdvancedSaveBackup/AdvancedSaveBackup.csproj +++ b/GeneralMods/AdvancedSaveBackup/AdvancedSaveBackup.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ AdvancedSaveBackup v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -83,19 +84,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/AdvancedSaveBackup/Framework/ModConfig.cs b/GeneralMods/AdvancedSaveBackup/Framework/ModConfig.cs index 1612c9f8..be464717 100644 --- a/GeneralMods/AdvancedSaveBackup/Framework/ModConfig.cs +++ b/GeneralMods/AdvancedSaveBackup/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.SaveBackup.Framework +namespace Omegasis.SaveBackup.Framework { /// The mod configuration. internal class ModConfig diff --git a/GeneralMods/AdvancedSaveBackup/SaveBackup.cs b/GeneralMods/AdvancedSaveBackup/SaveBackup.cs index b10f0878..fb19a21e 100644 --- a/GeneralMods/AdvancedSaveBackup/SaveBackup.cs +++ b/GeneralMods/AdvancedSaveBackup/SaveBackup.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.IO.Compression; using System.Linq; diff --git a/GeneralMods/AdvancedSaveBackup/packages.config b/GeneralMods/AdvancedSaveBackup/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/AdvancedSaveBackup/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/AutoSpeed/AutoSpeed.cs b/GeneralMods/AutoSpeed/AutoSpeed.cs index ec6bb545..80d44cdb 100644 --- a/GeneralMods/AutoSpeed/AutoSpeed.cs +++ b/GeneralMods/AutoSpeed/AutoSpeed.cs @@ -1,4 +1,4 @@ -using System; +using System; using Omegasis.AutoSpeed.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; diff --git a/GeneralMods/AutoSpeed/AutoSpeed.csproj b/GeneralMods/AutoSpeed/AutoSpeed.csproj index 23545179..50269de6 100644 --- a/GeneralMods/AutoSpeed/AutoSpeed.csproj +++ b/GeneralMods/AutoSpeed/AutoSpeed.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ AutoSpeed v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -81,19 +82,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/AutoSpeed/Framework/ModConfig.cs b/GeneralMods/AutoSpeed/Framework/ModConfig.cs index ee3eef38..2e6dc10f 100644 --- a/GeneralMods/AutoSpeed/Framework/ModConfig.cs +++ b/GeneralMods/AutoSpeed/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.AutoSpeed.Framework +namespace Omegasis.AutoSpeed.Framework { /// The mod configuration. internal class ModConfig diff --git a/GeneralMods/AutoSpeed/packages.config b/GeneralMods/AutoSpeed/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/AutoSpeed/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/BillboardAnywhere/BillboardAnywhere.cs b/GeneralMods/BillboardAnywhere/BillboardAnywhere.cs index 50480d7b..e09dadda 100644 --- a/GeneralMods/BillboardAnywhere/BillboardAnywhere.cs +++ b/GeneralMods/BillboardAnywhere/BillboardAnywhere.cs @@ -1,4 +1,4 @@ -using Omegasis.BillboardAnywhere.Framework; +using Omegasis.BillboardAnywhere.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; diff --git a/GeneralMods/BillboardAnywhere/BillboardAnywhere.csproj b/GeneralMods/BillboardAnywhere/BillboardAnywhere.csproj index a3638df8..d98ba599 100644 --- a/GeneralMods/BillboardAnywhere/BillboardAnywhere.csproj +++ b/GeneralMods/BillboardAnywhere/BillboardAnywhere.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ BillboardAnywhere v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -83,19 +84,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/BillboardAnywhere/Framework/ModConfig.cs b/GeneralMods/BillboardAnywhere/Framework/ModConfig.cs index e57f51ce..ec6f3b5c 100644 --- a/GeneralMods/BillboardAnywhere/Framework/ModConfig.cs +++ b/GeneralMods/BillboardAnywhere/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.BillboardAnywhere.Framework +namespace Omegasis.BillboardAnywhere.Framework { /// The mod configuration. internal class ModConfig diff --git a/GeneralMods/BillboardAnywhere/packages.config b/GeneralMods/BillboardAnywhere/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/BillboardAnywhere/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/BuildEndurance/BuildEndurance.cs b/GeneralMods/BuildEndurance/BuildEndurance.cs index 763e619a..d826fbc4 100644 --- a/GeneralMods/BuildEndurance/BuildEndurance.cs +++ b/GeneralMods/BuildEndurance/BuildEndurance.cs @@ -1,6 +1,5 @@ -using System; +using System; using System.IO; -using System.Linq; using Omegasis.BuildEndurance.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; @@ -17,9 +16,6 @@ namespace Omegasis.BuildEndurance /// The relative path for the current player's data file. private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); - /// The absolute path for the current player's legacy data file. - private string LegacyDataFilePath => Path.Combine(this.Helper.DirectoryPath, "PlayerData", $"BuildEndurance_data_{Game1.player.Name}.txt"); - /// The mod settings. private ModConfig Config; @@ -38,10 +34,10 @@ namespace Omegasis.BuildEndurance /// Whether the player was eating last time we checked. private bool WasEating; - public IModHelper ModHelper; public IMonitor ModMonitor; + /********* ** Public methods *********/ @@ -107,9 +103,9 @@ namespace Omegasis.BuildEndurance } // give XP when player stays up too late or collapses - if (!this.WasCollapsed && shouldFarmerPassout()) + if (!this.WasCollapsed && this.shouldFarmerPassout()) { - + this.PlayerData.CurrentExp += this.Config.ExpForCollapsing; this.WasCollapsed = true; //this.Monitor.Log("The player has collapsed!"); @@ -128,7 +124,6 @@ namespace Omegasis.BuildEndurance this.WasEating = false; // load player data - this.MigrateLegacyData(); this.PlayerData = this.Helper.ReadJsonFile(this.DataFilePath) ?? new PlayerData(); if (this.PlayerData.OriginalMaxStamina == 0) this.PlayerData.OriginalMaxStamina = Game1.player.MaxStamina; @@ -187,44 +182,7 @@ namespace Omegasis.BuildEndurance this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData); } - /// Migrate the legacy settings for the current player. - private void MigrateLegacyData() - { - // skip if no legacy data or new data already exists - if (!File.Exists(this.LegacyDataFilePath) || File.Exists(this.DataFilePath)) - return; - - // migrate to new file - try - { - string[] text = File.ReadAllLines(this.LegacyDataFilePath); - this.Helper.WriteJsonFile(this.DataFilePath, new PlayerData - { - CurrentLevel = Convert.ToInt32(text[3]), - CurrentExp = Convert.ToDouble(text[5]), - ExpToNextLevel = Convert.ToDouble(text[7]), - BaseStaminaBonus = Convert.ToInt32(text[9]), - CurrentLevelStaminaBonus = Convert.ToInt32(text[11]), - ClearModEffects = Convert.ToBoolean(text[14]), - OriginalMaxStamina = Convert.ToInt32(text[16]), - NightlyStamina = Convert.ToInt32(text[18]) - }); - - FileInfo file = new FileInfo(this.LegacyDataFilePath); - file.Delete(); - if (!file.Directory.EnumerateFiles().Any()) - file.Directory.Delete(); - } - catch (Exception ex) - { - this.Monitor.Log($"Error migrating data from the legacy 'PlayerData' folder for the current player. Technical details:\n {ex}", LogLevel.Error); - } - } - - /// - /// Try and emulate the old Game1.shouldFarmerPassout logic. - /// - /// + /// Try and emulate the old Game1.shouldFarmerPassout logic. public bool shouldFarmerPassout() { if (Game1.player.stamina <= 0 || Game1.player.health <= 0 || Game1.timeOfDay >= 2600) return true; diff --git a/GeneralMods/BuildEndurance/BuildEndurance.csproj b/GeneralMods/BuildEndurance/BuildEndurance.csproj index 0fd10fa4..83e9f2df 100644 --- a/GeneralMods/BuildEndurance/BuildEndurance.csproj +++ b/GeneralMods/BuildEndurance/BuildEndurance.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ BuildEndurance v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -82,19 +83,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/BuildEndurance/packages.config b/GeneralMods/BuildEndurance/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/BuildEndurance/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/BuildHealth/BuildHealth.cs b/GeneralMods/BuildHealth/BuildHealth.cs index 1ba8210c..bbdee068 100644 --- a/GeneralMods/BuildHealth/BuildHealth.cs +++ b/GeneralMods/BuildHealth/BuildHealth.cs @@ -1,6 +1,5 @@ -using System; +using System; using System.IO; -using System.Linq; using Omegasis.BuildHealth.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; @@ -17,9 +16,6 @@ namespace Omegasis.BuildHealth /// The relative path for the current player's data file. private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); - /// The absolute path for the current player's legacy data file. - private string LegacyDataFilePath => Path.Combine(this.Helper.DirectoryPath, "PlayerData", $"BuildHealth_data_{Game1.player.Name}.txt"); - /// The mod settings and player data. private ModConfig Config; @@ -103,7 +99,7 @@ namespace Omegasis.BuildHealth this.LastHealth = player.health; // give XP when player stays up too late or collapses - if (!this.WasCollapsed && shouldFarmerPassout()) + if (!this.WasCollapsed && this.shouldFarmerPassout()) { this.PlayerData.CurrentExp += this.Config.ExpForCollapsing; this.WasCollapsed = true; @@ -122,7 +118,6 @@ namespace Omegasis.BuildHealth this.WasCollapsed = false; // load player data - this.MigrateLegacyData(); this.PlayerData = this.Helper.ReadJsonFile(this.DataFilePath) ?? new PlayerData(); if (this.PlayerData.OriginalMaxHealth == 0) this.PlayerData.OriginalMaxHealth = Game1.player.maxHealth; @@ -177,39 +172,6 @@ namespace Omegasis.BuildHealth this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData); } - /// Migrate the legacy settings for the current player. - private void MigrateLegacyData() - { - // skip if no legacy data or new data already exists - if (!File.Exists(this.LegacyDataFilePath) || File.Exists(this.DataFilePath)) - return; - - // migrate to new file - try - { - string[] text = File.ReadAllLines(this.LegacyDataFilePath); - this.Helper.WriteJsonFile(this.DataFilePath, new PlayerData - { - CurrentLevel = Convert.ToInt32(text[3]), - CurrentExp = Convert.ToDouble(text[5]), - ExpToNextLevel = Convert.ToDouble(text[7]), - BaseHealthBonus = Convert.ToInt32(text[9]), - CurrentLevelHealthBonus = Convert.ToInt32(text[11]), - ClearModEffects = Convert.ToBoolean(text[14]), - OriginalMaxHealth = Convert.ToInt32(text[16]) - }); - - FileInfo file = new FileInfo(this.LegacyDataFilePath); - file.Delete(); - if (!file.Directory.EnumerateFiles().Any()) - file.Directory.Delete(); - } - catch (Exception ex) - { - this.Monitor.Log($"Error migrating data from the legacy 'PlayerData' folder for the current player. Technical details:\n {ex}", LogLevel.Error); - } - } - public bool shouldFarmerPassout() { if (Game1.player.stamina <= 0 || Game1.player.health <= 0 || Game1.timeOfDay >= 2600) return true; diff --git a/GeneralMods/BuildHealth/BuildHealth.csproj b/GeneralMods/BuildHealth/BuildHealth.csproj index d1627a93..f1846f3b 100644 --- a/GeneralMods/BuildHealth/BuildHealth.csproj +++ b/GeneralMods/BuildHealth/BuildHealth.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ BuildHealth v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -82,19 +83,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/BuildHealth/Framework/ModConfig.cs b/GeneralMods/BuildHealth/Framework/ModConfig.cs index e0849f74..e627f69b 100644 --- a/GeneralMods/BuildHealth/Framework/ModConfig.cs +++ b/GeneralMods/BuildHealth/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.BuildHealth.Framework +namespace Omegasis.BuildHealth.Framework { /// The mod settings and player data. internal class ModConfig diff --git a/GeneralMods/BuildHealth/Framework/PlayerData.cs b/GeneralMods/BuildHealth/Framework/PlayerData.cs index 1e9cbb8e..2995d74f 100644 --- a/GeneralMods/BuildHealth/Framework/PlayerData.cs +++ b/GeneralMods/BuildHealth/Framework/PlayerData.cs @@ -1,4 +1,4 @@ -namespace Omegasis.BuildHealth.Framework +namespace Omegasis.BuildHealth.Framework { /// The data for the current player. internal class PlayerData diff --git a/GeneralMods/BuildHealth/packages.config b/GeneralMods/BuildHealth/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/BuildHealth/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/BuyBackCollectables/BuyBackCollectables.cs b/GeneralMods/BuyBackCollectables/BuyBackCollectables.cs index 91d89a06..2493af01 100644 --- a/GeneralMods/BuyBackCollectables/BuyBackCollectables.cs +++ b/GeneralMods/BuyBackCollectables/BuyBackCollectables.cs @@ -1,4 +1,4 @@ -using Omegasis.BuyBackCollectables.Framework; +using Omegasis.BuyBackCollectables.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; diff --git a/GeneralMods/BuyBackCollectables/BuyBackCollectables.csproj b/GeneralMods/BuyBackCollectables/BuyBackCollectables.csproj index 488853fb..dcba9f4e 100644 --- a/GeneralMods/BuyBackCollectables/BuyBackCollectables.csproj +++ b/GeneralMods/BuyBackCollectables/BuyBackCollectables.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ BuyBackCollectables v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -84,19 +85,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/BuyBackCollectables/Framework/BuyBackMenu.cs b/GeneralMods/BuyBackCollectables/Framework/BuyBackMenu.cs index 92e6b3e6..24bfcbf4 100644 --- a/GeneralMods/BuyBackCollectables/Framework/BuyBackMenu.cs +++ b/GeneralMods/BuyBackCollectables/Framework/BuyBackMenu.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; diff --git a/GeneralMods/BuyBackCollectables/Framework/ModConfig.cs b/GeneralMods/BuyBackCollectables/Framework/ModConfig.cs index deee9c28..c1299949 100644 --- a/GeneralMods/BuyBackCollectables/Framework/ModConfig.cs +++ b/GeneralMods/BuyBackCollectables/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.BuyBackCollectables.Framework +namespace Omegasis.BuyBackCollectables.Framework { /// The mod configuration. internal class ModConfig diff --git a/GeneralMods/BuyBackCollectables/packages.config b/GeneralMods/BuyBackCollectables/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/BuyBackCollectables/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/CustomNPCFramework/Class1.cs b/GeneralMods/CustomNPCFramework/Class1.cs index 117b59eb..49ea38ef 100644 --- a/GeneralMods/CustomNPCFramework/Class1.cs +++ b/GeneralMods/CustomNPCFramework/Class1.cs @@ -1,20 +1,14 @@ -using CustomNPCFramework.Framework.Enums; -using CustomNPCFramework.Framework.Graphics; -using CustomNPCFramework.Framework.ModularNPCS; -using CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases; -using CustomNPCFramework.Framework.ModularNPCS.ColorCollections; -using CustomNPCFramework.Framework.NPCS; -using CustomNPCFramework.Framework.Utilities; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI; -using StardewValley; using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using CustomNPCFramework.Framework.Enums; +using CustomNPCFramework.Framework.Graphics; +using CustomNPCFramework.Framework.ModularNpcs.ColorCollections; +using CustomNPCFramework.Framework.NPCS; +using CustomNPCFramework.Framework.Utilities; +using Microsoft.Xna.Framework; +using StardewModdingAPI; +using StardewValley; namespace CustomNPCFramework { @@ -44,91 +38,73 @@ namespace CustomNPCFramework /// Find way to make sideways shirts render correctly. /// ///Get suggestions from modding community on requests and ways to improve the mod. - /// - public class Class1 : Mod { - /// - /// The mod helper for the mod. - /// + /// The mod helper for the mod. public static IModHelper ModHelper; - /// - /// The mod monitor for the mod. - /// + + /// The mod monitor for the mod. public static IMonitor ModMonitor; - /// - /// The npc tracker for the mod. Keeps track of all npcs added by the custom framework and cleans them up during saving. - /// - public static NPCTracker npcTracker; - /// - /// Keeps track of all of the asets/textures added in by the framework. Also manages all of the asset managers that are the ones actually managing the textures. - /// + /// The npc tracker for the mod. Keeps track of all npcs added by the custom framework and cleans them up during saving. + public static NpcTracker npcTracker; + + /// Keeps track of all of the asets/textures added in by the framework. Also manages all of the asset managers that are the ones actually managing the textures. public static AssetPool assetPool; public static IManifest Manifest; - - /// - /// Ran when loading the SMAPI. Used to initialize data. - /// - /// + + /// The mod entry point, called after the mod is first loaded. + /// Provides simplified APIs for writing mods. public override void Entry(IModHelper helper) { ModHelper = this.Helper; ModMonitor = this.Monitor; - Manifest = ModManifest; + Manifest = this.ModManifest; - StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_LoadChar; + StardewModdingAPI.Events.SaveEvents.AfterLoad += this.SaveEvents_LoadChar; - StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave; - StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave; + StardewModdingAPI.Events.SaveEvents.BeforeSave += this.SaveEvents_BeforeSave; + StardewModdingAPI.Events.SaveEvents.AfterSave += this.SaveEvents_AfterSave; - StardewModdingAPI.Events.PlayerEvents.Warped += LocationEvents_CurrentLocationChanged; - StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick; - npcTracker = new NPCTracker(); + StardewModdingAPI.Events.PlayerEvents.Warped += this.LocationEvents_CurrentLocationChanged; + StardewModdingAPI.Events.GameEvents.UpdateTick += this.GameEvents_UpdateTick; + npcTracker = new NpcTracker(); assetPool = new AssetPool(); var assetManager = new AssetManager(); assetPool.addAssetManager(new KeyValuePair("testNPC", assetManager)); - initializeExamples(); - initializeAssetPool(); + this.initializeExamples(); + this.initializeAssetPool(); assetPool.loadAllAssets(); } - /// - /// Initialize the asset pool with some test variables. - /// + /// Initialize the asset pool with some test variables. public void initializeAssetPool() { string path = Path.Combine(ModHelper.DirectoryPath, "Content", "Graphics", "NPCS"); assetPool.getAssetManager("testNPC").addPathCreateDirectory(new KeyValuePair("characters", path)); } - /// - /// A function that is called when the game finishes saving. - /// - /// - /// + /// A function that is called when the game finishes saving. + /// The event sender. + /// The event arguments. private void SaveEvents_AfterSave(object sender, EventArgs e) { npcTracker.afterSave(); } - /// - /// A function that is called when the game is about to load. Used to clean up all the npcs from the game world to prevent it from crashing. - /// - /// - /// + /// A function that is called when the game is about to load. Used to clean up all the npcs from the game world to prevent it from crashing. + /// The event sender. + /// The event arguments. private void SaveEvents_BeforeSave(object sender, EventArgs e) { npcTracker.cleanUpBeforeSave(); } - /// - /// Called upon 60 times a second. For testing purposes only. Will remove in future release. - /// - /// - /// + /// Called upon 60 times a second. For testing purposes only. Will remove in future release. + /// The event sender. + /// The event arguments. private void GameEvents_UpdateTick(object sender, EventArgs e) { /* @@ -147,47 +123,37 @@ namespace CustomNPCFramework */ } - /// - /// Called when the player's location changes. - /// - /// - /// - private void LocationEvents_CurrentLocationChanged(object sender, StardewModdingAPI.Events.EventArgsPlayerWarped e) - { - - } + /// Called when the player's location changes. + /// The event sender. + /// The event arguments. + private void LocationEvents_CurrentLocationChanged(object sender, StardewModdingAPI.Events.EventArgsPlayerWarped e) { } - /// - /// Used to spawn a custom npc just as an example. Don't keep this code. - /// GENERATE NPC AND CALL THE CODE - /// - /// - /// + /// Used to spawn a custom npc just as an example. Don't keep this code. GENERATE NPC AND CALL THE CODE + /// The event sender. + /// The event arguments. private void SaveEvents_LoadChar(object sender, EventArgs e) { - ExtendedNPC myNpc3 = assetPool.generateNPC(Genders.female, 0, 1,new StandardColorCollection(null, null, Color.Blue, null, Color.Yellow, null)); - MerchantNPC merch = new MerchantNPC(new List() + ExtendedNpc myNpc3 = assetPool.generateNPC(Genders.female, 0, 1, new StandardColorCollection(null, null, Color.Blue, null, Color.Yellow, null)); + MerchantNpc merch = new MerchantNpc(new List() { new StardewValley.Object(475,999) }, myNpc3); - npcTracker.addNewNPCToLocation(Game1.getLocationFromName("BusStop", false), merch,new Vector2(2,23)); + npcTracker.addNewNpcToLocation(Game1.getLocationFromName("BusStop", false), merch, new Vector2(2, 23)); } - /// - /// Used to initialize examples for other modders to look at as reference. - /// + /// Used to initialize examples for other modders to look at as reference. public void initializeExamples() { return; string dirPath = Path.Combine(ModHelper.DirectoryPath, "Content", "Templates"); - var aManager=assetPool.getAssetManager("testNPC"); + var aManager = assetPool.getAssetManager("testNPC"); aManager.addPathCreateDirectory(new KeyValuePair("templates", dirPath)); - string filePath =Path.Combine(dirPath, "Example.json"); + string filePath = Path.Combine(dirPath, "Example.json"); if (!File.Exists(filePath)) { string getRelativePath = getShortenedDirectory(filePath); ModMonitor.Log("THIS IS THE PATH::: " + getRelativePath); - AssetInfo info = new AssetInfo("MyExample",new NamePairings("StandingExampleL", "StandingExampleR", "StandingExampleU", "StandingExampleD"), new NamePairings("MovingExampleL", "MovingExampleR", "MovingExampleU", "MovingExampleD"), new NamePairings("SwimmingExampleL", "SwimmingExampleR", "SwimmingExampleU", "SwimmingExampleD"), new NamePairings("SittingExampleL", "SittingExampleR", "SittingExampleU", "SittingExampleD"), new Vector2(16, 16), false); + AssetInfo info = new AssetInfo("MyExample", new NamePairings("StandingExampleL", "StandingExampleR", "StandingExampleU", "StandingExampleD"), new NamePairings("MovingExampleL", "MovingExampleR", "MovingExampleU", "MovingExampleD"), new NamePairings("SwimmingExampleL", "SwimmingExampleR", "SwimmingExampleU", "SwimmingExampleD"), new NamePairings("SittingExampleL", "SittingExampleR", "SittingExampleU", "SittingExampleD"), new Vector2(16, 16), false); info.writeToJson(filePath); } @@ -205,31 +171,22 @@ namespace CustomNPCFramework } } - /// - /// Used to splice the mod directory to get relative paths. - /// - /// - /// + /// Used to splice the mod directory to get relative paths. public static string getShortenedDirectory(string path) { string lol = (string)path.Clone(); - string[] spliter = lol.Split(new string[] { ModHelper.DirectoryPath },StringSplitOptions.None); + string[] spliter = lol.Split(new string[] { ModHelper.DirectoryPath }, StringSplitOptions.None); try { return spliter[1]; } - catch(Exception err) + catch { - err.ToString(); return spliter[0]; } } - /// - /// Used to finish cleaning up absolute asset paths into a shortened relative path. - /// - /// - /// + /// Used to finish cleaning up absolute asset paths into a shortened relative path. public static string getRelativeDirectory(string path) { string s = getShortenedDirectory(path); diff --git a/GeneralMods/CustomNPCFramework/CustomNPCFramework.csproj b/GeneralMods/CustomNPCFramework/CustomNPCFramework.csproj index 20071e85..a6467cf3 100644 --- a/GeneralMods/CustomNPCFramework/CustomNPCFramework.csproj +++ b/GeneralMods/CustomNPCFramework/CustomNPCFramework.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,9 +11,6 @@ CustomNPCFramework v4.5 512 - - - true @@ -70,6 +67,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -93,20 +93,20 @@ - - - - + + + + - - - - - - - - - + + + + + + + + + @@ -116,24 +116,7 @@ - - - - + - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/GeneralMods/CustomNPCFramework/Framework/Enums/AnimationType.cs b/GeneralMods/CustomNPCFramework/Framework/Enums/AnimationType.cs index 15fa24b8..9f3300b2 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Enums/AnimationType.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Enums/AnimationType.cs @@ -1,31 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace CustomNPCFramework.Framework.Enums { - /// - /// A enum of different types of animations supported by the framework. - /// + /// A enum of different types of animations supported by the framework. public enum AnimationType { - /// - /// A key to be used whenever an npc uses a standing animation. - /// + /// A key to be used whenever an npc uses a standing animation. standing, - /// - /// A key to be used wheneven an npc uses a walking/moving animation. - /// + + /// A key to be used wheneven an npc uses a walking/moving animation. walking, - /// - /// A key to be used whenever an npc uses a swimming animation. - /// + + /// A key to be used whenever an npc uses a swimming animation. swimming, - /// - /// A key to be used whenever an npc uses a sitting animation. - /// + + /// A key to be used whenever an npc uses a sitting animation. sitting } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Enums/Direction.cs b/GeneralMods/CustomNPCFramework/Framework/Enums/Direction.cs index e894f068..6d0c753f 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Enums/Direction.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Enums/Direction.cs @@ -1,36 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace CustomNPCFramework.Framework.Enums { - /// - /// An enum to be used to signify directions. - /// The enum order corresponds to the same order Stardew Valley uses for directions where - /// Up=0 - /// Right=1 - /// Down=2 - /// Left=3 - /// + /// An enum to be used to signify directions. The enum order corresponds to the same order Stardew Valley uses for directions. public enum Direction { - /// - /// Used to signify something to face/move up. - /// - up, - /// - /// Used to signify something to face/move right. - /// - right, - /// - /// Used to signify something to face/move down. - /// - down, - /// - /// Used to signify something to face/move left. - /// - left + /// Used to signify something to face/move up. + up = 0, + + /// Used to signify something to face/move right. + right = 1, + + /// Used to signify something to face/move down. + down = 2, + + /// Used to signify something to face/move left. + left = 3 } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Enums/Genders.cs b/GeneralMods/CustomNPCFramework/Framework/Enums/Genders.cs index b1299af0..15050941 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Enums/Genders.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Enums/Genders.cs @@ -1,28 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using StardewValley; namespace CustomNPCFramework.Framework.Enums { - /// - /// Gender enum to signify the different genders for npcs. - /// Do what you want with this. For code simplicity anything that is non-binary is specified under other. - /// + /// Gender enum to signify the different genders for NPCs. Do what you want with this. For code simplicity anything that is non-binary is specified under other. public enum Genders { - /// - /// Used for npcs to signify that they are the male gender. - /// - male, - /// - /// Used for npcs to signify that they are the female gender. - /// - female, - /// - /// Used for npcs to signify that they are a non gender binary gender. - /// - other + /// Used for npcs to signify that they are the male gender. + male = NPC.male, + + /// Used for npcs to signify that they are the female gender. + female = NPC.female, + + /// Used for npcs to signify that they are a non gender binary gender. + other = NPC.undefined } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Enums/PartType.cs b/GeneralMods/CustomNPCFramework/Framework/Enums/PartType.cs index aab5d3b7..46712e60 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Enums/PartType.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Enums/PartType.cs @@ -1,55 +1,36 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace CustomNPCFramework.Framework.Enums { - /// - /// An enum used to signify the different asset types that can be used for npcs. - /// + /// An enum used to signify the different asset types that can be used for NPCs. public enum PartType { - /// - /// Used to signify that the asset is of the body part category. Without this the npc is basically a ghost. - /// + /// Used to signify that the asset is of the body part category. Without this the npc is basically a ghost. body, - /// - /// Used to signify that the asset is of the eyes part category. The window to the soul. - /// + + /// Used to signify that the asset is of the eyes part category. The window to the soul. eyes, - /// - /// Used to signify that the asset is of the hair part category. Volume looks good in 2D. - /// + + /// Used to signify that the asset is of the hair part category. Volume looks good in 2D. hair, - /// - /// Used to signify that the asset is of the shirt part category.No shirt = no service. - /// + + /// Used to signify that the asset is of the shirt part category.No shirt = no service. shirt, - /// - /// Used to signify that the asset is of the pants/bottoms part category. Also known as bottoms, skirts, shorts, etc. - /// + + /// Used to signify that the asset is of the pants/bottoms part category. Also known as bottoms, skirts, shorts, etc. pants, - /// - /// Used to signify that the asset is of the shoes part category. Lace up those kicks. - /// + + /// Used to signify that the asset is of the shoes part category. Lace up those kicks. shoes, - /// - /// Used to signify that the asset is of the accessort part category. Got to wear that bling. - /// + + /// Used to signify that the asset is of the accessort part category. Got to wear that bling. accessory, - /// - /// Used to signify that the asset is of the other part category. Who knows what this really is... - /// + + /// Used to signify that the asset is of the other part category. Who knows what this really is... other, - /// - /// Used to signify that the asset is of the swimsuit part category. Got to be decent when taking a dip. - /// + + /// Used to signify that the asset is of the swimsuit part category. Got to be decent when taking a dip. swimsuit, - /// - /// Used to signify that the asset is of the amrs part category. Arms need to be rendered above a shirt on npcs otherwise they get covered. - /// + + /// Used to signify that the asset is of the amrs part category. Arms need to be rendered above a shirt on npcs otherwise they get covered. arms } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Enums/Seasons.cs b/GeneralMods/CustomNPCFramework/Framework/Enums/Seasons.cs index e8e6cd7f..47f0a22b 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Enums/Seasons.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Enums/Seasons.cs @@ -1,36 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - - namespace CustomNPCFramework.Framework.Enums { - /// - /// An enum signifying the different seasons that are supported when chosing npc graphics. - /// + /// An enum signifying the different seasons that are supported when choosing NPC graphics. public enum Seasons { - /// - /// The spring season. This ensures that a corresponding graphic with this enum in it's seasons list can be chosen in the spring time. - /// Also used for functionality to check seasons. - /// + /// The spring season. This ensures that a corresponding graphic with this enum in it's seasons list can be chosen in the spring time. Also used for functionality to check seasons. spring, - /// - /// The summer season. This ensures that a corresponding graphic with this enum in it's seasons list can be chosen in the summer time. - /// Also used for functionality to check seasons. - /// + + /// The summer season. This ensures that a corresponding graphic with this enum in it's seasons list can be chosen in the summer time. Also used for functionality to check seasons. summer, - /// - /// The fall season. This ensures that a corresponding graphic with this enum in it's seasons list can be chosen in the fall time. - /// Also used for functionality to check seasons. - /// + + /// The fall season. This ensures that a corresponding graphic with this enum in it's seasons list can be chosen in the fall time. Also used for functionality to check seasons. fall, - /// - /// The winter season. This ensures that a corresponding graphic with this enum in it's seasons list can be chosen in the winter time. - /// Also used for functionality to check seasons. - /// + + /// The winter season. This ensures that a corresponding graphic with this enum in it's seasons list can be chosen in the winter time. Also used for functionality to check seasons. winter } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetInfo.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetInfo.cs index adc5d387..8ad12a14 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetInfo.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetInfo.cs @@ -1,92 +1,65 @@ -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Xna.Framework; namespace CustomNPCFramework.Framework.Graphics { - /// - /// A class to be used to hold information regarding assets such as the name of the assets and the paths to the images. - /// + /// A class to be used to hold information regarding assets such as the name of the assets and the paths to the images. public class AssetInfo { - /// - /// The name of the asset to be used in the main asset pool. - /// + /// The name of the asset to be used in the main asset pool. public string assetName; - /// - /// The list of files to be used for the standing animation. - /// + + /// The list of files to be used for the standing animation. public NamePairings standingAssetPaths; - /// - /// The list of files to be used for the swimming animation. - /// + + /// The list of files to be used for the swimming animation. public NamePairings swimmingAssetPaths; - /// - /// The list of files to be used with the moving animation. - /// + + /// The list of files to be used with the moving animation. public NamePairings movingAssetPaths; - /// - /// The list of files to be used with the sitting animation. - /// + + /// The list of files to be used with the sitting animation. public NamePairings sittingAssetPaths; - /// - /// The size of the asset texture. Width and height. - /// + + /// The size of the asset texture. Width and height. public Vector2 assetSize; - /// - /// Not really used anymore. More of a legacy feature. - /// + + /// Not really used anymore. More of a legacy feature. public bool randomizeUponLoad; - - /// - /// Empty constructor. - /// - public AssetInfo() - { - } + /// Construct an instance. + public AssetInfo() { } - /// - /// Constructor that assigns values to the class. - /// + /// Construct an instance. /// The name of the asset. This is the name that will be referenced in any asset manager or asset pool. - /// The name of the files to be used for the standing animation. - /// The name of the files to be used for the moving animation. - /// The name of the files to be used for the swimming animation. - /// The name of the files to be used for the sitting animation. + /// The name of the files to be used for the standing animation. + /// The name of the files to be used for the moving animation. + /// The name of the files to be used for the swimming animation. + /// The name of the files to be used for the sitting animation. /// The size of the asset. Width and height of the texture. /// Legacy, not really used anymore. - public AssetInfo(string assetName,NamePairings StandingAssetPaths, NamePairings MovingAssetPaths, NamePairings SwimmingAssetPaths, NamePairings SittingAssetPaths, Vector2 assetSize, bool randomizeUponLoad) + public AssetInfo(string assetName, NamePairings standingAssetPaths, NamePairings movingAssetPaths, NamePairings swimmingAssetPaths, NamePairings sittingAssetPaths, Vector2 assetSize, bool randomizeUponLoad) { this.assetName = assetName; - this.sittingAssetPaths = SittingAssetPaths; - this.standingAssetPaths = StandingAssetPaths; - this.movingAssetPaths = MovingAssetPaths; - this.swimmingAssetPaths = SwimmingAssetPaths; + this.sittingAssetPaths = sittingAssetPaths; + this.standingAssetPaths = standingAssetPaths; + this.movingAssetPaths = movingAssetPaths; + this.swimmingAssetPaths = swimmingAssetPaths; this.assetSize = assetSize; this.randomizeUponLoad = randomizeUponLoad; } - /// - /// Save the json to a certain location. - /// - /// + /// Save the json to a certain location. + /// The absolute path to save. public void writeToJson(string path) { Class1.ModHelper.WriteJsonFile(path, this); } - /// - /// Read the json from a certain location. - /// - /// - /// + /// Read the json from a certain location. + /// The absolute path to save. public static AssetInfo readFromJson(string path) { - return Class1.ModHelper.ReadJsonFile(path); + return Class1.ModHelper.ReadJsonFile(path); } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetManager.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetManager.cs index 1cd90755..ef6fc18f 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetManager.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetManager.cs @@ -1,286 +1,229 @@ -using CustomNPCFramework.Framework.Enums; using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using CustomNPCFramework.Framework.Enums; namespace CustomNPCFramework.Framework.Graphics { - /// - /// Used to hold assets from specified directories. - /// + /// Used to hold assets from specified directories. public class AssetManager { - /// - /// A list of all of the assets held by this asset manager. - /// + /// A list of all of the assets held by this asset manager. public List assets; - /// - /// A list of all of the directories managed by this asset manager. - /// - public Dictionary paths; - /// - /// Basic constructor. - /// + /// A list of all of the directories managed by this asset manager. + public Dictionary paths; + + /// Construct an instance. public AssetManager() { this.assets = new List(); this.paths = new Dictionary(); } - /// - /// Constructor. - /// + /// Construct an instance. /// A list of all directories to be managed by the asset manager. Name, path is the key pair value. - public AssetManager(Dictionary assetsPathsToLoadFrom) + public AssetManager(Dictionary assetsPathsToLoadFrom) { this.assets = new List(); this.paths = assetsPathsToLoadFrom; } - /// - /// Default loading function from hard coded paths. - /// + /// Default loading function from hardcoded paths. public void loadAssets() { - foreach(var path in this.paths) - { - ProcessDirectory(path.Value); - } + foreach (var path in this.paths) + this.ProcessDirectory(path.Value); } - /// - /// Taken from Microsoft c# documented webpages. - /// Process all .json files in the given directory. If there are more nested directories, keep digging to find more .json files. Also allows us to specify a broader directory like Content/Grahphics/ModularNPC/Hair to have multiple hair styles. - /// - /// + /// Process all .json files in the given directory. If there are more nested directories, keep digging to find more .json files. Also allows us to specify a broader directory like Content/Grahphics/ModularNPC/Hair to have multiple hair styles. + /// The absolute directory path to process. + /// Taken from Microsoft c# documented webpages. private void ProcessDirectory(string targetDirectory) { // Process the list of files found in the directory. string[] files = Directory.GetFiles(targetDirectory, "*.json"); - foreach (var file in files) - { - ProcessFile(file,targetDirectory); - } + foreach (string file in files) + this.ProcessFile(file, targetDirectory); + // Recurse into subdirectories of this directory. string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory); foreach (string subdirectory in subdirectoryEntries) - ProcessDirectory(subdirectory); + this.ProcessDirectory(subdirectory); } - /// - /// Actually load in the asset information. - /// - /// - /// - private void ProcessFile(string file,string path) + /// Actually load in the asset information. + /// The absolute file path to process. + /// The absolute directory path containing the file. + private void ProcessFile(string file, string path) { try { ExtendedAssetInfo info = ExtendedAssetInfo.readFromJson(file); AssetSheet sheet = new AssetSheet(info, path); - addAsset(sheet); + this.addAsset(sheet); Class1.ModMonitor.Log("Loaded in new modular asset: " + info.assetName + " asset type: " + info.type); } - catch (Exception err) + catch { AssetInfo info = AssetInfo.readFromJson(file); AssetSheet sheet = new AssetSheet(info, path); - addAsset(sheet); + this.addAsset(sheet); } } - /// - /// Add an asset to be handled from the asset manager. - /// - /// + /// Add an asset to be handled from the asset manager. + /// The asset sheet. public void addAsset(AssetSheet asset) { this.assets.Add(asset); } - /// - /// Get an individual asset by its name. - /// - /// - /// + /// Get an individual asset by its name. + /// The asset name. public AssetSheet getAssetByName(string s) { - foreach(var v in assets) + foreach (var v in this.assets) { - if (v.assetInfo.assetName == s) return v; + if (v.assetInfo.assetName == s) + return v; } return null; } - - /// - /// Add a new path to the asset manager and create the directory for it. - /// - /// - public void addPathCreateDirectory(KeyValuePair path) + + /// Add a new path to the asset manager and create the directory for it. + /// The absolute path to add. + public void addPathCreateDirectory(KeyValuePair path) { this.addPath(path); string dir = Path.Combine(Class1.ModHelper.DirectoryPath, path.Value); if (!Directory.Exists(dir)) - { Directory.CreateDirectory(Path.Combine(Class1.ModHelper.DirectoryPath, path.Value)); - } } - /// - /// Add a path to the dictionary. - /// - /// - private void addPath(KeyValuePair path) + /// Add a path to the dictionary. + /// The absolute path to add. + private void addPath(KeyValuePair path) { this.paths.Add(path.Key, path.Value); } - /// - /// Create appropriate directories for the path. - /// + /// Create appropriate directories for the path. private void createDirectoriesFromPaths() { - foreach(var v in paths) - { - Directory.CreateDirectory(Path.Combine(Class1.ModHelper.DirectoryPath,v.Value)); - } + foreach (var v in this.paths) + Directory.CreateDirectory(Path.Combine(Class1.ModHelper.DirectoryPath, v.Value)); } - /// - /// Returns a list of assets from this manager that match the given critera. - /// - /// The criteria we are searching for this time is gender. - /// + /// Get a list of assets which match the given critera. + /// The gender to match. public List getListOfAssetsThatMatchThisCriteria(Genders gender) { - List aSheet = new List(); - foreach(var v in this.assets) + List sheets = new List(); + foreach (var v in this.assets) { - if(v.assetInfo is ExtendedAssetInfo) + if (v.assetInfo is ExtendedAssetInfo info) { - if ((v.assetInfo as ExtendedAssetInfo).gender == gender) aSheet.Add(v); + if (info.gender == gender) + sheets.Add(v); } } - return aSheet; + return sheets; } - /// - /// Get a list of all the assets of this kind of part. - /// - /// The type of part to return a list of from this asset manager. - /// + /// Get a list of assets which match the given critera. + /// The part type to match. public List getListOfAssetsThatMatchThisCriteria(PartType type) { - List aSheet = new List(); + List sheets = new List(); foreach (var v in this.assets) { - if (v.assetInfo is ExtendedAssetInfo) + if (v.assetInfo is ExtendedAssetInfo info) { - if ((v.assetInfo as ExtendedAssetInfo).type == type) aSheet.Add(v); + if (info.type == type) + sheets.Add(v); } } - return aSheet; + return sheets; } - /// - /// Get a list of assets that match the critera. - /// - /// The gender criteria for this asset, such as if this part belongs to either a female or male character. - /// The type of asset to return. Hair eyes, shoes, etc. - /// - public List getListOfAssetsThatMatchThisCriteria(Genders gender,PartType type) + /// Get a list of assets which match the given critera. + /// The gender to match. + /// The part type to match. + public List getListOfAssetsThatMatchThisCriteria(Genders gender, PartType type) { - List aSheet = new List(); + List sheets = new List(); foreach (var v in this.assets) { - if (v.assetInfo is ExtendedAssetInfo) + if (v.assetInfo is ExtendedAssetInfo info) { - if ((v.assetInfo as ExtendedAssetInfo).type == type && (v.assetInfo as ExtendedAssetInfo).gender == gender) aSheet.Add(v); + if (info.type == type && info.gender == gender) + sheets.Add(v); } } - return aSheet; + return sheets; } - /// - /// Returns a list of assets from this manager that match the given critera. - /// - /// The criteria we are searching for this time is gender. - /// + /// Get a list of assets which match the given critera. + /// The season to match. public List getListOfAssetsThatMatchThisCriteria(Seasons season) { - List aSheet = new List(); + List sheets = new List(); foreach (var v in this.assets) { - if (v.assetInfo is ExtendedAssetInfo) + if (v.assetInfo is ExtendedAssetInfo info) { - foreach (var sea in (v.assetInfo as ExtendedAssetInfo).seasons) { - if (sea == season) aSheet.Add(v); - break; //Only need to find first validation that this is a valid asset. - } - } - } - return aSheet; - } - - /// - /// Get a list of assets that match this criteria of gender and seasons. - /// - /// - /// - /// - public List getListOfAssetsThatMatchThisCriteria(Genders gender,Seasons season) - { - List aSheet = new List(); - foreach (var v in this.assets) - { - if (v.assetInfo is ExtendedAssetInfo) - { - foreach (var sea in (v.assetInfo as ExtendedAssetInfo).seasons) + foreach (var sea in info.seasons) { - if (sea == season && (v.assetInfo as ExtendedAssetInfo).gender==gender) aSheet.Add(v); + if (sea == season) + sheets.Add(v); break; //Only need to find first validation that this is a valid asset. } } } - return aSheet; + return sheets; } - /// - /// Get a list of asssets that match certain critera. - /// - /// The gengder certain assets belong to, such as male or female. - /// The season that an asset can be displayed in. Good for seasonal assets. - /// The type of part to return a list of such as hair, eyes, or pants. - /// + /// Get a list of assets which match the given critera. + /// The gender to match. + /// The season to match. + public List getListOfAssetsThatMatchThisCriteria(Genders gender, Seasons season) + { + List sheets = new List(); + foreach (var v in this.assets) + { + if (v.assetInfo is ExtendedAssetInfo info) + { + foreach (var sea in info.seasons) + { + if (sea == season && info.gender == gender) + sheets.Add(v); + break; //Only need to find first validation that this is a valid asset. + } + } + } + return sheets; + } + + /// Get a list of assets which match the given critera. + /// The gender to match. + /// The season to match. + /// The part type to match. public List getListOfAssetsThatMatchThisCriteria(Genders gender, Seasons season, PartType type) { - List aSheet = new List(); + List sheets = new List(); foreach (var v in this.assets) { - if (v.assetInfo is ExtendedAssetInfo) + if (v.assetInfo is ExtendedAssetInfo info) { - foreach (var sea in (v.assetInfo as ExtendedAssetInfo).seasons) + foreach (var sea in info.seasons) { - //Class1.ModMonitor.Log("Searching: seasons"); - if (sea == season && (v.assetInfo as ExtendedAssetInfo).gender == gender && (v.assetInfo as ExtendedAssetInfo).type == type) - { - aSheet.Add(v); - } - else - { - //Class1.ModMonitor.Log("Not what I was looking for."); - } + if (sea == season && info.gender == gender && info.type == type) + sheets.Add(v); } } } - //Class1.ModMonitor.Log("ok it's over: "+aSheet.Count.ToString()); - return aSheet; + return sheets; } - - } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetPool.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetPool.cs index 5b1f593d..caf97e00 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetPool.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetPool.cs @@ -1,32 +1,26 @@ - -using CustomNPCFramework.Framework.Enums; -using CustomNPCFramework.Framework.ModularNPCS; -using CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases; -using CustomNPCFramework.Framework.ModularNPCS.ColorCollections; -using CustomNPCFramework.Framework.ModularNPCS.ModularRenderers; -using CustomNPCFramework.Framework.NPCS; -using Microsoft.Xna.Framework; -using StardewValley; using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using CustomNPCFramework.Framework.Enums; +using CustomNPCFramework.Framework.ModularNpcs; +using CustomNPCFramework.Framework.ModularNpcs.CharacterAnimationBases; +using CustomNPCFramework.Framework.ModularNpcs.ColorCollections; +using CustomNPCFramework.Framework.ModularNpcs.ModularRenderers; +using CustomNPCFramework.Framework.NPCS; +using StardewValley; namespace CustomNPCFramework.Framework.Graphics { - - /// - /// Used to hold a collection of strings. - /// + /// Used to hold a collection of strings. public class NamePairings { public string leftString; public string rightString; public string upString; public string downString; - public NamePairings(string LeftString,string RightString, string UpString, string DownString) + + public NamePairings(string LeftString, string RightString, string UpString, string DownString) { this.leftString = LeftString; this.rightString = RightString; @@ -35,37 +29,26 @@ namespace CustomNPCFramework.Framework.Graphics } } - /// - /// Used to contain all of the asset managers. - /// + /// Used to contain all of the asset managers. public class AssetPool { - - /// - /// A dictionary holding all of the asset managers. (Name, AssetManager) - /// + /// A dictionary holding all of the asset managers. (Name, AssetManager) public Dictionary assetPool; - /// - /// Constructor. - /// + /// Construct an instance. public AssetPool() { this.assetPool = new Dictionary(); } - /// - /// Adds an asset manager to the asset pool. - /// + /// Adds an asset manager to the asset pool. /// A key value pair with the convention being (Manager Name, Asset Manager) public void addAssetManager(KeyValuePair pair) { this.assetPool.Add(pair.Key, pair.Value); } - /// - /// Adds an asset manager to the asset pool. - /// + /// Adds an asset manager to the asset pool. /// The name of the asset manager to be added. /// The asset manager object to be added to the asset pool. public void addAssetManager(string assetManagerName, AssetManager assetManager) @@ -73,99 +56,74 @@ namespace CustomNPCFramework.Framework.Graphics this.assetPool.Add(assetManagerName, assetManager); } - /// - /// Get an asset manager from the asset pool from a name. - /// + /// Get an asset manager from the asset pool from a name. /// The name of the asset manager to return. - /// public AssetManager getAssetManager(string name) { - assetPool.TryGetValue(name, out AssetManager asset); + this.assetPool.TryGetValue(name, out AssetManager asset); return asset; } - /// - /// Remove an asset manager from the asset pool. - /// + /// Remove an asset manager from the asset pool. /// The name of the asset manager to remove. public void removeAssetManager(string key) { - assetPool.Remove(key); + this.assetPool.Remove(key); } - /// - /// Go through all of the asset managers and load assets according to their respective paths. - /// + /// Go through all of the asset managers and load assets according to their respective paths. public void loadAllAssets() { foreach (KeyValuePair assetManager in this.assetPool) - { assetManager.Value.loadAssets(); - } } - /// - /// Creates an extended animated sprite object given the asset name in the asset manager. - /// - /// - /// + /// Creates an extended animated sprite object given the asset name in the asset manager. + /// The asset name. public AnimatedSpriteExtended getAnimatedSpriteFromAsset(string name) { - assetPool.TryGetValue(name, out AssetManager asset); + this.assetPool.TryGetValue(name, out AssetManager asset); var assetSheet = asset.getAssetByName(name); - return new AnimatedSpriteExtended(assetSheet.path.Clone().ToString(),assetSheet.index, (int)assetSheet.assetInfo.assetSize.X, (int)assetSheet.assetInfo.assetSize.Y); + return new AnimatedSpriteExtended(assetSheet.path.Clone().ToString(), assetSheet.index, (int)assetSheet.assetInfo.assetSize.X, (int)assetSheet.assetInfo.assetSize.Y); } - - /// - /// Generates a new AnimatedSpriteCollection object from the data held in an asset sheet. - /// + /// Generates a new AnimatedSpriteCollection object from the data held in an asset sheet. /// An asset sheet that holds the data for textures. /// The type of asset to get from the sheet. Hair, eyes, shoes, etc. - /// public AnimatedSpriteCollection getSpriteCollectionFromSheet(AssetSheet assetSheet, AnimationType type) - { - var left = new AnimatedSpriteExtended(assetSheet.clone().getTexture(Direction.left, type),assetSheet); - var right = new AnimatedSpriteExtended(assetSheet.clone().getTexture(Direction.right, type), assetSheet); - var up = new AnimatedSpriteExtended(assetSheet.clone().getTexture(Direction.up, type), assetSheet); - var down = new AnimatedSpriteExtended(assetSheet.clone().getTexture(Direction.down, type), assetSheet); - return new AnimatedSpriteCollection(left, right, up, down, Direction.down); + { + var left = new AnimatedSpriteExtended(assetSheet.clone().getTexture(Direction.left, type), assetSheet); + var right = new AnimatedSpriteExtended(assetSheet.clone().getTexture(Direction.right, type), assetSheet); + var up = new AnimatedSpriteExtended(assetSheet.clone().getTexture(Direction.up, type), assetSheet); + var down = new AnimatedSpriteExtended(assetSheet.clone().getTexture(Direction.down, type), assetSheet); + return new AnimatedSpriteCollection(left, right, up, down, Direction.down); } - - /// - /// Gets an animated sprite collection (ie a hair style facing all four directions) from a list of asset names. - /// + /// Gets an animated sprite collection (ie a hair style facing all four directions) from a list of asset names. /// The name of the asset for the left facing sprite. /// The name of the asset for the right facing sprite. /// The name of the asset for the up facing sprite. /// The name of the asset for the down facing sprite. - /// - /// + /// The sprite's starting direction. public AnimatedSpriteCollection getAnimatedSpriteCollectionFromAssets(string left, string right, string up, string down, Direction startingDirection = Direction.down) { - var Left = getAnimatedSpriteFromAsset(left); - var Right = getAnimatedSpriteFromAsset(right); - var Up = getAnimatedSpriteFromAsset(up); - var Down = getAnimatedSpriteFromAsset(down); - return new AnimatedSpriteCollection(Left, Right, Up, Down, startingDirection); + var leftSprite = this.getAnimatedSpriteFromAsset(left); + var rightSprite = this.getAnimatedSpriteFromAsset(right); + var upSprite = this.getAnimatedSpriteFromAsset(up); + var downSprite = this.getAnimatedSpriteFromAsset(down); + return new AnimatedSpriteCollection(leftSprite, rightSprite, upSprite, downSprite, startingDirection); } - /// - /// Get an AnimatedSpriteCollection from a name pairing. - /// + /// Get an AnimatedSpriteCollection from a name pairing. /// A collection of strings that hold information on directional textures. /// The direction in which the sprite should face. - /// public AnimatedSpriteCollection getAnimatedSpriteCollectionFromAssets(NamePairings pair, Direction startingDirection = Direction.down) { - return getAnimatedSpriteCollectionFromAssets(pair.leftString, pair.rightString, pair.upString, pair.downString); + return this.getAnimatedSpriteCollectionFromAssets(pair.leftString, pair.rightString, pair.upString, pair.downString); } - /// - /// Get a collection of sprites to generate a collective animated sprite. - /// + /// Get a collection of sprites to generate a collective animated sprite. /// The collection of sprites to be used for the boyd of the npc. /// The collection of sprites to be used for the eye of the npc. /// The collection of sprites to be used for the hair of the npc. @@ -174,48 +132,44 @@ namespace CustomNPCFramework.Framework.Graphics /// The collection of sprites to be used for the shoes of the npc. /// The collection of sprites to be used for the accessories of the npc. /// The collection of collors to be used for chaing the color of an individual asset. - /// - public StandardCharacterAnimation GetStandardCharacterAnimation(NamePairings BodySprites, NamePairings EyeSprites, NamePairings HairSprites, NamePairings ShirtsSprites, NamePairings PantsSprites, NamePairings ShoesSprites,List AccessoriesSprites,StandardColorCollection DrawColors=null) + public StandardCharacterAnimation GetStandardCharacterAnimation(NamePairings BodySprites, NamePairings EyeSprites, NamePairings HairSprites, NamePairings ShirtsSprites, NamePairings PantsSprites, NamePairings ShoesSprites, List AccessoriesSprites, StandardColorCollection DrawColors = null) { - var body = getAnimatedSpriteCollectionFromAssets(BodySprites); - var eyes = getAnimatedSpriteCollectionFromAssets(EyeSprites); - var hair = getAnimatedSpriteCollectionFromAssets(HairSprites); - var shirts = getAnimatedSpriteCollectionFromAssets(ShirtsSprites); - var pants = getAnimatedSpriteCollectionFromAssets(PantsSprites); - var shoes = getAnimatedSpriteCollectionFromAssets(ShoesSprites); + var body = this.getAnimatedSpriteCollectionFromAssets(BodySprites); + var eyes = this.getAnimatedSpriteCollectionFromAssets(EyeSprites); + var hair = this.getAnimatedSpriteCollectionFromAssets(HairSprites); + var shirts = this.getAnimatedSpriteCollectionFromAssets(ShirtsSprites); + var pants = this.getAnimatedSpriteCollectionFromAssets(PantsSprites); + var shoes = this.getAnimatedSpriteCollectionFromAssets(ShoesSprites); + List accessories = new List(); - foreach(var v in AccessoriesSprites) - { - accessories.Add(getAnimatedSpriteCollectionFromAssets(v)); - } - if (DrawColors == null) DrawColors = new StandardColorCollection(); - return new StandardCharacterAnimation(body,eyes,hair,shirts,pants,shoes,accessories,DrawColors); + foreach (var v in AccessoriesSprites) + accessories.Add(this.getAnimatedSpriteCollectionFromAssets(v)); + + if (DrawColors == null) + DrawColors = new StandardColorCollection(); + + return new StandardCharacterAnimation(body, eyes, hair, shirts, pants, shoes, accessories, DrawColors); } - /// - /// Get a list of parts that can apply for this criteria. - /// + /// Get a list of parts that can apply for this criteria. /// The name of the asset manager. /// The gender critera. /// The season critera. /// The part type critera. - /// - public List getListOfApplicableBodyParts(string assetManagerName,Genders gender, Seasons season, PartType type) + public List getListOfApplicableBodyParts(string assetManagerName, Genders gender, Seasons season, PartType type) { var parts = this.getAssetManager(assetManagerName).getListOfAssetsThatMatchThisCriteria(gender, season, type); return parts; } - - /// - /// Generate a basic npc based off of all all of the NPC data here. - /// - /// - /// - /// - public ExtendedNPC generateNPC(Genders gender, int minNumOfAccessories, int maxNumOfAccessories ,StandardColorCollection DrawColors=null) + /// Generate a basic NPC based on the NPC data here. + /// The NPC gender. + /// The minimum number of accessories to generate. + /// The maximum number of accessories to generate. + /// The colors for the NPC's different assets. + public ExtendedNpc generateNPC(Genders gender, int minNumOfAccessories, int maxNumOfAccessories, StandardColorCollection drawColors = null) { - Seasons myseason=Seasons.spring; + Seasons myseason = Seasons.spring; if (Game1.currentSeason == "spring") myseason = Seasons.spring; if (Game1.currentSeason == "summer") myseason = Seasons.summer; @@ -233,95 +187,87 @@ namespace CustomNPCFramework.Framework.Graphics //Get all applicable parts from this current asset manager foreach (var assetManager in this.assetPool) { - var body = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.body); + var body = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.body); foreach (var piece in body) bodyList.Add(piece); - var eyes = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.eyes); + var eyes = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.eyes); foreach (var piece in eyes) eyesList.Add(piece); - var hair = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.hair); + var hair = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.hair); foreach (var piece in hair) hairList.Add(piece); - var shirt = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.shirt); + var shirt = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.shirt); foreach (var piece in shirt) shirtList.Add(piece); - var pants = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.pants); + var pants = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.pants); foreach (var piece in pants) pantsList.Add(piece); - var shoes = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.shoes); + var shoes = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.shoes); foreach (var piece in shoes) shoesList.Add(piece); - var accessory = getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.accessory); + var accessory = this.getListOfApplicableBodyParts(assetManager.Key, gender, myseason, PartType.accessory); foreach (var piece in accessory) accessoryList.Add(piece); } - - Random r = new Random(System.DateTime.Now.Millisecond); - int amount = 0; - - amount = r.Next(minNumOfAccessories,maxNumOfAccessories + 1); //Necessary since r.next returns a num between min and (max-1) - int bodyIndex = 0; - int eyesIndex = 0; - int hairIndex = 0; - int shirtIndex = 0; - int pantsIndex = 0; - int shoesIndex = 0; + Random r = new Random(DateTime.Now.Millisecond); + int amount = r.Next(minNumOfAccessories, maxNumOfAccessories + 1); - if (bodyList.Count != 0) { + int bodyIndex; + int eyesIndex; + int hairIndex; + int shirtIndex; + int pantsIndex; + int shoesIndex; + + if (bodyList.Count != 0) bodyIndex = r.Next(0, bodyList.Count - 1); - } else { Class1.ModMonitor.Log("Error: Not enough body templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return null; } - if (eyesList.Count != 0) { + if (eyesList.Count != 0) eyesIndex = r.Next(0, eyesList.Count - 1); - } else { Class1.ModMonitor.Log("Error: Not enough eyes templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return null; } - if (hairList.Count != 0) { + if (hairList.Count != 0) hairIndex = r.Next(0, hairList.Count - 1); - } else { Class1.ModMonitor.Log("Error: Not enough hair templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return null; } - if (shirtList.Count != 0) { + if (shirtList.Count != 0) shirtIndex = r.Next(0, shirtList.Count - 1); - } else { Class1.ModMonitor.Log("Error: Not enough shirt templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return null; } - if (pantsList.Count != 0) { + if (pantsList.Count != 0) pantsIndex = r.Next(0, pantsList.Count - 1); - } else { Class1.ModMonitor.Log("Error: Not enough pants templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return null; } - if (shoesList.Count != 0) { + if (shoesList.Count != 0) shoesIndex = r.Next(0, shoesList.Count - 1); - - } else { Class1.ModMonitor.Log("Error: Not enough shoes templates to generate an npc. Aborting", StardewModdingAPI.LogLevel.Error); return null; } + List accIntList = new List(); if (accessoryList.Count != 0) { @@ -333,97 +279,80 @@ namespace CustomNPCFramework.Framework.Graphics } //Get a single sheet to pull from. - AssetSheet bodySheet; - AssetSheet eyesSheet; - AssetSheet hairSheet; - AssetSheet shirtSheet; - AssetSheet shoesSheet; - AssetSheet pantsSheet; - - bodySheet = bodyList.ElementAt(bodyIndex); - eyesSheet = eyesList.ElementAt(eyesIndex); - hairSheet = hairList.ElementAt(hairIndex); - shirtSheet = shirtList.ElementAt(shirtIndex); - pantsSheet = pantsList.ElementAt(pantsIndex); - shoesSheet = shoesList.ElementAt(shoesIndex); - + AssetSheet bodySheet = bodyList.ElementAt(bodyIndex); + AssetSheet eyesSheet = eyesList.ElementAt(eyesIndex); + AssetSheet hairSheet = hairList.ElementAt(hairIndex); + AssetSheet shirtSheet = shirtList.ElementAt(shirtIndex); + AssetSheet pantsSheet = pantsList.ElementAt(pantsIndex); + AssetSheet shoesSheet = shoesList.ElementAt(shoesIndex); List accessorySheet = new List(); - - foreach (var v in accIntList) - { + foreach (int v in accIntList) accessorySheet.Add(accessoryList.ElementAt(v)); - } - if (DrawColors == null) DrawColors = new StandardColorCollection(); - var render = generateBasicRenderer(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet,DrawColors); - ExtendedNPC npc = new ExtendedNPC(new Sprite(getDefaultSpriteImage(bodySheet)), render, new Microsoft.Xna.Framework.Vector2(0,0) * Game1.tileSize, 2, NPCNames.getRandomNPCName(gender)); - return npc; - } - /// - /// Creates a character renderer (a collection of textures) from a bunch of different asset sheets. - /// - /// The textures for the npc's body. - /// The textures for the npc's eyes. - /// The textures for the npc's hair. - /// The textures for the npc's shirt. - /// The textures for the npc's pants. - /// The textures for the npc's shoes. - /// The textures for the npc's accessories. - /// The colors for the npc's different assets. - /// - public virtual BasicRenderer generateBasicRenderer(AssetSheet bodySheet, AssetSheet eyesSheet, AssetSheet hairSheet, AssetSheet shirtSheet, AssetSheet pantsSheet, AssetSheet shoesSheet, List accessorySheet, StandardColorCollection DrawColors=null) - { - if (DrawColors == null) DrawColors = new StandardColorCollection(); - //Get all of the appropriate animations. - AnimationType type = AnimationType.standing; - var standingAnimation = generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, type,DrawColors); - type = AnimationType.walking; - var movingAnimation = generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, type,DrawColors); - type = AnimationType.swimming; - var swimmingAnimation = generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, type,DrawColors); + if (drawColors == null) + drawColors = new StandardColorCollection(); - BasicRenderer render = new BasicRenderer(standingAnimation, movingAnimation, swimmingAnimation); - return render; + var render = this.generateBasicRenderer(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, drawColors); + return new ExtendedNpc(new Sprite(this.getDefaultSpriteImage(bodySheet)), render, new Microsoft.Xna.Framework.Vector2(0, 0) * Game1.tileSize, 2, NpcNames.getRandomNpcName(gender)); } - /// - /// Generate a Standard Character Animation from some asset sheets. - /// (collection of textures to animations) - /// - /// The textures for the npc's body. - /// The textures for the npc's eyes. - /// The textures for the npc's hair. - /// The textures for the npc's shirt. - /// The textures for the npc's pants. - /// The textures for the npc's shoes. - /// The textures for the npc's accessories. - /// The colors for the npc's different assets. - /// - public virtual StandardCharacterAnimation generateCharacterAnimation(AssetSheet body, AssetSheet eyes, AssetSheet hair, AssetSheet shirt, AssetSheet pants, AssetSheet shoes,List accessories, AnimationType animationType, StandardColorCollection DrawColors=null) + /// Creates a character renderer (a collection of textures) from a bunch of different asset sheets. + /// The textures for the NPC's body. + /// The textures for the NPC's eyes. + /// The textures for the NPC's hair. + /// The textures for the NPC's shirt. + /// The textures for the NPC's pants. + /// The textures for the NPC's shoes. + /// The textures for the NPC's accessories. + /// The colors for the NPC's different assets. + public virtual BasicRenderer generateBasicRenderer(AssetSheet bodySheet, AssetSheet eyesSheet, AssetSheet hairSheet, AssetSheet shirtSheet, AssetSheet pantsSheet, AssetSheet shoesSheet, List accessorySheet, StandardColorCollection drawColors = null) { - var bodySprite = getSpriteCollectionFromSheet(body, animationType); - var eyesSprite = getSpriteCollectionFromSheet(eyes, animationType); - var hairSprite = getSpriteCollectionFromSheet(hair, animationType); - var shirtSprite = getSpriteCollectionFromSheet(shirt, animationType); - var pantsSprite = getSpriteCollectionFromSheet(pants, animationType); - var shoesSprite = getSpriteCollectionFromSheet(shoes, animationType); + if (drawColors == null) + drawColors = new StandardColorCollection(); + + // Get all of the appropriate animations. + StandardCharacterAnimation standingAnimation = this.generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, AnimationType.standing, drawColors); + StandardCharacterAnimation movingAnimation = this.generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, AnimationType.walking, drawColors); + StandardCharacterAnimation swimmingAnimation = this.generateCharacterAnimation(bodySheet, eyesSheet, hairSheet, shirtSheet, pantsSheet, shoesSheet, accessorySheet, AnimationType.swimming, drawColors); + + return new BasicRenderer(standingAnimation, movingAnimation, swimmingAnimation); + } + + /// Generate a Standard Character Animation from some asset sheets. (collection of textures to animations) + /// The textures for the NPC's body. + /// The textures for the NPC's eyes. + /// The textures for the NPC's hair. + /// The textures for the NPC's shirt. + /// The textures for the NPC's pants. + /// The textures for the NPC's shoes. + /// The textures for the NPC's accessories. + /// The animation type to generate. + /// The colors for the NPC's different assets. + public virtual StandardCharacterAnimation generateCharacterAnimation(AssetSheet body, AssetSheet eyes, AssetSheet hair, AssetSheet shirt, AssetSheet pants, AssetSheet shoes, List accessories, AnimationType animationType, StandardColorCollection drawColors = null) + { + AnimatedSpriteCollection bodySprite = this.getSpriteCollectionFromSheet(body, animationType); + AnimatedSpriteCollection eyesSprite = this.getSpriteCollectionFromSheet(eyes, animationType); + AnimatedSpriteCollection hairSprite = this.getSpriteCollectionFromSheet(hair, animationType); + AnimatedSpriteCollection shirtSprite = this.getSpriteCollectionFromSheet(shirt, animationType); + AnimatedSpriteCollection pantsSprite = this.getSpriteCollectionFromSheet(pants, animationType); + AnimatedSpriteCollection shoesSprite = this.getSpriteCollectionFromSheet(shoes, animationType); + List accessoryCollection = new List(); foreach (var v in accessories) { - AnimatedSpriteCollection acc = getSpriteCollectionFromSheet(v, AnimationType.standing); + AnimatedSpriteCollection acc = this.getSpriteCollectionFromSheet(v, AnimationType.standing); accessoryCollection.Add(acc); } - if (DrawColors == null) DrawColors = new StandardColorCollection(); - StandardCharacterAnimation standingAnimation = new StandardCharacterAnimation(bodySprite, eyesSprite, hairSprite, shirtSprite, pantsSprite, shoesSprite, accessoryCollection,DrawColors); - return standingAnimation; + + if (drawColors == null) + drawColors = new StandardColorCollection(); + + return new StandardCharacterAnimation(bodySprite, eyesSprite, hairSprite, shirtSprite, pantsSprite, shoesSprite, accessoryCollection, drawColors); } - /// - /// Get the string for the standard character sprite to be used from this asset sheet. - /// + /// Get the string for the standard character sprite to be used from this asset sheet. /// The standard asset sheet to be used. - /// public virtual string getDefaultSpriteImage(AssetSheet imageGraphics) { return Class1.getRelativeDirectory(Path.Combine(imageGraphics.path, imageGraphics.assetInfo.standingAssetPaths.downString)); diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetSheet.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetSheet.cs index d2b7eabc..d868de75 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetSheet.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/AssetSheet.cs @@ -1,131 +1,95 @@ -using CustomNPCFramework.Framework.Enums; +using System.Collections.Generic; +using CustomNPCFramework.Framework.Enums; using CustomNPCFramework.Framework.Graphics.TextureGroups; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; using StardustCore.UIUtilities; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CustomNPCFramework.Framework.Graphics { - /// - /// Used to handle loading different textures and handling opperations on those textures. - /// + /// Used to handle loading different textures and handling opperations on those textures. public class AssetSheet { - /// - /// Used to hold the textures for the AssetSheet. - /// - public TextureGroups.TextureGroup textures; + /// Used to hold the textures for the AssetSheet. + public TextureGroup textures; - /// - /// Used to hold the info for the paths to these textures. - /// + /// Used to hold the info for the paths to these textures. public AssetInfo assetInfo; - - /// - /// The path to this assetinfo.json file - /// + + /// The path to this assetinfo.json file public string path; - /// - /// The soruce rectangle for the current texture to draw. - /// + /// The source rectangle for the current texture to draw. public Rectangle currentAsset; public int index; - /// - /// Constructor. - /// + + /// Construct an instance. /// The asset info file to be read in or created. Holds path information. /// The path to the assetinfo file. /// The direction to set the animation. - public AssetSheet(AssetInfo info,string path,Direction direction=Direction.down) + public AssetSheet(AssetInfo info, string path, Direction direction = Direction.down) { this.assetInfo = info; - this.textures = new TextureGroup(info,path,direction); + this.textures = new TextureGroup(info, path, direction); try { this.path = Class1.getShortenedDirectory(path); } - catch(Exception err) + catch { this.path = path; } this.index = 0; } - /// - /// Get the path to the current texture. - /// - /// + + /// Get the path to the current texture. public virtual KeyValuePair getPathTexturePair() { return new KeyValuePair(this.path, this.textures.currentTexture.currentTexture); } - - /// - /// Used just to get a copy of this asset sheet. - /// + /// Used just to get a copy of this asset sheet. public virtual AssetSheet clone() { - var asset = new AssetSheet(this.assetInfo,(string)this.path.Clone()); + var asset = new AssetSheet(this.assetInfo, (string)this.path.Clone()); return asset; } - /// - /// Sets the textures for this sheet to face left. - /// + /// Sets the textures for this sheet to face left. public virtual void setLeft() { this.textures.setLeft(); } - /// - /// Sets the textures for this sheet to face up. - /// + /// Sets the textures for this sheet to face up. public virtual void setUp() { this.textures.setUp(); } - /// - /// Sets the textures for this sheet to face down. - /// + /// Sets the textures for this sheet to face down. public virtual void setDown() { this.textures.setDown(); } - /// - /// Sets the textures for this sheet to face left. - /// + /// Sets the textures for this sheet to face left. public virtual void setRight() { this.textures.setRight(); } - /// - /// Get the current animation texture. - /// - /// + /// Get the current animation texture. public virtual Texture2DExtended getCurrentSpriteTexture() { return this.textures.currentTexture.currentTexture; } - /// - /// Get the specific texture depending on the direction and animation type. - /// - /// - /// - /// - public virtual Texture2DExtended getTexture(Direction direction,AnimationType type) + /// Get the specific texture depending on the direction and animation type. + /// The facing direction. + /// The animation type. + public virtual Texture2DExtended getTexture(Direction direction, AnimationType type) { return this.textures.getTextureFromAnimation(type).getTextureFromDirection(direction); } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/DirectionalTexture.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/DirectionalTexture.cs index 4303cf5a..d87d532e 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/DirectionalTexture.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/DirectionalTexture.cs @@ -1,134 +1,138 @@ -using CustomNPCFramework.Framework.Enums; -using Microsoft.Xna.Framework.Graphics; +using System.IO; +using CustomNPCFramework.Framework.Enums; using StardewModdingAPI; using StardustCore.UIUtilities; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CustomNPCFramework.Framework.Graphics { - /// - /// A class that's used to hold textures for different directions. - /// + /// A class that's used to hold textures for different directions. public class DirectionalTexture { - /// - /// The left texture for this group. - /// + /// The left texture for this group. public Texture2DExtended leftTexture; - /// - /// The right texture for this group. - /// + + /// The right texture for this group. public Texture2DExtended rightTexture; - - /// - /// The down textiure for this group. - /// + + /// The down textiure for this group. public Texture2DExtended downTexture; - /// - /// The up texture for this group. - /// + + /// The up texture for this group. public Texture2DExtended upTexture; - /// - /// The current texture for this group. - /// + /// The current texture for this group. public Texture2DExtended currentTexture; - /// - /// Constructor. - /// + /// Construct an instance. /// The left texture to use. /// The right texture to use. /// The up texture to use. /// The down texture to use. /// The direction texture for the sprite to face. - public DirectionalTexture(Texture2DExtended left, Texture2DExtended right, Texture2DExtended up, Texture2DExtended down, Direction direction=Direction.down) + public DirectionalTexture(Texture2DExtended left, Texture2DExtended right, Texture2DExtended up, Texture2DExtended down, Direction direction = Direction.down) { this.leftTexture = left; this.rightTexture = right; this.upTexture = up; this.downTexture = down; - if (direction == Direction.left) this.currentTexture = leftTexture; - if (direction == Direction.right) this.currentTexture = rightTexture; - if (direction == Direction.up) this.currentTexture = upTexture; - if (direction == Direction.down) this.currentTexture = downTexture; + switch (direction) + { + case Direction.left: + this.currentTexture = this.leftTexture; + break; + case Direction.right: + this.currentTexture = this.rightTexture; + break; + case Direction.up: + this.currentTexture = this.upTexture; + break; + + case Direction.down: + this.currentTexture = this.downTexture; + break; + } } - - public DirectionalTexture(IModHelper helper ,NamePairings info, string path, Direction direction = Direction.down) + public DirectionalTexture(IModHelper helper, NamePairings info, string path, Direction direction = Direction.down) { - - new Texture2DExtended(helper, Class1.Manifest, path); - - string leftString= Class1.getShortenedDirectory(Path.Combine(path, info.leftString + ".png")).Remove(0, 1); + string leftString = Class1.getShortenedDirectory(Path.Combine(path, info.leftString + ".png")).Remove(0, 1); string rightString = Class1.getShortenedDirectory(Path.Combine(path, info.rightString + ".png")).Remove(0, 1); string upString = Class1.getShortenedDirectory(Path.Combine(path, info.upString + ".png")).Remove(0, 1); string downString = Class1.getShortenedDirectory(Path.Combine(path, info.downString + ".png")).Remove(0, 1); - this.leftTexture = new Texture2DExtended(helper, Class1.Manifest, leftString); this.rightTexture = new Texture2DExtended(helper, Class1.Manifest, rightString); this.upTexture = new Texture2DExtended(helper, Class1.Manifest, upString); this.downTexture = new Texture2DExtended(helper, Class1.Manifest, downString); - if (direction == Direction.left) this.currentTexture = leftTexture; - if (direction == Direction.right) this.currentTexture = rightTexture; - if (direction == Direction.up) this.currentTexture = upTexture; - if (direction == Direction.down) this.currentTexture = downTexture; + switch (direction) + { + case Direction.left: + this.currentTexture = this.leftTexture; + break; + + case Direction.right: + this.currentTexture = this.rightTexture; + break; + + case Direction.up: + this.currentTexture = this.upTexture; + break; + + case Direction.down: + this.currentTexture = this.downTexture; + break; + } } - /// - /// Sets the direction of this current texture to left. - /// + /// Sets the direction of this current texture to left. public void setLeft() { - this.currentTexture = leftTexture; + this.currentTexture = this.leftTexture; } - /// - /// Sets the direction of this current texture to up. - /// + /// Sets the direction of this current texture to up. public void setUp() { - this.currentTexture = upTexture; + this.currentTexture = this.upTexture; } - /// - /// Sets the direction of this current texture to down. - /// + /// Sets the direction of this current texture to down. public void setDown() { - this.currentTexture = downTexture; + this.currentTexture = this.downTexture; } - /// - /// Sets the direction of this current texture to right. - /// + /// Sets the direction of this current texture to right. public void setRight() { - this.currentTexture = rightTexture; + this.currentTexture = this.rightTexture; } - /// - /// Gets the texture from this texture group depending on the direction. - /// - /// - /// + /// Gets the texture from this texture group depending on the direction. + /// The facing direction. public virtual Texture2DExtended getTextureFromDirection(Direction direction) { - if (direction == Direction.left) return this.leftTexture; - if (direction == Direction.right) return this.rightTexture; - if (direction == Direction.up) return this.upTexture; - if (direction == Direction.down) return this.downTexture; - return null; + switch (direction) + { + case Direction.left: + return this.leftTexture; + + case Direction.right: + return this.rightTexture; + + case Direction.up: + return this.upTexture; + + case Direction.down: + return this.downTexture; + + default: + return null; + } } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/ExtendedAssetInfo.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/ExtendedAssetInfo.cs index 0590fee3..41745722 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/ExtendedAssetInfo.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/ExtendedAssetInfo.cs @@ -1,73 +1,55 @@ -using CustomNPCFramework.Framework.Enums; -using Microsoft.Xna.Framework; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using CustomNPCFramework.Framework.Enums; +using Microsoft.Xna.Framework; namespace CustomNPCFramework.Framework.Graphics { - /// - /// An expanded Asset info class that deals with seasons and genders. - /// - public class ExtendedAssetInfo :AssetInfo + /// An expanded Asset info class that deals with seasons and genders. + public class ExtendedAssetInfo : AssetInfo { - /// - /// The genders this part is associated with. 0=Male, 1=female, 2=other. - /// + /// The genders this part is associated with. public Genders gender; - /// - /// A list of seasons where this part can be displayed - /// - public List seasons=new List(); - /// - /// The part type to be used for this asset such as hair, eyes, etc. - /// + + /// A list of seasons where this part can be displayed. + public List seasons = new List(); + + /// The part type to be used for this asset such as hair, eyes, etc. public PartType type; - - /// - /// Constructor. - /// - public ExtendedAssetInfo() + + /// Construct an instance. + public ExtendedAssetInfo() { } + + /// Construct an instance. + /// The name of the asset. This is the name that will be referenced in any asset manager or asset pool. + /// The name of the files to be used for the standing animation. + /// The name of the files to be used for the moving animation. + /// The name of the files to be used for the swimming animation. + /// The name of the files to be used for the sitting animation. + /// The size of the asset. Width and height of the texture. + /// Legacy, not really used anymore. + /// The type of gender this asset will be associated with. + /// The type of season this asset will be associated with. + /// The part type to be used for this asset such as hair, eyes, etc. + public ExtendedAssetInfo(string name, NamePairings standingAssetPaths, NamePairings movingAssetPaths, NamePairings swimmingAssetPaths, NamePairings sittingAssetPaths, Vector2 assetSize, bool randomizeOnLoad, Genders gender, List season, PartType type) + : base(name, standingAssetPaths, movingAssetPaths, swimmingAssetPaths, sittingAssetPaths, assetSize, randomizeOnLoad) { - this.seasons = new List(); - } - - /// - /// Constructor. - /// - /// - /// - /// - /// The type of gender this asset will be associated with. - /// The type of season this asset will be associated with. - public ExtendedAssetInfo(string name, NamePairings StandingAssetPaths, NamePairings MovingAssetPaths, NamePairings SwimmingAssetPaths, NamePairings SittingAssetPaths, Vector2 assetSize, bool randomizeOnLoad, Genders Gender, List Season, PartType Type): base(name,StandingAssetPaths,MovingAssetPaths,SwimmingAssetPaths,SittingAssetPaths, assetSize, randomizeOnLoad) - { - this.gender = Gender; - this.seasons = Season; - if (this.seasons == null) this.seasons = new List(); - this.type = Type; + this.gender = gender; + this.seasons = season ?? new List(); + this.type = type; } - /// - /// Save the json to a certain location. - /// - /// + /// Save the json to a certain location. + /// The absolute path to write. public new void writeToJson(string path) { Class1.ModHelper.WriteJsonFile(path, this); } - /// - /// Read the json from a certain location. - /// - /// - /// + /// Read the json from a certain location. + /// The absolute path to read. public new static ExtendedAssetInfo readFromJson(string path) { return Class1.ModHelper.ReadJsonFile(path); } - } } diff --git a/GeneralMods/CustomNPCFramework/Framework/Graphics/TextureGroups/TextureGroup.cs b/GeneralMods/CustomNPCFramework/Framework/Graphics/TextureGroups/TextureGroup.cs index 7b9f67d6..c5e9bd47 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Graphics/TextureGroups/TextureGroup.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Graphics/TextureGroups/TextureGroup.cs @@ -1,96 +1,67 @@ -using CustomNPCFramework.Framework.Enums; -using Microsoft.Xna.Framework.Graphics; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using CustomNPCFramework.Framework.Enums; namespace CustomNPCFramework.Framework.Graphics.TextureGroups { - /// - /// A group of a textures used to hold all of the textures associated with a single asset such as a hair style or a shirt. - /// + /// A group of a textures used to hold all of the textures associated with a single asset such as a hair style or a shirt. public class TextureGroup { - /// - /// The directional (Left, Right, Up, Down) textures to be used when the NPC is standing. - /// + /// The directional (Left, Right, Up, Down) textures to be used when the NPC is standing. public DirectionalTexture standingTexture; - /// - /// The directional (Left, Right, Up, Down) textures to be used when the NPC is sitting. - /// + + /// The directional (Left, Right, Up, Down) textures to be used when the NPC is sitting. public DirectionalTexture sittingTexture; - /// - /// The directional (Left, Right, Up, Down) textures to be used when the NPC is swimming. - /// + + /// The directional (Left, Right, Up, Down) textures to be used when the NPC is swimming. public DirectionalTexture swimmingTexture; - /// - /// The directional (Left, Right, Up, Down) textures to be used when the NPC is moving. - /// + + /// The directional (Left, Right, Up, Down) textures to be used when the NPC is moving. public DirectionalTexture movingTexture; - /// - /// The current directional texture to be used by the npc. Can be things such as the standing, swimming, moving, or sitting texture. - /// + /// The current directional texture to be used by the npc. Can be things such as the standing, swimming, moving, or sitting texture. public DirectionalTexture currentTexture; - /// - /// Asset info loaded in from the corresponding .json file. - /// - private AssetInfo info; - /// - /// The path to the .json file. - /// - private string path; - /// - /// The current direction of the texture group. See Direction.cs - /// - private Direction dir; - /// - /// The type of asset this is. Body, hair, eyes, shirt,etc... - /// - private AnimationType type; + /// Asset info loaded in from the corresponding .json file. + private readonly AssetInfo info; - /// - /// Constructor. - /// + /// The path to the .json file. + private readonly string path; + + /// The current direction of the texture group. + private readonly Direction dir; + + /// The type of asset this is. Body, hair, eyes, shirt, etc. + private readonly AnimationType type; + + /// Construct an instance. /// The asset info file to be stored with this texture group. /// Use to locate the files on disk. /// Used to determine the current direction/animation to load /// The type of asset this is. Eyes, Hair, Shirts, etc - public TextureGroup(AssetInfo info, string path,Direction direction ,AnimationType animationType=AnimationType.standing) + public TextureGroup(AssetInfo info, string path, Direction direction, AnimationType animationType = AnimationType.standing) { - this.standingTexture = new DirectionalTexture(Class1.ModHelper,info.standingAssetPaths, path, direction); + this.standingTexture = new DirectionalTexture(Class1.ModHelper, info.standingAssetPaths, path, direction); this.sittingTexture = new DirectionalTexture(Class1.ModHelper, info.sittingAssetPaths, path, direction); this.swimmingTexture = new DirectionalTexture(Class1.ModHelper, info.swimmingAssetPaths, path, direction); - this.movingTexture = new DirectionalTexture(Class1.ModHelper,info.movingAssetPaths, path, direction); + this.movingTexture = new DirectionalTexture(Class1.ModHelper, info.movingAssetPaths, path, direction); this.info = info; this.path = path; this.dir = direction; this.type = animationType; - if (animationType == AnimationType.standing) this.currentTexture = standingTexture; - if (animationType == AnimationType.sitting) this.currentTexture = sittingTexture; - if (animationType == AnimationType.swimming) this.currentTexture = swimmingTexture; - if (animationType == AnimationType.walking) this.currentTexture = movingTexture; - + if (animationType == AnimationType.standing) this.currentTexture = this.standingTexture; + if (animationType == AnimationType.sitting) this.currentTexture = this.sittingTexture; + if (animationType == AnimationType.swimming) this.currentTexture = this.swimmingTexture; + if (animationType == AnimationType.walking) this.currentTexture = this.movingTexture; } - /// - /// Gets a clone of this texture group. - /// - /// + /// Gets a clone of this texture group. public TextureGroup clone() { return new TextureGroup(this.info, this.path, this.dir, this.type); } - - /// - /// Sets all of the different animations to use their left facing sprites. - /// + /// Sets all of the different animations to use their left facing sprites. public virtual void setLeft() { this.movingTexture.setLeft(); @@ -99,9 +70,7 @@ namespace CustomNPCFramework.Framework.Graphics.TextureGroups this.swimmingTexture.setLeft(); } - /// - /// Sets all of the different animations to use their up facing sprites. - /// + /// Sets all of the different animations to use their up facing sprites. public virtual void setUp() { this.movingTexture.setUp(); @@ -110,9 +79,7 @@ namespace CustomNPCFramework.Framework.Graphics.TextureGroups this.swimmingTexture.setUp(); } - /// - /// Sets all of the different animations to use their down facing sprites. - /// + /// Sets all of the different animations to use their down facing sprites. public virtual void setDown() { this.movingTexture.setDown(); @@ -121,9 +88,7 @@ namespace CustomNPCFramework.Framework.Graphics.TextureGroups this.swimmingTexture.setDown(); } - /// - /// Sets all of the different animations to use their right facing sprites. - /// + /// Sets all of the different animations to use their right facing sprites. public virtual void setRight() { this.movingTexture.setRight(); @@ -132,11 +97,8 @@ namespace CustomNPCFramework.Framework.Graphics.TextureGroups this.swimmingTexture.setRight(); } - /// - /// Get's the appropriate animation texture based on the type of animation key passed in. - /// - /// - /// + /// Gets the appropriate animation texture based on the type of animation key passed in. + /// The animation type. public virtual DirectionalTexture getTextureFromAnimation(AnimationType type) { if (type == AnimationType.standing) return this.standingTexture; @@ -145,6 +107,5 @@ namespace CustomNPCFramework.Framework.Graphics.TextureGroups if (type == AnimationType.sitting) return this.sittingTexture; return null; } - } } diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/AnimatedSpriteCollection.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/AnimatedSpriteCollection.cs index 33f7caef..ce1160af 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/AnimatedSpriteCollection.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/AnimatedSpriteCollection.cs @@ -1,78 +1,62 @@ -using CustomNPCFramework.Framework.Enums; +using CustomNPCFramework.Framework.Enums; using CustomNPCFramework.Framework.NPCS; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace CustomNPCFramework.Framework.ModularNPCS +namespace CustomNPCFramework.Framework.ModularNpcs { - /// - /// Used to hold all of the sprites for a single asset such as hair or bodies. - /// + /// Used to hold all of the sprites for a single asset such as hair or bodies. public class AnimatedSpriteCollection { - /// - /// The left sprite for this sprite asset part. - /// + /// The left sprite for this sprite asset part. AnimatedSpriteExtended leftSprite; - /// - /// The right sprite for this sprite asset part. - /// + + /// The right sprite for this sprite asset part. AnimatedSpriteExtended rightSprite; - /// - /// The up sprite for this sprite asset part. - /// + + /// The up sprite for this sprite asset part. AnimatedSpriteExtended upSprite; - /// - /// The down sprite for this sprite asset part. - /// + + /// The down sprite for this sprite asset part. AnimatedSpriteExtended downSprite; - /// - /// The current sprite for this sprite collection. This is one of the four directions for this collection. - /// + /// The current sprite for this sprite collection. This is one of the four directions for this collection. public AnimatedSpriteExtended currentSprite; - /// - /// Constructor. - /// + /// Construct an instance. /// Left animated sprite for this piece. /// Right animated sprite for this piece. /// Up animated sprite for this piece. /// Down animated sprite for this piece. - /// - public AnimatedSpriteCollection(AnimatedSpriteExtended LeftSprite,AnimatedSpriteExtended RightSprite,AnimatedSpriteExtended UpSprite,AnimatedSpriteExtended DownSprite,Direction startingSpriteDirection) + /// The sprite's initial facing direction. + public AnimatedSpriteCollection(AnimatedSpriteExtended LeftSprite, AnimatedSpriteExtended RightSprite, AnimatedSpriteExtended UpSprite, AnimatedSpriteExtended DownSprite, Direction startingSpriteDirection) { this.leftSprite = LeftSprite; this.rightSprite = RightSprite; this.upSprite = UpSprite; this.downSprite = DownSprite; - if (startingSpriteDirection == Direction.down) + switch (startingSpriteDirection) { - setDown(); - } - if (startingSpriteDirection == Direction.left) - { - setLeft(); - } - if (startingSpriteDirection == Direction.right) - { - setRight(); - } - if (startingSpriteDirection == Direction.up) - { - setUp(); + case Direction.down: + this.setDown(); + break; + + case Direction.left: + this.setLeft(); + break; + + case Direction.right: + this.setRight(); + break; + + case Direction.up: + this.setUp(); + break; } } - /// - /// Reloads all of the directional textures for this texture collection. - /// + /// Reloads all of the directional textures for this texture collection. public virtual void reload() { this.leftSprite.reload(); @@ -81,109 +65,66 @@ namespace CustomNPCFramework.Framework.ModularNPCS this.downSprite.reload(); } - /// - /// Sets the current sprite direction to face left. - /// + /// Sets the current sprite direction to face left. public void setLeft() { - this.currentSprite = leftSprite; + this.currentSprite = this.leftSprite; } - /// - /// Sets the current sprite direction to face right. - /// + /// Sets the current sprite direction to face right. public void setRight() { - this.currentSprite = rightSprite; + this.currentSprite = this.rightSprite; } - /// - /// Sets the current sprite direction to face down. - /// + /// Sets the current sprite direction to face down. public void setDown() { - this.currentSprite = downSprite; + this.currentSprite = this.downSprite; } - /// - /// Sets the current sprite direction to face up. - /// + /// Sets the current sprite direction to face up. public void setUp() { - this.currentSprite = upSprite; + this.currentSprite = this.upSprite; } - /// - /// Used to draw the sprite to the screen. - /// - /// - /// - /// + /// Used to draw the sprite to the screen. public void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth) { b.Draw(this.currentSprite.sprite.Texture, screenPosition, new Rectangle?(this.currentSprite.sprite.sourceRect), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, this.currentSprite.sprite.currentAnimation == null || !this.currentSprite.sprite.currentAnimation[this.currentSprite.sprite.currentAnimationIndex].flip ? SpriteEffects.None : SpriteEffects.FlipHorizontally, layerDepth); } - /// - /// Used to draw the sprite to the screen. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// Used to draw the sprite to the screen. public void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth, int xOffset, int yOffset, Color c, bool flip = false, float scale = 1f, float rotation = 0.0f, bool characterSourceRectOffset = false) { b.Draw(this.currentSprite.sprite.Texture, screenPosition, new Rectangle?(new Rectangle(this.currentSprite.sprite.sourceRect.X + xOffset, this.currentSprite.sprite.sourceRect.Y + yOffset, this.currentSprite.sprite.sourceRect.Width, this.currentSprite.sprite.sourceRect.Height)), c, rotation, characterSourceRectOffset ? new Vector2((float)(this.currentSprite.sprite.SpriteWidth / 2), (float)((double)this.currentSprite.sprite.SpriteHeight * 3.0 / 4.0)) : Vector2.Zero, scale, flip || this.currentSprite.sprite.currentAnimation != null && this.currentSprite.sprite.currentAnimation[this.currentSprite.sprite.currentAnimationIndex].flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); } - /// - /// A very verbose asset drawer. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public void draw(SpriteBatch b, ExtendedNPC npc, Vector2 position, Rectangle sourceRectangle,Color color, float alpha,Vector2 origin,float scale,SpriteEffects effects,float layerDepth) + /// A very verbose asset drawer. + public void draw(SpriteBatch b, ExtendedNpc npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { //DEFINITELY FIX THIS PART. Something is wrong with how these two functions handle the drawing of my npc to the scene. //this.draw(b, position, layerDepth); - b.Draw(this.currentSprite.sprite.Texture,position,this.currentSprite.sprite.sourceRect, color, 0.0f, origin,scale,effects,layerDepth); + b.Draw(this.currentSprite.sprite.Texture, position, this.currentSprite.sprite.sourceRect, color, 0.0f, origin, scale, effects, layerDepth); //b.Draw(this.Sprite.Texture, npc.getLocalPosition(Game1.viewport) + new Vector2((float)(this.sprite.spriteWidth * Game1.pixelZoom / 2), (float)(this.GetBoundingBox().Height / 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(this.Sprite.SourceRect), Color.White * alpha, this.rotation, new Vector2((float)(this.sprite.spriteWidth / 2), (float)((double)this.sprite.spriteHeight * 3.0 / 4.0)), Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom, this.flip || this.sprite.currentAnimation != null && this.sprite.currentAnimation[this.sprite.currentAnimationIndex].flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.991f : (float)this.getStandingY() / 10000f)); } - - /// - /// Animate the current sprite. Theoreticlly works from index offset to how many frames - /// + /// Animate the current sprite. Theoreticlly works from index offset to how many frames /// The delay in milliseconds between frames. - public void Animate(float intervalDelay,bool loop=true) + public void Animate(float intervalDelay, bool loop = true) { - this.Animate(Game1.currentGameTime, 0,2, intervalDelay,this.currentSprite.sprite,loop); + this.Animate(Game1.currentGameTime, 0, 2, intervalDelay, this.currentSprite.sprite, loop); } - /// - /// Animate the current sprite. - /// + /// Animate the current sprite. /// The game time from Monogames/XNA /// The starting frame of the animation on the sprite sheet. /// The number of frames to animate the sprite. /// The delay between frames in milliseconds. /// The animated sprite from the npc. /// If true, the animation plays over and over again. - /// - public virtual bool Animate(GameTime gameTime, int startFrame, int numberOfFrames, float interval, AnimatedSprite sprite, bool loop=true) + public virtual bool Animate(GameTime gameTime, int startFrame, int numberOfFrames, float interval, AnimatedSprite sprite, bool loop = true) { if (sprite.CurrentFrame >= startFrame + numberOfFrames + 1 || sprite.CurrentFrame < startFrame) sprite.CurrentFrame = startFrame + sprite.CurrentFrame % numberOfFrames; @@ -204,10 +145,7 @@ namespace CustomNPCFramework.Framework.ModularNPCS return false; } - /// - /// Update the source rectangle on the sprite sheet. Needed for animation. - /// - /// + /// Update the source rectangle on the sprite sheet. Needed for animation. public virtual void UpdateSourceRect(AnimatedSprite sprite) { if (sprite.ignoreSourceRectUpdates) @@ -217,11 +155,8 @@ namespace CustomNPCFramework.Framework.ModularNPCS //sprite.SourceRect = new Rectangle(, 0, sprite.spriteWidth, sprite.spriteHeight); } - /// - /// Animate the current sprite. Theoreticlly works from index offset to how many frames - /// - /// - public void Animate(float intervalFromCharacter,int startFrame,int endFrame, bool loop) + /// Animate the current sprite. Theoreticlly works from index offset to how many frames + public void Animate(float intervalFromCharacter, int startFrame, int endFrame, bool loop) { this.currentSprite.sprite.loop = loop; this.currentSprite.sprite.Animate(Game1.currentGameTime, startFrame, endFrame, intervalFromCharacter); diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/AnimatedSpriteExtended.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/AnimatedSpriteExtended.cs index e7132923..9403c62b 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/AnimatedSpriteExtended.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/AnimatedSpriteExtended.cs @@ -1,32 +1,21 @@ -using CustomNPCFramework.Framework.Graphics; -using Microsoft.Xna.Framework.Content; +using CustomNPCFramework.Framework.Graphics; using Microsoft.Xna.Framework.Graphics; using StardewValley; using StardustCore.UIUtilities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace CustomNPCFramework.Framework.ModularNPCS +namespace CustomNPCFramework.Framework.ModularNpcs { - /// - /// Used as a wrapper for the AnimatedSprite class. - /// + /// Used as a wrapper for the AnimatedSprite class. public class AnimatedSpriteExtended { - /// - /// The actual sprite of the object. - /// + /// The actual sprite of the object. public AnimatedSprite sprite; - /// - /// The path to the texture to load the sprite from. - /// + + /// The path to the texture to load the sprite from. public string path; - - public AnimatedSpriteExtended(Texture2DExtended texture,AssetSheet assetSheet) + /// Construct an instance. + public AnimatedSpriteExtended(Texture2DExtended texture, AssetSheet assetSheet) { //Set the sprite texture this.sprite = new AnimatedSprite(); @@ -39,25 +28,17 @@ namespace CustomNPCFramework.Framework.ModularNPCS this.sprite.SpriteWidth = (int)assetSheet.assetInfo.assetSize.X; this.sprite.SpriteHeight = (int)assetSheet.assetInfo.assetSize.Y; - - } - /// - /// Constructor. - /// - /// - /// - /// - /// - public AnimatedSpriteExtended(string path ,int currentFrame, int spriteWidth, int spriteHeight) + /// Construct an instance. + public AnimatedSpriteExtended(string path, int currentFrame, int spriteWidth, int spriteHeight) { this.path = Class1.getRelativeDirectory(path); //Set the sprite texture this.sprite = new AnimatedSprite(); Texture2D load = Class1.ModHelper.Content.Load(this.path); - var thing=Class1.ModHelper.Reflection.GetField(this.sprite, "Texture", true); + var thing = Class1.ModHelper.Reflection.GetField(this.sprite, "Texture", true); thing.SetValue(load); //Set the fields. @@ -68,9 +49,7 @@ namespace CustomNPCFramework.Framework.ModularNPCS //this.sprite = new AnimatedSprite(texture, currentFrame, spriteWidth, spriteHeight); } - /// - /// Reloads the asset from disk. - /// + /// Reloads the asset from disk. public void reload() { //Set the sprite texture diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/CharacterAnimationBases/CharacterAnimationBase.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/CharacterAnimationBases/CharacterAnimationBase.cs index 2eb3f08b..c4073e35 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/CharacterAnimationBases/CharacterAnimationBase.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/CharacterAnimationBases/CharacterAnimationBase.cs @@ -1,131 +1,43 @@ -using CustomNPCFramework.Framework.NPCS; +using CustomNPCFramework.Framework.NPCS; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace CustomNPCFramework.Framework.ModularNPCS +namespace CustomNPCFramework.Framework.ModularNpcs { - /// - /// Used as a base class for character animations. - /// + /// Used as a base class for character animations. public class CharacterAnimationBase { + /// Set the character sprites to left. + public virtual void setLeft() { } - /// - /// Constructor. - /// - public CharacterAnimationBase() - { - } + /// Set the character sprites to right. + public virtual void setRight() { } - /// - /// Set the character sprites to left. - /// - public virtual void setLeft() - { - } + /// Set the character sprites to up. + public virtual void setUp() { } - /// - /// Set the character sprites to right. - /// - public virtual void setRight() - { + /// Set the character sprites to down. + public virtual void setDown() { } - } + /// Used to reload the sprite textures. + public virtual void reload() { } - /// - /// Set the character sprites to up. - /// - public virtual void setUp() - { - - } - /// - /// Set the character sprites to down. - /// - public virtual void setDown() - { - - } - - /// - /// Used to reload the sprite textures. - /// - public virtual void reload() - { - } - - /// - /// Animate the sprites. - /// + /// Animate the sprites. /// How long between animation frames in milliseconds. - public virtual void Animate(float animationInterval) - { + public virtual void Animate(float animationInterval) { } - } - - /// - /// Used to animate sprites. - /// + /// Used to animate sprites. /// How long between animation frames in milliseconds. /// Loop the animation. - public virtual void Animate(float animationInterval, bool loop=true) - { + public virtual void Animate(float animationInterval, bool loop = true) { } - } + /// Used to draw the sprite to the screen. + public virtual void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth) { } - /// - /// Used to draw the sprite to the screen. - /// - /// - /// - /// - public virtual void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth) - { - - } - - - - /// - /// Used to draw the sprite to the screen. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public virtual void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth, int xOffset, int yOffset, Color c, bool flip = false, float scale = 1f, float rotation = 0.0f, bool characterSourceRectOffset = false) - { - - } - - /// - /// A very verbose asset drawer. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public virtual void draw(SpriteBatch b, ExtendedNPC npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) - { - - } + /// Used to draw the sprite to the screen. + public virtual void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth, int xOffset, int yOffset, Color c, bool flip = false, float scale = 1f, float rotation = 0.0f, bool characterSourceRectOffset = false) { } + /// A very verbose asset drawer. + public virtual void draw(SpriteBatch b, ExtendedNpc npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/CharacterAnimationBases/StandardCharacterAnimation.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/CharacterAnimationBases/StandardCharacterAnimation.cs index c563354b..20f5e843 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/CharacterAnimationBases/StandardCharacterAnimation.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/CharacterAnimationBases/StandardCharacterAnimation.cs @@ -1,54 +1,39 @@ -using CustomNPCFramework.Framework.ModularNPCS.ColorCollections; +using System; +using System.Collections.Generic; +using CustomNPCFramework.Framework.ModularNpcs.ColorCollections; using CustomNPCFramework.Framework.NPCS; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases +namespace CustomNPCFramework.Framework.ModularNpcs.CharacterAnimationBases { - /// - /// A class used to reference the different textures used to comprise the different parts for character rendering. - /// - public class StandardCharacterAnimation :CharacterAnimationBase + /// A class used to reference the different textures used to comprise the different parts for character rendering. + public class StandardCharacterAnimation : CharacterAnimationBase { - /// - /// Used to hold all of the information for the npc hair part. - /// + /// Used to hold all of the information for the npc hair part. public AnimatedSpriteCollection hair; - /// - /// Used to hold all of the information for the npc body part. - /// + + /// Used to hold all of the information for the npc body part. public AnimatedSpriteCollection body; - /// - /// Used to hold all of the information for the npc eyes part. - /// + + /// Used to hold all of the information for the npc eyes part. public AnimatedSpriteCollection eyes; - /// - /// Used to hold all of the information for the npc shirt part. - /// + + /// Used to hold all of the information for the npc shirt part. public AnimatedSpriteCollection shirt; - /// - /// Used to hold all of the information for the npc pants part. - /// + + /// Used to hold all of the information for the npc pants part. public AnimatedSpriteCollection pants; - /// - /// Used to hold all of the information for the npc shoes part. - /// + + /// Used to hold all of the information for the npc shoes part. public AnimatedSpriteCollection shoes; - /// - /// Used to hold all of the information for draw colors for the different parts. - /// + + /// Used to hold all of the information for draw colors for the different parts. public StandardColorCollection drawColors; public List accessories; - /// - /// Constructor. - /// + /// Construct an instance. /// The collection of textures to be used for the body part for the npc. /// The collection of textures to be used for the eyes part for the npc. /// The collection of textures to be used for the hair part for the npc. @@ -57,7 +42,7 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases /// The collection of textures to be used for the shoes part for the npc. /// The collection of textures to be used for the accessories part for the npc. /// The collection of draw colors for the different parts for the npc. - public StandardCharacterAnimation(AnimatedSpriteCollection bodyAnimation, AnimatedSpriteCollection eyeAnimation, AnimatedSpriteCollection hairAnimation, AnimatedSpriteCollection shirtAnimation, AnimatedSpriteCollection pantsAnimation, AnimatedSpriteCollection shoesAnimation,List accessoriesWithAnimations, StandardColorCollection DrawColors) :base() + public StandardCharacterAnimation(AnimatedSpriteCollection bodyAnimation, AnimatedSpriteCollection eyeAnimation, AnimatedSpriteCollection hairAnimation, AnimatedSpriteCollection shirtAnimation, AnimatedSpriteCollection pantsAnimation, AnimatedSpriteCollection shoesAnimation, List accessoriesWithAnimations, StandardColorCollection DrawColors) { this.body = bodyAnimation; this.hair = hairAnimation; @@ -69,9 +54,7 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases this.drawColors = DrawColors; } - /// - /// Sets all of the different textures to face left. - /// + /// Sets all of the different textures to face left. public override void setLeft() { this.body.setLeft(); @@ -81,14 +64,11 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases this.pants.setLeft(); this.shoes.setLeft(); - foreach(var accessory in this.accessories) - { + foreach (var accessory in this.accessories) accessory.setLeft(); - } } - /// - /// Sets all of the different textures to face right. - /// + + /// Sets all of the different textures to face right. public override void setRight() { this.body.setRight(); @@ -99,13 +79,10 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases this.shoes.setRight(); foreach (var accessory in this.accessories) - { accessory.setRight(); - } } - /// - /// Sets all of the different textures to face up. - /// + + /// Sets all of the different textures to face up. public override void setUp() { this.body.setUp(); @@ -116,13 +93,10 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases this.shoes.setUp(); foreach (var accessory in this.accessories) - { accessory.setUp(); - } } - /// - /// Sets all of the different textures to face down. - /// + + /// Sets all of the different textures to face down. public override void setDown() { this.body.setDown(); @@ -133,14 +107,10 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases this.shoes.setDown(); foreach (var accessory in this.accessories) - { accessory.setDown(); - } } - /// - /// Reloads all of the sprite textures. - /// + /// Reloads all of the sprite textures. public override void reload() { this.body.reload(); @@ -151,119 +121,77 @@ namespace CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases this.shoes.reload(); } - /// - /// Animates all of the textures for this sprite. - /// + /// Animates all of the textures for this sprite. /// The delay in milliseconds between animation frames. /// Determines if the animation continuously plays over and over. - public override void Animate(float animationInterval,bool loop=true) + public override void Animate(float animationInterval, bool loop = true) { - this.body.Animate(animationInterval,loop); - this.hair.Animate(animationInterval,loop); - this.eyes.Animate(animationInterval,loop); - this.shirt.Animate(animationInterval,loop); - this.pants.Animate(animationInterval,loop); - this.shoes.Animate(animationInterval,loop); - foreach(var accessory in this.accessories) - { - accessory.Animate(animationInterval,loop); - } - + this.body.Animate(animationInterval, loop); + this.hair.Animate(animationInterval, loop); + this.eyes.Animate(animationInterval, loop); + this.shirt.Animate(animationInterval, loop); + this.pants.Animate(animationInterval, loop); + this.shoes.Animate(animationInterval, loop); + foreach (var accessory in this.accessories) + accessory.Animate(animationInterval, loop); } - /// - /// Used to draw the sprite to the screen. - /// - /// - /// - /// + /// Used to draw the sprite to the screen. public override void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth) { - this.body.draw(b,screenPosition,layerDepth); + this.body.draw(b, screenPosition, layerDepth); this.hair.draw(b, screenPosition, layerDepth); this.eyes.draw(b, screenPosition, layerDepth); this.shirt.draw(b, screenPosition, layerDepth); this.pants.draw(b, screenPosition, layerDepth); this.shoes.draw(b, screenPosition, layerDepth); foreach (var accessory in this.accessories) - { accessory.draw(b, screenPosition, layerDepth); - } //b.Draw(this.currentSprite.Texture, screenPosition, new Rectangle?(this.currentSprite.sourceRect), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, this.currentSprite.currentAnimation == null || !this.currentSprite.currentAnimation[this.currentSprite.currentAnimationIndex].flip ? SpriteEffects.None : SpriteEffects.FlipHorizontally, layerDepth); } - - - /// - /// Used to draw the sprite to the screen. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// Used to draw the sprite to the screen. public override void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth, int xOffset, int yOffset, Color c, bool flip = false, float scale = 1f, float rotation = 0.0f, bool characterSourceRectOffset = false) { // b.Draw(this.currentSprite.Texture, screenPosition, new Rectangle?(new Rectangle(this.currentSprite.sourceRect.X + xOffset, this.currentSprite.sourceRect.Y + yOffset, this.currentSprite.sourceRect.Width, this.currentSprite.sourceRect.Height)), c, rotation, characterSourceRectOffset ? new Vector2((float)(this.currentSprite.spriteWidth / 2), (float)((double)this.currentSprite.spriteHeight * 3.0 / 4.0)) : Vector2.Zero, scale, flip || this.currentSprite.currentAnimation != null && this.currentSprite.currentAnimation[this.currentSprite.currentAnimationIndex].flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); - this.body.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c,this.drawColors.bodyColor), flip, scale, rotation, characterSourceRectOffset); + this.body.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.bodyColor), flip, scale, rotation, characterSourceRectOffset); this.hair.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.hairColor), flip, scale, rotation, characterSourceRectOffset); this.eyes.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.eyeColor), flip, scale, rotation, characterSourceRectOffset); this.shirt.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.shirtColor), flip, scale, rotation, characterSourceRectOffset); this.pants.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.bottomsColor), flip, scale, rotation, characterSourceRectOffset); this.shoes.draw(b, screenPosition, layerDepth, xOffset, yOffset, StandardColorCollection.colorMult(c, this.drawColors.shoesColor), flip, scale, rotation, characterSourceRectOffset); - foreach(var accessory in this.accessories) - { + foreach (var accessory in this.accessories) accessory.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset); - } } - /// - /// A very verbose asset drawer. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public override void draw(SpriteBatch b, ExtendedNPC npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) + /// A very verbose asset drawer. + public override void draw(SpriteBatch b, ExtendedNpc npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { //Class1.ModMonitor.Log(sourceRectangle.ToString()); - Vector2 generalOffset = new Vector2(0, 1*Game1.tileSize); //Puts the sprite at the correct positioning. + Vector2 generalOffset = new Vector2(0, 1 * Game1.tileSize); //Puts the sprite at the correct positioning. position -= new Vector2(0, 0.25f * Game1.tileSize); float smallOffset = 0.001f; float tinyOffset = 0.0001f; //Class1.ModMonitor.Log((position - generalOffset).ToString()); float num = Math.Max(0.0f, (float)(Math.Ceiling(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 600.0 + (double)npc.DefaultPosition.X * 20.0)) / 4.0)); - this.body.draw(b, npc, position-generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.bodyColor), alpha, origin, scale*Game1.pixelZoom, effects, layerDepth + smallOffset); - this.eyes.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.eyeColor), alpha, origin, scale*Game1.pixelZoom, effects, layerDepth + smallOffset+(tinyOffset *1)); - this.hair.draw(b, npc, position-generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.hairColor), alpha, origin, scale*Game1.pixelZoom, effects, layerDepth + smallOffset+(tinyOffset *2)); + this.body.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.bodyColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset); + this.eyes.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.eyeColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 1)); + this.hair.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.hairColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 2)); if (num > 0.0f) { Vector2 shirtOffset = new Vector2((1 * Game1.tileSize) / 4, (1 * Game1.tileSize) / 4); - this.shirt.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.shirtColor), alpha, new Vector2(0.5f,1), scale * Game1.pixelZoom + num, effects, layerDepth + smallOffset + (tinyOffset * 3)); + this.shirt.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.shirtColor), alpha, new Vector2(0.5f, 1), scale * Game1.pixelZoom + num, effects, layerDepth + smallOffset + (tinyOffset * 3)); } else { this.shirt.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.shirtColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 3)); } - this.pants.draw(b, npc, position-generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.bottomsColor), alpha, origin, scale*Game1.pixelZoom, effects, layerDepth + smallOffset+(tinyOffset*4)); - this.shoes.draw(b, npc, position-generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.shoesColor), alpha, origin, scale*Game1.pixelZoom, effects, layerDepth + smallOffset+(tinyOffset*5)); - foreach(var accessory in this.accessories) - { - accessory.draw(b, npc, position-generalOffset, sourceRectangle, color, alpha, origin, scale, effects, layerDepth +0.0006f); - } - } + this.pants.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.bottomsColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 4)); + this.shoes.draw(b, npc, position - generalOffset, sourceRectangle, StandardColorCollection.colorMult(color, this.drawColors.shoesColor), alpha, origin, scale * Game1.pixelZoom, effects, layerDepth + smallOffset + (tinyOffset * 5)); + foreach (var accessory in this.accessories) + accessory.draw(b, npc, position - generalOffset, sourceRectangle, color, alpha, origin, scale, effects, layerDepth + 0.0006f); + } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ColorCollections/StandardColorCollection.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ColorCollections/StandardColorCollection.cs index c27922e7..7b50eceb 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ColorCollections/StandardColorCollection.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ColorCollections/StandardColorCollection.cs @@ -1,93 +1,72 @@ -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Xna.Framework; -namespace CustomNPCFramework.Framework.ModularNPCS.ColorCollections +namespace CustomNPCFramework.Framework.ModularNpcs.ColorCollections { - /// - /// Collection of colors to be used for the StandardCharacterAnimation object. - /// + /// Collection of colors to be used for the StandardCharacterAnimation object. public class StandardColorCollection { - /// - /// The draw color to be used for the body sprite for the npc. - /// + /// The draw color to be used for the body sprite for the npc. public Color bodyColor; - /// - /// The draw color to be used for the eye sprite for the npc. - /// + + /// The draw color to be used for the eye sprite for the npc. public Color eyeColor; - /// - /// The draw color to be used for the hair sprite for the npc. - /// + + /// The draw color to be used for the hair sprite for the npc. public Color hairColor; - /// - /// The draw color to be used for the shirt sprite for the npc. - /// + + /// The draw color to be used for the shirt sprite for the npc. public Color shirtColor; - /// - /// The draw color to be used for the bottoms/pants sprite for the npc. - /// + + /// The draw color to be used for the bottoms/pants sprite for the npc. public Color bottomsColor; - /// - /// The draw color to be used for the shoes sprite for the npc. - /// + + /// The draw color to be used for the shoes sprite for the npc. public Color shoesColor; - /// - /// Default constrctor that sets all of the draw colors to white. - /// + /// Construct an instance. public StandardColorCollection() { - defaultColor(this.bodyColor); - defaultColor(this.eyeColor); - defaultColor(this.hairColor); - defaultColor(this.shirtColor); - defaultColor(this.bottomsColor); - defaultColor(this.shoesColor); + this.defaultColor(this.bodyColor); + this.defaultColor(this.eyeColor); + this.defaultColor(this.hairColor); + this.defaultColor(this.shirtColor); + this.defaultColor(this.bottomsColor); + this.defaultColor(this.shoesColor); } - /// - /// Constructor that takes different colors as parameters. - /// - /// Color for the body texture. - /// Color for the eyes texture. - /// Color for the hair texture. - /// Color for the shirt texture. - /// Color for the bottoms texture. - /// Color for the shoes texture. - public StandardColorCollection(Color? BodyColor, Color? EyeColor, Color? HairColor, Color? ShirtColor, Color? BottomsColor, Color? ShoesColor) + /// Construct an instance. + /// Color for the body texture. + /// Color for the eyes texture. + /// Color for the hair texture. + /// Color for the shirt texture. + /// Color for the bottoms texture. + /// Color for the shoes texture. + public StandardColorCollection(Color? bodyColor, Color? eyeColor, Color? hairColor, Color? shirtColor, Color? bottomsColor, Color? shoesColor) { - this.bodyColor = (Color)BodyColor.GetValueOrDefault(Color.White); - this.eyeColor = (Color)EyeColor.GetValueOrDefault(Color.White); - this.hairColor = (Color)HairColor.GetValueOrDefault(Color.White); - this.shirtColor = (Color)ShirtColor.GetValueOrDefault(Color.White); - this.bottomsColor = (Color)BottomsColor.GetValueOrDefault(Color.White); - this.shoesColor = (Color)ShoesColor.GetValueOrDefault(Color.White); + this.bodyColor = bodyColor.GetValueOrDefault(Color.White); + this.eyeColor = eyeColor.GetValueOrDefault(Color.White); + this.hairColor = hairColor.GetValueOrDefault(Color.White); + this.shirtColor = shirtColor.GetValueOrDefault(Color.White); + this.bottomsColor = bottomsColor.GetValueOrDefault(Color.White); + this.shoesColor = shoesColor.GetValueOrDefault(Color.White); - defaultColor(this.bodyColor); - defaultColor(this.eyeColor); - defaultColor(this.hairColor); - defaultColor(this.shirtColor); - defaultColor(this.bottomsColor); - defaultColor(this.shoesColor); + this.defaultColor(this.bodyColor); + this.defaultColor(this.eyeColor); + this.defaultColor(this.hairColor); + this.defaultColor(this.shirtColor); + this.defaultColor(this.bottomsColor); + this.defaultColor(this.shoesColor); } - /// - /// If a color is null, make it white. - /// - /// + /// If a color is null, make it white. + /// The color to check. public void defaultColor(Color color) { - if (color == null) color = Color.White; + if (color == null) + color = Color.White; } - /// - /// Used to mix colors together. - /// + /// Used to mix colors together. /// The base color to mix. /// The modifier color to mix. /// A color that is a mix between the two colors passed in. diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ModularRenderers/AnimationKeys.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ModularRenderers/AnimationKeys.cs index de9249ae..d862d2be 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ModularRenderers/AnimationKeys.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ModularRenderers/AnimationKeys.cs @@ -1,31 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers +namespace CustomNPCFramework.Framework.ModularNpcs.ModularRenderers { - /// - /// A class used instead of an enum to hold keys for all of the different animations. - /// + /// A class used instead of an enum to hold keys for all of the different animations. public class AnimationKeys { - /// - /// The string that is used for the standing animation. - /// + /// The string that is used for the standing animation. public static string standingKey = "standing"; - /// - /// The string that is used for the walking/moving animation. - /// + + /// The string that is used for the walking/moving animation. public static string walkingKey = "walking"; - /// - /// The string that is used for the sitting animation. - /// + + /// The string that is used for the sitting animation. public static string sittingKey = "sitting"; - /// - /// The string that is used for the swimming animation. - /// + + /// The string that is used for the swimming animation. public static string swimmingKey = "swimming"; } } diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ModularRenderers/BasicRenderer.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ModularRenderers/BasicRenderer.cs index 6ea6629b..eb4ae60f 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ModularRenderers/BasicRenderer.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/ModularRenderers/BasicRenderer.cs @@ -1,205 +1,137 @@ -using CustomNPCFramework.Framework.Enums; -using CustomNPCFramework.Framework.Graphics; -using CustomNPCFramework.Framework.ModularNPCS.CharacterAnimationBases; +using System.Collections.Generic; +using CustomNPCFramework.Framework.Enums; +using CustomNPCFramework.Framework.ModularNpcs.CharacterAnimationBases; using CustomNPCFramework.Framework.NPCS; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace CustomNPCFramework.Framework.ModularNPCS.ModularRenderers +namespace CustomNPCFramework.Framework.ModularNpcs.ModularRenderers { - /// - /// A class used to hold all of the textures/animations/information to make modular npc rendering possible. - /// + /// A class used to hold all of the textures/animations/information to make modular npc rendering possible. public class BasicRenderer { - /// - /// Dictionary that holds key pair values of (animationName,Animation). USed to manage multiple animations. - /// + /// Dictionary that holds key pair values of (animationName,Animation). USed to manage multiple animations. public Dictionary animationList; - /// - /// Used to keep track of what animation is currently being used. - /// + + /// Used to keep track of what animation is currently being used. public StandardCharacterAnimation currentAnimation; - /// - /// Constructor. - /// + /// Construct an instance. /// The animation information to be used when the character is standing. /// The animation information to be used when the character is walking/moving. /// The animation information to be used when the character is walking/moving. - public BasicRenderer(StandardCharacterAnimation standingAnimation,StandardCharacterAnimation walkingAnimation, StandardCharacterAnimation swimmingAnimation) + public BasicRenderer(StandardCharacterAnimation standingAnimation, StandardCharacterAnimation walkingAnimation, StandardCharacterAnimation swimmingAnimation) { - animationList = new Dictionary(); - animationList.Add(AnimationKeys.standingKey, standingAnimation); - animationList.Add(AnimationKeys.walkingKey, walkingAnimation); - animationList.Add(AnimationKeys.swimmingKey, swimmingAnimation); - setAnimation(AnimationKeys.standingKey); + this.animationList = new Dictionary(); + this.animationList.Add(AnimationKeys.standingKey, standingAnimation); + this.animationList.Add(AnimationKeys.walkingKey, walkingAnimation); + this.animationList.Add(AnimationKeys.swimmingKey, swimmingAnimation); + this.setAnimation(AnimationKeys.standingKey); } - /// - /// Sets the animation associated with the key name; If it fails the npc will just default to standing. - /// + /// Sets the animation associated with the key name; If it fails the npc will just default to standing. /// The name of the animation to swap the current animation to. public virtual void setAnimation(string key) { - this.currentAnimation = animationList[key]; + this.currentAnimation = this.animationList[key]; if (this.currentAnimation == null) { - Class1.ModMonitor.Log("ERROR SETTING AN ANIMATION: "+key); + Class1.ModMonitor.Log("ERROR SETTING AN ANIMATION: " + key); this.setAnimation(AnimationKeys.standingKey); } } - /// - /// Sets the direction of the current animated sprite respectively. - /// + /// Sets the direction of the current animated sprite respectively. /// The direction to face. 0=up, 1=right, 2= down, 3=left. public virtual void setDirection(int facingDirection) { - if (facingDirection == 0) setUp(); - if (facingDirection == 1) setRight(); - if (facingDirection == 2) setDown(); - if (facingDirection == 2) setLeft(); + this.setDirection((Direction)facingDirection); } - /// - /// Sets the direction of the current animated sprite respectively to the direction passed in. - /// + /// Sets the direction of the current animated sprite respectively to the direction passed in. /// The direction to face. public virtual void setDirection(Direction direction) { - if (direction == Direction.up) setUp(); - if (direction == Direction.right) setRight(); - if (direction == Direction.down) setDown(); - if (direction == Direction.left) setLeft(); + switch (direction) + { + case Direction.up: + this.setUp(); + break; + + case Direction.right: + this.setRight(); + break; + + case Direction.down: + this.setDown(); + break; + + case Direction.left: + this.setLeft(); + break; + } } - - /// - /// Sets the current animated sprite to face left. - /// + /// Sets the current animated sprite to face left. public virtual void setLeft() { this.currentAnimation.setLeft(); } - /// - /// Sets the current animated sprite to face right. - /// + /// Sets the current animated sprite to face right. public virtual void setRight() { this.currentAnimation.setRight(); } - /// - /// Sets the current animated sprite to face up. - /// + /// Sets the current animated sprite to face up. public virtual void setUp() { this.currentAnimation.setUp(); } - - /// - /// Sets the current animated sprite to face down. - /// + + /// Sets the current animated sprite to face down. public virtual void setDown() { this.currentAnimation.setDown(); } - /// - /// Used to reload all of the sprites pertaining to all of the animations stored in this renderer. - /// + /// Used to reload all of the sprites pertaining to all of the animations stored in this renderer. public virtual void reloadSprites() { - foreach(var v in this.animationList) - { + foreach (var v in this.animationList) v.Value.reload(); - } } - /// - /// Used to draw the sprite to the screen. - /// - /// - /// - /// + /// Used to draw the sprite to the screen. public virtual void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth) { this.currentAnimation.draw(b, screenPosition, layerDepth); } - /// - /// Used to draw the sprite to the screen. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// Used to draw the sprite to the screen. public virtual void draw(SpriteBatch b, Vector2 screenPosition, float layerDepth, int xOffset, int yOffset, Color c, bool flip = false, float scale = 1f, float rotation = 0.0f, bool characterSourceRectOffset = false) { this.currentAnimation.draw(b, screenPosition, layerDepth, xOffset, yOffset, c, flip, scale, rotation, characterSourceRectOffset); } - /// - /// A very verbose asset drawer. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public virtual void draw(SpriteBatch b, ExtendedNPC npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) + /// A very verbose asset drawer. + public virtual void draw(SpriteBatch b, ExtendedNpc npc, Vector2 position, Rectangle sourceRectangle, Color color, float alpha, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { - this.currentAnimation.draw(b, npc, position, sourceRectangle, color, alpha, origin, scale, effects, layerDepth); } - /// - /// Animates the current animation for the current sprite. - /// - /// - /// - public virtual void Animate(float interval, bool loop=true) + /// Animates the current animation for the current sprite. + public virtual void Animate(float interval, bool loop = true) { - this.currentAnimation.Animate(interval,loop); + this.currentAnimation.Animate(interval, loop); } - - /// - /// Wrapper for a draw function that accepts rectangles to be null. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public virtual void draw(SpriteBatch b, ExtendedNPC extendedNPC, Vector2 position, Rectangle? v1, Color white, float rotation, Vector2 origin, float scale, SpriteEffects spriteEffects, float v3) + /// Wrapper for a draw function that accepts rectangles to be null. + public virtual void draw(SpriteBatch b, ExtendedNpc extendedNPC, Vector2 position, Rectangle? v1, Color white, float rotation, Vector2 origin, float scale, SpriteEffects spriteEffects, float v3) { - this.draw(b, extendedNPC, position, new Rectangle(0,0,16,32), white, rotation, origin, scale, spriteEffects, v3); + this.draw(b, extendedNPC, position, new Rectangle(0, 0, 16, 32), white, rotation, origin, scale, spriteEffects, v3); } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Portrait.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Portrait.cs index 4e6b10aa..2ec8b3e6 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Portrait.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Portrait.cs @@ -1,49 +1,32 @@ -using CustomNPCFramework.Framework.NPCS; +using CustomNPCFramework.Framework.NPCS; using Microsoft.Xna.Framework.Graphics; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace CustomNPCFramework.Framework.ModularNPCS +namespace CustomNPCFramework.Framework.ModularNpcs { - /// - /// Used as a wrapper for npc portraits. - /// + /// Used as a wrapper for npc portraits. public class Portrait { - /// - /// Used to display the npc portrait. - /// + /// Used to display the npc portrait. public Texture2D portrait; - /// - /// Used to hold the path to the texture to use for the npc portrait. - /// + + /// Used to hold the path to the texture to use for the npc portrait. public string relativePath; - /// - /// A class for handling portraits. - /// + /// /// The full path to the file. public Portrait(string path) { - this.relativePath =Class1.getRelativeDirectory(path); - this.portrait=Class1.ModHelper.Content.Load(path); + this.relativePath = Class1.getRelativeDirectory(path); + this.portrait = Class1.ModHelper.Content.Load(path); } - /// - /// Sets the npc's portrait to be this portrait texture. - /// - /// - public void setCharacterPortraitFromThis(ExtendedNPC npc) + /// Sets the npc's portrait to be this portrait texture. + public void setCharacterPortraitFromThis(ExtendedNpc npc) { npc.Portrait = this.portrait; } - /// - /// Reloads the texture for the NPC portrait. - /// + /// Reloads the texture for the NPC portrait. public void reload() { this.portrait = Class1.ModHelper.Content.Load(this.relativePath); diff --git a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Sprite.cs b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Sprite.cs index e821bebc..2a02bbff 100644 --- a/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Sprite.cs +++ b/GeneralMods/CustomNPCFramework/Framework/ModularNPCS/Sprite.cs @@ -1,32 +1,19 @@ -using CustomNPCFramework.Framework.ModularNPCS.ModularRenderers; using CustomNPCFramework.Framework.NPCS; using Microsoft.Xna.Framework.Graphics; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace CustomNPCFramework.Framework.ModularNPCS +namespace CustomNPCFramework.Framework.ModularNpcs { - /// - /// Used as a wrapper for the npcs to hold sprite information. - /// + /// Used as a wrapper for the npcs to hold sprite information. public class Sprite { - /// - /// The actual sprite to draw for the npc. - /// + /// The actual sprite to draw for the npc. public AnimatedSprite sprite; - /// - /// The path to the texture to use for the animated sprite. - /// + + /// The path to the texture to use for the animated sprite. public string relativePath; - /// - /// A class for handling character sprites. - /// + /// Construct an instance. /// The full path to the file. public Sprite(string path) { @@ -34,7 +21,7 @@ namespace CustomNPCFramework.Framework.ModularNPCS { this.relativePath = Class1.getShortenedDirectory(path); } - catch(Exception err) + catch { this.relativePath = path; } @@ -42,11 +29,11 @@ namespace CustomNPCFramework.Framework.ModularNPCS { this.sprite = new AnimatedSprite(); Texture2D text = Class1.ModHelper.Content.Load(this.relativePath); - var reflect=Class1.ModHelper.Reflection.GetField(this.sprite, "Texture", true); + var reflect = Class1.ModHelper.Reflection.GetField(this.sprite, "Texture", true); reflect.SetValue(text); - + } - catch(Exception err) + catch { this.sprite = new AnimatedSprite(); Texture2D text = Class1.ModHelper.Content.Load(this.relativePath); @@ -57,9 +44,7 @@ namespace CustomNPCFramework.Framework.ModularNPCS this.sprite.SpriteHeight = this.sprite.Texture.Height; } - /// - /// Constructor. - /// + /// Construct an instance. /// Used to hold the path to the asset. /// Used to assign the texture to the sprite from a pre-loaded asset. public Sprite(string path, string texture) @@ -70,75 +55,42 @@ namespace CustomNPCFramework.Framework.ModularNPCS this.sprite.SpriteHeight = this.sprite.Texture.Height; } - /// - /// Sets the npc's portrait to be this portrait texture. - /// - /// - public void setCharacterSpriteFromThis(ExtendedNPC npc) + /// Sets the npc's portrait to be this portrait texture. + public void setCharacterSpriteFromThis(ExtendedNpc npc) { npc.Sprite = this.sprite; } - /// - /// Reloads the texture for the NPC portrait. - /// + /// Reloads the texture for the NPC portrait. public void reload() { - var text=CustomNPCFramework.Class1.ModHelper.Reflection.GetField(this.sprite.Texture, "Texture", true); - Texture2D loaded= Class1.ModHelper.Content.Load(this.relativePath); + var text = Class1.ModHelper.Reflection.GetField(this.sprite.Texture, "Texture", true); + Texture2D loaded = Class1.ModHelper.Content.Load(this.relativePath); text.SetValue(loaded); } - /// - /// Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc. - /// - /// - public void setLeft(ExtendedNPC npc) + /// Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc. + public void setLeft(ExtendedNpc npc) { - if (npc.characterRenderer == null) - { - return; - } - else npc.characterRenderer.setLeft(); + npc.characterRenderer?.setLeft(); } - /// - /// Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc. - /// - /// - public void setRight(ExtendedNPC npc) + /// Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc. + public void setRight(ExtendedNpc npc) { - if (npc.characterRenderer == null) - { - return; - } - else npc.characterRenderer.setRight(); + npc.characterRenderer?.setRight(); } - /// - /// Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc. - /// - /// - public void setDown(ExtendedNPC npc) + /// Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc. + public void setDown(ExtendedNpc npc) { - if (npc.characterRenderer == null) - { - return; - } - else npc.characterRenderer.setDown(); + npc.characterRenderer?.setDown(); } - /// - /// Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc. - /// - /// - public void setUp(ExtendedNPC npc) + /// Set's the npc's sprites to face left IF and only if there is a non-null modular Renderer attached to the npc. + public void setUp(ExtendedNpc npc) { - if (npc.characterRenderer == null) - { - return; - } - else npc.characterRenderer.setUp(); + npc.characterRenderer?.setUp(); } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/NPCNames.cs b/GeneralMods/CustomNPCFramework/Framework/NPCNames.cs index 6ede8e02..f511193a 100644 --- a/GeneralMods/CustomNPCFramework/Framework/NPCNames.cs +++ b/GeneralMods/CustomNPCFramework/Framework/NPCNames.cs @@ -1,77 +1,59 @@ -using CustomNPCFramework.Framework.Enums; -using StardewValley; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using CustomNPCFramework.Framework.Enums; +using StardewValley; namespace CustomNPCFramework.Framework { - /// - /// Used as a class to hold all of the possible npc names. - /// - public class NPCNames + /// Used as a class to hold all of the possible NPC names. + public class NpcNames { - /// - /// Holds all of the npc male names. - /// - public static List maleNames = new List() + /// Holds all of the NPC male names. + public static List maleNames = new List { "Freddy", "Josh", "Ash" }; - /// - /// Holds all of the npc female names. - /// - public static List femaleNames = new List() + /// Holds all of the NPC female names. + public static List femaleNames = new List { "Rebecca", "Sierra", "Lisa" }; - /// - /// Holds all of the npc gender non-binary names. - /// - public static List otherGenderNames = new List() + /// Holds all of the NPC gender non-binary names. + public static List otherGenderNames = new List { "Jayden", "Ryanne", "Skylar" }; - /// - /// Get a gender appropriate name from the pool of npc names. - /// - /// - /// - public static string getRandomNPCName(Genders gender) + /// Get a gender appropriate name from the pool of NPC names. + public static string getRandomNpcName(Genders gender) { - if (gender == Genders.female) { - + if (gender == Genders.female) + { int rand = Game1.random.Next(0, femaleNames.Count - 1); return femaleNames.ElementAt(rand); } if (gender == Genders.male) { - int rand = Game1.random.Next(0, maleNames.Count - 1); return maleNames.ElementAt(rand); } if (gender == Genders.other) { - int rand = Game1.random.Next(0, otherGenderNames.Count - 1); return otherGenderNames.ElementAt(rand); } return ""; - } } } diff --git a/GeneralMods/CustomNPCFramework/Framework/NPCS/ExtendedNPC.cs b/GeneralMods/CustomNPCFramework/Framework/NPCS/ExtendedNPC.cs index 925fd7c3..9a3e4d08 100644 --- a/GeneralMods/CustomNPCFramework/Framework/NPCS/ExtendedNPC.cs +++ b/GeneralMods/CustomNPCFramework/Framework/NPCS/ExtendedNPC.cs @@ -1,35 +1,22 @@ -using CustomNPCFramework.Framework.Enums; -using CustomNPCFramework.Framework.ModularNPCS; -using CustomNPCFramework.Framework.ModularNPCS.ModularRenderers; +using System; +using CustomNPCFramework.Framework.Enums; +using CustomNPCFramework.Framework.ModularNpcs; +using CustomNPCFramework.Framework.ModularNpcs.ModularRenderers; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewValley; -using StardewValley.Buildings; -using StardewValley.Characters; -using StardewValley.Locations; -using StardewValley.Menus; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using xTile.Dimensions; -using xTile.ObjectModel; -using xTile.Tiles; namespace CustomNPCFramework.Framework.NPCS { - /// - /// TODO: Add in an resource loader for all of the character graphics and use it to populate some character graphics. - /// Make .json way to load in assets to the mod. - /// Organize it all. - /// Profit??? - /// - public class ExtendedNPC :StardewValley.NPC + // TODO: + // - Add in an resource loader for all of the character graphics and use it to populate some character graphics. + // - Make .json way to load in assets to the mod. + // - Organize it all. + // - Profit??? + + public class ExtendedNpc : NPC { - /// - /// The custom character renderer for this npc. - /// + /// The custom character renderer for this npc. public BasicRenderer characterRenderer; public bool hasBeenKissedToday; public Point previousEndPoint; @@ -37,122 +24,89 @@ namespace CustomNPCFramework.Framework.NPCS public bool hasSaidAfternoonDialogue; public int timeAfterSquare; - /// - /// Used to hold sprite information to be used in the case the npc renderer is null. - /// + /// Used to hold sprite information to be used in the case the npc renderer is null. public Sprite spriteInformation; - /// - /// Used to hold the portrait information for the npc and display it. - /// + /// Used to hold the portrait information for the npc and display it. public Portrait portraitInformation; - /// - /// The default location for this npc to reside in. - /// + /// The default location for this npc to reside in. public GameLocation defaultLocation; - /// - /// Empty Constructor. - /// - public ExtendedNPC() :base() - { - } + /// Construct an instance. + public ExtendedNpc() { } - /// - /// Non modular npc Constructor. - /// + /// Construct an instance. /// The sprite for the character. /// The position of the npc on the map. /// The direction of the npc /// The name of the npc. - public ExtendedNPC(Sprite sprite, Vector2 position, int facingDirection, string name) : base(sprite.sprite, position, facingDirection, name, null) + public ExtendedNpc(Sprite sprite, Vector2 position, int facingDirection, string name) + : base(sprite.sprite, position, facingDirection, name) { this.characterRenderer = null; - this.Portrait = (Texture2D)null; + this.Portrait = null; this.portraitInformation = null; this.spriteInformation = sprite; - if (this.spriteInformation != null) - { - this.spriteInformation.setCharacterSpriteFromThis(this); - } + this.spriteInformation?.setCharacterSpriteFromThis(this); this.swimming.Value = false; } - /// - /// Non modular npc Constructor. - /// + /// Construct an instance. /// The sprite for the character. /// The portrait texture for this npc. /// The position of the npc on the map. /// The direction of the npc /// The name of the npc. - public ExtendedNPC(Sprite sprite, Portrait portrait, Vector2 position, int facingDirection, string name) : base(sprite.sprite, position, facingDirection, name, null) + public ExtendedNpc(Sprite sprite, Portrait portrait, Vector2 position, int facingDirection, string name) + : base(sprite.sprite, position, facingDirection, name) { this.characterRenderer = null; this.portraitInformation = portrait; - if (this.portraitInformation != null) - { - this.portraitInformation.setCharacterPortraitFromThis(this); - } + this.portraitInformation?.setCharacterPortraitFromThis(this); this.spriteInformation = sprite; this.spriteInformation.setCharacterSpriteFromThis(this); this.swimming.Value = false; } - /// - /// Modular npc constructor. - /// + /// Construct an instance. /// The sprite for the character to use incase the renderer is null. /// The custom npc render. Used to draw the npcfrom a collection of assets. - /// The portrait texture for this npc. /// The position of the npc on the map. /// The direction of the npc /// The name of the npc. - public ExtendedNPC(Sprite sprite,BasicRenderer renderer,Vector2 position,int facingDirection,string name): base(sprite.sprite, position, facingDirection, name, null) + public ExtendedNpc(Sprite sprite, BasicRenderer renderer, Vector2 position, int facingDirection, string name) + : base(sprite.sprite, position, facingDirection, name) { this.characterRenderer = renderer; - this.Portrait = (Texture2D)null; + this.Portrait = null; this.portraitInformation = null; this.spriteInformation = sprite; - if (this.spriteInformation != null) - { - this.spriteInformation.setCharacterSpriteFromThis(this); - } + this.spriteInformation?.setCharacterSpriteFromThis(this); this.swimming.Value = false; } - /// - /// Modular constructor for the npc. - /// + /// Construct an instance. /// The sprite for the npc to use incase the renderer is null. /// The custom npc renderer used to draw the npc from the collection of textures. /// The portrait texture for the npc. /// The positon for the npc to be. /// The direction for the npc to face. /// The name for the npc. - public ExtendedNPC(Sprite sprite,BasicRenderer renderer,Portrait portrait, Vector2 position, int facingDirection, string name) : base(sprite.sprite, position, facingDirection, name, null) + public ExtendedNpc(Sprite sprite, BasicRenderer renderer, Portrait portrait, Vector2 position, int facingDirection, string name) + : base(sprite.sprite, position, facingDirection, name) { this.characterRenderer = renderer; this.portraitInformation = portrait; - if (this.portraitInformation != null) - { - this.portraitInformation.setCharacterPortraitFromThis(this); - } + this.portraitInformation?.setCharacterPortraitFromThis(this); this.spriteInformation = sprite; - if (this.spriteInformation != null) - { - this.spriteInformation.setCharacterSpriteFromThis(this); - } + this.spriteInformation?.setCharacterSpriteFromThis(this); this.swimming.Value = false; } - /// - /// Used to reload the sprite for the npc. - /// + /// Used to reload the sprite for the npc. public void reloadSprite() { - if (this.characterRenderer == null) { this.spriteInformation.reload(); @@ -160,10 +114,9 @@ namespace CustomNPCFramework.Framework.NPCS { this.portraitInformation.reload(); } - catch (Exception ex) + catch { - ex.ToString(); - this.Portrait = (Texture2D)null; + this.Portrait = null; } } else @@ -173,14 +126,12 @@ namespace CustomNPCFramework.Framework.NPCS { this.portraitInformation.reload(); } - catch (Exception ex) + catch { - ex.ToString(); - this.Portrait = (Texture2D)null; + this.Portrait = null; } } - int num = this.IsInvisible ? 1 : 0; - if (!Game1.newDay && (int)Game1.gameMode != 6) + if (!Game1.newDay && Game1.gameMode != 6) return; this.faceDirection(this.DefaultFacingDirection); this.scheduleTimeToTry = 9999999; @@ -188,164 +139,133 @@ namespace CustomNPCFramework.Framework.NPCS this.Schedule = this.getSchedule(Game1.dayOfMonth); this.faceDirection(this.defaultFacingDirection); this.Sprite.standAndFaceDirection(this.defaultFacingDirection); - + if (this.isMarried()) this.marriageDuties(); - bool flag = Utility.isFestivalDay(Game1.dayOfMonth, Game1.currentSeason); try { this.displayName = this.Name; } - catch (Exception ex) - { - ex.ToString(); - } - + catch { } } - /// - /// Functionality used when interacting with the npc. - /// - /// - /// - /// - public override bool checkAction(StardewValley.Farmer who, GameLocation l) + /// Functionality used when interacting with the npc. + public override bool checkAction(Farmer who, GameLocation l) { base.checkAction(who, l); return false; } - /// - /// Used to move the npc. Different code is used depending if the character renderer is null or not. - /// - /// - /// - /// + /// Used to move the npc. Different code is used depending if the character renderer is null or not. public override void MovePosition(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation currentLocation) { if (this.characterRenderer != null) - { - ModularMovement(time,viewport,currentLocation); - } + this.ModularMovement(time, viewport, currentLocation); else - { - NonModularMovement(time,viewport,currentLocation); - } - return; - + this.NonModularMovement(time, viewport, currentLocation); } - /// - /// Set's the npc to move a certain direction and then executes the movement. - /// - /// - /// - /// - /// The direction to move the npc. + /// Set's the npc to move a certain direction and then executes the movement. + /// The direction to move the npc. /// Set's the npc's sprite to halt if Move=false. Else set it to true. - public virtual void SetMovingAndMove(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation currentLocation, Direction MoveDirection, bool Move=true) + public virtual void SetMovingAndMove(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation currentLocation, Direction moveDirection, bool Move = true) { - if (MoveDirection == Direction.down) this.SetMovingDown(Move); - if (MoveDirection == Direction.left) this.SetMovingLeft(Move); - if (MoveDirection == Direction.up) this.SetMovingUp(Move); - if (MoveDirection == Direction.right) this.SetMovingRight(Move); + switch (moveDirection) + { + case Direction.down: + this.SetMovingDown(Move); + break; + + case Direction.left: + this.SetMovingLeft(Move); + break; + + case Direction.up: + this.SetMovingUp(Move); + break; + + case Direction.right: + this.SetMovingRight(Move); + break; + } + this.MovePosition(time, viewport, currentLocation); } - /// - /// USed to move the npc if the character renderer is null. - /// - /// - /// - /// + /// USed to move the npc if the character renderer is null. public virtual void NonModularMovement(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation location) { - base.MovePosition(time, viewport, currentLocation); - return; + base.MovePosition(time, viewport, this.currentLocation); } - /// - /// Used to determine if the npc can move past the next location. - /// - /// - /// + /// Used to determine if the npc can move past the next location. public virtual bool canMovePastNextLocation(xTile.Dimensions.Rectangle viewport) { //Up - if (!currentLocation.isTilePassable(this.nextPosition(0), viewport) || !this.willDestroyObjectsUnderfoot) - { + if (!this.currentLocation.isTilePassable(this.nextPosition(0), viewport) || !this.willDestroyObjectsUnderfoot) return false; - } + //Right - if (!currentLocation.isTilePassable(this.nextPosition(1), viewport) || !this.willDestroyObjectsUnderfoot) - { + if (!this.currentLocation.isTilePassable(this.nextPosition(1), viewport) || !this.willDestroyObjectsUnderfoot) return false; - } + //Down - if (!currentLocation.isTilePassable(this.nextPosition(2), viewport) || !this.willDestroyObjectsUnderfoot) - { + if (!this.currentLocation.isTilePassable(this.nextPosition(2), viewport) || !this.willDestroyObjectsUnderfoot) return false; - } + //Left - if (!currentLocation.isTilePassable(this.nextPosition(3), viewport) || !this.willDestroyObjectsUnderfoot) - { + if (!this.currentLocation.isTilePassable(this.nextPosition(3), viewport) || !this.willDestroyObjectsUnderfoot) return false; - } + return true; } - /// - /// Used to move the npc if the character renderer is valid. Handles animating all of the sprites associated with the renderer. - /// - /// - /// - /// - /// + /// Used to move the npc if the character renderer is valid. Handles animating all of the sprites associated with the renderer. public virtual void ModularMovement(GameTime time, xTile.Dimensions.Rectangle viewport, GameLocation location, float interval = 1000f) { this.characterRenderer.setAnimation(AnimationKeys.walkingKey); - if (this.canMovePastNextLocation(viewport) == false) + if (!this.canMovePastNextLocation(viewport)) { this.Halt(); return; } if (this.GetType() == typeof(FarmAnimal)) this.willDestroyObjectsUnderfoot = false; - if ((double)this.xVelocity != 0.0 || (double)this.yVelocity != 0.0) + if (this.xVelocity != 0.0 || this.yVelocity != 0.0) { - Microsoft.Xna.Framework.Rectangle boundingBox = this.GetBoundingBox(); + var boundingBox = this.GetBoundingBox(); boundingBox.X += (int)this.xVelocity; boundingBox.Y -= (int)this.yVelocity; - if (currentLocation == null || !currentLocation.isCollidingPosition(boundingBox, viewport, false, 0, false, this)) + if (this.currentLocation == null || !this.currentLocation.isCollidingPosition(boundingBox, viewport, false, 0, false, this)) { this.position.X += this.xVelocity; this.position.Y -= this.yVelocity; } - this.xVelocity = (float)(int)((double)this.xVelocity - (double)this.xVelocity / 2.0); - this.yVelocity = (float)(int)((double)this.yVelocity - (double)this.yVelocity / 2.0); + this.xVelocity = (int)(this.xVelocity - this.xVelocity / 2.0); + this.yVelocity = (int)(this.yVelocity - this.yVelocity / 2.0); } else if (this.moveUp) { - if (currentLocation == null || !currentLocation.isCollidingPosition(this.nextPosition(0), viewport, false, 0, false, this) || this.isCharging) + if (this.currentLocation == null || !this.currentLocation.isCollidingPosition(this.nextPosition(0), viewport, false, 0, false, this) || this.isCharging) { - this.position.Y -= (float)(this.speed + this.addedSpeed); + this.position.Y -= this.speed + this.addedSpeed; if (!this.ignoreMovementAnimation) { this.spriteInformation.setUp(this); - this.characterRenderer.Animate(interval,true); + this.characterRenderer.Animate(interval); //this.sprite.AnimateUp(time, (this.speed - 2 + this.addedSpeed) * -25, Utility.isOnScreen(this.getTileLocationPoint(), 1, currentLocation) ? "Cowboy_Footstep" : ""); this.faceDirection(0); } } - else if (!currentLocation.isTilePassable(this.nextPosition(0), viewport) || !this.willDestroyObjectsUnderfoot) + else if (!this.currentLocation.isTilePassable(this.nextPosition(0), viewport) || !this.willDestroyObjectsUnderfoot) this.Halt(); else if (this.willDestroyObjectsUnderfoot) { - Vector2 vector2 = new Vector2((float)(this.getStandingX() / Game1.tileSize), (float)(this.getStandingY() / Game1.tileSize - 1)); - if (currentLocation.characterDestroyObjectWithinRectangle(this.nextPosition(0), true)) + Vector2 vector2 = new Vector2(this.getStandingX() / Game1.tileSize, this.getStandingY() / Game1.tileSize - 1); + if (this.currentLocation.characterDestroyObjectWithinRectangle(this.nextPosition(0), true)) { - this.doEmote(12, true); - this.position.Y -= (float)(this.speed + this.addedSpeed); + this.doEmote(12); + this.position.Y -= this.speed + this.addedSpeed; } else this.blockedInterval = this.blockedInterval + time.ElapsedGameTime.Milliseconds; @@ -353,27 +273,27 @@ namespace CustomNPCFramework.Framework.NPCS } else if (this.moveRight) { - if (currentLocation == null || !currentLocation.isCollidingPosition(this.nextPosition(1), viewport, false, 0, false, this) || this.isCharging) + if (this.currentLocation == null || !this.currentLocation.isCollidingPosition(this.nextPosition(1), viewport, false, 0, false, this) || this.isCharging) { - this.position.X += (float)(this.speed + this.addedSpeed); + this.position.X += this.speed + this.addedSpeed; if (!this.ignoreMovementAnimation) { this.spriteInformation.setRight(this); - this.characterRenderer.Animate(interval,true); + this.characterRenderer.Animate(interval); //this.spriteInformation.sprite.Animate(time, 0, 3, 1f); //this.sprite.AnimateRight(time, (this.speed - 2 + this.addedSpeed) * -25, Utility.isOnScreen(this.getTileLocationPoint(), 1, currentLocation) ? "Cowboy_Footstep" : ""); this.faceDirection(1); } } - else if (!currentLocation.isTilePassable(this.nextPosition(1), viewport) || !this.willDestroyObjectsUnderfoot) + else if (!this.currentLocation.isTilePassable(this.nextPosition(1), viewport) || !this.willDestroyObjectsUnderfoot) this.Halt(); else if (this.willDestroyObjectsUnderfoot) { - Vector2 vector2 = new Vector2((float)(this.getStandingX() / Game1.tileSize + 1), (float)(this.getStandingY() / Game1.tileSize)); - if (currentLocation.characterDestroyObjectWithinRectangle(this.nextPosition(1), true)) + Vector2 vector2 = new Vector2(this.getStandingX() / Game1.tileSize + 1, this.getStandingY() / Game1.tileSize); + if (this.currentLocation.characterDestroyObjectWithinRectangle(this.nextPosition(1), true)) { - this.doEmote(12, true); - this.position.X += (float)(this.speed + this.addedSpeed); + this.doEmote(12); + this.position.X += this.speed + this.addedSpeed; } else this.blockedInterval = this.blockedInterval + time.ElapsedGameTime.Milliseconds; @@ -381,27 +301,27 @@ namespace CustomNPCFramework.Framework.NPCS } else if (this.moveDown) { - if (currentLocation == null || !currentLocation.isCollidingPosition(this.nextPosition(2), viewport, false, 0, false, this) || this.isCharging) + if (this.currentLocation == null || !this.currentLocation.isCollidingPosition(this.nextPosition(2), viewport, false, 0, false, this) || this.isCharging) { - this.position.Y += (float)(this.speed + this.addedSpeed); + this.position.Y += this.speed + this.addedSpeed; if (!this.ignoreMovementAnimation) { this.spriteInformation.setDown(this); - this.characterRenderer.Animate(interval,true); + this.characterRenderer.Animate(interval); //this.spriteInformation.sprite.Animate(time, 0, 3, 1f); //this.sprite.AnimateDown(time, (this.speed - 2 + this.addedSpeed) * -25, Utility.isOnScreen(this.getTileLocationPoint(), 1, currentLocation) ? "Cowboy_Footstep" : ""); this.faceDirection(2); } } - else if (!currentLocation.isTilePassable(this.nextPosition(2), viewport) || !this.willDestroyObjectsUnderfoot) + else if (!this.currentLocation.isTilePassable(this.nextPosition(2), viewport) || !this.willDestroyObjectsUnderfoot) this.Halt(); else if (this.willDestroyObjectsUnderfoot) { - Vector2 vector2 = new Vector2((float)(this.getStandingX() / Game1.tileSize), (float)(this.getStandingY() / Game1.tileSize + 1)); - if (currentLocation.characterDestroyObjectWithinRectangle(this.nextPosition(2), true)) + Vector2 vector2 = new Vector2(this.getStandingX() / Game1.tileSize, this.getStandingY() / Game1.tileSize + 1); + if (this.currentLocation.characterDestroyObjectWithinRectangle(this.nextPosition(2), true)) { - this.doEmote(12, true); - this.position.Y += (float)(this.speed + this.addedSpeed); + this.doEmote(12); + this.position.Y += this.speed + this.addedSpeed; } else this.blockedInterval = this.blockedInterval + time.ElapsedGameTime.Milliseconds; @@ -409,35 +329,35 @@ namespace CustomNPCFramework.Framework.NPCS } else if (this.moveLeft) { - if (currentLocation == null || !currentLocation.isCollidingPosition(this.nextPosition(3), viewport, false, 0, false, this) || this.isCharging) + if (this.currentLocation == null || !this.currentLocation.isCollidingPosition(this.nextPosition(3), viewport, false, 0, false, this) || this.isCharging) { - this.position.X -= (float)(this.speed + this.addedSpeed); + this.position.X -= this.speed + this.addedSpeed; if (!this.ignoreMovementAnimation) { this.spriteInformation.setLeft(this); - this.characterRenderer.Animate(interval,true); + this.characterRenderer.Animate(interval); //this.spriteInformation.sprite.Animate(time, 0, 3, 1f); //this.sprite.AnimateLeft(time, (this.speed - 2 + this.addedSpeed) * -25, Utility.isOnScreen(this.getTileLocationPoint(), 1, currentLocation) ? "Cowboy_Footstep" : ""); this.faceDirection(3); } } - else if (!currentLocation.isTilePassable(this.nextPosition(3), viewport) || !this.willDestroyObjectsUnderfoot) + else if (!this.currentLocation.isTilePassable(this.nextPosition(3), viewport) || !this.willDestroyObjectsUnderfoot) this.Halt(); else if (this.willDestroyObjectsUnderfoot) { - Vector2 vector2 = new Vector2((float)(this.getStandingX() / Game1.tileSize - 1), (float)(this.getStandingY() / Game1.tileSize)); - if (currentLocation.characterDestroyObjectWithinRectangle(this.nextPosition(3), true)) + Vector2 vector2 = new Vector2(this.getStandingX() / Game1.tileSize - 1, this.getStandingY() / Game1.tileSize); + if (this.currentLocation.characterDestroyObjectWithinRectangle(this.nextPosition(3), true)) { - this.doEmote(12, true); - this.position.X -= (float)(this.speed + this.addedSpeed); + this.doEmote(12); + this.position.X -= this.speed + this.addedSpeed; } else this.blockedInterval = this.blockedInterval + time.ElapsedGameTime.Milliseconds; } } - if (this.blockedInterval >= 3000 && (double)this.blockedInterval <= 3750.0 && !Game1.eventUp) + if (this.blockedInterval >= 3000 && this.blockedInterval <= 3750.0 && !Game1.eventUp) { - this.doEmote(Game1.random.NextDouble() < 0.5 ? 8 : 40, true); + this.doEmote(Game1.random.NextDouble() < 0.5 ? 8 : 40); this.blockedInterval = 3750; } else @@ -450,33 +370,15 @@ namespace CustomNPCFramework.Framework.NPCS } } - /// - /// Used to halt the npc sprite. Sets the npc's animation to the standing animation if the character renderer is not null. - /// + /// Used to halt the npc sprite. Sets the npc's animation to the standing animation if the character renderer is not null. public override void Halt() { - if (this.characterRenderer != null) - { - this.characterRenderer.setAnimation(AnimationKeys.standingKey); - } + this.characterRenderer?.setAnimation(AnimationKeys.standingKey); base.Halt(); } - /// - /// Used to update npc information. - /// - /// - /// - public override void update(GameTime time, GameLocation location) - { - base.update(time, location); - } - - /// - /// Pathfinding code. - /// - /// - public virtual void routeEndAnimationFinished(StardewValley.Farmer who) + /// Pathfinding code. + public virtual void routeEndAnimationFinished(Farmer who) { this.doingEndOfRouteAnimation.Value = false; this.freezeMotion = false; @@ -493,26 +395,15 @@ namespace CustomNPCFramework.Framework.NPCS this.timeAfterSquare = Game1.timeOfDay; } - /// - /// Pathfinding code. - /// - /// - /// - public virtual void doAnimationAtEndOfScheduleRoute(Character c, GameLocation l) - { - } + /// Pathfinding code. + public virtual void doAnimationAtEndOfScheduleRoute(Character c, GameLocation l) { } - /// - /// Pathfinding code. - /// - /// + /// Pathfinding code. public virtual void startRouteBehavior(string behaviorName) { if (behaviorName.Length > 0 && (int)behaviorName[0] == 34) - { this.endOfRouteMessage.Value = behaviorName.Replace("\"", ""); - } else { if (behaviorName.Contains("square_")) @@ -524,24 +415,20 @@ namespace CustomNPCFramework.Framework.NPCS } else { - Utility.getGameLocationOfCharacter(this).temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Microsoft.Xna.Framework.Rectangle(167, 1714, 19, 14), 100f, 3, 999999, new Vector2(2f, 3f) * (float)Game1.tileSize + new Vector2(7f, 12f) * (float)Game1.pixelZoom, false, false, 0.0002f, 0.0f, Color.White, (float)Game1.pixelZoom, 0.0f, 0.0f, 0.0f, false) + Utility.getGameLocationOfCharacter(this).temporarySprites.Add(new TemporaryAnimatedSprite("LooseSprites\\Cursors", new Microsoft.Xna.Framework.Rectangle(167, 1714, 19, 14), 100f, 3, 999999, new Vector2(2f, 3f) * (float)Game1.tileSize + new Vector2(7f, 12f) * (float)Game1.pixelZoom, false, false, 0.0002f, 0.0f, Color.White, (float)Game1.pixelZoom, 0.0f, 0.0f, 0.0f) { id = 688f }); - this.doEmote(52, true); + this.doEmote(52); } } } - /// - /// Occurs when the npc gets hit by the player. - /// - /// - /// + /// Occurs when the npc gets hit by the player. public new void getHitByPlayer(StardewValley.Farmer who, GameLocation location) { - this.doEmote(12, true); + this.doEmote(12); if (who == null) { if (Game1.IsMultiplayer) @@ -550,8 +437,7 @@ namespace CustomNPCFramework.Framework.NPCS } if (who.friendshipData.ContainsKey(this.Name)) { - Friendship f; - who.friendshipData.TryGetValue(this.Name, out f); + who.friendshipData.TryGetValue(this.Name, out Friendship f); f.Points -= 30; if (who.IsMainPlayer) { @@ -570,7 +456,7 @@ namespace CustomNPCFramework.Framework.NPCS public override void dayUpdate(int dayOfMonth) { if (this.currentLocation != null) - Game1.warpCharacter(this, this.DefaultMap, this.DefaultPosition / (float)Game1.tileSize); + Game1.warpCharacter(this, this.DefaultMap, this.DefaultPosition / Game1.tileSize); Game1.player.mailReceived.Remove(this.Name); Game1.player.mailReceived.Remove(this.Name + "Cooking"); this.doingEndOfRouteAnimation.Value = false; @@ -582,18 +468,18 @@ namespace CustomNPCFramework.Framework.NPCS this.hasSaidAfternoonDialogue = false; this.ignoreScheduleToday = false; this.Halt(); - this.controller = (PathFindController)null; - this.temporaryController = (PathFindController)null; - this.DirectionsToNewLocation = (SchedulePathDescription)null; + this.controller = null; + this.temporaryController = null; + this.DirectionsToNewLocation = null; this.faceDirection(this.DefaultFacingDirection); this.scheduleTimeToTry = 9999999; this.previousEndPoint = new Point((int)this.DefaultPosition.X / Game1.tileSize, (int)this.DefaultPosition.Y / Game1.tileSize); this.IsWalkingInSquare = false; this.returningToEndPoint = false; - this.lastCrossroad = Microsoft.Xna.Framework.Rectangle.Empty; + this.lastCrossroad = Rectangle.Empty; if (this.isVillager()) this.Schedule = this.getSchedule(dayOfMonth); - this.endOfRouteMessage.Value = (string)null; + this.endOfRouteMessage.Value = null; bool flag = Utility.isFestivalDay(dayOfMonth, Game1.currentSeason); if (!this.isMarried()) return; @@ -602,18 +488,10 @@ namespace CustomNPCFramework.Framework.NPCS //this.daysMarried = this.daysMarried + 1; } - /// - /// Does effectively nothing. - /// - public new void setUpForOutdoorPatioActivity() - { - } + /// Does effectively nothing. + public new void setUpForOutdoorPatioActivity() { } - /// - /// Used to draw the npc with the custom renderer. - /// - /// - /// + /// Used to draw the npc with the custom renderer. public virtual void drawModular(SpriteBatch b, float alpha = 1f) { if (this.characterRenderer == null || this.IsInvisible || !Utility.isOnScreen(this.position, 2 * Game1.tileSize)) @@ -623,7 +501,7 @@ namespace CustomNPCFramework.Framework.NPCS { this.characterRenderer.setAnimation(AnimationKeys.swimmingKey); this.characterRenderer.setDirection(this.facingDirection); - this.characterRenderer.draw(b,this,this.getLocalPosition(Game1.viewport) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize + Game1.tileSize / 4 + this.yJumpOffset * 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero) - new Vector2(0.0f, this.yOffset), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(this.Sprite.SourceRect.X, this.Sprite.SourceRect.Y, this.Sprite.SourceRect.Width, this.Sprite.SourceRect.Height / 2 - (int)((double)this.yOffset / (double)Game1.pixelZoom))), Color.White, this.rotation, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 3 / 2)) / 4f, Math.Max(0.2f, this.Scale) * (float)Game1.pixelZoom, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, (float)this.getStandingY() / 10000f)); + this.characterRenderer.draw(b, this, this.getLocalPosition(Game1.viewport) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize + Game1.tileSize / 4 + this.yJumpOffset * 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero) - new Vector2(0.0f, this.yOffset), new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(this.Sprite.SourceRect.X, this.Sprite.SourceRect.Y, this.Sprite.SourceRect.Width, this.Sprite.SourceRect.Height / 2 - (int)((double)this.yOffset / (double)Game1.pixelZoom))), Color.White, this.rotation, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 3 / 2)) / 4f, Math.Max(0.2f, this.Scale) * (float)Game1.pixelZoom, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, (float)this.getStandingY() / 10000f)); //Vector2 localPosition = this.getLocalPosition(Game1.viewport); //b.Draw(Game1.staminaRect, new Microsoft.Xna.Framework.Rectangle((int)localPosition.X + (int)this.yOffset + Game1.pixelZoom * 2, (int)localPosition.Y - 32 * Game1.pixelZoom + this.sprite.SourceRect.Height * Game1.pixelZoom + Game1.tileSize * 3 / 4 + this.yJumpOffset * 2 - (int)this.yOffset, this.sprite.SourceRect.Width * Game1.pixelZoom - (int)this.yOffset * 2 - Game1.pixelZoom * 4, Game1.pixelZoom), new Microsoft.Xna.Framework.Rectangle?(Game1.staminaRect.Bounds), Color.White * 0.75f, 0.0f, Vector2.Zero, SpriteEffects.None, (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0)); } @@ -655,7 +533,7 @@ namespace CustomNPCFramework.Framework.NPCS sourceRect.Height /= 2; } //The actual character drawing to the screen? - this.characterRenderer.draw(b, this, this.getLocalPosition(Game1.viewport) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(sourceRect), Color.White * alpha, this.rotation,Vector2.Zero, Math.Max(0.2f, this.Scale), this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.992f : (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0))); + this.characterRenderer.draw(b, this, this.getLocalPosition(Game1.viewport) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(sourceRect), Color.White * alpha, this.rotation, Vector2.Zero, Math.Max(0.2f, this.Scale), this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.992f : (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0))); //this.characterRenderer.draw(b,this, this.getLocalPosition(Game1.viewport) + vector2 + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(sourceRect), Color.White * alpha, this.rotation, new Vector2((float)(sourceRect.Width / 2), (float)(sourceRect.Height / 2 + 1)), Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom + num, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.992f : (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0))); //this.characterRenderer.draw(b, this, this.getLocalPosition(Game1.viewport) + vector2 + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(sourceRect), Color.White * alpha, this.rotation, new Vector2((float)(sourceRect.Width / 2), (float)(sourceRect.Height / 2 + 1)), Math.Max(0.2f, this.scale) * (float)Game1.pixelZoom + num, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, .99f); } @@ -667,7 +545,7 @@ namespace CustomNPCFramework.Framework.NPCS //Checks if the npc is glowing. if (this.isGlowing) - this.characterRenderer.draw(b,this, this.getLocalPosition(Game1.viewport) + new Vector2((float)(this.Sprite.SpriteWidth * Game1.pixelZoom / 2), (float)(this.GetBoundingBox().Height / 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(this.Sprite.SourceRect), this.glowingColor * this.glowingTransparency, this.rotation, new Vector2((float)(this.Sprite.SpriteWidth / 2), (float)((double)this.Sprite.SpriteHeight * 3.0 / 4.0)), Math.Max(0.2f, this.Scale) * 4f, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.99f : (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0))); + this.characterRenderer.draw(b, this, this.getLocalPosition(Game1.viewport) + new Vector2((float)(this.Sprite.SpriteWidth * Game1.pixelZoom / 2), (float)(this.GetBoundingBox().Height / 2)) + (this.shakeTimer > 0 ? new Vector2((float)Game1.random.Next(-1, 2), (float)Game1.random.Next(-1, 2)) : Vector2.Zero), new Microsoft.Xna.Framework.Rectangle?(this.Sprite.SourceRect), this.glowingColor * this.glowingTransparency, this.rotation, new Vector2((float)(this.Sprite.SpriteWidth / 2), (float)((double)this.Sprite.SpriteHeight * 3.0 / 4.0)), Math.Max(0.2f, this.Scale) * 4f, this.flip ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0.0f, this.drawOnTop ? 0.99f : (float)((double)this.getStandingY() / 10000.0 + 1.0 / 1000.0))); //This code runs if the npc is emoting. if (!this.IsEmoting || Game1.eventUp) @@ -677,9 +555,7 @@ namespace CustomNPCFramework.Framework.NPCS b.Draw(Game1.emoteSpriteSheet, localPosition1, new Microsoft.Xna.Framework.Rectangle?(new Microsoft.Xna.Framework.Rectangle(this.CurrentEmoteIndex * 16 % Game1.emoteSpriteSheet.Width, this.CurrentEmoteIndex * 16 / Game1.emoteSpriteSheet.Width * 16, 16, 16)), Color.White, 0.0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, (float)this.getStandingY() / 10000f); } - /// - /// Used to draw the sprite without the modular npc renderer - /// + /// Used to draw the sprite without the modular npc renderer /// /// public virtual void drawNonModularSprite(SpriteBatch b, float alpha = 1f) @@ -728,9 +604,7 @@ namespace CustomNPCFramework.Framework.NPCS } - /// - /// Basic draw functionality to checkn whether or not to draw the npc using it's default sprite or using a custom character renderer. - /// + /// Basic draw functionality to checkn whether or not to draw the npc using it's default sprite or using a custom character renderer. /// /// public override void draw(SpriteBatch b, float alpha = 1f) diff --git a/GeneralMods/CustomNPCFramework/Framework/NPCS/MerchantNPC.cs b/GeneralMods/CustomNPCFramework/Framework/NPCS/MerchantNPC.cs index 457523cc..34433679 100644 --- a/GeneralMods/CustomNPCFramework/Framework/NPCS/MerchantNPC.cs +++ b/GeneralMods/CustomNPCFramework/Framework/NPCS/MerchantNPC.cs @@ -1,56 +1,41 @@ -using CustomNPCFramework.Framework.ModularNPCS; -using CustomNPCFramework.Framework.ModularNPCS.ModularRenderers; +using System.Collections.Generic; +using CustomNPCFramework.Framework.ModularNpcs; +using CustomNPCFramework.Framework.ModularNpcs.ModularRenderers; using Microsoft.Xna.Framework; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CustomNPCFramework.Framework.NPCS { - /// - /// Extended merchant npc from ExtendedNPC. - /// - class MerchantNPC: ExtendedNPC + /// Extended merchant npc from ExtendedNPC. + class MerchantNpc : ExtendedNpc { - /// - /// Thelist of items this npc has for sale. - /// + /// The list of items this npc has for sale. public List stock; - /// - /// Constructor. - /// + + /// Construct an instance. /// The list of items this npc will sell. /// The sprite for the npc to use. /// The renderer for the npc to use. /// The position for the npc to use. /// The facing direction for the player to face. /// The name for the npc. - public MerchantNPC(List Stock, Sprite sprite, BasicRenderer renderer,Vector2 position,int facingDirection,string name): base(sprite,renderer,position,facingDirection,name) + public MerchantNpc(List Stock, Sprite sprite, BasicRenderer renderer, Vector2 position, int facingDirection, string name) + : base(sprite, renderer, position, facingDirection, name) { this.stock = Stock; } - - /// - /// Constructor. - /// + /// Construct an instance. /// The list of items for the npc to sell. /// The npc base for the character to be expanded upon. - public MerchantNPC(List Stock, ExtendedNPC npcBase) : base(npcBase.spriteInformation, npcBase.characterRenderer, npcBase.portraitInformation, npcBase.position, npcBase.facingDirection, npcBase.Name) + public MerchantNpc(List Stock, ExtendedNpc npcBase) + : base(npcBase.spriteInformation, npcBase.characterRenderer, npcBase.portraitInformation, npcBase.position, npcBase.facingDirection, npcBase.Name) { this.stock = Stock; } - /// - /// Used to interact with the npc. When interacting pulls up a shop menu for the npc with their current stock. - /// - /// - /// - /// - public override bool checkAction(StardewValley.Farmer who, GameLocation l) + /// Used to interact with the npc. When interacting pulls up a shop menu for the npc with their current stock. + public override bool checkAction(Farmer who, GameLocation l) { if (Game1.activeClickableMenu == null) { diff --git a/GeneralMods/CustomNPCFramework/Framework/Utilities/NPCTracker.cs b/GeneralMods/CustomNPCFramework/Framework/Utilities/NPCTracker.cs index 4240bd0d..571aca1c 100644 --- a/GeneralMods/CustomNPCFramework/Framework/Utilities/NPCTracker.cs +++ b/GeneralMods/CustomNPCFramework/Framework/Utilities/NPCTracker.cs @@ -1,89 +1,64 @@ -using CustomNPCFramework.Framework.NPCS; +using System.Collections.Generic; +using CustomNPCFramework.Framework.NPCS; using Microsoft.Xna.Framework; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace CustomNPCFramework.Framework.Utilities { - /// - /// Used to keep track of all of the custom npcs. - /// - public class NPCTracker + /// Used to keep track of all of the custom npcs. + public class NpcTracker { - /// - /// A list used to keep track of the npcs. - /// - public List moddedNPCS; + /// A list used to keep track of the npcs. + public List moddedNpcs; - /// - /// Constructor. - /// - public NPCTracker() + /// Construct an instance. + public NpcTracker() { - this.moddedNPCS = new List(); + this.moddedNpcs = new List(); } - /// - /// Use this to add a new npc into the game. - /// + /// Use this to add a new npc into the game. /// The game location to add the npc to. /// The extended npc to add to the location. - public void addNewNPCToLocation(GameLocation loc,ExtendedNPC npc) + public void addNewNpcToLocation(GameLocation loc, ExtendedNpc npc) { - this.moddedNPCS.Add(npc); + this.moddedNpcs.Add(npc); npc.defaultLocation = loc; npc.currentLocation = loc; loc.addCharacter(npc); } - /// - /// Add a npc to a location. - /// + /// Add a npc to a location. /// The game location to add an npc to. /// The extended npc to add to the location. /// The tile position at the game location to add the mpc to. - public void addNewNPCToLocation(GameLocation loc, ExtendedNPC npc, Vector2 tilePosition) + public void addNewNpcToLocation(GameLocation loc, ExtendedNpc npc, Vector2 tilePosition) { - this.moddedNPCS.Add(npc); + this.moddedNpcs.Add(npc); npc.defaultLocation = loc; npc.currentLocation = loc; - npc.position.Value = tilePosition*Game1.tileSize; + npc.position.Value = tilePosition * Game1.tileSize; loc.addCharacter(npc); } - /// - /// Use this simply to remove a single npc from a location. - /// - /// - /// - public void removeCharacterFromLocation(GameLocation loc, ExtendedNPC npc) + /// Use this simply to remove a single npc from a location. + public void removeCharacterFromLocation(GameLocation loc, ExtendedNpc npc) { loc.characters.Remove(npc); } - - /// - /// Use this to completly remove and npc from the game as it is removed from the location and is no longer tracked. - /// + + /// Use this to completly remove and npc from the game as it is removed from the location and is no longer tracked. /// The npc to remove from the location. - public void removeFromLocationAndTrackingList(ExtendedNPC npc) + public void removeFromLocationAndTrackingList(ExtendedNpc npc) { - if (npc.currentLocation != null) - { - npc.currentLocation.characters.Remove(npc); - } - this.moddedNPCS.Remove(npc); + npc.currentLocation?.characters.Remove(npc); + this.moddedNpcs.Remove(npc); } - /// - /// Use this to clean up all of the npcs before the game is saved. - /// + /// Use this to clean up all of the npcs before the game is saved. public void cleanUpBeforeSave() { - foreach(ExtendedNPC npc in this.moddedNPCS) + foreach (ExtendedNpc npc in this.moddedNpcs) { //npc.currentLocation.characters.Remove(npc); //Game1.removeThisCharacterFromAllLocations(npc); @@ -91,19 +66,13 @@ namespace CustomNPCFramework.Framework.Utilities Class1.ModMonitor.Log("Removed an npc!"); //Do some saving code here. } - } - /// - /// Use this to load in all of the npcs again after saving. - /// + /// Use this to load in all of the npcs again after saving. public void afterSave() { - foreach(ExtendedNPC npc in this.moddedNPCS) - { + foreach (ExtendedNpc npc in this.moddedNpcs) npc.defaultLocation.addCharacter(npc); - } } - } } diff --git a/GeneralMods/CustomNPCFramework/manifest.json b/GeneralMods/CustomNPCFramework/manifest.json index 56346973..0aec6403 100644 --- a/GeneralMods/CustomNPCFramework/manifest.json +++ b/GeneralMods/CustomNPCFramework/manifest.json @@ -6,5 +6,5 @@ "UniqueID": "Omegasis.CustomNPCFramework", "EntryDll": "CustomNPCFramework.dll", "MinimumApiVersion": "2.0", - "UpdateKeys": [ ] + "UpdateKeys": [] } diff --git a/GeneralMods/CustomNPCFramework/packages.config b/GeneralMods/CustomNPCFramework/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/CustomNPCFramework/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/DailyQuestAnywhere/DailyQuestAnywhere.cs b/GeneralMods/DailyQuestAnywhere/DailyQuestAnywhere.cs index 0be9151e..e8e4fe99 100644 --- a/GeneralMods/DailyQuestAnywhere/DailyQuestAnywhere.cs +++ b/GeneralMods/DailyQuestAnywhere/DailyQuestAnywhere.cs @@ -1,17 +1,16 @@ -using Omegasis.DailyQuestAnywhere.Framework; +using System; +using Omegasis.DailyQuestAnywhere.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; using StardewValley.Menus; using StardewValley.Quests; -using System; namespace Omegasis.DailyQuestAnywhere { /* *TODO: Make quest core mod??? */ - /// The mod entry point. public class DailyQuestAnywhere : Mod { @@ -34,12 +33,10 @@ namespace Omegasis.DailyQuestAnywhere this.Config = helper.ReadConfig(); ControlEvents.KeyPressed += this.ControlEvents_KeyPressed; - StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave; + SaveEvents.AfterSave += this.SaveEvents_AfterSave; } - - /********* ** Private methods *********/ @@ -49,31 +46,26 @@ namespace Omegasis.DailyQuestAnywhere private void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e) { if (Context.IsPlayerFree && e.KeyPressed.ToString() == this.Config.KeyBinding) - if (Game1.player.hasDailyQuest() == false ) + if (!Game1.player.hasDailyQuest()) { if (this.dailyQuest == null) { - this.dailyQuest = generateDailyQuest(); + this.dailyQuest = this.generateDailyQuest(); } Game1.questOfTheDay = this.dailyQuest; Game1.activeClickableMenu = new Billboard(true); - } + } } - /// - /// Makes my daily quest referene null so we can't just keep getting a new reference. - /// - /// - /// + /// Makes my daily quest referene null so we can't just keep getting a new reference. + /// The event sender. + /// The event data. private void SaveEvents_AfterSave(object sender, System.EventArgs e) { this.dailyQuest = null; //Nullify my quest reference. } - /// - /// Generate a daily quest for sure. - /// - /// + /// Generate a daily quest for sure. public Quest generateDailyQuest() { @@ -82,18 +74,27 @@ namespace Omegasis.DailyQuestAnywhere float actualChance = chance / 100; //If we hit the chance for actually generating a daily quest do so, otherwise don't generate a daily quest. - if (actualChance <= Config.chanceForDailyQuest) + if (actualChance <= this.Config.chanceForDailyQuest) { Random r = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed); int rand = r.Next(0, 7); - - if (rand == 0) return new ItemDeliveryQuest(); - if (rand == 1) return new FishingQuest(); - if (rand == 2) return new StardewValley.Quests.CraftingQuest(); - if (rand == 3) return new StardewValley.Quests.ItemDeliveryQuest(); - if (rand == 4) return new StardewValley.Quests.ItemHarvestQuest(); - if (rand == 5) return new StardewValley.Quests.ResourceCollectionQuest(); - if (rand == 6) return new StardewValley.Quests.SlayMonsterQuest(); + switch (rand) + { + case 0: + return new ItemDeliveryQuest(); + case 1: + return new FishingQuest(); + case 2: + return new StardewValley.Quests.CraftingQuest(); + case 3: + return new StardewValley.Quests.ItemDeliveryQuest(); + case 4: + return new StardewValley.Quests.ItemHarvestQuest(); + case 5: + return new StardewValley.Quests.ResourceCollectionQuest(); + case 6: + return new StardewValley.Quests.SlayMonsterQuest(); + } } return null; //This should never happen. } diff --git a/GeneralMods/DailyQuestAnywhere/DailyQuestAnywhere.csproj b/GeneralMods/DailyQuestAnywhere/DailyQuestAnywhere.csproj index 2d0790fc..13cf5c50 100644 --- a/GeneralMods/DailyQuestAnywhere/DailyQuestAnywhere.csproj +++ b/GeneralMods/DailyQuestAnywhere/DailyQuestAnywhere.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ DailyQuestAnywhere v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -83,19 +84,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/DailyQuestAnywhere/Framework/ModConfig.cs b/GeneralMods/DailyQuestAnywhere/Framework/ModConfig.cs index a6f01664..a88ee0fe 100644 --- a/GeneralMods/DailyQuestAnywhere/Framework/ModConfig.cs +++ b/GeneralMods/DailyQuestAnywhere/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.DailyQuestAnywhere.Framework +namespace Omegasis.DailyQuestAnywhere.Framework { /// The mod configuration. internal class ModConfig @@ -6,9 +6,7 @@ /// The key which shows the menu. public string KeyBinding { get; set; } = "H"; - /// - /// The chance for a daily quest to actually happen. - /// + /// The chance for a daily quest to actually happen. public float chanceForDailyQuest { get; set; } = .75f; } } diff --git a/GeneralMods/DailyQuestAnywhere/packages.config b/GeneralMods/DailyQuestAnywhere/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/DailyQuestAnywhere/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/Fall28SnowDay/Fall28SnowDay.cs b/GeneralMods/Fall28SnowDay/Fall28SnowDay.cs index 58d7f373..00b042d6 100644 --- a/GeneralMods/Fall28SnowDay/Fall28SnowDay.cs +++ b/GeneralMods/Fall28SnowDay/Fall28SnowDay.cs @@ -1,4 +1,4 @@ -using System; +using System; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; diff --git a/GeneralMods/Fall28SnowDay/Fall28SnowDay.csproj b/GeneralMods/Fall28SnowDay/Fall28SnowDay.csproj index e0b9c753..23b5bc04 100644 --- a/GeneralMods/Fall28SnowDay/Fall28SnowDay.csproj +++ b/GeneralMods/Fall28SnowDay/Fall28SnowDay.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ Fall28SnowDay v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -82,19 +83,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/Fall28SnowDay/packages.config b/GeneralMods/Fall28SnowDay/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/Fall28SnowDay/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/FarmersMarketStall/Class1.cs b/GeneralMods/FarmersMarketStall/Class1.cs index 036a74a5..6d4e3138 100644 --- a/GeneralMods/FarmersMarketStall/Class1.cs +++ b/GeneralMods/FarmersMarketStall/Class1.cs @@ -1,17 +1,12 @@ -using EventSystem.Framework.FunctionEvents; +using System; +using EventSystem.Framework.FunctionEvents; using FarmersMarketStall.Framework.MapEvents; using Microsoft.Xna.Framework; using StardewModdingAPI; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace FarmersMarketStall { - /// /// TODO: /// Make a farmers market menu @@ -21,21 +16,21 @@ namespace FarmersMarketStall /// Make a selling menu /// Make a minigame event for bonus money to earn. /// - /// - - public class Class1 :Mod + public class Class1 : Mod { - public static IModHelper ModHelper; public static IMonitor ModMonitor; - public static FarmersMarketStall.Framework.MarketStall marketStall; + public static Framework.MarketStall marketStall; + + /// The mod entry point, called after the mod is first loaded. + /// Provides simplified APIs for writing mods. public override void Entry(IModHelper helper) { - ModHelper = Helper; - ModMonitor = Monitor; + ModHelper = this.Helper; + ModMonitor = this.Monitor; - StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave; - StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; + StardewModdingAPI.Events.SaveEvents.BeforeSave += this.SaveEvents_BeforeSave; + StardewModdingAPI.Events.SaveEvents.AfterLoad += this.SaveEvents_AfterLoad; marketStall = new Framework.MarketStall(); } @@ -46,7 +41,8 @@ namespace FarmersMarketStall private void SaveEvents_BeforeSave(object sender, EventArgs e) { - if (marketStall.stock.Count > 0) { + if (marketStall.stock.Count > 0) + { // Game1.endOfNightMenus.Push(new StardewValley.Menus.ShippingMenu(marketStall.stock)); marketStall.sellAllItems(); } diff --git a/GeneralMods/FarmersMarketStall/FarmersMarketStall.csproj b/GeneralMods/FarmersMarketStall/FarmersMarketStall.csproj index c2b0dbbc..d77edb4c 100644 --- a/GeneralMods/FarmersMarketStall/FarmersMarketStall.csproj +++ b/GeneralMods/FarmersMarketStall/FarmersMarketStall.csproj @@ -11,8 +11,6 @@ FarmersMarketStall v4.6.1 512 - - true @@ -68,9 +66,9 @@ MinimumRecommendedRules.ruleset - - ..\MapEvents\bin\Release\EventSystem.dll - + + + @@ -88,17 +86,13 @@ - + + {bb737337-2d82-4245-aa46-f3b82fc6f228} + EventSystem + - + - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/FarmersMarketStall/Framework/MapEvents/ShopInteractionEvent.cs b/GeneralMods/FarmersMarketStall/Framework/MapEvents/ShopInteractionEvent.cs index 25fbd4b1..7ee285b6 100644 --- a/GeneralMods/FarmersMarketStall/Framework/MapEvents/ShopInteractionEvent.cs +++ b/GeneralMods/FarmersMarketStall/Framework/MapEvents/ShopInteractionEvent.cs @@ -1,18 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using EventSystem; using EventSystem.Framework.FunctionEvents; using Microsoft.Xna.Framework; using StardewValley; namespace FarmersMarketStall.Framework.MapEvents { - public class ShopInteractionEvent :EventSystem.Framework.MapEvent + public class ShopInteractionEvent : EventSystem.Framework.MapEvent { - public ShopInteractionEvent(string Name, GameLocation Location, Vector2 Position, MouseButtonEvents MouseEvents, MouseEntryLeaveEvent EntryLeave) : base(Name, Location, Position) + public ShopInteractionEvent(string Name, GameLocation Location, Vector2 Position, MouseButtonEvents MouseEvents, MouseEntryLeaveEvent EntryLeave) + : base(Name, Location, Position) { this.name = Name; this.location = Location; @@ -24,18 +19,17 @@ namespace FarmersMarketStall.Framework.MapEvents this.mouseEntryLeaveEvents = EntryLeave; } - public override bool OnLeftClick() { - if (base.OnLeftClick() == false) return false; - if (this.location.isObjectAt((int)this.tilePosition.X * Game1.tileSize, (int)this.tilePosition.Y * Game1.tileSize)) return false; + if (!base.OnLeftClick()) + return false; + if (this.location.isObjectAt((int)this.tilePosition.X * Game1.tileSize, (int)this.tilePosition.Y * Game1.tileSize)) + return false; Game1.activeClickableMenu = Menus.MarketStallMenu.openMenu(Class1.marketStall); return true; } - /// - /// Used to update the event and check for interaction. - /// + /// Used to update the event and check for interaction. public override void update() { this.clickEvent(); @@ -43,6 +37,5 @@ namespace FarmersMarketStall.Framework.MapEvents this.OnMouseEnter(); this.OnMouseLeave(); } - } } diff --git a/GeneralMods/FarmersMarketStall/Framework/MarketStall.cs b/GeneralMods/FarmersMarketStall/Framework/MarketStall.cs index c043bcf6..5ae3c5e6 100644 --- a/GeneralMods/FarmersMarketStall/Framework/MarketStall.cs +++ b/GeneralMods/FarmersMarketStall/Framework/MarketStall.cs @@ -1,9 +1,5 @@ -using StardewValley; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using StardewValley; namespace FarmersMarketStall.Framework { @@ -11,10 +7,7 @@ namespace FarmersMarketStall.Framework { public List stock; - public MarketStall() - { - - } + public MarketStall() { } public void addItemToSell(Item item) { @@ -28,12 +21,10 @@ namespace FarmersMarketStall.Framework public void sellAllItems() { - foreach(var item in stock) - { - Game1.player.money+=(int)(item.salePrice() * 1.10f); //Replace the multiplier with some sort of level. - } + foreach (var item in this.stock) + Game1.player.money += (int)(item.salePrice() * 1.10f); //Replace the multiplier with some sort of level. + this.stock.Clear(); } - } } diff --git a/GeneralMods/FarmersMarketStall/Framework/Menus/MarketStallMenu.cs b/GeneralMods/FarmersMarketStall/Framework/Menus/MarketStallMenu.cs index 466833db..47b8cecc 100644 --- a/GeneralMods/FarmersMarketStall/Framework/Menus/MarketStallMenu.cs +++ b/GeneralMods/FarmersMarketStall/Framework/Menus/MarketStallMenu.cs @@ -1,10 +1,5 @@ -using StardewValley; -using StardewValley.Menus; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using StardewValley.Menus; namespace FarmersMarketStall.Framework.Menus { @@ -17,9 +12,8 @@ namespace FarmersMarketStall.Framework.Menus public static IClickableMenu openMenu(MarketStall marketStall) { - throw new NotImplementedException("This menu isn't implemented because the author is busy/lazy. Please encorage Omegasis to finish it!",null); + throw new NotImplementedException("This menu isn't implemented because the author is busy/lazy. Please encorage Omegasis to finish it!", null); //return new StardewValley.Menus.InventoryMenu((int)(Game1.viewport.Width*.25f),(int)(Game1.viewport.Height*.25f),true,marketStall.stock); } - } } diff --git a/GeneralMods/FarmersMarketStall/manifest.json b/GeneralMods/FarmersMarketStall/manifest.json index c6ed000c..6cf9b432 100644 --- a/GeneralMods/FarmersMarketStall/manifest.json +++ b/GeneralMods/FarmersMarketStall/manifest.json @@ -6,11 +6,8 @@ "UniqueID": "SunDrop.SunDropMapEvents.FarmersMarketStall", "EntryDll": "FarmersMarketStall.dll", "MinimumApiVersion": "2.0", - "UpdateKeys": [ ], + "UpdateKeys": [], "Dependencies": [ - { - "UniqueID": "Omegasis.EventSystem", - "IsRequired": true - } -] + { "UniqueID": "Omegasis.EventSystem" } + ] } diff --git a/GeneralMods/FarmersMarketStall/packages.config b/GeneralMods/FarmersMarketStall/packages.config deleted file mode 100644 index 84563214..00000000 --- a/GeneralMods/FarmersMarketStall/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/HappyBirthday/BirthdayEvents.cs b/GeneralMods/HappyBirthday/BirthdayEvents.cs index 1d71cd3d..8da384ae 100644 --- a/GeneralMods/HappyBirthday/BirthdayEvents.cs +++ b/GeneralMods/HappyBirthday/BirthdayEvents.cs @@ -1,16 +1,9 @@ -using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using StardewValley; namespace Omegasis.HappyBirthday { - /// - /// TODO:Make all the events - /// Resources:https://stardewvalleywiki.com/Modding:Event_data - /// + // TODO: Make all the events + // Resources:https://stardewvalleywiki.com/Modding:Event_data public class BirthdayEvents { public Event communityCenterJunimoEvent; @@ -21,7 +14,7 @@ namespace Omegasis.HappyBirthday public BirthdayEvents() { - initializeEvents(); + this.initializeEvents(); } public void initializeEvents() @@ -29,7 +22,5 @@ namespace Omegasis.HappyBirthday Event e = new Event("", -1, Game1.player); Game1.player.currentLocation.currentEvent = new Event(); } - - } } diff --git a/GeneralMods/HappyBirthday/BirthdayMessages.cs b/GeneralMods/HappyBirthday/BirthdayMessages.cs index 49c33786..1d31f427 100644 --- a/GeneralMods/HappyBirthday/BirthdayMessages.cs +++ b/GeneralMods/HappyBirthday/BirthdayMessages.cs @@ -1,25 +1,17 @@ -using Newtonsoft.Json; -using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Newtonsoft.Json; namespace Omegasis.HappyBirthday { public class BirthdayMessages { - /// - /// The actual birthday wishes given by an npc. - /// + /// The actual birthday wishes given by an npc. public Dictionary birthdayWishes; public Dictionary spouseBirthdayWishes; - /// - /// TODO: Make this. - /// + // TODO: Make this. public Dictionary defaultSpouseBirthdayWishes = new Dictionary() { ["Alex"] = "", @@ -36,9 +28,7 @@ namespace Omegasis.HappyBirthday ["Penny"] = "", }; - /// - /// Used to contain - /// + /// Used to contain public Dictionary defaultBirthdayWishes = new Dictionary() { ["Robin"] = "Hey @, happy birthday! I'm glad you choose this town to move here to. ", @@ -76,12 +66,9 @@ namespace Omegasis.HappyBirthday ["Krobus"] = "I have heard that it is tradition to give a gift to others on their birthday. In that case, happy birthday @." }; - /// - /// Used to load all of the default birthday greetings. - /// + /// Used to load all of the default birthday greetings. public void createBirthdayGreetings() { - var serializer = JsonSerializer.Create(); serializer.Formatting = Formatting.Indented; @@ -89,75 +76,64 @@ namespace Omegasis.HappyBirthday string defaultPath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", HappyBirthday.Config.translationInfo.currentTranslation); if (!Directory.Exists(defaultPath)) Directory.CreateDirectory(defaultPath); - string birthdayFileDict=HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", HappyBirthday.Config.translationInfo.currentTranslation); - string path = Path.Combine( "Content", "Dialogue", HappyBirthday.Config.translationInfo.currentTranslation, birthdayFileDict); + string birthdayFileDict = HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", HappyBirthday.Config.translationInfo.currentTranslation); + string path = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.currentTranslation, birthdayFileDict); //Handle normal birthday wishes. - if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath,path))) + if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, path))) { HappyBirthday.ModMonitor.Log("Creating Villager Birthday Messages", StardewModdingAPI.LogLevel.Alert); - HappyBirthday.ModHelper.Data.WriteJsonFile>(path, defaultBirthdayWishes); - this.birthdayWishes = defaultBirthdayWishes; + HappyBirthday.ModHelper.Data.WriteJsonFile>(path, this.defaultBirthdayWishes); + this.birthdayWishes = this.defaultBirthdayWishes; } else - { - birthdayWishes = HappyBirthday.ModHelper.Data.ReadJsonFile>(path); - } + this.birthdayWishes = HappyBirthday.ModHelper.Data.ReadJsonFile>(path); //handle spouse birthday wishes. string spouseBirthdayFileDict = HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", HappyBirthday.Config.translationInfo.currentTranslation); string spousePath = Path.Combine("Content", "Dialogue", HappyBirthday.Config.translationInfo.currentTranslation, spouseBirthdayFileDict); - if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath,spousePath))) + if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, spousePath))) { HappyBirthday.ModMonitor.Log("Creating Spouse Messages", StardewModdingAPI.LogLevel.Alert); - HappyBirthday.ModHelper.Data.WriteJsonFile>(spousePath, defaultSpouseBirthdayWishes); - this.spouseBirthdayWishes = defaultSpouseBirthdayWishes; + HappyBirthday.ModHelper.Data.WriteJsonFile>(spousePath, this.defaultSpouseBirthdayWishes); + this.spouseBirthdayWishes = this.defaultSpouseBirthdayWishes; } else - { - spouseBirthdayWishes = HappyBirthday.ModHelper.Data.ReadJsonFile>(spousePath); - } + this.spouseBirthdayWishes = HappyBirthday.ModHelper.Data.ReadJsonFile>(spousePath); //Non-english logic for creating templates. - foreach(var translation in HappyBirthday.Config.translationInfo.translationCodes) + foreach (var translation in HappyBirthday.Config.translationInfo.translationCodes) { - if (translation.Key == "English") continue; - string basePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath,"Content", "Dialogue", translation.Key); - if (!Directory.Exists(basePath)) Directory.CreateDirectory(basePath); - string tempBirthdayFile =Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", translation.Key)); - string tempSpouseBirthdayFile =Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", translation.Key)); + if (translation.Key == "English") + continue; + + string basePath = Path.Combine(HappyBirthday.ModHelper.DirectoryPath, "Content", "Dialogue", translation.Key); + if (!Directory.Exists(basePath)) + Directory.CreateDirectory(basePath); + string tempBirthdayFile = Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("BirthdayWishes", translation.Key)); + string tempSpouseBirthdayFile = Path.Combine("Content", "Dialogue", translation.Key, HappyBirthday.Config.translationInfo.getjsonForTranslation("SpouseBirthdayWishes", translation.Key)); Dictionary tempBirthdayDict = new Dictionary(); if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, tempBirthdayFile))) { - - foreach (var pair in defaultBirthdayWishes) - { + foreach (var pair in this.defaultBirthdayWishes) tempBirthdayDict.Add(pair.Key, ""); - } HappyBirthday.ModHelper.Data.WriteJsonFile>(tempBirthdayFile, tempBirthdayDict); } else - { tempBirthdayDict = HappyBirthday.ModHelper.Data.ReadJsonFile>(tempBirthdayFile); - } Dictionary tempSpouseBirthdayDict = new Dictionary(); if (!File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, tempSpouseBirthdayFile))) { - - foreach (var pair in defaultSpouseBirthdayWishes) - { + foreach (var pair in this.defaultSpouseBirthdayWishes) tempSpouseBirthdayDict.Add(pair.Key, ""); - } HappyBirthday.ModHelper.Data.WriteJsonFile>(tempSpouseBirthdayFile, tempSpouseBirthdayDict); } else - { tempSpouseBirthdayDict = HappyBirthday.ModHelper.Data.ReadJsonFile>(tempSpouseBirthdayFile); - } //Set translated birthday info. if (HappyBirthday.Config.translationInfo.currentTranslation == translation.Key) @@ -166,10 +142,7 @@ namespace Omegasis.HappyBirthday this.spouseBirthdayWishes = tempSpouseBirthdayDict; HappyBirthday.ModMonitor.Log("Language set to: " + translation); } - } } - - } } diff --git a/GeneralMods/HappyBirthday/Framework/BirthdayMenu.cs b/GeneralMods/HappyBirthday/Framework/BirthdayMenu.cs index 4e9d1c9c..8c6f8e9b 100644 --- a/GeneralMods/HappyBirthday/Framework/BirthdayMenu.cs +++ b/GeneralMods/HappyBirthday/Framework/BirthdayMenu.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -50,9 +50,7 @@ namespace Omegasis.HappyBirthday.Framework this.OnChanged = onChanged; this.SetUpPositions(); } - - - + /// The method called when the game window changes size. /// The former viewport. /// The new viewport. @@ -155,7 +153,7 @@ namespace Omegasis.HappyBirthday.Framework case "OK": if (this.BirthdayDay >= 1 || this.BirthdayDay <= 28) MultiplayerSupport.SendBirthdayInfoToOtherPlayers(); //Send updated info to others. - Game1.exitActiveMenu(); + Game1.exitActiveMenu(); break; default: diff --git a/GeneralMods/HappyBirthday/Framework/Messages.cs b/GeneralMods/HappyBirthday/Framework/Messages.cs index 14d720bd..4cf68e86 100644 --- a/GeneralMods/HappyBirthday/Framework/Messages.cs +++ b/GeneralMods/HappyBirthday/Framework/Messages.cs @@ -1,6 +1,5 @@ - + using StardewValley; -using System.Collections.Generic; namespace Omegasis.HappyBirthday.Framework { @@ -28,8 +27,6 @@ namespace Omegasis.HappyBirthday.Framework Game1.player.mailReceived.Add("BackpackTip"); Game1.addMailForTomorrow("pierreBackpack", false, false); } - - } } diff --git a/GeneralMods/HappyBirthday/Framework/ModConfig.cs b/GeneralMods/HappyBirthday/Framework/ModConfig.cs index fb501b14..87d56ad5 100644 --- a/GeneralMods/HappyBirthday/Framework/ModConfig.cs +++ b/GeneralMods/HappyBirthday/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.HappyBirthday.Framework +namespace Omegasis.HappyBirthday.Framework { /// The mod configuration. public class ModConfig @@ -6,14 +6,10 @@ /// The key which shows the menu. public string KeyBinding { get; set; } = "O"; - /// - /// The minimum amount of friendship needed to get a birthday gift. - /// + /// The minimum amount of friendship needed to get a birthday gift. public int minNeutralFriendshipGiftLevel = 3; - /// - /// The max amount of friendship needed to get a neutral gift from an npc. - /// + /// The max amount of friendship needed to get a neutral gift from an npc. public int maxNeutralFriendshipGiftLevel = 4; /// @@ -21,34 +17,22 @@ /// public int minLikeFriendshipLevel = 5; - /// - /// The max amount of friendship needed to get a liked gift from an npc. - /// + /// The max amount of friendship needed to get a liked gift from an npc. public int maxLikeFriendshipLevel = 6; - /// - /// The minimum amount of friendship needed to get a loved gift from an npc. - /// + /// The minimum amount of friendship needed to get a loved gift from an npc. public int minLoveFriendshipLevel = 7; - /// - /// The minimum amount of friendship needed to get a happy birthday greeting from an npc. - /// - public int minimumFriendshipLevelForBirthdayWish=2; + /// The minimum amount of friendship needed to get a happy birthday greeting from an npc. + public int minimumFriendshipLevelForBirthdayWish = 2; - /// - /// Handles different translations of files. - /// + /// Handles different translations of files. public TranslationInfo translationInfo; - /// - /// Whether or not to load from the old BirthdayGifts.xnb located in StardewValley/Data or from the new BirthdayGifts.json located in the mod directory. - /// + /// Whether or not to load from the old BirthdayGifts.xnb located in StardewValley/Data or from the new BirthdayGifts.json located in the mod directory. public bool useLegacyBirthdayFiles; - /// - /// Constructor. - /// + /// Construct an instance. public ModConfig() { this.translationInfo = new TranslationInfo(); diff --git a/GeneralMods/HappyBirthday/Framework/MultiplayerSupport.cs b/GeneralMods/HappyBirthday/Framework/MultiplayerSupport.cs index 83eb234f..931bcacd 100644 --- a/GeneralMods/HappyBirthday/Framework/MultiplayerSupport.cs +++ b/GeneralMods/HappyBirthday/Framework/MultiplayerSupport.cs @@ -1,27 +1,20 @@ -using StardewValley; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using StardewValley; namespace Omegasis.HappyBirthday.Framework { public class MultiplayerSupport { - public static string FSTRING_SendBirthdayMessageToOthers = "Omegasis.HappyBirthday.Framework.Messages.SendBirthdayMessageToOtherPlayers"; public static string FSTRING_SendBirthdayInfoToOthers = "Omegasis.HappyBirthday.Framework.Messages.SendBirthdayInfoToOtherPlayers"; - public static void SendBirthdayMessageToOtherPlayers() { HUDMessage message = new HUDMessage("It's " + Game1.player.Name + "'s birthday! Happy birthday to them!", 1); - - foreach (KeyValuePair f in Game1.otherFarmers) + foreach (KeyValuePair f in Game1.otherFarmers) { - HappyBirthday.ModHelper.Multiplayer.SendMessage(message.message, FSTRING_SendBirthdayMessageToOthers,new string[] { HappyBirthday.ModHelper.Multiplayer.ModID }, new long[] { f.Key }); + HappyBirthday.ModHelper.Multiplayer.SendMessage(message.message, FSTRING_SendBirthdayMessageToOthers, new string[] { HappyBirthday.ModHelper.Multiplayer.ModID }, new long[] { f.Key }); //ModdedUtilitiesNetworking.ModCore.multiplayer.sendMessage(FSTRING_SendBirthdayMessageToOthers, ModdedUtilitiesNetworking.Framework.Extentions.StrardewValleyExtentions.MessagesExtentions.HUDMessageIconIdentifier, message, ModdedUtilitiesNetworking.Framework.Enums.MessageTypes.messageTypes.SendToSpecific, f); } } @@ -30,10 +23,9 @@ namespace Omegasis.HappyBirthday.Framework { foreach (KeyValuePair f in Game1.otherFarmers) { - HappyBirthday.ModHelper.Multiplayer.SendMessage>(new KeyValuePair(Game1.player.uniqueMultiplayerID, HappyBirthday.PlayerBirthdayData), FSTRING_SendBirthdayInfoToOthers, new string[] { HappyBirthday.ModHelper.Multiplayer.ModID }, new long[] { f.Key }); + HappyBirthday.ModHelper.Multiplayer.SendMessage>(new KeyValuePair(Game1.player.uniqueMultiplayerID, HappyBirthday.PlayerBirthdayData), FSTRING_SendBirthdayInfoToOthers, new string[] { HappyBirthday.ModHelper.Multiplayer.ModID }, new long[] { f.Key }); //ModdedUtilitiesNetworking.ModCore.multiplayer.sendMessage(FSTRING_SendBirthdayMessageToOthers, ModdedUtilitiesNetworking.Framework.Extentions.StrardewValleyExtentions.MessagesExtentions.HUDMessageIconIdentifier, message, ModdedUtilitiesNetworking.Framework.Enums.MessageTypes.messageTypes.SendToSpecific, f); } - } public static void SendBirthdayInfoToConnectingPlayer(long id) @@ -42,6 +34,5 @@ namespace Omegasis.HappyBirthday.Framework //ModdedUtilitiesNetworking.ModCore.multiplayer.sendMessage(FSTRING_SendBirthdayMessageToOthers, ModdedUtilitiesNetworking.Framework.Extentions.StrardewValleyExtentions.MessagesExtentions.HUDMessageIconIdentifier, message, ModdedUtilitiesNetworking.Framework.Enums.MessageTypes.messageTypes.SendToSpecific, f); } - } } diff --git a/GeneralMods/HappyBirthday/Framework/ObjectUtility.cs b/GeneralMods/HappyBirthday/Framework/ObjectUtility.cs index 49e9c263..469a0b31 100644 --- a/GeneralMods/HappyBirthday/Framework/ObjectUtility.cs +++ b/GeneralMods/HappyBirthday/Framework/ObjectUtility.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using StardewValley; using Object = StardewValley.Object; diff --git a/GeneralMods/HappyBirthday/Framework/PlayerData.cs b/GeneralMods/HappyBirthday/Framework/PlayerData.cs index f956b797..bfee948f 100644 --- a/GeneralMods/HappyBirthday/Framework/PlayerData.cs +++ b/GeneralMods/HappyBirthday/Framework/PlayerData.cs @@ -1,4 +1,4 @@ -namespace Omegasis.HappyBirthday.Framework +namespace Omegasis.HappyBirthday.Framework { /// The data for the current player. public class PlayerData diff --git a/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs b/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs index abc244eb..d534dd4d 100644 --- a/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs +++ b/GeneralMods/HappyBirthday/Framework/TranslationInfo.cs @@ -1,70 +1,56 @@ -using StardewValley; -using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using StardewValley; namespace Omegasis.HappyBirthday.Framework { - /// - /// A class which deals with handling different translations for Vocalization should other voice teams ever wish to voice act for that language. - /// + /// A class which deals with handling different translations for Vocalization should other voice teams ever wish to voice act for that language. public class TranslationInfo { - /// - /// The list of all supported translations by this mod. - /// + /// The list of all supported translations by this mod. public List translations; - /// - /// The current translation mode for the mod, so that it knows what files to load at the beginning of the game. - /// + /// The current translation mode for the mod, so that it knows what files to load at the beginning of the game. public string currentTranslation; - /// - /// Holds the info for what translation has what file extension. - /// + /// Holds the info for what translation has what file extension. public Dictionary translationFileInfo; - public Dictionary translationCodes; - /// - /// Default constructor. - /// + + /// Construct an instance.. public TranslationInfo() { - translations = new List(); + this.translations = new List(); - translationFileInfo = new Dictionary(); - translationCodes = new Dictionary(); - translations.Add("English"); - translations.Add("Spanish"); - translations.Add("Chinese"); - translations.Add("Japanese"); - translations.Add("Russian"); - translations.Add("German"); - translations.Add("Brazillian Portuguese"); + this.translationFileInfo = new Dictionary(); + this.translationCodes = new Dictionary(); + this.translations.Add("English"); + this.translations.Add("Spanish"); + this.translations.Add("Chinese"); + this.translations.Add("Japanese"); + this.translations.Add("Russian"); + this.translations.Add("German"); + this.translations.Add("Brazillian Portuguese"); - currentTranslation = "English"; + this.currentTranslation = "English"; - translationFileInfo.Add("English", ".json"); - translationFileInfo.Add("Spanish", ".es-ES.json"); - translationFileInfo.Add("Chinese", ".zh-CN.json"); - translationFileInfo.Add("Japanese", ".ja-JP.json"); - translationFileInfo.Add("Russian", ".ru-RU.json"); - translationFileInfo.Add("German", ".de-DE.json"); - translationFileInfo.Add("Brazillian Portuguese", ".pt-BR.json"); + this.translationFileInfo.Add("English", ".json"); + this.translationFileInfo.Add("Spanish", ".es-ES.json"); + this.translationFileInfo.Add("Chinese", ".zh-CN.json"); + this.translationFileInfo.Add("Japanese", ".ja-JP.json"); + this.translationFileInfo.Add("Russian", ".ru-RU.json"); + this.translationFileInfo.Add("German", ".de-DE.json"); + this.translationFileInfo.Add("Brazillian Portuguese", ".pt-BR.json"); - translationCodes.Add("English", LocalizedContentManager.LanguageCode.en); - translationCodes.Add("Spanish", LocalizedContentManager.LanguageCode.es); - translationCodes.Add("Chinese", LocalizedContentManager.LanguageCode.zh); - translationCodes.Add("Japanese", LocalizedContentManager.LanguageCode.ja); - translationCodes.Add("Russian", LocalizedContentManager.LanguageCode.ru); - translationCodes.Add("German", LocalizedContentManager.LanguageCode.de); - translationCodes.Add("Brazillian Portuguese", LocalizedContentManager.LanguageCode.pt); + this.translationCodes.Add("English", LocalizedContentManager.LanguageCode.en); + this.translationCodes.Add("Spanish", LocalizedContentManager.LanguageCode.es); + this.translationCodes.Add("Chinese", LocalizedContentManager.LanguageCode.zh); + this.translationCodes.Add("Japanese", LocalizedContentManager.LanguageCode.ja); + this.translationCodes.Add("Russian", LocalizedContentManager.LanguageCode.ru); + this.translationCodes.Add("German", LocalizedContentManager.LanguageCode.de); + this.translationCodes.Add("Brazillian Portuguese", LocalizedContentManager.LanguageCode.pt); } @@ -73,12 +59,11 @@ namespace Omegasis.HappyBirthday.Framework return Path.GetFileName(fullPath); } - public void changeLocalizedContentManagerFromTranslation(string translation) { - string tra = getTranslationNameFromPath(translation); - bool f = translationCodes.TryGetValue(tra, out LocalizedContentManager.LanguageCode code); - if (f == false) LocalizedContentManager.CurrentLanguageCode = LocalizedContentManager.LanguageCode.en; + string tra = this.getTranslationNameFromPath(translation); + bool f = this.translationCodes.TryGetValue(tra, out LocalizedContentManager.LanguageCode code); + if (!f) LocalizedContentManager.CurrentLanguageCode = LocalizedContentManager.LanguageCode.en; else LocalizedContentManager.CurrentLanguageCode = code; return; } @@ -88,24 +73,21 @@ namespace Omegasis.HappyBirthday.Framework LocalizedContentManager.CurrentLanguageCode = LocalizedContentManager.LanguageCode.en; } - /// - /// Gets the proper file extension for the current translation. - /// + /// Gets the proper file extension for the current translation. /// - /// public string getFileExtentionForTranslation(string path) { /* bool f = translationFileInfo.TryGetValue(translation, out string value); - if (f == false) return ".json"; + if (!f) return ".json"; else return value; */ string translation = Path.GetFileName(path); try { - return translationFileInfo[translation]; + return this.translationFileInfo[translation]; } - catch (Exception err) + catch { HappyBirthday.ModMonitor.Log("WTF SOMETHING IS WRONG!", StardewModdingAPI.LogLevel.Warn); //Vocalization.ModMonitor.Log(err.ToString()); @@ -114,45 +96,34 @@ namespace Omegasis.HappyBirthday.Framework } } - /// - /// Gets the proper json for Buildings (aka Blueprints) from the data folder. - /// - /// - /// + /// Gets the proper json for Buildings (aka Blueprints) from the data folder. public string getBuildingjsonForTranslation(string translation) { string buildings = "Blueprints"; - return buildings + getFileExtentionForTranslation(translation); + return buildings + this.getFileExtentionForTranslation(translation); } - /// - /// Gets the proper json file for the name passed in. Combines the file name with it's proper translation extension. - /// + /// Gets the proper json file for the name passed in. Combines the file name with it's proper translation extension. /// /// - /// public string getjsonForTranslation(string jsonFileName, string translation) { - return jsonFileName + getFileExtentionForTranslation(translation); + return jsonFileName + this.getFileExtentionForTranslation(translation); } - /// - /// Loads an json file from StardewValley/Content - /// + /// Loads an json file from StardewValley/Content /// /// /// - /// public string LoadjsonFile(string jsonFileName, string key, string translation) { - string json = jsonFileName + getFileExtentionForTranslation(translation); + string json = jsonFileName + this.getFileExtentionForTranslation(translation); Dictionary loadedDict = Game1.content.Load>(json); - string loaded; - bool f = loadedDict.TryGetValue(key, out loaded); - if (f == false) + bool f = loadedDict.TryGetValue(key, out string loaded); + if (!f) { //Vocalization.ModMonitor.Log("Big issue: Key not found in file:" + json + " " + key); return ""; @@ -160,15 +131,12 @@ namespace Omegasis.HappyBirthday.Framework else return loaded; } - /// - /// Loads a string dictionary from a json file. - /// + /// Loads a string dictionary from a json file. /// /// - /// - public Dictionary LoadJsonFileDictionary(string jsonFileName, string translation) + public Dictionary LoadJsonFileDictionary(string jsonFileName, string translation) { - string json = jsonFileName + getFileExtentionForTranslation(translation); + string json = jsonFileName + this.getFileExtentionForTranslation(translation); Dictionary loadedDict = Game1.content.Load>(json); return loadedDict; @@ -181,9 +149,7 @@ namespace Omegasis.HappyBirthday.Framework { return string.Format(format, sub1, sub2, sub3); } - catch (Exception ex) - { - } + catch { } return format; } @@ -195,9 +161,7 @@ namespace Omegasis.HappyBirthday.Framework { return string.Format(format, sub1, sub2); } - catch (Exception ex) - { - } + catch { } return format; } @@ -209,20 +173,15 @@ namespace Omegasis.HappyBirthday.Framework { return string.Format(format, sub1); } - catch (Exception ex) - { - } + catch { } return format; } public virtual string LoadString(string path, string translation) { - string assetName; - string key; - this.parseStringPath(path, out assetName, out key); - - return LoadjsonFile(assetName, key, translation); + this.parseStringPath(path, out string assetName, out string key); + return this.LoadjsonFile(assetName, key, translation); } public virtual string LoadString(string path, string translation, params object[] substitutions) @@ -234,14 +193,11 @@ namespace Omegasis.HappyBirthday.Framework { return string.Format(format, substitutions); } - catch (Exception ex) - { - } + catch { } } return format; } - private void parseStringPath(string path, out string assetName, out string key) { int length = path.IndexOf(':'); diff --git a/GeneralMods/HappyBirthday/GiftManager.cs b/GeneralMods/HappyBirthday/GiftManager.cs index 18972ab3..b7aa8032 100644 --- a/GeneralMods/HappyBirthday/GiftManager.cs +++ b/GeneralMods/HappyBirthday/GiftManager.cs @@ -1,65 +1,60 @@ -using Omegasis.HappyBirthday.Framework; -using StardewModdingAPI; -using StardewValley; using System; using System.Collections.Generic; using System.IO; using System.Linq; +using Omegasis.HappyBirthday.Framework; +using StardewValley; +using static System.String; using SObject = StardewValley.Object; namespace Omegasis.HappyBirthday { public class GiftManager { - public ModConfig Config + public ModConfig Config => HappyBirthday.Config; + + private Dictionary defaultBirthdayGifts = new Dictionary() { - get - { - return HappyBirthday.Config; - } - } + ["Universal_Love_Gift"] = "74 1 446 1 204 1 446 5 773 1", + ["Universal_Like_Gift"] = "-2 3 -7 1 -26 2 -75 5 -80 3 72 1 220 1 221 1 395 1 613 1 634 1 635 1 636 1 637 1 638 1 724 1 233 1 223 1 465 20 -79 5", + ["Universal_Neutral_Gift"] = "194 1 262 5 -74 5 -75 3 334 5 335 1 390 20 388 20 -81 5 -79 3", + ["Robin"] = " BestGifts/224 1 426 1 636 1/GoodGift/-6 5 -79 5 424 1 709 1/NeutralGift//", + ["Demetrius"] = " Best Gifts/207 1 232 1 233 1 400 1/Good Gifts/-5 3 -79 5 422 1/NeutralGift/-4 3/", + ["Maru"] = " BestGift/72 1 197 1 190 1 215 1 222 1 243 1 336 1 337 1 400 1 787 1/Good Gift/-260 1 62 1 64 1 66 1 68 1 70 1 334 1 335 1 725 1 726 1/NeutralGift/", + ["Sebastian"] = " Best/84 1 227 1 236 1 575 1 305 1 /Good/267 1 276 1/Neutral/-4 3/", + ["Linus"] = " Best/88 1 90 1 234 1 242 1 280 1/Good/-5 3 -6 5 -79 5 -81 10/Neutral/-4 3/", + ["Pierre"] = " Best/202 1/Good/-5 3 -6 5 -7 1 18 1 22 1 402 1 418 1 259 1/Neutral//", + ["Caroline"] = " Best/213 1 593 1/Good/-7 1 18 1 402 1 418 1/Neutral// ", + ["Abigail"] = " Best/66 1 128 1 220 1 226 1 276 1 611 1/Good//Neutral// ", + ["Alex"] = " Best/201 1 212 1 662 1 664 1/Good/-5 3/Neutral// ", + ["George"] = " Best/20 1 205 1/Good/18 1 195 1 199 1 200 1 214 1 219 1 223 1 231 1 233 1/Neutral// ", + ["Evelyn"] = " Best/72 1 220 1 239 1 284 1 591 1 595 1/Good/-6 5 18 1 402 1 418 1/Neutral// ", + ["Lewis"] = " Best/200 1 208 1 235 1 260 1/Good/-80 5 24 1 88 1 90 1 192 1 258 1 264 1 272 1 274 1 278 1/Neutral// ", + ["Clint"] = " Best/60 1 62 1 64 1 66 1 68 1 70 1 336 1 337 1 605 1 649 1 749 1 337 5/Good/334 20 335 10 336 5/Neutral// ", + ["Penny"] = " Best/60 1 376 1 651 1 72 1 164 1 218 1 230 1 244 1 254 1/Good/-6 5 20 1 22 1/Neutral// ", + ["Pam"] = " Best/24 1 90 1 199 1 208 1 303 1 346 1/Good/-6 5 -75 5 -79 5 18 1 227 1 228 1 231 1 232 1 233 1 234 1 235 1 236 1 238 1 402 1 418 1/Neutral/-4 3/ ", + ["Emily"] = " Best/60 1 62 1 64 1 66 1 68 1 70 1 241 1 428 1 440 1 /Good/18 1 82 1 84 1 86 1 196 1 200 1 207 1 230 1 235 1 402 1 418 1/Neutral// ", + ["Haley"] = " Best/221 1 421 1 610 1 88 1 /Good/18 1 60 1 62 1 64 1 70 1 88 1 222 1 223 1 232 1 233 1 234 1 402 1 418 1 /Neutral// ", + ["Jas"] = " Best/221 1 595 1 604 1 /Good/18 1 60 1 64 1 70 1 88 1 232 1 233 1 234 1 222 1 223 1 340 1 344 1 402 1 418 1 /Neutral// ", + ["Vincent"] = " Best/221 1 398 1 612 1 /Good/18 1 60 1 64 1 70 1 88 1 232 1 233 1 234 1 222 1 223 1 340 1 344 1 402 1 418 1 /Neutral// ", + ["Jodi"] = " Best/72 1 200 1 211 1 214 1 220 1 222 1 225 1 231 1 /Good/-5 3 -6 5 -79 5 18 1 402 1 418 1 /Neutral// ", + ["Kent"] = " Best/607 1 649 1 /Good/-5 3 -79 5 18 1 402 1 418 1 /Neutral// ", + ["Sam"] = " Best/90 1 206 1 655 1 658 1 562 1 731 1/Good/167 1 210 1 213 1 220 1 223 1 224 1 228 1 232 1 233 1 239 1 -5 3/Neutral// ", + ["Leah"] = " Best/196 1 200 1 348 1 606 1 651 1 650 1 426 1 430 1 /Good/-5 3 -6 5 -79 5 -81 10 18 1 402 1 406 1 408 1 418 1 86 1 /Neutral// ", + ["Shane"] = " Best/206 1 215 1 260 1 346 1 /Good/-5 3 -79 5 303 1 /Neutral// ", + ["Marnie"] = " Best/72 1 221 1 240 1 608 1 /Good/-5 3 -6 5 402 1 418 1 /Neutral// ", + ["Elliott"] = " Best/715 1 732 1 218 1 444 1 /Good/727 1 728 1 -79 5 60 1 80 1 82 1 84 1 149 1 151 1 346 1 348 1 728 1 /Neutral/-4 3 / ", + ["Gus"] = " Best/72 1 213 1 635 1 729 1 /Good/348 1 303 1 -7 1 18 1 /Neutral// ", + ["Dwarf"] = " Best/60 1 62 1 64 1 66 1 68 1 70 1 749 1 /Good/82 1 84 1 86 1 96 1 97 1 98 1 99 1 121 1 122 1 /Neutral/-28 20 / ", + ["Wizard"] = " Best/107 1 155 1 422 1 769 1 768 1 /Good/-12 3 72 1 82 1 84 1/Neutral// ", + ["Harvey"] = " Best/348 1 237 1 432 1 395 1 342 1 /Good/-81 10 -79 5 -7 1 402 1 418 1 422 1 436 1 438 1 442 1 444 1 422 1 /Neutral// ", + ["Sandy"] = " Best/18 1 402 1 418 1 /Good/-75 5 -79 5 88 1 428 1 436 1 438 1 440 1 /Neutral// ", + ["Willy"] = " Best/72 1 143 1 149 1 154 1 276 1 337 1 698 1 /Good/66 1 336 1 340 1 699 1 707 1 /Neutral/-4 3 / ", + ["Krobus"] = " Best/72 1 16 1 276 1 337 1 305 1 /Good/66 1 336 1 340 1 /Neutral// " + }; - - private Dictionary defaultBirthdayGifts=new Dictionary() { - ["Universal_Love_Gift"] = "74 1 446 1 204 1 446 5 773 1", - ["Universal_Like_Gift"] = "-2 3 -7 1 -26 2 -75 5 -80 3 72 1 220 1 221 1 395 1 613 1 634 1 635 1 636 1 637 1 638 1 724 1 233 1 223 1 465 20 -79 5", - ["Universal_Neutral_Gift"] = "194 1 262 5 -74 5 -75 3 334 5 335 1 390 20 388 20 -81 5 -79 3", - ["Robin"] = " BestGifts/224 1 426 1 636 1/GoodGift/-6 5 -79 5 424 1 709 1/NeutralGift//", - ["Demetrius"] = " Best Gifts/207 1 232 1 233 1 400 1/Good Gifts/-5 3 -79 5 422 1/NeutralGift/-4 3/", - ["Maru"] = " BestGift/72 1 197 1 190 1 215 1 222 1 243 1 336 1 337 1 400 1 787 1/Good Gift/-260 1 62 1 64 1 66 1 68 1 70 1 334 1 335 1 725 1 726 1/NeutralGift/", - ["Sebastian"] = " Best/84 1 227 1 236 1 575 1 305 1 /Good/267 1 276 1/Neutral/-4 3/", - ["Linus"] = " Best/88 1 90 1 234 1 242 1 280 1/Good/-5 3 -6 5 -79 5 -81 10/Neutral/-4 3/", - ["Pierre"] = " Best/202 1/Good/-5 3 -6 5 -7 1 18 1 22 1 402 1 418 1 259 1/Neutral//", - ["Caroline"] = " Best/213 1 593 1/Good/-7 1 18 1 402 1 418 1/Neutral// ", - ["Abigail"] = " Best/66 1 128 1 220 1 226 1 276 1 611 1/Good//Neutral// ", - ["Alex"] = " Best/201 1 212 1 662 1 664 1/Good/-5 3/Neutral// ", - ["George"] = " Best/20 1 205 1/Good/18 1 195 1 199 1 200 1 214 1 219 1 223 1 231 1 233 1/Neutral// ", - ["Evelyn"] = " Best/72 1 220 1 239 1 284 1 591 1 595 1/Good/-6 5 18 1 402 1 418 1/Neutral// ", - ["Lewis"] = " Best/200 1 208 1 235 1 260 1/Good/-80 5 24 1 88 1 90 1 192 1 258 1 264 1 272 1 274 1 278 1/Neutral// ", - ["Clint"] = " Best/60 1 62 1 64 1 66 1 68 1 70 1 336 1 337 1 605 1 649 1 749 1 337 5/Good/334 20 335 10 336 5/Neutral// ", - ["Penny"] = " Best/60 1 376 1 651 1 72 1 164 1 218 1 230 1 244 1 254 1/Good/-6 5 20 1 22 1/Neutral// ", - ["Pam"] = " Best/24 1 90 1 199 1 208 1 303 1 346 1/Good/-6 5 -75 5 -79 5 18 1 227 1 228 1 231 1 232 1 233 1 234 1 235 1 236 1 238 1 402 1 418 1/Neutral/-4 3/ ", - ["Emily"] = " Best/60 1 62 1 64 1 66 1 68 1 70 1 241 1 428 1 440 1 /Good/18 1 82 1 84 1 86 1 196 1 200 1 207 1 230 1 235 1 402 1 418 1/Neutral// ", - ["Haley"] = " Best/221 1 421 1 610 1 88 1 /Good/18 1 60 1 62 1 64 1 70 1 88 1 222 1 223 1 232 1 233 1 234 1 402 1 418 1 /Neutral// ", - ["Jas"] = " Best/221 1 595 1 604 1 /Good/18 1 60 1 64 1 70 1 88 1 232 1 233 1 234 1 222 1 223 1 340 1 344 1 402 1 418 1 /Neutral// ", - ["Vincent"] = " Best/221 1 398 1 612 1 /Good/18 1 60 1 64 1 70 1 88 1 232 1 233 1 234 1 222 1 223 1 340 1 344 1 402 1 418 1 /Neutral// ", - ["Jodi"] = " Best/72 1 200 1 211 1 214 1 220 1 222 1 225 1 231 1 /Good/-5 3 -6 5 -79 5 18 1 402 1 418 1 /Neutral// ", - ["Kent"] = " Best/607 1 649 1 /Good/-5 3 -79 5 18 1 402 1 418 1 /Neutral// ", - ["Sam"] = " Best/90 1 206 1 655 1 658 1 562 1 731 1/Good/167 1 210 1 213 1 220 1 223 1 224 1 228 1 232 1 233 1 239 1 -5 3/Neutral// ", - ["Leah"] = " Best/196 1 200 1 348 1 606 1 651 1 650 1 426 1 430 1 /Good/-5 3 -6 5 -79 5 -81 10 18 1 402 1 406 1 408 1 418 1 86 1 /Neutral// ", - ["Shane"] = " Best/206 1 215 1 260 1 346 1 /Good/-5 3 -79 5 303 1 /Neutral// ", - ["Marnie"] = " Best/72 1 221 1 240 1 608 1 /Good/-5 3 -6 5 402 1 418 1 /Neutral// ", - ["Elliott"] = " Best/715 1 732 1 218 1 444 1 /Good/727 1 728 1 -79 5 60 1 80 1 82 1 84 1 149 1 151 1 346 1 348 1 728 1 /Neutral/-4 3 / ", - ["Gus"] = " Best/72 1 213 1 635 1 729 1 /Good/348 1 303 1 -7 1 18 1 /Neutral// ", - ["Dwarf"] = " Best/60 1 62 1 64 1 66 1 68 1 70 1 749 1 /Good/82 1 84 1 86 1 96 1 97 1 98 1 99 1 121 1 122 1 /Neutral/-28 20 / ", - ["Wizard"] = " Best/107 1 155 1 422 1 769 1 768 1 /Good/-12 3 72 1 82 1 84 1/Neutral// ", - ["Harvey"] = " Best/348 1 237 1 432 1 395 1 342 1 /Good/-81 10 -79 5 -7 1 402 1 418 1 422 1 436 1 438 1 442 1 444 1 422 1 /Neutral// ", - ["Sandy"] = " Best/18 1 402 1 418 1 /Good/-75 5 -79 5 88 1 428 1 436 1 438 1 440 1 /Neutral// ", - ["Willy"] = " Best/72 1 143 1 149 1 154 1 276 1 337 1 698 1 /Good/66 1 336 1 340 1 699 1 707 1 /Neutral/-4 3 / ", - ["Krobus"] = " Best/72 1 16 1 276 1 337 1 305 1 /Good/66 1 336 1 340 1 /Neutral// " - }; - - public Dictionary defaultSpouseBirthdayGifts = new Dictionary() { + public Dictionary defaultSpouseBirthdayGifts = new Dictionary() + { ["Universal_Gifts"] = "74 1 446 1 204 1 446 5 773 1", ["Alex"] = "", @@ -74,8 +69,6 @@ namespace Omegasis.HappyBirthday ["Leah"] = "", ["Maru"] = "", ["Penny"] = "", - - }; public List BirthdayGifts; @@ -83,7 +76,7 @@ namespace Omegasis.HappyBirthday /// The next birthday gift the player will receive. public Item BirthdayGiftToReceive; - + /// Construct an instance. public GiftManager() { this.BirthdayGifts = new List(); @@ -91,30 +84,22 @@ namespace Omegasis.HappyBirthday this.loadSpouseBirthdayGifts(); } - /// - /// Load birthday gift information from disk. Preferably from BirthdayGift.json in the mod's directory. - /// - /// + /// Load birthday gift information from disk. Preferably from BirthdayGift.json in the mod's directory. public void loadVillagerBirthdayGifts() { - if (HappyBirthday.Config.useLegacyBirthdayFiles == false) + if (!HappyBirthday.Config.useLegacyBirthdayFiles) { string villagerGifts = Path.Combine("Content", "Gifts", "BirthdayGifts.json"); if (File.Exists(Path.Combine(HappyBirthday.ModHelper.DirectoryPath, villagerGifts))) - { this.defaultBirthdayGifts = HappyBirthday.ModHelper.Data.ReadJsonFile>(villagerGifts); - } else - { HappyBirthday.ModHelper.Data.WriteJsonFile>(villagerGifts, this.defaultBirthdayGifts); - } - } else { - - if (File.Exists(Path.Combine(Game1.content.RootDirectory, "Data", "PossibleBirthdayGifts.xnb"))){ + if (File.Exists(Path.Combine(Game1.content.RootDirectory, "Data", "PossibleBirthdayGifts.xnb"))) + { HappyBirthday.ModMonitor.Log("Legacy loading detected. Attempting to load from StardewValley/Content/Data/PossibleBirthdayGifts.xnb"); this.defaultBirthdayGifts = Game1.content.Load>(Path.Combine("Data", "PossibleBirthdayGifts")); @@ -122,16 +107,11 @@ namespace Omegasis.HappyBirthday HappyBirthday.ModHelper.Data.WriteJsonFile>(villagerGifts, this.defaultBirthdayGifts); } else - { HappyBirthday.ModMonitor.Log("No birthday gift information found. Loading from internal birthday list"); - } } } - /// - /// Used to load spouse birthday gifts from disk. - /// - /// + /// Used to load spouse birthday gifts from disk. public void loadSpouseBirthdayGifts() { string spouseGifts = Path.Combine("Content", "Gifts", "SpouseBirthdayGifts.json"); @@ -147,7 +127,6 @@ namespace Omegasis.HappyBirthday } } - /// Get the default gift items. /// The villager's name. private IEnumerable GetDefaultBirthdayGifts(string name) @@ -156,14 +135,14 @@ namespace Omegasis.HappyBirthday try { // read from birthday gifts file - IDictionary data = defaultBirthdayGifts; + IDictionary data = this.defaultBirthdayGifts; data.TryGetValue(name, out string text); if (text != null) { string[] fields = text.Split('/'); // love - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLoveFriendshipLevel) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= this.Config.minLoveFriendshipLevel) { string[] loveFields = fields[1].Split(' '); for (int i = 0; i < loveFields.Length; i += 2) @@ -177,7 +156,7 @@ namespace Omegasis.HappyBirthday } // like - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLikeFriendshipLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxLikeFriendshipLevel) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= this.Config.minLikeFriendshipLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= this.Config.maxLikeFriendshipLevel) { string[] likeFields = fields[3].Split(' '); for (int i = 0; i < likeFields.Length; i += 2) @@ -191,7 +170,7 @@ namespace Omegasis.HappyBirthday } // neutral - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxNeutralFriendshipGiftLevel) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= this.Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= this.Config.maxNeutralFriendshipGiftLevel) { string[] neutralFields = fields[5].Split(' '); @@ -207,54 +186,48 @@ namespace Omegasis.HappyBirthday } // get NPC's preferred gifts - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLoveFriendshipLevel) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= this.Config.minLoveFriendshipLevel) gifts.AddRange(this.GetUniversalItems("Love", true)); - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLikeFriendshipLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxLikeFriendshipLevel) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= this.Config.minLikeFriendshipLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= this.Config.maxLikeFriendshipLevel) this.BirthdayGifts.AddRange(this.GetUniversalItems("Like", true)); - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxNeutralFriendshipGiftLevel) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= this.Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= this.Config.maxNeutralFriendshipGiftLevel) this.BirthdayGifts.AddRange(this.GetUniversalItems("Neutral", true)); } catch { // get NPC's preferred gifts - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLoveFriendshipLevel) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= this.Config.minLoveFriendshipLevel) { this.BirthdayGifts.AddRange(this.GetUniversalItems("Love", false)); this.BirthdayGifts.AddRange(this.GetLovedItems(name)); } - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minLikeFriendshipLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxLikeFriendshipLevel) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= this.Config.minLikeFriendshipLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= this.Config.maxLikeFriendshipLevel) { this.BirthdayGifts.AddRange(this.GetLikedItems(name)); this.BirthdayGifts.AddRange(this.GetUniversalItems("Like", false)); } - if (Game1.player.getFriendshipHeartLevelForNPC(name) >= Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= Config.maxNeutralFriendshipGiftLevel) + if (Game1.player.getFriendshipHeartLevelForNPC(name) >= this.Config.minNeutralFriendshipGiftLevel && Game1.player.getFriendshipHeartLevelForNPC(name) <= this.Config.maxNeutralFriendshipGiftLevel) this.BirthdayGifts.AddRange(this.GetUniversalItems("Neutral", false)); } - + //Add in spouse specific birthday gifts. if (Game1.player.isMarried()) { if (name == Game1.player.spouse) { - this.BirthdayGifts.AddRange(getSpouseBirthdayGifts(name)); - this.BirthdayGifts.AddRange(getSpouseBirthdayGifts("Universal_Gifts")); + this.BirthdayGifts.AddRange(this.getSpouseBirthdayGifts(name)); + this.BirthdayGifts.AddRange(this.getSpouseBirthdayGifts("Universal_Gifts")); } } return gifts; } - /// - /// Get - /// - /// - /// - /// private IEnumerable getSpouseBirthdayGifts(string npcName) { Dictionary data = this.defaultSpouseBirthdayGifts; data.TryGetValue(npcName, out string text); - if (String.IsNullOrEmpty(text)) + if (IsNullOrEmpty(text)) yield break; // parse @@ -266,7 +239,6 @@ namespace Omegasis.HappyBirthday } } - /// Get the items loved by all villagers. /// The group to get (one of Like, Love, Neutral). /// Whether to get data from Data\BirthdayGifts.xnb instead of the game data. @@ -352,8 +324,6 @@ namespace Omegasis.HappyBirthday : new[] { new SObject(id, 1) }; } - - /// Get the items matching the given ID. /// The category or item ID. /// The stack size. diff --git a/GeneralMods/HappyBirthday/HappyBirthday.cs b/GeneralMods/HappyBirthday/HappyBirthday.cs index 86742385..628acc30 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.cs +++ b/GeneralMods/HappyBirthday/HappyBirthday.cs @@ -1,10 +1,9 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; -using Newtonsoft.Json; using Omegasis.HappyBirthday.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; @@ -12,7 +11,6 @@ using StardewValley; using StardewValley.Characters; using StardewValley.Menus; using StardewValley.Monsters; -using SObject = StardewValley.Object; namespace Omegasis.HappyBirthday { @@ -34,19 +32,11 @@ namespace Omegasis.HappyBirthday /// The data for the current player. public static PlayerData PlayerBirthdayData; - /// - /// Wrapper for static field PlayerBirthdayData; - /// + /// Wrapper for static field PlayerBirthdayData; public PlayerData PlayerData { - get - { - return PlayerBirthdayData; - } - set - { - PlayerBirthdayData = value; - } + get => PlayerBirthdayData; + set => PlayerBirthdayData = value; } /// Whether the player has chosen a birthday. @@ -55,49 +45,26 @@ namespace Omegasis.HappyBirthday /// The queue of villagers who haven't given a gift yet. private List VillagerQueue; - /// Whether we've already checked for and (if applicable) set up the player's birthday today. private bool CheckedForBirthday; //private Dictionary Dialogue; //private bool SeenEvent; - public bool CanEdit(IAssetInfo asset) - { - return asset.AssetNameEquals(@"Data\mail"); - } - - public void Edit(IAssetData asset) - { - asset - .AsDictionary() - .Set("birthdayMom", "Dear @,^ Happy birthday sweetheart. It's been amazing watching you grow into the kind, hard working person that I've always dreamed that you would become. I hope you continue to make many more fond memories with the ones you love. ^ Love, Mom ^ P.S. Here's a little something that I made for you. %item object 221 1 %%"); - - asset - .AsDictionary() - .Set("birthdayDad", "Dear @,^ Happy birthday kiddo. It's been a little quiet around here on your birthday since you aren't around, but your mother and I know that you are making both your grandpa and us proud. We both know that living on your own can be tough but we believe in you one hundred percent, just keep following your dreams.^ Love, Dad ^ P.S. Here's some spending money to help you out on the farm. Good luck! %item money 5000 5001 %%"); - } - public static IModHelper ModHelper; public static IMonitor ModMonitor; - /// - /// Class to handle all birthday messages for this mod. - /// + /// Class to handle all birthday messages for this mod. public BirthdayMessages messages; - /// - /// Class to handle all birthday gifts for this mod. - /// + /// Class to handle all birthday gifts for this mod. public GiftManager giftManager; - /// - /// Checks if the current billboard is the daily quest screen or not. - /// + /// Checks if the current billboard is the daily quest screen or not. bool isDailyQuestBoard; + Dictionary othersBirthdays; - Dictionary othersBirthdays; /********* ** Public methods @@ -114,35 +81,54 @@ namespace Omegasis.HappyBirthday SaveEvents.AfterLoad += this.SaveEvents_AfterLoad; SaveEvents.BeforeSave += this.SaveEvents_BeforeSave; ControlEvents.KeyPressed += this.ControlEvents_KeyPressed; - MenuEvents.MenuChanged += MenuEvents_MenuChanged; - MenuEvents.MenuClosed += MenuEvents_MenuClosed; + MenuEvents.MenuChanged += this.MenuEvents_MenuChanged; + MenuEvents.MenuClosed += this.MenuEvents_MenuClosed; - - - GraphicsEvents.OnPostRenderGuiEvent += GraphicsEvents_OnPostRenderGuiEvent; - StardewModdingAPI.Events.GraphicsEvents.OnPostRenderHudEvent += GraphicsEvents_OnPostRenderHudEvent; + GraphicsEvents.OnPostRenderGuiEvent += this.GraphicsEvents_OnPostRenderGuiEvent; + StardewModdingAPI.Events.GraphicsEvents.OnPostRenderHudEvent += this.GraphicsEvents_OnPostRenderHudEvent; //MultiplayerSupport.initializeMultiplayerSupport(); - ModHelper = Helper; - ModMonitor = Monitor; + ModHelper = this.Helper; + ModMonitor = this.Monitor; - messages = new BirthdayMessages(); - giftManager = new GiftManager(); - messages.createBirthdayGreetings(); - isDailyQuestBoard = false; + this.messages = new BirthdayMessages(); + this.giftManager = new GiftManager(); + this.messages.createBirthdayGreetings(); + this.isDailyQuestBoard = false; - ModHelper.Events.Multiplayer.ModMessageReceived += Multiplayer_ModMessageReceived; + ModHelper.Events.Multiplayer.ModMessageReceived += this.Multiplayer_ModMessageReceived; - ModHelper.Events.Multiplayer.PeerDisconnected += Multiplayer_PeerDisconnected; + ModHelper.Events.Multiplayer.PeerDisconnected += this.Multiplayer_PeerDisconnected; this.othersBirthdays = new Dictionary(); - } - /// - /// Used to check for player disconnections. - /// - /// - /// + /// Get whether this instance can edit the given asset. + /// Basic metadata about the asset being loaded. + public bool CanEdit(IAssetInfo asset) + { + return asset.AssetNameEquals(@"Data\mail"); + } + + /// Edit a matched asset. + /// A helper which encapsulates metadata about an asset and enables changes to it. + public void Edit(IAssetData asset) + { + asset + .AsDictionary() + .Set("birthdayMom", "Dear @,^ Happy birthday sweetheart. It's been amazing watching you grow into the kind, hard working person that I've always dreamed that you would become. I hope you continue to make many more fond memories with the ones you love. ^ Love, Mom ^ P.S. Here's a little something that I made for you. %item object 221 1 %%"); + + asset + .AsDictionary() + .Set("birthdayDad", "Dear @,^ Happy birthday kiddo. It's been a little quiet around here on your birthday since you aren't around, but your mother and I know that you are making both your grandpa and us proud. We both know that living on your own can be tough but we believe in you one hundred percent, just keep following your dreams.^ Love, Dad ^ P.S. Here's some spending money to help you out on the farm. Good luck! %item money 5000 5001 %%"); + } + + + /********* + ** Private methods + *********/ + /// Used to check for player disconnections. + /// The event sender. + /// The event arguments. private void Multiplayer_PeerDisconnected(object sender, PeerDisconnectedEventArgs e) { this.othersBirthdays.Remove(e.Peer.PlayerID); @@ -150,60 +136,50 @@ namespace Omegasis.HappyBirthday private void Multiplayer_ModMessageReceived(object sender, ModMessageReceivedEventArgs e) { - if (e.FromModID == ModHelper.Multiplayer.ModID && e.Type==MultiplayerSupport.FSTRING_SendBirthdayMessageToOthers) + if (e.FromModID == ModHelper.Multiplayer.ModID && e.Type == MultiplayerSupport.FSTRING_SendBirthdayMessageToOthers) { string message = e.ReadAs(); - Game1.hudMessages.Add(new HUDMessage(message,1)); + Game1.hudMessages.Add(new HUDMessage(message, 1)); } if (e.FromModID == ModHelper.Multiplayer.ModID && e.Type == MultiplayerSupport.FSTRING_SendBirthdayInfoToOthers) { - KeyValuePair message = e.ReadAs>(); + KeyValuePair message = e.ReadAs>(); if (!this.othersBirthdays.ContainsKey(message.Key)) { - this.othersBirthdays.Add(message.Key,message.Value); + this.othersBirthdays.Add(message.Key, message.Value); MultiplayerSupport.SendBirthdayInfoToConnectingPlayer(e.FromPlayerID); - Monitor.Log("Got other player's birthday data from: "+ Game1.getFarmer(e.FromPlayerID).name); + this.Monitor.Log("Got other player's birthday data from: " + Game1.getFarmer(e.FromPlayerID).name); } else { //Brute force update birthday info if it has already been recevived but dont send birthday info again. this.othersBirthdays.Remove(message.Key); this.othersBirthdays.Add(message.Key, message.Value); - Monitor.Log("Got other player's birthday data from: " + Game1.getFarmer(e.FromPlayerID).name); + this.Monitor.Log("Got other player's birthday data from: " + Game1.getFarmer(e.FromPlayerID).name); } - - - } - } - /// - /// Used to check when a menu is closed. - /// - /// - /// + /// Used to check when a menu is closed. + /// The event sender. + /// The event arguments. private void MenuEvents_MenuClosed(object sender, EventArgsClickableMenuClosed e) { this.isDailyQuestBoard = false; } - - /// - /// Used to properly display hovertext for all events happening on a calendar day. - /// - /// - /// + /// Used to properly display hovertext for all events happening on a calendar day. + /// The event sender. + /// The event arguments. private void GraphicsEvents_OnPostRenderHudEvent(object sender, EventArgs e) { if (Game1.activeClickableMenu == null) return; - if (PlayerData == null) return; - if (PlayerData.BirthdaySeason == null) return; - if (PlayerData.BirthdaySeason.ToLower() != Game1.currentSeason.ToLower()) return; + if (this.PlayerData?.BirthdaySeason == null) return; + if (this.PlayerData.BirthdaySeason.ToLower() != Game1.currentSeason.ToLower()) return; if (Game1.activeClickableMenu is Billboard) { - if (isDailyQuestBoard) return; + if (this.isDailyQuestBoard) return; if ((Game1.activeClickableMenu as Billboard).calendarDays == null) return; //Game1.player.FarmerRenderer.drawMiniPortrat(Game1.spriteBatch, new Vector2(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 230 + (index - 1) / 7 * 32 * 4), 1f, 4f, 2, Game1.player); @@ -211,115 +187,96 @@ namespace Omegasis.HappyBirthday string hoverText = ""; List texts = new List(); - foreach (var clicky in (Game1.activeClickableMenu as Billboard).calendarDays) + foreach (var clicky in ((Billboard)Game1.activeClickableMenu).calendarDays) { if (clicky.containsPoint(Game1.getMouseX(), Game1.getMouseY())) { - if (!String.IsNullOrEmpty(clicky.hoverText)) - { + if (!string.IsNullOrEmpty(clicky.hoverText)) texts.Add(clicky.hoverText); //catches npc birhday names. - } - else if (!String.IsNullOrEmpty(clicky.name)) - { + else if (!string.IsNullOrEmpty(clicky.name)) texts.Add(clicky.name); //catches festival dates. - } } } - - for(int i = 0; i< texts.Count; i++) - { + for (int i = 0; i < texts.Count; i++) + { hoverText += texts[i]; //Append text. - if (i == texts.Count - 1) continue; - else - { + if (i != texts.Count - 1) hoverText += Environment.NewLine; //Append new line. - } } - if (!String.IsNullOrEmpty(hoverText)) + if (!string.IsNullOrEmpty(hoverText)) { - var oldText = Helper.Reflection.GetField(Game1.activeClickableMenu, "hoverText", true); + var oldText = this.Helper.Reflection.GetField(Game1.activeClickableMenu, "hoverText"); oldText.SetValue(hoverText); } - } } - /// - /// Used to show the farmer's portrait on the billboard menu. - /// - /// - /// + /// Used to show the farmer's portrait on the billboard menu. + /// The event sender. + /// The event arguments. private void GraphicsEvents_OnPostRenderGuiEvent(object sender, EventArgs e) { - if (Game1.activeClickableMenu == null) return; - //Don't do anything if birthday has not been chosen yet. - if (PlayerData == null) return; - + if (Game1.activeClickableMenu == null || this.isDailyQuestBoard) + return; + //Don't do anything if birthday has not been chosen yet. + if (this.PlayerData == null) + return; if (Game1.activeClickableMenu is Billboard) { - if (isDailyQuestBoard) return; - - if (!String.IsNullOrEmpty(PlayerData.BirthdaySeason)) + if (!string.IsNullOrEmpty(this.PlayerData.BirthdaySeason)) { - if (PlayerData.BirthdaySeason.ToLower() == Game1.currentSeason.ToLower()) + if (this.PlayerData.BirthdaySeason.ToLower() == Game1.currentSeason.ToLower()) { - int index = PlayerData.BirthdayDay; + int index = this.PlayerData.BirthdayDay; Game1.player.FarmerRenderer.drawMiniPortrat(Game1.spriteBatch, new Vector2(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 230 + (index - 1) / 7 * 32 * 4), 0.5f, 4f, 2, Game1.player); } } - foreach(var pair in this.othersBirthdays) + foreach (var pair in this.othersBirthdays) { int index = pair.Value.BirthdayDay; if (pair.Value.BirthdaySeason != Game1.currentSeason.ToLower()) continue; //Hide out of season birthdays. index = pair.Value.BirthdayDay; Game1.player.FarmerRenderer.drawMiniPortrat(Game1.spriteBatch, new Vector2(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 230 + (index - 1) / 7 * 32 * 4), 0.5f, 4f, 2, Game1.getFarmer(pair.Key)); } - } } - /// - /// Functionality to display the player's birthday on the billboard. - /// - /// - /// - public void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) + /// Functionality to display the player's birthday on the billboard. + /// The event sender. + /// The event arguments. + private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (Game1.activeClickableMenu == null) { - isDailyQuestBoard = false; + this.isDailyQuestBoard = false; return; } - if(Game1.activeClickableMenu is Billboard) + if (Game1.activeClickableMenu is Billboard) { - isDailyQuestBoard = ModHelper.Reflection.GetField((Game1.activeClickableMenu as Billboard), "dailyQuestBoard", true).GetValue(); - if (isDailyQuestBoard) return; + this.isDailyQuestBoard = ModHelper.Reflection.GetField((Game1.activeClickableMenu as Billboard), "dailyQuestBoard", true).GetValue(); + if (this.isDailyQuestBoard) return; - - - Texture2D text = new Texture2D(Game1.graphics.GraphicsDevice,1,1); + Texture2D text = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1); Color[] col = new Color[1]; col[0] = new Color(0, 0, 0, 1); text.SetData(col); - //players birthdy position rect=new .... + //players birthday position rect=new .... - if (!String.IsNullOrEmpty(PlayerData.BirthdaySeason)) + if (!string.IsNullOrEmpty(this.PlayerData.BirthdaySeason)) { - if (PlayerData.BirthdaySeason.ToLower() == Game1.currentSeason.ToLower()) + if (this.PlayerData.BirthdaySeason.ToLower() == Game1.currentSeason.ToLower()) { - int index = PlayerData.BirthdayDay; + int index = this.PlayerData.BirthdayDay; Rectangle birthdayRect = new Rectangle(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 200 + (index - 1) / 7 * 32 * 4, 124, 124); (Game1.activeClickableMenu as Billboard).calendarDays.Add(new ClickableTextureComponent("", birthdayRect, "", Game1.player.name + "'s Birthday", text, new Rectangle(0, 0, 124, 124), 1f, false)); - } } - foreach (var pair in this.othersBirthdays) { if (pair.Value.BirthdaySeason != Game1.currentSeason.ToLower()) continue; @@ -327,14 +284,9 @@ namespace Omegasis.HappyBirthday Rectangle otherBirthdayRect = new Rectangle(Game1.activeClickableMenu.xPositionOnScreen + 152 + (index - 1) % 7 * 32 * 4, Game1.activeClickableMenu.yPositionOnScreen + 200 + (index - 1) / 7 * 32 * 4, 124, 124); (Game1.activeClickableMenu as Billboard).calendarDays.Add(new ClickableTextureComponent("", otherBirthdayRect, "", Game1.getFarmer(pair.Key).name + "'s Birthday", text, new Rectangle(0, 0, 124, 124), 1f, false)); } - } } - - /********* - ** Private methods - *********/ /// The method invoked after a new day starts. /// The event sender. /// The event data. @@ -359,7 +311,7 @@ namespace Omegasis.HappyBirthday /// The event data. private void SaveEvents_AfterLoad(object sender, EventArgs e) { - this.DataFilePath = Path.Combine("data", Game1.player.Name + "_" + Game1.player.UniqueMultiplayerID+".json"); + this.DataFilePath = Path.Combine("data", Game1.player.Name + "_" + Game1.player.UniqueMultiplayerID + ".json"); // reset state this.VillagerQueue = new List(); @@ -396,13 +348,13 @@ namespace Omegasis.HappyBirthday { if (!Context.IsWorldReady || Game1.eventUp || Game1.isFestival()) return; - if (!this.HasChosenBirthday && Game1.activeClickableMenu == null && Game1.player.Name.ToLower()!="unnamed farmhand") + if (!this.HasChosenBirthday && Game1.activeClickableMenu == null && Game1.player.Name.ToLower() != "unnamed farmhand") { Game1.activeClickableMenu = new BirthdayMenu(this.PlayerData.BirthdaySeason, this.PlayerData.BirthdayDay, this.SetBirthday); this.CheckedForBirthday = false; } - if (!this.CheckedForBirthday && Game1.activeClickableMenu==null) + if (!this.CheckedForBirthday && Game1.activeClickableMenu == null) { this.CheckedForBirthday = true; @@ -440,28 +392,26 @@ namespace Omegasis.HappyBirthday { bool spouseMessage = false; //Used to determine if there is a valid spouse message for the player. If false load in the generic birthday wish. //Check if npc name is spouse's name. If no spouse then add in generic dialogue. - if (messages.spouseBirthdayWishes.ContainsKey(npc.Name) && Game1.player.isMarried()) + if (this.messages.spouseBirthdayWishes.ContainsKey(npc.Name) && Game1.player.isMarried()) { - Monitor.Log("Spouse Checks out"); + this.Monitor.Log("Spouse Checks out"); //Check to see if spouse message exists. - if (!String.IsNullOrEmpty(messages.spouseBirthdayWishes[npc.Name])) + if (!string.IsNullOrEmpty(this.messages.spouseBirthdayWishes[npc.Name])) { spouseMessage = true; - Dialogue d = new Dialogue(messages.spouseBirthdayWishes[npc.Name], npc); + Dialogue d = new Dialogue(this.messages.spouseBirthdayWishes[npc.Name], npc); npc.CurrentDialogue.Push(d); - if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(messages.spouseBirthdayWishes[npc.Name]); + if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(this.messages.spouseBirthdayWishes[npc.Name]); } else - { - Monitor.Log("No spouse message???", LogLevel.Warn); - } + this.Monitor.Log("No spouse message???", LogLevel.Warn); } - if (spouseMessage == false) + if (!spouseMessage) { //Load in - Dialogue d = new Dialogue(messages.birthdayWishes[npc.Name], npc); + Dialogue d = new Dialogue(this.messages.birthdayWishes[npc.Name], npc); npc.CurrentDialogue.Push(d); - if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(messages.birthdayWishes[npc.Name]); + if (npc.CurrentDialogue.ElementAt(0) != d) npc.setNewDialogue(this.messages.birthdayWishes[npc.Name]); } } } @@ -480,12 +430,11 @@ namespace Omegasis.HappyBirthday } //Don't constantly set the birthday menu. - if (Game1.activeClickableMenu != null) - { - if (Game1.activeClickableMenu.GetType() == typeof(BirthdayMenu)) return; - } + if (Game1.activeClickableMenu?.GetType() == typeof(BirthdayMenu)) + return; + // ask for birthday date - if (!this.HasChosenBirthday && Game1.activeClickableMenu==null) + if (!this.HasChosenBirthday && Game1.activeClickableMenu == null) { Game1.activeClickableMenu = new BirthdayMenu(this.PlayerData.BirthdaySeason, this.PlayerData.BirthdayDay, this.SetBirthday); this.CheckedForBirthday = false; @@ -501,7 +450,7 @@ namespace Omegasis.HappyBirthday { try { - giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name); + this.giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name); this.VillagerQueue.Remove(Game1.currentSpeaker.Name); } catch (Exception ex) @@ -511,15 +460,14 @@ namespace Omegasis.HappyBirthday } //Validate the gift and give it to the player. - if (giftManager.BirthdayGiftToReceive != null) + if (this.giftManager.BirthdayGiftToReceive != null) { - while (giftManager.BirthdayGiftToReceive.Name == "Error Item" || giftManager.BirthdayGiftToReceive.Name == "Rock" || giftManager.BirthdayGiftToReceive.Name == "???") - giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name); - Game1.player.addItemByMenuIfNecessaryElseHoldUp(giftManager.BirthdayGiftToReceive); - giftManager.BirthdayGiftToReceive = null; + while (this.giftManager.BirthdayGiftToReceive.Name == "Error Item" || this.giftManager.BirthdayGiftToReceive.Name == "Rock" || this.giftManager.BirthdayGiftToReceive.Name == "???") + this.giftManager.SetNextBirthdayGift(Game1.currentSpeaker.Name); + Game1.player.addItemByMenuIfNecessaryElseHoldUp(this.giftManager.BirthdayGiftToReceive); + this.giftManager.BirthdayGiftToReceive = null; } } - } /// Set the player's birthday/ @@ -564,12 +512,13 @@ namespace Omegasis.HappyBirthday try { if (!File.Exists(this.LegacyDataFilePath) || File.Exists(this.DataFilePath)) - if (this.PlayerData == null) this.PlayerData = new PlayerData(); - return; + { + if (this.PlayerData == null) + this.PlayerData = new PlayerData(); + } } - catch(Exception err) + catch { - err.ToString(); // migrate to new file try { @@ -590,10 +539,6 @@ namespace Omegasis.HappyBirthday this.Monitor.Log($"Error migrating data from the legacy 'Player_Birthdays' folder for the current player. Technical details:\n {ex}", LogLevel.Error); } } - } - - - } } diff --git a/GeneralMods/HappyBirthday/HappyBirthday.csproj b/GeneralMods/HappyBirthday/HappyBirthday.csproj index 6d571ee8..15023a81 100644 --- a/GeneralMods/HappyBirthday/HappyBirthday.csproj +++ b/GeneralMods/HappyBirthday/HappyBirthday.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ HappyBirthday v4.5 512 - - true @@ -71,9 +69,10 @@ MinimumRecommendedRules.ruleset - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll - + + + + @@ -98,22 +97,11 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/HappyBirthday/manifest.json b/GeneralMods/HappyBirthday/manifest.json index 54b399eb..eceefd57 100644 --- a/GeneralMods/HappyBirthday/manifest.json +++ b/GeneralMods/HappyBirthday/manifest.json @@ -2,7 +2,6 @@ "Name": "Happy Birthday", "Author": "Alpha_Omegasis", "Version": "1.8.2", - "MinimumApiVersion": "1.15", "Description": "Adds the farmer's birthday to the game.", "UniqueID": "Omegasis.HappyBirthday", "EntryDll": "HappyBirthday.dll", diff --git a/GeneralMods/HappyBirthday/packages.config b/GeneralMods/HappyBirthday/packages.config deleted file mode 100644 index b8b15c8e..00000000 --- a/GeneralMods/HappyBirthday/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/GeneralMods/MapEvents/EventSystem.cs b/GeneralMods/MapEvents/EventSystem.cs index a173367e..8b11646c 100644 --- a/GeneralMods/MapEvents/EventSystem.cs +++ b/GeneralMods/MapEvents/EventSystem.cs @@ -1,31 +1,25 @@ -using EventSystem.Framework; -using StardewModdingAPI; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using EventSystem.Framework; +using StardewModdingAPI; namespace EventSystem -{ - /* - *TODO: Make Bed/Sleep Event. - * - * - */ - public class EventSystem: Mod +{ + // TODO: Make Bed/Sleep Event. + public class EventSystem : Mod { public static IModHelper ModHelper; public static IMonitor ModMonitor; public static EventManager eventManager; + + /// The mod entry point, called after the mod is first loaded. + /// Provides simplified APIs for writing mods. public override void Entry(IModHelper helper) { - ModHelper = this.Helper; ModMonitor = this.Monitor; - StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick; - StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; + StardewModdingAPI.Events.GameEvents.UpdateTick += this.GameEvents_UpdateTick; + StardewModdingAPI.Events.SaveEvents.AfterLoad += this.SaveEvents_AfterLoad; } private void SaveEvents_AfterLoad(object sender, EventArgs e) @@ -35,8 +29,7 @@ namespace EventSystem private void GameEvents_UpdateTick(object sender, EventArgs e) { - if (eventManager == null) return; - eventManager.update(); + eventManager?.update(); } } } diff --git a/GeneralMods/MapEvents/EventSystem.csproj b/GeneralMods/MapEvents/EventSystem.csproj index 8dd8ec3a..227d5cbf 100644 --- a/GeneralMods/MapEvents/EventSystem.csproj +++ b/GeneralMods/MapEvents/EventSystem.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ EventSystem v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -92,24 +93,7 @@ - - - - + - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - \ No newline at end of file diff --git a/GeneralMods/MapEvents/Framework/Delegates.cs b/GeneralMods/MapEvents/Framework/Delegates.cs index 617d0080..1447e614 100644 --- a/GeneralMods/MapEvents/Framework/Delegates.cs +++ b/GeneralMods/MapEvents/Framework/Delegates.cs @@ -1,8 +1,4 @@ -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EventSystem.Framework { diff --git a/GeneralMods/MapEvents/Framework/EventManager.cs b/GeneralMods/MapEvents/Framework/EventManager.cs index e4ddeb32..6be0aedb 100644 --- a/GeneralMods/MapEvents/Framework/EventManager.cs +++ b/GeneralMods/MapEvents/Framework/EventManager.cs @@ -1,9 +1,5 @@ -using StardewValley; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using StardewValley; namespace EventSystem.Framework { @@ -11,111 +7,80 @@ namespace EventSystem.Framework { public Dictionary> mapEvents; - /// - /// Constructor. - /// + /// Construct an instance. public EventManager() { this.mapEvents = new Dictionary>(); - foreach(var v in Game1.locations) - { - addLocation(v.Name, false); - } + foreach (var v in Game1.locations) + this.addLocation(v.Name, false); } - /// - /// Adds an event to the map given the name of the map. - /// - /// - /// - public virtual void addEvent(string mapName,MapEvent mapEvent) - { - foreach(var pair in this.mapEvents) - { - if (pair.Key.Name == mapName) - { - pair.Value.Add(mapEvent); - } - } - } - - /// - /// Adds an event to a map. - /// - /// - /// - public virtual void addEvent(GameLocation Location, MapEvent mapEvent) + /// Adds an event to the map given the name of the map. + public virtual void addEvent(string mapName, MapEvent mapEvent) { foreach (var pair in this.mapEvents) { - if (pair.Key == Location) - { - + if (pair.Key.Name == mapName) pair.Value.Add(mapEvent); - } } } - /// - /// Adds a location to have events handled. - /// - /// The location to handle events. - public virtual void addLocation(GameLocation Location) + /// Adds an event to a map. + public virtual void addEvent(GameLocation location, MapEvent mapEvent) { - EventSystem.ModMonitor.Log("Adding event processing for location: " + Location.Name); - this.mapEvents.Add(Location, new List()); + foreach (var pair in this.mapEvents) + { + if (pair.Key == location) + pair.Value.Add(mapEvent); + } } - /// - /// Adds a location to have events handled. - /// - /// - /// - public virtual void addLocation(GameLocation Location,List Events) + /// Adds a location to have events handled. + /// The location to handle events. + public virtual void addLocation(GameLocation location) { - EventSystem.ModMonitor.Log("Adding event processing for location: " + Location.Name); - this.mapEvents.Add(Location, Events); + EventSystem.ModMonitor.Log($"Adding event processing for location: {location.Name}"); + this.mapEvents.Add(location, new List()); } - /// - /// Adds a location to handle events. - /// - /// The name of the location. Can include farm buildings. + /// Adds a location to have events handled. + public virtual void addLocation(GameLocation location, List events) + { + EventSystem.ModMonitor.Log($"Adding event processing for location: {location.Name}"); + this.mapEvents.Add(location, events); + } + + /// Adds a location to handle events. + /// The name of the location. Can include farm buildings. /// Used if the building is a stucture. True=building. - public virtual void addLocation(string Location,bool isStructure) + public virtual void addLocation(string location, bool isStructure) { - EventSystem.ModMonitor.Log("Adding event processing for location: " + Location); - this.mapEvents.Add(Game1.getLocationFromName(Location,isStructure), new List()); + EventSystem.ModMonitor.Log($"Adding event processing for location: {location}"); + this.mapEvents.Add(Game1.getLocationFromName(location, isStructure), new List()); } - /// - /// Adds a location to have events handled. - /// - /// The name of the location. Can include farm buildings. + /// Adds a location to have events handled. + /// The name of the location. Can include farm buildings. /// Used if the building is a stucture. True=building. - /// A list of pre-initialized events. - public virtual void addLocation(string Location, bool isStructure, List Events) + /// A list of pre-initialized events. + public virtual void addLocation(string location, bool isStructure, List events) { - EventSystem.ModMonitor.Log("Adding event processing for location: " + Location); - this.mapEvents.Add(Game1.getLocationFromName(Location,isStructure), Events); + EventSystem.ModMonitor.Log($"Adding event processing for location: {location}"); + this.mapEvents.Add(Game1.getLocationFromName(location, isStructure), events); } - /// - /// Updates all events associated with the event manager. - /// + /// Updates all events associated with the event manager. public virtual void update() { - List events = new List(); - if (Game1.player == null) return; - if (Game1.hasLoadedGame == false) return; - bool ok=this.mapEvents.TryGetValue(Game1.player.currentLocation, out events); - if (ok == false) return; - else + if (Game1.player == null) + return; + if (!Game1.hasLoadedGame) + return; + + if (this.mapEvents.TryGetValue(Game1.player.currentLocation, out List events)) { - foreach(var v in events) - { + foreach (var v in events) v.update(); - } } } } diff --git a/GeneralMods/MapEvents/Framework/Events/DialogueDisplayEvent.cs b/GeneralMods/MapEvents/Framework/Events/DialogueDisplayEvent.cs index 54e143c1..fec23321 100644 --- a/GeneralMods/MapEvents/Framework/Events/DialogueDisplayEvent.cs +++ b/GeneralMods/MapEvents/Framework/Events/DialogueDisplayEvent.cs @@ -1,19 +1,15 @@ -using EventSystem.Framework.FunctionEvents; -using EventSystem.Framework.Information; +using EventSystem.Framework.FunctionEvents; using Microsoft.Xna.Framework; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EventSystem.Framework.Events { - public class DialogueDisplayEvent :MapEvent + public class DialogueDisplayEvent : MapEvent { - string dialogue; - public DialogueDisplayEvent(string Name, GameLocation Location, Vector2 Position, MouseButtonEvents MouseEvents,MouseEntryLeaveEvent EntryLeave, string Dialogue) : base(Name, Location, Position) + private readonly string dialogue; + + public DialogueDisplayEvent(string Name, GameLocation Location, Vector2 Position, MouseButtonEvents MouseEvents, MouseEntryLeaveEvent EntryLeave, string Dialogue) + : base(Name, Location, Position) { this.name = Name; this.location = Location; @@ -26,18 +22,15 @@ namespace EventSystem.Framework.Events this.mouseEntryLeaveEvents = EntryLeave; } - public override bool OnLeftClick() { - if (base.OnLeftClick() == false) return false; - if (this.location.isObjectAt((int)this.tilePosition.X*Game1.tileSize, (int)this.tilePosition.Y*Game1.tileSize)) return false; + if (!base.OnLeftClick()) return false; + if (this.location.isObjectAt((int)this.tilePosition.X * Game1.tileSize, (int)this.tilePosition.Y * Game1.tileSize)) return false; Game1.activeClickableMenu = new StardewValley.Menus.DialogueBox(this.dialogue); return true; } - /// - /// Used to update the event and check for interaction. - /// + /// Used to update the event and check for interaction. public override void update() { this.clickEvent(); @@ -45,6 +38,5 @@ namespace EventSystem.Framework.Events this.OnMouseEnter(); this.OnMouseLeave(); } - } } diff --git a/GeneralMods/MapEvents/Framework/Events/WarpEvent.cs b/GeneralMods/MapEvents/Framework/Events/WarpEvent.cs index ac661f48..360f3e3d 100644 --- a/GeneralMods/MapEvents/Framework/Events/WarpEvent.cs +++ b/GeneralMods/MapEvents/Framework/Events/WarpEvent.cs @@ -1,31 +1,23 @@ -using EventSystem.Framework.FunctionEvents; +using EventSystem.Framework.FunctionEvents; using EventSystem.Framework.Information; using Microsoft.Xna.Framework; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EventSystem.Framework.Events { - /// - /// Used to handle warp events on the map. - /// - public class WarpEvent :MapEvent + /// Used to handle warp events on the map. + public class WarpEvent : MapEvent { - WarpInformation warpInfo; + private readonly WarpInformation warpInfo; - /// - /// Constructor for handling warp events. - /// + /// Constructor for handling warp events. /// The name of the event. /// The game location that this event is located at. /// The x,y tile position of the event. /// The events to occur when the player enters the warp tile before the warp. /// The information for warping the farmer. - public WarpEvent(string Name, GameLocation Location, Vector2 Position, PlayerEvents playerEvents,WarpInformation WarpInfo) : base(Name, Location, Position, playerEvents) + public WarpEvent(string Name, GameLocation Location, Vector2 Position, PlayerEvents playerEvents, WarpInformation WarpInfo) + : base(Name, Location, Position, playerEvents) { this.name = Name; this.location = Location; @@ -36,38 +28,28 @@ namespace EventSystem.Framework.Events this.doesInteractionNeedToRun = true; } - /// - /// Occurs when the player enters the warp tile event position. - /// + /// Occurs when the player enters the warp tile event position. public override bool OnPlayerEnter() { - if (base.OnPlayerEnter() == false) return false; - else - { - - Game1.warpFarmer(this.warpInfo.targetMapName, this.warpInfo.targetX, this.warpInfo.targetY, this.warpInfo.facingDirection, this.warpInfo.isStructure); - return true; - } - } + if (!base.OnPlayerEnter()) + return false; - /// - /// Runs when the player is not on the tile and resets player interaction. - /// - public override bool OnPlayerLeave() - { - if (base.OnPlayerLeave() == false) return false; + Game1.warpFarmer(this.warpInfo.targetMapName, this.warpInfo.targetX, this.warpInfo.targetY, this.warpInfo.facingDirection, this.warpInfo.isStructure); return true; } - /// - /// Used to update the event and check for interaction. - /// + /// Runs when the player is not on the tile and resets player interaction. + public override bool OnPlayerLeave() + { + if (!base.OnPlayerLeave()) return false; + return true; + } + + /// Used to update the event and check for interaction. public override void update() { this.OnPlayerEnter(); this.OnPlayerLeave(); } - - } } diff --git a/GeneralMods/MapEvents/Framework/FunctionEvents/MouseButtonEvents.cs b/GeneralMods/MapEvents/Framework/FunctionEvents/MouseButtonEvents.cs index 634f9086..f2d921e7 100644 --- a/GeneralMods/MapEvents/Framework/FunctionEvents/MouseButtonEvents.cs +++ b/GeneralMods/MapEvents/Framework/FunctionEvents/MouseButtonEvents.cs @@ -1,43 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace EventSystem.Framework.FunctionEvents { - /// - /// Used to handle mouse interactions with button clicks and scrolling the mouse wheel. - /// + /// Used to handle mouse interactions with button clicks and scrolling the mouse wheel. public class MouseButtonEvents { - /// - /// Function that runs when the user left clicks. - /// + /// Function that runs when the user left clicks. public functionEvent onLeftClick; - /// - /// Function that runs when the user right clicks. - /// + + /// Function that runs when the user right clicks. public functionEvent onRightClick; - /// - /// Function that runs when the user scrolls the mouse wheel. - /// + + /// Function that runs when the user scrolls the mouse wheel. public functionEvent onMouseScroll; - /// - /// A constructor used to set a single function to a mouse button. - /// + /// A constructor used to set a single function to a mouse button. /// /// If true the function is set to the left click. If false the function is set to the right click. public MouseButtonEvents(functionEvent clickFunction, bool leftClick) { - if (leftClick == true) this.onLeftClick = clickFunction; + if (leftClick) this.onLeftClick = clickFunction; else this.onRightClick = clickFunction; } - /// - /// A constructor used to map functions to mouse clicks. - /// + /// A constructor used to map functions to mouse clicks. /// A function to be ran when the mouse left clicks this position. /// A function to be ran when the mouse right clicks this position. public MouseButtonEvents(functionEvent OnLeftClick, functionEvent OnRightClick) @@ -46,13 +30,11 @@ namespace EventSystem.Framework.FunctionEvents this.onRightClick = OnRightClick; } - /// - /// A constructor used to map functions to mouse clicks and scrolling the mouse wheel. - /// + /// A constructor used to map functions to mouse clicks and scrolling the mouse wheel. /// A function to be ran when the mouse left clicks this position. /// A function to be ran when the mouse right clicks this position. /// A function to be ran when the user scrolls the mouse - public MouseButtonEvents(functionEvent OnLeftClick,functionEvent OnRightClick, functionEvent OnMouseScroll) + public MouseButtonEvents(functionEvent OnLeftClick, functionEvent OnRightClick, functionEvent OnMouseScroll) { this.onLeftClick = OnLeftClick; this.onRightClick = OnRightClick; diff --git a/GeneralMods/MapEvents/Framework/FunctionEvents/MouseEntryLeaveEvent.cs b/GeneralMods/MapEvents/Framework/FunctionEvents/MouseEntryLeaveEvent.cs index 7ae55635..1a7e408b 100644 --- a/GeneralMods/MapEvents/Framework/FunctionEvents/MouseEntryLeaveEvent.cs +++ b/GeneralMods/MapEvents/Framework/FunctionEvents/MouseEntryLeaveEvent.cs @@ -1,28 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace EventSystem.Framework.FunctionEvents { - /// - /// Used to handle events that happens when a mouse enters/leaves a specified position. - /// + /// Used to handle events that happens when a mouse enters/leaves a specified position. public class MouseEntryLeaveEvent { - /// - /// A function that is called when a mouse enters a certain position. - /// + /// A function that is called when a mouse enters a certain position. public functionEvent onMouseEnter; - /// - /// A function that is called when a mouse leaves a certain position. - /// + + /// A function that is called when a mouse leaves a certain position. public functionEvent onMouseLeave; - /// - /// Constructor. - /// + /// Construct an instance. /// The function that occurs when the mouse enters a certain position. /// The function that occurs when the mouse leaves a certain position. public MouseEntryLeaveEvent(functionEvent OnMouseEnter, functionEvent OnMouseLeave) diff --git a/GeneralMods/MapEvents/Framework/FunctionEvents/PlayerEvents.cs b/GeneralMods/MapEvents/Framework/FunctionEvents/PlayerEvents.cs index e29d55ae..bc30d63d 100644 --- a/GeneralMods/MapEvents/Framework/FunctionEvents/PlayerEvents.cs +++ b/GeneralMods/MapEvents/Framework/FunctionEvents/PlayerEvents.cs @@ -1,30 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace EventSystem.Framework.FunctionEvents { - /// - /// Used to handle various functions that occur on player interaction. - /// + /// Used to handle various functions that occur on player interaction. public class PlayerEvents { - /// - /// Occurs when the player enters the same tile as this event. - /// + /// Occurs when the player enters the same tile as this event. public functionEvent onPlayerEnter; - /// - /// Occurs when the player leaves the same tile as this event. - /// + + /// Occurs when the player leaves the same tile as this event. public functionEvent onPlayerLeave; - /// - /// Constructor. - /// - /// - /// + /// Construct an instance. + /// Occurs when the player enters the same tile as this event. + /// Occurs when the player leaves the same tile as this event. public PlayerEvents(functionEvent OnPlayerEnter, functionEvent OnPlayerLeave) { this.onPlayerEnter = OnPlayerEnter; diff --git a/GeneralMods/MapEvents/Framework/FunctionEvents/functionEvent.cs b/GeneralMods/MapEvents/Framework/FunctionEvents/functionEvent.cs index 896c2050..b3b0ff33 100644 --- a/GeneralMods/MapEvents/Framework/FunctionEvents/functionEvent.cs +++ b/GeneralMods/MapEvents/Framework/FunctionEvents/functionEvent.cs @@ -1,23 +1,15 @@ -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using static EventSystem.Framework.Delegates; namespace EventSystem.Framework { - /// - /// Used to pair a function and a parameter list using the super object class to run virtually any function for map events. - /// + /// Used to pair a function and a parameter list using the super object class to run virtually any function for map events. public class functionEvent { public paramFunction function; public List parameters; - /// - /// Constructor. - /// + /// Construct an instance. /// The function to be called when running an event. /// The list of system.objects to be used in the function. Can include objects,strings, ints, etc. Anything can be passed in as a parameter or can be passed in as empty. Passing in null will just create an empty list. public functionEvent(paramFunction Function, List Parameters) @@ -27,17 +19,13 @@ namespace EventSystem.Framework this.parameters = Parameters; } - /// - /// Runs the function with the passed in parameters. - /// + /// Runs the function with the passed in parameters. public void run() { this.function.Invoke(this.parameters); } - /// - /// Simply swaps out the old parameters list for a new one. - /// + /// Simply swaps out the old parameters list for a new one. /// public void updateParameters(List newParameters) { diff --git a/GeneralMods/MapEvents/Framework/Information/WarpInformation.cs b/GeneralMods/MapEvents/Framework/Information/WarpInformation.cs index 7cda2745..f63a4031 100644 --- a/GeneralMods/MapEvents/Framework/Information/WarpInformation.cs +++ b/GeneralMods/MapEvents/Framework/Information/WarpInformation.cs @@ -1,14 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace EventSystem.Framework.Information { - /// - /// Used to store all of the information necessary to warp the farmer. - /// + /// Used to store all of the information necessary to warp the farmer. public class WarpInformation { public string targetMapName; @@ -17,15 +9,13 @@ namespace EventSystem.Framework.Information public int facingDirection; public bool isStructure; - /// - /// Constructor used to bundle together necessary information to warp the player character. - /// + /// Constructor used to bundle together necessary information to warp the player character. /// The target map name to warp the farmer to. /// The target X location on the map to warp the farmer to. /// The target Y location on the map to warp the farmer to. /// The facing direction for the farmer to be facing after the warp. /// Used to determine the position to be warped to when leaving a structure. - public WarpInformation(string MapName, int TargetX,int TargetY, int FacingDirection, bool IsStructure) + public WarpInformation(string MapName, int TargetX, int TargetY, int FacingDirection, bool IsStructure) { this.targetMapName = MapName; this.targetX = TargetX; diff --git a/GeneralMods/MapEvents/Framework/MapEvent.cs b/GeneralMods/MapEvents/Framework/MapEvent.cs index fbf2913d..90e88983 100644 --- a/GeneralMods/MapEvents/Framework/MapEvent.cs +++ b/GeneralMods/MapEvents/Framework/MapEvent.cs @@ -1,27 +1,17 @@ -using EventSystem.Framework.FunctionEvents; +using EventSystem.Framework.FunctionEvents; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EventSystem.Framework { - /// - /// Base class used to handle map tile events. - /// + /// Base class used to handle map tile events. public class MapEvent { - /// - /// //MAKE NAME FOR EVENTS - /// - + /// //MAKE NAME FOR EVENTS public string name; - + public Vector2 tilePosition; public GameLocation location; @@ -41,84 +31,64 @@ namespace EventSystem.Framework *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #region + /// Empty Constructor. + public MapEvent() { } - - /// - /// Empty Constructor - /// - public MapEvent() - { - - } - - /// - /// A simple map event that doesn't do anything. - /// - /// - /// - public MapEvent(string name,GameLocation Location,Vector2 Position) + /// A simple map event that doesn't do anything. + public MapEvent(string name, GameLocation location, Vector2 position) { this.name = name; - this.location = Location; - this.tilePosition = Position; - } - - /// - /// A simple map function that runs when the player enters and leaves a tile. Set values to null for nothing to happen. - /// - /// The game location where the event is. I.E Farm, Town, Mine etc. - /// The x,y position on the map the event is. - /// Handles various events that runs when the player enters/leaves a tile, etc. - - public MapEvent(string name,GameLocation Location,Vector2 position, PlayerEvents PlayerEvents) - { - this.name = name; - this.location = Location; + this.location = location; this.tilePosition = position; - this.playerEvents = PlayerEvents; } - /// - /// A constructor that handles when the mouse leaves and enters a tile. - /// - /// The game location where the event is. - /// The x,y position of the tile at the game location. - /// A class used to handle mouse entry/leave events. - public MapEvent(string name,GameLocation Location, Vector2 Position, MouseEntryLeaveEvent mouseEvents) + /// A simple map function that runs when the player enters and leaves a tile. Set values to null for nothing to happen. + /// The game location where the event is. I.E Farm, Town, Mine etc. + /// The x,y position on the map the event is. + /// Handles various events that runs when the player enters/leaves a tile, etc. + public MapEvent(string name, GameLocation location, Vector2 position, PlayerEvents playerEvents) { this.name = name; - this.location = Location; - this.tilePosition = Position; + this.location = location; + this.tilePosition = position; + this.playerEvents = playerEvents; + } + + /// A constructor that handles when the mouse leaves and enters a tile. + /// The game location where the event is. + /// The x,y position of the tile at the game location. + /// A class used to handle mouse entry/leave events. + public MapEvent(string name, GameLocation location, Vector2 position, MouseEntryLeaveEvent mouseEvents) + { + this.name = name; + this.location = location; + this.tilePosition = position; this.mouseEntryLeaveEvents = mouseEvents; } - /// - /// A constructor that handles when the mouse leaves and enters a tile. - /// - /// The game location where the event is. - /// The x,y position of the tile at the game location. + /// A constructor that handles when the mouse leaves and enters a tile. + /// The game location where the event is. + /// The x,y position of the tile at the game location. /// A class used to handle mouse click/scroll events. - public MapEvent(string name,GameLocation Location, Vector2 Position, MouseButtonEvents mouseEvents) + public MapEvent(string name, GameLocation location, Vector2 position, MouseButtonEvents mouseEvents) { this.name = name; - this.location = Location; - this.tilePosition = Position; + this.location = location; + this.tilePosition = position; this.mouseButtonEvents = mouseEvents; } - /// - /// A constructor encapsulating player, mouse button, and mouse entry events. - /// - /// The game location for which the event is located. I.E Town, Farm, etc. - /// The x,y cordinates for this event to be located at. + /// A constructor encapsulating player, mouse button, and mouse entry events. + /// The game location for which the event is located. I.E Town, Farm, etc. + /// The x,y cordinates for this event to be located at. /// The events that occur associated with the player. I.E player entry, etc. /// The events associated with clicking a mouse button while on this tile. /// The events that occur when the mouse enters or leaves the same tile position as this event. - public MapEvent(string name,GameLocation Location, Vector2 Position, PlayerEvents playerEvents, MouseButtonEvents mouseButtonEvents, MouseEntryLeaveEvent mouseEntryLeaveEvents) + public MapEvent(string name, GameLocation location, Vector2 position, PlayerEvents playerEvents, MouseButtonEvents mouseButtonEvents, MouseEntryLeaveEvent mouseEntryLeaveEvents) { this.name = name; - this.location = Location; - this.tilePosition = Position; + this.location = location; + this.tilePosition = position; this.playerEvents = playerEvents; this.mouseButtonEvents = mouseButtonEvents; this.mouseEntryLeaveEvents = mouseEntryLeaveEvents; @@ -126,129 +96,109 @@ namespace EventSystem.Framework #endregion - /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Player related functions + /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Player related functions - *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ + *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ #region - /// - /// Occurs when the player enters the same tile as this event. The function associated with this event is then ran. - /// + /// Occurs when the player enters the same tile as this event. The function associated with this event is then ran. public virtual bool OnPlayerEnter() { if (this.playerEvents == null) return false; - if (isPlayerOnTile() == true && this.doesInteractionNeedToRun==true) + if (this.isPlayerOnTile() && this.doesInteractionNeedToRun) { this.playerOnTile = true; this.doesInteractionNeedToRun = false; - if (this.playerEvents.onPlayerEnter != null) this.playerEvents.onPlayerEnter.run(); + this.playerEvents.onPlayerEnter?.run(); return true; } return false; } - /// - /// Occurs when the player leaves the same tile that this event is on. The function associated with thie event is then ran. - /// + /// Occurs when the player leaves the same tile that this event is on. The function associated with thie event is then ran. public virtual bool OnPlayerLeave() { if (this.playerEvents == null) return false; - if (isPlayerOnTile() == false && this.playerOnTile==true){ + if (!this.isPlayerOnTile() && this.playerOnTile) + { this.playerOnTile = false; this.doesInteractionNeedToRun = true; - if (this.playerEvents.onPlayerLeave != null) this.playerEvents.onPlayerLeave.run(); + this.playerEvents.onPlayerLeave?.run(); return true; } return false; } - /// - /// Checks if the player is on the same tile as this event. - /// - /// + /// Checks if the player is on the same tile as this event. public virtual bool isPlayerOnTile() { - if (Game1.player.getTileX() == this.tilePosition.X && Game1.player.getTileY() == this.tilePosition.Y) return true; - else return false; + return + Game1.player.getTileX() == this.tilePosition.X + && Game1.player.getTileY() == this.tilePosition.Y; } #endregion - /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Mouse related functions + /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Mouse related functions - *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - */ + *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ #region - /// - /// Occurs when the player left clicks the same tile that this event is on. - /// + /// Occurs when the player left clicks the same tile that this event is on. public virtual bool OnLeftClick() { - if (this.mouseOnTile==false) return false; + if (!this.mouseOnTile) return false; if (this.mouseButtonEvents == null) return false; - if (this.mouseButtonEvents.onLeftClick != null) this.mouseButtonEvents.onLeftClick.run(); + this.mouseButtonEvents.onLeftClick?.run(); return true; } - /// - /// Occurs when the player right clicks the same tile that this event is on. - /// + /// Occurs when the player right clicks the same tile that this event is on. public virtual bool OnRightClick() { - if (this.mouseOnTile == false) return false; + if (!this.mouseOnTile) return false; if (this.mouseButtonEvents == null) return false; - if (this.mouseButtonEvents.onRightClick != null) this.mouseButtonEvents.onRightClick.run(); + this.mouseButtonEvents.onRightClick?.run(); return true; } - /// - /// Occurs when the mouse tile position is the same as this event's x,y position. - /// + /// Occurs when the mouse tile position is the same as this event's x,y position. public virtual bool OnMouseEnter() { if (this.mouseEntryLeaveEvents == null) return false; - if (isMouseOnTile()) + if (this.isMouseOnTile()) { this.mouseOnTile = true; - if (this.mouseEntryLeaveEvents.onMouseEnter != null) this.mouseEntryLeaveEvents.onMouseEnter.run(); + this.mouseEntryLeaveEvents.onMouseEnter?.run(); return true; } return false; } - /// - /// Occurs when the mouse tile position leaves the the same x,y position as this event. - /// + /// Occurs when the mouse tile position leaves the the same x,y position as this event. public virtual bool OnMouseLeave() { if (this.mouseEntryLeaveEvents == null) return false; - if (isMouseOnTile() == false && this.mouseOnTile == true) + if (!this.isMouseOnTile() && this.mouseOnTile) { this.mouseOnTile = false; - if (this.mouseEntryLeaveEvents.onMouseLeave != null) this.mouseEntryLeaveEvents.onMouseLeave.run(); + this.mouseEntryLeaveEvents.onMouseLeave?.run(); return true; } return false; } - /// - /// UNUSED!!!! - /// Occurs when the mouse is on the same position as the tile AND the user scrolls the mouse wheel. - /// + /// UNUSED!!!! Occurs when the mouse is on the same position as the tile AND the user scrolls the mouse wheel. public virtual bool OnMouseScroll() { - - if (isMouseOnTile() == false) return false; - if (this.mouseButtonEvents.onMouseScroll != null) this.mouseButtonEvents.onMouseScroll.run(); + if (!this.isMouseOnTile()) return false; + this.mouseButtonEvents.onMouseScroll?.run(); return true; } - /// - /// Checks if the mouse is on the tile. - /// - /// + /// Checks if the mouse is on the tile. public virtual bool isMouseOnTile() { Vector2 mousePosition = Game1.currentCursorTile; @@ -256,30 +206,27 @@ namespace EventSystem.Framework return false; } - /// - /// Occurs when the tile is clicked. Runs the appropriate event. - /// + /// Occurs when the tile is clicked. Runs the appropriate event. public virtual void clickEvent() { - if (this.mouseOnTile == false) return; - var mouseState=Mouse.GetState(); - if (mouseState.LeftButton == ButtonState.Pressed) OnLeftClick(); - if (mouseState.RightButton == ButtonState.Pressed) OnRightClick(); + if (!this.mouseOnTile) return; + var mouseState = Mouse.GetState(); + if (mouseState.LeftButton == ButtonState.Pressed) + this.OnLeftClick(); + if (mouseState.RightButton == ButtonState.Pressed) + this.OnRightClick(); } -#endregion + #endregion - - /// - /// Used to check if any sort of events need to run on this tile right now. - /// + /// Used to check if any sort of events need to run on this tile right now. public virtual void update() { if (Game1.activeClickableMenu != null) return; - clickEvent(); //click events - OnPlayerEnter(); //player enter events - OnPlayerLeave(); //player leave events - OnMouseEnter(); //on mouse enter events - OnMouseLeave(); //on mouse leave events. + this.clickEvent(); //click events + this.OnPlayerEnter(); //player enter events + this.OnPlayerLeave(); //player leave events + this.OnMouseEnter(); //on mouse enter events + this.OnMouseLeave(); //on mouse leave events. } } } diff --git a/GeneralMods/MapEvents/manifest.json b/GeneralMods/MapEvents/manifest.json index 4579d6f3..4c72d707 100644 --- a/GeneralMods/MapEvents/manifest.json +++ b/GeneralMods/MapEvents/manifest.json @@ -6,5 +6,5 @@ "UniqueID": "Omegasis.EventSystem", "EntryDll": "EventSystem.dll", "MinimumApiVersion": "2.0", - "UpdateKeys": [ ] + "UpdateKeys": [] } diff --git a/GeneralMods/MapEvents/packages.config b/GeneralMods/MapEvents/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/MapEvents/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/MoreRain/Framework/ModConfig.cs b/GeneralMods/MoreRain/Framework/ModConfig.cs index ce34e80f..791216b4 100644 --- a/GeneralMods/MoreRain/Framework/ModConfig.cs +++ b/GeneralMods/MoreRain/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.MoreRain.Framework +namespace Omegasis.MoreRain.Framework { /// The mod configuration. internal class ModConfig diff --git a/GeneralMods/MoreRain/MoreRain.cs b/GeneralMods/MoreRain/MoreRain.cs index 8b1adfbd..d17e32ba 100644 --- a/GeneralMods/MoreRain/MoreRain.cs +++ b/GeneralMods/MoreRain/MoreRain.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using Omegasis.MoreRain.Framework; using StardewModdingAPI; @@ -88,7 +88,6 @@ namespace Omegasis.MoreRain this.VerboseLog("It will be stormy tomorrow."); return; } - break; case "summer": @@ -143,7 +142,7 @@ namespace Omegasis.MoreRain } } - /// Log a message if is false. + /// Log a message if is false. /// The message to log. private void VerboseLog(string message) { diff --git a/GeneralMods/MoreRain/MoreRain.csproj b/GeneralMods/MoreRain/MoreRain.csproj index 3b5337c8..1517a05e 100644 --- a/GeneralMods/MoreRain/MoreRain.csproj +++ b/GeneralMods/MoreRain/MoreRain.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ MoreRain v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -81,19 +82,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/MoreRain/packages.config b/GeneralMods/MoreRain/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/MoreRain/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/MuseumRearranger/Framework/ModConfig.cs b/GeneralMods/MuseumRearranger/Framework/ModConfig.cs index f14ea7ad..923c969b 100644 --- a/GeneralMods/MuseumRearranger/Framework/ModConfig.cs +++ b/GeneralMods/MuseumRearranger/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.MuseumRearranger.Framework +namespace Omegasis.MuseumRearranger.Framework { /// The mod configuration. internal class ModConfig diff --git a/GeneralMods/MuseumRearranger/Framework/NewMuseumMenu.cs b/GeneralMods/MuseumRearranger/Framework/NewMuseumMenu.cs index dcef035a..a81eca27 100644 --- a/GeneralMods/MuseumRearranger/Framework/NewMuseumMenu.cs +++ b/GeneralMods/MuseumRearranger/Framework/NewMuseumMenu.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI; using StardewValley; diff --git a/GeneralMods/MuseumRearranger/MuseumRearranger.cs b/GeneralMods/MuseumRearranger/MuseumRearranger.cs index 98df59ee..8494f4ae 100644 --- a/GeneralMods/MuseumRearranger/MuseumRearranger.cs +++ b/GeneralMods/MuseumRearranger/MuseumRearranger.cs @@ -1,4 +1,4 @@ -using Omegasis.MuseumRearranger.Framework; +using Omegasis.MuseumRearranger.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; diff --git a/GeneralMods/MuseumRearranger/MuseumRearranger.csproj b/GeneralMods/MuseumRearranger/MuseumRearranger.csproj index 07ec6f76..7f1ced70 100644 --- a/GeneralMods/MuseumRearranger/MuseumRearranger.csproj +++ b/GeneralMods/MuseumRearranger/MuseumRearranger.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ MuseumRearranger v4.5 512 - - true @@ -69,6 +67,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -84,19 +85,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/MuseumRearranger/packages.config b/GeneralMods/MuseumRearranger/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/MuseumRearranger/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/NightOwl/Framework/ModConfig.cs b/GeneralMods/NightOwl/Framework/ModConfig.cs index 7dfcbed4..43edd686 100644 --- a/GeneralMods/NightOwl/Framework/ModConfig.cs +++ b/GeneralMods/NightOwl/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.NightOwl.Framework +namespace Omegasis.NightOwl.Framework { /// The mod configuration. internal class ModConfig @@ -25,9 +25,7 @@ public bool KeepStaminaAfterCollapse { get; set; } = true; - /// - /// Whether or not to use the internal NightFish asset editor. When false, it will just use the Fish.xnb file. - /// + /// Whether or not to use the internal NightFish asset editor. When false, it will just use the Fish.xnb file. public bool UseInternalNightFishAssetEditor { get; set; } = true; } } diff --git a/GeneralMods/NightOwl/Framework/NightFishing.cs b/GeneralMods/NightOwl/Framework/NightFishing.cs index 79541d6b..21b1f06c 100644 --- a/GeneralMods/NightOwl/Framework/NightFishing.cs +++ b/GeneralMods/NightOwl/Framework/NightFishing.cs @@ -1,9 +1,5 @@ -using StardewModdingAPI; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using StardewModdingAPI; namespace Omegasis.NightOwl.Framework { @@ -16,7 +12,7 @@ namespace Omegasis.NightOwl.Framework public void Edit(IAssetData asset) { - Dictionary nightFish=new Dictionary // (T)(object) is a trick to cast anything to T if we know it's compatible + Dictionary nightFish = new Dictionary // (T)(object) is a trick to cast anything to T if we know it's compatible { [128] = "Pufferfish/80/floater/1/36/1200 1600/summer/sunny/690 .4 685 .1/4/.3/.5/0", [129] = "Anchovy/30/dart/1/16/600 3000/spring fall/both/682 .2/1/.25/.3/0", @@ -82,10 +78,10 @@ namespace Omegasis.NightOwl.Framework [799] = "Spook Fish/60/dart/8/25/600 3000/spring summer fall winter/both/685 .35/3/.4/.1/0", [800] = "Blobfish/75/floater/8/25/600 3000/spring summer fall winter/both/685 .35/3/.4/.1/0", }; - foreach (KeyValuePair pair in nightFish) { + foreach (KeyValuePair pair in nightFish) + { asset.AsDictionary().Set(pair.Key, pair.Value); } } - } } diff --git a/GeneralMods/NightOwl/NightOwl.cs b/GeneralMods/NightOwl/NightOwl.cs index eb4a978e..41b37fbb 100644 --- a/GeneralMods/NightOwl/NightOwl.cs +++ b/GeneralMods/NightOwl/NightOwl.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -11,15 +11,11 @@ using StardewValley; using StardewValley.Characters; using StardewValley.Locations; -/*TODO: -Issues: --Mail can't be wiped without destroying all mail. --Lighting transition does not work if it is raining. - -set the weather to clear if you are stayig up late. - -transition still doesnt work. However atleast it is dark now. - --Known glitched -*/ +// TODO: +// -Mail can't be wiped without destroying all mail. +// -Lighting transition does not work if it is raining. +// -set the weather to clear if you are stayig up late. +// -transition still doesnt work. However atleast it is dark now. namespace Omegasis.NightOwl { /// The mod entry point. @@ -64,32 +60,21 @@ namespace Omegasis.NightOwl /// The player's health before they collapsed. private int PreCollapseHealth; - /// - /// Checks if the player was bathing or not before passing out. - /// + /// Checks if the player was bathing or not before passing out. private bool isBathing; - /// - /// Checks if the player was in their swimsuit before passing out. - /// + /// Checks if the player was in their swimsuit before passing out. private bool isInSwimSuit; - - /// - /// The horse the player was riding before they collapsed. - /// + + /// The horse the player was riding before they collapsed. private Horse horse; - /// - /// Determines whehther or not to rewarp the player's horse to them. - /// + /// Determines whehther or not to rewarp the player's horse to them. private bool shouldWarpHorse; - /// - /// Event in the night taht simulates the earthquake event that should happen. - /// + /// Event in the night taht simulates the earthquake event that should happen. StardewValley.Events.SoundInTheNightEvent eve; - private List oldAnimalHappiness; @@ -103,37 +88,28 @@ namespace Omegasis.NightOwl this.oldAnimalHappiness = new List(); this.Config = helper.ReadConfig(); - if (Config.UseInternalNightFishAssetEditor) - { + if (this.Config.UseInternalNightFishAssetEditor) this.Helper.Content.AssetEditors.Add(new NightFishing()); - } + TimeEvents.TimeOfDayChanged += this.TimeEvents_TimeOfDayChanged; TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted; SaveEvents.AfterLoad += this.SaveEvents_AfterLoad; SaveEvents.BeforeSave += this.SaveEvents_BeforeSave; GameEvents.FourthUpdateTick += this.GameEvents_FourthUpdateTick; - GameEvents.UpdateTick += GameEvents_UpdateTick; - shouldWarpHorse = false; + GameEvents.UpdateTick += this.GameEvents_UpdateTick; + this.shouldWarpHorse = false; } - /********* ** Private methods *********/ - - /// - /// Updates the earthquake event. - /// - /// - /// + /// Updates the earthquake event. + /// The event sender. + /// The event data. private void GameEvents_UpdateTick(object sender, EventArgs e) { - if (eve == null) return; - else - { - eve.tickUpdate(Game1.currentGameTime); - } + this.eve?.tickUpdate(Game1.currentGameTime); } /// The method invoked every fourth game update (roughly 15 times per second). @@ -160,7 +136,7 @@ namespace Omegasis.NightOwl this.WriteErrorLog(); } } - + /// The method invoked before the game saves. /// The event sender. /// The event data. @@ -170,17 +146,14 @@ namespace Omegasis.NightOwl string[] passOutFees = Game1.player.mailbox .Where(p => p.Contains("passedOut")) .ToArray(); - for (int idx=0; idx< passOutFees.Length; idx++) - { - string[] msg = passOutFees[idx].Split(' '); - collapseFee += Int32.Parse(msg[1]); - } - - if (this.Config.KeepMoneyAfterCollapse) - { - Game1.player.money += collapseFee; - } - + foreach (string fee in passOutFees) + { + string[] msg = fee.Split(' '); + collapseFee += int.Parse(msg[1]); + } + + if (this.Config.KeepMoneyAfterCollapse) + Game1.player.money += collapseFee; } /// The method invoked after the player loads a save. @@ -213,51 +186,39 @@ namespace Omegasis.NightOwl if (this.Config.KeepHealthAfterCollapse) Game1.player.health = this.PreCollapseHealth; if (this.Config.KeepPositionAfterCollapse) - if (Game1.weddingToday == false) - { + { + if (!Game1.weddingToday) Game1.warpFarmer(this.PreCollapseMap, this.PreCollapseTile.X, this.PreCollapseTile.Y, false); - } - if (horse != null && shouldWarpHorse==true) - { - Game1.warpCharacter(horse, Game1.player.currentLocation, Game1.player.position); - shouldWarpHorse = false; } - if (isInSwimSuit) + + if (this.horse != null && this.shouldWarpHorse) { + Game1.warpCharacter(this.horse, Game1.player.currentLocation, Game1.player.position); + this.shouldWarpHorse = false; + } + if (this.isInSwimSuit) Game1.player.changeIntoSwimsuit(); - } - if (isBathing) - { + if (this.isBathing) Game1.player.swimming.Value = true; - } + //Reflction to ensure that the railroad becomes properly unblocked. if (Game1.dayOfMonth == 1 && Game1.currentSeason == "summer" && Game1.year == 1) { Mountain mountain = (Mountain)Game1.getLocationFromName("Mountain"); - var reflect2 = Helper.Reflection.GetField(mountain, "railroadAreaBlocked", true); - var netBool2 = reflect2.GetValue(); + NetBool netBool2 = this.Helper.Reflection.GetField(mountain, "railroadAreaBlocked").GetValue(); netBool2.Value = false; - reflect2.SetValue(netBool2); + this.Helper.Reflection.GetField(mountain, "railroadBlockRect").SetValue(Rectangle.Empty); - var reflect3 = Helper.Reflection.GetField(mountain, "railroadBlockRect", true); - var netBool3 = reflect3.GetValue(); - netBool3 = new Rectangle(0, 0, 0, 0); - reflect3.SetValue(netBool3); - - - eve = new StardewValley.Events.SoundInTheNightEvent(4); - eve.setUp(); - eve.makeChangesToLocation(); - + this.eve = new StardewValley.Events.SoundInTheNightEvent(4); + this.eve.setUp(); + this.eve.makeChangesToLocation(); } } - if(Game1.currentSeason!="spring" && Game1.year >= 1) - { - clearRailRoadBlock(); - } + if (Game1.currentSeason != "spring" && Game1.year >= 1) + this.clearRailRoadBlock(); // delete annoying charge messages (if only I could do this with mail IRL) if (this.Config.SkipCollapseMail) @@ -280,23 +241,15 @@ namespace Omegasis.NightOwl } } - /// - /// If the user for this mod never gets the event that makes the railroad blok go away we will always force it to go away if they have met the conditions for it. I.E not being in spring of year 1. - /// + /// If the user for this mod never gets the event that makes the railroad blok go away we will always force it to go away if they have met the conditions for it. I.E not being in spring of year 1. private void clearRailRoadBlock() { Mountain mountain = (Mountain)Game1.getLocationFromName("Mountain"); - var reflect2 = Helper.Reflection.GetField(mountain, "railroadAreaBlocked", true); - var netBool2 = reflect2.GetValue(); + var netBool2 = this.Helper.Reflection.GetField(mountain, "railroadAreaBlocked").GetValue(); netBool2.Value = false; - reflect2.SetValue(netBool2); - - var reflect3 = Helper.Reflection.GetField(mountain, "railroadBlockRect", true); - var netBool3 = reflect3.GetValue(); - netBool3 = new Rectangle(0, 0, 0, 0); - reflect3.SetValue(netBool3); + this.Helper.Reflection.GetField(mountain, "railroadBlockRect").SetValue(Rectangle.Empty); } /// The method invoked when changes. @@ -322,11 +275,10 @@ namespace Omegasis.NightOwl Game1.isRaining = false; // remove rain, otherwise lighting gets screwy Game1.updateWeatherIcon(); Game1.timeOfDay = 150; //change it from 1:50 am late, to 1:50 am early - foreach(FarmAnimal animal in Game1.getFarm().getAllFarmAnimals()) + foreach (FarmAnimal animal in Game1.getFarm().getAllFarmAnimals()) { this.oldAnimalHappiness.Add(animal.happiness); } - } // collapse player at 6am to save & reset @@ -343,15 +295,11 @@ namespace Omegasis.NightOwl if (character is Horse) { (character as Horse).dismount(); - horse = (character as Horse); - shouldWarpHorse = true; + this.horse = (character as Horse); + this.shouldWarpHorse = true; } - - } - catch (Exception err) - { - } + catch { } } } this.JustCollapsed = true; @@ -366,7 +314,6 @@ namespace Omegasis.NightOwl this.isBathing = Game1.player.swimming.Value; - if (Game1.currentMinigame != null) Game1.currentMinigame = null; @@ -375,14 +322,12 @@ namespace Omegasis.NightOwl Game1.timeOfDay += 2400; //Recalculate for the sake of technically being up a whole day. //Reset animal happiness since it drains over night. - for(int i=0; i < oldAnimalHappiness.Count; i++) + for (int i = 0; i < this.oldAnimalHappiness.Count; i++) { - Game1.getFarm().getAllFarmAnimals()[i].happiness.Value = oldAnimalHappiness[i].Value; + Game1.getFarm().getAllFarmAnimals()[i].happiness.Value = this.oldAnimalHappiness[i].Value; } Game1.player.startToPassOut(); - - } } catch (Exception ex) @@ -412,10 +357,7 @@ namespace Omegasis.NightOwl this.Helper.WriteJsonFile(path, state); } - /// - /// Try and emulate the old Game1.shouldFarmerPassout logic. - /// - /// + /// Try and emulate the old Game1.shouldFarmerPassout logic. public bool shouldFarmerPassout() { if (Game1.player.stamina <= 0 || Game1.player.health <= 0 || Game1.timeOfDay >= 2600) return true; diff --git a/GeneralMods/NightOwl/NightOwl.csproj b/GeneralMods/NightOwl/NightOwl.csproj index a744fce1..7c0f46b8 100644 --- a/GeneralMods/NightOwl/NightOwl.csproj +++ b/GeneralMods/NightOwl/NightOwl.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ NightOwl v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -87,19 +88,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/NightOwl/packages.config b/GeneralMods/NightOwl/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/NightOwl/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/NoMorePets/NoMorePets.cs b/GeneralMods/NoMorePets/NoMorePets.cs index 07982c33..7b38c409 100644 --- a/GeneralMods/NoMorePets/NoMorePets.cs +++ b/GeneralMods/NoMorePets/NoMorePets.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using StardewModdingAPI; using StardewModdingAPI.Events; @@ -28,7 +28,7 @@ namespace Omegasis.NoMorePets /// The event sender. /// The event data. public void SaveEvents_AfterLoad(object sender, EventArgs e) - { + { foreach (Pet pet in Game1.player.currentLocation.getCharacters().OfType().ToArray()) pet.currentLocation.characters.Remove(pet); } diff --git a/GeneralMods/NoMorePets/NoMorePets.csproj b/GeneralMods/NoMorePets/NoMorePets.csproj index 9b5cef2a..d6478fbb 100644 --- a/GeneralMods/NoMorePets/NoMorePets.csproj +++ b/GeneralMods/NoMorePets/NoMorePets.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ NoMorePets v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -82,19 +83,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/NoMorePets/packages.config b/GeneralMods/NoMorePets/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/NoMorePets/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/Revitalize/Framework/Crafting/Recipe.cs b/GeneralMods/Revitalize/Framework/Crafting/Recipe.cs index 0a9d8589..40906ab2 100644 --- a/GeneralMods/Revitalize/Framework/Crafting/Recipe.cs +++ b/GeneralMods/Revitalize/Framework/Crafting/Recipe.cs @@ -1,10 +1,7 @@ -using Revitalize.Framework.Utilities; -using StardewValley; -using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Revitalize.Framework.Utilities; +using StardewValley; namespace Revitalize.Framework.Crafting { @@ -17,45 +14,32 @@ namespace Revitalize.Framework.Crafting public Item DisplayItem { - get - { - if (this.displayItem == null) return outputs.ElementAt(0).Key; - else - { - return displayItem; - } - } - set - { - this.displayItem = value; - } + get => this.displayItem ?? this.outputs.ElementAt(0).Key; + set => this.displayItem = value; } public string outputDescription; public string outputName; - public Recipe() - { + public Recipe() { } - } - - /// - /// Constructor for single item output. - /// + /// Constructor for single item output. /// All the ingredients required to make the output. /// The item given as output with how many - public Recipe(Dictionary inputs,KeyValuePair output) + public Recipe(Dictionary inputs, KeyValuePair output) { this.ingredients = inputs; this.DisplayItem = output.Key; this.outputDescription = output.Key.getDescription(); this.outputName = output.Key.DisplayName; - this.outputs = new Dictionary(); - this.outputs.Add(output.Key, output.Value); + this.outputs = new Dictionary + { + [output.Key] = output.Value + }; } - public Recipe(Dictionary inputs,Dictionary outputs,string OutputName, string OutputDescription,Item DisplayItem=null) + public Recipe(Dictionary inputs, Dictionary outputs, string OutputName, string OutputDescription, Item DisplayItem = null) { this.ingredients = inputs; this.outputs = outputs; @@ -64,165 +48,122 @@ namespace Revitalize.Framework.Crafting this.DisplayItem = DisplayItem; } - - /// - /// Checks if a player contains all recipe ingredients. - /// - /// + /// Checks if a player contains all recipe ingredients. public bool PlayerContainsAllIngredients() { - return InventoryContainsAllIngredient(Game1.player.Items.ToList()); + return this.InventoryContainsAllIngredient(Game1.player.Items.ToList()); } - /// - /// Checks if a player contains a recipe ingredient. - /// - /// - /// - public bool PlayerContainsIngredient(KeyValuePair pair) + /// Checks if a player contains a recipe ingredient. + public bool PlayerContainsIngredient(KeyValuePair pair) { - return InventoryContainsIngredient(Game1.player.Items.ToList(), pair); + return this.InventoryContainsIngredient(Game1.player.Items.ToList(), pair); } - - /// - /// Checks if an inventory contains all items. - /// - /// - /// + /// Checks if an inventory contains all items. public bool InventoryContainsAllIngredient(List items) { foreach (KeyValuePair pair in this.ingredients) - { - if (InventoryContainsIngredient(items,pair) == false) return false; - } + if (!this.InventoryContainsIngredient(items, pair)) return false; return true; } - /// - /// Checks if an inventory contains an ingredient. - /// - /// - /// - /// - public bool InventoryContainsIngredient(List items,KeyValuePair pair) + /// Checks if an inventory contains an ingredient. + public bool InventoryContainsIngredient(List items, KeyValuePair pair) { foreach (Item i in items) { - if (i == null) continue; - if (ItemEqualsOther(i, pair.Key) && pair.Value == i.Stack) - { + if (i != null && this.ItemEqualsOther(i, pair.Key) && pair.Value == i.Stack) return true; - } } return false; } - - /// - /// Checks roughly if two items equal each other. - /// - /// - /// - /// + /// Checks roughly if two items equal each other. public bool ItemEqualsOther(Item self, Item other) { - if (self.Name == other.Name && self.getCategoryName() == other.getCategoryName() && self.GetType() == other.GetType()) return true; - return false; + return + self.Name == other.Name + && self.getCategoryName() == other.getCategoryName() + && self.GetType() == other.GetType(); } public void consume(ref List from) { - if (!InventoryContainsAllIngredient(from)) return; + if (!this.InventoryContainsAllIngredient(from)) + return; + InventoryManager manager = new InventoryManager(from); - List removalList = new List(); - - foreach (KeyValuePair pair in this.ingredients) + foreach (KeyValuePair pair in this.ingredients) { - foreach(Item InventoryItem in manager.items) + foreach (Item item in manager.items) { - if (InventoryItem == null) continue; - if (ItemEqualsOther(InventoryItem, pair.Key)) + if (item == null) continue; + if (this.ItemEqualsOther(item, pair.Key)) { - if (InventoryItem.Stack == pair.Value) - { - removalList.Add(InventoryItem); //remove the item - } + if (item.Stack == pair.Value) + removalList.Add(item); //remove the item else - { - InventoryItem.Stack -= pair.Value; //or reduce the stack size. - } + item.Stack -= pair.Value; //or reduce the stack size. } } } foreach (var v in removalList) - { manager.items.Remove(v); - } removalList.Clear(); from = manager.items; } - public void produce(ref List to,bool dropToGround=false,bool isPlayerInventory=false) + public void produce(ref List to, bool dropToGround = false, bool isPlayerInventory = false) { - InventoryManager manager; - if (isPlayerInventory == true) + var manager = isPlayerInventory + ? new InventoryManager(new List()) + : new InventoryManager(to); + foreach (KeyValuePair pair in this.outputs) { - manager = new InventoryManager(new List()); - } - else - { - manager = new InventoryManager(to); - } - foreach(KeyValuePair pair in this.outputs) - { - Item I = pair.Key.getOne(); - I.addToStack(pair.Value - 1); - bool added=manager.addItem(I); - if (added == false && dropToGround==true) - { - Game1.createItemDebris(I, Game1.player.getStandingPosition(), Game1.player.getDirection()); - } + Item item = pair.Key.getOne(); + item.addToStack(pair.Value - 1); + bool added = manager.addItem(item); + if (!added && dropToGround) + Game1.createItemDebris(item, Game1.player.getStandingPosition(), Game1.player.getDirection()); } to = manager.items; } - public void craft(ref List from,ref List to,bool dropToGround=false,bool isPlayerInventory=false) + public void craft(ref List from, ref List to, bool dropToGround = false, bool isPlayerInventory = false) { InventoryManager manager = new InventoryManager(to); if (manager.ItemCount + this.outputs.Count >= manager.capacity) { - if (isPlayerInventory) Game1.showRedMessage("Inventory Full"); + if (isPlayerInventory) + Game1.showRedMessage("Inventory Full"); else return; } - consume(ref from); - produce(ref to,dropToGround,isPlayerInventory); + this.consume(ref from); + this.produce(ref to, dropToGround, isPlayerInventory); } public void craft() { List playerItems = Game1.player.Items.ToList(); List outPutItems = new List(); - craft(ref playerItems,ref outPutItems, true,true); + this.craft(ref playerItems, ref outPutItems, true, true); Game1.player.Items = playerItems; //Set the items to be post consumption. - foreach(Item I in outPutItems) - { + foreach (Item I in outPutItems) Game1.player.addItemToInventory(I); //Add all items produced. - } } public bool PlayerCanCraft() { - return PlayerContainsAllIngredients(); + return this.PlayerContainsAllIngredients(); } public bool CanCraft(List items) { - return InventoryContainsAllIngredient(items); + return this.InventoryContainsAllIngredient(items); } - } } diff --git a/GeneralMods/Revitalize/Framework/Environment/DarkerNight.cs b/GeneralMods/Revitalize/Framework/Environment/DarkerNight.cs index f2075411..c0b505cf 100644 --- a/GeneralMods/Revitalize/Framework/Environment/DarkerNight.cs +++ b/GeneralMods/Revitalize/Framework/Environment/DarkerNight.cs @@ -1,108 +1,80 @@ -using StardewValley; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Revitalize.Framework.Illuminate; using System.IO; using Microsoft.Xna.Framework; +using StardewValley; namespace Revitalize.Framework.Environment { - /// - /// Deals with making night time darker in Stardew. - /// + /// Deals with making night time darker in Stardew. public class DarkerNight { - - /// - /// Darkness intensity. - /// + /// Darkness intensity. public static float IncrediblyDark = 0.9f; - /// - /// Darkness intensity. - /// + + /// Darkness intensity. public static float VeryDark = 0.75f; - /// - /// Darkness intensity. - /// + + /// Darkness intensity. public static float SomewhatDark = 0.50f; - /// - /// The config file. - /// + /// The config file. public static DarkerNightConfig Config; - /// - /// The calculated night color. - /// + /// The calculated night color. private static Color CalculatedColor; - /// - /// Initializes the config for DarkerNight. - /// + /// Initializes the config for DarkerNight. public static void InitializeConfig() { - if (File.Exists(Path.Combine(Revitalize.ModCore.ModHelper.DirectoryPath, "Configs", "DarkerNightConfig.json"))) - { - Config = Revitalize.ModCore.ModHelper.Data.ReadJsonFile(Path.Combine("Configs", "DarkerNightConfig.json")); - } + if (File.Exists(Path.Combine(ModCore.ModHelper.DirectoryPath, "Configs", "DarkerNightConfig.json"))) + Config = ModCore.ModHelper.Data.ReadJsonFile(Path.Combine("Configs", "DarkerNightConfig.json")); else { Config = new DarkerNightConfig(); - Revitalize.ModCore.ModHelper.Data.WriteJsonFile(Path.Combine("Configs", "DarkerNightConfig.json"),Config); + ModCore.ModHelper.Data.WriteJsonFile(Path.Combine("Configs", "DarkerNightConfig.json"), Config); } } - /// - /// Sets the color of darkness at night. - /// + /// Sets the color of darkness at night. public static void SetDarkerColor() { - if (Config.Enabled == false) return; - if (Game1.player == null) return; - if (Game1.player.currentLocation == null) return; + if (!Config.Enabled || Game1.player?.currentLocation == null) + return; + if (Game1.player.currentLocation.IsOutdoors && Game1.timeOfDay >= Game1.getStartingToGetDarkTime()) - { Game1.outdoorLight = CalculatedColor; - } } - /// - /// Calculates how dark it should be a night. - /// + /// Calculates how dark it should be a night. public static void CalculateDarkerNightColor() { - if (Config.Enabled == false) return; - if (Game1.player == null) return; - if (Game1.player.currentLocation == null) return; + if (!Config.Enabled || Game1.player?.currentLocation == null) + return; + //Calculate original lighting. if (Game1.timeOfDay >= Game1.getTrulyDarkTime()) { - float num = Math.Min(0.93f, (float)(0.75 + ((double)((int)((double)(Game1.timeOfDay - Game1.timeOfDay % 100) + (double)(Game1.timeOfDay % 100 / 10) * 16.6599998474121) - Game1.getTrulyDarkTime()) + (double)Game1.gameTimeInterval / 7000.0 * 16.6000003814697) * 0.000624999986030161)); + float num = Math.Min(0.93f, (float)(0.75 + ((int)(Game1.timeOfDay - Game1.timeOfDay % 100 + Game1.timeOfDay % 100 / 10 * 16.6599998474121) - Game1.getTrulyDarkTime() + Game1.gameTimeInterval / 7000.0 * 16.6000003814697) * 0.000624999986030161)); Game1.outdoorLight = (Game1.isRaining ? Game1.ambientLight : Game1.eveningColor) * num; } else if (Game1.timeOfDay >= Game1.getStartingToGetDarkTime()) { - float num = Math.Min(0.93f, (float)(0.300000011920929 + ((double)((int)((double)(Game1.timeOfDay - Game1.timeOfDay % 100) + (double)(Game1.timeOfDay % 100 / 10) * 16.6599998474121) - Game1.getStartingToGetDarkTime()) + (double)Game1.gameTimeInterval / 7000.0 * 16.6000003814697) * 0.00224999990314245)); + float num = Math.Min(0.93f, (float)(0.300000011920929 + ((int)(Game1.timeOfDay - Game1.timeOfDay % 100 + Game1.timeOfDay % 100 / 10 * 16.6599998474121) - Game1.getStartingToGetDarkTime() + Game1.gameTimeInterval / 7000.0 * 16.6000003814697) * 0.00224999990314245)); Game1.outdoorLight = (Game1.isRaining ? Game1.ambientLight : Game1.eveningColor) * num; } - Revitalize.ModCore.log("OUT: " + Game1.outdoorLight); + ModCore.log("OUT: " + Game1.outdoorLight); int red = Game1.outdoorLight.R; - if (Game1.player.currentLocation.IsOutdoors && Game1.timeOfDay>= Game1.getStartingToGetDarkTime()) + if (Game1.player.currentLocation.IsOutdoors && Game1.timeOfDay >= Game1.getStartingToGetDarkTime()) { //Game1.ambientLight = Game1.ambientLight.GreyScaleAverage(); - CalculatedColor = Game1.ambientLight* ( (red+30) / 255f) * Config.DarknessIntensity; + CalculatedColor = Game1.ambientLight * ((red + 30) / 255f) * Config.DarknessIntensity; - Revitalize.ModCore.log("OUT: " + CalculatedColor); - Revitalize.ModCore.log("Ambient"+Game1.ambientLight); + ModCore.log("OUT: " + CalculatedColor); + ModCore.log("Ambient" + Game1.ambientLight); } } - - } } diff --git a/GeneralMods/Revitalize/Framework/Environment/DarkerNightConfig.cs b/GeneralMods/Revitalize/Framework/Environment/DarkerNightConfig.cs index 6d2c4b93..71819fff 100644 --- a/GeneralMods/Revitalize/Framework/Environment/DarkerNightConfig.cs +++ b/GeneralMods/Revitalize/Framework/Environment/DarkerNightConfig.cs @@ -1,10 +1,3 @@ -using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Revitalize.Framework.Environment { public class DarkerNightConfig @@ -16,6 +9,5 @@ namespace Revitalize.Framework.Environment this.Enabled = true; this.DarknessIntensity = .9f; } - } } diff --git a/GeneralMods/Revitalize/Framework/Graphics/Animations/Animation.cs b/GeneralMods/Revitalize/Framework/Graphics/Animations/Animation.cs index 70c86246..9218b13b 100644 --- a/GeneralMods/Revitalize/Framework/Graphics/Animations/Animation.cs +++ b/GeneralMods/Revitalize/Framework/Graphics/Animations/Animation.cs @@ -1,80 +1,59 @@ -using Microsoft.Xna.Framework; -using Netcode; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Xml.Serialization; +using Microsoft.Xna.Framework; +using Netcode; namespace Revitalize.Framework.Graphics.Animations { - /// - /// A custom class used to deal with custom animations/ - /// - public class Animation + /// A custom class used to deal with custom animations/ + public class Animation { - /// - /// The source rectangle on the texture to display. - /// - public Rectangle sourceRectangle; - /// - /// The duration of the frame in length. - /// - public int frameDuration; - /// - /// The duration until the next frame. - /// - public int frameCountUntilNextAnimation; + /// The source rectangle on the texture to display. + public Rectangle sourceRectangle; - [XmlIgnore] - public NetFields NetFields { get; } = new NetFields(); + /// The duration of the frame in length. + public int frameDuration; + + /// The duration until the next frame. + public int frameCountUntilNextAnimation; + + [XmlIgnore] + public NetFields NetFields { get; } = new NetFields(); public Animation() { - this.sourceRectangle = new Rectangle(0,0,16,16); + this.sourceRectangle = new Rectangle(0, 0, 16, 16); this.frameCountUntilNextAnimation = -1; this.frameDuration = -1; } - /// - /// Constructor that causes the animation frame count to be set to -1; This forces it to never change. - /// + /// Constructor that causes the animation frame count to be set to -1; This forces it to never change. /// The draw source for this animation. public Animation(Rectangle SourceRectangle) { - sourceRectangle = SourceRectangle; + this.sourceRectangle = SourceRectangle; this.frameCountUntilNextAnimation = -1; - frameDuration = -1; + this.frameDuration = -1; } - /// - /// Constructor. - /// + /// Construct an instance. /// The draw source for this animation. /// How many on screen frames this animation stays for. Every draw frame decrements an active animation by 1 frame. Set this to -1 to have it be on the screen infinitely. - public Animation(Rectangle SourceRectangle,int existForXFrames) + public Animation(Rectangle SourceRectangle, int existForXFrames) { - sourceRectangle = SourceRectangle; - frameDuration = existForXFrames; + this.sourceRectangle = SourceRectangle; + this.frameDuration = existForXFrames; } - /// - /// Decrements the amount of frames this animation is on the screen for by 1. - /// + /// Decrements the amount of frames this animation is on the screen for by 1. public void tickAnimationFrame() { - frameCountUntilNextAnimation--; + this.frameCountUntilNextAnimation--; } - /// - /// This sets the animation frame count to be the max duration. I.E restart the timer. - /// + /// This sets the animation frame count to be the max duration. I.E restart the timer. public void startAnimation() { - frameCountUntilNextAnimation = frameDuration; + this.frameCountUntilNextAnimation = this.frameDuration; } - - } } diff --git a/GeneralMods/Revitalize/Framework/Graphics/Animations/AnimationManager.cs b/GeneralMods/Revitalize/Framework/Graphics/Animations/AnimationManager.cs index 4611ceba..dbc1520e 100644 --- a/GeneralMods/Revitalize/Framework/Graphics/Animations/AnimationManager.cs +++ b/GeneralMods/Revitalize/Framework/Graphics/Animations/AnimationManager.cs @@ -1,165 +1,131 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI; -using StardewValley; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using StardewValley; namespace Revitalize.Framework.Graphics.Animations { - /// - /// Used to play animations for Stardust.CoreObject type objects and all objects that extend from it. In draw code of object make sure to use this info instead. - /// - public class AnimationManager + /// Used to play animations for Stardust.CoreObject type objects and all objects that extend from it. In draw code of object make sure to use this info instead. + public class AnimationManager { - public Dictionary> animations = new SerializableDictionary>(); - public string currentAnimationName; - public int currentAnimationListIndex; - public List currentAnimationList = new List(); - private Texture2DExtended objectTexture; ///Might not be necessary if I use the CoreObject texture sheet. - public Animation defaultDrawFrame; - public Animation currentAnimation; - public bool enabled; - + public Dictionary> animations = new SerializableDictionary>(); + public string currentAnimationName; + public int currentAnimationListIndex; + public List currentAnimationList = new List(); + private Texture2DExtended objectTexture; ///Might not be necessary if I use the CoreObject texture sheet. + public Animation defaultDrawFrame; + public Animation currentAnimation; + public bool enabled; public string animationDataString; + public bool IsNull => this.defaultDrawFrame == null && this.objectTexture == null; - public bool IsNull - { - get - { - if (this.defaultDrawFrame == null && this.objectTexture == null) return true; - else return false; - } - } - /// - /// Empty constructor. - /// - public AnimationManager() - { - - } + /// Construct an instance. + public AnimationManager() { } - /// - /// Constructor for Animation Manager class. - /// + /// Constructor for Animation Manager class. /// The texture that will be used for the animation. This is typically the same as the object this class is attached to. /// This is used if no animations will be available to the animation manager. /// Whether or not animations play by default. Default value is true. - public AnimationManager (Texture2DExtended ObjectTexture,Animation DefaultFrame, bool EnabledByDefault=true) + public AnimationManager(Texture2DExtended ObjectTexture, Animation DefaultFrame, bool EnabledByDefault = true) { - currentAnimationListIndex = 0; + this.currentAnimationListIndex = 0; this.objectTexture = ObjectTexture; this.defaultDrawFrame = DefaultFrame; this.enabled = EnabledByDefault; - currentAnimation = this.defaultDrawFrame; + this.currentAnimation = this.defaultDrawFrame; this.currentAnimationName = ""; this.animationDataString = ""; } - - public AnimationManager(Texture2DExtended ObjectTexture,Animation DefaultFrame ,string animationString, string startingAnimationKey, int startingAnimationFrame=0,bool EnabledByDefault=true) + + public AnimationManager(Texture2DExtended ObjectTexture, Animation DefaultFrame, string animationString, string startingAnimationKey, int startingAnimationFrame = 0, bool EnabledByDefault = true) { - currentAnimationListIndex = 0; + this.currentAnimationListIndex = 0; this.objectTexture = ObjectTexture; this.defaultDrawFrame = DefaultFrame; this.enabled = EnabledByDefault; this.animationDataString = animationString; this.animations = parseAnimationsFromXNB(animationString); - bool f = animations.TryGetValue(startingAnimationKey, out currentAnimationList); - if (f == true) - { - setAnimation(startingAnimationKey, startingAnimationFrame); - } + if (this.animations.TryGetValue(startingAnimationKey, out this.currentAnimationList)) + this.setAnimation(startingAnimationKey, startingAnimationFrame); else { - currentAnimation = this.defaultDrawFrame; + this.currentAnimation = this.defaultDrawFrame; this.currentAnimationName = ""; } } - public AnimationManager(Texture2DExtended ObjectTexture, Animation DefaultFrame, Dictionary> animationString, string startingAnimationKey, int startingAnimationFrame = 0, bool EnabledByDefault = true) + public AnimationManager(Texture2DExtended ObjectTexture, Animation DefaultFrame, Dictionary> animationString, string startingAnimationKey, int startingAnimationFrame = 0, bool EnabledByDefault = true) { - currentAnimationListIndex = 0; + this.currentAnimationListIndex = 0; this.objectTexture = ObjectTexture; this.defaultDrawFrame = DefaultFrame; this.enabled = EnabledByDefault; this.animations = animationString; - bool f = animations.TryGetValue(startingAnimationKey, out currentAnimationList); - if (f == true) - { - setAnimation(startingAnimationKey, startingAnimationFrame); - } + if (this.animations.TryGetValue(startingAnimationKey, out this.currentAnimationList)) + this.setAnimation(startingAnimationKey, startingAnimationFrame); else { - currentAnimation = this.defaultDrawFrame; + this.currentAnimation = this.defaultDrawFrame; this.currentAnimationName = ""; } } - /// - /// Update the animation frame once after drawing the object. - /// + /// Update the animation frame once after drawing the object. public void tickAnimation() { try { - if (this.currentAnimation.frameDuration == -1 || this.enabled == false || this.currentAnimation == this.defaultDrawFrame) return; //This is if this is a default animation or the animation stops here. - if (this.currentAnimation.frameCountUntilNextAnimation == 0) getNextAnimation(); + if (this.currentAnimation.frameDuration == -1 || !this.enabled || this.currentAnimation == this.defaultDrawFrame) + return; //This is if this is a default animation or the animation stops here. + if (this.currentAnimation.frameCountUntilNextAnimation == 0) + this.getNextAnimation(); this.currentAnimation.tickAnimationFrame(); } - catch(Exception err) + catch (Exception err) { ModCore.ModMonitor.Log("An internal error occured when trying to tick the animation."); ModCore.ModMonitor.Log(err.ToString(), StardewModdingAPI.LogLevel.Error); } } - /// - /// Get the next animation in the list of animations. - /// + /// Get the next animation in the list of animations. public void getNextAnimation() { - currentAnimationListIndex++; - if(currentAnimationListIndex==currentAnimationList.Count) //If the animation frame I'm tryting to get is 1 outside my list length, reset the list. - { - currentAnimationListIndex = 0; - } - - //Get the next animation from the list and reset it's counter to the starting frame value. - this.currentAnimation = currentAnimationList[currentAnimationListIndex]; - this.currentAnimation.startAnimation(); + this.currentAnimationListIndex++; + if (this.currentAnimationListIndex == this.currentAnimationList.Count) //If the animation frame I'm tryting to get is 1 outside my list length, reset the list. + this.currentAnimationListIndex = 0; + + //Get the next animation from the list and reset it's counter to the starting frame value. + this.currentAnimation = this.currentAnimationList[this.currentAnimationListIndex]; + this.currentAnimation.startAnimation(); } - /// - /// Gets the animation from the dictionary of all animations available. - /// + /// Gets the animation from the dictionary of all animations available. /// /// - /// - public bool setAnimation(string AnimationName, int StartingFrame=0) + public bool setAnimation(string AnimationName, int StartingFrame = 0) { - List dummyList = new List(); - bool f = animations.TryGetValue(AnimationName, out dummyList); - if (f == true) + if (this.animations.TryGetValue(AnimationName, out List dummyList)) { - if (dummyList.Count != 0 || StartingFrame>=dummyList.Count) + if (dummyList.Count != 0 || StartingFrame >= dummyList.Count) { - currentAnimationList = dummyList; - currentAnimation = currentAnimationList[StartingFrame]; - currentAnimationName = AnimationName; + this.currentAnimationList = dummyList; + this.currentAnimation = this.currentAnimationList[StartingFrame]; + this.currentAnimationName = AnimationName; return true; } else { - if(dummyList.Count==0) ModCore.ModMonitor.Log("Error: Current animation " + AnimationName+ " has no animation frames associated with it."); - if (dummyList.Count > dummyList.Count) ModCore.ModMonitor.Log("Error: Animation frame "+ StartingFrame+ " is outside the range of provided animations. Which has a maximum count of "+ dummyList.Count); + if (dummyList.Count == 0) + ModCore.ModMonitor.Log("Error: Current animation " + AnimationName + " has no animation frames associated with it."); + if (dummyList.Count > dummyList.Count) + ModCore.ModMonitor.Log("Error: Animation frame " + StartingFrame + " is outside the range of provided animations. Which has a maximum count of " + dummyList.Count); return false; } } @@ -170,17 +136,13 @@ namespace Revitalize.Framework.Graphics.Animations } } - /// - /// Sets the animation manager to an on state, meaning that this animation will update on the draw frame. - /// + /// Sets the animation manager to an on state, meaning that this animation will update on the draw frame. public void enableAnimation() { this.enabled = true; } - /// - /// Sets the animation manager to an off state, meaning that this animation will no longer update on the draw frame. - /// + /// Sets the animation manager to an off state, meaning that this animation will no longer update on the draw frame. public void disableAnimation() { this.enabled = false; @@ -189,28 +151,27 @@ namespace Revitalize.Framework.Graphics.Animations public static Dictionary> parseAnimationsFromXNB(string s) { string[] array = s.Split('*'); - Dictionary> parsedDic = new Dictionary>(); - foreach(var v in array) + Dictionary> parsedDic = new Dictionary>(); + foreach (string v in array) { - // Log.AsyncC(v); - string[] AnimationArray = v.Split(' '); - if (parsedDic.ContainsKey(AnimationArray[0])) + // Log.AsyncC(v); + string[] animationArray = v.Split(' '); + if (parsedDic.ContainsKey(animationArray[0])) { - List aniList = new List(); - aniList = parseAnimationFromString(v); - foreach(var ani in aniList) { - parsedDic[AnimationArray[0]].Add(ani); + List animations = parseAnimationFromString(v); + foreach (var animation in animations) + { + parsedDic[animationArray[0]].Add(animation); } - } else { - parsedDic.Add(AnimationArray[0], new List()); + parsedDic.Add(animationArray[0], new List()); List aniList = new List(); aniList = parseAnimationFromString(v); foreach (var ani in aniList) { - parsedDic[AnimationArray[0]].Add(ani); + parsedDic[animationArray[0]].Add(ani); } } } @@ -219,28 +180,22 @@ namespace Revitalize.Framework.Graphics.Animations public static List parseAnimationFromString(string s) { - List ok = new List(); + List ok = new List(); string[] array2 = s.Split('>'); - foreach(var q in array2) { + foreach (string q in array2) + { string[] array = q.Split(' '); try { Animation ani = new Animation(new Rectangle(Convert.ToInt32(array[1]), Convert.ToInt32(array[2]), Convert.ToInt32(array[3]), Convert.ToInt32(array[4])), Convert.ToInt32(array[5])); - // ModCore.ModMonitor.Log(ani.sourceRectangle.ToString()); + // ModCore.ModMonitor.Log(ani.sourceRectangle.ToString()); ok.Add(ani); } - catch(Exception err) - { - err.ToString(); - continue; - } - + catch { } } return ok; } - /// - /// Used to handle general drawing functionality using the animation manager. - /// + /// Used to handle general drawing functionality using the animation manager. /// We need a spritebatch to draw. /// The texture to draw. /// The onscreen position to draw to. @@ -251,7 +206,7 @@ namespace Revitalize.Framework.Graphics.Animations /// The scale of the texture. /// Effects that get applied to the sprite. /// The dept at which to draw the texture. - public void draw(SpriteBatch spriteBatch,Texture2D texture, Vector2 Position, Rectangle? sourceRectangle,Color drawColor, float rotation, Vector2 origin, float scale,SpriteEffects spriteEffects, float LayerDepth) + public void draw(SpriteBatch spriteBatch, Texture2D texture, Vector2 Position, Rectangle? sourceRectangle, Color drawColor, float rotation, Vector2 origin, float scale, SpriteEffects spriteEffects, float LayerDepth) { //Log.AsyncC("Animation Manager is working!"); spriteBatch.Draw(texture, Position, sourceRectangle, drawColor, rotation, origin, scale, spriteEffects, LayerDepth); @@ -285,6 +240,5 @@ namespace Revitalize.Framework.Graphics.Animations { return this.objectTexture.getTexture(); } - } } diff --git a/GeneralMods/Revitalize/Framework/Graphics/Texture2DExtended.cs b/GeneralMods/Revitalize/Framework/Graphics/Texture2DExtended.cs index 3d316a96..e78447f2 100644 --- a/GeneralMods/Revitalize/Framework/Graphics/Texture2DExtended.cs +++ b/GeneralMods/Revitalize/Framework/Graphics/Texture2DExtended.cs @@ -1,11 +1,6 @@ -using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI; -using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Xna.Framework.Graphics; +using StardewModdingAPI; namespace Revitalize.Framework.Graphics { @@ -14,13 +9,11 @@ namespace Revitalize.Framework.Graphics public string Name; public Texture2D texture; public string path; - IModHelper helper; public string modID; public ContentSource source; + private readonly IModHelper helper; - /// - /// Empty/null constructor. - /// + /// Empty/null constructor. public Texture2DExtended() { this.Name = ""; @@ -39,9 +32,7 @@ namespace Revitalize.Framework.Graphics this.modID = ""; } - /// - /// Constructor. - /// + /// Construct an instance. /// The relative path to file on disk. See StardustCore.Utilities.getRelativePath(modname,path); public Texture2DExtended(IModHelper helper, IManifest manifest, string path, ContentSource contentSource = ContentSource.ModFolder) { @@ -73,10 +64,7 @@ namespace Revitalize.Framework.Graphics return this.helper; } - /// - /// Returns the actual 2D texture held by this wrapper class. - /// - /// + /// Returns the actual 2D texture held by this wrapper class. public Texture2D getTexture() { return this.texture; diff --git a/GeneralMods/Revitalize/Framework/Illuminate/ColorExtensions.cs b/GeneralMods/Revitalize/Framework/Illuminate/ColorExtensions.cs index c3a03831..e4e65c52 100644 --- a/GeneralMods/Revitalize/Framework/Illuminate/ColorExtensions.cs +++ b/GeneralMods/Revitalize/Framework/Illuminate/ColorExtensions.cs @@ -1,9 +1,5 @@ -using Microsoft.Xna.Framework; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Xna.Framework; namespace Revitalize.Framework.Illuminate { @@ -22,6 +18,5 @@ namespace Revitalize.Framework.Illuminate int b = Math.Abs(255 - color.B); return new Color(r, g, b); } - } } diff --git a/GeneralMods/Revitalize/Framework/Illuminate/LightManager.cs b/GeneralMods/Revitalize/Framework/Illuminate/LightManager.cs index 0dbb3efe..f963d00d 100644 --- a/GeneralMods/Revitalize/Framework/Illuminate/LightManager.cs +++ b/GeneralMods/Revitalize/Framework/Illuminate/LightManager.cs @@ -1,167 +1,112 @@ -using Microsoft.Xna.Framework; -using StardewValley; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using StardewValley; namespace Revitalize.Framework.Illuminate { public class LightManager { - public Dictionary lights; + public Dictionary lights; public bool lightsOn; public LightManager() { this.lights = new Dictionary(); - lightsOn = false; + this.lightsOn = false; } - /// - /// Add a light to the list of tracked lights. - /// - /// - /// - /// - /// - public bool addLight(Vector2 IdKey,LightSource light,StardewValley.Object gameObject) + /// Add a light to the list of tracked lights. + public bool addLight(Vector2 IdKey, LightSource light, StardewValley.Object gameObject) { - Vector2 initialPosition = gameObject.TileLocation*Game1.tileSize; + Vector2 initialPosition = gameObject.TileLocation * Game1.tileSize; initialPosition += IdKey; if (this.lights.ContainsKey(IdKey)) - { return false; - } - else - { - light.position.Value = initialPosition; - this.lights.Add(IdKey, light); - return true; - } + + light.position.Value = initialPosition; + this.lights.Add(IdKey, light); + return true; } - /// - /// Turn off a single light. - /// - /// - /// - /// + /// Turn off a single light. public bool turnOffLight(Vector2 IdKey, GameLocation location) { - if (!lights.ContainsKey(IdKey)) - { + if (!this.lights.ContainsKey(IdKey)) return false; - } - else - { - LightSource light = new LightSource(); - this.lights.TryGetValue(IdKey, out light); - Game1.currentLightSources.Remove(light); - location.sharedLights.Remove(light); - return true; - } + + this.lights.TryGetValue(IdKey, out LightSource light); + Game1.currentLightSources.Remove(light); + location.sharedLights.Remove(light); + return true; } - /// - /// Turn on a single light. - /// - /// - /// - /// - public bool turnOnLight(Vector2 IdKey, GameLocation location,StardewValley.Object gameObject) + /// Turn on a single light. + public bool turnOnLight(Vector2 IdKey, GameLocation location, StardewValley.Object gameObject) { - if (!lights.ContainsKey(IdKey)) - { + if (!this.lights.ContainsKey(IdKey)) return false; - } - else - { - LightSource light = new LightSource(); - this.lights.TryGetValue(IdKey, out light); - if (light == null) - { - throw new Exception("Light is null????"); - } - Game1.currentLightSources.Add(light); - if (location == null) - { - throw new Exception("WHY IS LOC NULL???"); - } - if (location.sharedLights == null) - { - throw new Exception("Locational lights is null!"); - - } - Game1.showRedMessage("TURN ON!"); - Game1.currentLightSources.Add(light); - location.sharedLights.Add(light); - repositionLight(light,IdKey,gameObject); - return true; - } + + this.lights.TryGetValue(IdKey, out var light); + if (light == null) + throw new Exception("Light is null????"); + + Game1.currentLightSources.Add(light); + if (location == null) + throw new Exception("WHY IS LOC NULL???"); + + if (location.sharedLights == null) + throw new Exception("Locational lights is null!"); + + Game1.showRedMessage("TURN ON!"); + Game1.currentLightSources.Add(light); + location.sharedLights.Add(light); + this.repositionLight(light, IdKey, gameObject); + return true; } - - - - /// - /// Add a light source to this location. - /// + /// Add a light source to this location. /// The game location to add the light source in. - /// The color of the light to be added - public virtual void turnOnLights(GameLocation environment,StardewValley.Object gameObject) + public virtual void turnOnLights(GameLocation environment, StardewValley.Object gameObject) { - foreach(KeyValuePair pair in this.lights) - { - turnOnLight(pair.Key, environment,gameObject); - } - repositionLights(gameObject); + foreach (KeyValuePair pair in this.lights) + this.turnOnLight(pair.Key, environment, gameObject); + this.repositionLights(gameObject); } - /// - /// Removes a lightsource from the game location. - /// + /// Removes a lightsource from the game location. /// The game location to remove the light source from. public void turnOffLights(GameLocation environment) { foreach (KeyValuePair pair in this.lights) - { - turnOffLight(pair.Key, environment); - } - + this.turnOffLight(pair.Key, environment); } public void repositionLights(StardewValley.Object gameObject) { foreach (KeyValuePair pair in this.lights) - { - repositionLight(pair.Value, pair.Key, gameObject); - } + this.repositionLight(pair.Value, pair.Key, gameObject); } - public void repositionLight(LightSource light,Vector2 offset,StardewValley.Object gameObject) + public void repositionLight(LightSource light, Vector2 offset, StardewValley.Object gameObject) { Vector2 initialPosition = gameObject.TileLocation * Game1.tileSize; light.position.Value = initialPosition + offset; } - public virtual void toggleLights(GameLocation location,StardewValley.Object gameObject) + public virtual void toggleLights(GameLocation location, StardewValley.Object gameObject) { - - if (lightsOn == false) + if (!this.lightsOn) { - this.turnOnLights(location,gameObject); - lightsOn = true; + this.turnOnLights(location, gameObject); + this.lightsOn = true; } - else if (lightsOn == true) + else if (this.lightsOn) { - this.turnOffLights(Game1.player.currentLocation); - lightsOn = false; + this.lightsOn = false; } } - } } diff --git a/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs b/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs index bccfe455..21207f61 100644 --- a/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs +++ b/GeneralMods/Revitalize/Framework/Objects/BasicItemInformation.cs @@ -1,18 +1,14 @@ -using Microsoft.Xna.Framework; +using System; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using PyTK.CustomElementHandler; using Revitalize.Framework.Graphics.Animations; using Revitalize.Framework.Illuminate; using Revitalize.Framework.Utilities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Revitalize.Framework.Objects { - public class BasicItemInformation: CustomObjectData + public class BasicItemInformation : CustomObjectData { public string name; public string description; @@ -37,14 +33,14 @@ namespace Revitalize.Framework.Objects public LightManager lightManager; - public BasicItemInformation() : base() + public BasicItemInformation() { - name = ""; - description = ""; - categoryName = ""; - categoryColor = new Color(0, 0, 0); - price = 0; - TileLocation = Vector2.Zero; + this.name = ""; + this.description = ""; + this.categoryName = ""; + this.categoryColor = new Color(0, 0, 0); + this.price = 0; + this.TileLocation = Vector2.Zero; this.edibility = -300; this.canBeSetIndoors = false; this.canBeSetOutdoors = false; @@ -56,7 +52,7 @@ namespace Revitalize.Framework.Objects this.lightManager = new LightManager(); } - public BasicItemInformation(string name, string description, string categoryName, Color categoryColor,int edibility,int fragility,bool isLamp,int price, Vector2 TileLocation,bool canBeSetOutdoors,bool canBeSetIndoors,string id, string data, Texture2D texture, Color color,int tileIndex, bool bigCraftable, Type type, CraftingData craftingData, AnimationManager animationManager,Color DrawColor,bool ignoreBoundingBox, InventoryManager Inventory,LightManager Lights):base(id,data,texture,color,tileIndex,bigCraftable,type,craftingData) + public BasicItemInformation(string name, string description, string categoryName, Color categoryColor, int edibility, int fragility, bool isLamp, int price, Vector2 TileLocation, bool canBeSetOutdoors, bool canBeSetIndoors, string id, string data, Texture2D texture, Color color, int tileIndex, bool bigCraftable, Type type, CraftingData craftingData, AnimationManager animationManager, Color drawColor, bool ignoreBoundingBox, InventoryManager Inventory, LightManager Lights) : base(id, data, texture, color, tileIndex, bigCraftable, type, craftingData) { this.name = name; this.description = description; @@ -78,49 +74,19 @@ namespace Revitalize.Framework.Objects this.animationManager.getExtendedTexture().texture = this.texture; } else - { this.texture = this.animationManager.getTexture(); - } this.drawPosition = Vector2.Zero; - - if (DrawColor == null) - { - this.drawColor = Color.White; - } - else - { - this.drawColor = DrawColor; - } - + this.drawColor = drawColor; this.ignoreBoundingBox = ignoreBoundingBox; - - recreateDataString(); - if (Inventory == null) - { - this.inventory = new InventoryManager(); - } - else - { - this.inventory = Inventory; - } - - if (Lights == null) - { - this.lightManager = new LightManager(); - } - else - { - this.lightManager = Lights; - } + this.recreateDataString(); + this.inventory = Inventory ?? new InventoryManager(); + this.lightManager = Lights ?? new LightManager(); } public void recreateDataString() { - this.data=this.name+"/"+this.price+"/"+this.edibility+"/"+"Crafting -9"+"/"+this.description+"/"+this.canBeSetOutdoors+"/"+this.canBeSetIndoors+"/"+this.fragility+"/"+this.isLamp+"/"+this.name; + this.data = $"{this.name}/{this.price}/{this.edibility}/Crafting -9/{this.description}/{this.canBeSetOutdoors}/{this.canBeSetIndoors}/{this.fragility}/{this.isLamp}/{this.name}"; } - - - } } diff --git a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs index 8949ce30..b9c111bb 100644 --- a/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/CustomObject.cs @@ -1,111 +1,71 @@ -using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using PyTK.CustomElementHandler; -using Revitalize.Framework.Graphics; using Revitalize.Framework.Graphics.Animations; using StardewValley; using StardewValley.Objects; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Revitalize.Framework.Objects { - /// - /// A custom object template. - /// - /// Todo: - /// -Multiple Lights - /// -Events when walking over? - /// -Inventories - /// + // TODO: + // -Multiple Lights + // -Events when walking over? + // -Inventories + + /// A custom object template. public class CustomObject : PySObject { public string id; public BasicItemInformation info; public GameLocation location; - /// - /// The animation manager. - /// - public AnimationManager animationManager - { - get - { - return info.animationManager; - } - } + /// The animation manager. + public AnimationManager animationManager => this.info.animationManager; - /// - /// The display texture for this object. - /// - public Texture2D displayTexture - { - get - { - return animationManager.getTexture(); - } - } + /// The display texture for this object. + public Texture2D displayTexture => this.animationManager.getTexture(); - /// - /// Empty constructor. - /// - public CustomObject() - { - - } + /// Empty constructor. + public CustomObject() { } - /// - /// Constructor. - /// - /// - public CustomObject(BasicItemInformation info):base(info,Vector2.Zero) + /// Construct an instance. + public CustomObject(BasicItemInformation info) + : base(info, Vector2.Zero) { this.info = info; this.initializeBasics(); } - /// - /// Constructor. - /// - /// - /// - public CustomObject(BasicItemInformation info,Vector2 TileLocation) : base(info, TileLocation) + /// Construct an instance. + public CustomObject(BasicItemInformation info, Vector2 TileLocation) + : base(info, TileLocation) { this.info = info; this.initializeBasics(); } - /// - /// Sets some basic information up. - /// + /// Sets some basic information up. public virtual void initializeBasics() { - this.name = info.name; - this.displayName = getDisplayNameFromStringsFile(this.id); - this.Edibility = info.edibility; + this.name = this.info.name; + this.displayName = this.getDisplayNameFromStringsFile(this.id); + this.Edibility = this.info.edibility; this.Category = -9; //For crafting. - this.displayName = info.name; + this.displayName = this.info.name; this.setOutdoors.Value = true; this.setIndoors.Value = true; this.isLamp.Value = false; this.fragility.Value = 0; - this.updateDrawPosition(0,0); + this.updateDrawPosition(0, 0); this.bigCraftable.Value = false; - - if (this.info.ignoreBoundingBox) - { - //this.boundingBox.Value = new Rectangle(Int32.MinValue, Int32.MinValue, 0, 0); - } - - + //if (this.info.ignoreBoundingBox) + // this.boundingBox.Value = new Rectangle(int.MinValue, int.MinValue, 0, 0); } public override bool isPassable() @@ -115,56 +75,39 @@ namespace Revitalize.Framework.Objects public override Rectangle getBoundingBox(Vector2 tileLocation) { - if (this.info.ignoreBoundingBox) - { - return new Rectangle(Int32.MinValue, Int32.MinValue, 0, 0); - } - else - { - return base.getBoundingBox(tileLocation); - } + return this.info.ignoreBoundingBox + ? new Rectangle(int.MinValue, int.MinValue, 0, 0) + : base.getBoundingBox(tileLocation); } - /// - /// Checks for interaction with the object. - /// - /// - /// - /// + /// Checks for interaction with the object. public override bool checkForAction(Farmer who, bool justCheckingForActivity = false) { - var mState = Microsoft.Xna.Framework.Input.Mouse.GetState(); - var keyboardState = Game1.GetKeyboardState(); + MouseState mState = Mouse.GetState(); + KeyboardState keyboardState = Game1.GetKeyboardState(); - if (mState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift))==false) + if (mState.RightButton == ButtonState.Pressed && (keyboardState.IsKeyDown(Keys.LeftShift) || !keyboardState.IsKeyDown(Keys.RightShift))) { - Revitalize.ModCore.log("Right clicked!"); - return rightClicked(who); - } - else if(mState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift))) - { - return shiftRightClicked(who); + ModCore.log("Right clicked!"); + return this.rightClicked(who); } + if (mState.RightButton == ButtonState.Pressed && (keyboardState.IsKeyDown(Keys.LeftShift) || keyboardState.IsKeyDown(Keys.RightShift))) + return this.shiftRightClicked(who); + if (justCheckingForActivity) - { return true; - } - Revitalize.ModCore.log("Left clicked!"); + ModCore.log("Left clicked!"); return this.clicked(who); } public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) { - BasicItemInformation data =(BasicItemInformation) CustomObjectData.collection[additionalSaveData["id"]]; - return new CustomObject((BasicItemInformation) CustomObjectData.collection[additionalSaveData["id"]], (replacement as Chest).TileLocation); + BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]]; + return new CustomObject(data, (replacement as Chest).TileLocation); } - /// - /// What happens when the player right clicks the object. - /// - /// - /// + /// What happens when the player right clicks the object. public virtual bool rightClicked(Farmer who) { // Game1.showRedMessage("YOOO"); @@ -183,42 +126,28 @@ namespace Revitalize.Framework.Objects return true; } - /// - /// What happens when the player shift-right clicks this object. - /// - /// - /// + /// What happens when the player shift-right clicks this object. public virtual bool shiftRightClicked(Farmer who) { - Revitalize.ModCore.log("Shift right clicked!"); + ModCore.log("Shift right clicked!"); return true; } - /// - /// What happens when the player left clicks the object. - /// - /// - /// + /// What happens when the player left clicks the object. public override bool clicked(Farmer who) { - Revitalize.ModCore.log("Clicky click!"); + ModCore.log("Clicky click!"); - Revitalize.ModCore.log(System.Environment.StackTrace); + ModCore.log(System.Environment.StackTrace); - return removeAndAddToPlayersInventory(); + return this.removeAndAddToPlayersInventory(); //return base.clicked(who); } - /// - /// What happens when a player uses a tool on this object. - /// - /// - /// - /// + /// What happens when a player uses a tool on this object. public override bool performToolAction(Tool t, GameLocation location) { - - if(t.GetType()== typeof(StardewValley.Tools.Axe) || t.GetType()== typeof(StardewValley.Tools.Pickaxe)) + if (t.GetType() == typeof(StardewValley.Tools.Axe) || t.GetType() == typeof(StardewValley.Tools.Pickaxe)) { Game1.createItemDebris(this, Game1.player.getStandingPosition(), Game1.player.getDirection()); this.location = null; @@ -232,10 +161,7 @@ namespace Revitalize.Framework.Objects //return base.performToolAction(t, location); } - /// - /// Remove the object from the world and add it to the player's inventory if possible. - /// - /// + /// Remove the object from the world and add it to the player's inventory if possible. public virtual bool removeAndAddToPlayersInventory() { if (Game1.player.isInventoryFull()) @@ -250,102 +176,72 @@ namespace Revitalize.Framework.Objects return true; } - /// - /// Gets the category color for the object. - /// - /// + /// Gets the category color for the object. public override Color getCategoryColor() { - return info.categoryColor; + return this.info.categoryColor; //return data.categoryColor; } - /// - /// Gets the category name for the object. - /// - /// + /// Gets the category name for the object. public override string getCategoryName() { - return info.categoryName; + return this.info.categoryName; } - /// - /// Gets the description for the object. - /// - /// + /// Gets the description for the object. public override string getDescription() { - string text = info.description; + string text = this.info.description; SpriteFont smallFont = Game1.smallFont; int width = Game1.tileSize * 4 + Game1.tileSize / 4; return Game1.parseText(text, smallFont, width); } - /// - /// Places an object down. - /// - /// - /// - /// - /// - /// + /// Places an object down. public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { - this.updateDrawPosition(x,y); + this.updateDrawPosition(x, y); this.location = location; return base.placementAction(location, x, y, who); } - /// - /// Updates a visual draw position. - /// + /// Updates a visual draw position. public virtual void updateDrawPosition(int x, int y) { this.info.drawPosition = new Vector2((int)(x / Game1.tileSize), (int)(y / Game1.tileSize)); //this.info.drawPosition = new Vector2((float)this.boundingBox.X, (float)(this.boundingBox.Y - (this.animationManager.currentAnimation.sourceRectangle.Height * Game1.pixelZoom - this.boundingBox.Height))); } - /// - /// Gets a clone of the game object. - /// - /// + /// Gets a clone of the game object. public override Item getOne() { return new CustomObject((BasicItemInformation)this.data); } - /// - /// What happens when the object is drawn at a tile location. - /// - /// - /// - /// - /// + /// What happens when the object is drawn at a tile location. public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) { if (x <= -1) { - spriteBatch.Draw(this.info.animationManager.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.info.drawPosition), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y*Game1.tileSize) / 10000f)); + spriteBatch.Draw(this.info.animationManager.getTexture(), Game1.GlobalToLocal(Game1.viewport, this.info.drawPosition), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y * Game1.tileSize) / 10000f)); } else { //The actual planter box being drawn. - if (animationManager == null) + if (this.animationManager == null) { if (this.animationManager.getExtendedTexture() == null) - { ModCore.ModMonitor.Log("Tex Extended is null???"); - } - - spriteBatch.Draw(this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y*Game1.tileSize) / 10000f)); + spriteBatch.Draw(this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y * Game1.tileSize) / 10000f)); // Log.AsyncG("ANIMATION IS NULL?!?!?!?!"); } else { //Log.AsyncC("Animation Manager is working!"); - this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y*Game1.tileSize) / 10000f)); + this.animationManager.draw(spriteBatch, this.displayTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), y * Game1.tileSize)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, Math.Max(0f, (float)(this.TileLocation.Y * Game1.tileSize) / 10000f)); try { this.animationManager.tickAnimation(); @@ -358,23 +254,12 @@ namespace Revitalize.Framework.Objects } // spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)((double)tileLocation.X * (double)Game1.tileSize + (((double)tileLocation.X * 11.0 + (double)tileLocation.Y * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2), (float)((double)tileLocation.Y * (double)Game1.tileSize + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) + (float)(Game1.tileSize / 2))), new Rectangle?(new Rectangle((int)((double)tileLocation.X * 51.0 + (double)tileLocation.Y * 77.0) % 3 * 16, 128 + this.whichForageCrop * 16, 16, 16)), Color.White, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom, SpriteEffects.None, (float)(((double)tileLocation.Y * (double)Game1.tileSize + (double)(Game1.tileSize / 2) + (((double)tileLocation.Y * 11.0 + (double)tileLocation.X * 7.0) % 10.0 - 5.0)) / 10000.0)); - - - } } - /// - /// Draw the game object at a non-tile spot. Aka like debris. - /// - /// - /// - /// - /// - /// + /// Draw the game object at a non-tile spot. Aka like debris. public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1f) { - if (Game1.eventUp && Game1.CurrentEvent.isTileWalkedOn(xNonTile / 64, yNonTile / 64)) return; if ((int)(this.ParentSheetIndex) != 590 && (int)(this.Fragility) != 2) @@ -391,33 +276,10 @@ namespace Revitalize.Framework.Objects int num3 = (bool)(this.flipped) ? 1 : 0; double num4 = (double)layerDepth; - spriteBatch1.Draw(this.displayTexture, local, this.animationManager.defaultDrawFrame.sourceRectangle, info.drawColor*alpha, (float)num1, origin, (float)4f, (SpriteEffects)num3, (float)num4); - + spriteBatch1.Draw(this.displayTexture, local, this.animationManager.defaultDrawFrame.sourceRectangle, this.info.drawColor * alpha, (float)num1, origin, (float)4f, (SpriteEffects)num3, (float)num4); } - - - public override void drawAsProp(SpriteBatch b) - { - base.drawAsProp(b); - } - - public override void drawAttachments(SpriteBatch b, int x, int y) - { - base.drawAttachments(b, x, y); - } - - /// - /// What happens when the object is drawn in a menu. - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// What happens when the object is drawn in a menu. public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow) { if (drawStackNumber && this.maximumStackSize() > 1 && ((double)scaleSize > 0.3 && this.Stack != int.MaxValue) && this.Stack > 1) @@ -427,30 +289,19 @@ namespace Revitalize.Framework.Objects float num = this.Quality < 4 ? 0.0f : (float)((Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1.0) * 0.0500000007450581); spriteBatch.Draw(Game1.mouseCursors, location + new Vector2(12f, (float)(Game1.tileSize - 12) + num), new Microsoft.Xna.Framework.Rectangle?(this.Quality < 4 ? new Microsoft.Xna.Framework.Rectangle(338 + (this.Quality - 1) * 8, 400, 8, 8) : new Microsoft.Xna.Framework.Rectangle(346, 392, 8, 8)), Color.White * transparency, 0.0f, new Vector2(4f, 4f), (float)(3.0 * (double)scaleSize * (1.0 + (double)num)), SpriteEffects.None, layerDepth); } - spriteBatch.Draw(this.displayTexture, location + new Vector2((float)(Game1.tileSize/2), (float)(Game1.tileSize*.75)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), info.drawColor*transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), 3f, SpriteEffects.None, layerDepth); + spriteBatch.Draw(this.displayTexture, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * .75)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), 3f, SpriteEffects.None, layerDepth); } - public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location) - { - base.drawPlacementBounds(spriteBatch, location); - } - - - /// - /// What happens when the object is drawn when held by a player. - /// - /// - /// - /// + /// What happens when the object is drawn when held by a player. public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f) { if (f.ActiveObject.bigCraftable.Value) { - spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, this.info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); return; } - spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + spriteBatch.Draw(this.displayTexture, objectPosition, this.animationManager.currentAnimation.sourceRectangle, this.info.drawColor, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); if (f.ActiveObject != null && f.ActiveObject.Name.Contains("=")) { spriteBatch.Draw(this.displayTexture, objectPosition + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), this.animationManager.currentAnimation.sourceRectangle, Color.White, 0f, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), (float)Game1.pixelZoom + Math.Abs(Game1.starCropShimmerPause) / 8f, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); @@ -467,12 +318,10 @@ namespace Revitalize.Framework.Objects //base.drawWhenHeld(spriteBatch, objectPosition, f); } - public string getDisplayNameFromStringsFile(string objectID) { //Load in a file that has all object names referenced here or something. - return info.name; + return this.info.name; } - } } diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs index a59ee09a..5a1928ca 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs @@ -1,46 +1,32 @@ -using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using PyTK.CustomElementHandler; using StardewValley; using StardewValley.Objects; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Revitalize.Framework.Objects { - public class MultiTiledComponent:CustomObject + public class MultiTiledComponent : CustomObject { - public MultiTiledObject containerObject; - public MultiTiledComponent():base() - { + public MultiTiledComponent() { } - } + public MultiTiledComponent(BasicItemInformation info) : base(info) { } - public MultiTiledComponent(BasicItemInformation info):base(info) - { - - } - - public MultiTiledComponent(BasicItemInformation info, Vector2 TileLocation): base(info, TileLocation) - { - - } + public MultiTiledComponent(BasicItemInformation info, Vector2 TileLocation) : base(info, TileLocation) { } public override bool checkForAction(Farmer who, bool justCheckingForActivity = false) { - //Revitalize.ModCore.log("Checking for a clicky click???"); + //ModCore.log("Checking for a clicky click???"); return base.checkForAction(who, justCheckingForActivity); } public override bool clicked(Farmer who) { - - Revitalize.ModCore.log("Clicked a multiTiledComponent!"); + ModCore.log("Clicked a multiTiledComponent!"); this.containerObject.pickUp(); return true; //return base.clicked(who); @@ -49,12 +35,10 @@ namespace Revitalize.Framework.Objects public override bool rightClicked(Farmer who) { if (this.location == null) - { this.location = Game1.player.currentLocation; - } this.info.lightManager.toggleLights(this.location, this); - Revitalize.ModCore.playerInfo.sittingInfo.sit(this, Vector2.Zero); + ModCore.playerInfo.sittingInfo.sit(this, Vector2.Zero); return true; } @@ -67,25 +51,18 @@ namespace Revitalize.Framework.Objects base.performRemoveAction(this.TileLocation, environment); } - public virtual void removeFromLocation(GameLocation location,Vector2 offset) + public virtual void removeFromLocation(GameLocation location, Vector2 offset) { - location.removeObject(this.TileLocation,false); + location.removeObject(this.TileLocation, false); this.location = null; //this.performRemoveAction(this.TileLocation,location); } - /// - /// Places an object down. - /// - /// - /// - /// - /// - /// + /// Places an object down. public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { - Revitalize.ModCore.ModMonitor.Log("SCREAMING!!!!"); - this.updateDrawPosition(x,y); + ModCore.ModMonitor.Log("SCREAMING!!!!"); + this.updateDrawPosition(x, y); this.location = location; if (this.location == null) this.location = Game1.player.currentLocation; @@ -103,24 +80,23 @@ namespace Revitalize.Framework.Objects float num = this.Quality < 4 ? 0.0f : (float)((Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1.0) * 0.0500000007450581); spriteBatch.Draw(Game1.mouseCursors, location + new Vector2(12f, (float)(Game1.tileSize - 12) + num), new Microsoft.Xna.Framework.Rectangle?(this.Quality < 4 ? new Microsoft.Xna.Framework.Rectangle(338 + (this.Quality - 1) * 8, 400, 8, 8) : new Microsoft.Xna.Framework.Rectangle(346, 392, 8, 8)), Color.White * transparency, 0.0f, new Vector2(4f, 4f), (float)(3.0 * (double)scaleSize * (1.0 + (double)num)), SpriteEffects.None, layerDepth); } - spriteBatch.Draw(this.displayTexture, location + new Vector2((float)(Game1.tileSize / 4), (float)(Game1.tileSize * .75)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), info.drawColor * transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), scaleSize, SpriteEffects.None, layerDepth); + spriteBatch.Draw(this.displayTexture, location + new Vector2((float)(Game1.tileSize / 4), (float)(Game1.tileSize * .75)), new Rectangle?(this.animationManager.currentAnimation.sourceRectangle), this.info.drawColor * transparency, 0f, new Vector2((float)(this.animationManager.currentAnimation.sourceRectangle.Width / 2), (float)(this.animationManager.currentAnimation.sourceRectangle.Height)), scaleSize, SpriteEffects.None, layerDepth); } public override Item getOne() { - MultiTiledComponent component=new MultiTiledComponent(this.info, this.TileLocation); + MultiTiledComponent component = new MultiTiledComponent(this.info, this.TileLocation); component.containerObject = this.containerObject; return component; - } public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) { BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]]; - MultiTiledComponent component= new MultiTiledComponent((BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]], (replacement as Chest).TileLocation); - component.containerObject = this.containerObject; - return containerObject; + return new MultiTiledComponent(data, (replacement as Chest).TileLocation) + { + containerObject = this.containerObject + }; } - } } diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs index bc30ba63..056825e6 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs @@ -1,42 +1,40 @@ -using Microsoft.Xna.Framework; +using System.Collections.Generic; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using PyTK.CustomElementHandler; using StardewValley; using StardewValley.Objects; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Revitalize.Framework.Objects { - public class MultiTiledObject:CustomObject + public class MultiTiledObject : CustomObject { public Dictionary objects; - public MultiTiledObject() : base() - { - - this.objects = new Dictionary(); - } - - public MultiTiledObject(BasicItemInformation info) : base(info) + public MultiTiledObject() { this.objects = new Dictionary(); } - public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation) : base(info, TileLocation) + public MultiTiledObject(BasicItemInformation info) + : base(info) { this.objects = new Dictionary(); } - public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary ObjectsList) : base(info, TileLocation) + public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation) + : base(info, TileLocation) { this.objects = new Dictionary(); - foreach(var v in ObjectsList) + } + + public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary ObjectsList) + : base(info, TileLocation) + { + this.objects = new Dictionary(); + foreach (var v in ObjectsList) { - MultiTiledComponent component =(MultiTiledComponent)v.Value.getOne(); + MultiTiledComponent component = (MultiTiledComponent)v.Value.getOne(); this.addComponent(v.Key, component); } } @@ -44,102 +42,64 @@ namespace Revitalize.Framework.Objects public bool addComponent(Vector2 key, MultiTiledComponent obj) { if (this.objects.ContainsKey(key)) - { return false; - } - else - { - this.objects.Add(key, obj); - obj.containerObject = this; - return true; - } + + this.objects.Add(key, obj); + obj.containerObject = this; + return true; } public bool removeComponent(Vector2 key) { if (!this.objects.ContainsKey(key)) - { return false; - } - else - { - this.objects.Remove(key); - return true; - } + + this.objects.Remove(key); + return true; } public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1) { foreach (KeyValuePair pair in this.objects) - { pair.Value.draw(spriteBatch, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, alpha); - } } public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1) { foreach (KeyValuePair pair in this.objects) - { - pair.Value.draw(spriteBatch, xNonTile + (int)pair.Key.X * Game1.tileSize, yNonTile+ (int)pair.Key.Y * Game1.tileSize, layerDepth, alpha); - } + pair.Value.draw(spriteBatch, xNonTile + (int)pair.Key.X * Game1.tileSize, yNonTile + (int)pair.Key.Y * Game1.tileSize, layerDepth, alpha); //base.draw(spriteBatch, xNonTile, yNonTile, layerDepth, alpha); } - public override void drawAsProp(SpriteBatch b) - { - base.drawAsProp(b); - } - - public override void drawAttachments(SpriteBatch b, int x, int y) - { - base.drawAttachments(b, x, y); - } - public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow) { foreach (KeyValuePair pair in this.objects) - { - pair.Value.drawInMenu(spriteBatch, location + (pair.Key*16), 1.0f, transparency, layerDepth, drawStackNumber, c, drawShadow); - } - //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, c, drawShadow); - } - - public override void drawPlacementBounds(SpriteBatch spriteBatch, GameLocation location) - { - base.drawPlacementBounds(spriteBatch, location); + pair.Value.drawInMenu(spriteBatch, location + (pair.Key * 16), 1.0f, transparency, layerDepth, drawStackNumber, c, drawShadow); + //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, c, drawShadow); } public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, Farmer f) { - - foreach(KeyValuePair pair in this.objects) - { + foreach (KeyValuePair pair in this.objects) pair.Value.drawWhenHeld(spriteBatch, objectPosition + (pair.Key * Game1.tileSize), f); - } //base.drawWhenHeld(spriteBatch, objectPosition, f); } - - //IMPLEMENT THESE! public virtual void pickUp() { - bool canPickUp= this.removeAndAddToPlayersInventory(); + bool canPickUp = this.removeAndAddToPlayersInventory(); if (canPickUp) { foreach (KeyValuePair pair in this.objects) - { - pair.Value.removeFromLocation(pair.Value.location,pair.Key); - } + pair.Value.removeFromLocation(pair.Value.location, pair.Key); this.location = null; } else - { Game1.showRedMessage("NOOOOOOOO"); - } } public override bool removeAndAddToPlayersInventory() @@ -155,11 +115,10 @@ namespace Revitalize.Framework.Objects public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { - - foreach(KeyValuePair pair in this.objects) - { - pair.Value.placementAction(location, x + (int)pair.Key.X*Game1.tileSize, y + (int)pair.Key.Y*Game1.tileSize, who); - Revitalize.ModCore.log(pair.Value.TileLocation); + foreach (KeyValuePair pair in this.objects) + { + pair.Value.placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who); + ModCore.log(pair.Value.TileLocation); } this.location = location; return true; @@ -168,21 +127,20 @@ namespace Revitalize.Framework.Objects public override bool canBePlacedHere(GameLocation l, Vector2 tile) { - foreach(KeyValuePair pair in this.objects) + foreach (KeyValuePair pair in this.objects) { - if (pair.Value.canBePlacedHere(l, tile + pair.Key) == false) return false; + if (!pair.Value.canBePlacedHere(l, tile + pair.Key)) + return false; } return true; } public override bool clicked(Farmer who) { - Revitalize.ModCore.log("WTF IS HAPPENING???"); - bool cleanUp=clicked(who); + ModCore.log("WTF IS HAPPENING???"); + bool cleanUp = this.clicked(who); if (cleanUp) - { - pickUp(); - } + this.pickUp(); return cleanUp; } @@ -204,13 +162,13 @@ namespace Revitalize.Framework.Objects public override Item getOne() { - return new MultiTiledObject(this.info, this.TileLocation,this.objects); + return new MultiTiledObject(this.info, this.TileLocation, this.objects); } public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) { BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]]; - return new MultiTiledObject((BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]], (replacement as Chest).TileLocation,this.objects); + return new MultiTiledObject(data, (replacement as Chest).TileLocation, this.objects); } } } diff --git a/GeneralMods/Revitalize/Framework/Player/Managers/SittingInfo.cs b/GeneralMods/Revitalize/Framework/Player/Managers/SittingInfo.cs index ef668982..3e429060 100644 --- a/GeneralMods/Revitalize/Framework/Player/Managers/SittingInfo.cs +++ b/GeneralMods/Revitalize/Framework/Player/Managers/SittingInfo.cs @@ -1,100 +1,61 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Revitalize.Framework.Player.Managers { - /// - /// TODO: - /// Make chair - /// animate player better - /// have it where when player is sitting on chair it is passable so it can't be destoryed underneath - /// + // TODO: + // - Make chair + // - animate player better + // - have it where when player is sitting on chair it is passable so it can't be destoryed underneath public class SittingInfo { - /// - /// If the player is currently sitting. - /// + /// If the player is currently sitting. public bool isSitting; - /// - /// How long a Farmer has sat (in milliseconds) - /// + /// How long a Farmer has sat (in milliseconds) private int elapsedTime; - /// - /// Gets how long the farmer has sat (in milliseconds). - /// - public int ElapsedTime - { - get - { - return elapsedTime; - } - } + /// Gets how long the farmer has sat (in milliseconds). + public int ElapsedTime => this.elapsedTime; - /// - /// Keeps trck of time elapsed. - /// + /// Keeps trck of time elapsed. GameTime timer; + + /// How long a player has to sit to recover energy/health; + public int SittingSpan { get; } - /// - /// The default amount of time a player has to sit to recover some energy/health - /// - private int _sittingSpan; - /// - /// A modified version of how long a player has to sit to recover energy/health; - /// - public int SittingSpan - { - get - { - return _sittingSpan; - } - } - - - - /// - /// Constructor. - /// + /// Construct an instance. public SittingInfo() { - timer = Game1.currentGameTime; - this._sittingSpan = 10000; + this.timer = Game1.currentGameTime; + this.SittingSpan = 10000; } - /// - /// Update the sitting info. - /// + /// Update the sitting info. public void update() { if (Game1.activeClickableMenu != null) return; if (Game1.player.isMoving()) { - isSitting = false; - elapsedTime = 0; + this.isSitting = false; + this.elapsedTime = 0; } - if (isSitting && Game1.player.CanMove) + if (this.isSitting && Game1.player.CanMove) { - showSitting(); - if (timer == null) timer = Game1.currentGameTime; - elapsedTime += timer.ElapsedGameTime.Milliseconds; + this.showSitting(); + if (this.timer == null) this.timer = Game1.currentGameTime; + this.elapsedTime += this.timer.ElapsedGameTime.Milliseconds; } - if (elapsedTime >= SittingSpan) + if (this.elapsedTime >= this.SittingSpan) { - elapsedTime %= SittingSpan; + this.elapsedTime %= this.SittingSpan; Game1.player.health++; Game1.player.Stamina++; } - Revitalize.ModCore.log(elapsedTime); + ModCore.log(this.elapsedTime); } @@ -103,26 +64,25 @@ namespace Revitalize.Framework.Player.Managers switch (Game1.player.FacingDirection) { case 0: - Game1.player.FarmerSprite.setCurrentSingleFrame(113, (short)32000, false, false); + Game1.player.FarmerSprite.setCurrentSingleFrame(113); break; case 1: - Game1.player.FarmerSprite.setCurrentSingleFrame(106, (short)32000, false, false); + Game1.player.FarmerSprite.setCurrentSingleFrame(106); break; case 2: - Game1.player.FarmerSprite.setCurrentSingleFrame(107, (short)32000, false, false); + Game1.player.FarmerSprite.setCurrentSingleFrame(107); break; case 3: - Game1.player.FarmerSprite.setCurrentSingleFrame(106, (short)32000, false, true); + Game1.player.FarmerSprite.setCurrentSingleFrame(106); break; } } - public void sit(StardewValley.Object obj,Vector2 offset) + public void sit(StardewValley.Object obj, Vector2 offset) { this.isSitting = true; Game1.player.Position = (obj.TileLocation * Game1.tileSize + offset); - Game1.player.position.Y += Game1.tileSize/2; + Game1.player.position.Y += Game1.tileSize / 2; } - } } diff --git a/GeneralMods/Revitalize/Framework/Player/PlayerInfo.cs b/GeneralMods/Revitalize/Framework/Player/PlayerInfo.cs index efde5463..3c0dc322 100644 --- a/GeneralMods/Revitalize/Framework/Player/PlayerInfo.cs +++ b/GeneralMods/Revitalize/Framework/Player/PlayerInfo.cs @@ -1,11 +1,4 @@ -using Microsoft.Xna.Framework; using Revitalize.Framework.Player.Managers; -using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Revitalize.Framework.Player { @@ -15,13 +8,12 @@ namespace Revitalize.Framework.Player public PlayerInfo() { - sittingInfo = new SittingInfo(); + this.sittingInfo = new SittingInfo(); } - public void update() { - sittingInfo.update(); + this.sittingInfo.update(); } } } diff --git a/GeneralMods/Revitalize/Framework/Utilities/InventoryManager.cs b/GeneralMods/Revitalize/Framework/Utilities/InventoryManager.cs index 2816519c..1265d65d 100644 --- a/GeneralMods/Revitalize/Framework/Utilities/InventoryManager.cs +++ b/GeneralMods/Revitalize/Framework/Utilities/InventoryManager.cs @@ -1,223 +1,132 @@ -using StardewValley; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using StardewValley; namespace Revitalize.Framework.Utilities { - /// - /// Handles dealing with objects. - /// + /// Handles dealing with objects. public class InventoryManager { - /// - /// How many items the inventory can hold. - /// + /// How many items the inventory can hold. public int capacity; - /// - /// The hard uper limit in case of upgrading or resizing. - /// - private int maxCapacity; + /// The hard uper limit for # of items to be held in case of upgrading or resizing. + public int MaxCapacity { get; private set; } - /// - /// The hard uper limit for # of items to be held in case of upgrading or resizing. - /// - public int MaxCapacity - { - get - { - return maxCapacity; - } - } + /// How many items are currently stored in the inventory. + public int ItemCount => this.items.Count; - /// - /// How many items are currently stored in the inventory. - /// - public int ItemCount - { - get - { - return this.items.Count; - } - } - - /// - /// The actual contents of the inventory. - /// + /// The actual contents of the inventory. public List items; - /// - /// Checks if the inventory is full or not. - /// - public bool IsFull - { - get - { - return this.ItemCount >= this.capacity; - } - } + /// Checks if the inventory is full or not. + public bool IsFull => this.ItemCount >= this.capacity; - /// - /// Checks to see if this core object actually has a valid inventory. - /// - public bool HasInventory - { - get - { - if (this.capacity <= 0) return false; - return true; - } - } + /// Checks to see if this core object actually has a valid inventory. + public bool HasInventory => this.capacity > 0; public InventoryManager() { this.capacity = 0; - setMaxLimit(0); + this.setMaxLimit(0); this.items = new List(); } - /// - /// Constructor. - /// - /// + /// Construct an instance. public InventoryManager(List items) { - this.capacity = Int32.MaxValue; - this.setMaxLimit(Int32.MaxValue); + this.capacity = int.MaxValue; + this.setMaxLimit(int.MaxValue); this.items = items; } - /// - /// Constructor. - /// - /// + /// Construct an instance. public InventoryManager(int capacity) { this.capacity = capacity; - this.maxCapacity = Int32.MaxValue; + this.MaxCapacity = int.MaxValue; this.items = new List(); } - /// - /// Constructor. - /// - /// - /// + /// Construct an instance. public InventoryManager(int capacity, int MaxCapacity) { this.capacity = capacity; - setMaxLimit(MaxCapacity); + this.setMaxLimit(MaxCapacity); this.items = new List(); } - /// - /// Add the item to the inventory. - /// - /// - /// - public bool addItem(Item I) + /// Add the item to the inventory. + public bool addItem(Item item) { - if (IsFull) + if (this.IsFull) { return false; } else { - foreach(Item self in this.items) + foreach (Item self in this.items) { - if (self == null) continue; - if (self.canStackWith(I)) + if (self != null && self.canStackWith(item)) { - self.addToStack(I.Stack); + self.addToStack(item.Stack); return true; } } - this.items.Add(I); + this.items.Add(item); return true; } } - /// - /// Gets a reference to the object IF it exists in the inventory. - /// - /// - /// - public Item getItem(Item I) + /// Gets a reference to the object IF it exists in the inventory. + public Item getItem(Item item) { - foreach(Item i in this.items) + foreach (Item i in this.items) { - if (I == i) return I; + if (item == i) + return item; } return null; } - /// - /// Get the item at the specific index. - /// - /// - /// - public Item getItemAtIndex(int Index) + /// Get the item at the specific index. + public Item getItemAtIndex(int index) { - return items[Index]; + return this.items[index]; } - /// - /// Gets only one item from the stack. - /// - /// - /// - public Item getSingleItemFromStack(Item I) + /// Gets only one item from the stack. + public Item getSingleItemFromStack(Item item) { - if (I.Stack == 1) - { - return I; - } - else - { - I.Stack = I.Stack - 1; - return I.getOne(); - } + if (item.Stack == 1) + return item; + + item.Stack = item.Stack - 1; + return item.getOne(); } - /// - /// Empty the inventory. - /// + /// Empty the inventory. public void clear() { this.items.Clear(); } - /// - /// Empty the inventory. - /// + /// Empty the inventory. public void empty() { this.clear(); } - /// - /// Resize how many items can be held by this object. - /// - /// + /// Resize how many items can be held by this object. public void resizeCapacity(int Amount) { - if (this.capacity + Amount < this.maxCapacity) - { + if (this.capacity + Amount < this.MaxCapacity) this.capacity += Amount; - } } - /// - /// Sets the upper limity of the capacity size for the inventory. - /// - /// + /// Sets the upper limity of the capacity size for the inventory. public void setMaxLimit(int amount) { - this.maxCapacity = amount; + this.MaxCapacity = amount; } - } } diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index c1858c8b..f0a63dfa 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -1,86 +1,79 @@ -using Microsoft.Xna.Framework; -using PyTK.Types; -using PyTK.Extensions; -using Revitalize.Framework.Objects; -using StardewModdingAPI; -using StardewValley; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.IO; +using Microsoft.Xna.Framework; +using PyTK.Extensions; +using PyTK.Types; +using Revitalize.Framework.Crafting; +using Revitalize.Framework.Environment; using Revitalize.Framework.Graphics; using Revitalize.Framework.Graphics.Animations; -using Revitalize.Framework.Environment; -using System.IO; -using Revitalize.Framework.Crafting; -using StardewValley.Objects; using Revitalize.Framework.Illuminate; +using Revitalize.Framework.Objects; using Revitalize.Framework.Player; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Objects; namespace Revitalize { - - /* - * Todo: - * -Multiple Lights On Object - * -Illumination Colors - * Furniture: - * -rugs - * -tables - * -lamps - * -chairs - * -dressers/other storage containers - * -fun interactables - * -More crafting tables - * -Machines - * !=Energy - * -Furnace - * -Seed Maker - * -Stone Quarry - * -Materials - * -Tin/Bronze/Alluminum/Silver?Platinum/Etc - * -Crafting Menu - * -Item Grab Menu (Extendable) - * -Gift Boxes - * Magic! - * -Alchemy Bags - * -Transmutation - * -Effect Crystals - * -Spell books - * -Potions! - * -Magic Meter - * Festivals - * -Firework festival? - * Stargazing??? - * -Moon Phases+DarkerNight - * Bigger/Better Museum? - * More Crops? - * More Food? - * - * Equippables! - * -accessories that provide buffs/regen/friendship - * - * Music??? - * -IDK maybe add in instruments??? - * - * More buildings???? - * - * More Animals??? - * - * Readable Books? - * - * Custom NPCs for shops??? - * - * Frisbee Minigame? - * - * HorseRace Minigame/Betting? - * - * Locations: - * -Small Island Home? - * - * More crops - */ + // TODO: + // -Multiple Lights On Object + // -Illumination Colors + // Furniture: + // -rugs + // -tables + // -lamps + // -chairs + // -dressers/other storage containers + // -fun interactables + // -More crafting tables + // -Machines + // !=Energy + // -Furnace + // -Seed Maker + // -Stone Quarry + // -Materials + // -Tin/Bronze/Alluminum/Silver?Platinum/Etc + // -Crafting Menu + // -Item Grab Menu (Extendable) + // -Gift Boxes + // Magic! + // -Alchemy Bags + // -Transmutation + // -Effect Crystals + // -Spell books + // -Potions! + // -Magic Meter + // Festivals + // -Firework festival? + // Stargazing??? + // -Moon Phases+DarkerNight + // Bigger/Better Museum? + // More Crops? + // More Food? + // + // Equippables! + // -accessories that provide buffs/regen/friendship + // + // Music??? + // -IDK maybe add in instruments??? + // + // More buildings???? + // + // More Animals??? + // + // Readable Books? + // + // Custom NPCs for shops??? + // + // Frisbee Minigame? + // + // HorseRace Minigame/Betting? + // + // Locations: + // -Small Island Home? + // + // More crops public class ModCore : Mod { @@ -94,19 +87,17 @@ namespace Revitalize public override void Entry(IModHelper helper) { ModHelper = helper; - ModMonitor = Monitor; + ModMonitor = this.Monitor; - createDirectories(); - initailizeComponents(); + this.createDirectories(); + this.initailizeComponents(); - - ModHelper.Events.GameLoop.SaveLoaded += GameLoop_SaveLoaded; - ModHelper.Events.GameLoop.TimeChanged += GameLoop_TimeChanged; - ModHelper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked; + ModHelper.Events.GameLoop.SaveLoaded += this.GameLoop_SaveLoaded; + ModHelper.Events.GameLoop.TimeChanged += this.GameLoop_TimeChanged; + ModHelper.Events.GameLoop.UpdateTicked += this.GameLoop_UpdateTicked; playerInfo = new PlayerInfo(); } - private void createDirectories() { Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath, "Configs")); @@ -117,7 +108,6 @@ namespace Revitalize DarkerNight.InitializeConfig(); } - private void GameLoop_UpdateTicked(object sender, StardewModdingAPI.Events.UpdateTickedEventArgs e) { DarkerNight.SetDarkerColor(); @@ -131,14 +121,14 @@ namespace Revitalize private void GameLoop_SaveLoaded(object sender, StardewModdingAPI.Events.SaveLoadedEventArgs e) { - MultiTiledComponent obj = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest","YAY FUN!","Omegasis.Revitalize.MultiTiledComponent",Color.White,-300,0,false,100,Vector2.Zero,true,true,"Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet,Color.White,0,true,typeof(MultiTiledComponent),null,new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet),new Animation(new Rectangle(0,0,16,16))),Color.Red,true,null,null)); - MultiTiledComponent obj2 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest2", "SomeFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 16, 16, 16))), Color.Red,false,null,null)); - MultiTiledComponent obj3 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest3", "NoFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 32, 16, 16))), Color.Red,false,null,null)); + MultiTiledComponent obj = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest", "YAY FUN!", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 0, 16, 16))), Color.Red, true, null, null)); + MultiTiledComponent obj2 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest2", "SomeFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 16, 16, 16))), Color.Red, false, null, null)); + MultiTiledComponent obj3 = new MultiTiledComponent(new BasicItemInformation("CoreObjectTest3", "NoFun", "Omegasis.Revitalize.MultiTiledComponent", Color.White, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.TEST1", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledComponent), null, new AnimationManager(new Texture2DExtended(Game1.objectSpriteSheet), new Animation(new Rectangle(0, 32, 16, 16))), Color.Red, false, null, null)); obj.info.lightManager.addLight(new Vector2(Game1.tileSize), new LightSource(4, new Vector2(0, 0), 2.5f, Color.Orange.Invert()), obj); - MultiTiledObject bigObject= new MultiTiledObject(new BasicItemInformation("MultiTest", "A really big object", "Omegasis.Revitalize.MultiTiledObject", Color.Blue, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.BigTiledTest", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledObject), null, new AnimationManager(), Color.White,false,null,null)); + MultiTiledObject bigObject = new MultiTiledObject(new BasicItemInformation("MultiTest", "A really big object", "Omegasis.Revitalize.MultiTiledObject", Color.Blue, -300, 0, false, 100, Vector2.Zero, true, true, "Omegasis.BigTiledTest", "2048/0/-300/Crafting -9/Play '2048 by Platonymous' at home!/true/true/0/2048", Game1.objectSpriteSheet, Color.White, 0, true, typeof(MultiTiledObject), null, new AnimationManager(), Color.White, false, null, null)); bigObject.addComponent(new Vector2(0, 0), obj); bigObject.addComponent(new Vector2(1, 0), obj2); bigObject.addComponent(new Vector2(2, 0), obj3); @@ -146,22 +136,20 @@ namespace Revitalize Recipe pie = new Recipe(new Dictionary() { [bigObject] = 1 - },new KeyValuePair(new Furniture(3,Vector2.Zero),1)); + }, new KeyValuePair(new Furniture(3, Vector2.Zero), 1)); - new InventoryItem(bigObject, 100,1).addToNPCShop("Gus"); + new InventoryItem(bigObject, 100, 1).addToNPCShop("Gus"); Game1.player.addItemToInventory(bigObject); - - if (pie.PlayerCanCraft()) - { - //pie.craft(); - } - + + //if (pie.PlayerCanCraft()) + //{ + // pie.craft(); + //} } public static void log(object message) { - ModMonitor.Log(message.ToString()); } } diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj index c117d27d..8fa04685 100644 --- a/GeneralMods/Revitalize/Revitalize.csproj +++ b/GeneralMods/Revitalize/Revitalize.csproj @@ -11,8 +11,6 @@ Revitalize v4.6.1 512 - - true @@ -31,9 +29,12 @@ prompt 4 + + + - ..\..\..\..\..\..\..\Desktop\New folder (2)\PyTK.dll + $(GamePath)\Mods\PyTK\PyTK.dll @@ -65,20 +66,6 @@ - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/Revitalize/packages.config b/GeneralMods/Revitalize/packages.config deleted file mode 100644 index 84563214..00000000 --- a/GeneralMods/Revitalize/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/SaveAnywhere/Framework/ModConfig.cs b/GeneralMods/SaveAnywhere/Framework/ModConfig.cs index 2fc20210..e48269e3 100644 --- a/GeneralMods/SaveAnywhere/Framework/ModConfig.cs +++ b/GeneralMods/SaveAnywhere/Framework/ModConfig.cs @@ -1,4 +1,4 @@ -namespace Omegasis.SaveAnywhere.Framework +namespace Omegasis.SaveAnywhere.Framework { /// The mod configuration. internal class ModConfig diff --git a/GeneralMods/SaveAnywhere/Framework/Models/CharacterType.cs b/GeneralMods/SaveAnywhere/Framework/Models/CharacterType.cs index da6e2530..39d40429 100644 --- a/GeneralMods/SaveAnywhere/Framework/Models/CharacterType.cs +++ b/GeneralMods/SaveAnywhere/Framework/Models/CharacterType.cs @@ -1,4 +1,4 @@ -namespace Omegasis.SaveAnywhere.Framework.Models +namespace Omegasis.SaveAnywhere.Framework.Models { /// The character type for an NPC. public enum CharacterType diff --git a/GeneralMods/SaveAnywhere/Framework/Models/PositionData.cs b/GeneralMods/SaveAnywhere/Framework/Models/PositionData.cs index 5708b451..17ac9cf8 100644 --- a/GeneralMods/SaveAnywhere/Framework/Models/PositionData.cs +++ b/GeneralMods/SaveAnywhere/Framework/Models/PositionData.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; namespace Omegasis.SaveAnywhere.Framework.Models { diff --git a/GeneralMods/SaveAnywhere/Framework/NewSaveGameMenu.cs b/GeneralMods/SaveAnywhere/Framework/NewSaveGameMenu.cs index b3917895..6a5523c1 100644 --- a/GeneralMods/SaveAnywhere/Framework/NewSaveGameMenu.cs +++ b/GeneralMods/SaveAnywhere/Framework/NewSaveGameMenu.cs @@ -1,40 +1,34 @@ -using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewValley; using StardewValley.BellsAndWhistles; using StardewValley.Menus; -using System; -using System.Collections.Generic; -using System.Text; namespace Omegasis.SaveAnywhere.Framework { - /// A marker subclass to detect when a custom save is in progress. - internal class NewSaveGameMenu : SaveGameMenu { - + internal class NewSaveGameMenu : SaveGameMenu + { public event EventHandler SaveComplete; private int completePause = -1; private int margin = 500; - private StringBuilder _stringBuilder = new StringBuilder(); + private readonly StringBuilder _stringBuilder = new StringBuilder(); private float _ellipsisDelay = 0.5f; private IEnumerator loader; public bool quit; public bool hasDrawn; - private SparklingText saveText; + private readonly SparklingText saveText; private int _ellipsisCount; - + public NewSaveGameMenu() { - this.saveText = new SparklingText(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:SaveGameMenu.cs.11378"), Color.LimeGreen, new Color((int)(Color.Black.R * (1.0 / 1000.0)),(int)( Color.Black.G * (1.0 / 1000.0)),(int)( Color.Black.B * (1.0 / 1000.0)),255), false, 0.1, 1500, 32, 500); + this.saveText = new SparklingText(Game1.dialogueFont, Game1.content.LoadString("Strings\\StringsFromCSFiles:SaveGameMenu.cs.11378"), Color.LimeGreen, new Color((int)(Color.Black.R * (1.0 / 1000.0)), (int)(Color.Black.G * (1.0 / 1000.0)), (int)(Color.Black.B * (1.0 / 1000.0)), 255), false, 0.1, 1500, 32, 500); } - public override void receiveRightClick(int x, int y, bool playSound = true) - { - } - - public new void complete() { Game1.playSound("money"); @@ -91,9 +85,7 @@ namespace Omegasis.SaveAnywhere.Framework if (Game1.IsMasterGame) { if (Game1.saveOnNewDay) - { this.loader = SaveGame.Save(); - } else { this.margin = -1; @@ -105,7 +97,6 @@ namespace Omegasis.SaveAnywhere.Framework NewSaveGameMenu.saveClientOptions(); this.complete(); } - } if (this.completePause < 0) return; @@ -171,8 +162,4 @@ namespace Omegasis.SaveAnywhere.Framework Game1.game1.IsSaving = false; } } - - } - - diff --git a/GeneralMods/SaveAnywhere/Framework/NewShippingMenu.cs b/GeneralMods/SaveAnywhere/Framework/NewShippingMenu.cs index 87dd59e6..8aa2d542 100644 --- a/GeneralMods/SaveAnywhere/Framework/NewShippingMenu.cs +++ b/GeneralMods/SaveAnywhere/Framework/NewShippingMenu.cs @@ -1,4 +1,4 @@ -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework; using Netcode; using StardewModdingAPI; using StardewValley; @@ -16,8 +16,6 @@ namespace Omegasis.SaveAnywhere.Framework private readonly IReflectedField SavedYet; - - /********* ** Public methods *********/ @@ -30,12 +28,7 @@ namespace Omegasis.SaveAnywhere.Framework this.SavedYet = reflection.GetField(this, "savedYet"); } - /// - /// Overrides some base functionality of the shipping menu to enable proper closing. - /// - /// - /// - /// + /// Overrides some base functionality of the shipping menu to enable proper closing. public override void receiveLeftClick(int x, int y, bool playSound = true) { if (this.okButton.containsPoint(x, y)) this.exitThisMenu(true); diff --git a/GeneralMods/SaveAnywhere/Framework/SaveManager.cs b/GeneralMods/SaveAnywhere/Framework/SaveManager.cs index 16eb42b1..96789e17 100644 --- a/GeneralMods/SaveAnywhere/Framework/SaveManager.cs +++ b/GeneralMods/SaveAnywhere/Framework/SaveManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -52,10 +52,7 @@ namespace Omegasis.SaveAnywhere.Framework } - private void empty(object o, EventArgs args) - { - - } + private void empty(object o, EventArgs args) { } /// Perform any required update logic. public void Update() @@ -63,22 +60,20 @@ namespace Omegasis.SaveAnywhere.Framework // perform passive save if (this.WaitingToSave && Game1.activeClickableMenu == null) { - currentSaveMenu = new NewSaveGameMenu(); - currentSaveMenu.SaveComplete += CurrentSaveMenu_SaveComplete; - Game1.activeClickableMenu = currentSaveMenu; + this.currentSaveMenu = new NewSaveGameMenu(); + this.currentSaveMenu.SaveComplete += this.CurrentSaveMenu_SaveComplete; + Game1.activeClickableMenu = this.currentSaveMenu; this.WaitingToSave = false; } } - /// - /// Event function for NewSaveGameMenu event SaveComplete - /// - /// - /// + /// Event function for NewSaveGameMenu event SaveComplete + /// The event sender. + /// The event arguments. private void CurrentSaveMenu_SaveComplete(object sender, EventArgs e) { - currentSaveMenu.SaveComplete -= CurrentSaveMenu_SaveComplete; - currentSaveMenu = null; + this.currentSaveMenu.SaveComplete -= this.CurrentSaveMenu_SaveComplete; + this.currentSaveMenu = null; //AfterSave.Invoke(this, EventArgs.Empty); } @@ -92,12 +87,11 @@ namespace Omegasis.SaveAnywhere.Framework /// Initiate a game save. public void BeginSaveData() { - // save game data Farm farm = Game1.getFarm(); if (farm.shippingBin.Any()) { - + Game1.activeClickableMenu = new NewShippingMenu(farm.shippingBin, this.Reflection); farm.shippingBin.Clear(); farm.lastItemShipped = null; @@ -105,11 +99,11 @@ namespace Omegasis.SaveAnywhere.Framework } else { - currentSaveMenu = new NewSaveGameMenu(); - currentSaveMenu.SaveComplete += CurrentSaveMenu_SaveComplete; - Game1.activeClickableMenu = currentSaveMenu; + this.currentSaveMenu = new NewSaveGameMenu(); + this.currentSaveMenu.SaveComplete += this.CurrentSaveMenu_SaveComplete; + Game1.activeClickableMenu = this.currentSaveMenu; } - + // get data PlayerData data = new PlayerData @@ -146,23 +140,19 @@ namespace Omegasis.SaveAnywhere.Framework //AfterLoad.Invoke(this, EventArgs.Empty); } - /// - /// Checks to see if the player was swimming when the game was saved and if so, resumes the swimming animation. - /// - /// + /// Checks to see if the player was swimming when the game was saved and if so, resumes the swimming animation. public void ResumeSwimming(PlayerData data) { try { - if (data.IsCharacterSwimming == true) + if (data.IsCharacterSwimming) { Game1.player.changeIntoSwimsuit(); Game1.player.swimming.Value = true; } } - catch (Exception err) + catch { - err.ToString(); //Here to allow compatability with old save files. } } @@ -178,7 +168,8 @@ namespace Omegasis.SaveAnywhere.Framework var player = Game1.player; string name = player.Name; string map = player.currentLocation.uniqueName.Value; //Try to get a unique name for the location and if we can't we are going to default to the actual name of the map. - if (map == ""|| map==null) map = player.currentLocation.Name; //This is used to account for maps that share the same name but have a unique ID such as Coops, Barns and Sheds. + if (string.IsNullOrEmpty(map)) + map = player.currentLocation.Name; //This is used to account for maps that share the same name but have a unique ID such as Coops, Barns and Sheds. Point tile = player.getTileLocationPoint(); int facingDirection = player.facingDirection; @@ -189,9 +180,8 @@ namespace Omegasis.SaveAnywhere.Framework foreach (NPC npc in Utility.getAllCharacters()) { CharacterType? type = this.GetCharacterType(npc); - if (type == null) + if (type == null || npc?.currentLocation == null) continue; - if (npc == null || npc.currentLocation == null) continue; string name = npc.Name; string map = npc.currentLocation.Name; Point tile = npc.getTileLocationPoint(); diff --git a/GeneralMods/SaveAnywhere/SaveAnywhere.cs b/GeneralMods/SaveAnywhere/SaveAnywhere.cs index ee824935..8908de45 100644 --- a/GeneralMods/SaveAnywhere/SaveAnywhere.cs +++ b/GeneralMods/SaveAnywhere/SaveAnywhere.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Omegasis.SaveAnywhere.Framework; @@ -31,20 +31,17 @@ namespace Omegasis.SaveAnywhere /// Whether we're performing a non-vanilla save (i.e. not by sleeping in bed). private bool IsCustomSaving; - - /// - /// Used to access the Mod's helper from other files associated with the mod. - /// + /// Used to access the Mod's helper from other files associated with the mod. public static IModHelper ModHelper; - /// - /// Used to access the Mod's monitor to allow for debug logging in other files associated with the mod. - /// + + /// Used to access the Mod's monitor to allow for debug logging in other files associated with the mod. public static IMonitor ModMonitor; private List monsters; private bool customMenuOpen; + /********* ** Public methods *********/ @@ -63,16 +60,11 @@ namespace Omegasis.SaveAnywhere TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted; ModHelper = helper; - ModMonitor = Monitor; - customMenuOpen = false; + ModMonitor = this.Monitor; + this.customMenuOpen = false; } - /*Notes. Mods that want to support save anywhere will get the api for Save anywhere and then add their clean up code to the events that happen for Before/After Save and Loading. - Example with pseudo code. - SaveAnywhere.api.BeforeSave+=StardustCore.Objects.CleanUpBeforeSave; - We then can use function wrapping (is that what it's called?) to just handle calling the actual function that deals with clean-up code. - */ /********* ** Private methods *********/ @@ -95,28 +87,25 @@ namespace Omegasis.SaveAnywhere private void SaveEvents_AfterSave(object sender, EventArgs e) { // clear custom data after a normal save (to avoid restoring old state) - if (!this.IsCustomSaving) + if (!this.IsCustomSaving) this.SaveManager.ClearData(); else { - IsCustomSaving = false; + this.IsCustomSaving = false; } } - /// The method invoked when the game updates (roughly 60 times per second). /// The event sender. /// The event data. private void GameEvents_UpdateTick(object sender, EventArgs e) { - // let save manager run background logic if (Context.IsWorldReady) { - if (Game1.player.IsMainPlayer == false) return; + if (!Game1.player.IsMainPlayer) return; this.SaveManager.Update(); } - // reset NPC schedules if (Context.IsWorldReady && this.ShouldResetSchedules) @@ -125,10 +114,10 @@ namespace Omegasis.SaveAnywhere this.ApplySchedules(); } - if (Game1.activeClickableMenu == null && this.customMenuOpen == false) return; - if(Game1.activeClickableMenu==null && this.customMenuOpen == true) + if (Game1.activeClickableMenu == null && !this.customMenuOpen) return; + if (Game1.activeClickableMenu == null && this.customMenuOpen) { - restoreMonsters(); + this.restoreMonsters(); this.customMenuOpen = false; return; } @@ -141,43 +130,30 @@ namespace Omegasis.SaveAnywhere } } - /// - /// Saves all monsters from the game world. - /// + /// Saves all monsters from the game world. private void cleanMonsters() { - monsters = new List(); + this.monsters = new List(); - foreach (var monster in Game1.player.currentLocation.characters) + foreach (var npc in Game1.player.currentLocation.characters) { try { - if (monster is Monster) - { - monsters.Add(monster as Monster); - } - } - catch (Exception err) - { - + if (npc is Monster monster) + this.monsters.Add(monster); } + catch { } } foreach (var monster in this.monsters) - { Game1.player.currentLocation.characters.Remove(monster); - } } - /// - /// Adds all saved monster back into the game world. - /// + /// Adds all saved monster back into the game world. private void restoreMonsters() { foreach (var monster in this.monsters) - { Game1.player.currentLocation.characters.Add(monster); - } } /// The method invoked after a new day starts. @@ -205,14 +181,12 @@ namespace Omegasis.SaveAnywhere if (!Context.IsPlayerFree) return; - - // initiate save (if valid context) if (e.KeyPressed.ToString() == this.Config.SaveKey) { - if (Game1.client==null) + if (Game1.client == null) { - cleanMonsters(); + this.cleanMonsters(); // validate: community center Junimos can't be saved if (Game1.player.currentLocation.getCharacters().OfType().Any()) @@ -221,14 +195,13 @@ namespace Omegasis.SaveAnywhere return; } - // save this.IsCustomSaving = true; this.SaveManager.BeginSaveData(); } else { - Game1.addHUDMessage(new HUDMessage("Only server hosts can save anywhere.",HUDMessage.error_type)); + Game1.addHUDMessage(new HUDMessage("Only server hosts can save anywhere.", HUDMessage.error_type)); } } } @@ -251,16 +224,14 @@ namespace Omegasis.SaveAnywhere continue; // get schedule data - string scheduleData; - if (!this.NpcSchedules.TryGetValue(npc.Name, out scheduleData) || string.IsNullOrEmpty(scheduleData)) + if (!this.NpcSchedules.TryGetValue(npc.Name, out string scheduleData) || string.IsNullOrEmpty(scheduleData)) { //this.Monitor.Log("THIS IS AWKWARD"); continue; } // get schedule script - string script; - if (!rawSchedule.TryGetValue(scheduleData, out script)) + if (!rawSchedule.TryGetValue(scheduleData, out string script)) continue; // parse entries @@ -300,10 +271,8 @@ namespace Omegasis.SaveAnywhere .Invoke(npc.currentLocation.Name, npc.getTileX(), npc.getTileY(), endMap, x, y, endFacingDir, null, null); index++; } - catch (Exception ex) + catch { - ex.ToString(); - //this.Monitor.Log($"Error pathfinding NPC {npc.name}: {ex}", LogLevel.Error); continue; } @@ -326,7 +295,7 @@ namespace Omegasis.SaveAnywhere { return Game1.content.Load>($"Characters\\schedules\\{npcName}"); } - catch (Exception) + catch { return null; } @@ -375,9 +344,8 @@ namespace Omegasis.SaveAnywhere if (schedule.ContainsKey(Game1.currentSeason + "_" + Game1.dayOfMonth)) return Game1.currentSeason + "_" + Game1.dayOfMonth; int i; - Friendship f; - Game1.player.friendshipData.TryGetValue(npc.Name, out f); - for (i = (Game1.player.friendshipData.ContainsKey(npc.Name) ? (f.Points/ 250) : -1); i > 0; i--) + Game1.player.friendshipData.TryGetValue(npc.Name, out Friendship f); + for (i = (Game1.player.friendshipData.ContainsKey(npc.Name) ? (f.Points / 250) : -1); i > 0; i--) { if (schedule.ContainsKey(Game1.dayOfMonth + "_" + i)) return Game1.dayOfMonth + "_" + i; @@ -394,8 +362,7 @@ namespace Omegasis.SaveAnywhere return "rain"; } List list = new List { Game1.currentSeason, Game1.shortDayNameFromDayOfSeason(Game1.dayOfMonth) }; - Friendship friendship; - Game1.player.friendshipData.TryGetValue(npc.Name, out friendship); + Game1.player.friendshipData.TryGetValue(npc.Name, out Friendship friendship); i = (Game1.player.friendshipData.ContainsKey(npc.Name) ? (friendship.Points / 250) : -1); while (i > 0) { @@ -425,8 +392,7 @@ namespace Omegasis.SaveAnywhere } list.RemoveAt(list.Count - 1); list.Add("spring"); - Friendship friendship2; - Game1.player.friendshipData.TryGetValue(npc.Name, out friendship2); + Game1.player.friendshipData.TryGetValue(npc.Name, out Friendship friendship2); i = (Game1.player.friendshipData.ContainsKey(npc.Name) ? (friendship2.Points / 250) : -1); while (i > 0) { @@ -436,9 +402,9 @@ namespace Omegasis.SaveAnywhere i--; list.RemoveAt(list.Count - 1); } - if (schedule.ContainsKey("spring")) - return "spring"; - return null; + return schedule.ContainsKey("spring") + ? "spring" + : null; } } } diff --git a/GeneralMods/SaveAnywhere/SaveAnywhere.csproj b/GeneralMods/SaveAnywhere/SaveAnywhere.csproj index a059c773..2fb9a4ca 100644 --- a/GeneralMods/SaveAnywhere/SaveAnywhere.csproj +++ b/GeneralMods/SaveAnywhere/SaveAnywhere.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ SaveAnywhere v4.5.2 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -92,19 +93,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/SaveAnywhere/manifest.json b/GeneralMods/SaveAnywhere/manifest.json index bfaa6bb2..9ff92a6a 100644 --- a/GeneralMods/SaveAnywhere/manifest.json +++ b/GeneralMods/SaveAnywhere/manifest.json @@ -7,5 +7,5 @@ "EntryDll": "SaveAnywhere.dll", "MinimumApiVersion": "2.4", "Dependencies": [ - ] + ] } diff --git a/GeneralMods/SaveAnywhere/packages.config b/GeneralMods/SaveAnywhere/packages.config deleted file mode 100644 index 30506716..00000000 --- a/GeneralMods/SaveAnywhere/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/SimpleSoundManager/Framework/Sound.cs b/GeneralMods/SimpleSoundManager/Framework/Sound.cs index 3f3d5b44..0fb68e22 100644 --- a/GeneralMods/SimpleSoundManager/Framework/Sound.cs +++ b/GeneralMods/SimpleSoundManager/Framework/Sound.cs @@ -1,38 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace SimpleSoundManager.Framework { - /// - /// Interface used for common sound functionality; - /// + /// Interface used for common sound functionality; public interface Sound { - /// - /// Handles playing a sound. - /// + /// Handles playing a sound. void play(); void play(float volume); - /// - /// Handles pausing a song. - /// + + /// Handles pausing a song. void pause(); - /// - /// Handles stopping a song. - /// + + /// Handles stopping a song. void stop(); - /// - /// Handles restarting a song. - /// + + /// Handles restarting a song. void restart(); - /// - /// Handles getting a clone of the song. - /// - /// + + /// Handles getting a clone of the song. Sound clone(); string getSoundName(); diff --git a/GeneralMods/SimpleSoundManager/Framework/SoundManager.cs b/GeneralMods/SimpleSoundManager/Framework/SoundManager.cs index a9ce5a58..617baa6e 100644 --- a/GeneralMods/SimpleSoundManager/Framework/SoundManager.cs +++ b/GeneralMods/SimpleSoundManager/Framework/SoundManager.cs @@ -1,187 +1,117 @@ -using Microsoft.Xna.Framework.Audio; +using System.Collections.Generic; +using Microsoft.Xna.Framework.Audio; using StardewModdingAPI; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SimpleSoundManager.Framework { public class SoundManager { - - public Dictionary sounds; + public Dictionary sounds; public Dictionary musicBanks; public float volume; public List currentlyPlayingSounds = new List(); - /// - /// Constructor for this class. - /// + + /// Constructor for this class. public SoundManager() { this.sounds = new Dictionary(); this.musicBanks = new Dictionary(); - currentlyPlayingSounds = new List(); + this.currentlyPlayingSounds = new List(); this.volume = 1.0f; } - /// - /// Constructor for wav files. - /// - /// - /// - public void loadWavFile(string soundName,string pathToWav) + /// Constructor for wav files. + public void loadWavFile(string soundName, string pathToWav) { - WavSound wav = new WavSound(soundName,pathToWav); + WavSound wav = new WavSound(soundName, pathToWav); SimpleSoundManagerMod.ModMonitor.Log("Getting sound file:" + soundName); try { this.sounds.Add(soundName, wav); } - catch(Exception err) - { - - } + catch { } } - - /// - /// Constructor for wav files. - /// - /// - /// - /// - public void loadWavFile(IModHelper helper,string soundName,string pathToWav) + + /// Constructor for wav files. + public void loadWavFile(IModHelper helper, string soundName, string pathToWav) { - WavSound wav = new WavSound(helper ,soundName,pathToWav); + WavSound wav = new WavSound(helper, soundName, pathToWav); SimpleSoundManagerMod.ModMonitor.Log("Getting sound file:" + soundName); try { this.sounds.Add(soundName, wav); } - catch(Exception err) + catch { //Sound already added so no need to worry? } } - /// - /// Constructor for wav files. - /// - /// - /// - /// - public void loadWavFile(IModHelper helper,string songName,List pathToWav) + /// Constructor for wav files. + public void loadWavFile(IModHelper helper, string songName, List pathToWav) { - WavSound wav = new WavSound(helper,songName,pathToWav); + WavSound wav = new WavSound(helper, songName, pathToWav); SimpleSoundManagerMod.ModMonitor.Log("Getting sound file:" + songName); try { this.sounds.Add(songName, wav); } - catch(Exception err) - { - - } + catch { } } - /// - /// Constructor for XACT files. - /// - /// - /// - /// + /// Constructor for XACT files. public void loadXACTFile(WaveBank waveBank, ISoundBank soundBank, string songName) { XACTSound xactSound = new XACTSound(waveBank, soundBank, songName); this.sounds.Add(songName, xactSound); } - /// - /// Constructor for XACT files based on already added music packs. - /// - /// - /// + /// Constructor for XACT files based on already added music packs. public void loadXACTFile(string pairName, string songName) { - XACTMusicPair musicPair = getMusicPack(pairName); + XACTMusicPair musicPair = this.getMusicPack(pairName); if (pairName == null) - { return; - } - loadXACTFile(musicPair.waveBank, musicPair.soundBank, songName); + this.loadXACTFile(musicPair.waveBank, musicPair.soundBank, songName); } - - /// - /// Creates a music pack pair that holds .xwb and .xsb music files. - /// + /// Creates a music pack pair that holds .xwb and .xsb music files. /// The mod's helper that will handle the path of the files. /// The name of this music pack pair. /// The relative path to the .xwb file /// The relative path to the .xsb file - public void loadXACTMusicBank(IModHelper helper,string pairName,string wavName, string soundName) + public void loadXACTMusicBank(IModHelper helper, string pairName, string wavName, string soundName) { - this.musicBanks.Add(pairName,new XACTMusicPair(helper, wavName, soundName)); + this.musicBanks.Add(pairName, new XACTMusicPair(helper, wavName, soundName)); } - /// - /// Gets the music pack pair from the sound pool. - /// - /// - /// + /// Gets the music pack pair from the sound pool. public XACTMusicPair getMusicPack(string name) { - foreach(var pack in this.musicBanks) + foreach (var pack in this.musicBanks) { - if (name == pack.Key) return pack.Value; + if (name == pack.Key) + return pack.Value; } return null; } - /// - /// Gets a clone of the loaded sound. - /// - /// - /// + /// Gets a clone of the loaded sound. public Sound getSoundClone(string name) { - foreach(var sound in this.sounds) + foreach (var sound in this.sounds) { - if (sound.Key == name) return sound.Value.clone(); + if (sound.Key == name) + return sound.Value.clone(); } return null; } - /// - /// Play the sound with the given name. - /// - /// + /// Play the sound with the given name. public void playSound(string soundName) - { - SimpleSoundManagerMod.ModMonitor.Log("Trying to play sound: " + soundName); - foreach(var sound in this.sounds) - { - if (sound.Key == soundName) - { - SimpleSoundManagerMod.ModMonitor.Log("Time to play sound: " + soundName); - var s=getSoundClone(soundName); - s.play(this.volume); - this.currentlyPlayingSounds.Add(s); - break; - } - } - } - - /// - /// Play the sound with the given name and volume. - /// - /// - /// - public void playSound(string soundName,float volume=1.0f) { SimpleSoundManagerMod.ModMonitor.Log("Trying to play sound: " + soundName); foreach (var sound in this.sounds) @@ -189,7 +119,24 @@ namespace SimpleSoundManager.Framework if (sound.Key == soundName) { SimpleSoundManagerMod.ModMonitor.Log("Time to play sound: " + soundName); - var s = getSoundClone(soundName); + var s = this.getSoundClone(soundName); + s.play(this.volume); + this.currentlyPlayingSounds.Add(s); + break; + } + } + } + + /// Play the sound with the given name and volume. + public void playSound(string soundName, float volume = 1.0f) + { + SimpleSoundManagerMod.ModMonitor.Log("Trying to play sound: " + soundName); + foreach (var sound in this.sounds) + { + if (sound.Key == soundName) + { + SimpleSoundManagerMod.ModMonitor.Log("Time to play sound: " + soundName); + var s = this.getSoundClone(soundName); s.play(volume); this.currentlyPlayingSounds.Add(s); break; @@ -197,10 +144,7 @@ namespace SimpleSoundManager.Framework } } - /// - /// Stop the sound that is playing. - /// - /// + /// Stop the sound that is playing. public void stopSound(string soundName) { List removalList = new List(); @@ -212,16 +156,11 @@ namespace SimpleSoundManager.Framework removalList.Add(sound); } } - foreach(var v in removalList) - { + foreach (var v in removalList) this.currentlyPlayingSounds.Remove(v); - } } - /// - /// Pause the sound with this name? - /// - /// + /// Pause the sound with this name? public void pauseSound(string soundName) { List removalList = new List(); @@ -234,9 +173,7 @@ namespace SimpleSoundManager.Framework } } foreach (var v in removalList) - { this.currentlyPlayingSounds.Remove(v); - } } public void swapSounds(string newSong) @@ -247,29 +184,19 @@ namespace SimpleSoundManager.Framework public void update() { List removalList = new List(); - foreach(Sound song in this.currentlyPlayingSounds) + foreach (Sound song in this.currentlyPlayingSounds) { if (song.isStopped()) - { removalList.Add(song); - } } - foreach(var v in removalList) - { + foreach (var v in removalList) this.currentlyPlayingSounds.Remove(v); - } } public void stopAllSounds() { - foreach(var v in this.currentlyPlayingSounds) - { + foreach (var v in this.currentlyPlayingSounds) v.stop(); - } } - - - - } } diff --git a/GeneralMods/SimpleSoundManager/Framework/WavSound.cs b/GeneralMods/SimpleSoundManager/Framework/WavSound.cs index 6926b528..923248e4 100644 --- a/GeneralMods/SimpleSoundManager/Framework/WavSound.cs +++ b/GeneralMods/SimpleSoundManager/Framework/WavSound.cs @@ -1,95 +1,70 @@ -using Microsoft.Xna.Framework.Audio; -using SimpleSoundManager.Framework; -using StardewModdingAPI; -using StardewValley; using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Xna.Framework.Audio; +using SimpleSoundManager.Framework; +using StardewModdingAPI; namespace SimpleSoundManager { class WavSound : Sound { - /// - /// Used to actually play the song. - /// + /// Used to actually play the song. DynamicSoundEffectInstance dynamicSound; - /// - /// Used to keep track of where in the song we are. - /// - int position; - /// - /// ??? - /// - int count; - /// - /// Used to store the info for the song. - /// - byte[] byteArray; + /// Used to keep track of where in the song we are. + int position; + + int count; + + /// Used to store the info for the song. + byte[] byteArray; public string path; public string soundName; - public bool loop; - /// - /// Get a raw disk path to the wav file. - /// - /// - public WavSound(string name,string pathToWavFile,bool Loop=false) + /// Get a raw disk path to the wav file. + public WavSound(string name, string pathToWavFile, bool loop = false) { this.path = pathToWavFile; - LoadWavFromFileToStream(); + this.LoadWavFromFileToStream(); this.soundName = name; - this.loop = Loop; + this.loop = loop; } - /// - /// A constructor that takes a mod helper and a relative path to a wav file. - /// - /// - /// - public WavSound(IModHelper modHelper,string name, string pathInModDirectory,bool Loop=false) + /// A constructor that takes a mod helper and a relative path to a wav file. + public WavSound(IModHelper modHelper, string name, string pathInModDirectory, bool loop = false) { string path = Path.Combine(modHelper.DirectoryPath, pathInModDirectory); this.path = path; this.soundName = name; - this.loop = Loop; + this.loop = loop; } - /// - /// Constructor that is more flexible than typing an absolute path. - /// + /// Constructor that is more flexible than typing an absolute path. /// The mod helper for the mod you wish to use to load the music files from. /// The list of folders and files that make up a complete path. - public WavSound(IModHelper modHelper,string soundName, List pathPieces,bool Loop=false) + public WavSound(IModHelper modHelper, string soundName, List pathPieces, bool loop = false) { - string s = modHelper.DirectoryPath; - foreach(var str in pathPieces) - { - s = Path.Combine(s, str); - } - this.path = s; + string dirPath = modHelper.DirectoryPath; + foreach (string str in pathPieces) + dirPath = Path.Combine(dirPath, str); + this.path = dirPath; this.soundName = soundName; - this.loop = Loop; + this.loop = loop; } - /// - /// Loads the .wav file from disk and plays it. - /// + /// Loads the .wav file from disk and plays it. public void LoadWavFromFileToStream() { // Create a new SpriteBatch, which can be used to draw textures. string file = this.path; - System.IO.Stream waveFileStream = File.OpenRead(file); //TitleContainer.OpenStream(file); + Stream waveFileStream = File.OpenRead(file); //TitleContainer.OpenStream(file); BinaryReader reader = new BinaryReader(waveFileStream); @@ -115,104 +90,83 @@ namespace SimpleSoundManager int dataID = reader.ReadInt32(); int dataSize = reader.ReadInt32(); - byteArray = reader.ReadBytes(dataSize); + this.byteArray = reader.ReadBytes(dataSize); - dynamicSound = new DynamicSoundEffectInstance(sampleRate, (AudioChannels)channels); - count = byteArray.Length;//dynamicSound.GetSampleSizeInBytes(TimeSpan.FromMilliseconds(1000)); + this.dynamicSound = new DynamicSoundEffectInstance(sampleRate, (AudioChannels)channels); + this.count = this.byteArray.Length;//dynamicSound.GetSampleSizeInBytes(TimeSpan.FromMilliseconds(1000)); - dynamicSound.BufferNeeded += new EventHandler(DynamicSound_BufferNeeded); - + this.dynamicSound.BufferNeeded += this.DynamicSound_BufferNeeded; } void DynamicSound_BufferNeeded(object sender, EventArgs e) { try { - dynamicSound.SubmitBuffer(byteArray, position, count); - } - catch (Exception err) - { - //SimpleSoundManagerMod.ModMonitor.Log(err.ToString()); + this.dynamicSound.SubmitBuffer(this.byteArray, this.position, this.count); } + catch { } - position += count; - if (position + count > byteArray.Length) + this.position += this.count; + if (this.position + this.count > this.byteArray.Length) { - if (loop) - { - position = 0; - } - else - { - //this.stop(); - } + if (this.loop) + this.position = 0; + //else + // this.stop(); } } - /// - /// Used to pause the current song. - /// + /// Used to pause the current song. public void pause() { - if (dynamicSound != null) dynamicSound.Pause(); + this.dynamicSound?.Pause(); } - /// - /// Used to play a song. - /// - /// + /// Used to play a song. public void play() { - if (this.isPlaying() == true) return; - LoadWavFromFileToStream(); - dynamicSound.Play(); + if (this.isPlaying()) + return; + + this.LoadWavFromFileToStream(); + this.dynamicSound.Play(); } - /// - /// Used to play a song. - /// - /// + /// Used to play a song. /// How lound the sound is when playing. 0~1.0f public void play(float volume) { - if (this.isPlaying() == true) return; - LoadWavFromFileToStream(); - dynamicSound.Volume = volume; - dynamicSound.Play(); + if (this.isPlaying()) + return; + + this.LoadWavFromFileToStream(); + this.dynamicSound.Volume = volume; + this.dynamicSound.Play(); } - /// - /// Used to resume the currently playing song. - /// + /// Used to resume the currently playing song. public void resume() { - if (dynamicSound == null) return; - dynamicSound.Resume(); + dynamicSound?.Resume(); } - /// - /// Used to stop the currently playing song. - /// + /// Used to stop the currently playing song. public void stop() { - - if (dynamicSound != null) + if (this.dynamicSound != null) { - dynamicSound.Stop(true); - dynamicSound.BufferNeeded -= new EventHandler(DynamicSound_BufferNeeded); - position = 0; - count = 0; - byteArray = new byte[0]; + this.dynamicSound.Stop(true); + this.dynamicSound.BufferNeeded -= this.DynamicSound_BufferNeeded; + this.position = 0; + this.count = 0; + this.byteArray = new byte[0]; } } - /// - /// Used to change from one playing song to another; - /// - /// + /// Used to change from one playing song to another; public void swap(string pathToNewWavFile) { this.stop(); @@ -220,42 +174,27 @@ namespace SimpleSoundManager this.play(); } - /// - /// Checks if the song is currently playing. - /// - /// + /// Checks if the song is currently playing. public bool isPlaying() { - if (this.dynamicSound == null) return false; - if (this.dynamicSound.State == SoundState.Playing) return true; - else return false; + return this.dynamicSound?.State == SoundState.Playing; } - /// - /// Checks if the song is currently paused. - /// - /// + /// Checks if the song is currently paused. public bool isPaused() { - if (this.dynamicSound == null) return false; - if (this.dynamicSound.State == SoundState.Paused) return true; - else return false; + return this.dynamicSound?.State == SoundState.Paused; } - /// - /// Checks if the song is currently stopped. - /// - /// + /// Checks if the song is currently stopped. public bool isStopped() { - if (this.dynamicSound == null) return false; - if (this.dynamicSound.State == SoundState.Stopped) return true; - else return false; + return this.dynamicSound?.State == SoundState.Stopped; } public Sound clone() { - return new WavSound(this.getSoundName(),this.path); + return new WavSound(this.getSoundName(), this.path); } public string getSoundName() @@ -268,6 +207,5 @@ namespace SimpleSoundManager this.stop(); this.play(); } - } } diff --git a/GeneralMods/SimpleSoundManager/Framework/XACTSound.cs b/GeneralMods/SimpleSoundManager/Framework/XACTSound.cs index b3bfad14..a9e6379e 100644 --- a/GeneralMods/SimpleSoundManager/Framework/XACTSound.cs +++ b/GeneralMods/SimpleSoundManager/Framework/XACTSound.cs @@ -1,11 +1,5 @@ -using Microsoft.Xna.Framework.Audio; -using StardewModdingAPI; +using Microsoft.Xna.Framework.Audio; using StardewValley; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SimpleSoundManager.Framework { @@ -14,29 +8,25 @@ namespace SimpleSoundManager.Framework public WaveBank waveBank; public ISoundBank soundBank; public string soundName; - WaveBank vanillaWaveBank; - ISoundBank vanillaSoundBank; - Cue song; + readonly WaveBank vanillaWaveBank; + readonly ISoundBank vanillaSoundBank; + readonly Cue song; - /// - /// Make a new Sound Manager to play and manage sounds in a modded wave bank. - /// + /// Make a new Sound Manager to play and manage sounds in a modded wave bank. /// The reference to the wave bank in the mod's asset folder. /// The reference to the sound bank in the mod's asset folder. - public XACTSound(WaveBank newWaveBank, ISoundBank newSoundBank,string soundName) + public XACTSound(WaveBank newWaveBank, ISoundBank newSoundBank, string soundName) { this.waveBank = newWaveBank; this.soundBank = newSoundBank; - vanillaSoundBank = Game1.soundBank; - vanillaWaveBank = Game1.waveBank; + this.vanillaSoundBank = Game1.soundBank; + this.vanillaWaveBank = Game1.waveBank; this.soundName = soundName; - song = this.soundBank.GetCue(this.soundName); + this.song = this.soundBank.GetCue(this.soundName); } - /// - /// Play a sound from the mod's wave bank. - /// + /// Play a sound from the mod's wave bank. /// The name of the sound in the mod's wave bank. This will fail if the sound doesn't exists. This is also case sensitive. public void play(string soundName) { @@ -51,89 +41,65 @@ namespace SimpleSoundManager.Framework Game1.soundBank = this.vanillaSoundBank; } - /// - /// Pauses the first instance of this sound. - /// + /// Pauses the first instance of this sound. /// public void pause(string soundName) { - if (this.song == null) return; - this.song.Pause(); + this.song?.Pause(); } - /// - /// Resume the first instance of the sound that has this name. - /// + /// Resume the first instance of the sound that has this name. public void resume(string soundName) { - if (this.song == null) return; - this.song.Resume(); + this.song?.Resume(); } - /// - /// Stop the first instance of the sound that has this name. - /// + /// Stop the first instance of the sound that has this name. /// public void stop(string soundName) { - if (this.song == null) return; - this.song.Stop(AudioStopOptions.Immediate); + this.song?.Stop(AudioStopOptions.Immediate); } - /// - /// Resumes a paused song. - /// + /// Resumes a paused song. public void resume() { - this.resume(soundName); + this.resume(this.soundName); } - /// - /// Plays this song. - /// + /// Plays this song. public void play() { this.play(this.soundName); } - /// - /// Plays this song. - /// + /// Plays this song. public void play(float volume) { this.play(this.soundName); } - /// - /// Pauses this song. - /// + /// Pauses this song. public void pause() { this.pause(this.soundName); } - /// - /// Stops this somg. - /// + /// Stops this somg. public void stop() { this.stop(this.soundName); } - /// - /// Restarts this song. - /// + /// Restarts this song. public void restart() { this.stop(); this.play(); } - /// - /// Gets a clone of this song. - /// - /// + /// Gets a clone of this song. public Sound clone() { return new XACTSound(this.waveBank, this.soundBank, this.soundName); @@ -146,11 +112,7 @@ namespace SimpleSoundManager.Framework public bool isStopped() { - if (this.song == null) return true; - if (this.song.IsStopped) return true; - return false; + return this.song == null || this.song.IsStopped; } - - } } diff --git a/GeneralMods/SimpleSoundManager/Framework/XactMusicPair.cs b/GeneralMods/SimpleSoundManager/Framework/XactMusicPair.cs index fe3a77c2..84129dc1 100644 --- a/GeneralMods/SimpleSoundManager/Framework/XactMusicPair.cs +++ b/GeneralMods/SimpleSoundManager/Framework/XactMusicPair.cs @@ -1,12 +1,7 @@ -using Microsoft.Xna.Framework.Audio; +using System.IO; +using Microsoft.Xna.Framework.Audio; using StardewModdingAPI; using StardewValley; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SimpleSoundManager { @@ -15,20 +10,17 @@ namespace SimpleSoundManager public WaveBank waveBank; public ISoundBank soundBank; - /// - /// Create a xwb and xsb music pack pair. - /// + /// Create a xwb and xsb music pack pair. /// The mod helper from the mod that will handle loading in the file. /// A relative path to the .xwb file in the mod helper's mod directory. /// A relative path to the .xsb file in the mod helper's mod directory. - public XACTMusicPair(IModHelper helper,string wavBankPath, string soundBankPath) + public XACTMusicPair(IModHelper helper, string wavBankPath, string soundBankPath) { wavBankPath = Path.Combine(helper.DirectoryPath, wavBankPath); soundBankPath = Path.Combine(helper.DirectoryPath, soundBankPath); - - waveBank = new WaveBank(Game1.audioEngine, wavBankPath); - soundBank = new SoundBankWrapper(new SoundBank(Game1.audioEngine, soundBankPath)); + this.waveBank = new WaveBank(Game1.audioEngine, wavBankPath); + this.soundBank = new SoundBankWrapper(new SoundBank(Game1.audioEngine, soundBankPath)); } } } diff --git a/GeneralMods/SimpleSoundManager/SimpleSoundManager.csproj b/GeneralMods/SimpleSoundManager/SimpleSoundManager.csproj index b5eb855e..4e840a0a 100644 --- a/GeneralMods/SimpleSoundManager/SimpleSoundManager.csproj +++ b/GeneralMods/SimpleSoundManager/SimpleSoundManager.csproj @@ -1,5 +1,5 @@  - + Debug @@ -11,8 +11,6 @@ SimpleSoundManager v4.5 512 - - true @@ -67,6 +65,9 @@ prompt MinimumRecommendedRules.ruleset + + + @@ -82,19 +83,8 @@ - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/GeneralMods/SimpleSoundManager/SimpleSoundManagerMod.cs b/GeneralMods/SimpleSoundManager/SimpleSoundManagerMod.cs index b93be9b0..1a583b3b 100644 --- a/GeneralMods/SimpleSoundManager/SimpleSoundManagerMod.cs +++ b/GeneralMods/SimpleSoundManager/SimpleSoundManagerMod.cs @@ -1,4 +1,4 @@ -using StardewModdingAPI; +using StardewModdingAPI; namespace SimpleSoundManager { @@ -7,10 +7,12 @@ namespace SimpleSoundManager internal static IModHelper ModHelper; internal static IMonitor ModMonitor; + /// The mod entry point, called after the mod is first loaded. + /// Provides simplified APIs for writing mods. public override void Entry(IModHelper helper) { ModHelper = helper; - ModMonitor = Monitor; + ModMonitor = this.Monitor; } } } diff --git a/GeneralMods/SimpleSoundManager/packages.config b/GeneralMods/SimpleSoundManager/packages.config deleted file mode 100644 index af793ad3..00000000 --- a/GeneralMods/SimpleSoundManager/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/GeneralMods/StardewMods.sln b/GeneralMods/StardewMods.sln index 47b5fc95..5ccc93d6 100644 --- a/GeneralMods/StardewMods.sln +++ b/GeneralMods/StardewMods.sln @@ -33,9 +33,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TimeFreeze", "TimeFreeze\Ti EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "~metadata", "~metadata", "{90EB59CA-51F6-49CF-8DCE-A8BB62C58E17}" ProjectSection(SolutionItems) = preProject + ..\.editorconfig = ..\.editorconfig deploy.targets = deploy.targets GlobalAssemblyInfo.cs = GlobalAssemblyInfo.cs - AdditionalCropsFramework\ModularCropObject.cs = AdditionalCropsFramework\ModularCropObject.cs ..\README.md = ..\README.md EndProjectSection EndProject diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Config.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Config.cs index 1e1c81ba..96b93350 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Config.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Config.cs @@ -1,44 +1,24 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace StardewSymphonyRemastered { - /// - /// A class that handles all of the config files for this mod. - /// + /// A class that handles all of the config files for this mod. public class Config { - /// - /// Whether or not to display debug log information on the SMAPI console for this mod. - /// - public bool EnableDebugLog { get; set; }=false; + /// Whether or not to display debug log information on the SMAPI console for this mod. + public bool EnableDebugLog { get; set; } = false; - /// - /// The minimum delay between songs in terms of milliseconds. - /// - public int MinimumDelayBetweenSongsInMilliseconds { get; set; }=5000; + /// The minimum delay between songs in terms of milliseconds. + public int MinimumDelayBetweenSongsInMilliseconds { get; set; } = 5000; - /// - /// The maximum delay between songs in terms of milliseconds. - /// - public int MaximumDelayBetweenSongsInMilliseconds { get; set; }=60000; + /// The maximum delay between songs in terms of milliseconds. + public int MaximumDelayBetweenSongsInMilliseconds { get; set; } = 60000; - /// - /// The key binding to open up the menu music. - /// - public string KeyBinding { get; set; }="L"; - - /// - /// Used to write a .json file for every possible option for a music pack. Use at your own risk! - /// + /// The key binding to open up the menu music. + public string KeyBinding { get; set; } = "L"; + + /// Used to write a .json file for every possible option for a music pack. Use at your own risk! public bool writeAllConfigMusicOptions { get; set; } = false; - /// - /// Used to completely disable the Stardew Valley OST. - /// + /// Used to completely disable the Stardew Valley OST. public bool disableStardewMusic { get; set; } = false; } } diff --git a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs index e4118a5f..c618f97e 100644 --- a/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs +++ b/GeneralMods/StardewSymphonyRemastered/StardewSymphonyRemastered/Framework/Menus/MusicManagerMenu.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; @@ -11,18 +11,13 @@ using StardustCore.UIUtilities.MenuComponents; using StardustCore.UIUtilities.MenuComponents.Delegates; using StardustCore.UIUtilities.MenuComponents.Delegates.Functionality; using StardustCore.UIUtilities.SpriteFonts; -using StardustCore.UIUtilities.SpriteFonts.Components; namespace StardewSymphonyRemastered.Framework.Menus { - /// - /// Interface for the menu for selection music. - /// + /// Interface for the menu for selection music. public class MusicManagerMenu : IClickableMenuExtended { - /// - /// The different displays for this menu. - /// + /// The different displays for this menu. public enum DrawMode { AlbumSelection, @@ -47,7 +42,7 @@ namespace StardewSymphonyRemastered.Framework.Menus SeasonSelection, } - public List