forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.py
More file actions
170 lines (128 loc) · 4.73 KB
/
Copy pathcontext.py
File metadata and controls
170 lines (128 loc) · 4.73 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from ctypes import *
from dftypes import *
libdfhack.ContextManager_Alloc.restype = c_void_p
libdfhack.ContextManager_Free.argtypes = [ c_void_p ]
libdfhack.ContextManager_getContext.restype = c_void_p
libdfhack.ContextManager_getSingleContext.restype = c_void_p
libdfhack.Context_Free.argtypes = [ c_void_p ]
libdfhack.Context_getMemoryInfo.restype = c_void_p
libdfhack.Context_getProcess.restype = c_void_p
libdfhack.Context_getWindow.restype = c_void_p
libdfhack.Context_getCreatures.restype = c_void_p
libdfhack.Context_getMaps.restype = c_void_p
libdfhack.Context_getGui.restype = c_void_p
libdfhack.Context_getPosition.restype = c_void_p
libdfhack.Context_getMaterials.restype = c_void_p
libdfhack.Context_getTranslation.restype = c_void_p
libdfhack.Context_getVegetation.restype = c_void_p
libdfhack.Context_getBuildings.restype = c_void_p
libdfhack.Context_getConstructions.restype = c_void_p
libdfhack.Context_getItems.restype = c_void_p
class ContextManager(object):
def __init__(self, memory_path):
self._cm_ptr = libdfhack.ContextManager_Alloc(create_string_buffer(memory_path))
def __del__(self):
libdfhack.ContextManager_Free(self._cm_ptr)
def refresh(self):
return libdfhack.ContextManager_Refresh(self._cm_ptr) > 0
def purge(self):
libdfhack.ContextManager_purge(self._cm_ptr)
def get_context(self, index):
p = libdfhack.ContextManager_getContext(self._cm_ptr, index)
if p:
return Context(p)
else:
return None
def get_single_context(self):
p = libdfhack.ContextManager_getSingleContext(self._cm_ptr)
if p:
return Context(p)
else:
return None
class Context(object):
def __init__(self, ptr):
self._c_ptr = ptr
self._pos_obj = None
self._mat_obj = None
self._map_obj = None
self._veg_obj = None
self._build_obj = None
self._con_obj = None
self._gui_obj = None
self._tran_obj = None
self._item_obj = None
self._creature_obj = None
def __del__(self):
libdfhack.Context_Free(self._c_ptr)
def attach(self):
return libdfhack.Context_Attach(self._c_ptr) > 0
def detach(self):
return libdfhack.Context_Detach(self._c_ptr) > 0
def suspend(self):
return libdfhack.Context_Suspend(self._c_ptr) > 0
def resume(self):
return libdfhack.Context_Resume(self._c_ptr) > 0
def force_resume(self):
return libdfhack.Context_ForceResume(self._c_ptr) > 0
def async_suspend(self):
return libdfhack.Context_AsyncSuspend(self._c_ptr) > 0
@property
def is_attached(self):
return libdfhack.Context_isAttached(self._c_ptr) > 0
@property
def is_suspended(self):
return libdfhack.Context_isSuspended(self._c_ptr) > 0
@property
def position(self):
import position
if self._pos_obj is None:
self._pos_obj = position.Position(libdfhack.Context_getPosition(self._c_ptr))
return self._pos_obj
@property
def materials(self):
import materials
if self._mat_obj is None:
self._mat_obj = materials.Materials(libdfhack.Context_getMaterials(self._c_ptr))
return self._mat_obj
@property
def maps(self):
import maps
if self._map_obj is None:
self._map_obj = maps.Maps(libdfhack.Context_getMaps(self._c_ptr))
return self._map_obj
@property
def vegetation(self):
import vegetation
if self._veg_obj is None:
self._veg_obj = vegetation.Vegetation(libdfhack.Context_getVegetation(self._c_ptr))
return self._veg_obj
@property
def buildings(self):
import buildings
if self._build_obj is None:
self._build_obj = buildings.Buildings(libdfhack.Context_getBuildings(self._c_ptr))
return self._build_obj
@property
def creatures(self):
import creatures
if self._creature_obj is None:
self._creature_obj = creatures.Creatures(libdfhack.Context_getCreatures(self._c_ptr))
return self._creature_obj
@property
def gui(self):
import gui
if self._gui_obj is None:
self._gui_obj = gui.Gui(libdfhack.Context_getGui(self._c_ptr))
return self._gui_obj
@property
def items(self):
import items
if self._item_obj is None:
self._item_obj = items.Items(libdfhack.Context_getItems(self._c_ptr))
return self._item_obj
@property
def translation(self):
import translation
if self._tran_obj is None:
self._tran_obj = translation.Translation(libdfhack.Context_getTranslation(self._c_ptr))
return self._tran_obj