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

Suits/Loadouts: Always convert to dict form for simpler downstream code.

This commit is contained in:
Athanasius 2021-04-29 11:30:55 +01:00
parent addb178d3d
commit bd1b86d3a3
2 changed files with 20 additions and 10 deletions

View File

@ -537,16 +537,15 @@ Content of `state` (updated to the current journal entry):
| `Data` | `dict` | 'Data' MicroResources in Odyssey, `int` count each. | | `Data` | `dict` | 'Data' MicroResources in Odyssey, `int` count each. |
| `BackPack` | `dict` | `dict` of Odyssey MicroResources in backpack. | | `BackPack` | `dict` | `dict` of Odyssey MicroResources in backpack. |
| `SuitCurrent` | `dict` | CAPI-returned data of currently worn suit. NB: May be `None` if no data. | | `SuitCurrent` | `dict` | CAPI-returned data of currently worn suit. NB: May be `None` if no data. |
| `Suits` | `dict` or `list`[1] | CAPI-returned data of owned suits. NB: Type depends on if array is sparse or not. 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. | | `SuitLoadoutCurrent` | `dict` | CAPI-returned data of current Suit Loadout. NB: May be `None` if no data. |
| `SuitLoadouts` | `dict` | CAPI-returned data of all Suit Loadouts. NB: May be `None` if no data. | | `SuitLoadouts` | `dict`[1] | CAPI-returned data of all Suit Loadouts. NB: May be `None` if no data. |
[1] - With `Suits` there's a caveat depending on all the slots from 0 are [1] - Some data from the CAPI is sometimes returned as a `list` (when all
contiguously used or not. If they are then the type is `list` and members are present) and other times as an integer-keyed `dict` (when at
indexing is purely numeric. If not then it's a `dict` and you need to index it least one member is missing, so the indices are not contiguous). We choose to
with a string. There is `companion.index_possibly_sparse_list()` to aid always convert to the integer-keyed `dict` form so that code utilising the data
with this, or if you wish to iterate over it use `companion.listify()` to is simpler.
fill in any gaps and have a `list` to operate on.
New in version 4.1.6: New in version 4.1.6:

View File

@ -680,13 +680,24 @@ class Session(object):
return return
monitor.state['SuitCurrent'] = current_suit monitor.state['SuitCurrent'] = current_suit
monitor.state['Suits'] = data.get('suits') # It's easier to always have this in the 'sparse array' dict form
suits = data.get('suits')
if isinstance(suits, list):
monitor.state['Suits'] = dict(enumerate(suits))
else:
monitor.state['Suits'] = suits
if (suit_loadouts := data.get('loadouts')) is None: if (suit_loadouts := data.get('loadouts')) is None:
logger.warning('CAPI data had "suit" but no (suit) "loadouts"') logger.warning('CAPI data had "suit" but no (suit) "loadouts"')
monitor.state['SuitLoadoutCurrent'] = data.get('loadout') monitor.state['SuitLoadoutCurrent'] = data.get('loadout')
monitor.state['SuitLoadouts'] = suit_loadouts # It's easier to always have this in the 'sparse array' dict form
if isinstance(suit_loadouts, list):
monitor.state['SuitLoadouts'] = dict(enumerate(suit_loadouts))
else:
monitor.state['SuitLoadouts'] = suit_loadouts
def close(self) -> None: def close(self) -> None:
"""Close CAPI authorization session.""" """Close CAPI authorization session."""