LootDumpProcessor/Storage/Collections/SubdivisionedKeyableDictionary.cs
chomp 6e4c7abf73 dump-processor-cleanup (#6)
Co-authored-by: Alex <alex@dm-me-for-questions.com>
Reviewed-on: SPT-AKI/LootDumpProcessor#6
2024-04-16 18:29:40 +00:00

50 lines
1.3 KiB
C#

using System.Text.Json.Serialization;
using LootDumpProcessor.Utils;
using Newtonsoft.Json;
namespace LootDumpProcessor.Storage.Collections;
public class SubdivisionedKeyableDictionary<K, V> : Dictionary<K, V>, IKeyable
{
[JsonProperty("__id__")]
[JsonPropertyName("__id__")]
public string __ID { get; set; } = KeyGenerator.GetNextKey();
[JsonProperty("extras")]
[JsonPropertyName("extras")]
public string? Extras
{
get
{
if (ExtraSubdivisions == null)
return null;
return string.Join(",", ExtraSubdivisions);
}
set { ExtraSubdivisions = value.Split(","); }
}
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
private string[]? ExtraSubdivisions { get; set; }
public IKey GetKey()
{
if (ExtraSubdivisions != null)
{
var subdivisions = new List<string>
{
"dictionaries"
};
subdivisions.AddRange(ExtraSubdivisions);
subdivisions.Add(__ID);
return new SubdivisionedUniqueKey(subdivisions.ToArray());
}
return new SubdivisionedUniqueKey(["dictionaries", __ID]);
}
public void AddExtraSubdivisions(string[] extras)
{
ExtraSubdivisions = extras;
}
}