Skip to content

Commit

Permalink
[2262] Simplify SLEF Building
Browse files Browse the repository at this point in the history
  • Loading branch information
Rixxan committed Jun 19, 2024
1 parent c60c048 commit d478a68
Showing 1 changed file with 17 additions and 38 deletions.
55 changes: 17 additions & 38 deletions plugins/inara.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ def journal_entry( # noqa: C901, CCR001
cur_ship['shipRebuyCost'] = state['Rebuy']

new_add_event('setCommanderShip', entry['timestamp'], cur_ship)
make_slef(state, entry)
make_slef(entry)

# Stored modules
if event_name == 'StoredModules':
Expand Down Expand Up @@ -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 = {
"header": {"appName": appname, "appVersion": str(appversion())}
}
data_dict = {}
loadout = make_loadout(state)
modules = loadout['shipLoadout']
mod_dict = []
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 = 2**int(cap[0])
ship = edmc_data.ship_name_map[state["ShipType"]]
fuel = {'Main': cap, 'Reserve': ships[ship]['reserveFuelCapacity']}
data_dict.update({"FuelCapacity": fuel})
mod_dict.append(builder)
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 = edmc_data.ship_name_map[entry["Ship"]]
fuel = {'Main': cap, 'Reserve': ships[ship]['reserveFuelCapacity']}
data_dict.update({"FuelCapacity": fuel})
data_dict.update({
'Ship': state["ShipType"],
'ShipName': state['ShipName'],
'ShipIdent': state['ShipIdent'],
'HullValue': state['HullValue'],
'ModulesValue': state['ModulesValue'],
'Rebuy': state['Rebuy'],
'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': mod_dict,
'Modules': entry['Modules'],
})
initial_dict.update({'data': data_dict})
json.dump(initial_dict, open('inara.json', 'w'), indent=4)
Expand Down

0 comments on commit d478a68

Please sign in to comment.