Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed May 2, 2024
1 parent 679dd1d commit 37af2c4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions MonkeyLoader/Configuration/ConfigSection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HarmonyLib;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NuGet.Packaging;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
Expand All @@ -23,7 +24,7 @@ public abstract class ConfigSection
/// <summary>
/// Stores the <see cref="IDefiningConfigKey"/>s tracked by this section.
/// </summary>
protected readonly HashSet<IDefiningConfigKey> keys;
protected readonly HashSet<IDefiningConfigKey> keys = new();

private readonly Lazy<string> _fullId;

Expand Down Expand Up @@ -98,11 +99,6 @@ public abstract class ConfigSection
/// </summary>
protected ConfigSection()
{
keys = new(GetConfigKeys());

foreach (var key in keys)
key.Section = this;

_fullId = new(() => $"{Config.Owner.Id}.{Id}");
}

Expand Down Expand Up @@ -185,6 +181,18 @@ public bool TryGetDefinedKey<T>(ITypedConfigKey<T> typedTemplateKey, [NotNullWhe
public bool TryGetDefinedKey(IConfigKey templateKey, [NotNullWhen(true)] out IDefiningConfigKey? definingKey)
=> Config.TryGetDefiningKey(templateKey.AsUntyped, out definingKey) && keys.Contains(definingKey);

internal void InitializeKeys()
{
var keysToAdd = GetConfigKeys().ToArray();
keys.AddRange(keysToAdd);

foreach (var key in keysToAdd)
key.Section = this;

foreach (var key in keysToAdd)
Config.RegisterConfigKey(key);
}

internal void Load(JObject source, JsonSerializer jsonSerializer)
{
if (source.Count > 0)
Expand Down

0 comments on commit 37af2c4

Please sign in to comment.