Remove hardcoded settings backend.
This commit is contained in:
@@ -17,29 +17,33 @@ namespace OpenRA
|
||||
{
|
||||
public sealed class HotkeyManager
|
||||
{
|
||||
readonly KeySettings settings;
|
||||
readonly Dictionary<string, HotkeyDefinition> keys = new Dictionary<string, HotkeyDefinition>();
|
||||
readonly Dictionary<string, Hotkey> settings;
|
||||
readonly Dictionary<string, HotkeyDefinition> definitions = new Dictionary<string, HotkeyDefinition>();
|
||||
readonly Dictionary<string, Hotkey> keys = new Dictionary<string, Hotkey>();
|
||||
|
||||
public HotkeyManager(IReadOnlyFileSystem fileSystem, KeySettings settings, Manifest manifest)
|
||||
public HotkeyManager(IReadOnlyFileSystem fileSystem, Dictionary<string, Hotkey> settings, Manifest manifest)
|
||||
{
|
||||
this.settings = settings;
|
||||
|
||||
var keyDefinitions = MiniYaml.Load(fileSystem, manifest.Hotkeys, null);
|
||||
foreach (var kd in keyDefinitions)
|
||||
keys[kd.Key] = new HotkeyDefinition(kd.Key, kd.Value);
|
||||
{
|
||||
var definition = new HotkeyDefinition(kd.Key, kd.Value);
|
||||
definitions[kd.Key] = definition;
|
||||
keys[kd.Key] = definition.Default;
|
||||
}
|
||||
|
||||
foreach (var kv in settings)
|
||||
keys[kv.Key] = kv.Value;
|
||||
}
|
||||
|
||||
internal Func<Hotkey> GetHotkeyReference(string name)
|
||||
{
|
||||
var ret = settings.GetHotkeyReference(name);
|
||||
if (ret != null)
|
||||
return ret;
|
||||
// Is this a mod-defined hotkey?
|
||||
if (keys.ContainsKey(name))
|
||||
return () => keys[name];
|
||||
|
||||
HotkeyDefinition keyDefinition;
|
||||
if (keys.TryGetValue(name, out keyDefinition))
|
||||
return () => keyDefinition.Default;
|
||||
|
||||
// Not a mod-defined hotkey, so try and parse as a hardcoded definition
|
||||
// Try and parse as a hardcoded definition
|
||||
Hotkey key;
|
||||
if (!Hotkey.TryParse(name, out key))
|
||||
key = Hotkey.Invalid;
|
||||
@@ -49,11 +53,15 @@ namespace OpenRA
|
||||
|
||||
public void Set(string name, Hotkey value)
|
||||
{
|
||||
var field = settings.GetType().GetField(name + "Key");
|
||||
if (field == null)
|
||||
HotkeyDefinition definition;
|
||||
if (!definitions.TryGetValue(name, out definition))
|
||||
return;
|
||||
|
||||
field.SetValue(settings, value);
|
||||
keys[name] = value;
|
||||
if (value != definition.Default)
|
||||
settings[name] = value;
|
||||
else
|
||||
settings.Remove(name);
|
||||
}
|
||||
|
||||
public HotkeyReference this[string name]
|
||||
@@ -64,6 +72,6 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<HotkeyDefinition> Definitions { get { return keys.Values; } }
|
||||
public IEnumerable<HotkeyDefinition> Definitions { get { return definitions.Values; } }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user