Exemple #1
0
        public static string GetString(string section, string name)
        {
            MelonPreferences_Category category = MelonPreferences.GetCategory(section);

            if (category == null)
            {
                return(null);
            }
            MelonPreferences_Entry entry = category.GetEntry(name);

            if (entry == null)
            {
                return(null);
            }
            return(entry.GetValueAsString());
        }
Exemple #2
0
        public static void SetString(string section, string name, string value)
        {
            MelonPreferences_Category category = MelonPreferences.GetCategory(section);

            if (category == null)
            {
                return;
            }
            MelonPreferences_Entry entry = category.GetEntry(name);

            if (entry == null)
            {
                return;
            }
            switch (entry)
            {
            case MelonPreferences_Entry <string> stringEntry:
                stringEntry.Value = value;
                break;

            case MelonPreferences_Entry <int> intEntry:
                if (int.TryParse(value, out var parsedInt))
                {
                    intEntry.Value = parsedInt;
                }
                break;

            case MelonPreferences_Entry <float> floatEntry:
                if (float.TryParse(value, out var parsedFloat))
                {
                    floatEntry.Value = parsedFloat;
                }
                break;

            case MelonPreferences_Entry <bool> boolEntry:
                if (value.ToLower().StartsWith("true") || value.ToLower().StartsWith("false"))
                {
                    boolEntry.Value = value.ToLower().StartsWith("true");
                }
                break;
            }
        }