/// <param name="id"><see cref="ID"/></param> /// <param name="name"><see cref="Name"/></param> /// <param name="saveValue"><see cref="SaveValue"/></param> /// <param name="type"><see cref="Type"/></param> /// <param name="value">The default value</param> protected CustomOption(string id, string name, bool saveValue, CustomOptionType type, object value) { PluginID = GetCallingPluginId(); ConfigID = id; //string Id = ID = $"{nameof(CustomOption)}_{PluginID}_{id}"; string Id = ID = $"{PluginID}_{id}"; Name = name; SaveValue = saveValue; Type = type; DefaultValue = OldValue = Value = value; int i = 0; while (Options.Any(option => option.ID.Equals(ID, StringComparison.Ordinal))) { ID = $"{Id}_{i++}"; ConfigID = $"{id}_{i++}"; } Options.Add(this); }
protected internal CustomOption(int id, string name, CustomOptionType type, object defaultValue, Func <object, string> format = null) { ID = id; Name = name; Type = type; DefaultValue = Value = defaultValue; Format = format ?? (obj => $"{obj}"); if (Type == CustomOptionType.Button) { return; } AllOptions.Add(this); Set(Value); }
/// <param name="id">The ID of the option, used to maintain the last value when <paramref name="saveValue"/> is true and to transmit the value between players</param> /// <param name="name">The name/title of the option</param> /// <param name="saveValue">Saves the last value of the option to apply again when the game is reopened (only applies for the lobby host)</param> /// <param name="type">The option type. See <see cref="CustomOptionType"/>.</param> /// <param name="value">The initial/default value</param> protected CustomOption(string id, string name, bool saveValue, CustomOptionType type, object value) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Option id cannot be null or empty."); } if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name), "Option name cannot be null or empty."); } if (value == null) { throw new ArgumentNullException(nameof(value), "Value cannot be null"); } PluginID = PluginHelpers.GetCallingPluginId(); ConfigID = id; //string Id = ID = $"{nameof(CustomOption)}_{PluginID}_{id}"; string Id = ID = $"{PluginID}_{id}"; Name = name; SaveValue = saveValue; Type = type; DefaultValue = OldValue = Value = value; int i = 0; while (Options.Any(option => option.ID.Equals(ID, StringComparison.Ordinal))) { ID = $"{Id}_{++i}"; ConfigID = $"{id}_{i}"; } SHA1 = SHA1Helper.Create(ID); Options.Add(this); }