From 007c2020587549b94b45901765610d9e89f43a2b Mon Sep 17 00:00:00 2001 From: David Higueros <111460331+TheDavSmasher@users.noreply.github.com> Date: Sat, 20 Jun 2026 00:52:07 -0600 Subject: [PATCH] Changed properties to init instead of set to allow using object initializer but not changing the values later --- MiraAPI/GameOptions/IModdedOptionList.cs | 10 ++++++---- .../GameOptions/OptionTypes/ModdedOptionList.cs | 17 +++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/MiraAPI/GameOptions/IModdedOptionList.cs b/MiraAPI/GameOptions/IModdedOptionList.cs index 4fed3b3..62dd7d5 100644 --- a/MiraAPI/GameOptions/IModdedOptionList.cs +++ b/MiraAPI/GameOptions/IModdedOptionList.cs @@ -20,14 +20,16 @@ public interface IModdedOptionList IMiraPlugin? ParentMod { get; set; } /// - /// Gets or sets the visibility function for the options. + /// Gets the visibility function for the options. + /// Leaving it null will leave the options unchanged. /// - Func Visible { get; set; } + Func? Visible { get; init; } /// - /// Gets or sets a value indicating whether the options should be included with presets. + /// Gets a value indicating whether the options should be included with presets. + /// Leaving it null will leave the options unchanged. /// - bool IncludeInPreset { get; set; } + bool? IncludeInPreset { get; init; } /// /// Saves the options to a preset configuration file. diff --git a/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs b/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs index a32a727..7e97a1a 100644 --- a/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs +++ b/MiraAPI/GameOptions/OptionTypes/ModdedOptionList.cs @@ -38,12 +38,13 @@ public class ModdedOptionList : IModdedOptionList, IReadOnlyList where T : public IReadOnlyList Options { get; } /// - public Func Visible + public Func? Visible { get; - set + init { field = value; + if (value == null) return; foreach (var (option, idx) in Options.Select((o, i) => (o, i))) { option.Visible = () => value(idx); @@ -52,15 +53,16 @@ public class ModdedOptionList : IModdedOptionList, IReadOnlyList where T : } /// - public bool IncludeInPreset + public bool? IncludeInPreset { get; - set + init { field = value; + if (value == null) return; foreach (var option in Options) { - option.IncludeInPreset = value; + option.IncludeInPreset = value.Value; } } } @@ -71,12 +73,11 @@ public class ModdedOptionList : IModdedOptionList, IReadOnlyList where T : /// The option list's length. /// The option factory to instantiate the options from. /// Whether to include the options in the preset. - public ModdedOptionList(int count, Func optionFactory, bool includeInPreset = true) + public ModdedOptionList(int count, Func optionFactory, bool? includeInPreset = true) { Count = count; - Visible = _ => true; - IncludeInPreset = includeInPreset; Options = Enumerable.Range(0, Count).Select(optionFactory).ToArray(); + IncludeInPreset = includeInPreset; } ///