1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-04 01:21:03 +03:00

[2262] Simplify SLEF Building

This commit is contained in:
David Sangrey 2024-06-18 21:15:11 -04:00
parent c60c0483b4
commit d478a68bc6
No known key found for this signature in database
GPG Key ID: 3AEADBB0186884BC

View File

@ -871,7 +871,7 @@ def journal_entry( # noqa: C901, CCR001
cur_ship['shipRebuyCost'] = state['Rebuy'] cur_ship['shipRebuyCost'] = state['Rebuy']
new_add_event('setCommanderShip', entry['timestamp'], cur_ship) new_add_event('setCommanderShip', entry['timestamp'], cur_ship)
make_slef(state, entry) make_slef(entry)
# Stored modules # Stored modules
if event_name == 'StoredModules': if event_name == 'StoredModules':
@ -1478,51 +1478,30 @@ def make_loadout(state: dict[str, Any]) -> dict[str, Any]: # noqa: CCR001
} }
def make_slef(state: dict[str, Any], entry) -> None: def make_slef(entry) -> None:
initial_dict = { initial_dict = {
"header": {"appName": appname, "appVersion": str(appversion())} "header": {"appName": appname, "appVersion": str(appversion())}
} }
data_dict = {} data_dict = {}
loadout = make_loadout(state) for module in entry['Modules']:
modules = loadout['shipLoadout'] if module.get('Slot') == 'FuelTank':
mod_dict = [] cap = module['Item'].split('size')
for module in modules:
if module['slotName']:
builder = {
'Slot': module['slotName'],
'Item': module['itemName']
}
if module.get('itemHealth'):
builder.update({'ItemHealth': module['itemHealth']})
if module.get('isOn'):
builder.update({'On': True})
elif not module.get('isOn'):
builder.update({'On': False})
if module.get('itemPriority'):
builder.update({'Priority': module['itemPriority']})
if module.get('itemValue'):
builder.update({'Value': module['itemValue']})
if not module.get('itemValue'):
builder.update({'Value': 0})
if module.get('slotName') == 'FuelTank':
cap = module['itemName'].split('size')
cap = cap[1].split('_') cap = cap[1].split('_')
cap = 2 ** int(cap[0]) cap = 2 ** int(cap[0])
ship = edmc_data.ship_name_map[state["ShipType"]] ship = edmc_data.ship_name_map[entry["Ship"]]
fuel = {'Main': cap, 'Reserve': ships[ship]['reserveFuelCapacity']} fuel = {'Main': cap, 'Reserve': ships[ship]['reserveFuelCapacity']}
data_dict.update({"FuelCapacity": fuel}) data_dict.update({"FuelCapacity": fuel})
mod_dict.append(builder)
data_dict.update({ data_dict.update({
'Ship': state["ShipType"], 'Ship': entry["Ship"],
'ShipName': state['ShipName'], 'ShipName': entry['ShipName'],
'ShipIdent': state['ShipIdent'], 'ShipIdent': entry['ShipIdent'],
'HullValue': state['HullValue'], 'HullValue': entry['HullValue'],
'ModulesValue': state['ModulesValue'], 'ModulesValue': entry['ModulesValue'],
'Rebuy': state['Rebuy'], 'Rebuy': entry['Rebuy'],
'MaxJumpRange': entry['MaxJumpRange'], 'MaxJumpRange': entry['MaxJumpRange'],
'UnladenMass': entry['UnladenMass'], 'UnladenMass': entry['UnladenMass'],
'CargoCapacity': entry['CargoCapacity'], 'CargoCapacity': entry['CargoCapacity'],
'Modules': mod_dict, 'Modules': entry['Modules'],
}) })
initial_dict.update({'data': data_dict}) initial_dict.update({'data': data_dict})
json.dump(initial_dict, open('inara.json', 'w'), indent=4) json.dump(initial_dict, open('inara.json', 'w'), indent=4)