cleanup modded options

This commit is contained in:
XtraCube committed 2024-08-19 18:07:13 -04:00
1 parent 730b22f7ce
commit 8a502bc7d6
9 files changed
+42 -58

No files matched your search

@@ -4,17 +4,13 @@ using System.Reflection;
namespace MiraAPI.GameOptions.Attributes;
public class ModdedEnumOptionAttribute : ModdedOptionAttribute
public class ModdedEnumOptionAttribute(string title, Type enumType, Type roleType = null)
: ModdedOptionAttribute(title, roleType)
{
public Type EnumType;
public ModdedEnumOptionAttribute(string title, Type enumType, Type roleType = null) : base(title, roleType)
{
EnumType = enumType;
}
public override IModdedOption CreateOption(object value, PropertyInfo property)
{
var opt = new ModdedEnumOption(Title, (int)value, EnumType, RoleType);
var opt = new ModdedEnumOption(Title, (int)value, enumType, RoleType);
return opt;
}
@@ -27,6 +23,6 @@ public class ModdedEnumOptionAttribute : ModdedOptionAttribute
public override object GetValue()
{
ModdedEnumOption opt = HolderOption as ModdedEnumOption;
return Enum.ToObject(EnumType.GetType(), opt.Value);
return Enum.ToObject(enumType, opt.Value);
}
}
@@ -4,26 +4,19 @@ using System.Reflection;
namespace MiraAPI.GameOptions.Attributes;
public class ModdedNumberOptionAttribute : ModdedOptionAttribute
public class ModdedNumberOptionAttribute(
string title,
float min,
float max,
float increment = 1,
NumberSuffixes suffixType = NumberSuffixes.None,
bool zeroInfinity = false,
Type roleType = null)
: ModdedOptionAttribute(title, roleType)
{
public float Min { get; private set; }
public float Max { get; private set; }
public float Increment { get; private set; }
public NumberSuffixes SuffixType { get; private set; }
public bool ZeroInfinity { get; private set; }
public ModdedNumberOptionAttribute(string title, float min, float max, float increment = 1, NumberSuffixes suffixType = NumberSuffixes.None, bool zeroInfinity = false, Type roleType = null) : base(title, roleType)
{
Min = min;
Max = max;
Increment = increment;
SuffixType = suffixType;
ZeroInfinity = zeroInfinity;
}
public override IModdedOption CreateOption(object value, PropertyInfo property)
{
var toggleOpt = new ModdedNumberOption(Title, (float)value, Min, Max, Increment, SuffixType, ZeroInfinity, RoleType);
var toggleOpt = new ModdedNumberOption(Title, (float)value, min, max, increment, suffixType, zeroInfinity, RoleType);
return toggleOpt;
}
@@ -4,18 +4,17 @@ using System.Reflection;
namespace MiraAPI.GameOptions.Attributes;
[AttributeUsage(AttributeTargets.Property)]
public abstract class ModdedOptionAttribute : Attribute
public abstract class ModdedOptionAttribute(string title, Type roleType = null) : Attribute
{
public IModdedOption HolderOption { get; set; }
public string Title { get; private set; }
public Type RoleType { get; private set; }
public ModdedOptionAttribute(string title, Type roleType = null)
{
Title = title;
RoleType = roleType;
}
public string Title { get; private set; } = title;
protected Type RoleType { get; private set; } = roleType;
public abstract void SetValue(object val);
public abstract object GetValue();
public abstract IModdedOption CreateOption(object value, PropertyInfo property);
}
@@ -4,17 +4,12 @@ using System.Reflection;
namespace MiraAPI.GameOptions.Attributes;
public class ModdedStringOptionAttribute : ModdedOptionAttribute
public class ModdedStringOptionAttribute(string title, string[] values, Type roleType = null)
: ModdedOptionAttribute(title, roleType)
{
public string[] Values;
public ModdedStringOptionAttribute(string title, string[] strings, Type roleType = null) : base(title, roleType)
{
Values = strings;
}
public override IModdedOption CreateOption(object value, PropertyInfo property)
{
var opt = new ModdedStringOption(Title, (int)value, Values, RoleType);
var opt = new ModdedStringOption(Title, (int)value, values, RoleType);
return opt;
}
@@ -4,12 +4,8 @@ using System.Reflection;
namespace MiraAPI.GameOptions.Attributes;
public class ModdedToggleOptionAttribute : ModdedOptionAttribute
public class ModdedToggleOptionAttribute(string title, Type roleType = null) : ModdedOptionAttribute(title, roleType)
{
public ModdedToggleOptionAttribute(string title, Type roleType = null) : base(title, roleType)
{
}
public override IModdedOption CreateOption(object value, PropertyInfo property)
{
var toggleOpt = new ModdedToggleOption(Title, (bool)value, RoleType);
@@ -9,6 +9,8 @@ namespace MiraAPI.GameOptions.OptionTypes;
public class ModdedEnumOption : ModdedOption<int>
{
public string[] Values { get; }
public ModdedEnumOption(string title, int defaultValue, Type enumType, Type roleType) : base(title, defaultValue, roleType)
{
Values = Enum.GetNames(enumType);
@@ -20,8 +22,6 @@ public class ModdedEnumOption : ModdedOption<int>
data.Values = Values.Select(CustomStringName.CreateAndRegister).ToArray();
data.Index = Value;
}
public string[] Values { get; set; }
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
{
@@ -9,11 +9,16 @@ namespace MiraAPI.GameOptions.OptionTypes;
public class ModdedNumberOption : ModdedOption<float>
{
public float Min { get; private set; }
public float Max { get; private set; }
public float Increment { get; private set; }
public NumberSuffixes SuffixType { get; private set; }
public bool ZeroInfinity { get; private set; }
public float Min { get;}
public float Max { get; }
public float Increment { get; }
public NumberSuffixes SuffixType { get; }
public bool ZeroInfinity { get; }
public ModdedNumberOption(string title, float defaultValue, float min, float max, float increment, NumberSuffixes suffixType, bool zeroInfinity, Type roleType) : base(title, defaultValue, roleType)
{
Min = min;
@@ -24,7 +24,7 @@ public abstract class ModdedOption<T> : IModdedOption
public ModdedOptionGroup Group { get; set; } = null;
public IMiraPlugin ParentMod { get; set; } = null;
public ModdedOption(string title, T defaultValue, Type roleType) : this()
protected ModdedOption(string title, T defaultValue, Type roleType) : this()
{
Title = title;
DefaultValue = defaultValue;
@@ -37,8 +37,8 @@ public abstract class ModdedOption<T> : IModdedOption
AdvancedRole = roleType;
}
}
public ModdedOption()
private ModdedOption()
{
Logger<MiraApiPlugin>.Error("created modded option");
Id = ModdedOptionsManager.NextId++;
@@ -9,6 +9,8 @@ namespace MiraAPI.GameOptions.OptionTypes;
public class ModdedStringOption : ModdedOption<int>
{
public string[] Values { get; }
public ModdedStringOption(string title, int defaultValue, string[] values, Type roleType) : base(title, defaultValue, roleType)
{
Values = values;
@@ -21,8 +23,6 @@ public class ModdedStringOption : ModdedOption<int>
data.Index = Value;
}
public string[] Values { get; set; }
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
{
var stringOption = Object.Instantiate(stringOpt, container);