summaryrefslogtreecommitdiff
path: root/src/mapdata.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapdata.py')
-rw-r--r--src/mapdata.py49
1 files changed, 38 insertions, 11 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()