summaryrefslogtreecommitdiff
path: root/src/mapdata.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/mapdata.py117
1 files changed, 110 insertions, 7 deletions
diff --git a/src/mapdata.py b/src/mapdata.py
index 23c6b83..6f71daf 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -147,6 +147,108 @@ class KPTileLayer(KPLayer):
y += 1
+@mapfile.dumpable('associate_layer')
+class KPPathTileLayer(KPLayer):
+ __dump_attribs__ = KPLayer.__dump_attribs__ + ('tileset', 'objects', 'doodads', 'associate')
+
+ def _load(self, mapObj, src):
+ self.updateCache()
+
+ def __repr__(self):
+ return "<KPPathTileLayer with %r connected to %r>" % (self.tileset, self.associate)
+
+ def __init__(self, pathnode):
+ KPLayer.__init__(self)
+ self.tileset = KP.map.pathNodeTileset
+ self.objects = []
+ self.doodads = []
+ self.associate = pathnode
+
+ self.cache = ['DUMMY_FLAG']
+ self.updateCache()
+
+ self.icon = KP.icon('LayerTile')
+
+ def associate(self):
+ return self.associate
+
+ def _visibilityChanged(self, value):
+ for obj in self.objects:
+ item = obj.qtItem
+ if item:
+ item.setVisible(value)
+
+ for obj in self.doodads:
+ item = obj.qtItem
+ if item:
+ item.setVisible(value)
+
+ def setActivated(self, value, listToUse=None):
+ flag1 = QtGui.QGraphicsItem.ItemIsSelectable
+ flag2 = QtGui.QGraphicsItem.ItemIsMovable
+
+ if listToUse is None:
+ listToUse = self.objects + self.doodads
+
+ for obj in listToUse:
+ item = obj.qtItem
+ if item:
+ item.setFlag(flag1, value)
+ item.setFlag(flag2, value)
+
+ def updateCache(self):
+ if len(self.objects) == 0:
+ if len(self.cache) != 0:
+ self.cache = []
+ self.cacheBasePos = (0,0)
+ self.cacheSize = (0,0)
+ return
+
+ x1, x2 = MAP_SIZE_IN_TILES[0] - 1, 0
+ y1, y2 = MAP_SIZE_IN_TILES[1] - 1, 0
+
+ for obj in self.objects:
+ x, y = obj.position
+ w, h = obj.size
+ right, bottom = (x+w-1), (y+h-1)
+
+ if x < x1:
+ x1 = x
+ if y < y1:
+ y1 = y
+ if right > x2:
+ x2 = right
+ if bottom > y2:
+ y2 = bottom
+
+
+ # create the cache
+ # I was going to just resize it, but setting every tile to -1
+ # in Python would probably be slower than creating a new one ...
+ size = (x2 - x1 + 1, y2 - y1 + 1)
+ width, height = size
+
+ cache = [[-1 for i in xrange(width)] for j in xrange(height)]
+ self.cache = cache
+
+ self.cacheBasePos = (x1, y1)
+ self.cacheSize = size
+
+ # now generate the thing
+ for obj in self.objects:
+ oX, oY = obj.position
+ baseX = oX - x1
+ y = oY - y1
+
+ for row in obj.cache:
+ destRow = cache[y]
+ x = baseX
+ for tile in row:
+ destRow[x] = tile
+ x += 1
+ y += 1
+
+
@mapfile.dumpable('doodad')
class KPDoodad(object):
__dump_attribs__ = ('position', 'size', 'angle', 'animations')
@@ -241,11 +343,6 @@ class KPDoodadLayer(KPLayer):
item.setVisible(value)
-class KPNodeAction(object):
- def __init__(self):
- pass
-
-
@mapfile.dumpable('node')
class KPNode(object):
__dump_attribs__ = (
@@ -274,7 +371,6 @@ class KPNode(object):
return True if (self.level or self.mapChange or len(self.exits) != 2) else False
-
@mapfile.dumpable('path')
class KPPath(object):
__dump_attribs__ = ('unlocks', 'secret', 'animation', 'movementSpeed')
@@ -369,7 +465,7 @@ class KPPathLayer(KPLayer):
@mapfile.dumpable('map_root')
class KPMap(object):
- __dump_attribs__ = ('layers', 'nextLayerNumber', 'doodadDefinitions')
+ __dump_attribs__ = ('layers', 'nextLayerNumber', 'doodadDefinitions', 'pathNodeTileset')
def _preload(self, src):
# we need this early so we can use the deref methods!
@@ -413,6 +509,13 @@ 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):