Exemplo n.º 1
0
        public MelonPreferences_Entry <T> CreateEntry <T>(string identifier, T default_value, string display_name = null,
                                                          string description = null, bool is_hidden = false, bool dont_save_default = false, Preferences.ValueValidator validator = null)
        {
            if (string.IsNullOrEmpty(identifier))
            {
                throw new Exception("identifier is null or empty when calling CreateEntry");
            }

            if (display_name == null)
            {
                display_name = identifier;
            }

            var entry = GetEntry <T>(identifier);

            if (entry != null)
            {
                throw new Exception($"Calling CreateEntry for { display_name } when it Already Exists");
            }

            if (validator != null && !validator.IsValid(default_value))
            {
                throw new ArgumentException($"Default value '{default_value}' is invalid according to the provided ValueValidator!");
            }

            entry = new MelonPreferences_Entry <T>
            {
                Identifier      = identifier,
                DisplayName     = display_name,
                Description     = description,
                IsHidden        = is_hidden,
                DontSaveDefault = dont_save_default,
                Category        = this,
                DefaultValue    = default_value,
                Value           = default_value,
                Validator       = validator,
            };

            Preferences.IO.File currentFile = File;
            if (currentFile == null)
            {
                currentFile = MelonPreferences.DefaultFile;
            }
            currentFile.SetupEntryFromRawValue(entry);

            Entries.Add(entry);

            return(entry);
        }
 public MelonPreferences_Entry <T> CreateEntry <T>(string identifier, T default_value, string display_name,
                                                   string description, bool is_hidden, bool dont_save_default, Preferences.ValueValidator validator)
 => CreateEntry(identifier, default_value, display_name, description, is_hidden, dont_save_default, validator, null);