diff options
Diffstat (limited to '')
-rw-r--r-- | src/mapdata.py | 76 |
1 files changed, 62 insertions, 14 deletions
diff --git a/src/mapdata.py b/src/mapdata.py index 85549e2..e864df0 100644 --- a/src/mapdata.py +++ b/src/mapdata.py @@ -1,4 +1,5 @@ from common import * +import weakref TILE_SIZE = (24,24) MAP_SIZE_IN_TILES = (512,512) @@ -27,6 +28,19 @@ class KPLayer(object): def _visibilityChanged(self, value): pass + def setActivated(self, value, listToUse=None): + flag1 = QtGui.QGraphicsItem.ItemIsSelectable + flag2 = QtGui.QGraphicsItem.ItemIsMovable + + if listToUse is None: + listToUse = self.objects + + for obj in listToUse: + item = obj.qtItem + if item: + item.setFlag(flag1, value) + item.setFlag(flag2, value) + class KPObject(object): def __init__(self): @@ -150,20 +164,38 @@ class KPNode(object): def __init__(self): self.position = (0,0) self.actions = [] + self.exits = [] + self.isStop = False -class KPPathSegment(object): - def __init__(self): - self.start = None - self.end = None - self.animation = None # default +class KPPath(object): + def __init__(self, startNode, endNode, cloneFrom=None): + self._startNodeRef = weakref.ref(startNode) + self._endNodeRef = weakref.ref(endNode) + startNode.exits.append(self) + endNode.exits.append(self) -class KPPath(object): - def __init__(self): - self.startNode = None - self.endNode = None - self.segments = [] + if cloneFrom is None: + self.animation = None + else: + self.animation = cloneFrom.animation + + def setStart(self, newStart): + currentStart = self._startNodeRef() + if currentStart is not None: + currentStart.exits.remove(self) + + newStart.exits.append(self) + self._startNodeRef = weakref.ref(newStart) + + def setEnd(self, newEnd): + currentEnd = self._endNodeRef() + if currentEnd is not None: + currentEnd.exits.remove(self) + + newEnd.exits.append(self) + self._endNodeRef = weakref.ref(newEnd) class KPPathLayer(KPLayer): @@ -176,10 +208,20 @@ class KPPathLayer(KPLayer): self.paths = [] def _visibilityChanged(self, value): - for obj in self.objects: - item = obj.qtItem + for objList in (self.nodes, self.paths): + for obj in objList: + item = obj.qtItem + if item: + item.setVisible(value) + + def setActivated(self, value): + KPLayer.setActivated(self, value, self.nodes) + + flag = QtGui.QGraphicsItem.ItemIsSelectable + for path in self.paths: + item = path.qtItem if item: - item.setVisible(value) + item.setFlag(flag, value) @@ -189,7 +231,8 @@ class KPMap(object): def __init__(self): self.nextLayerNumber = 1 - self.layers = [self.createNewTileLayer('Test') for x in range(4)] + self.pathLayer = self._createPathLayer() + self.layers = [self.pathLayer] self.layerModel = KPMap.LayerModel(self.layers) self.nodes = [] self.paths = [] @@ -259,6 +302,11 @@ class KPMap(object): return False + def _createPathLayer(self): + layer = KPPathLayer() + layer.name = 'Paths' + return layer + def createNewTileLayer(self, tilesetName): layer = KPTileLayer() layer.name = "Tilemap - Layer %d" % self.nextLayerNumber |