remove support for legacy Build Endurance/Health data files

This commit is contained in:
Jesse Plamondon-Willard 2018-12-30 19:45:04 -05:00
parent 691515072b
commit de84552019
No known key found for this signature in database
GPG Key ID: 7D7C8097B62033CE
2 changed files with 1 additions and 78 deletions

View File

@ -1,6 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using Omegasis.BuildEndurance.Framework; using Omegasis.BuildEndurance.Framework;
using StardewModdingAPI; using StardewModdingAPI;
using StardewModdingAPI.Events; using StardewModdingAPI.Events;
@ -17,9 +16,6 @@ namespace Omegasis.BuildEndurance
/// <summary>The relative path for the current player's data file.</summary> /// <summary>The relative path for the current player's data file.</summary>
private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json");
/// <summary>The absolute path for the current player's legacy data file.</summary>
private string LegacyDataFilePath => Path.Combine(this.Helper.DirectoryPath, "PlayerData", $"BuildEndurance_data_{Game1.player.Name}.txt");
/// <summary>The mod settings.</summary> /// <summary>The mod settings.</summary>
private ModConfig Config; private ModConfig Config;
@ -38,10 +34,10 @@ namespace Omegasis.BuildEndurance
/// <summary>Whether the player was eating last time we checked.</summary> /// <summary>Whether the player was eating last time we checked.</summary>
private bool WasEating; private bool WasEating;
public IModHelper ModHelper; public IModHelper ModHelper;
public IMonitor ModMonitor; public IMonitor ModMonitor;
/********* /*********
** Public methods ** Public methods
*********/ *********/
@ -128,7 +124,6 @@ namespace Omegasis.BuildEndurance
this.WasEating = false; this.WasEating = false;
// load player data // load player data
this.MigrateLegacyData();
this.PlayerData = this.Helper.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData(); this.PlayerData = this.Helper.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData();
if (this.PlayerData.OriginalMaxStamina == 0) if (this.PlayerData.OriginalMaxStamina == 0)
this.PlayerData.OriginalMaxStamina = Game1.player.MaxStamina; this.PlayerData.OriginalMaxStamina = Game1.player.MaxStamina;
@ -187,40 +182,6 @@ namespace Omegasis.BuildEndurance
this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData); this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData);
} }
/// <summary>Migrate the legacy settings for the current player.</summary>
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);
}
}
/// <summary>Try and emulate the old Game1.shouldFarmerPassout logic.</summary> /// <summary>Try and emulate the old Game1.shouldFarmerPassout logic.</summary>
public bool shouldFarmerPassout() public bool shouldFarmerPassout()
{ {

View File

@ -1,6 +1,5 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using Omegasis.BuildHealth.Framework; using Omegasis.BuildHealth.Framework;
using StardewModdingAPI; using StardewModdingAPI;
using StardewModdingAPI.Events; using StardewModdingAPI.Events;
@ -17,9 +16,6 @@ namespace Omegasis.BuildHealth
/// <summary>The relative path for the current player's data file.</summary> /// <summary>The relative path for the current player's data file.</summary>
private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json");
/// <summary>The absolute path for the current player's legacy data file.</summary>
private string LegacyDataFilePath => Path.Combine(this.Helper.DirectoryPath, "PlayerData", $"BuildHealth_data_{Game1.player.Name}.txt");
/// <summary>The mod settings and player data.</summary> /// <summary>The mod settings and player data.</summary>
private ModConfig Config; private ModConfig Config;
@ -122,7 +118,6 @@ namespace Omegasis.BuildHealth
this.WasCollapsed = false; this.WasCollapsed = false;
// load player data // load player data
this.MigrateLegacyData();
this.PlayerData = this.Helper.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData(); this.PlayerData = this.Helper.ReadJsonFile<PlayerData>(this.DataFilePath) ?? new PlayerData();
if (this.PlayerData.OriginalMaxHealth == 0) if (this.PlayerData.OriginalMaxHealth == 0)
this.PlayerData.OriginalMaxHealth = Game1.player.maxHealth; this.PlayerData.OriginalMaxHealth = Game1.player.maxHealth;
@ -177,39 +172,6 @@ namespace Omegasis.BuildHealth
this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData); this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData);
} }
/// <summary>Migrate the legacy settings for the current player.</summary>
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() public bool shouldFarmerPassout()
{ {
if (Game1.player.stamina <= 0 || Game1.player.health <= 0 || Game1.timeOfDay >= 2600) return true; if (Game1.player.stamina <= 0 || Game1.player.health <= 0 || Game1.timeOfDay >= 2600) return true;