public static bool IsActive(string key) { try { var settingsPath = Path.Combine(Path.Combine(Application.persistentDataPath, "Modsettings"), "ColorblindMode.json"); ColorblindModeSettings settings = new ColorblindModeSettings(); if (File.Exists(settingsPath)) { settings = JsonConvert.DeserializeObject <ColorblindModeSettings>(File.ReadAllText(settingsPath)); } bool?isEnabled = null; if (!string.IsNullOrEmpty(key) && !settings.EnabledModules.TryGetValue(key, out isEnabled)) { settings.EnabledModules[key] = null; } File.WriteAllText(settingsPath, JsonConvert.SerializeObject(settings, Formatting.Indented)); return(isEnabled ?? settings.Enabled); } catch (Exception e) { Debug.LogFormat(@"[Colorblind Mode] Error in ""{0}"": {1} ({2})\n{3}", key ?? "<null>", e.Message, e.GetType().FullName, e.StackTrace); return(false); } }
static void ReadSettings() { try { if (!File.Exists(_settingsPath)) { WriteSettings(); } _settings = JsonConvert.DeserializeObject <ColorblindModeSettings>(File.ReadAllText(_settingsPath)); } catch { _settings = new ColorblindModeSettings(); } }
static void WriteSettings(ColorblindModeSettings settings) { File.WriteAllText(settingsPath, JsonConvert.SerializeObject(settings, Formatting.Indented)); }