32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using SlatedGameToolkit.Tools.System.Interaction;
|
||
|
|
||
|
namespace SlatedGameToolkit.Tools.System
|
||
|
{
|
||
|
public class CommandMap {
|
||
|
Dictionary<string, IInvocable> invocations;
|
||
|
public IInvocable this[string invocation] {
|
||
|
get {
|
||
|
IInvocable result = null;
|
||
|
invocations.TryGetValue(invocation, out result);
|
||
|
return result;
|
||
|
}
|
||
|
}
|
||
|
public CommandMap(params IInvocable[] invokables) {
|
||
|
invocations = new Dictionary<string, IInvocable>();
|
||
|
foreach (IInvocable item in invokables)
|
||
|
{
|
||
|
string[] invokers = item.GetInvokers();
|
||
|
foreach (string invoker in invokers)
|
||
|
{
|
||
|
try {
|
||
|
invocations.Add(invoker, item);
|
||
|
} catch (ArgumentException e) {
|
||
|
throw new ArgumentException("A duplicate invocation string was found!", e);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|