summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.py2
-rw-r--r--src/editorui.py4
-rw-r--r--src/mapdata.py13
-rw-r--r--src/tileset.py20
-rw-r--r--src/ui.py24
5 files changed, 51 insertions, 12 deletions
diff --git a/src/common.py b/src/common.py
index 3165ab4..2b965d7 100644
--- a/src/common.py
+++ b/src/common.py
@@ -2,8 +2,8 @@ import sys
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import Qt
-from mapdata import *
from tileset import *
+from mapdata import *
from main import KP
diff --git a/src/editorui.py b/src/editorui.py
index 7f2a7f7..51b148d 100644
--- a/src/editorui.py
+++ b/src/editorui.py
@@ -31,7 +31,7 @@ class KPMapScene(QtGui.QGraphicsScene):
drawRight = min(areaRightT, right)
drawTop = max(areaTopT, top)
- drawBottom = max(areaBottomT, bottom)
+ drawBottom = min(areaBottomT, bottom)
srcY = drawTop - top
destY = drawTop * 24
@@ -40,7 +40,7 @@ class KPMapScene(QtGui.QGraphicsScene):
baseDestX = drawLeft * 24
rows = layer.cache
- tileset = KP.map.tilesets[layer.tileset]
+ tileset = KP.map.loadedTilesets[layer.tileset]
tileList = tileset.tiles
for y in xrange(drawTop, drawBottom):
diff --git a/src/mapdata.py b/src/mapdata.py
index 550d710..d4eb2eb 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -123,6 +123,11 @@ class KPMap(object):
self.paths = []
self.doodads = []
self.tilesets = {}
+ self.loadedTilesets = {}
+
+ # TESTING CRAP
+ self.tilesets['Test'] = {'path': '/home/me/Dropbox/NEWERsmbw/Test2.arc'}
+ self.reloadTileset('Test')
# LAYERS
@@ -224,4 +229,12 @@ class KPMap(object):
self.layerModel.beginRemoveRows(QtCore.QModelIndex(), index, index)
del self.layers[index]
self.layerModel.endRemoveRows()
+
+
+ def reloadTileset(self, name):
+ info = self.tilesets[name]
+ self.loadedTilesets[name] = KPTileset.loadFromArc(info['path'])
+ # TODO: handle relative paths properly in relation to the map file
+ # TODO: add some sort of callback/signal to regenerate objects/layers
+ # and refresh the view
diff --git a/src/tileset.py b/src/tileset.py
index 857a805..50aaf38 100644
--- a/src/tileset.py
+++ b/src/tileset.py
@@ -1,4 +1,5 @@
from common import *
+from wii.u8archive import WiiArchiveU8
import struct
import cPickle
@@ -268,6 +269,25 @@ class KPGroupItem(object):
class KPTileset(object):
+ @classmethod
+ def loadFromArc(cls, handleOrPath):
+ arc = WiiArchiveU8(handleOrPath)
+
+ img = arc.resolvePath('/BG_tex').children[0].data
+ grp = arc.resolvePath('/BG_grp').children[0].data
+
+ untDir = arc.resolvePath('/BG_unt')
+ obj, meta = None, None
+
+ for child in untDir.children:
+ if child.name.endswith('_hd.bin'):
+ meta = child.data
+ else:
+ obj = child.data
+
+ return cls(img, obj, meta, grp)
+
+
def __init__(self, imageBuffer, objectBuffer, objectMetadata, groupBuffer):
'''A Koopatlas Tileset class. To initialize, pass it image data,
object data, and group data as read from a Koopatlas tileset file.
diff --git a/src/ui.py b/src/ui.py
index cc3d4be..a6115ed 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -13,6 +13,7 @@ class KPLayerList(QtGui.QWidget):
self.listView = QtGui.QListView()
self.listView.setModel(self.model)
+ self.listView.selectionModel().currentRowChanged.connect(self.handleRowChanged)
self.layout.addWidget(self.listView)
self.toolbar = QtGui.QToolBar()
@@ -35,6 +36,15 @@ class KPLayerList(QtGui.QWidget):
def selectedLayer(self):
return KP.map.layers[self.listView.selectionModel().currentIndex().row()]
+ selectedLayerChanged = QtCore.pyqtSignal(KPLayer, KPLayer)
+
+ @QtCore.pyqtSlot(QtCore.QModelIndex, QtCore.QModelIndex)
+ def handleRowChanged(self, current, previous):
+ self.selectedLayerChanged.emit(
+ KP.map.layers[current.row()],
+ ((previous.row() >= 0) and KP.map.layers[previous.row()]) or None
+ )
+
def addLayer(self):
KP.map.appendLayer(KP.map.createNewLayer())
@@ -162,21 +172,17 @@ class KPMainWindow(QtGui.QMainWindow):
self.layerListDock.setWidget(self.layerList)
self.objectSelector = KPObjectSelector()
- # TODO: refactor this, this is just a bit of a hack for now
- from wii.u8archive import WiiArchiveU8
- arc = WiiArchiveU8(open('/home/me/Dropbox/NEWERsmbw/Test2.arc', 'rb'))
- img = arc.resolvePath('/BG_tex/Test2_tex.bin').data
- obj = arc.resolvePath('/BG_unt/Test2.bin').data
- objm = arc.resolvePath('/BG_unt/Test2_hd.bin').data
- grp = arc.resolvePath('/BG_grp/Test2_grp.bin').data
- TestTileset = KPTileset(img, obj, objm, grp)
- self.objectSelector.setModel(TestTileset.getModel())
+ self.updateObjectSelector()
self.objectSelectorDock = QtGui.QDockWidget('Objects')
self.objectSelectorDock.setWidget(self.objectSelector)
self.addDockWidget(Qt.RightDockWidgetArea, self.layerListDock)
self.addDockWidget(Qt.RightDockWidgetArea, self.objectSelectorDock)
+
+ @QtCore.pyqtSlot()
+ def updateObjectSelector(self):
+ pass