summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Noga <Tempus@Spectrum-Song.local>2011-11-08 01:14:04 -0600
committerColin Noga <Tempus@Spectrum-Song.local>2011-11-08 01:14:04 -0600
commitf54d177364dbfacce45ec6768462bc81e837a274 (patch)
treed62b847ca631b77812dbd063ac54a27008e7dd01
parent29276f779022e3ea2d7a645f87cedf16ca8a8c7e (diff)
downloadkoopatlas-f54d177364dbfacce45ec6768462bc81e837a274.tar.gz
koopatlas-f54d177364dbfacce45ec6768462bc81e837a274.zip
Fleshed out tileset.py
Diffstat (limited to '')
-rwxr-xr-xKoopuzzle/Koopuzzle.py524
-rwxr-xr-xKoopuzzle/windows_build.py18
2 files changed, 70 insertions, 472 deletions
diff --git a/Koopuzzle/Koopuzzle.py b/Koopuzzle/Koopuzzle.py
index 4962e5c..510e5e0 100755
--- a/Koopuzzle/Koopuzzle.py
+++ b/Koopuzzle/Koopuzzle.py
@@ -41,16 +41,27 @@ class TilesetClass():
class Object():
- def __init__(self, height, width, uslope, lslope, tilelist):
+ def __init__(self, tilelist, height, width, wrapmode):
'''Tile Constructor'''
self.height = height
self.width = width
- self.upperslope = uslope
- self.lowerslope = lslope
-
self.tiles = tilelist
+
+ self.wrap = wrapmode
+
+ # --- Wrapmodes ---
+ # 'Repeat'
+ # 'Stretch Center'
+ # 'Stretch X'
+ # 'Stretch Y'
+ # 'Repeat Bottom'
+ # 'Repeat Top'
+ # 'Repeat Left'
+ # 'Repeat Right'
+ # 'Upward slope' (LL to UR)
+ # 'Downward slope' (UL to LR)
def __init__(self):
@@ -68,17 +79,16 @@ class TilesetClass():
self.tiles.append(self.Tile(image))
- def addObject(self, height = 1, width = 1, uslope = [0, 0], lslope = [0, 0], tilelist = [[(0, 0xFFFF, 0)]]):
+ def addObject(self, tilelist = [[0xFFFF]], height = 1, width = 1, wrapmode = 0):
'''Adds a new object'''
global Tileset
-
# Initialize trusim power! This is required to work, due to python's single default parameter initialization
- if tilelist == [[(0, 0xFFFF, 0)]]:
- tilelist = [[(0, 0xFFFF, 0)]]
+ if tilelist == [[0xFFFF]]:
+ tilelist = [[0xFFFF]]
- self.objects.append(self.Object(height, width, uslope, lslope, tilelist))
+ self.objects.append(self.Object(tilelist, height, width, wrapmode))
def removeObject(self, index):
@@ -136,8 +146,8 @@ def SetupObjectModel(self, objects, tiles, treecko, group):
for i in range(len(object.tiles)):
for tile in object.tiles[i]:
- if (tile[1] != 0xFFFF):
- painter.drawPixmap(Xoffset, Yoffset, tiles[tile[1]].image)
+ if (tile != 0xFFFF):
+ painter.drawPixmap(Xoffset, Yoffset, tiles[tile].image)
Xoffset += 24
Xoffset = 0
Yoffset += 24
@@ -208,8 +218,8 @@ class displayWidget(QtGui.QListView):
def __init__(self, parent=None):
super(displayWidget, self).__init__(parent)
- self.setMinimumWidth(818)
- self.setMaximumWidth(818)
+ self.setMinimumWidth(828)
+ self.setMaximumWidth(828)
self.setMinimumHeight(404)
self.setMaximumHeight(404)
self.setDragEnabled(True)
@@ -293,9 +303,7 @@ class tileOverlord(QtGui.QWidget):
'Repeat Left',
'Repeat Right',
'Upward slope',
- 'Downward slope',
- 'Downward reverse slope',
- 'Upward reverse slope'])
+ 'Downward slope'])
# Connections
@@ -386,65 +394,11 @@ class tileOverlord(QtGui.QWidget):
def setObject(self, index):
global Tileset
object = Tileset.objects[index.row()]
-
- width = len(object.tiles[0])-1
- height = len(object.tiles)-1
- Xuniform = True
- Yuniform = True
- Xstretch = False
- Ystretch = False
-
- for tile in object.tiles[0]:
- if tile[0] != object.tiles[0][0][1]:
- Xuniform = False
-
- for tile in object.tiles:
- if tile[0][0] != object.tiles[0][0][1]:
- Yuniform = False
-
- if object.tiles[0][0][1] == object.tiles[0][width][0] and Xuniform == False:
- Xstretch = True
-
- if object.tiles[0][0][1] == object.tiles[height][0][0] and Xuniform == False:
- Ystretch = True
-
-
-
- if object.upperslope[0] != 0:
- if object.upperslope[0] == 0x90:
- self.tilingMethod.setCurrentIndex(8)
- elif object.upperslope[0] == 0x91:
- self.tilingMethod.setCurrentIndex(9)
- elif object.upperslope[0] == 0x92:
- self.tilingMethod.setCurrentIndex(10)
- elif object.upperslope[0] == 0x93:
- self.tilingMethod.setCurrentIndex(11)
-
- else:
- if Xuniform and Yuniform:
- self.tilingMethod.setCurrentIndex(0)
- elif Xstretch and Ystretch:
- self.tilingMethod.setCurrentIndex(1)
- elif Xstretch:
- self.tilingMethod.setCurrentIndex(2)
- elif Ystretch:
- self.tilingMethod.setCurrentIndex(3)
- elif Xuniform and Yuniform == False and object.tiles[0][0][0] == 0:
- self.tilingMethod.setCurrentIndex(4)
- elif Xuniform and Yuniform == False and object.tiles[height][0][0] == 0:
- self.tilingMethod.setCurrentIndex(5)
- elif Xuniform == False and Yuniform and object.tiles[0][0][0] == 0:
- self.tilingMethod.setCurrentIndex(6)
- elif Xuniform == False and Yuniform and object.tiles[0][width][0] == 0:
- self.tilingMethod.setCurrentIndex(7)
-
+
+ self.tilingMethod.setCurrentIndex(object.wrap)
self.tiles.setObject(object)
- # print 'Object {0}, Width: {1} / Height: {2}, Slope {3}/{4}'.format(index.row(), object.width, object.height, object.upperslope, object.lowerslope)
- # for row in object.tiles:
- # print 'Row: {0}'.format(row)
- # print ''
@QtCore.pyqtSlot(int)
def setTiling(self, listindex):
@@ -453,257 +407,9 @@ class tileOverlord(QtGui.QWidget):
index = window.objectList.currentIndex()
object = Tileset.objects[index.row()]
-
- if listindex == 0: # Repeat
- ctile = 0
- crow = 0
-
- for row in object.tiles:
- for tile in row:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- if listindex == 1: # Stretch Center
-
- if object.width < 3 and object.height < 3:
- reply = QtGui.QMessageBox.information(self, "Warning", "An object must be at least 3 tiles\nwide and 3 tiles tall to apply stretch center.")
- self.setObject(index)
- return
-
- ctile = 0
- crow = 0
-
- for row in object.tiles:
- for tile in row:
- if crow == 0 and ctile == 0:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- elif crow == 0 and ctile == object.width-1:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- elif crow == object.height-1 and ctile == object.width-1:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- elif crow == object.height-1 and ctile == 0:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- elif crow == 0 or crow == object.height-1:
- object.tiles[crow][ctile] = (1, tile[1], tile[2])
- elif ctile == 0 or ctile == object.width-1:
- object.tiles[crow][ctile] = (2, tile[1], tile[2])
- else:
- object.tiles[crow][ctile] = (3, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0, 0]
- object.lowerslope = [0, 0]
-
- if listindex == 2: # Stretch X
-
- if object.width < 3:
- reply = QtGui.QMessageBox.information(self, "Warning", "An object must be at least 3 tiles\nwide to apply stretch X.")
- self.setObject(index)
- return
-
- ctile = 0
- crow = 0
-
- for row in object.tiles:
- for tile in row:
- if ctile == 0:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- elif ctile == object.width-1:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- else:
- object.tiles[crow][ctile] = (1, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0, 0]
- object.lowerslope = [0, 0]
-
- if listindex == 3: # Stretch Y
-
- if object.height < 3:
- reply = QtGui.QMessageBox.information(self, "Warning", "An object must be at least 3 tiles\ntall to apply stretch Y.")
- self.setObject(index)
- return
-
- ctile = 0
- crow = 0
-
- for row in object.tiles:
- for tile in row:
- if crow == 0:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- elif crow == object.height-1:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- else:
- object.tiles[crow][ctile] = (2, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0, 0]
- object.lowerslope = [0, 0]
-
- if listindex == 4: # Repeat Bottom
-
- if object.height < 2:
- reply = QtGui.QMessageBox.information(self, "Warning", "An object must be at least 2 tiles\ntall to apply repeat bottom.")
- self.setObject(index)
- return
-
- ctile = 0
- crow = 0
-
- for row in object.tiles:
- for tile in row:
- if crow == object.height-1:
- object.tiles[crow][ctile] = (2, tile[1], tile[2])
- else:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0, 0]
- object.lowerslope = [0, 0]
-
- if listindex == 5: # Repeat Top
-
- if object.height < 2:
- reply = QtGui.QMessageBox.information(self, "Warning", "An object must be at least 2 tiles\ntall to apply repeat top.")
- self.setObject(index)
- return
-
- ctile = 0
- crow = 0
-
- for row in object.tiles:
- for tile in row:
- if crow == 0:
- object.tiles[crow][ctile] = (2, tile[1], tile[2])
- else:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0, 0]
- object.lowerslope = [0, 0]
-
- if listindex == 6: # Repeat Left
-
- if object.width < 2:
- reply = QtGui.QMessageBox.information(self, "Warning", "An object must be at least 2 tiles\nwide to apply repeat left.")
- self.setObject(index)
- return
-
- ctile = 0
- crow = 0
-
- for row in object.tiles:
- for tile in row:
- if ctile == 0:
- object.tiles[crow][ctile] = (1, tile[1], tile[2])
- else:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0, 0]
- object.lowerslope = [0, 0]
-
- if listindex == 7: # Repeat Right
-
- if object.width < 2:
- reply = QtGui.QMessageBox.information(self, "Warning", "An object must be at least 2 tiles\nwide to apply repeat right.")
- self.setObject(index)
- return
-
- ctile = 0
- crow = 0
-
- for row in object.tiles:
- for tile in row:
- if ctile == object.width-1:
- object.tiles[crow][ctile] = (1, tile[1], tile[2])
- else:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0, 0]
- object.lowerslope = [0, 0]
-
-
- if listindex == 8: # Upward Slope
- ctile = 0
- crow = 0
- for row in object.tiles:
- for tile in row:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0x90, 1]
- object.lowerslope = [0x84, object.height - 1]
- self.tiles.slope = 1
-
- self.tiles.update()
+ object.wrap = listindex
- if listindex == 9: # Downward Slope
- ctile = 0
- crow = 0
- for row in object.tiles:
- for tile in row:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0x91, 1]
- object.lowerslope = [0x84, object.height - 1]
- self.tiles.slope = 1
-
- self.tiles.update()
-
- if listindex == 10: # Upward Reverse Slope
- ctile = 0
- crow = 0
- for row in object.tiles:
- for tile in row:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0x92, object.height - 1]
- object.lowerslope = [0x84, 1]
- self.tiles.slope = 0-(object.height-1)
-
- self.tiles.update()
-
- if listindex == 11: # Downward Reverse Slope
- ctile = 0
- crow = 0
- for row in object.tiles:
- for tile in row:
- object.tiles[crow][ctile] = (0, tile[1], tile[2])
- ctile += 1
- crow += 1
- ctile = 0
-
- object.upperslope = [0x93, object.height - 1]
- object.lowerslope = [0x84, 1]
- self.tiles.slope = 0-(object.height-1)
-
- self.tiles.update()
+ self.tiles.update()
class tileWidget(QtGui.QWidget):
@@ -759,7 +465,7 @@ class tileWidget(QtGui.QWidget):
curObj.width += 1
for row in curObj.tiles:
- row.append((0, 0xFFFF, 0))
+ row.append(0xFFFF)
self.update()
self.updateList()
@@ -814,7 +520,7 @@ class tileWidget(QtGui.QWidget):
curObj.tiles.append([])
for i in xrange(0, curObj.width):
- curObj.tiles[len(curObj.tiles)-1].append((0, 0xFFFF, 0))
+ curObj.tiles[len(curObj.tiles)-1].append(0xFFFF)
self.update()
self.updateList()
@@ -851,28 +557,24 @@ class tileWidget(QtGui.QWidget):
self.size = [object.width, object.height]
- if not object.upperslope[1] == 0:
- if object.upperslope[0] & 2:
- self.slope = 0 - object.lowerslope[1]
+ if object.wrap > 7:
+ if (object.wrap == 8) or (object.wrap == 10):
+ self.slope = 1
else:
- self.slope = object.upperslope[1]
+ self.slope = -1
x = 0
y = 0
for row in object.tiles:
for tile in row:
- if (Tileset.slot == 0) or ((tile[2] & 3) != 0):
- if (tile[1] == 0xFFFF):
- pix = QtGui.QPixmap(24,24)
- pix.fill(QtGui.QColor(205, 205, 255))
- self.tiles.append([x, y, pix])
- else:
- self.tiles.append([x, y, Tileset.tiles[tile[1]].image])
- else:
+ if (tile == 0xFFFF):
pix = QtGui.QPixmap(24,24)
pix.fill(QtGui.QColor(205, 205, 255))
self.tiles.append([x, y, pix])
+ else:
+ self.tiles.append([x, y, Tileset.tiles[tile].image])
+
x += 1
y += 1
x = 0
@@ -927,7 +629,7 @@ class tileWidget(QtGui.QWidget):
self.tiles[(y * self.size[0]) + x][2] = Tileset.tiles[tile].image
- Tileset.objects[self.object].tiles[y][x] = (Tileset.objects[self.object].tiles[y][x][0], tile, Tileset.slot)
+ Tileset.objects[self.object].tiles[y][x] = (tile)
ix += 1
if self.size[0]-1 < ix:
@@ -982,18 +684,12 @@ class tileWidget(QtGui.QWidget):
upperLeftY = centerPoint.y() - self.size[1]*12
tile = dlg.tile.value()
- tileset = dlg.tileset.currentIndex()
x = (self.contX - upperLeftX)/24
y = (self.contY - upperLeftY)/24
- if tileset != Tileset.slot:
- tex = QtGui.QPixmap(self.size[0] * 24, self.size[1] * 24)
- tex.fill(QtCore.Qt.transparent)
-
- self.tiles[(y * self.size[0]) + x][2] = tex
- Tileset.objects[self.object].tiles[y][x] = (Tileset.objects[self.object].tiles[y][x][0], tile, tileset)
+ Tileset.objects[self.object].tiles[y][x] = tile
self.update()
self.updateList()
@@ -1339,64 +1035,29 @@ class MainWindow(QtGui.QMainWindow):
# Load Objects
meta = []
- for i in xrange(len(metadata)/4):
- meta.append(struct.unpack_from('>H2B', metadata, i * 4))
+ for i in xrange(len(metadata)/5):
+ meta.append(struct.unpack_from('>H3B', metadata, i * 5))
- tilelist = [[]]
- upperslope = [0, 0]
- lowerslope = [0, 0]
- byte = 0
+ tilelist = []
+ rowlist = []
for entry in meta:
offset = entry[0]
- byte = struct.unpack_from('>B', objstrings, offset)[0]
row = 0
- while byte != 0xFF:
-
- if byte == 0xFE:
- tilelist.append([])
-
- if (upperslope[0] != 0) and (lowerslope[0] == 0):
- upperslope[1] = upperslope[1] + 1
-
- if lowerslope[0] != 0:
- lowerslope[1] = lowerslope[1] + 1
+ for tiles in xrange(entry[2]):
+ for tiles in xrange(entry[1]):
+ untile = struct.unpack_from('>H', objstrings, offset)[0]
- offset += 1
- byte = struct.unpack_from('>B', objstrings, offset)[0]
+ rowlist.append(untile)
+ offset += 2
- elif (byte & 0x80):
+ tilelist.append(rowlist)
+ rowlist = []
- if upperslope[0] == 0:
- upperslope[0] = byte
- else:
- lowerslope[0] = byte
-
- offset += 1
- byte = struct.unpack_from('>B', objstrings, offset)[0]
-
- else:
- untile = struct.unpack_from('>BH', objstrings, offset)
- retile = (untile[0], untile[1], 0)
+ Tileset.addObject(tilelist, entry[2], entry[1], entry[3])
- tilelist[len(tilelist)-1].append(retile)
-
- offset += 3
- byte = struct.unpack_from('>B', objstrings, offset)[0]
-
- tilelist.pop()
-
- if (upperslope[0] & 0x80) and (upperslope[0] & 0x2):
- for i in range(lowerslope[1]):
- pop = tilelist.pop()
- tilelist.insert(0, pop)
-
- Tileset.addObject(entry[2], entry[1], upperslope, lowerslope, tilelist)
-
- tilelist = [[]]
- upperslope = [0, 0]
- lowerslope = [0, 0]
+ tilelist = []
self.setuptile()
SetupObjectModel(self.objmodel, Tileset.objects, Tileset.tiles, self.treeki, group)
@@ -1610,74 +1271,17 @@ class MainWindow(QtGui.QMainWindow):
o = 0
for object in Tileset.objects:
-
- # Slopes
- if object.upperslope[0] != 0:
-
- # Reverse Slopes
- if object.upperslope[0] & 0x2:
- a = struct.pack('>B', object.upperslope[0])
-
- if object.height == 1:
- iterationsA = 0
- iterationsB = 1
- else:
- iterationsA = object.upperslope[1]
- iterationsB = object.lowerslope[1] + object.upperslope[1]
-
- for row in xrange(iterationsA, iterationsB):
- for tile in object.tiles[row]:
- a = a + struct.pack('>BH', tile[0], tile[1])
- a = a + '\xfe'
+ a = ''
+
+ for tilerow in object.tiles:
+ for tile in tilerow:
+ a = a + struct.pack('>H', tile)
- if object.height > 1:
- a = a + struct.pack('>B', object.lowerslope[0])
-
- for row in xrange(0, object.upperslope[1]):
- for tile in object.tiles[row]:
- a = a + struct.pack('>BH', tile[0], tile[1])
- a = a + '\xfe'
-
- a = a + '\xff'
-
- objectStrings.append(a)
-
-
- # Regular Slopes
- else:
- a = struct.pack('>B', object.upperslope[0])
-
- for row in xrange(0, object.upperslope[1]):
- for tile in object.tiles[row]:
- a = a + struct.pack('>BH', tile[0], tile[1])
- a = a + '\xfe'
-
- if object.height > 1:
- a = a + struct.pack('>B', object.lowerslope[0])
-
- for row in xrange(object.upperslope[1], object.height):
- for tile in object.tiles[row]:
- a = a + struct.pack('>BH', tile[0], tile[1])
- a = a + '\xfe'
-
- a = a + '\xff'
-
- objectStrings.append(a)
-
-
- # Not slopes!
- else:
- a = ''
-
- for tilerow in object.tiles:
- for tile in tilerow:
- a = a + struct.pack('>BH', tile[0], tile[1])
-
- a = a + '\xfe'
-
- a = a + '\xff'
-
- objectStrings.append(a)
+ print tile
+
+ a = a + '\xff'
+
+ objectStrings.append(a)
o += 1
@@ -1685,7 +1289,7 @@ class MainWindow(QtGui.QMainWindow):
Metabuffer = ''
i = 0
for a in objectStrings:
- Metabuffer = Metabuffer + struct.pack('>H2B', len(Objbuffer), Tileset.objects[i].width, Tileset.objects[i].height)
+ Metabuffer = Metabuffer + struct.pack('>H3B', len(Objbuffer), Tileset.objects[i].width, Tileset.objects[i].height, Tileset.objects[i].wrap)
Objbuffer = Objbuffer + a
i += 1
diff --git a/Koopuzzle/windows_build.py b/Koopuzzle/windows_build.py
index 10d710c..2f36999 100755
--- a/Koopuzzle/windows_build.py
+++ b/Koopuzzle/windows_build.py
@@ -9,8 +9,7 @@ if '-upx' in sys.argv:
dir = 'distrib/windows'
-print '[[ Running Puzzle Through py2exe! ]]'
-print 'Note: Puzzle MUST have NSMBlib-0.5a or none at all to function.'
+print '[[ Running Koopuzzle Through py2exe! ]]'
print '>> Destination directory: %s' % dir
sys.argv.append('py2exe')
@@ -25,11 +24,11 @@ excludes = ['encodings', 'doctest', 'pdb', 'unittest', 'difflib', 'inspect',
# set it up
setup(
- name='Puzzle',
+ name='Koopuzzle',
version='1.0',
- description='Puzzle - Tileset Editor',
+ description='Koopuzzle - Koopatlas Tileset Editor',
windows=[
- {'script': 'puzzle.py',
+ {'script': 'Koopuzzle.py',
}
],
options={'py2exe':{
@@ -59,14 +58,9 @@ if upxFlag:
print '>> Compression complete.'
else:
print '>> UPX not found, binaries can\'t be compressed.'
- print '>> In order to build Reggie! with UPX, place the upx.exe file into '\
+ print '>> In order to build Koopuzzle! with UPX, place the upx.exe file into '\
'this folder.'
-if os.path.isdir(dir + '/Icons'): shutil.rmtree(dir + '/Icons')
-if os.path.isdir(dir + '/nsmblib-0.5a'): shutil.rmtree(dir + '/nsmblib-0.5a')
-shutil.copytree('Icons', dir + '/Icons')
-shutil.copytree('nsmblib-0.5a', dir + '/nsmblib-0.5a')
-shutil.copy('license.txt', dir)
print '>> Attempting to copy VC++2008 libraries...'
if os.path.isdir('Microsoft.VC90.CRT'):
@@ -78,4 +72,4 @@ else:
print '>> In order to automatically include the runtimes, place the '\
'Microsoft.VC90.CRT folder into this folder.'
-print '>> Reggie has been frozen to %s!' % dir
+print '>> Koopuzzle has been frozen to %s!' % dir