develop
Petr Mrázek 2011-03-06 23:57:22 +01:00
commit bbbea3d023
9 changed files with 269 additions and 125 deletions

@ -236,16 +236,6 @@ DFHackObject* Context_getProcess(DFHackObject* context)
return NULL;
}
DFHackObject* Context_getWindow(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getWindowIO();
}
return NULL;
}
DFHackObject* Context_getCreatures(DFHackObject* context)
{
if(context != NULL)
@ -346,6 +336,26 @@ DFHackObject* Context_getItems(DFHackObject* context)
return NULL;
}
DFHackObject* Context_getWorld(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getWorld();
}
return NULL;
}
DFHackObject* Context_getWindowIO(DFHackObject* context)
{
if(context != NULL)
{
return (DFHackObject*)((DFHack::Context*)context)->getWindowIO();
}
return NULL;
}
void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target)
{
if(context != NULL)

@ -133,7 +133,6 @@ DFHACK_EXPORT int Context_AsyncSuspend(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getMemoryInfo(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getProcess(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getWindow(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getCreatures(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getMaps(DFHackObject* context);
@ -145,6 +144,8 @@ DFHACK_EXPORT DFHackObject* Context_getVegetation(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getBuildings(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getConstructions(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getItems(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getWorld(DFHackObject* context);
DFHACK_EXPORT DFHackObject* Context_getWindowIO(DFHackObject* context);
//these are DANGEROUS...can crash/segfault DF, turn the seas to blood, call up the Antichrist, etc
DFHACK_EXPORT void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target);

@ -32,9 +32,9 @@ distribution.
extern "C" {
#endif
DFHACK_EXPORT int WindowIO_TypeStr(DFHackObject* window, const char* input, int delay, bool useShift);
DFHACK_EXPORT int WindowIO_TypeStr(DFHackObject* window, const char* input, uint32_t delay, int8_t useShift);
DFHACK_EXPORT int WindowIO_TypeSpecial(DFHackObject* window, t_special command, int count, int delay);
DFHACK_EXPORT int WindowIO_TypeSpecial(DFHackObject* window, t_special command, uint32_t count, uint32_t delay);
#ifdef __cplusplus
}

@ -233,6 +233,9 @@ t_matgloss* Materials_getInorganic(DFHackObject* mat)
if(materials->inorganic.size() > 0)
{
t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->inorganic.size()));
@ -258,6 +261,9 @@ t_matgloss* Materials_getOrganic(DFHackObject* mat)
{
t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->organic.size()));
if(buf != NULL)
@ -282,6 +288,9 @@ t_matgloss* Materials_getTree(DFHackObject* mat)
{
t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->tree.size()));
if(buf != NULL)
@ -306,6 +315,9 @@ t_matgloss* Materials_getPlant(DFHackObject* mat)
{
t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->plant.size()));
if(buf != NULL)
@ -330,6 +342,9 @@ t_matgloss* Materials_getRace(DFHackObject* mat)
{
t_matgloss* buf = NULL;
if(alloc_matgloss_buffer_callback == NULL)
return NULL;
((*alloc_matgloss_buffer_callback)(buf, materials->race.size()));
if(buf != NULL)
@ -356,6 +371,9 @@ c_creaturetype* Materials_getRaceEx(DFHackObject* mat)
{
c_creaturetype* buf = NULL;
if(alloc_creaturetype_buffer_callback == NULL)
return NULL;
((*alloc_creaturetype_buffer_callback)(buf, matSize));
if(buf != NULL)

@ -40,18 +40,23 @@ using namespace DFHack;
extern "C" {
#endif
int WindowIO_TypeStr(DFHackObject* window, const char* input, int delay, bool useShift)
int WindowIO_TypeStr(DFHackObject* window, const char* input, uint32_t delay, int8_t useShift)
{
if(window != NULL)
{
((DFHack::WindowIO*)window)->TypeStr(input, delay, useShift);
bool shifting = false;
if(useShift > 0)
shifting = true;
((DFHack::WindowIO*)window)->TypeStr(input, delay, shifting);
return 1;
}
return -1;
}
int WindowIO_TypeSpecial(DFHackObject* window, t_special command, int count, int delay)
int WindowIO_TypeSpecial(DFHackObject* window, t_special command, uint32_t count, uint32_t delay)
{
if(window != NULL)
{

@ -11,7 +11,6 @@ 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
@ -23,6 +22,8 @@ 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
libdfhack.Context_getWorld.restype = c_void_p
libdfhack.Context_getWindowIO.restype = c_void_p
class ContextManager(object):
def __init__(self, memory_path):
@ -67,6 +68,8 @@ class Context(object):
self._tran_obj = None
self._item_obj = None
self._creature_obj = None
self._world_obj = None
self._window_io_obj = None
def __del__(self):
libdfhack.Context_Free(self._c_ptr)
@ -167,4 +170,20 @@ class Context(object):
if self._tran_obj is None:
self._tran_obj = translation.Translation(libdfhack.Context_getTranslation(self._c_ptr))
return self._tran_obj
return self._tran_obj
@property
def world(self):
import world
if self._world_obj is None:
self._world_obj = world.World(libdfhack.Context_getWorld(self._c_ptr))
return self._world_obj
@property
def window_io(self):
import window_io
if self._window_io_obj is None:
self._window_io_obj = window_io.WindowIO(libdfhack.Context_getWindowIO(self._c_ptr))
return self._window_io_obj

@ -95,3 +95,62 @@ 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)

@ -2,17 +2,6 @@ from ctypes import *
from dftypes import libdfhack
from util import *
_get_arg_types = [ c_void_p, _arr_create_func ]
libdfhack.Materials_getInorganic.argtypes = _get_arg_types
libdfhack.Materials_getOrganic.argtypes = _get_arg_types
libdfhack.Materials_getTree.argtypes = _get_arg_types
libdfhack.Materials_getPlant.argtypes = _get_arg_types
libdfhack.Materials_getRace.argtypes = _get_arg_types
#libdfhack.Materials_getRaceEx.argtypes = _get_arg_types
libdfhack.Materials_getColor.argtypes = _get_arg_types
libdfhack.Materials_getOther.argtypes = _get_arg_types
class Materials(object):
def __init__(self, ptr):
self._mat_ptr = ptr
@ -25,117 +14,135 @@ class Materials(object):
self.race_ex = None
self.color = None
self.other = None
def _get_inorganic(self):
self.inorganic = libdfhack.Materials_getInorganic(self._mat_ptr)
def _get_organic(self):
self.organic = libdfhack.Materials_getOrganic(self._mat_ptr)
def _get_tree(self):
self.tree = libdfhack.Materials_getTree(self._mat_ptr)
def _get_plant(self):
self.plant = libdfhack.Materials_getPlant(self._mat_ptr)
def _get_race(self):
self.race = libdfhack.Materials_getRace(self._mat_ptr)
def _get_race_ex(self):
self.race_ex = libdfhack.Materials_getRaceEx(self._mat_ptr)
def _get_color(self):
self.color = libdfhack.Materials_getColor(self._mat_ptr)
def _get_other(self):
self.other = libdfhack.Materials_getOther(self._mat_ptr)
def _get_all(self):
self._get_inorganic()
self._get_organic()
self._get_tree()
self._get_plant()
self._get_race()
self._get_race_ex()
self._get_color()
self._get_other()
def _clear_all(self):
self.inorganic = None
self.organic = None
self.tree = None
self.plant = None
self.race = None
self.race_ex = None
self.color = None
self.other = None
def read_inorganic(self):
return libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr)
result = libdfhack.Materials_ReadInorganicMaterials(self._mat_ptr) > 0
if result == True:
self._get_inorganic()
else:
self.inorganic = None
return result
def read_organic(self):
return libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr)
def read_wood(self):
return libdfhack.Materials_ReadWoodMaterials(self._mat_ptr)
result = libdfhack.Materials_ReadOrganicMaterials(self._mat_ptr) > 0
if result == True:
self._get_organic()
else:
self.organic = None
return result
def read_tree(self):
result = libdfhack.Materials_ReadWoodMaterials(self._mat_ptr) > 0
if result == True:
self._get_tree()
else:
self.tree = None
return result
def read_plant(self):
return libdfhack.Materials_ReadPlantMaterials(self._mat_ptr)
result = libdfhack.Materials_ReadPlantMaterials(self._mat_ptr) > 0
if result == True:
self._get_plant()
else:
self.plant = None
return result
def read_creature_types(self):
return libdfhack.Materials_ReadCreatureTypes(self._mat_ptr)
result = libdfhack.Materials_ReadCreatureTypes(self._mat_ptr) > 0
if result == True:
self._get_race()
else:
self.race = None
return result
def read_creature_types_ex(self):
return libdfhack.Materials_ReadCreatureTypesEx(self._mat_ptr)
result = libdfhack.Materials_ReadCreatureTypesEx(self._mat_ptr) > 0
if result == True:
self._get_race_ex()
else:
self.race_ex = None
return result
def read_descriptor_colors(self):
return libdfhack.Materials_ReadDescriptorColors(self._mat_ptr)
result = libdfhack.Materials_ReadDescriptorColors(self._mat_ptr) > 0
if result == True:
self._get_color()
else:
self.color = None
return result
def read_others(self):
return libdfhack.Materials_ReadOthers(self._mat_ptr)
result = libdfhack.Materials_ReadOthers(self._mat_ptr) > 0
if result == True:
self._get_other()
else:
self.other = None
return result
def read_all(self):
libdfhack.Materials_ReadAllMaterials(self._mat_ptr)
result = libdfhack.Materials_ReadAllMaterials(self._mat_ptr) > 0
if result == True:
self._get_all()
else:
self._clear_all()
return result
def get_type(self, material):
return libdfhack.Materials_getType(self._mat_ptr, byref(material))
def get_description(self, material):
return libdfhack.Materials_getDescription(self._mat_ptr, byref(material))
def update_inorganic_cache(self):
def update_callback(count):
allocated = _allocate_array(Matgloss, count)
self.inorganic = allocated[0]
return allocated[1]
callback = _arr_create_func(update_callback)
return libdfhack.Materials_getInorganic(self._mat_ptr, callback)
def update_organic_cache(self):
def update_callback(count):
allocated = _allocate_array(Matgloss, count)
self.organic = allocated[0]
return allocated[1]
callback = _arr_create_func(update_callback)
return libdfhack.Materials_getOrganic(self._mat_ptr, callback)
def update_tree_cache(self):
def update_callback(count):
allocated = _allocate_array(Matgloss, count)
self.tree = allocated[0]
return allocated[1]
callback = _arr_create_func(update_callback)
return libdfhack.Materials_getTree(self._mat_ptr, callback)
def update_plant_cache(self):
def update_callback(count):
allocated = _allocate_array(Matgloss, count)
self.plant = allocated[0]
return allocated[1]
callback = _arr_create_func(update_callback)
return libdfhack.Materials_getPlant(self._mat_ptr, callback)
def update_race_cache(self):
def update_callback(count):
allocated = _allocate_array(Matgloss, count)
self.race = allocated[0]
return allocated[1]
callback = _arr_create_func(update_callback)
return libdfhack.Materials_getRace(self._mat_ptr, callback)
def update_color_cache(self):
def update_callback(count):
allocated = _allocate_array(DescriptorColor, count)
self.color = allocated[0]
return allocated[1]
callback = _arr_create_func(update_callback)
return libdfhack.Materials_getColor(self._mat_ptr, callback)
def update_other_cache(self):
def update_callback(count):
allocated = _allocate_array(MatglossOther, count)
self.other = allocated[0]
return allocated[1]
callback = _arr_create_func(update_callback)
return libdfhack.Materials_getOther(self._mat_ptr, callback)
return libdfhack.Materials_getDescription(self._mat_ptr, byref(material))

@ -0,0 +1,25 @@
from ctypes import *
libdfhack.WindowIO_TypeStr.argtypes = [ c_void_p, c_char_p, c_uint, c_byte ]
libdfhack.WindowIO_TypeSpecial.argtypes = [ c_void_p, c_uint, c_uint, c_uint, c_uint ]
class WindowIO(object):
def __init__(self, ptr):
self._window_io_ptr = ptr
def type_str(self, s, delay = 0, use_shift = False):
c_shift = c_byte(0)
c_delay = c_int(delay)
c_s = c_char_p(s)
if use_shift is True:
c_shift = c_byte(1)
return libdfhack.WindowIO_TypeStr(self._window_io_ptr, c_s, c_delay, c_shift) > 0
def type_special(self, command, count = 1, delay = 0):
c_command = c_uint(command)
c_count = c_uint(count)
c_delay = c_uint(delay)
return libdfhack.WindwIO_TypeSpecial(self._window_io_ptr, c_command, c_count, c_delay) > 0