diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/exporter.py | 7 | ||||
-rw-r--r-- | src/main.py | 1 | ||||
-rw-r--r-- | src/tileset.py | 40 |
3 files changed, 26 insertions, 22 deletions
diff --git a/src/exporter.py b/src/exporter.py index 0ddc98a..ed377c3 100644 --- a/src/exporter.py +++ b/src/exporter.py @@ -82,6 +82,9 @@ class KPMapExporter: for i in xrange(sectorBottom - sectorTop + 1): rawSectors.append([None for j in xrange(sectorRight - sectorLeft + 1)]) + tileset = KP.tileset(layer.tileset) + optMappings = tileset.optMappings + # copy every tile index over for srcY in xrange(layerHeight): srcRow = cache[srcY] @@ -98,6 +101,8 @@ class KPMapExporter: tile = srcRow[srcX] if tile == -1: continue + tile = optMappings[tile] + if tile == -1: continue destSector = destRow[sectorX - sectorLeft] if destSector is None: @@ -398,7 +403,7 @@ class KPMapExporter: struct.pack_into('>ii', data, 8, len(tilesets), len(data)) for setname in tilesets: offsets[('tileset', setname)] = len(data) - data += self._buildGXTexObjRGB5A3(1024, 512, offsets[setname]) + data += self._buildGXTexObjRGB5A3(896, 448, offsets[setname]) for tex in textures: offsets[tex] = len(data) diff --git a/src/main.py b/src/main.py index 8d8d494..f417d94 100644 --- a/src/main.py +++ b/src/main.py @@ -76,6 +76,7 @@ class KP: tsInfo['hash'] = newHash from tileset import KPTileset + print "Loading set: %s" % name cls.loadedTilesets[name] = KPTileset.loadFromArc(data) diff --git a/src/tileset.py b/src/tileset.py index ab77223..cc36d18 100644 --- a/src/tileset.py +++ b/src/tileset.py @@ -341,22 +341,18 @@ class KPTileset(object): def loadFromArc(cls, handleOrPath): arc = WiiArchiveU8(handleOrPath) - img = arc.resolvePath('/BG_tex').children[0].data - grp = arc.resolvePath('/BG_grp').children[0].data + img = arc.resolvePath('/texture.bin').data + grp = arc.resolvePath('/groups.bin').data - untDir = arc.resolvePath('/BG_unt') - obj, meta = None, None + obj = arc.resolvePath('/objects.bin').data + meta = arc.resolvePath('/objectsMeta.bin').data - for child in untDir.children: - if child.name.endswith('_hd.bin'): - meta = child.data - else: - obj = child.data + tmaps = arc.resolvePath('/optimisedTileMappings.txt').data - return cls(img, obj, meta, grp) + return cls(img, obj, meta, grp, tmaps) - def __init__(self, imageBuffer, objectBuffer, objectMetadata, groupBuffer): + def __init__(self, imageBuffer, objectBuffer, objectMetadata, groupBuffer, optMapBuffer): '''A Koopatlas Tileset class. To initialize, pass it image data, object data, and group data as read from a Koopatlas tileset file. @@ -402,6 +398,8 @@ class KPTileset(object): self.groupItem.calculateIndices(0) self.groupModel = KPGroupModel(self.groupItem) + self.optMappings = map(int, optMapBuffer.split(',')) + def processImage(self, imageBuffer): '''Takes an imageBuffer from a Koopatlas Tileset and converts it into 24x24 @@ -412,14 +410,14 @@ class KPTileset(object): self.tileImage = QtGui.QPixmap.fromImage(dest) # Makes us some nice Tiles! - Xoffset = 4 - Yoffset = 4 + Xoffset = 2 + Yoffset = 2 for i in range(512): self.tiles.append(self.tileImage.copy(Xoffset,Yoffset,24,24)) - Xoffset += 32 - if Xoffset >= 1024: - Xoffset = 4 - Yoffset += 32 + Xoffset += 28 + if Xoffset >= 896: + Xoffset = 2 + Yoffset += 28 @@ -428,8 +426,8 @@ class KPTileset(object): import time b = time.clock() - out = bytearray(1024*512*4) - dest = QtGui.QImage(1024,512,QtGui.QImage.Format_ARGB32) + out = bytearray(896*448*4) + dest = QtGui.QImage(896,448,QtGui.QImage.Format_ARGB32) dest.fill(Qt.transparent) # Some fairly ugly code, in an attempt to make it run faster @@ -440,8 +438,8 @@ class KPTileset(object): i = 0 - xtile_range = _xrange(0, 1024, 4) - ytile_range = _xrange(0, 512, 4) + xtile_range = _xrange(0, 896, 4) + ytile_range = _xrange(0, 448, 4) for ytile in ytile_range: ypixel_range = _xrange(ytile, ytile + 4) |