Added python interface of texture component

This commit is contained in:
_ 2018-04-27 04:42:18 -07:00
parent e06d7dcd8f
commit be691baffb

View File

@ -240,17 +240,87 @@ devil1geo = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO")
class PLDHeader:
def __init__(self, filedata = None):
self.offsets = []
# self.offsets = []
# if filedata:
# h = PldHeader()
# devil1pld.getheader(ctypes.byref(h), filedata)
# self.offsets = h.offsets[:h.numOffset]
# self.offsets.append(len(filedata))
# Store C Struct in order to call C functions
self.cstruct = PldHeader()
if filedata:
h = PldHeader()
devil1pld.getheader(ctypes.byref(h), filedata)
self.offsets = h.offsets[:h.numOffset]
devil1pld.getheader(ctypes.byref(self.cstruct), filedata)
self.eof = len(filedata)
def __str__(self):
output = "numOffset: %s" % str(len(self.offsets))
for offset in self.offsets:
output += "\n\t" + str(hex(offset))
return output
# def __str__(self):
# output = "numOffset: %s" % str(len(self.offsets))
# for offset in self.offsets:
# output += "\n\t" + str(hex(offset))
# return output
def show(self):
devil1pld.printheader(ctypes.byref(self.cstruct))
return
def getnumoffsets(self):
return self.cstruct.numOffsets
# return pythonic list of offsets
def getoffsets(self):
return self.cstruct.offsets[:self.cstruct.numOffset]
def sizeofsector(self, i):
ptr = ctypes.byref(self.cstruct)
return devil1pld.sizeofsector(ptr, i, self.eof)
class TEXturePack:
def __init__(self, filedata):
self.cstruct = TexturePack()
self.th = ctypes.pointer(self.cstruct)
devil1tex.getheader(ctypes.byref(self.th), filedata)
devil1tex.printheader(self.th)
return
def show(self):
devil1tex.printheader(ctypes.byref(self.cstruct))
devil1tex.printheader(self.th)
def getbatchno(self):
return self.cstruct.batchNumber
def getfirstbatchoffset(self):
return self.cstruct.firstBatchOffset
class TEXtureBatchDescriptor:
def __init__(self, i, filedata):
self.cstruct = TextureBatchDescriptor()
ptrofptr = ctypes.byref(ctypes.byref(self.cstruct))
if filedata():
devil1tex.getbatchdesc(ptrofptr, i, filedata, len(filedata))
return
def show(self):
ptr = ctypes.byref(self.cstruct)
devil1tex.printbatchdesc(ptr)
def getbatchidx(self):
return self.cstruct.batchIdx
def gethash(self):
return self.cstruct.hash
def gettexno(self):
return self.cstruct.texNumber
def gettexturesize(self):
return self.cstruct.textureSize
class TEXtures:
def __init__(self, i, batchdescriptor, filedata):
self.cstruct = Texture()[batchdescriptor.gettexno()]
if filedata:
devil1tex.gettextures(self.cstruct, i, filedata, len(filedata))
return
#--------------------------------------+
# Regular Python
@ -312,9 +382,14 @@ if __name__ == "__main__":
with open("pl01.pld", "rb") as f:
data = f.read()
pld = PLDHeader(data)
print(pld)
pld.show()
pld2 = PLDHeader()
print(pld2)
pld2.show()
with open("pl01.pld_1.txp", "rb") as f:
data = f.read()
txp = TEXturePack(data)
txp.show()
#---------------------------------------+
# main()
mainx()