ResoniteModdingGroup / MonkeyLoader.GamePacks.ResoniteModLoader

MonkeyLoader Game Pack that provides compatibility for ResoniteModLoader.
GNU Lesser General Public License v3.0
4 stars 1 forks source link

Generate sliders in the settings for config keys that use FrooxEngine.RangeAttribute #10

Closed Nytra closed 2 months ago

Nytra commented 2 months ago

ResoniteModSettings does this and it's pretty nice

Screenshot 2024-05-10 223504

Banane9 commented 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.

Banane9 commented 2 months ago

The Range attribute could be mapped to the components though, just like the QuantityAttribute could be mapped to ConfigKeyQuantity

Nytra commented 2 months ago

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.

Banane9 commented 2 months ago

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.

Nytra commented 2 months ago

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

Nytra commented 2 months ago

Also how exactly does adding components work? Because this code won't compile:

fieldValue.UntypedKey.Components.Add(new ConfigKeyRange<float>());
Nytra commented 2 months ago

I figured it out:

((DefiningConfigKey<float>)fieldValue.UntypedKey).Components.Add(new ConfigKeyRange<float>());