From 22487264500cb29a19d584dac97c0c790b002617 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Mon, 17 Mar 2025 09:12:26 -0400 Subject: [PATCH] IncludeInPreset property --- MiraAPI/GameOptions/IModdedOption.cs | 5 ++ .../OptionTypes/ModdedEnumOption.cs | 18 ++--- .../OptionTypes/ModdedNumberOption.cs | 4 +- .../GameOptions/OptionTypes/ModdedOption.cs | 65 ++++++------------- .../OptionTypes/ModdedToggleOption.cs | 3 +- 5 files changed, 39 insertions(+), 56 deletions(-) diff --git a/MiraAPI/GameOptions/IModdedOption.cs b/MiraAPI/GameOptions/IModdedOption.cs index 86baf9d..e002912 100644 --- a/MiraAPI/GameOptions/IModdedOption.cs +++ b/MiraAPI/GameOptions/IModdedOption.cs @@ -46,6 +46,11 @@ public interface IModdedOption /// Func Visible { get; set; } + /// + /// Gets or sets a value indicating whether the option should be included with presets. + /// + bool IncludeInPreset { get; set; } + /// /// Gets or sets the ConfigDefinition for the option, used for BepInEx configuration. /// diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs index ff422f5..18f13c6 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedEnumOption.cs @@ -18,7 +18,7 @@ public class ModdedEnumOption : ModdedOption /// /// Gets the string values of the enum. /// - public string[]? Values { get; } + public string[] Values { get; } /// /// Initializes a new instance of the class. @@ -27,7 +27,8 @@ public class ModdedEnumOption : ModdedOption /// The default value as an int. /// The Enum type. /// An option list of string values to use in place of the enum name. - public ModdedEnumOption(string title, int defaultValue, Type enumType, string[]? values = null) : base(title, defaultValue) + /// Whether to include this option in the preset or not. + public ModdedEnumOption(string title, int defaultValue, Type enumType, string[]? values = null, bool includeInPreset=true) : base(title, defaultValue, includeInPreset) { Values = values ?? Enum.GetNames(enumType); Data = ScriptableObject.CreateInstance(); @@ -37,7 +38,7 @@ public class ModdedEnumOption : ModdedOption data.Type = global::OptionTypes.String; data.Values = values is null ? Enum.GetNames(enumType).Select(CustomStringName.CreateAndRegister).ToArray() - : values.Select(CustomStringName.CreateAndRegister).ToArray(); + : [.. values.Select(CustomStringName.CreateAndRegister)]; data.Index = Value; } @@ -87,7 +88,7 @@ public class ModdedEnumOption : ModdedOption /// protected override void OnValueChanged(int newValue) { - HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data?.GetValueString(newValue), false); + HudManager.Instance.Notifier.AddSettingsChangeMessage(StringName, Data.GetValueString(newValue), false); if (!OptionBehaviour) { return; @@ -109,7 +110,7 @@ public class ModdedEnumOption : ModdedOption where T : Enum /// /// Gets the string values of the enum. /// - public string[]? Values { get; } + public string[] Values { get; } /// /// Initializes a new instance of the class. @@ -117,7 +118,8 @@ public class ModdedEnumOption : ModdedOption where T : Enum /// The title of the option. /// The default value as an int. /// An option list of string values to use in place of the enum name. - public ModdedEnumOption(string title, T defaultValue, string[]? values = null) : base(title, defaultValue) + /// Whether to include this option in the preset or not. + public ModdedEnumOption(string title, T defaultValue, string[]? values = null, bool includeInPreset=true) : base(title, defaultValue, includeInPreset) { Values = values ?? Enum.GetNames(typeof(T)); Data = ScriptableObject.CreateInstance(); @@ -127,9 +129,9 @@ public class ModdedEnumOption : ModdedOption where T : Enum data.Type = global::OptionTypes.String; data.Values = values is null ? Enum.GetNames(typeof(T)).Select(CustomStringName.CreateAndRegister).ToArray() - : values.Select(CustomStringName.CreateAndRegister).ToArray(); + : [.. values.Select(CustomStringName.CreateAndRegister)]; - data.Index = Convert.ToInt32(Value); + data.Index = Convert.ToInt32(Value, NumberFormatInfo.InvariantInfo); } /// diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index 4d38c04..a01ffe8 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -48,6 +48,7 @@ public class ModdedNumberOption : ModdedOption /// The suffix type. /// Optional format string for the option screen. /// Whether zero is infinity or not. + /// Whether to include this option in the preset or not. public ModdedNumberOption( string title, float defaultValue, @@ -56,7 +57,8 @@ public class ModdedNumberOption : ModdedOption float increment, MiraNumberSuffixes suffixType, string? formatString = null, - bool zeroInfinity = false) : base(title, defaultValue) + bool zeroInfinity = false, + bool includeInPreset = true) : base(title, defaultValue, includeInPreset) { Min = min; Max = max; diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs index 670fb3c..2b61e2b 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOption.cs @@ -16,29 +16,19 @@ public abstract class ModdedOption : IModdedOption { private IMiraPlugin? _parentMod; - /// - /// Gets the unique identifier of the option. - /// + /// public uint Id { get; } - /// - /// Gets the title of the option. - /// + /// public string Title { get; } - /// - /// Gets the StringName object of the option. - /// + /// public StringNames StringName { get; } - /// - /// Gets the BaseGameSetting data of the option. - /// - public BaseGameSetting Data { get; protected init; } + /// + public BaseGameSetting Data { get; protected init; } = null!; - /// - /// Gets or sets the parent mod of the option. - /// + /// public IMiraPlugin? ParentMod { get => _parentMod; @@ -66,19 +56,16 @@ public abstract class ModdedOption : IModdedOption /// public Action? ChangedEvent { get; set; } - /// - /// Gets or sets the visibility of the option. - /// + /// public Func Visible { get; set; } - /// - /// Gets or sets the option behaviour of the option. - /// + /// + public bool IncludeInPreset { get; set; } + + /// public OptionBehaviour? OptionBehaviour { get; protected set; } - /// - /// Gets or sets the config definition of the option. - /// + /// public ConfigDefinition? ConfigDefinition { get => _configDefinition; @@ -96,7 +83,8 @@ public abstract class ModdedOption : IModdedOption /// /// The option title. /// The default value. - protected ModdedOption(string title, T defaultValue) + /// Whether to include the option in the preset. + protected ModdedOption(string title, T defaultValue, bool includeInPreset = true) { Id = ModdedOptionsManager.NextId; Title = title; @@ -104,6 +92,7 @@ public abstract class ModdedOption : IModdedOption Value = defaultValue; StringName = CustomStringName.CreateAndRegister(Title); Visible = () => true; + IncludeInPreset = includeInPreset; } internal void ValueChanged(OptionBehaviour optionBehaviour) @@ -138,22 +127,13 @@ public abstract class ModdedOption : IModdedOption OnValueChanged(newValue); } - /// - /// Gets the float data of the option. - /// - /// A float object representing the option's value. + /// public abstract float GetFloatData(); - /// - /// Gets the net data of the option. - /// - /// A NetData object representing this option's data. + /// public abstract NetData GetNetData(); - /// - /// Handles incoming net data. - /// - /// The NetData's byte array. + /// public abstract void HandleNetData(byte[] data); /// @@ -169,14 +149,7 @@ public abstract class ModdedOption : IModdedOption /// The value. public abstract T GetValueFromOptionBehaviour(OptionBehaviour optionBehaviour); - /// - /// Creates the option behaviour. - /// - /// The ToggleOption prefab. - /// The NumberOption prefab. - /// The StringOption prefab. - /// The options container. - /// A new OptionBehaviour for this modded option. + /// public abstract OptionBehaviour CreateOption( ToggleOption toggleOpt, NumberOption numberOpt, diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs index 3495e86..26ecc74 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs @@ -15,7 +15,8 @@ public class ModdedToggleOption : ModdedOption /// /// The option title. /// The default value. - public ModdedToggleOption(string title, bool defaultValue) : base(title, defaultValue) + /// Whether to include this option in the preset or not. + public ModdedToggleOption(string title, bool defaultValue, bool includeInPreset=true) : base(title, defaultValue, includeInPreset) { Data = ScriptableObject.CreateInstance();