diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mapdata.py | 49 | ||||
-rw-r--r-- | src/ui.py | 5 |
2 files changed, 42 insertions, 12 deletions
diff --git a/src/mapdata.py b/src/mapdata.py index 0a636f7..0866815 100644 --- a/src/mapdata.py +++ b/src/mapdata.py @@ -249,13 +249,7 @@ class KPMap(object): self.tilesets = {} self.loadedTilesets = {} - # TESTING CRAP - import os.path - if os.path.exists('/Users/Tempus'): - self.tilesets['Test'] = {'path': '/Users/Tempus/Dropbox/NEWERsmbw/Test3.arc'} - else: - self.tilesets['Test'] = {'path': '/home/me/Dropbox/NEWERsmbw/Test3.arc'} - self.reloadTileset('Test') + self.loadTilesets() # LAYERS @@ -373,10 +367,43 @@ class KPMap(object): self.layerModel.endRemoveRows() + def loadTilesets(self): + import os + from hashlib import sha256 as sha + + path = os.getcwd() + os.sep + 'Tilesets' + + if not os.path.exists(path): + os.mkdir(path) + + for file in os.listdir(path): + name = file[:-4] + + if file[-4:] == '.arc': + filepath = path + os.sep + file + + filehandler = open(filepath) + data = filehandler.read() + filehandler.close() + hash = sha(data).hexdigest() + + self.tilesets[name] = {'path': filepath, 'hash': hash} + self.loadedTilesets[name] = KPTileset.loadFromArc(filepath) + + def reloadTileset(self, name): + from hashlib import sha256 as sha + info = self.tilesets[name] - self.loadedTilesets[name] = KPTileset.loadFromArc(info['path']) - # TODO: handle relative paths properly in relation to the map file - # TODO: add some sort of callback/signal to regenerate objects/layers - # and refresh the view + + filehandler = open(info['path']) + data = filehandler.read() + filehandler.close() + hash = sha(data).hexdigest() + + if info['hash'] != hash: + self.loadedTilesets[name] = KPTileset.loadFromArc(info['path']) + + KP.mapscene.update() + KP.mapscene.views()[0].update() @@ -461,7 +461,10 @@ class KPMainWindow(QtGui.QMainWindow): self.objectSelectorDock.show() self.objectSelector.setModel(KP.map.loadedTilesets[layer.tileset].getModel()) - + + print 'Reloading ', layer.tileset + KP.map.reloadTileset(layer.tileset) + @QtCore.pyqtSlot(int, KPTileObject) def handleSelectedObjectChanged(self, index, obj): |