Skip to content

Commit fe55cb6

Browse files
committed
Change naming for @JKDev
1 parent cdc467b commit fe55cb6

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

src/Managers/Config.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@ namespace PolyMod.Managers;
88
/// </summary>
99
public 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:

src/Managers/GLDConfig.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ public class GldConfigTemplate
99
{
1010
private static readonly string ConfigPath = Path.Combine(Plugin.BASE_PATH, "mods.json");
1111

12-
private readonly string _templateText;
13-
private JsonObject _currentConfig = new();
14-
private string _modName;
12+
private readonly string templateText;
13+
private JsonObject currentConfig = new();
14+
private string modName;
1515

1616
public GldConfigTemplate(string templateText, string modName)
1717
{
18-
_templateText = templateText;
19-
_modName = modName;
18+
this.templateText = templateText;
19+
this.modName = modName;
2020
Load();
2121
}
2222
private void Load()
@@ -25,34 +25,34 @@ private void Load()
2525
{
2626
var json = File.ReadAllText(ConfigPath);
2727
if (JsonNode.Parse(json) is JsonObject modsConfig
28-
&& modsConfig.TryGetPropertyValue(_modName, out var modConfigNode)
28+
&& modsConfig.TryGetPropertyValue(modName, out var modConfigNode)
2929
&& modConfigNode is JsonObject modConfig)
3030
{
31-
_currentConfig = modConfig;
31+
currentConfig = modConfig;
3232
return;
3333
}
3434
}
35-
_currentConfig = new JsonObject();
35+
currentConfig = new JsonObject();
3636
}
3737

3838
public string? Render()
3939
{
40-
if (!_templateText.Contains("{{")) return _templateText;
41-
var template = Template.Parse(_templateText);
40+
if (!templateText.Contains("{{")) return templateText;
41+
var template = Template.Parse(templateText);
4242
var context = new TemplateContext();
4343
var scriptObject = new ScriptObject();
4444

4545
bool changedConfig = false;
4646
scriptObject.Import("config",
4747
new Func<string, string, string>((key, defaultValue) =>
4848
{
49-
if (_currentConfig.TryGetPropertyValue(key, out var token) && token != null)
49+
if (currentConfig.TryGetPropertyValue(key, out var token) && token != null)
5050
{
5151
return token.ToString();
5252
}
5353

5454
changedConfig = true;
55-
_currentConfig[key] = defaultValue;
55+
currentConfig[key] = defaultValue;
5656

5757
return defaultValue;
5858
})
@@ -88,7 +88,7 @@ public void SaveChanges()
8888
modsConfigJson = new JsonObject();
8989
}
9090

91-
modsConfigJson[_modName] = _currentConfig;
91+
modsConfigJson[modName] = currentConfig;
9292
File.WriteAllText(ConfigPath, modsConfigJson.ToJsonString(new JsonSerializerOptions { WriteIndented = true }));
9393
}
9494
}

0 commit comments

Comments
 (0)