1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-12 15:27:14 +03:00

Merge pull request #2266 from HullSeals/enhancement/2262/generate-inara-slef

[2262] Generate Inara SLEF
This commit is contained in:
David Sangrey 2024-07-21 23:29:49 -04:00 committed by GitHub
commit 2a9a7f19e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 124 additions and 42 deletions

View File

@ -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";

View File

@ -51,7 +51,8 @@ if __name__ == "__main__":
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']}

View File

@ -21,9 +21,10 @@ from time import gmtime, localtime, mktime, sleep, strftime, strptime, time
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
@ -109,6 +110,7 @@ class EDLogs(FileSystemEventHandler):
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
@ -701,6 +703,34 @@ class EDLogs(FileSystemEventHandler):
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']] = {

View File

@ -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
}
}

View File

@ -194,6 +194,10 @@ class HyperlinkLabel(tk.Label or ttk.Label): # type: ignore
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(
@ -224,3 +228,8 @@ class HyperlinkLabel(tk.Label or ttk.Label): # type: ignore
"""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)