forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenum.py
More file actions
156 lines (134 loc) · 4.54 KB
/
Copy pathenum.py
File metadata and controls
156 lines (134 loc) · 4.54 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#found this in the cookbook: http://code.activestate.com/recipes/576415/
from ctypes import c_uint
class C_EnumerationType(type(c_uint)):
def __new__(metacls, name, bases, dictionary):
if not "_members_" in dictionary:
_members_ = {}
for key, value in dictionary.iteritems():
if not key.startswith("_"):
_members_[key] = value
dictionary["_members_"] = _members_
cls = type(c_uint).__new__(metacls, name, bases, dictionary)
for key, value in cls._members_.iteritems():
globals()[key] = value
return cls
def __contains__(self, value):
return value in self._members_.values()
def __repr__(self):
return "<Enumeration %s>" % self.__name__
class C_Enumeration(c_uint):
__metaclass__ = C_EnumerationType
_members_ = {}
def __init__(self, value):
for key, value in self._members_.iteritems():
if v == value:
self.name = key
break
else:
raise ValueError("No enumeration member with value %r" % value)
c_uint.__init__(self, value)
def __repr__(self):
return "<member %s=%d of %r>" % (self.name, self.value, self.__class__)
@classmethod
def from_param(cls, param):
if isinstance(param, C_Enumeration):
if param.__class__ != cls:
raise ValueError("Cannot mix enumeration members")
else:
return param
else:
return cls(param)
FeatureType = C_EnumerationType("FeatureType",
(c_uint,),
{"Other" : 0,
"Adamantine_Tube" : 1,
"Underworld" : 2,
"Hell_Temple" : 3})
BiomeOffset = C_EnumerationType("BiomeOffset",
(c_uint,),
{"NorthWest" : 0,
"North" : 1,
"NorthEast" : 2,
"West" : 3,
"Here" : 4,
"East" : 5,
"SouthWest" : 6,
"South" : 7,
"SouthEast" : 8,
"BiomeCount" : 9})
TrafficType = C_EnumerationType("TrafficType",
(c_uint,),
{"Normal" : 0,
"Low" : 1,
"High" : 2,
"Restricted" : 3})
DesignationType = C_EnumerationType("DesignationType",
(c_uint,),
{"No" : 0,
"Default" : 1,
"UD_Stair" : 2,
"Channel" : 3,
"Ramp" : 4,
"D_Stair" : 5,
"U_Stair" : 6,
"Whatever" : 7})
LiquidType = C_EnumerationType("LiquidType",
(c_uint,),
{"Water" : 0,
"Magma" : 1})
#this list must stay in the same order as the one in dfhack/library/include/dfhack/modules/WindowIO.h!
_keys = ["ENTER",
"SPACE",
"BACK_SPACE",
"TAB",
"CAPS_LOCK",
"LEFT_SHIFT",
"RIGHT_SHIFT",
"LEFT_CONTROL",
"RIGHT_CONTROL",
"ALT",
"WAIT",
"ESCAPE",
"UP",
"DOWN",
"LEFT",
"RIGHT",
"F1",
"F2",
"F3",
"F4",
"F5",
"F6",
"F7",
"F8",
"F9",
"F10",
"F11",
"F12",
"PAGE_UP",
"PAGE_DOWN",
"INSERT",
"DFK_DELETE",
"HOME",
"END",
"KEYPAD_DIVIDE",
"KEYPAD_MULTIPLY",
"KEYPAD_SUBTRACT",
"KEYPAD_ADD,"
"KEYPAD_ENTER",
"KEYPAD_0",
"KEYPAD_1",
"KEYPAD_2",
"KEYPAD_3",
"KEYPAD_4",
"KEYPAD_5",
"KEYPAD_6",
"KEYPAD_7",
"KEYPAD_8",
"KEYPAD_9",
"KEYPAD_DECIMAL_POINT",
"NUM_SPECIALS"]
_key_dict = dict([(k, i) for i, k in enumerate(_keys)])
KeyType = C_EnumerationType("KeyType",
(c_uint,),
_key_dict)