mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 08:20:00 +09:00
Add mod setting (de)serialization support
This commit is contained in:
@ -35,16 +35,11 @@ namespace osu.Game.Configuration
|
||||
{
|
||||
public static IEnumerable<Drawable> CreateSettingsControls(this object obj)
|
||||
{
|
||||
foreach (var property in obj.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance))
|
||||
foreach (var (attr, property) in obj.GetSettingsSourceProperties())
|
||||
{
|
||||
var attr = property.GetCustomAttribute<SettingSourceAttribute>(true);
|
||||
object value = property.GetValue(obj);
|
||||
|
||||
if (attr == null)
|
||||
continue;
|
||||
|
||||
var prop = property.GetValue(obj);
|
||||
|
||||
switch (prop)
|
||||
switch (value)
|
||||
{
|
||||
case BindableNumber<float> bNumber:
|
||||
yield return new SettingsSlider<float>
|
||||
@ -102,9 +97,22 @@ namespace osu.Game.Configuration
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException($"{nameof(SettingSourceAttribute)} was attached to an unsupported type ({prop})");
|
||||
throw new InvalidOperationException($"{nameof(SettingSourceAttribute)} was attached to an unsupported type ({value})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<(SettingSourceAttribute, PropertyInfo)> GetSettingsSourceProperties(this object obj)
|
||||
{
|
||||
foreach (var property in obj.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
var attr = property.GetCustomAttribute<SettingSourceAttribute>(true);
|
||||
|
||||
if (attr == null)
|
||||
continue;
|
||||
|
||||
yield return (attr, property);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user