summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/editorui/editormain.py8
-rw-r--r--src/mapdata.py43
-rw-r--r--src/ui.py43
3 files changed, 65 insertions, 29 deletions
diff --git a/src/editorui/editormain.py b/src/editorui/editormain.py
index 1ba06bd..c20cc47 100644
--- a/src/editorui/editormain.py
+++ b/src/editorui/editormain.py
@@ -280,7 +280,7 @@ class KPMapScene(QtGui.QGraphicsScene):
baseDestX = drawLeft * 24
rows = pnLayer.cache
- tileset = KP.map.loadedTilesets[KP.map.pathNodeTileset]
+ tileset = KP.map.loadedTilesets[pnLayer.tileset]
tileList = tileset.tiles
for y in xrange(drawTop, drawBottom):
@@ -426,7 +426,8 @@ class KPEditorWidget(QtGui.QGraphicsView):
obj.position = (x,y)
obj.size = (1,1)
obj.tileset = layer.tileset
- obj.kind = paint
+ obj.kind = self.objectIDToPaint
+ obj.kindObj = paint
obj.updateCache()
layer.objects.append(obj)
layer.updateCache()
@@ -605,7 +606,8 @@ class KPEditorWidget(QtGui.QGraphicsView):
obj.position = (x,y)
obj.size = (1,1)
obj.tileset = layer.tileset
- obj.kind = paint
+ obj.kind = self.objectIDToPaint
+ obj.kindObj = paint
obj.updateCache()
layer.objects.append(obj)
layer.updateCache()
diff --git a/src/mapdata.py b/src/mapdata.py
index 2bdc4eb..7346634 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -48,25 +48,23 @@ class KPLayer(object):
@mapfile.dumpable('object')
class KPObject(object):
- __dump_attribs__ = ('position', 'size', 'tileset')
+ __dump_attribs__ = ('position', 'size', 'tileset', 'kind')
def _load(self, mapObj, src):
- self.kind = mapObj.loadedTilesets[self.tileset].objects[src['kind']]
+ self.kindObj = mapObj.loadedTilesets[self.tileset].objects[self.kind]
self.updateCache()
- def _dump(self, mapObj, dest):
- dest['kind'] = mapObj.loadedTilesets[self.tileset].objects.index(self.kind)
-
def __init__(self):
self.position = (0,0)
self.size = (1,1)
self.kind = 0
+ self.kindObj = None
self.cache = []
self.tileset = None
self.qtItem = None
def updateCache(self):
- self.cache = self.kind.render(self.size)
+ self.cache = self.kindObj.render(self.size)
@mapfile.dumpable('tile_layer')
@@ -178,7 +176,7 @@ class KPPathTileLayer(KPLayer):
if pathnode is None:
return
- self.tileset = KP.map.pathNodeTileset
+ self.tileset = ''
self.objects = []
self.doodads = []
self.associate = pathnode
@@ -260,6 +258,18 @@ class KPPathTileLayer(KPLayer):
destRow[x] = tile
x += 1
y += 1
+
+ def setTileset(self, tileset):
+ self.tileset = tileset
+
+ tsObjects = KP.map.loadedTilesets[tileset]
+
+ for obj in self.objects:
+ obj.tileset = tileset
+ obj.kindObj = tsObjects[obj.kind]
+ obj.updateCache()
+
+ self.updateCache()
@mapfile.dumpable('doodad')
@@ -480,7 +490,7 @@ class KPPathLayer(KPLayer):
@mapfile.dumpable('map_root')
class KPMap(object):
- __dump_attribs__ = ('layers', 'associateLayers', 'nextLayerNumber', 'doodadDefinitions', 'pathNodeTileset')
+ __dump_attribs__ = ('layers', 'associateLayers', 'nextLayerNumber', 'doodadDefinitions')
def _preload(self, src):
# we need this early so we can use the deref methods!
@@ -492,6 +502,14 @@ class KPMap(object):
self.layerModel.list = self.layers
self.doodadModel.list = self.doodadDefinitions
+ if 'version' in source:
+ self.version = source['version']
+ else:
+ self.version = 1
+
+ def _dump(self, mapObj, dest):
+ dest['version'] = self.version
+
def save(self):
path = self.filePath
if path is None:
@@ -510,6 +528,8 @@ class KPMap(object):
open(path, 'wb').write(data)
def __init__(self):
+ self.version = 2
+
self.filePath = None
self.nextLayerNumber = 1
@@ -527,13 +547,6 @@ class KPMap(object):
self.loadTilesets()
- try:
- self.pathNodeTileset = self.tilesets.keys()[0]
- except:
- # TODO: This should probably error out or something. Seriously.
- # It'll ruin the path or object layers if there are NO tilesets.
- self.pathNodeTileset = ''
-
# LAYERS
class LayerModel(QtCore.QAbstractListModel):
diff --git a/src/ui.py b/src/ui.py
index 56795b6..a7e71ba 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -150,16 +150,34 @@ class KPPathNodeList(QtGui.QWidget):
self.tree.addTopLevelItems(kids)
def setTileset(self):
+ item = self.tree.currentItem()
+ if not isinstance(item, self.KPPathNodeItem):
+ return
+
+ layer = item.layer
+ assoc = item.associate
+ name = 'path' if isinstance(item.associate, KPPath) else 'node'
+
from dialogs import KPTilesetChooserDialog
- tilesetName = KPTilesetChooserDialog.run('Choose a tileset for the path/node layers')
+ tilesetName = KPTilesetChooserDialog.run('Choose a tileset for the %s layer' % name)
if tilesetName is None:
return
- KP.map.pathNodeTileset = tilesetName
+ layer.setTileset(tilesetName)
def addLayer(self, associate):
layer = KPPathTileLayer(associate)
+ name = 'path' if isinstance(associate, KPPath) else 'node'
+
+ from dialogs import KPTilesetChooserDialog
+
+ tilesetName = None
+ while tilesetName is None:
+ tilesetName = KPTilesetChooserDialog.run('Choose a tileset for the %s layer' % name)
+
+ layer.tileset = tilesetName
+
item = self.KPPathNodeItem(self.tree, layer, associate)
def loadLayer(self, layer):
@@ -470,7 +488,7 @@ class KPDoodadSelector(QtGui.QWidget):
class KPObjectSelector(QtGui.QWidget):
def __init__(self):
- """Initialises the widget. Remember to call setModel() on it with a KPGroupModel
+ """Initialises the widget. Remember to call setTileset() on it
whenever the layer changes."""
QtGui.QWidget.__init__(self)
@@ -512,7 +530,7 @@ class KPObjectSelector(QtGui.QWidget):
# Borrowed the signals and junk from Reggie, figure we'll need em'
- # Some more signals are set in setModel
+ # Some more signals are set in setTileset
self.listView.clicked.connect(self.handleObjReplace)
self.sorterMenu.aboutToShow.connect(self.fixUpMenuSize)
self.sorterMenu.triggered.connect(self.toggleTopLevel)
@@ -542,12 +560,15 @@ class KPObjectSelector(QtGui.QWidget):
return object
- def setModel(self, model):
+ def setTileset(self, tileset):
"""Sets the model and the menu sorting list"""
+ model = tileset.getModel()
if model == self.model:
return
+ self.tileset = tileset
+
self.model = model
self.listView.setModel(model)
self.listView.setEnabled(True)
@@ -600,7 +621,7 @@ class KPObjectSelector(QtGui.QWidget):
i = current.row()
object, depth = self.model.groupItem().getItem(i)
- self.objChanged.emit(i, object)
+ self.objChanged.emit(self.tileset.objects.index(object), object)
def handleObjReplace(self, index):
@@ -609,7 +630,7 @@ class KPObjectSelector(QtGui.QWidget):
i = current.row()
object, depth = self.model.groupItem().getItem(i)
- self.objReplaced.emit(i, object)
+ self.objReplaced.emit(self.tileset.objects.index(object), object)
objChanged = QtCore.pyqtSignal(int, KPTileObject)
objReplaced = QtCore.pyqtSignal(int, KPTileObject)
@@ -803,7 +824,7 @@ class KPMainWindow(QtGui.QMainWindow):
KP.map.reloadTileset(layer.tileset)
showObjects = True
- self.objectSelector.setModel(KP.map.loadedTilesets[layer.tileset].getModel())
+ self.objectSelector.setTileset(KP.map.loadedTilesets[layer.tileset])
self.objectSelectorDock.setVisible(showObjects)
self.doodadSelectorDock.setVisible(showDoodads)
@@ -818,9 +839,9 @@ class KPMainWindow(QtGui.QMainWindow):
self.scene.setCurrentLayer(layer)
- KP.map.reloadTileset(KP.map.pathNodeTileset)
+ KP.map.reloadTileset(layer.tileset)
- self.objectSelector.setModel(KP.map.loadedTilesets[KP.map.pathNodeTileset].getModel())
+ self.objectSelector.setTileset(KP.map.loadedTilesets[layer.tileset])
self.objectSelectorDock.setVisible(True)
self.doodadSelectorDock.setVisible(True)
@@ -1000,7 +1021,7 @@ class KPMainWindow(QtGui.QMainWindow):
KPTileLayer.tileset = tilesetName
- self.objectSelector.setModel(KP.map.loadedTilesets[layer.tileset].getModel())
+ self.objectSelector.setTileset(KP.map.loadedTilesets[layer.tileset])
# Animate