2424
2525namespace PlayEveryWare . EpicOnlineServices . Extensions
2626{
27- using Epic . OnlineServices . Auth ;
2827 using Utility ;
2928 using System ;
3029 using System . Collections . Generic ;
@@ -61,11 +60,11 @@ public static class InputStateButtonFlagsExtensions
6160
6261 /// <summary>
6362 /// Tries to parse the given list of strings representing individual
64- /// AuthScopeFlags enum values, and performing a
63+ /// InputStateButtonFlags enum values, and performing a
6564 /// bitwise OR operation on those values.
6665 /// </summary>
6766 /// <param name="stringFlags">
68- /// List of strings representing individual AuthScopeFlags enum values.
67+ /// List of strings representing individual InputStateButtonFlags enum values.
6968 /// </param>
7069 /// <param name="result">
7170 /// The result of performing a bitwise OR operation on the values that
@@ -79,6 +78,53 @@ public static bool TryParse(IList<string> stringFlags, out InputStateButtonFlags
7978 {
8079 return EnumUtility < InputStateButtonFlags > . TryParse ( stringFlags , CustomMappings , out result ) ;
8180 }
81+
82+ /// <summary>
83+ /// Parses an InputStateButtonFlags value in to its component strings.
84+ /// These strings can then be safely stored in a configuration value.
85+ /// </summary>
86+ /// <param name="flags">Enum to separate into parts.</param>
87+ /// <returns>A list of strings representing these flags.</returns>
88+ public static List < string > FlagsToStrings ( this InputStateButtonFlags flags )
89+ {
90+ List < string > flagStrings = new List < string > ( ) ;
91+
92+ // Iterate over all possible flag values
93+ foreach ( InputStateButtonFlags flagOption in Enum . GetValues ( typeof ( InputStateButtonFlags ) ) )
94+ {
95+ // If the passed in Enum doesn't have this flag, skip it
96+ if ( ! flags . HasFlag ( flagOption ) )
97+ {
98+ continue ;
99+ }
100+
101+ // Look up this flag's name in the custom mappings dictionary
102+ // The dictionary is keyed by string value and valued by enum,
103+ // so it must be entirely traversed to find its matching string
104+ bool foundMapping = false ;
105+ foreach ( KeyValuePair < string , InputStateButtonFlags > mapping in CustomMappings )
106+ {
107+ // Continue if this isn't the flag that matches the current option
108+ if ( mapping . Value != flagOption )
109+ {
110+ continue ;
111+ }
112+
113+ // This is the value needed, so use it
114+ flagStrings . Add ( mapping . Key ) ;
115+ foundMapping = true ;
116+ continue ;
117+ }
118+
119+ // If no custom mapping was found, use ToString instead
120+ if ( ! foundMapping )
121+ {
122+ flagStrings . Add ( flagOption . ToString ( ) ) ;
123+ }
124+ }
125+
126+ return flagStrings ;
127+ }
82128 }
83129}
84130
0 commit comments