Added subclasses for all exported classes, and linked them to API

develop
RusAnon 2010-05-03 17:13:35 +11:00
parent 1d2f085ef3
commit 3ccb7783c9
11 changed files with 257 additions and 13 deletions

@ -11,6 +11,12 @@ class Point(object):
def get_block(self):
return Point(self.x/16, self.y/16, self.z, True)
def __repr__(self):
b = ''
if self.block:
b = ', Block'
return "<Point({0.x}, {0.y}, {0.z}{1})>".format(self, b)
class Block(object):
"""

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
Python class for DF_Hack::Construction
"""
from ._pydfhack import _ConstructionManager
class Construction(_ConstructionManager):
api = None
started = False
def __init__(self, api, *args, **kwds):
_ConstructionManager.__init__(self, args, kwds)
self.api = api
def prepare(self):
"""
Enforce Suspend/Start
"""
if self.api.prepare():
if not self.started:
self.started = self.Start()
return self.started
else:
return False

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
Python class for DF_Hack::Creature
"""
from ._pydfhack import _CreatureManager
class Creature(_CreatureManager):
api = None
started = False
def __init__(self, api, *args, **kwds):
_CreatureManager.__init__(self, args, kwds)
self.api = api
def prepare(self):
"""
Enforce Suspend/Start
"""
if self.api.prepare():
if not self.started:
self.started = self.Start()
return self.started
else:
return False

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
Python class for DF_Hack::GUI
"""
from ._pydfhack import _GUIManager
class GUI(_GUIManager):
api = None
started = False
def __init__(self, api, *args, **kwds):
_GUIManager.__init__(self, args, kwds)
self.api = api
def prepare(self):
"""
Enforce Suspend/Start
"""
if self.api.prepare():
if not self.started:
self.started = self.Start()
return self.started
else:
return False

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
Python class for DF_Hack::Maps
"""
from ._pydfhack import _MapManager
class Map(_MapManager):
api = None
started = False
def __init__(self, api, *args, **kwds):
_MapManager.__init__(self, args, kwds)
self.api = api
def prepare(self):
"""
Enforce Suspend/Start
"""
if self.api.prepare():
if not self.started:
self.started = self.Start()
return self.started
else:
return False

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
Python class for DF_Hack::Materials
"""
from ._pydfhack import _MaterialsManager
class Materials(_MaterialsManager):
api = None
started = False
def __init__(self, api, *args, **kwds):
_MaterialsManager.__init__(self, args, kwds)
self.api = api
def prepare(self):
"""
Enforce Suspend/Start
"""
if self.api.prepare():
if not self.started:
self.started = self.Start()
return self.started
else:
return False

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
Python class for DF_Hack::MemInfo
"""
from ._pydfhack import _MemInfo
class MemInfo(_MemInfo):
api = None
started = False
def __init__(self, api, *args, **kwds):
_MemInfo.__init__(self, args, kwds)
self.api = api
def prepare(self):
"""
Enforce Suspend/Start
"""
if self.api.prepare():
if not self.started:
self.started = self.Start()
return self.started
else:
return False

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
"""
Python class for DF_Hack::Position
"""
from ._pydfhack import _PositionManager
from .blocks import Point, Block
class Position(_PositionManager):
api = None
def __init__(self, api, *args, **kwds):
_PositionManager.__init__(self, args, kwds)
self.api = api
def prepare(self):
"""
Enforce Suspend/Start
"""
return self.api.prepare()
def get_cursor(self):
self.prepare()
coords = self.cursor_coords
return Point(*coords)

@ -1,4 +1,14 @@
import _pydfhack, os
from .blocks import Point, Block
from .meminfo import MemInfo
from .position import Position
from .materials import Materials
from .creature import Creature
from .map import Map
from .translation import Translation
from .construction import Construction
from .vegetation import Vegetation
from .gui import GUI
class API(_pydfhack._API):
for file in ["Memory.xml", os.path.join("..","..","output","Memory.xml")]:
if os.path.isfile(file):
@ -7,21 +17,26 @@ class API(_pydfhack._API):
else:
raise ImportError, "Memory.xml not found."
def prepare(self):
"""
Enforce Attach/Suspend behavior.
Return True if succeeded, else False
"""
r = True
if not self.is_attached:
r = self.Attach()
if r and not self.is_suspended:
r = self.Suspend()
return r
def __init__(self, *args, **kwds):
_pydfhack._API.__init__(self, API.datafile)
self._mem_info_mgr_type = MemInfo
self._position_mgr_type = Position
self._material_mgr_type = Materials
self._creature_mgr_type = Creature
self._map_mgr_type = Map
self._translate_mgr_type = Translation
self._construction_mgr_type = Construction
self._vegetation_mgr_type = Vegetation
self._gui_mgr_type = GUI
class Map(_pydfhack._MapManager):
def __init__(self, *args, **kwds):
_pydfhack._MapManager.__init__(self, args, kwds)
class Vegetation(_pydfhack._VegetationManager):
def __init__(self, *args, **kwds):
_pydfhack._VegetationManager.__init__(self, args, kwds)
class GUI(_pydfhack._GUIManager):
def __init__(self, *args, **kwds):
_pydfhack._GUIManager.__init__(self, args, kwds)

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
Python class for DF_Hack::Translation
"""
from ._pydfhack import _TranslationManager
class Translation(_TranslationManager):
api = None
started = False
def __init__(self, api, *args, **kwds):
_TranslationManager.__init__(self, args, kwds)
self.api = api
def prepare(self):
"""
Enforce Suspend/Start
"""
if self.api.prepare():
if not self.started:
self.started = self.Start()
return self.started
else:
return False

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
"""
Python class for DF_Hack::Vegetation
"""
from ._pydfhack import _VegetationManager
class Vegetation(_VegetationManager):
api = None
started = False
def __init__(self, api, *args, **kwds):
_VegetationManager.__init__(self, args, kwds)
self.api = api
def prepare(self):
"""
Enforce Suspend/Start
"""
if self.api.prepare():
if not self.started:
self.started = self.Start()
return self.started
else:
return False