summaryrefslogtreecommitdiff
path: root/src/mapdata.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapdata.py')
-rw-r--r--src/mapdata.py95
1 files changed, 80 insertions, 15 deletions
diff --git a/src/mapdata.py b/src/mapdata.py
index b8ab263..6f71daf 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -147,27 +147,30 @@ class KPTileLayer(KPLayer):
y += 1
-@mapfile.dumpable('tile_layer')
-class KPPathTileLayer(KPTileLayer):
- __dump_attribs__ = KPLayer.__dump_attribs__ + ('tileset', 'objects')
+@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 %r with %r connected to %r>" % (self.name, self.tileset, self.pathnode)
+ 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.pathnode = pathnode
+ self.associate = pathnode
self.cache = ['DUMMY_FLAG']
self.updateCache()
self.icon = KP.icon('LayerTile')
- def getPathNode(self):
- return self.pathnode
+ def associate(self):
+ return self.associate
def _visibilityChanged(self, value):
for obj in self.objects:
@@ -180,6 +183,71 @@ class KPPathTileLayer(KPTileLayer):
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):
@@ -275,11 +343,6 @@ class KPDoodadLayer(KPLayer):
item.setVisible(value)
-class KPNodeAction(object):
- def __init__(self):
- pass
-
-
@mapfile.dumpable('node')
class KPNode(object):
__dump_attribs__ = (
@@ -402,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!
@@ -447,13 +510,15 @@ class KPMap(object):
self.loadTilesets()
try:
- self.pathNodeTileset = self.tilesets[0]
+ 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.QAbstractItemModel):
+ class LayerModel(QtCore.QAbstractListModel):
def __init__(self, layerList):
QtCore.QAbstractListModel.__init__(self)
self.list = layerList