-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathload.py
executable file
·50 lines (43 loc) · 1.39 KB
/
load.py
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
#!/usr/bin/python3
import glob,os,dataclasses
DIRDUNGEONS='MEDIA/DUNGEONS'
REFERENCE='/media/sda2/windows/steam/steamapps/common/Torchlight II/'#TODO make argument
DIRMAPS='media/units/items/maps'
@dataclasses.dataclass
class Dungeon:
name:str
dungeonname:str
scroll:str='catacombsmapa105' #technically a Map but that's a highlighted Python function
def topath(self,path,filename):
return f'{path}/{filename}.dat'
def __post_init__(self):
self.dungeon=self.topath(DIRDUNGEONS,self.dungeonname)
self.scroll=self.topath(DIRMAPS,self.scroll)
dungeons=[]
def findnames(path):
names=[]
with open(path,encoding='utf-16') as f:
for l in f.readlines():
if 'DISPLAYNAME:' in l:
names.append(l[l.index(':')+1:l.index('\n')])
return names
def scan(query='*.DAT',prefix=f'{REFERENCE}/{DIRDUNGEONS}/'):
scanned=[]
duplicates=set()
for m in glob.glob(prefix+query):
if 'QA_ARENA' in m:
print(f'skip arena: {m}...')
continue
try:
name=os.path.basename(m)
name=name[:name.index('.')]
displayname=findnames(f'{REFERENCE}/{DIRDUNGEONS}/{name.upper()}.DAT')[0]
d=Dungeon(displayname,name.lower())
if d.dungeonname in duplicates:
raise Exception('Duplicate name: '+self.name)
duplicates.add(d.dungeonname)
scanned.append(d)
except Exception as e:
print('error: '+m)
raise e
return scanned