105 lines
2 KiB
C#
105 lines
2 KiB
C#
using I2.Loc.SimpleJSON;
|
|
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using UnityEngine;
|
|
|
|
namespace DiamondTimeViewer
|
|
{
|
|
public enum DisplayMode
|
|
{
|
|
Never,
|
|
Diamond,
|
|
Gold,
|
|
Always,
|
|
}
|
|
|
|
public class Config
|
|
{
|
|
private const string CONFIG_FILE_NAME = "config.json";
|
|
|
|
public static bool Enabled = true;
|
|
public static DisplayMode Mode = DisplayMode.Diamond;
|
|
public static bool HideSilver = false;
|
|
|
|
public static void Init()
|
|
{
|
|
if (File.Exists(GetConfigPath()))
|
|
ReadConfig();
|
|
else
|
|
SaveConfig();
|
|
}
|
|
|
|
public static void ReadConfig()
|
|
{
|
|
if (!File.Exists(GetConfigPath()))
|
|
return;
|
|
|
|
JSONNode data;
|
|
try
|
|
{
|
|
data = JSON.Parse(File.ReadAllText(GetConfigPath()));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError("Exception reading DiamondViewer config: " + e.Message);
|
|
return;
|
|
}
|
|
|
|
if (data["enabled"] != null)
|
|
Enabled = data["enabled"].AsBool;
|
|
|
|
if (data["mode"] != null)
|
|
{
|
|
string mode = data["mode"].Value.ToLower();
|
|
|
|
switch(mode)
|
|
{
|
|
case "never":
|
|
Mode = DisplayMode.Never;
|
|
break;
|
|
case "diamond":
|
|
Mode = DisplayMode.Diamond;
|
|
break;
|
|
case "gold":
|
|
Mode = DisplayMode.Gold;
|
|
break;
|
|
case "always":
|
|
Mode = DisplayMode.Always;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (data["hideSilver"] != null)
|
|
HideSilver = data["hideSilver"].AsBool;
|
|
}
|
|
|
|
public static void SaveConfig()
|
|
{
|
|
JSONNode node = new JSONClass();
|
|
node.Add("enabled", Enabled ? "true" : "false");
|
|
switch(Mode)
|
|
{
|
|
case DisplayMode.Never:
|
|
node.Add("mode", "never");
|
|
break;
|
|
case DisplayMode.Diamond:
|
|
node.Add("mode", "diamond");
|
|
break;
|
|
case DisplayMode.Gold:
|
|
node.Add("mode", "gold");
|
|
break;
|
|
case DisplayMode.Always:
|
|
node.Add("mode", "always");
|
|
break;
|
|
}
|
|
node.Add("hideSilver", HideSilver ? "true" : "false");
|
|
File.WriteAllText(GetConfigPath(), node.ToString());
|
|
}
|
|
|
|
public static string GetConfigPath()
|
|
{
|
|
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), CONFIG_FILE_NAME);
|
|
}
|
|
}
|
|
}
|