From 258ea63e0629df5a398fe540059c4d1f6105bf08 Mon Sep 17 00:00:00 2001 From: Treeki Date: Tue, 8 Nov 2011 23:33:31 +0100 Subject: made the thing run and added some quick and dirty testing code --- src/tileset.py | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) (limited to 'src/tileset.py') diff --git a/src/tileset.py b/src/tileset.py index 609fa1a..857a805 100644 --- a/src/tileset.py +++ b/src/tileset.py @@ -1,4 +1,6 @@ from common import * +import struct +import cPickle @@ -195,22 +197,22 @@ class KPGroupModel(QtCore.QAbstractListModel): item = self.container.getItem(n) if role == QtCore.Qt.DecorationRole: - if isInstance(item, KPTileObject): + if isinstance(item, KPTileObject): return item.icon if role == QtCore.Qt.BackgroundRole: return QtGui.qApp.palette().base() if role == QtCore.Qt.UserRole: - if isInstance(item, KPTileObject): + if isinstance(item, KPTileObject): return item.itemsize if role == QtCore.Qt.DisplayRole: - if isInstance(item, KPGroupItem): + if isinstance(item, KPGroupItem): return item.name if role == QtCore.Qt.TextAlignmentRole: - if isInstance(item, KPGroupItem): + if isinstance(item, KPGroupItem): return item.alignment @@ -239,13 +241,13 @@ class KPGroupItem(object): objCount += len(self.objects) objCount += len(self.groups) - for group in groups: + for group in self.groups: objCount += group.objectCount() return objCount - def getItem(index): + def getItem(self, index): ''' Retrieves an item of a specific index. The index is already checked for validity ''' if index == self.startIndex: @@ -313,7 +315,7 @@ class KPTileset(object): '''Takes an imageBuffer from a Koopatlas Tileset and converts it into 24x24 tiles, which get put into KPTileset.tiles.''' - dest = self.RGB4A3Decode(Image) + dest = self.RGB4A3Decode(imageBuffer) self.tileImage = QtGui.QPixmap.fromImage(dest) @@ -325,11 +327,12 @@ class KPTileset(object): Xoffset += 32 if Xoffset >= 1024: Xoffset = 4 - Yoffset += 32 + Yoffset += 32 - def RGB4A3Decode (tex): + @staticmethod + def RGB4A3Decode(tex): dest = QtGui.QImage(1024,512,QtGui.QImage.Format_ARGB32) dest.fill(QtCore.Qt.transparent) @@ -399,7 +402,7 @@ class KPTileset(object): tilelist.append(rowlist) rowlist = [] - painter.end() + painter.end() self.objects.append(KPTileObject(tilelist, entry[2], entry[1], entry[3], tex)) @@ -411,7 +414,7 @@ class KPTileset(object): def processGroup(self, groupBuffer): - grovyle = cPickle.loads(group) + grovyle = cPickle.loads(groupBuffer) self.makeTree(grovyle, self.groupItem) @@ -426,7 +429,7 @@ class KPTileset(object): if (type(razorLeaf) is str) and (razorLeaf[:6] == "Object"): objnum = int(razorLeaf[7:]) - obj = self.objects(objnum) + obj = self.objects[objnum] treecko.objects.append(obj) @@ -437,11 +440,11 @@ class KPTileset(object): makeTree(razorLeaf[1], a) - treecko.endIndex = treecko.startIndex + treecko.objCount() + treecko.endIndex = treecko.startIndex + treecko.objectCount() - def getTile(index): + def getTile(self, index): '''Takes a tile index and returns a tile image as a QPixmap, or -1 if failed.''' if index > 511: @@ -453,7 +456,7 @@ class KPTileset(object): return self.tiles[index] - def getObject(index): + def getObject(self, index): '''Takes an object index and returns a KPTileObject, or false if failed.''' if index < 0: @@ -462,14 +465,14 @@ class KPTileset(object): return self.tiles[index] - def getObjectIcon(index): + def getObjectIcon(self, index): '''Takes an object index or a KPTileObject and returns a QPixmap for the object, or false if failed.''' - if isInstance(index, KPTileObject): + if isinstance(index, KPTileObject): return index.icon - if isInstance(index, int): + if isinstance(index, int): try: return self.objects[index].icon except: @@ -478,14 +481,14 @@ class KPTileset(object): return false - def getObjectRender(index, size): + def getObjectRender(self, index, size): '''Takes an object index or a KPTileObject and returns a render map for the object, or false if failed.''' - if isInstance(index, KPTileObject): + if isinstance(index, KPTileObject): return index.render(size) - if isInstance(index, int): + if isinstance(index, int): try: return self.objects[index].render(size) except: @@ -494,14 +497,14 @@ class KPTileset(object): return false - def getMode(): + def getModel(self): '''Returns the Group Model''' return self.groupModel - def overrideTile(index, pixmap): + def overrideTile(self, index, pixmap): '''Takes a 24x24 QPixmap and a tile index, and returns true if it succeeds.''' if index > 511: @@ -510,7 +513,7 @@ class KPTileset(object): if index < 0: return false - if not isInstance(pixmap, QtGui.QPixmap): + if not isinstance(pixmap, QtGui.QPixmap): return false if (QtGui.QPixmap.height() != 24) or (QtGui.QPixmap.width() != 24): -- cgit v1.2.3