Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3c4174d
Added monitor state TypedDict definitions
A-UNDERSCORE-D Aug 1, 2021
481170f
Updated definitions based on feedback
A-UNDERSCORE-D Aug 3, 2021
65464f0
resolved type errors
A-UNDERSCORE-D Aug 3, 2021
649d086
resolved additional suit related errors
A-UNDERSCORE-D Aug 3, 2021
a540e2b
Set SuitCurrent to an empty dict by default
A-UNDERSCORE-D Aug 3, 2021
68354d9
removed comments
A-UNDERSCORE-D Aug 3, 2021
a974b59
re-added import missed in rebase
A-UNDERSCORE-D Aug 4, 2021
b4a42c0
Added rank/reputation/engineers
A-UNDERSCORE-D Aug 4, 2021
ad8b1f7
fixed spell checker complaints
A-UNDERSCORE-D Aug 4, 2021
7a6943d
added modules
A-UNDERSCORE-D Aug 4, 2021
01cc8a2
removed Optional from ShipID, ShipName, and ShipType
A-UNDERSCORE-D Aug 4, 2021
34325a6
workaround for autopep8 issues
A-UNDERSCORE-D Aug 4, 2021
a8b06c7
added suit and suit loadouts
A-UNDERSCORE-D Aug 6, 2021
d79ded6
update state usage
A-UNDERSCORE-D Aug 6, 2021
c4db544
clear up assumptions and type monitor state usage
A-UNDERSCORE-D Aug 6, 2021
9070b67
Re-type plugins as needed for MonitorStateDict
A-UNDERSCORE-D Aug 6, 2021
b0abf0f
change default to 0, rearange comments
A-UNDERSCORE-D Aug 6, 2021
a1dec24
removed Optional for multicrew items
A-UNDERSCORE-D Aug 6, 2021
e43a38e
Noted that 0-1 is a workaround for autopep8
A-UNDERSCORE-D Aug 6, 2021
6ccf6ca
Moved some comments around
A-UNDERSCORE-D Aug 6, 2021
66b39b5
ensured that a missing locName doesnt explode
A-UNDERSCORE-D Aug 6, 2021
c236798
add extra entry for empty crew role
A-UNDERSCORE-D Aug 6, 2021
dc7c745
note hacky use of undoccumented attr
A-UNDERSCORE-D Aug 6, 2021
4724042
missed two Captian and Role sets
A-UNDERSCORE-D Aug 6, 2021
2e245f6
removed TYPE_CHECKING guard
A-UNDERSCORE-D Aug 6, 2021
581a5d8
resolve flake8 complaints
A-UNDERSCORE-D Aug 7, 2021
6a24473
fixed import order
A-UNDERSCORE-D Aug 7, 2021
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
9 changes: 5 additions & 4 deletions EDMarketConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,13 @@ def update_suit_text(self) -> None:
self.suit['text'] = ''
return

if (suit := monitor.state.get('SuitCurrent')) is None:
if (suit := monitor.state['SuitCurrent']) is None:
self.suit['text'] = f'<{_("Unknown")}>' # LANG: Unknown suit
return

suitname = suit['edmcName']

if (suitloadout := monitor.state.get('SuitLoadoutCurrent')) is None:
if (suitloadout := monitor.state['SuitLoadoutCurrent']) is None:
self.suit['text'] = ''
return

Expand Down Expand Up @@ -739,7 +739,7 @@ def set_labels(self):
"""Set main window labels, e.g. after language change."""
self.cmdr_label['text'] = _('Cmdr') + ':' # LANG: Label for commander name in main window
# LANG: 'Ship' or multi-crew role label in main window, as applicable
self.ship_label['text'] = (monitor.state['Captain'] and _('Role') or _('Ship')) + ':' # Main window
self.ship_label['text'] = (_('Role') if monitor.state['Captain'] else _('Ship')) + ':' # Main window
self.suit_label['text'] = _('Suit') + ':' # LANG: Label for 'Suit' line in main UI
self.system_label['text'] = _('System') + ':' # LANG: Label for 'System' line in main UI
self.station_label['text'] = _('Station') + ':' # LANG: Label for 'Station' line in main UI
Expand Down Expand Up @@ -991,7 +991,7 @@ def getandsend(self, event=None, retrying: bool = False): # noqa: C901, CCR001
if monitor.state['Modules']:
self.ship.configure(state=True)

if monitor.state.get('SuitCurrent') is not None:
if monitor.state['SuitCurrent'] is not None:
if (loadout := data.get('loadout')) is not None:
if (suit := loadout.get('suit')) is not None:
if (suitname := suit.get('edmcName')) is not None:
Expand Down Expand Up @@ -1076,6 +1076,7 @@ def crewroletext(role: str) -> str:
"""
return {
None: '',
'': '',
'Idle': '',
'FighterCon': _('Fighter'), # LANG: Multicrew role
'FireCon': _('Gunner'), # LANG: Multicrew role
Expand Down
20 changes: 15 additions & 5 deletions companion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from edmc_data import companion_category_map as category_map
from EDMCLogging import get_main_logger
from monitor import monitor
from monitor_state_dict import SuitDict, SuitLoadoutDict
from protocol import protocolhandler

logger = get_main_logger()
Expand Down Expand Up @@ -388,7 +389,7 @@ def authorize(self, payload: str) -> str: # noqa: CCR001

# All 'FID' seen in Journals so far have been 'F<id>'
# Frontier, Steam and Epic
if f'F{customer_id}' != monitor.state.get('FID'):
if f'F{customer_id}' != monitor.state['FID']:
# LANG: Frontier auth customer_id doesn't match game session FID
raise CredentialsError(_("Error: customer_id doesn't match!"))

Expand Down Expand Up @@ -713,28 +714,37 @@ def suit_update(self, data: CAPIData) -> None:

:param data: CAPI data to extra suit data from.
"""
current_suit: Optional[SuitDict]
if (current_suit := data.get('suit')) is None:
# Probably no Odyssey on the account, so point attempting more.
return

monitor.state['SuitCurrent'] = current_suit
# It's easier to always have this in the 'sparse array' dict form
suits = data.get('suits')
suits: Optional[Union[List[SuitDict], Dict[int, SuitDict]]] = data.get('suits')
if isinstance(suits, list):
monitor.state['Suits'] = dict(enumerate(suits))

else:
elif isinstance(suits, dict):
monitor.state['Suits'] = suits
else:
# If it was neither, it didn't exist, so ... dont muck with it, as something is either broken or
# we didn't see a bunch of info.
pass

# We need to be setting our edmcName for all suits
loc_name = monitor.state['SuitCurrent'].get('locName', monitor.state['SuitCurrent']['name'])
monitor.state['SuitCurrent']['edmcName'] = monitor.suit_sane_name(loc_name)
if (current_suit := monitor.state['SuitCurrent']) is not None:
loc_name = current_suit['locName'] if current_suit.get('locName') else current_suit['name']
current_suit['edmcName'] = monitor.suit_sane_name(loc_name)

for s in monitor.state['Suits']:
loc_name = monitor.state['Suits'][s].get('locName', monitor.state['Suits'][s]['name'])
monitor.state['Suits'][s]['edmcName'] = monitor.suit_sane_name(loc_name)

suit_loadouts: Optional[Union[List[SuitLoadoutDict], Dict[int, SuitLoadoutDict]]]
if (suit_loadouts := data.get('loadouts')) is None:
logger.warning('CAPI data had "suit" but no (suit) "loadouts"')
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is the change of behaviour you mentioned on Discord.

Before this if CAPI says no suit loadouts we'll None our copy. With this, it won't.

So now the question is do we really distrust CAPI that much ? I'm inclined to allow this change as the Journal is in much better shape and we should always be picking things up properly from it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah Im undecided here. The other option is to blank our loadouts and return?


monitor.state['SuitLoadoutCurrent'] = data.get('loadout')
# It's easier to always have this in the 'sparse array' dict form
Expand Down
Loading