summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorColin Noga <Tempus@Spectrum-Song.local>2011-11-30 00:07:26 -0600
committerColin Noga <Tempus@Spectrum-Song.local>2011-11-30 00:07:26 -0600
commit982998939f668571fbb33df759828119b7e6c473 (patch)
treec68a1bebcc86f8dde56f4bca1628edd3feace6fc /src
parentb108fc94779df34fe498b8a2b5ce6a155711455c (diff)
downloadkoopatlas-982998939f668571fbb33df759828119b7e6c473.tar.gz
koopatlas-982998939f668571fbb33df759828119b7e6c473.zip
Tileset loading and reloading
Diffstat (limited to 'src')
-rw-r--r--src/mapdata.py49
-rw-r--r--src/ui.py5
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()
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):