44using HarmonyLib ;
55using Polyglot ;
66
7- namespace ExtendedColorSchemes . HarmonyPatches
7+ namespace ExtendedColorSchemes . HarmonyPatches ;
8+
9+ [ HarmonyPatch ( typeof ( ColorSchemesSettings ) , MethodType . Constructor , typeof ( ColorScheme [ ] ) ) ]
10+ internal class ColorSchemesSettingsConstructor
811{
9- [ HarmonyPatch ( typeof ( ColorSchemesSettings ) , MethodType . Constructor , typeof ( ColorScheme [ ] ) ) ]
10- internal class ColorSchemesSettingsConstructor
11- {
12- public static int NumberOfDefaultUserColorSchemes ;
13- public static string ? DefaultSelectedColorSchemeId ;
14- public static ColorScheme [ ] ? DefaultColorSchemes ;
12+ public static int NumberOfDefaultUserColorSchemes ;
13+ public static string ? DefaultSelectedColorSchemeId ;
14+ public static ColorScheme [ ] ? DefaultColorSchemes ;
1515
16- private const int NumberOfColorSchemesToAddByDefault = 8 ;
17- private static readonly int NumberOfColorSchemesToAdd = Plugin . Config . colorSchemes . Count > 0 ? Plugin . Config . colorSchemes . Count : NumberOfColorSchemesToAddByDefault ;
16+ private const int NumberOfColorSchemesToAddByDefault = 8 ;
17+ private static readonly int NumberOfColorSchemesToAdd = Plugin . Config . colorSchemes . Count > 0 ? Plugin . Config . colorSchemes . Count : NumberOfColorSchemesToAddByDefault ;
1818
19- internal static void Prefix ( ref ColorScheme [ ] colorSchemes )
20- {
21- DefaultColorSchemes = colorSchemes ;
22- NumberOfDefaultUserColorSchemes = colorSchemes . Count ( x => x . isEditable ) ;
23- string translation = Localization . Get ( "CUSTOM_0_COLOR_SCHEME" ) ;
24- var regex = new Regex ( @"\d+" , RegexOptions . None ) ;
25-
26- List < ColorScheme > colorSchemesList = colorSchemes . ToList ( ) ;
19+ internal static void Prefix ( ref ColorScheme [ ] colorSchemes )
20+ {
21+ DefaultColorSchemes = colorSchemes ;
22+ NumberOfDefaultUserColorSchemes = colorSchemes . Count ( x => x . isEditable ) ;
23+ string translation = Localization . Get ( "CUSTOM_0_COLOR_SCHEME" ) ;
24+ var regex = new Regex ( @"\d+" , RegexOptions . None ) ;
2725
28- var first = colorSchemesList . First ( ) ;
29- var firstWithBoostColors = colorSchemesList . FirstOrDefault ( x => x . supportsEnvironmentColorBoost ) ;
26+ List < ColorScheme > colorSchemesList = colorSchemes . ToList ( ) ;
3027
31- for ( var i = 0 ; i < NumberOfColorSchemesToAdd ; i ++ )
32- {
33- ColorSchemeWithEditableName ? savedColorScheme = Plugin . Config . colorSchemes . Count > i ? Plugin . Config . colorSchemes [ i ] : null ;
34- colorSchemesList . Insert ( i + NumberOfDefaultUserColorSchemes , new ColorScheme (
35- $ "User{ i + NumberOfDefaultUserColorSchemes } ",
36- $ "_UNLOCALIZED_",
37- true ,
38- ! string . IsNullOrWhiteSpace ( savedColorScheme ? . colorSchemeName ) ? savedColorScheme ? . colorSchemeName : regex . Replace ( translation , ( i + NumberOfDefaultUserColorSchemes ) . ToString ( ) ) ,
39- first . isEditable ,
40- savedColorScheme ? . saberAColor ?? first . saberAColor ,
41- savedColorScheme ? . saberBColor ?? first . saberBColor ,
42- savedColorScheme ? . environmentColor0 ?? first . environmentColor0 ,
43- savedColorScheme ? . environmentColor1 ?? first . environmentColor1 ,
44- savedColorScheme ? . supportsEnvironmentColorBoost ?? firstWithBoostColors ? . supportsEnvironmentColorBoost ?? first . supportsEnvironmentColorBoost ,
45- savedColorScheme ? . environmentColor0Boost ?? firstWithBoostColors ? . environmentColor0Boost ?? first . environmentColor0Boost ,
46- savedColorScheme ? . environmentColor1Boost ?? firstWithBoostColors ? . environmentColor1Boost ?? first . environmentColor1Boost ,
47- savedColorScheme ? . obstaclesColor ?? first . obstaclesColor ) ) ;
48- }
28+ var first = colorSchemesList . First ( ) ;
29+ var firstWithBoostColors = colorSchemesList . FirstOrDefault ( x => x . supportsEnvironmentColorBoost ) ;
4930
50- if ( Plugin . Config . selectedColorSchemeId != null && colorSchemesList . All ( x => x . colorSchemeId != Plugin . Config . selectedColorSchemeId ) )
51- {
52- Plugin . Log . Warn ( $ "Selected color scheme doesn't exist in the collection, restoring default value \" { DefaultSelectedColorSchemeId } \" .") ;
53- Plugin . Config . selectedColorSchemeId = DefaultSelectedColorSchemeId ;
54- }
31+ for ( var i = 0 ; i < NumberOfColorSchemesToAdd ; i ++ )
32+ {
33+ ColorSchemeWithEditableName ? savedColorScheme = Plugin . Config . colorSchemes . Count > i ? Plugin . Config . colorSchemes [ i ] : null ;
34+ colorSchemesList . Insert ( i + NumberOfDefaultUserColorSchemes , new ColorScheme (
35+ $ "User{ i + NumberOfDefaultUserColorSchemes } ",
36+ $ "_UNLOCALIZED_",
37+ true ,
38+ ! string . IsNullOrWhiteSpace ( savedColorScheme ? . ColorSchemeName ) ? savedColorScheme ? . ColorSchemeName : regex . Replace ( translation , ( i + NumberOfDefaultUserColorSchemes ) . ToString ( ) ) ,
39+ first . isEditable ,
40+ savedColorScheme ? . saberAColor ?? first . saberAColor ,
41+ savedColorScheme ? . saberBColor ?? first . saberBColor ,
42+ savedColorScheme ? . environmentColor0 ?? first . environmentColor0 ,
43+ savedColorScheme ? . environmentColor1 ?? first . environmentColor1 ,
44+ savedColorScheme ? . SupportsEnvironmentColorBoost ?? firstWithBoostColors ? . supportsEnvironmentColorBoost ?? first . supportsEnvironmentColorBoost ,
45+ savedColorScheme ? . environmentColor0Boost ?? firstWithBoostColors ? . environmentColor0Boost ?? first . environmentColor0Boost ,
46+ savedColorScheme ? . environmentColor1Boost ?? firstWithBoostColors ? . environmentColor1Boost ?? first . environmentColor1Boost ,
47+ savedColorScheme ? . obstaclesColor ?? first . obstaclesColor ) ) ;
48+ }
5549
56- colorSchemes = colorSchemesList . ToArray ( ) ;
50+ if ( Plugin . Config . selectedColorSchemeId != null && colorSchemesList . All ( x => x . colorSchemeId != Plugin . Config . selectedColorSchemeId ) )
51+ {
52+ Plugin . Log . Warn ( $ "Selected color scheme doesn't exist in the collection, restoring default value \" { DefaultSelectedColorSchemeId } \" .") ;
53+ Plugin . Config . selectedColorSchemeId = DefaultSelectedColorSchemeId ;
5754 }
55+
56+ colorSchemes = colorSchemesList . ToArray ( ) ;
5857 }
58+ }
5959
60- //[HarmonyPatch(typeof(ColorSchemesSettings), "selectedColorSchemeId", MethodType.Setter)]
61- internal class ColorSchemesSettingsSelectedColorSchemeIdSetter
60+ //[HarmonyPatch(typeof(ColorSchemesSettings), "selectedColorSchemeId", MethodType.Setter)]
61+ internal class ColorSchemesSettingsSelectedColorSchemeIdSetter
62+ {
63+ //[HarmonyPriority(Priority.HigherThanNormal)]
64+ internal static void Prefix ( ref string ? value )
6265 {
63- //[HarmonyPriority(Priority.HigherThanNormal)]
64- internal static void Prefix ( ref string ? value )
66+ if ( LoadFromCurrentVersionPatch . PlayerDataIsCorrupted )
6567 {
66- if ( LoadFromCurrentVersionPatch . PlayerDataIsCorrupted )
67- {
68- Plugin . Log . Error ( "Player data is corrupted, aborting." ) ;
69- return ;
70- }
68+ Plugin . Log . Error ( "Player data is corrupted, aborting." ) ;
69+ return ;
70+ }
7171
72- string ? colorSchemeId = value ;
73- if ( ColorSchemesSettingsConstructor . DefaultColorSchemes != null && ColorSchemesSettingsConstructor . DefaultColorSchemes . Any ( x => x . colorSchemeId == colorSchemeId ) )
74- {
75- ColorSchemesSettingsConstructor . DefaultSelectedColorSchemeId = value ;
76- }
72+ string ? colorSchemeId = value ;
73+ if ( ColorSchemesSettingsConstructor . DefaultColorSchemes != null && ColorSchemesSettingsConstructor . DefaultColorSchemes . Any ( x => x . colorSchemeId == colorSchemeId ) )
74+ {
75+ ColorSchemesSettingsConstructor . DefaultSelectedColorSchemeId = value ;
76+ }
7777
78- if ( ! LoadFromCurrentVersionPatch . IsCalledByLoadFromCurrentVersion )
79- {
80- Plugin . Log . Info ( "Not called by LoadFromCurrentVersion, aborting." ) ;
81- return ;
82- }
78+ if ( ! LoadFromCurrentVersionPatch . IsCalledByLoadFromCurrentVersion )
79+ {
80+ Plugin . Log . Info ( "Not called by LoadFromCurrentVersion, aborting." ) ;
81+ return ;
82+ }
8383
84- Plugin . Log . Info ( $ "DefaultSelectedColorSchemeId={ value } ") ;
84+ Plugin . Log . Info ( $ "DefaultSelectedColorSchemeId={ value } ") ;
8585
86- if ( Plugin . Config . selectedColorSchemeId == null )
87- {
88- Plugin . Config . selectedColorSchemeId = value ;
89- Plugin . Log . Info ( $ "Plugin.Config.selectedColorSchemeId={ value } ") ;
90- }
91- else
92- {
93- value = Plugin . Config . selectedColorSchemeId ;
94- Plugin . Log . Info ( $ "value={ Plugin . Config . selectedColorSchemeId } ") ;
95- }
86+ if ( Plugin . Config . selectedColorSchemeId == null )
87+ {
88+ Plugin . Config . selectedColorSchemeId = value ;
89+ Plugin . Log . Info ( $ "Plugin.Config.selectedColorSchemeId={ value } ") ;
90+ }
91+ else
92+ {
93+ value = Plugin . Config . selectedColorSchemeId ;
94+ Plugin . Log . Info ( $ "value={ Plugin . Config . selectedColorSchemeId } ") ;
9695 }
9796 }
98- }
97+ }
0 commit comments