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

monitor: Change .system to state['SystemName']

1. EDDB plugin needs to track the system name, but we're moving all of that
  into monitor.py.
2. monitor.py was tracking this in monitor.system, but it needs to be in
  monitor.state['SystemName'] in order for plugins to access it.

So, move monitor.system to monitor.state['SystemName'] and update all uses.
This commit is contained in:
Athanasius 2023-01-09 15:05:29 +00:00
parent dab69367e2
commit fa1c072d9e
No known key found for this signature in database
GPG Key ID: 772697E181BB2767
4 changed files with 43 additions and 30 deletions

11
EDMC.py

@ -326,7 +326,7 @@ sys.path: {sys.path}'''
raise companion.CmdrError()
elif (
data['lastSystem']['name'] != monitor.system or
data['lastSystem']['name'] != monitor.state['SystemName'] or
((data['commander']['docked'] and data['lastStarport']['name'] or None) != monitor.station) or
data['ship']['id'] != monitor.state['ShipID'] or
data['ship']['name'].lower() != monitor.state['ShipType']
@ -431,10 +431,11 @@ sys.path: {sys.path}'''
new_data = capi_response.capi_data
# might have undocked while we were waiting for retry in which case station data is unreliable
if new_data['commander'].get('docked') and \
deep_get(new_data, 'lastSystem', 'name') == monitor.system and \
deep_get(new_data, 'lastStarport', 'name') == monitor.station:
if (
new_data['commander'].get('docked')
and deep_get(new_data, 'lastSystem', 'name') == monitor.state['SystemName']
and deep_get(new_data, 'lastStarport', 'name') == monitor.station
):
data = new_data
if args.s:

@ -1089,7 +1089,7 @@ class AppWindow(object):
self.status['text'] = _('CAPI query aborted: GameVersion unknown')
return
if not monitor.system:
if not monitor.state['SystemName']:
logger.trace_if('capi.worker', 'Aborting Query: Current star system unknown')
# LANG: CAPI queries aborted because current star system name unknown
self.status['text'] = _('CAPI query aborted: Current system unknown')
@ -1272,9 +1272,10 @@ class AppWindow(object):
f"not {capi_response.capi_data['commander'].get('docked')!r}")
raise companion.ServerLagging()
elif capi_response.capi_data['lastSystem']['name'] != monitor.system:
elif capi_response.capi_data['lastSystem']['name'] != monitor.state['SystemName']:
# CAPI system must match last journal one
logger.warning(f"{capi_response.capi_data['lastSystem']['name']!r} != {monitor.system!r}")
logger.warning(f"{capi_response.capi_data['lastSystem']['name']!r} != "
f"{monitor.state['SystemName']!r}")
raise companion.ServerLagging()
elif capi_response.capi_data['lastStarport']['name'] != monitor.station:
@ -1526,7 +1527,7 @@ class AppWindow(object):
self.update_suit_text()
self.suit_show_if_set()
self.edit_menu.entryconfigure(0, state=monitor.system and tk.NORMAL or tk.DISABLED) # Copy
self.edit_menu.entryconfigure(0, state=monitor.state['SystemName'] and tk.NORMAL or tk.DISABLED) # Copy
if entry['event'] in (
'Undocked',
@ -1589,7 +1590,7 @@ class AppWindow(object):
err = plug.notify_journal_entry(
monitor.cmdr,
monitor.is_beta,
monitor.system,
monitor.state['SystemName'],
monitor.station,
entry,
monitor.state
@ -1728,11 +1729,16 @@ class AppWindow(object):
def system_url(self, system: str) -> str | None:
"""Despatch a system URL to the configured handler."""
return plug.invoke(config.get_str('system_provider'), 'EDSM', 'system_url', monitor.system)
return plug.invoke(
config.get_str('system_provider'), 'EDSM', 'system_url', monitor.state['SystemName']
)
def station_url(self, station: str) -> str | None:
"""Despatch a station URL to the configured handler."""
return plug.invoke(config.get_str('station_provider'), 'eddb', 'station_url', monitor.system, monitor.station)
return plug.invoke(
config.get_str('station_provider'), 'eddb', 'station_url',
monitor.state['SystemName'], monitor.station
)
def cooldown(self) -> None:
"""Display and update the cooldown timer for 'Update' button."""
@ -1746,12 +1752,14 @@ class AppWindow(object):
else:
self.button['text'] = self.theme_button['text'] = _('Update') # LANG: Update button in main window
self.button['state'] = self.theme_button['state'] = (monitor.cmdr and
monitor.mode and
monitor.mode != 'CQC' and
not monitor.state['Captain'] and
monitor.system and
tk.NORMAL or tk.DISABLED)
self.button['state'] = self.theme_button['state'] = (
monitor.cmdr and
monitor.mode and
monitor.mode != 'CQC' and
not monitor.state['Captain'] and
monitor.state['SystemName'] and
tk.NORMAL or tk.DISABLED
)
if sys.platform == 'win32':
def ontop_changed(self, event=None) -> None:
@ -1761,9 +1769,12 @@ class AppWindow(object):
def copy(self, event=None) -> None:
"""Copy system, and possible station, name to clipboard."""
if monitor.system:
if monitor.state['SystemName']:
self.w.clipboard_clear()
self.w.clipboard_append(monitor.station and f'{monitor.system},{monitor.station}' or monitor.system)
self.w.clipboard_append(
f"{monitor.state['SystemName']},{monitor.station}" if monitor.station
else monitor.state['SystemName']
)
def help_general(self, event=None) -> None:
"""Open Wiki Help page in browser."""
@ -1898,7 +1909,7 @@ class AppWindow(object):
defaultextension=default_extension,
filetypes=[('JSON', '.json'), ('All Files', '*')],
initialdir=config.get_str('outdir'),
initialfile=f'{monitor.system}.{monitor.station}.{timestamp}'
initialfile=f"{monitor.state['SystemName']}.{monitor.station}.{timestamp}"
)
if not f:
return

@ -116,7 +116,6 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.mode: str | None = None
self.group: str | None = None
self.cmdr: str | None = None
self.system: str | None = None
self.systempopulation: int | None = None
self.station: str | None = None
self.station_marketid: int | None = None
@ -191,6 +190,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
'Dropship': None, # Best effort as to whether or not the above taxi is a dropship.
'StarPos': None, # Best effort current system's galaxy position.
'SystemAddress': None,
'SystemName': None,
'Body': None,
'BodyID': None,
'BodyType': None,
@ -303,7 +303,6 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.mode = None
self.group = None
self.cmdr = None
self.system = None
self.state['SystemAddress'] = None
self.state['StarPos'] = None
self.state['Body'] = None
@ -527,7 +526,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
entry: dict[str, Any] = {
'timestamp': strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()),
'event': 'StartUp',
'StarSystem': self.system,
'StarSystem': self.state['SystemName'],
'StarPos': self.state['StarPos'],
'SystemAddress': self.state['SystemAddress'],
'Population': self.systempopulation,
@ -578,7 +577,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.cmdr = None
self.mode = None
self.group = None
self.system = None
self.state['SystemName'] = None
self.state['SystemAddress'] = None
self.state['StarPos'] = None
self.state['Body'] = None
@ -615,7 +614,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.mode = entry.get('GameMode')
self.group = entry.get('Group')
self.system = None
self.state['SystemName'] = None
self.state['SystemAddress'] = None
self.state['StarPos'] = None
self.state['Body'] = None
@ -943,10 +942,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.systempopulation = entry.get('Population')
if entry['StarSystem'] == 'ProvingGround':
self.system = 'CQC'
self.state['SystemName'] = 'CQC'
else:
self.system = entry['StarSystem']
self.state['SystemName'] = entry['StarSystem']
###############################################################
###############################################################
@ -1687,7 +1686,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.state['Captain'] = entry['Captain']
self.state['Role'] = 'Idle'
self.state['StarPos'] = None
self.system = None
self.state['SystemName'] = None
self.state['SystemAddress'] = None
self.state['StarPos'] = None
self.state['Body'] = None
@ -1705,7 +1704,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
elif event_type == 'quitacrew':
self.state['Captain'] = None
self.state['Role'] = None
self.system = None
self.state['SystemName'] = None
self.state['SystemAddress'] = None
self.state['StarPos'] = None
self.state['Body'] = None

@ -184,6 +184,8 @@ def journal_entry( # noqa: CCR001
return
this.on_foot = state['OnFoot']
this.system_address = state['SystemAddress']
# Always update our system address even if we're not currently the provider for system or station, but dont update
# on events that contain "future" data, such as FSDTarget
if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'):