blob: 951e927107b6b2ab2a4227f5979e9a24cf1bec2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
from common import *
class KP:
@staticmethod
def run():
KP.app = QtGui.QApplication(sys.argv)
KP.app.settings = QtCore.QSettings('Koopatlas', 'Newer Team')
from mapdata import KPMap
KP.map = KPMap()
from ui import KPMainWindow
KP.mainWindow = KPMainWindow()
KP.mainWindow.show()
KP.enumerateTilesets()
KP.app.exec_()
@classmethod
def icon(cls, name):
try:
cache = cls.iconCache
except AttributeError:
cache = {}
cls.iconCache = cache
try:
return cache[name]
except KeyError:
icon = QtGui.QIcon('Resources/%s.png' % name)
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
import time
b = time.clock()
cls.loadedTilesets[name] = KPTileset.loadFromArc(data)
e = time.clock()
print "Loading set: {0} in {1}".format(name, e-b)
@classmethod
def tileset(cls, name):
cache = cls.loadedTilesets
try:
return cache[name]
except KeyError:
cls.loadTileset(name)
return cache[name]
|