@@ -8,32 +8,32 @@ namespace PolyMod.Managers;
88/// </summary>
99public class Config < T > where T : class
1010{
11- private T ? _currentConfig ;
12- private readonly string _modName ;
13- private readonly ConfigTypes _configType ;
11+ private T ? currentConfig ;
12+ private readonly string modName ;
13+ private readonly ConfigTypes configType ;
1414 private static readonly string ExposedConfigPath = Path . Combine ( Plugin . BASE_PATH , "mods.json" ) ;
15- private readonly string _perModConfigPath ;
16- private T ? _defaultConfig ;
15+ private readonly string perModConfigPath ;
16+ private T ? defaultConfig ;
1717 public Config ( string modName , ConfigTypes configType )
1818 {
19- _modName = modName ;
20- _configType = configType ;
21- _perModConfigPath = Path . Combine ( Plugin . MODS_PATH , $ "{ modName } .json") ;
19+ this . modName = modName ;
20+ this . configType = configType ;
21+ perModConfigPath = Path . Combine ( Plugin . MODS_PATH , $ "{ modName } .json") ;
2222 Load ( ) ;
2323 }
2424
2525 internal void Load ( ) // can be called internally if config changes; gui config not implemented yet
2626 {
27- switch ( _configType )
27+ switch ( configType )
2828 {
2929 case ConfigTypes . PerMod :
3030 {
31- if ( ! File . Exists ( _perModConfigPath ) )
31+ if ( ! File . Exists ( perModConfigPath ) )
3232 {
3333 return ;
3434 }
35- var jsonText = File . ReadAllText ( _perModConfigPath ) ;
36- _currentConfig = JsonSerializer . Deserialize < T > ( jsonText ) ;
35+ var jsonText = File . ReadAllText ( perModConfigPath ) ;
36+ currentConfig = JsonSerializer . Deserialize < T > ( jsonText ) ;
3737 break ;
3838 }
3939 case ConfigTypes . Exposed :
@@ -43,7 +43,7 @@ public Config(string modName, ConfigTypes configType)
4343 return ;
4444 }
4545 var jsonText = File . ReadAllText ( ExposedConfigPath ) ;
46- _currentConfig = JsonNode . Parse ( jsonText ) ! [ _modName ] ? . Deserialize < T > ( ) ;
46+ currentConfig = JsonNode . Parse ( jsonText ) ! [ modName ] ? . Deserialize < T > ( ) ;
4747 break ;
4848 }
4949 default :
@@ -55,9 +55,9 @@ public Config(string modName, ConfigTypes configType)
5555 /// </summary>
5656 public void SetDefaultConfig ( T defaultValue )
5757 {
58- _defaultConfig = defaultValue ;
59- if ( _currentConfig is not null ) return ;
60- Write ( _defaultConfig ) ;
58+ defaultConfig = defaultValue ;
59+ if ( currentConfig is not null ) return ;
60+ Write ( defaultConfig ) ;
6161 SaveChanges ( ) ;
6262 }
6363
@@ -66,45 +66,45 @@ public void SetDefaultConfig(T defaultValue)
6666 /// </summary>
6767 public void Write ( T config )
6868 {
69- _currentConfig = config ;
69+ currentConfig = config ;
7070 }
7171 /// <summary>
7272 /// Gets the config. Should only be called after setting a default.
7373 /// </summary>
7474 public T Get ( )
7575 {
76- return _currentConfig ?? throw new InvalidOperationException ( "Must set default before reading config." ) ;
76+ return currentConfig ?? throw new InvalidOperationException ( "Must set default before reading config." ) ;
7777 }
7878 /// <summary>
79- /// edits the config. Should only be called after setting a default.
79+ /// Edits the config. Should only be called after setting a default.
8080 /// </summary>
8181 /// <remarks>Call SaveChanges after editing</remarks>
8282 public void Edit ( Action < T > editor )
8383 {
84- editor ( _currentConfig ?? throw new InvalidOperationException ( "Must set default before reading config." ) ) ;
84+ editor ( currentConfig ?? throw new InvalidOperationException ( "Must set default before reading config." ) ) ;
8585 }
8686 /// <summary>
8787 /// Gets part of the config. Should only be called after setting a default
8888 /// </summary>
8989 public TResult Get < TResult > ( Func < T , TResult > getter )
9090 {
91- return getter ( _currentConfig ?? throw new InvalidOperationException ( "Must set default before reading config." ) ) ;
91+ return getter ( currentConfig ?? throw new InvalidOperationException ( "Must set default before reading config." ) ) ;
9292 }
9393 /// <summary>
9494 /// writes the config to disk
9595 /// </summary>
9696 public void SaveChanges ( )
9797 {
98- switch ( _configType )
98+ switch ( configType )
9999 {
100100 case ConfigTypes . PerMod :
101- var perModJson = JsonSerializer . Serialize ( _currentConfig , new JsonSerializerOptions { WriteIndented = true } ) ;
102- File . WriteAllText ( _perModConfigPath , perModJson ) ;
101+ var perModJson = JsonSerializer . Serialize ( currentConfig , new JsonSerializerOptions { WriteIndented = true } ) ;
102+ File . WriteAllText ( perModConfigPath , perModJson ) ;
103103 break ;
104104 case ConfigTypes . Exposed :
105105 var modsConfigText = File . ReadAllText ( ExposedConfigPath ) ;
106106 var modsConfigJson = JsonNode . Parse ( modsConfigText ) ! . AsObject ( ) ;
107- modsConfigJson [ _modName ] = JsonSerializer . SerializeToNode ( _currentConfig ! ) ;
107+ modsConfigJson [ modName ] = JsonSerializer . SerializeToNode ( currentConfig ! ) ;
108108 File . WriteAllText ( ExposedConfigPath , modsConfigJson . ToJsonString ( new JsonSerializerOptions { WriteIndented = true } ) ) ;
109109 break ;
110110 default :
0 commit comments