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

WIP: implement journal_entry_cqc()

journal_entry_cqc function in plugin's api allow plugins to recieve
journal events when player are in CQC
This commit is contained in:
norohind 2021-08-09 04:37:23 +03:00
parent 1a0b4ae480
commit 27fe43bf8c
Signed by: norohind
GPG Key ID: 01C3BECC26FB59E1
3 changed files with 41 additions and 2 deletions

@ -872,7 +872,8 @@ class AppWindow(object):
play_bad = False
err: Optional[str] = None
if not monitor.cmdr or not monitor.mode or monitor.state['Captain'] or not monitor.system:
if not monitor.cmdr or not monitor.mode or monitor.state['Captain'] or not monitor.system or \
monitor.mode == 'CQC':
return # In CQC or on crew - do nothing
if companion.session.state == companion.Session.STATE_AUTH:
@ -1171,6 +1172,15 @@ class AppWindow(object):
config.set('cmdrs', config.get_list('cmdrs', default=[]) + [monitor.cmdr])
self.login()
if monitor.mode == 'CQC':
err = plug.notify_journal_entry_cqc(monitor.cmdr, monitor.is_beta, entry, monitor.state)
if err:
self.status['text'] = err
if not config.get_int('hotkey_mute'):
hotkeymgr.play_bad()
return # in CQC
if not entry['event'] or not monitor.mode:
# logger.trace('Startup or in CQC, returning')
return # Startup or in CQC
@ -1335,6 +1345,7 @@ class AppWindow(object):
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
# and monitor.mode == 'CQC' and
not monitor.state['Captain'] and
monitor.system and
tk.NORMAL or tk.DISABLED)

@ -494,6 +494,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
entry['timestamp'] # we expect this to exist # TODO: replace with assert? or an if key in check
event_type = entry['event'].lower()
# logger.debug(f'Monitor event: {entry["event"]}')
if event_type == 'fileheader':
self.live = False
@ -529,7 +530,11 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
# Odyssey: bool
self.cmdr = entry['Commander']
# 'Open', 'Solo', 'Group', or None for CQC (and Training - but no LoadGame event)
self.mode = entry.get('GameMode')
if not entry.get('Ship'): # TODO: Test with loading to CQC right from main game
logger.debug(f'loadgame to cqc: {entry}')
self.mode = 'CQC'
else:
self.mode = entry.get('GameMode')
self.group = entry.get('Group')
self.planet = None
self.system = None

23
plug.py

@ -312,6 +312,29 @@ def notify_newdata(data, is_beta):
return error
def notify_journal_entry_cqc(cmdr, is_beta, entry, state):
"""
Send a journal entry to each plugin.
:param cmdr: The Cmdr name, or None if not yet known
:param entry: The journal entry as a dictionary
:param state: A dictionary containing info about the Cmdr, current ship and cargo
:param is_beta: whether the player is in a Beta universe.
:returns: Error message from the first plugin that returns one (if any)
"""
error = None
for plugin in PLUGINS:
journal_entry = plugin._get_func('journal_entry_cqc')
if journal_entry:
try:
# Pass a copy of the journal entry in case the callee modifies it
newerror = journal_entry(cmdr, is_beta, dict(entry), dict(state))
error = error or newerror
except Exception as e:
logger.exception(f'Plugin "{plugin.name}" failed')
return error
def show_error(err):
"""
Display an error message in the status line of the main window.