updated to actually match the C stuff (not passing allocator callbacks every time, etc)

develop
doomchild 2011-03-03 14:19:20 -06:00
parent d314c733b2
commit c98bc9da9d
1 changed files with 114 additions and 107 deletions

@ -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))