summaryrefslogtreecommitdiff
path: root/src/mapdata.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/mapdata.py43
1 files changed, 28 insertions, 15 deletions
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):