mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-16 09:10:35 +03:00
Suits: Set/update suit text as necessary.
* After any Journal event we might as well set it. * Attempt to update on a `SwitchSuitLoadout` event, assuming the new slot is one we heard about in the last CAPI data.
This commit is contained in:
parent
29c059c275
commit
c28dd8c55d
@ -604,6 +604,19 @@ class AppWindow(object):
|
||||
self.postprefs(False) # Companion login happens in callback from monitor
|
||||
self.toggle_suit_row(visible=False)
|
||||
|
||||
def update_suit_text(self) -> None:
|
||||
"""Update the suit text for current type and loadout."""
|
||||
if (suit := monitor.state.get('SuitCurrent')) is None:
|
||||
return
|
||||
|
||||
suitname = suit['locName']
|
||||
|
||||
if (suitloadout := monitor.state.get('SuitLoadoutCurrent')) is None:
|
||||
return
|
||||
|
||||
loadout_name = suitloadout['name']
|
||||
self.suit['text'] = f'{suitname} ({loadout_name})'
|
||||
|
||||
def toggle_suit_row(self, visible: Optional[bool] = None) -> None:
|
||||
"""
|
||||
Toggle the visibility of the 'Suit' row.
|
||||
@ -1035,6 +1048,8 @@ class AppWindow(object):
|
||||
self.ship_label['text'] = _('Ship') + ':' # Main window
|
||||
self.ship['text'] = ''
|
||||
|
||||
self.update_suit_text()
|
||||
|
||||
self.edit_menu.entryconfigure(0, state=monitor.system and tk.NORMAL or tk.DISABLED) # Copy
|
||||
|
||||
if entry['event'] in (
|
||||
|
27
monitor.py
27
monitor.py
@ -827,6 +827,33 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
|
||||
if self.state['BackPack'][c][m] < 0:
|
||||
self.state['BackPack'][c][m] = 0
|
||||
|
||||
elif event_type == 'SwitchSuitLoadout':
|
||||
loadoutid = entry['LoadoutID']
|
||||
# Observed LoadoutID in SwitchSuitLoadout events are, e.g.
|
||||
# 4293000005 for CAPI slot 5.
|
||||
# This *might* actually be "lower 6 bits", but maybe it's not.
|
||||
new_slot = loadoutid - 4293000000
|
||||
try:
|
||||
self.state['SuitLoadoutCurrent'] = self.state['SuitLoadouts'][f'{new_slot}']
|
||||
|
||||
except KeyError:
|
||||
logger.exception(f"Getting suit loadout after switch, bad slot: {new_slot} ({loadoutid})")
|
||||
# Might mean that a new suit loadout was created and we need a new CAPI fetch ?
|
||||
|
||||
else:
|
||||
try:
|
||||
new_suitid = self.state['SuitLoadoutCurrent']['suit']['suitId']
|
||||
|
||||
except KeyError:
|
||||
logger.exception(f"Getting switched-to suit ID from slot {new_slot} ({loadoutid})")
|
||||
|
||||
else:
|
||||
try:
|
||||
self.state['SuitCurrent'] = self.state['Suits'][f'{new_suitid}']
|
||||
|
||||
except KeyError:
|
||||
logger.exception(f"Getting switched-to suit from slot {new_slot} ({loadoutid}")
|
||||
|
||||
elif event_type == 'NavRoute':
|
||||
# Added in ED 3.7 - multi-hop route details in NavRoute.json
|
||||
with open(join(self.currentdir, 'NavRoute.json'), 'rb') as rf: # type: ignore
|
||||
|
Loading…
x
Reference in New Issue
Block a user