Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
updated logic handling old data
Browse files Browse the repository at this point in the history
  • Loading branch information
johnathan-clause committed Sep 25, 2020
1 parent c0c8bee commit 681b85c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions CustomGameStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public class CustomGameStats : BaseUnityPlugin
public static ModConfig AIConfig { get; private set; }
public static string Dir { get; private set; } = $@"Mods\ModConfigs\{ Settings.ModName }\";

//mod settings
public bool FirstRun = true;

internal void Awake()
{
Instance = this;
Expand Down Expand Up @@ -71,27 +68,32 @@ public void ResetConfig(string flag)

private void Init()
{
ModSettings _ms = new ModSettings();
string _file = $@"Mods\{ Settings.ModName }.json";
string _path = $@"Mods\ModConfigs\{ Settings.ModName}";

if (!Directory.Exists(Dir))
{
Directory.CreateDirectory(Dir);
}
else

if (!File.Exists(_file))
{
if (!File.Exists(_file))
{
File.WriteAllText(_file, JsonUtility.ToJson(new CustomGameStats()));
}
_ms.FirstRun = true;
File.WriteAllText(_file, JsonUtility.ToJson(_ms));
}

CustomGameStats _settings = JsonUtility.FromJson<CustomGameStats>(_file);
ModSettings _settings = JsonUtility.FromJson<ModSettings>(File.ReadAllText(_file));
if (!_settings.FirstRun) { return; }

if (File.Exists($"{ _path }{ Settings.PlayerStatsTitle }.xml")) { File.Delete($"{ _path }{ Settings.PlayerStatsTitle }.xml"); }
if (File.Exists($"{ _path }{ Settings.AIStatsTitle }.xml")) { File.Delete($"{ _path }{ Settings.AIStatsTitle }.xml"); }

Directory.Delete(Dir, true);
Directory.CreateDirectory(Dir);

_ms.FirstRun = false;
File.WriteAllText(_file, JsonUtility.ToJson(_ms));
}

private ModConfig SetupConfig(string flag)
Expand Down
1 change: 1 addition & 0 deletions CustomGameStats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="RPCManager.cs" />
<Compile Include="StatManager.cs" />
<Compile Include="util\AT.cs" />
<Compile Include="util\ModSettings.cs" />
<Compile Include="util\Settings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="util\VitalsInfo.cs" />
Expand Down

0 comments on commit 681b85c

Please sign in to comment.