forked from pyfa-org/Pyfa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamicattributes.py
75 lines (55 loc) · 2.59 KB
/
dynamicattributes.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
75
#!/usr/bin/env python2.7
"""
This script will generate a dynamicItemAttributes.json file using res files
"""
import argparse
import json
import os
from shutil import copyfile
parser = argparse.ArgumentParser(description='This script updates module icons for pyfa')
parser.add_argument('-e', '--eve', required=True, type=str, help='path to eve\'s ')
parser.add_argument('-s', '--server', required=False, default='tq', type=str, help='which server to use (defaults to tq)')
args = parser.parse_args()
LOADER_FILE = 'app:/bin/dynamicItemAttributesLoader.pyd'
RES_FILE = 'res:/staticdata/dynamicitemattributes.fsdbinary'
binaryfile = os.path.split(RES_FILE)[1]
eve_path = os.path.join(args.eve, 'index_{}.txt'.format(args.server))
with open(eve_path, 'r') as f:
lines = f.readlines()
file_index = {x.split(',')[0]: x.split(',') for x in lines}
resfileindex = file_index['app:/resfileindex.txt']
res_cache = os.path.join(args.eve, 'ResFiles')
with open(os.path.join(res_cache, resfileindex[1]), 'r') as f:
lines = f.readlines()
res_index = {x.split(',')[0].lower(): x.split(',') for x in lines}
# Need to copy the file to our cuirrent directory
attribute_loader_file = os.path.join(res_cache, file_index[LOADER_FILE][1])
to_path = os.path.dirname(os.path.abspath(__file__))
copyfile(attribute_loader_file, os.path.join(os.path.dirname(os.path.abspath(__file__)), os.path.split(LOADER_FILE)[1]))
# The loader expect it to be the correct filename, so copy trhe file as well
dynattribute_file = os.path.join(res_cache, res_index[RES_FILE.lower()][1])
to_path = os.path.dirname(os.path.abspath(__file__))
copyfile(dynattribute_file, os.path.join(os.path.dirname(os.path.abspath(__file__)), binaryfile))
import dynamicItemAttributesLoader
attributes = dynamicItemAttributesLoader.load(os.path.join(to_path, binaryfile))
attributes_obj = {}
# convert top level to dict
attributes = dict(attributes)
# This is such a brute force method. todo: recursively generate this by inspecting the objects
for k, v in attributes.items():
attributes_obj[k] = {
'attributeIDs': dict(v.attributeIDs),
'inputOutputMapping': list(v.inputOutputMapping)
}
for i, x in enumerate(v.inputOutputMapping):
attributes_obj[k]['inputOutputMapping'][i] = {
'resultingType': x.resultingType,
'applicableTypes': list(x.applicableTypes)
}
for k2, v2 in v.attributeIDs.items():
attributes_obj[k]['attributeIDs'][k2] = {
'min': v2.min,
'max': v2.max
}
with open('dynamicattributes.json', 'w') as outfile:
json.dump(attributes_obj, outfile)