Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2262] Generate Inara SLEF #2266

Merged
merged 9 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions L10n/en.template
Original file line number Diff line number Diff line change
Expand Up @@ -813,3 +813,6 @@

/* ttkHyperlinkLabel.py: Open Element In Selected Provider; */
"Open in {URL}" = "Open in {URL}";

/* ttkHyperlinkLabel.py: Copy the Inara SLEF Format of the active ship to the clipboard; */
"Copy Inara SLEF" = "Copy Inara SLEF";
3 changes: 2 additions & 1 deletion coriolis-update-files.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def add(modules, name, attributes) -> None:
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']}
ships[name] = {'hullMass': m['properties']['hullMass'],
'reserveFuelCapacity': m['properties']['reserveFuelCapacity']}
for i, bulkhead in enumerate(bulkheads):
modules['_'.join([reverse_ship_map[name], 'armour', bulkhead])] = {'mass': m['bulkheads'][i]['mass']}

Expand Down
34 changes: 32 additions & 2 deletions monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
from typing import TYPE_CHECKING, Any, BinaryIO, MutableMapping
import semantic_version
import util_ships
from config import config
from edmc_data import edmc_suit_shortnames, edmc_suit_symbol_localised
from config import config, appname, appversion
from edmc_data import edmc_suit_shortnames, edmc_suit_symbol_localised, ship_name_map
from EDMCLogging import get_main_logger
from edshipyard import ships

if TYPE_CHECKING:
import tkinter
Expand Down Expand Up @@ -109,6 +110,7 @@ def __init__(self) -> None:
self.group: str | None = None
self.cmdr: str | None = None
self.started: int | None = None # Timestamp of the LoadGame event
self.slef: str | None = None

self._navroute_retries_remaining = 0
self._last_navroute_journal_timestamp: float | None = None
Expand Down Expand Up @@ -701,6 +703,34 @@ def parse_entry(self, line: bytes) -> MutableMapping[str, Any]: # noqa: C901, C
module.pop('AmmoInHopper')

self.state['Modules'][module['Slot']] = module
# SLEF
initial_dict: dict[str, dict[str, Any]] = {
"header": {"appName": appname, "appVersion": str(appversion())}
}
data_dict = {}
for module in entry['Modules']:
if module.get('Slot') == 'FuelTank':
cap = module['Item'].split('size')
cap = cap[1].split('_')
cap = 2 ** int(cap[0])
ship = ship_name_map[entry["Ship"]]
fuel = {'Main': cap, 'Reserve': ships[ship]['reserveFuelCapacity']}
data_dict.update({"FuelCapacity": fuel})
data_dict.update({
'Ship': entry["Ship"],
'ShipName': entry['ShipName'],
'ShipIdent': entry['ShipIdent'],
'HullValue': entry['HullValue'],
'ModulesValue': entry['ModulesValue'],
'Rebuy': entry['Rebuy'],
'MaxJumpRange': entry['MaxJumpRange'],
'UnladenMass': entry['UnladenMass'],
'CargoCapacity': entry['CargoCapacity'],
'Modules': entry['Modules'],
})
initial_dict.update({'data': data_dict})
output = json.dumps(initial_dict, indent=4)
self.slef = str(f"[{output}]")

elif event_type == 'modulebuy':
self.state['Modules'][entry['Slot']] = {
Expand Down
117 changes: 78 additions & 39 deletions ships.json
Original file line number Diff line number Diff line change
@@ -1,119 +1,158 @@
{
"Adder": {
"hullMass": 35
"hullMass": 35,
"reserveFuelCapacity": 0.36
},
"Alliance Challenger": {
"hullMass": 450
"hullMass": 450,
"reserveFuelCapacity": 0.77
},
"Alliance Chieftain": {
"hullMass": 400
"hullMass": 400,
"reserveFuelCapacity": 0.77
},
"Alliance Crusader": {
"hullMass": 500
"hullMass": 500,
"reserveFuelCapacity": 0.77
},
"Anaconda": {
"hullMass": 400
"hullMass": 400,
"reserveFuelCapacity": 1.07
},
"Asp Explorer": {
"hullMass": 280
"hullMass": 280,
"reserveFuelCapacity": 0.63
},
"Asp Scout": {
"hullMass": 150
"hullMass": 150,
"reserveFuelCapacity": 0.47
},
"Beluga Liner": {
"hullMass": 950
"hullMass": 950,
"reserveFuelCapacity": 0.81
},
"Cobra MkIII": {
"hullMass": 180
"hullMass": 180,
"reserveFuelCapacity": 0.49
},
"Cobra MkIV": {
"hullMass": 210
"hullMass": 210,
"reserveFuelCapacity": 0.51
},
"Diamondback Explorer": {
"hullMass": 260
"hullMass": 260,
"reserveFuelCapacity": 0.52
},
"Diamondback Scout": {
"hullMass": 170
"hullMass": 170,
"reserveFuelCapacity": 0.49
},
"Dolphin": {
"hullMass": 140
"hullMass": 140,
"reserveFuelCapacity": 0.5
},
"Eagle": {
"hullMass": 50
"hullMass": 50,
"reserveFuelCapacity": 0.34
},
"Federal Assault Ship": {
"hullMass": 480
"hullMass": 480,
"reserveFuelCapacity": 0.72
},
"Federal Corvette": {
"hullMass": 900
"hullMass": 900,
"reserveFuelCapacity": 1.13
},
"Federal Dropship": {
"hullMass": 580
"hullMass": 580,
"reserveFuelCapacity": 0.83
},
"Federal Gunship": {
"hullMass": 580
"hullMass": 580,
"reserveFuelCapacity": 0.82
},
"Fer-de-Lance": {
"hullMass": 250
"hullMass": 250,
"reserveFuelCapacity": 0.67
},
"Hauler": {
"hullMass": 14
"hullMass": 14,
"reserveFuelCapacity": 0.25
},
"Imperial Clipper": {
"hullMass": 400
"hullMass": 400,
"reserveFuelCapacity": 0.74
},
"Imperial Courier": {
"hullMass": 35
"hullMass": 35,
"reserveFuelCapacity": 0.41
},
"Imperial Cutter": {
"hullMass": 1100
"hullMass": 1100,
"reserveFuelCapacity": 1.16
},
"Imperial Eagle": {
"hullMass": 50
"hullMass": 50,
"reserveFuelCapacity": 0.37
},
"Keelback": {
"hullMass": 180
"hullMass": 180,
"reserveFuelCapacity": 0.39
},
"Krait MkII": {
"hullMass": 320
"hullMass": 320,
"reserveFuelCapacity": 0.63
},
"Krait Phantom": {
"hullMass": 270
"hullMass": 270,
"reserveFuelCapacity": 0.63
},
"Mamba": {
"hullMass": 250
"hullMass": 250,
"reserveFuelCapacity": 0.5
},
"Orca": {
"hullMass": 290
"hullMass": 290,
"reserveFuelCapacity": 0.79
},
"Python": {
"hullMass": 350
"hullMass": 350,
"reserveFuelCapacity": 0.83
},
"Python Mk II": {
"hullMass": 450
"hullMass": 450,
"reserveFuelCapacity": 0.83
},
"Sidewinder": {
"hullMass": 25
"hullMass": 25,
"reserveFuelCapacity": 0.3
},
"Type-10 Defender": {
"hullMass": 1200
"hullMass": 1200,
"reserveFuelCapacity": 0.77
},
"Type-6 Transporter": {
"hullMass": 155
"hullMass": 155,
"reserveFuelCapacity": 0.39
},
"Type-7 Transporter": {
"hullMass": 350
"hullMass": 350,
"reserveFuelCapacity": 0.52
},
"Type-9 Heavy": {
"hullMass": 850
"hullMass": 850,
"reserveFuelCapacity": 0.77
},
"Viper MkIII": {
"hullMass": 50
"hullMass": 50,
"reserveFuelCapacity": 0.41
},
"Viper MkIV": {
"hullMass": 190
"hullMass": 190,
"reserveFuelCapacity": 0.46
},
"Vulture": {
"hullMass": 230
"hullMass": 230,
"reserveFuelCapacity": 0.57
}
}
9 changes: 9 additions & 0 deletions ttkHyperlinkLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ def _contextmenu(self, event: tk.Event) -> None:
menu.add_command(label=tr.tl('Copy'), command=self.copy) # As in Copy and Paste

if self.name == 'ship':
# LANG: Copy the Inara SLEF Format of the active ship to the clipboard
menu.add_command(label=tr.tl('Copy Inara SLEF'), command=self.copy_slef, state=tk.DISABLED)
menu.entryconfigure(1, state=monitor.slef and tk.NORMAL or tk.DISABLED)

menu.add_separator()
for url in plug.provides('shipyard_url'):
menu.add_command(
Expand Down Expand Up @@ -224,3 +228,8 @@ def copy(self) -> None:
"""Copy the current text to the clipboard."""
self.clipboard_clear()
self.clipboard_append(self['text'])

def copy_slef(self) -> None:
"""Copy the current text to the clipboard."""
self.clipboard_clear()
self.clipboard_append(monitor.slef)
Loading