Files
GoakeFlax/Source/Game/Console/Config.cs

48 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
namespace Game;
public class Config
{
private Dictionary<string, string> dictionary = new Dictionary<string, string>();
public string this[string key]
{
get => dictionary[key];
set => dictionary[key] = value;
}
// TODO: This is for debugging only, remove this later
public string[] Commands = Array.Empty<string>();
public string[] GetLines()
{
string[] lines = new string[dictionary.Count + Commands.Length];
int lineIndex = 0;
foreach (var kvp in dictionary)
lines[lineIndex++] = $"{kvp.Key} {kvp.Value}";
foreach (var cmd in Commands)
lines[lineIndex++] = cmd;
return lines;
}
public void Merge(Config config)
{
if (config.dictionary.Count == 0)
return;
foreach (var kvp in config.dictionary)
{
if (dictionary.TryGetValue(kvp.Key, out string oldValue))
{
if (oldValue == kvp.Value)
continue;
dictionary[kvp.Key] = kvp.Value;
}
else
dictionary.Add(kvp.Key, kvp.Value);
}
}
}