2016-12-09 08:34:28 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2017-07-28 08:28:39 +08:00
|
|
|
|
using StardewModdingAPI;
|
2017-07-30 01:47:19 +08:00
|
|
|
|
using StardewModdingAPI.Events;
|
|
|
|
|
using StardewValley;
|
2016-12-09 08:34:28 +08:00
|
|
|
|
|
2017-07-28 08:28:39 +08:00
|
|
|
|
namespace Omegasis.AutoSpeed
|
2016-12-09 08:34:28 +08:00
|
|
|
|
{
|
2017-07-30 01:47:19 +08:00
|
|
|
|
/// <summary>The mod entry point.</summary>
|
2016-12-09 08:34:28 +08:00
|
|
|
|
public class AutoSpeed : Mod
|
|
|
|
|
{
|
2017-07-30 01:47:19 +08:00
|
|
|
|
/*********
|
|
|
|
|
** 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>
|
2016-12-09 08:34:28 +08:00
|
|
|
|
public override void Entry(IModHelper helper)
|
|
|
|
|
{
|
2017-07-30 01:47:19 +08:00
|
|
|
|
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
|
|
|
|
|
|
|
|
|
|
string configLocation = Path.Combine(helper.DirectoryPath, "AutoSpeed_Data.txt");
|
2016-12-09 08:34:28 +08:00
|
|
|
|
if (!File.Exists(configLocation))
|
2017-07-30 01:47:19 +08:00
|
|
|
|
this.Speed = 1;
|
|
|
|
|
|
|
|
|
|
this.LoadConfig();
|
|
|
|
|
this.Monitor.Log("AutoSpeed Initialization Completed", LogLevel.Info);
|
2016-12-09 08:34:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 01:47:19 +08:00
|
|
|
|
|
|
|
|
|
/*********
|
|
|
|
|
** 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>
|
2016-12-09 08:34:28 +08:00
|
|
|
|
private void GameEvents_UpdateTick(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-07-30 01:47:19 +08:00
|
|
|
|
Game1.player.addedSpeed = Speed;
|
2016-12-09 08:34:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-30 01:47:19 +08:00
|
|
|
|
/// <summary>Load the configuration settings.</summary>
|
|
|
|
|
private void LoadConfig()
|
2016-12-09 08:34:28 +08:00
|
|
|
|
{
|
2017-07-30 01:47:19 +08:00
|
|
|
|
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.
|
2016-12-09 08:34:28 +08:00
|
|
|
|
{
|
2017-07-30 01:47:19 +08:00
|
|
|
|
this.Monitor.Log("The config file for AutoSpeed was not found, guess I'll create it...", LogLevel.Warn);
|
|
|
|
|
this.WriteConfig();
|
2016-12-09 08:34:28 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-30 01:47:19 +08:00
|
|
|
|
string[] text = File.ReadAllLines(path);
|
|
|
|
|
this.Speed = Convert.ToInt32(text[3]);
|
2016-12-09 08:34:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-30 01:47:19 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>Save the configuration settings.</summary>
|
|
|
|
|
void WriteConfig()
|
2016-12-09 08:34:28 +08:00
|
|
|
|
{
|
2017-07-30 01:47:19 +08:00
|
|
|
|
string path = Path.Combine(this.Helper.DirectoryPath, "AutoSpeed_data.txt");
|
|
|
|
|
string[] text = new string[20];
|
|
|
|
|
if (!File.Exists(path))
|
2016-12-09 08:34:28 +08:00
|
|
|
|
{
|
2017-07-30 02:05:24 +08:00
|
|
|
|
this.Monitor.Log("The data file for AutoSpeed was not found, guess I'll create it when you sleep.", LogLevel.Info);
|
2016-12-09 08:34:28 +08:00
|
|
|
|
|
2017-07-30 01:47:19 +08:00
|
|
|
|
text[0] = "Player: AutoSpeed Config:";
|
|
|
|
|
text[1] = "====================================================================================";
|
|
|
|
|
text[2] = "Player Added Speed:";
|
|
|
|
|
text[3] = Speed.ToString();
|
|
|
|
|
File.WriteAllLines(path, text);
|
2016-12-09 08:34:28 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-30 01:47:19 +08:00
|
|
|
|
text[0] = "Player: AutoSpeed Config:";
|
|
|
|
|
text[1] = "====================================================================================";
|
2016-12-09 08:34:28 +08:00
|
|
|
|
|
2017-07-30 01:47:19 +08:00
|
|
|
|
text[2] = "Player Added Speed:";
|
|
|
|
|
text[3] = Speed.ToString();
|
2016-12-09 08:34:28 +08:00
|
|
|
|
|
2017-07-30 01:47:19 +08:00
|
|
|
|
File.WriteAllLines(path, text);
|
2016-12-09 08:34:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-30 01:47:19 +08:00
|
|
|
|
}
|
|
|
|
|
}
|