summaryrefslogtreecommitdiff
path: root/src/main.py
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-03-27 23:15:51 +0200
committerTreeki <treeki@gmail.com>2012-03-27 23:15:51 +0200
commit93349b8e694ac31f0aba4f6bc25515bd5a531f7d (patch)
tree22eabb7d881efd482f5f62f526039931994066e9 /src/main.py
parent8d5d27396da513fea62d99d8550923dee2f08ed8 (diff)
downloadkoopatlas-93349b8e694ac31f0aba4f6bc25515bd5a531f7d.tar.gz
koopatlas-93349b8e694ac31f0aba4f6bc25515bd5a531f7d.zip
tilesets now loaded on-demand and not part of KPMap
Diffstat (limited to '')
-rw-r--r--src/main.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/src/main.py b/src/main.py
index a429916..8d8d494 100644
--- a/src/main.py
+++ b/src/main.py
@@ -7,7 +7,6 @@ class KP:
KP.app.settings = QtCore.QSettings('Koopatlas', 'Newer Team')
-
from mapdata import KPMap
KP.map = KPMap()
@@ -16,6 +15,8 @@ class KP:
KP.mainWindow = KPMainWindow()
KP.mainWindow.show()
+ KP.enumerateTilesets()
+
KP.app.exec_()
@@ -34,3 +35,57 @@ class KP:
cache[name] = icon
return icon
+
+ @classmethod
+ def enumerateTilesets(cls):
+ try:
+ registry = cls.knownTilesets
+ except AttributeError:
+ registry = {}
+ cls.knownTilesets = registry
+ cls.loadedTilesets = {}
+
+ path = os.path.join(os.getcwd(), 'Tilesets')
+ if not os.path.exists(path):
+ os.mkdir(path)
+
+ for file in os.listdir(path):
+ name = file[:-4]
+
+ if file.endswith('.arc'):
+ filepath = os.path.join(path, file)
+ registry[name] = {'path': filepath}
+
+
+ @classmethod
+ def loadTileset(cls, name):
+ from hashlib import sha256 as sha
+
+ if name in cls.loadedTilesets:
+ return
+
+ filepath = cls.knownTilesets[name]['path']
+ data = open(filepath, 'rb').read()
+
+ tsInfo = cls.knownTilesets[name]
+ newHash = sha(data).hexdigest()
+ if 'hash' in tsInfo and tsInfo['hash'] == newHash:
+ # file hasn't changed
+ return
+
+ tsInfo['hash'] = newHash
+
+ from tileset import KPTileset
+ cls.loadedTilesets[name] = KPTileset.loadFromArc(data)
+
+
+ @classmethod
+ def tileset(cls, name):
+ cache = cls.loadedTilesets
+
+ try:
+ return cache[name]
+ except KeyError:
+ cls.loadTileset(name)
+ return cache[name]
+