replace manual JSON parsing with SMAPI's config API
This commit is contained in:
parent
21d3a165a5
commit
9257605595
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Omegasis.BuildEndurance.Framework;
|
||||
using StardewModdingAPI;
|
||||
using StardewModdingAPI.Events;
|
||||
|
@ -67,35 +65,7 @@ namespace Omegasis.BuildEndurance
|
|||
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
|
||||
TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted;
|
||||
|
||||
string configPath = Path.Combine(helper.DirectoryPath, "BuildEnduranceConfig.json");
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
this.Monitor.Log("Initial configuration file setup.");
|
||||
this.Config = new ModConfig
|
||||
{
|
||||
CurrentLevel = 0,
|
||||
MaxLevel = 100,
|
||||
StaminaIncreasePerLevel = 1,
|
||||
CurrentExp = 0,
|
||||
ExpToNextLevel = 20,
|
||||
ExpCurve = 1.15,
|
||||
ExpForEating = 2,
|
||||
ExpForSleeping = 10,
|
||||
ExpForToolUse = 1,
|
||||
BaseStaminaBonus = 0,
|
||||
CurrentLevelStaminaBonus = 0,
|
||||
ExpForExhaustion = 25,
|
||||
ExpForCollapsing = 50
|
||||
};
|
||||
File.WriteAllBytes(configPath, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(this.Config)));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Config = JsonConvert.DeserializeObject<ModConfig>(Encoding.UTF8.GetString(File.ReadAllBytes(configPath)));
|
||||
this.Monitor.Log("Found BuildEndurance config file.");
|
||||
}
|
||||
|
||||
this.Monitor.Log("BuildEndurance Initialization Completed");
|
||||
this.Config = helper.ReadConfig<ModConfig>();
|
||||
}
|
||||
|
||||
/// <summary>The method invoked once per second during a game update.</summary>
|
||||
|
@ -234,7 +204,7 @@ namespace Omegasis.BuildEndurance
|
|||
string path = Path.Combine(Helper.DirectoryPath, "PlayerData", $"BuildEndurance_data_{Game1.player.name}.txt");
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
this.Monitor.Log("Clear Data Loaded could not find the correct file."));
|
||||
this.Monitor.Log("Clear Data Loaded could not find the correct file.");
|
||||
|
||||
this.ClearModEffects = false;
|
||||
this.OriginalStamina = 0;
|
||||
|
|
|
@ -30,10 +30,6 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace Omegasis.BuildEndurance.Framework
|
|||
internal class ModConfig
|
||||
{
|
||||
/// <summary>The XP points needed to reach the next endurance level.</summary>
|
||||
public double ExpToNextLevel { get; set; }
|
||||
public double ExpToNextLevel { get; set; } = 20;
|
||||
|
||||
/// <summary>The player's current endurance XP points.</summary>
|
||||
public double CurrentExp { get; set; }
|
||||
|
@ -19,27 +19,27 @@ namespace Omegasis.BuildEndurance.Framework
|
|||
public int CurrentLevelStaminaBonus { get; set; }
|
||||
|
||||
/// <summary>The multiplier for the experience points to need to reach an endurance level relative to the previous one.</summary>
|
||||
public double ExpCurve { get; set; }
|
||||
public double ExpCurve { get; set; } = 1.15;
|
||||
|
||||
/// <summary>The maximum endurance level the player can reach.</summary>
|
||||
public int MaxLevel { get; set; }
|
||||
public int MaxLevel { get; set; } = 100;
|
||||
|
||||
/// <summary>The amount of stamina the player should gain for each endurance level.</summary>
|
||||
public int StaminaIncreasePerLevel { get; set; }
|
||||
public int StaminaIncreasePerLevel { get; set; } = 1;
|
||||
|
||||
/// <summary>The experience points to gain for using a tool.</summary>
|
||||
public int ExpForToolUse { get; set; }
|
||||
public int ExpForToolUse { get; set; } = 1;
|
||||
|
||||
/// <summary>The experience points to gain for eating or drinking.</summary>
|
||||
public int ExpForEating { get; set; }
|
||||
public int ExpForEating { get; set; } = 2;
|
||||
|
||||
/// <summary>The experience points to gain for sleeping.</summary>
|
||||
public int ExpForSleeping { get; set; }
|
||||
public int ExpForSleeping { get; set; } = 10;
|
||||
|
||||
/// <summary>The experience points to gain for reaching a state of exhaustion for the day.</summary>
|
||||
public int ExpForExhaustion { get; set; }
|
||||
public int ExpForExhaustion { get; set; } = 25;
|
||||
|
||||
/// <summary>The experience points to gain for collapsing for the day.</summary>
|
||||
public int ExpForCollapsing { get; set; }
|
||||
public int ExpForCollapsing { get; set; } = 50;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
|
||||
<package id="Pathoschild.Stardew.ModBuildConfig" version="1.7.0" targetFramework="net45" />
|
||||
</packages>
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Omegasis.BuildHealth.Framework;
|
||||
using StardewModdingAPI;
|
||||
using StardewModdingAPI.Events;
|
||||
|
@ -61,36 +59,10 @@ namespace Omegasis.BuildHealth
|
|||
{
|
||||
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
|
||||
GameEvents.OneSecondTick += this.GameEvents_OneSecondTick;
|
||||
|
||||
TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted;
|
||||
SaveEvents.AfterLoad += this.SaveEvents_AfterLoaded;
|
||||
|
||||
var configPath = Path.Combine(helper.DirectoryPath, "BuildHealthConfig.json");
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
this.Config = new ModConfig
|
||||
{
|
||||
CurrentLevel = 0,
|
||||
MaxLevel = 100,
|
||||
HealthIncreasePerLevel = 1,
|
||||
CurrentExp = 0,
|
||||
ExpToNextLevel = 20,
|
||||
ExpCurve = 1.15,
|
||||
ExpForEating = 2,
|
||||
ExpForSleeping = 10,
|
||||
ExpForToolUse = 1,
|
||||
BaseHealthBonus = 0,
|
||||
CurrentLevelHealthBonus = 0
|
||||
};
|
||||
File.WriteAllBytes(configPath, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(this.Config)));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Config = JsonConvert.DeserializeObject<ModConfig>(Encoding.UTF8.GetString(File.ReadAllBytes(configPath)));
|
||||
this.Monitor.Log("Found BuildHealth config file.");
|
||||
}
|
||||
|
||||
this.Monitor.Log("BuildHealth Initialization Completed");
|
||||
this.Config = helper.ReadConfig<ModConfig>();
|
||||
}
|
||||
|
||||
/// <summary>The method invoked once per second during a game update.</summary>
|
||||
|
|
|
@ -30,10 +30,6 @@
|
|||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
internal class ModConfig
|
||||
{
|
||||
/// <summary>The XP points needed to reach the next level.</summary>
|
||||
public double ExpToNextLevel { get; set; }
|
||||
public double ExpToNextLevel { get; set; } = 20;
|
||||
|
||||
/// <summary>The player's current XP points.</summary>
|
||||
public double CurrentExp { get; set; }
|
||||
|
@ -19,22 +19,22 @@
|
|||
public int CurrentLevelHealthBonus { get; set; }
|
||||
|
||||
/// <summary>The multiplier for the experience points to need to reach an endurance level relative to the previous one.</summary>
|
||||
public double ExpCurve { get; set; }
|
||||
public double ExpCurve { get; set; } = 1.15;
|
||||
|
||||
/// <summary>The maximum endurance level the player can reach.</summary>
|
||||
public int MaxLevel { get; set; }
|
||||
public int MaxLevel { get; set; } = 100;
|
||||
|
||||
/// <summary>The amount of stamina the player should gain for each endurance level.</summary>
|
||||
public int HealthIncreasePerLevel { get; set; }
|
||||
public int HealthIncreasePerLevel { get; set; } = 1;
|
||||
|
||||
/// <summary>The experience points to gain for using a tool.</summary>
|
||||
public int ExpForToolUse { get; set; }
|
||||
public int ExpForToolUse { get; set; } = 1;
|
||||
|
||||
/// <summary>The experience points to gain for eating or drinking.</summary>
|
||||
public int ExpForEating { get; set; }
|
||||
public int ExpForEating { get; set; } = 2;
|
||||
|
||||
/// <summary>The experience points to gain for sleeping.</summary>
|
||||
public int ExpForSleeping { get; set; }
|
||||
public int ExpForSleeping { get; set; } = 10;
|
||||
|
||||
/// <summary>The experience points to gain for collapsing for the day.</summary>
|
||||
public int ExpForCollapsing { get; set; }
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
|
||||
<package id="Pathoschild.Stardew.ModBuildConfig" version="1.7.0" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Reference in New Issue