using System; using System.IO; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; using StardewValley.Locations; namespace Omegasis.TimeFreeze { /// The mod entry point. public class TimeFreeze : Mod { /********* ** Properties *********/ /// Whether time should be unfrozen while the player is swimming. private bool PassTimeWhileSwimming = true; /// Whether time should be unfrozen while the player is swimming in the vanilla bathhouse. private bool PassTimeWhileSwimmingInBathhouse = true; /********* ** Public methods *********/ /// The mod entry point, called after the mod is first loaded. /// Provides simplified APIs for writing mods. public override void Entry(IModHelper helper) { GameEvents.UpdateTick += this.GameEvents_UpdateTick; this.LoadConfig(); } /********* ** Private methods *********/ /// 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) { if (!Context.IsWorldReady) return; if (this.ShouldFreezeTime(Game1.player, Game1.player.currentLocation)) Game1.gameTimeInterval = 0; } /// Get whether time should be frozen for the player at the given location. /// The player to check. /// The location to check. private bool ShouldFreezeTime(StardewValley.Farmer player, GameLocation location) { if (location.name == "Mine" || location.name == "SkullCave" || location.name == "UndergroundMine" || location.isOutdoors) return false; if (player.swimming) { if (this.PassTimeWhileSwimmingInBathhouse && location is BathHousePool) return false; if (this.PassTimeWhileSwimming) return false; } return true; } /// Save the configuration settings. private void WriteConfig() { string path = Path.Combine(Helper.DirectoryPath, "ModConfig.txt"); string[] text = new string[6]; text[0] = "Player: TimeFreeze Config"; text[1] = "===================================================================================="; text[2] = "Whether to unfreeze time while swimming in the vanilla bathhouse."; text[3] = this.PassTimeWhileSwimmingInBathhouse.ToString(); text[4] = "Whether to unfreeze time while swimming anywhere."; text[5] = this.PassTimeWhileSwimming.ToString(); File.WriteAllLines(path, text); } /// Load the configuration settings. private void LoadConfig() { string path = Path.Combine(Helper.DirectoryPath, "ModConfig.txt"); if (!File.Exists(path)) { this.PassTimeWhileSwimming = true; this.PassTimeWhileSwimmingInBathhouse = true; this.WriteConfig(); } else { string[] text = File.ReadAllLines(path); this.PassTimeWhileSwimming = Convert.ToBoolean(text[3]); this.PassTimeWhileSwimmingInBathhouse = Convert.ToBoolean(text[5]); } } } }