Closed Nytra closed 2 months ago
The Resonite Integration will already do this if you add a ConfigKeyRange
component to your config key - but that's not directly available for RML mods of course.
The Range attribute could be mapped to the components though, just like the QuantityAttribute
could be mapped to ConfigKeyQuantity
I have looked into this a bit, but I'm not sure where is the best place to check for the attributes, and I don't know how to correctly check which attributes the key has.
You'll want to do that in ModConfigurationDefinitionBuilder.ProcessField(field)
. You'll have to do .GetCustomAttribute<RangeAttribute>()
and .GetCustomAttribute<QuantityAttribute>()
on the field info to get if those attributes were placed on them. If not, it'll just be null. Then you just have to do some funny generic creation stuff like the SettingsDataFeedInjector does for some of the DataFeedItem generation to add the right components to the internal MonkeyLoader DefiningConfigKey of the ModConfigurationKeys.
When logging the custom attributes of the key type I was just getting a bunch of these:
System.Runtime.CompilerServices.NullableAttribute
System.Runtime.CompilerServices.NullableContextAttribute
But I will give it another try
Also how exactly does adding components work? Because this code won't compile:
fieldValue.UntypedKey.Components.Add(new ConfigKeyRange<float>());
I figured it out:
((DefiningConfigKey<float>)fieldValue.UntypedKey).Components.Add(new ConfigKeyRange<float>());
ResoniteModSettings does this and it's pretty nice