From 143a205fb9074bb9314fb59441a71a279e1dc8da Mon Sep 17 00:00:00 2001 From: Athanasius Date: Thu, 20 May 2021 18:13:51 +0100 Subject: [PATCH] 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)