diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs index e9097ee..a45201f 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedNumberOption.cs @@ -61,10 +61,10 @@ public class ModdedNumberOption : ModdedOption /// The maximum value. /// The increment. /// The suffix type. - /// Optional format string for the option screen. - /// Determines what is shown for zero. Options: ∞, #, or a word value (such as Off). - /// Determines what is shown for negative 1. Options: ∞, #, or a word value (such as Off). + /// Determines what is shown for zero. + /// Determines what is shown for negative 1. /// Whether increments can be split in half. + /// Optional format string for the option screen. /// Whether to include this option in the preset or not. public ModdedNumberOption( string title, @@ -78,36 +78,8 @@ public class ModdedNumberOption : ModdedOption string? formatString = null, bool halfIncrements = false, bool includeInPreset = true) - : base(title, defaultValue, includeInPreset) + : this(title, defaultValue, min, max, increment, suffixType, zeroBehavior, negativeBehavior, halfIncrements, formatString, includeInPreset) { - Min = min; - Max = max; - Increment = increment; - SuffixType = suffixType; - ZeroWordValue = zeroBehavior; - NegativeWordValue = negativeBehavior; - ShiftIncrement = halfIncrements; - - Value = Mathf.Clamp(defaultValue, min, max); - - Data = ScriptableObject.CreateInstance(); - - var data = (FloatGameSetting)Data; - data.Type = global::OptionTypes.Float; - data.Title = StringName; - data.Value = Value; - data.Increment = Increment; - data.ValidRange = new FloatRange(Min, Max); - data.FormatString = formatString ?? - (defaultValue.IsInteger() && - Increment.IsInteger() && - Value.IsInteger() && - Min.IsInteger() && - Max.IsInteger() ? "0" : "0.0"); - - data.ZeroIsInfinity = ZeroInfinity; - data.SuffixType = (NumberSuffixes)SuffixType; - data.OptionName = FloatOptionNames.Invalid; } /// @@ -119,8 +91,8 @@ public class ModdedNumberOption : ModdedOption /// The maximum value. /// The increment. /// The suffix type. - /// Optional format string for the option screen. /// Whether zero is infinity or not. + /// Optional format string for the option screen. /// Whether to include this option in the preset or not. public ModdedNumberOption( string title, @@ -132,21 +104,35 @@ public class ModdedNumberOption : ModdedOption string? formatString = null, bool zeroInfinity = false, bool includeInPreset = true) + : this(title, defaultValue, min, max, increment, suffixType, zeroInfinity ? "∞" : "#", "#", increment == 1f, formatString, includeInPreset) + { + } + + private ModdedNumberOption( + string title, + float defaultValue, + float min, + float max, + float increment, + MiraNumberSuffixes suffixType, + string zeroBehavior, + string negativeBehavior, + bool shiftIncrement, + string? formatString, + bool includeInPreset) : base(title, defaultValue, includeInPreset) { Min = min; Max = max; Increment = increment; SuffixType = suffixType; - ZeroWordValue = zeroInfinity ? "∞" : "#"; - NegativeWordValue = "#"; - ShiftIncrement = Mathf.Approximately(increment, 1f); + ZeroWordValue = zeroBehavior; + ShiftIncrement = shiftIncrement; + NegativeWordValue = negativeBehavior; Value = Mathf.Clamp(defaultValue, min, max); - Data = ScriptableObject.CreateInstance(); - - var data = (FloatGameSetting)Data; + var data = ScriptableObject.CreateInstance(); data.Type = global::OptionTypes.Float; data.Title = StringName; data.Value = Value; @@ -162,6 +148,8 @@ public class ModdedNumberOption : ModdedOption data.ZeroIsInfinity = ZeroInfinity; data.SuffixType = (NumberSuffixes)SuffixType; data.OptionName = FloatOptionNames.Invalid; + + Data = data; } /// diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs index a9f5143..6e9e9ad 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs @@ -44,6 +44,13 @@ public class ModdedOptionList : IModdedOptionList Options = [.. options]; } + /// + /// Indexes the option of type . + /// + /// The option's index. + /// option of type . + public T this[int idx] => Options[idx]; + /// public IEnumerator GetEnumerator() { @@ -62,13 +69,6 @@ public class ModdedOptionList : IModdedOptionList return ((IEnumerable)Options).GetEnumerator(); } - /// - /// Indexes the option of type . - /// - /// The option's index. - /// option of type . - public T this[int idx] => Options[idx]; - /// IModdedOption IReadOnlyList.this[int index] => this[index]; } diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs index bd96499..e45c81e 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedPlayerOption.cs @@ -37,15 +37,16 @@ public class ModdedPlayerOption : ModdedOption public ModdedPlayerOption(string title, bool allowNone = true) : base(title, allowNone ? -1 : 0, false) { - Data = ScriptableObject.CreateInstance(); - var data = (PlayerSelectionGameSetting)Data; + Values = []; + AllowNone = allowNone; + Value = DefaultValue; + + var data = ScriptableObject.CreateInstance(); data.Title = StringName; data.Type = global::OptionTypes.Player; - Values = []; - AllowNone = allowNone; - Value = DefaultValue; + Data = data; } /// diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs index 6209881..291ba67 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedStringOption.cs @@ -36,15 +36,15 @@ public class ModdedStringOption : ModdedOption : base(title, defaultValue, includeInPreset) { Values = values; - Data = ScriptableObject.CreateInstance(); - var data = (StringGameSetting)Data; + StringNameValues = [.. values.Select(MiraLocaleManager.GetOrCreateLocaleString)]; + var data = ScriptableObject.CreateInstance(); data.Title = StringName; data.Type = global::OptionTypes.String; - StringNameValues = [.. values.Select(MiraLocaleManager.GetOrCreateLocaleString)]; data.Values = StringNameValues; - data.Index = GetIndex(Value); + + Data = data; } /// diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs index 6fa8be3..1a331d4 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedToggleOption.cs @@ -20,11 +20,11 @@ public class ModdedToggleOption : ModdedOption public ModdedToggleOption(string title, bool defaultValue, bool includeInPreset = true) : base(title, defaultValue, includeInPreset) { - Data = ScriptableObject.CreateInstance(); - - var data = (CheckboxGameSetting)Data; + var data = ScriptableObject.CreateInstance(); data.Title = StringName; data.Type = global::OptionTypes.Checkbox; + + Data = data; } ///