1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-17 17:42:20 +03:00

Merge pull request #1232 from norohind/feature/1030/journal-entry-cqc

Feature/1030/journal entry cqc
This commit is contained in:
Athanasius 2021-08-11 12:27:05 +01:00 committed by GitHub
commit f6c0139440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 4 deletions

View File

@ -872,7 +872,10 @@ 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,9 +1174,18 @@ class AppWindow(object):
config.set('cmdrs', config.get_list('cmdrs', default=[]) + [monitor.cmdr])
self.login()
if monitor.mode == 'CQC' and entry['event']:
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
# logger.trace('Startup, returning')
return # Startup
if entry['event'] in ['StartUp', 'LoadGame'] and monitor.started:
logger.info('Startup or LoadGame event')
@ -1335,6 +1347,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
monitor.mode == 'CQC' and
not monitor.state['Captain'] and
monitor.system and
tk.NORMAL or tk.DISABLED)

View File

@ -529,7 +529,15 @@ 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') and not entry.get('GameMode') or entry.get('GameMode', '').lower() == 'cqc':
if 'cqc-loadgame-events' in trace_on:
logger.trace(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

26
plug.py
View File

@ -1,6 +1,7 @@
"""
Plugin hooks for EDMC - Ian Norton, Jonathan Harris
"""
import copy
import importlib
import logging
import operator
@ -272,6 +273,31 @@ def notify_journal_entry(cmdr, is_beta, system, station, entry, state):
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:
cqc_callback = plugin._get_func('journal_entry_cqc')
if cqc_callback is not None and callable(cqc_callback):
try:
# Pass a copy of the journal entry in case the callee modifies it
newerror = cqc_callback(cmdr, is_beta, copy.deepcopy(entry), copy.deepcopy(state))
error = error or newerror
except Exception:
logger.exception(f'Plugin "{plugin.name}" failed while handling CQC mode journal entry')
return error
def notify_dashboard_entry(cmdr, is_beta, entry):
"""
Send a status entry to each plugin.