1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

monitor/Body: Tweak & comment, and remove defunct tracking from eddn.py

* Typod '.status' instead of 'state'.
* Bring in some sanity-checks and comments from eddn.py to monitor.py.
* Have a 'pass' elif for 'supercruiseentry' so as to comment why we do NOT
  use this to blank out body state.
* Bring in the 'if we exit to main menu, blank body state' from eddn.py.
* Remove checks from eddn.py that are now in monitor.py.
* Have a disctinct 'docked' event check in eddn.py for triggering the
  "Now we're docked, so the Delay sending until docked is satisfied"
  sending of messages.
This commit is contained in:
Athanasius 2023-01-03 16:34:56 +00:00
parent e3254aec31
commit 232e91ebfc
No known key found for this signature in database
GPG Key ID: 772697E181BB2767
2 changed files with 42 additions and 52 deletions

View File

@ -619,9 +619,9 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
self.system = None
self.state['SystemAddress'] = None
self.state['StarPos'] = self.coordinates = None
self.status['Body'] = None
self.status['BodyID'] = None
self.status['BodyType'] = None
self.state['Body'] = None
self.state['BodyID'] = None
self.state['BodyType'] = None
self.station = None
self.station_marketid = None
self.stationtype = None
@ -874,7 +874,14 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# Plugins need this as well, so copy in state
self.state['StarPos'] = self.coordinates = tuple(entry['StarPos']) # type: ignore
self.state['SystemAddress'] = entry.get('SystemAddress')
if 'SystemAddress' not in entry:
logger.warning(f'"location" event without SystemAddress !!!:\n{entry}\n')
# But we'll still *use* the value, because if a 'location' event doesn't
# have this we've still moved and now don't know where and MUST NOT
# continue to use any old value.
# Yes, explicitly state `None` here, so it's crystal clear.
self.state['SystemAddress'] = entry.get('SystemAddress', None)
self.systempopulation = entry.get('Population')
@ -902,16 +909,32 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
elif event_type == 'approachbody':
self.state['Body'] = entry['Body']
self.state['BodyID'] = entry.get('BodyID')
self.state['BodyType'] = 'Planet' # Best guess. Journal says always planet.
# This isn't in the event, but Journal doc for ApproachBody says:
# when in Supercruise, and distance from planet drops to within the 'Orbital Cruise' zone
self.state['BodyType'] = 'Planet'
elif event_type in ('leavebody', 'supercruiseentry'):
# FIXME: In the plugins/eddn.py version of this tracking we
# explicitly do NOT clear this information for `supercruiseentry',
# but it is also doing some Status.jon checking.
elif event_type == 'leavebody':
# Triggered when ship goes above Orbital Cruise altitude, such
# that a new 'ApproachBody' would get triggered if the ship
# went back down.
self.state['Body'] = None
self.state['BodyID'] = None
self.state['BodyType'] = None
elif event_type == 'supercruiseentry':
# NB: Do **NOT** clear Body state, because we won't get a fresh
# ApproachBody if we don't leave Orbital Cruise but land
# again.
pass
elif event_type == 'music':
if entry['MusicTrack'] == 'MainMenu':
# We'll get new Body state when the player logs back into
# the game.
self.state['Body'] = None
self.state['BodyID'] = None
self.state['BodyType'] = None
elif event_type in ('rank', 'promotion'):
payload = dict(entry)
payload.pop('event')

View File

@ -1279,6 +1279,8 @@ class EDDN:
logger.warning(f'this.status_body_name was not set properly:'
f' "{this.status_body_name}" ({type(this.status_body_name)})')
# this.status_body_name is available for cross-checks, so try to set
# BodyName and ID.
else:
# In case Frontier add it in
if 'BodyName' not in entry:
@ -2208,40 +2210,14 @@ def journal_entry( # noqa: C901, CCR001
entry
)
# TODO - uncomment this, i.e. use monitor.py tracking, not also here
# Copy some state into module-held variables because we might need it
# outside of this function.
# this.body_name = state['Body']
# this.body_id = state['BodyID']
# this.coordinates = state['StarPos']
# this.systemaddress = state['SystemAddress']
# Track location
if event_name == 'supercruiseexit':
# For any orbital station we have no way of determining the body
# it orbits:
#
# In-ship Status.json doesn't specify this.
# On-foot Status.json lists the station itself as Body.
# Location for stations (on-foot or in-ship) has station as Body.
# SupercruiseExit (own ship or taxi) lists the station as the Body.
if entry['BodyType'] == 'Station':
this.body_name = None
this.body_id = None
elif event_name in ('location', 'fsdjump', 'docked', 'carrierjump'):
if event_name in ('location', 'carrierjump'):
if entry.get('BodyType') == 'Planet':
this.body_name = entry.get('Body')
this.body_id = entry.get('BodyID')
else:
this.body_name = None
elif event_name == 'fsdjump':
this.body_name = None
this.body_id = None
this.body_name = state['Body']
this.body_id = state['BodyID']
this.coordinates = state['StarPos']
this.systemaddress = state['SystemAddress']
if event_name in ('location', 'fsdjump', 'docked', 'carrierjump'):
if 'StarPos' in entry:
this.coordinates = tuple(entry['StarPos'])
@ -2251,18 +2227,9 @@ def journal_entry( # noqa: C901, CCR001
if 'SystemAddress' not in entry:
logger.warning(f'"location" event without SystemAddress !!!:\n{entry}\n')
# But we'll still *use* the value, because if a 'location' event doesn't
# have this we've still moved and now don't know where and MUST NOT
# continue to use any old value.
# Yes, explicitly state `None` here, so it's crystal clear.
this.systemaddress = entry.get('SystemAddress', None) # type: ignore
if event_name == 'docked':
this.eddn.parent.after(this.eddn.REPLAY_DELAY, this.eddn.sender.queue_check_and_send, False)
elif event_name == 'approachbody':
this.body_name = entry['Body']
this.body_id = entry.get('BodyID')
if event_name == 'docked':
# Trigger a send/retry of pending EDDN messages
this.eddn.parent.after(this.eddn.REPLAY_DELAY, this.eddn.sender.queue_check_and_send, False)
elif event_name == 'leavebody':
# NB: **NOT** SupercruiseEntry, because we won't get a fresh