/
InputControl.cs
67 lines (55 loc) · 1.82 KB
/
InputControl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARDrone.Input.Utility;
namespace ARDrone.Input.InputControls
{
public abstract class InputControl
{
public enum ControlType { BooleanValue, ContinuousValue }
protected Dictionary<String, ControlType> controlTypeMap = new Dictionary<String, ControlType>();
protected Dictionary<String, String> mappings;
protected InputControl()
{
mappings = new Dictionary<String, String>();
}
protected InputControl(Dictionary<String, String> mappings)
{
Dictionary<String, String> copiedButtonMappings = new Dictionary<String, String>(mappings);
this.mappings = copiedButtonMappings;
}
public void SetProperty(String name, String value)
{
CheckPropertyName(name);
mappings[name] = value;
}
public String GetProperty(String name)
{
CheckPropertyName(name);
if (mappings.ContainsKey(name))
return mappings[name];
return null;
}
private void CheckPropertyName(String name)
{
if (!controlTypeMap.ContainsKey(name))
throw new Exception("The control named '" + name + "' is not within the control type map");
}
public bool IsContinuousMapping(String name)
{
return controlTypeMap[name] == ControlType.ContinuousValue;
}
public bool IsBooleanMapping(String name)
{
return controlTypeMap[name] == ControlType.BooleanValue;
}
public Dictionary<String, String> Mappings
{
get
{
return new Dictionary<String, String>(mappings);
}
}
}
}