Stardew_Valley_Mods/GeneralMods/AutoSpeed/AutoSpeed.cs

92 lines
3.2 KiB
C#
Raw Normal View History

using System;
using System.IO;
2017-07-28 08:28:39 +08:00
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
2017-07-28 08:28:39 +08:00
namespace Omegasis.AutoSpeed
{
/// <summary>The mod entry point.</summary>
public class AutoSpeed : Mod
{
/*********
** Properties
*********/
/// <summary>The speed multiplier.</summary>
private int Speed = 5;
/*********
** Public methods
*********/
/// <summary>The mod entry point, called after the mod is first loaded.</summary>
/// <param name="helper">Provides simplified APIs for writing mods.</param>
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
*********/
/// <summary>The method invoked when the game updates (roughly 60 times per second).</summary>
/// <param name="sender">The event sender.</param>
/// <param name="e">The event data.</param>
private void GameEvents_UpdateTick(object sender, EventArgs e)
{
Game1.player.addedSpeed = Speed;
}
/// <summary>Load the configuration settings.</summary>
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]);
}
}
/// <summary>Save the configuration settings.</summary>
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);
}
}
}
}