From 143a205fb9074bb9314fb59441a71a279e1dc8da Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 20 May 2021 18:13:51 +0100 Subject: [PATCH 1/2] Backpack: event name is CamelCase, stored in monitor.state, doc * Surprise! The new event is `BackPack`, not `Backpack`, although the filename *is* `Backpack.json`. * Store the loaded JSON dict in `monitor.state['BackpackJSON']`. That `p` is lower case to match with the filename, not the event name. * Document this in PLUGINS.md. Unless EDSM is telling us to discard this we should now be sending it. --- PLUGINS.md | 1 + monitor.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/PLUGINS.md b/PLUGINS.md index 6a14b445..1eb2a4a2 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -599,6 +599,7 @@ Content of `state` (updated to the current journal entry): | `Consumable` | `dict` | 'Consumable' MicroResources in Odyssey, `int` count each. | | `Data` | `dict` | 'Data' MicroResources in Odyssey, `int` count each. | | `BackPack` | `dict` | `dict` of Odyssey MicroResources in backpack. | +| `BackpackJSON` | `dict` | Content of Backpack.json as of last read. | | `SuitCurrent` | `dict` | CAPI-returned data of currently worn suit. NB: May be `None` if no data. | | `Suits` | `dict`[1] | CAPI-returned data of owned suits. NB: May be `None` if no data. | | `SuitLoadoutCurrent` | `dict` | CAPI-returned data of current Suit Loadout. NB: May be `None` if no data. | diff --git a/monitor.py b/monitor.py index 49028521..899a28a5 100644 --- a/monitor.py +++ b/monitor.py @@ -151,6 +151,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below 'Item': defaultdict(int), # BackPack Items 'Data': defaultdict(int), # Backpack Data }, + 'BackpackJSON': None, # Raw JSON from `Backpack.json` file, if available 'SuitCurrent': None, 'Suits': {}, 'SuitLoadoutCurrent': None, @@ -866,17 +867,21 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below {self.canonicalise(x['Name']): x['Count'] for x in clean_data} ) - elif event_type == 'Backpack': + elif event_type == 'BackPack': # TODO: v31 doc says this is`backpack.json` ... but Howard Chalkley # said it's `Backpack.json` with open(join(self.currentdir, 'Backpack.json'), 'rb') as backpack: # type: ignore try: - entry = json.load(backpack) + # Preserve property order because why not? + entry = json.load(backpack, object_pairs_hook=OrderedDict) except json.JSONDecodeError: logger.exception('Failed decoding Backpack.json', exc_info=True) else: + # Store in monitor.state + self.state['BackpackJSON'] = entry + # Assume this reflects the current state when written self.state['BackPack']['Component'] = defaultdict(int) self.state['BackPack']['Consumable'] = defaultdict(int) From e5909e90240121c37f02c67aa7bb9de2ff59d3b3 Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 20 May 2021 18:26:51 +0100 Subject: [PATCH 2/2] EDSM: Use loaded BackPack data, not the empty event. --- plugins/edsm.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/edsm.py b/plugins/edsm.py index 66b833c6..422d0b56 100644 --- a/plugins/edsm.py +++ b/plugins/edsm.py @@ -432,6 +432,11 @@ def journal_entry( elif entry['event'] == 'NavBeaconScan': this.navbeaconscan = entry['NumBodies'] + elif entry['event'] == 'BackPack': + # Use the stored file contents, not the empty journal event + if state['BackpackJSON']: + entry = state['BackpackJSON'] + # Send interesting events to EDSM if ( config.get_int('edsm_out') and not is_beta and not this.multicrew and credentials(cmdr) and