-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathcoriolis-update-files.py
executable file
·105 lines (89 loc) · 3.59 KB
/
coriolis-update-files.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""
coriolis-update-files.py - Build ship and module databases from https://github.com/EDCD/coriolis-data/.
Copyright (c) EDCD, All Rights Reserved
Licensed under the GNU General Public License.
See LICENSE file.
This script also utilizes the file outfitting.csv. Due to how collate.py
both reads and writes to this file, a local copy in the root of the
project structure is used for this purpose. If you want to utilize the
FDevIDs/ version of the file, copy it over the local one.
"""
import json
import subprocess
import sys
from collections import OrderedDict
import outfitting
from edmc_data import coriolis_ship_map, ship_name_map
if __name__ == "__main__":
def add(modules, name, attributes) -> None:
"""Add the given module to the modules dict."""
assert (
name not in modules or modules[name] == attributes
), f"{name}: {modules.get(name)} != {attributes}"
assert name not in modules, name
modules[name] = attributes
# Regenerate coriolis-data distribution
subprocess.check_call(
"npm install",
cwd="coriolis-data",
shell=True,
stdout=sys.stdout,
stderr=sys.stderr,
)
data = json.load(open("coriolis-data/dist/index.json"))
# Symbolic name from in-game name
reverse_ship_map = {v: k for k, v in list(ship_name_map.items())}
bulkheads = list(outfitting.armour_map.keys())
ships = {}
modules = {}
# Ship and armour masses
for m in list(data["Ships"].values()):
name = coriolis_ship_map.get(
m["properties"]["name"], str(m["properties"]["name"])
)
assert name in reverse_ship_map, name
ships[name] = {"hullMass": m["properties"]["hullMass"]}
for i in range(len(bulkheads)):
modules["_".join([reverse_ship_map[name], "armour", bulkheads[i]])] = {
"mass": m["bulkheads"][i]["mass"]
}
ships = OrderedDict(
[(k, ships[k]) for k in sorted(ships)]
) # sort for easier diffing
with open("resources/ships.json", "w") as ships_file:
json.dump(ships, ships_file, indent=4)
# Module masses
for cat in list(data["Modules"].values()):
for grp, mlist in list(cat.items()):
for m in mlist:
assert "symbol" in m, m
key = str(m["symbol"].lower())
if grp == "fsd":
modules[key] = {
"mass": m["mass"],
"optmass": m["optmass"],
"maxfuel": m["maxfuel"],
"fuelmul": m["fuelmul"],
"fuelpower": m["fuelpower"],
}
elif grp == "gfsb":
modules[key] = {
"mass": m["mass"],
"jumpboost": m["jumpboost"],
}
else:
modules[key] = {
"mass": m.get("mass", 0)
} # Some modules don't have mass
# Pre 3.3 modules
add(modules, "int_stellarbodydiscoveryscanner_standard", {"mass": 2})
add(modules, "int_stellarbodydiscoveryscanner_intermediate", {"mass": 2})
add(modules, "int_stellarbodydiscoveryscanner_advanced", {"mass": 2})
# Missing
add(modules, "hpt_multicannon_fixed_small_advanced", {"mass": 2})
add(modules, "hpt_multicannon_fixed_medium_advanced", {"mass": 4})
modules = OrderedDict(
[(k, modules[k]) for k in sorted(modules)]
) # sort for easier diffing
with open("modules.json", "w") as modules_file:
json.dump(modules, modules_file, indent=4)