using System; using System.IO; using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; namespace Omegasis.AutoSpeed { /// The mod entry point. public class AutoSpeed : Mod { /********* ** Properties *********/ /// The speed multiplier. private int Speed = 5; /********* ** 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; string configLocation = Path.Combine(helper.DirectoryPath, "AutoSpeed_Data.txt"); if (!File.Exists(configLocation)) this.Speed = 1; this.LoadConfig(); this.Monitor.Log("AutoSpeed Initialization Completed", LogLevel.Info); } /********* ** 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) { Game1.player.addedSpeed = Speed; } /// Load the configuration settings. private void LoadConfig() { string path = Path.Combine(this.Helper.DirectoryPath, "AutoSpeed_data.txt"); if (!File.Exists(path)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out. { this.Monitor.Log("The config file for AutoSpeed was not found, guess I'll create it...", LogLevel.Warn); this.WriteConfig(); } else { string[] text = File.ReadAllLines(path); this.Speed = Convert.ToInt32(text[3]); } } /// Save the configuration settings. void WriteConfig() { string path = Path.Combine(this.Helper.DirectoryPath, "AutoSpeed_data.txt"); string[] text = new string[20]; if (!File.Exists(path)) { this.Monitor.Log("The data file for AutoSpeed was not found, guess I'll create it when you sleep.", LogLevel.Info); text[0] = "Player: AutoSpeed Config:"; text[1] = "===================================================================================="; text[2] = "Player Added Speed:"; text[3] = Speed.ToString(); File.WriteAllLines(path, text); } else { text[0] = "Player: AutoSpeed Config:"; text[1] = "===================================================================================="; text[2] = "Player Added Speed:"; text[3] = Speed.ToString(); File.WriteAllLines(path, text); } } } }