| | 1 | | using System; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.SettingsCommon |
| | 6 | | { |
| | 7 | | public class PlayerPrefsSettingsByKey : IPlayerPrefsSettingsByKey |
| | 8 | | { |
| | 9 | | private readonly string prefixPrefsKey; |
| | 10 | |
|
| 0 | 11 | | public PlayerPrefsSettingsByKey(string prefixPrefsKey) |
| | 12 | | { |
| 0 | 13 | | this.prefixPrefsKey = prefixPrefsKey; |
| 0 | 14 | | } |
| | 15 | |
|
| | 16 | | public T GetEnum<T>(string fieldName, T defaultValue) where T : struct |
| | 17 | | { |
| 3840 | 18 | | if (!Enum.TryParse<T>(PlayerPrefs.GetString(GetFieldKey(fieldName), ""), out var result)) |
| 2046 | 19 | | return defaultValue; |
| 1794 | 20 | | return result; |
| | 21 | | } |
| | 22 | |
|
| | 23 | | public bool GetBool(string fieldName, bool defaultValue) |
| | 24 | | { |
| 5760 | 25 | | return PlayerPrefsUtils.GetBool(GetFieldKey(fieldName), defaultValue); |
| | 26 | | } |
| | 27 | |
|
| | 28 | | public float GetFloat(string fieldName, float defaultValue) |
| | 29 | | { |
| 11520 | 30 | | return PlayerPrefs.GetFloat(GetFieldKey(fieldName), defaultValue); |
| | 31 | | } |
| | 32 | |
|
| | 33 | | public int GetInt(string fieldName, int defaultValue) |
| | 34 | | { |
| 640 | 35 | | return PlayerPrefs.GetInt(GetFieldKey(fieldName), defaultValue); |
| | 36 | | } |
| | 37 | |
|
| | 38 | | public string GetString(string fieldName, string defaultValue) |
| | 39 | | { |
| 640 | 40 | | return PlayerPrefs.GetString(GetFieldKey(fieldName), defaultValue); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public void SetBool(string fieldName, bool value) |
| | 44 | | { |
| 9 | 45 | | PlayerPrefsUtils.SetBool(GetFieldKey(fieldName), value); |
| 9 | 46 | | } |
| | 47 | |
|
| | 48 | | public void SetFloat(string fieldName, float value) |
| | 49 | | { |
| 18 | 50 | | PlayerPrefs.SetFloat(GetFieldKey(fieldName), value); |
| 18 | 51 | | } |
| | 52 | |
|
| | 53 | | public void SetEnum<T>(string fieldName, T value) where T : struct |
| | 54 | | { |
| 6 | 55 | | PlayerPrefs.SetString(GetFieldKey(fieldName), value.ToString()); |
| 6 | 56 | | } |
| | 57 | |
|
| | 58 | | public void SetInt(string fieldName, int value) |
| | 59 | | { |
| 1 | 60 | | PlayerPrefs.SetInt(GetFieldKey(fieldName), value); |
| 1 | 61 | | } |
| | 62 | |
|
| | 63 | | public void SetString(string fieldName, string value) |
| | 64 | | { |
| 1 | 65 | | PlayerPrefs.SetString(GetFieldKey(fieldName), value); |
| 1 | 66 | | } |
| | 67 | |
|
| | 68 | | private string GetFieldKey(string fieldName) |
| | 69 | | { |
| 22435 | 70 | | return $"{prefixPrefsKey}.{fieldName}"; |
| | 71 | | } |
| | 72 | | } |
| | 73 | | } |