diff --git a/Config.cs b/Config.cs new file mode 100644 index 0000000..df1c54e --- /dev/null +++ b/Config.cs @@ -0,0 +1,101 @@ +using I2.Loc.SimpleJSON; +using System; +using System.IO; +using System.Reflection; +using System.Web; +using UnityEngine; + +namespace MiuuDiamondTimeViewer +{ + 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 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; + } + } + } + + 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; + } + File.WriteAllText(GetConfigPath(), node.ToString()); + } + + public static string GetConfigPath() + { + return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), CONFIG_FILE_NAME); + } + } +} diff --git a/Patcher.cs b/Patcher.cs index 97a44c0..9e7d96a 100644 --- a/Patcher.cs +++ b/Patcher.cs @@ -13,6 +13,7 @@ namespace MiuuDiamondTimeViewer public static void OnStartup() { SceneManager.sceneLoaded += beginPatch; + Config.Init(); } private static void beginPatch(Scene scene, LoadSceneMode loadSceneMode) diff --git a/Patches/MedalsDisplayPatches.cs b/Patches/MedalsDisplayPatches.cs index ed9303c..febf341 100644 --- a/Patches/MedalsDisplayPatches.cs +++ b/Patches/MedalsDisplayPatches.cs @@ -11,6 +11,9 @@ namespace MiuuDiamondTimeViewer.Patches { static bool Prefix(MedalsDisplay __instance, float silver, float gold, List eggUnlock) { + if (!Config.Enabled) + return true; + // Get diamond time (since it is not passed in as a parameter) float diamond = LevelSelect.instance.level.DiamondTime; @@ -21,8 +24,25 @@ namespace MiuuDiamondTimeViewer.Patches if (hasEgg) eggText = (gotEgg ? " " : " "); + bool showDiamondTime = false; + switch (Config.Mode) + { + case DisplayMode.Always: + showDiamondTime = true; + break; + case DisplayMode.Diamond: + showDiamondTime = LevelSelect.instance.bestScore > 0f && LevelSelect.instance.bestScore <= diamond; + break; + case DisplayMode.Gold: + showDiamondTime = LevelSelect.instance.bestScore > 0f && LevelSelect.instance.bestScore <= gold; + break; + case DisplayMode.Never: + showDiamondTime = false; + break; + } + string diamondText = ""; - if (LevelSelect.instance.bestScore > 0f && LevelSelect.instance.bestScore <= diamond) + if (showDiamondTime) diamondText = " " + SegmentedTime.SPTimeText(diamond); __instance.MedalTimes.text = string.Concat(new string[]