Skip to content

Fix wrongly used value in enum handling in the settings menu#1101

Open
Wartori54 wants to merge 2 commits into
EverestAPI:devfrom
Wartori54:enum-setting-fix
Open

Fix wrongly used value in enum handling in the settings menu#1101
Wartori54 wants to merge 2 commits into
EverestAPI:devfrom
Wartori54:enum-setting-fix

Conversation

@Wartori54

Copy link
Copy Markdown
Member

The default handling of Enum as a setting mixed the value and the index of the value, causing enums which do not have the values auto assigned in c# to misbehave.
This was first reported with an enum like following:

public enum MyEnum {
    Option1 = 0x1,
    Option2 = 0xff,
}

public MyEnum MyEnumSetting { get; set; } = MyEnum.Option2;

where the settings menu showed Option1 right after adding the setting to the class. This is due to mixing an internal index with the enum value.
Furthermore, it also saved the wrong values in the yaml, due to it using the internal index, rather than the proper value associated with the selected enum value.

@maddie480-bot maddie480-bot added the 1: review needed This PR needs 2 approvals to be merged (bot-managed) label Apr 3, 2026

@microlith57 microlith57 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread Celeste.Mod.mm/Mod/Module/EverestModule.cs
Co-authored-by: microlith57 <microlith57@gmail.com>

@microlith57 microlith57 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

else if (propType.IsEnum)
{
else if (propType.IsEnum) {
Array enumValues = Enum.GetValues(propType);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we .distinct() it first?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on how we want to handle that case. I'd say it is not really beneficial to eliminate duplicate values since having indistinguishable enum values does not make much sense in an enum for configuration. Thus we shouldn't handle that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1: review needed This PR needs 2 approvals to be merged (bot-managed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants