summaryrefslogtreecommitdiff
path: root/src/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.py')
-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]
+