mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-07 19:03:23 +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:
parent
1a0b4ae480
commit
27fe43bf8c
@ -872,7 +872,8 @@ class AppWindow(object):
|
|||||||
play_bad = False
|
play_bad = False
|
||||||
err: Optional[str] = None
|
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
|
return # In CQC or on crew - do nothing
|
||||||
|
|
||||||
if companion.session.state == companion.Session.STATE_AUTH:
|
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])
|
config.set('cmdrs', config.get_list('cmdrs', default=[]) + [monitor.cmdr])
|
||||||
self.login()
|
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:
|
if not entry['event'] or not monitor.mode:
|
||||||
# logger.trace('Startup or in CQC, returning')
|
# logger.trace('Startup or in CQC, returning')
|
||||||
return # Startup or in CQC
|
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['text'] = self.theme_button['text'] = _('Update') # LANG: Update button in main window
|
||||||
self.button['state'] = self.theme_button['state'] = (monitor.cmdr and
|
self.button['state'] = self.theme_button['state'] = (monitor.cmdr and
|
||||||
monitor.mode and
|
monitor.mode and
|
||||||
|
# and monitor.mode == 'CQC' and
|
||||||
not monitor.state['Captain'] and
|
not monitor.state['Captain'] and
|
||||||
monitor.system and
|
monitor.system and
|
||||||
tk.NORMAL or tk.DISABLED)
|
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
|
entry['timestamp'] # we expect this to exist # TODO: replace with assert? or an if key in check
|
||||||
|
|
||||||
event_type = entry['event'].lower()
|
event_type = entry['event'].lower()
|
||||||
|
# logger.debug(f'Monitor event: {entry["event"]}')
|
||||||
if event_type == 'fileheader':
|
if event_type == 'fileheader':
|
||||||
self.live = False
|
self.live = False
|
||||||
|
|
||||||
@ -529,6 +530,10 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
|
|||||||
# Odyssey: bool
|
# Odyssey: bool
|
||||||
self.cmdr = entry['Commander']
|
self.cmdr = entry['Commander']
|
||||||
# 'Open', 'Solo', 'Group', or None for CQC (and Training - but no LoadGame event)
|
# 'Open', 'Solo', 'Group', or None for CQC (and Training - but no LoadGame event)
|
||||||
|
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.mode = entry.get('GameMode')
|
||||||
self.group = entry.get('Group')
|
self.group = entry.get('Group')
|
||||||
self.planet = None
|
self.planet = None
|
||||||
|
23
plug.py
23
plug.py
@ -312,6 +312,29 @@ def notify_newdata(data, is_beta):
|
|||||||
return error
|
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):
|
def show_error(err):
|
||||||
"""
|
"""
|
||||||
Display an error message in the status line of the main window.
|
Display an error message in the status line of the main window.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user