-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
74 lines (55 loc) · 2.04 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
from pathlib import Path
from analyse import Analyse
from unity_asset_dir import get_dbs
from unity_unpack import unpack_dbs
def hashable_res(block):
# The inner tuples must contain everything the optimizer cares about
res = sorted((m, rk, rv)
for m in ('inputs', 'optionalInputs', 'outputs')
for rk, rv in block[m].items())
with_conns = (tuple(res), *(block['connectUpper' + d] for d in ('Forward', 'Back', 'Left', 'Right')))
return with_conns
def trim(blocks):
old_len = len(blocks)
while True:
try:
i = next(i for i, b in enumerate(blocks)
if b['category'] == 'WILD_TILES' or b['toolTipHeader'] == 'CANAL BRIDGE')
except StopIteration:
break
del blocks[i]
len_after_un = len(blocks)
blocks_hashable = sorted((hashable_res(b), ib) for ib, b in enumerate(blocks))
to_remove = set()
i = 0
while i < len(blocks_hashable)-1:
res, ib = blocks_hashable[i]
for j in range(i+1, len(blocks_hashable)):
next_res, next_ib = blocks_hashable[j]
if res == next_res:
to_remove.add(next_ib)
else:
break
i = j
for ib in sorted(to_remove, reverse=True):
del blocks[ib]
print('Trimmed blocks: %d unavailable, %d equivalent.' % (old_len - len_after_un,
len_after_un - len(blocks)))
def export_blocks(blocks):
from csv import DictWriter
keys = tuple(blocks[0].keys())
with open('blocks.csv', 'w', encoding='utf-8', newline='') as f:
w = DictWriter(f, keys)
w.writeheader()
for b in blocks:
w.writerow(b)
def main() -> None:
block_db, resource_db = get_dbs(Path(r'D:\SteamLibrary'))
blocks, resources = unpack_dbs(block_db['data'], resource_db['data'])
# export_blocks(blocks)
trim(blocks)
print()
Analyse(blocks, resources).analyse()
if __name__ == '__main__':
main()