From 982998939f668571fbb33df759828119b7e6c473 Mon Sep 17 00:00:00 2001 From: Colin Noga Date: Wed, 30 Nov 2011 00:07:26 -0600 Subject: Tileset loading and reloading --- Resources/Test3.arc | Bin 1053536 -> 0 bytes Tilesets/Test3.arc | Bin 0 -> 1053536 bytes src/mapdata.py | 49 ++++++++++++++++++++++++++++++++++++++----------- src/ui.py | 5 ++++- 4 files changed, 42 insertions(+), 12 deletions(-) delete mode 100644 Resources/Test3.arc create mode 100644 Tilesets/Test3.arc diff --git a/Resources/Test3.arc b/Resources/Test3.arc deleted file mode 100644 index f45d7e2..0000000 Binary files a/Resources/Test3.arc and /dev/null differ diff --git a/Tilesets/Test3.arc b/Tilesets/Test3.arc new file mode 100644 index 0000000..f45d7e2 Binary files /dev/null and b/Tilesets/Test3.arc differ 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() diff --git a/src/ui.py b/src/ui.py index 89b0674..6f9cde8 100644 --- a/src/ui.py +++ b/src/ui.py @@ -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): -- cgit v1.2.3