private bool ValidateValues(WaterFoodHotKeyStates cfg, out KeyCode selectedKey) { selectedKey = KeyCode.None; foreach (KeyCode key in Enum.GetValues(typeof(KeyCode))) { Debug.Log($"[WaterFoodHotKey] Key: {key}"); if (String.Equals(key.ToString(), cfg.WaterHotKey, StringComparison.OrdinalIgnoreCase)) { Debug.Log($"[WaterFoodHotKey] WaterKey: {key}"); selectedKey = key; break; } if (String.Equals(key.ToString(), cfg.FoodHotKey, StringComparison.OrdinalIgnoreCase)) { selectedKey = key; Debug.Log($"[WaterFoodHotKey] FoodKey: {key}"); break; } } if (selectedKey != KeyCode.None) { return(true); } return(false); }
internal bool AttemptToCreate() { if (!File.Exists(lightStatePath)) { WaterFoodHotKeyStates myObject = new WaterFoodHotKeyStates(); myObject.UseThisConfig = false; myObject.WaterHotKey = "K"; myObject.FoodHotKey = "L"; myObject.TextValue = 0; myObject.ToggleFoodHotKey = true; myObject.ToggleWaterHotKey = true; myObject.WaterPercentage = 50.0f; myObject.FoodPercentage = 50.0f; // myObject.HoveBikeLightState = false; string json = JsonUtility.ToJson(myObject, true); File.WriteAllText(lightStatePath, json); // AttemptToLoad(); } return(true); }
internal bool AttemptToLoad() { try { if (File.Exists(lightStatePath)) { string settingsJson = File.ReadAllText(lightStatePath); WaterFoodHotKeyStates settingFromFile = JsonUtility.FromJson <WaterFoodHotKeyStates>(settingsJson); MainPatch.settings = settingFromFile; if (!this.ValidateValues(settingFromFile, out KeyCode validatedKeyCode)) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Info, $"validatedKeyCode: {validatedKeyCode}", null, true); return(false); } else { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Info, $"else validatedKeyCode: {validatedKeyCode}", null, true); } HarmonyPatches.FirstAidHotkey = validatedKeyCode; } } return(true); }