mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-06 02:13:41 +03:00
EDDN: Restore safe_modules_and_ships() from 4.2.4
This commit is contained in:
parent
b6dcc39fb2
commit
63be402cb4
@ -299,6 +299,36 @@ Msg:\n{msg}'''
|
|||||||
|
|
||||||
this.commodities = commodities
|
this.commodities = commodities
|
||||||
|
|
||||||
|
def safe_modules_and_ships(self, data: Mapping[str, Any]) -> Tuple[Dict, Dict]:
|
||||||
|
modules: Dict[str, Any] = data['lastStarport'].get('modules')
|
||||||
|
if modules is None or not isinstance(modules, dict):
|
||||||
|
if modules is None:
|
||||||
|
logger.debug('modules was None. FC or Damaged Station?')
|
||||||
|
|
||||||
|
elif isinstance(modules, list):
|
||||||
|
if len(modules) == 0:
|
||||||
|
logger.debug('modules is empty list. Damaged Station?')
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.error(f'modules is non-empty list: {modules!r}')
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.error(f'modules was not None, a list, or a dict! type = {type(modules)}')
|
||||||
|
# Set a safe value
|
||||||
|
modules = {}
|
||||||
|
|
||||||
|
ships: Dict[str, Any] = data['lastStarport'].get('ships')
|
||||||
|
if ships is None or not isinstance(ships, dict):
|
||||||
|
if ships is None:
|
||||||
|
logger.debug('ships was None')
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.error(f'ships was neither None nor a Dict! Type = {type(ships)}')
|
||||||
|
# Set a safe value
|
||||||
|
ships = {'shipyard_list': {}, 'unavailable_list': []}
|
||||||
|
|
||||||
|
return (modules, ships)
|
||||||
|
|
||||||
def export_outfitting(self, data: CAPIData, is_beta: bool) -> None:
|
def export_outfitting(self, data: CAPIData, is_beta: bool) -> None:
|
||||||
"""
|
"""
|
||||||
export_outfitting updates EDDN with the current (lastStarport) station's outfitting options, if any.
|
export_outfitting updates EDDN with the current (lastStarport) station's outfitting options, if any.
|
||||||
@ -307,19 +337,20 @@ Msg:\n{msg}'''
|
|||||||
:param data: dict containing the outfitting data
|
:param data: dict containing the outfitting data
|
||||||
:param is_beta: whether or not we're currently in beta mode
|
:param is_beta: whether or not we're currently in beta mode
|
||||||
"""
|
"""
|
||||||
|
modules, ships = self.safe_modules_and_ships(data)
|
||||||
|
|
||||||
# Horizons flag - will hit at least Int_PlanetApproachSuite other than at engineer bases ("Colony"),
|
# Horizons flag - will hit at least Int_PlanetApproachSuite other than at engineer bases ("Colony"),
|
||||||
# prison or rescue Megaships, or under Pirate Attack etc
|
# prison or rescue Megaships, or under Pirate Attack etc
|
||||||
horizons: bool = is_horizons(
|
horizons: bool = is_horizons(
|
||||||
data['lastStarport'].get('economies', {}),
|
data['lastStarport'].get('economies', {}),
|
||||||
data['lastStarport']['modules'],
|
modules,
|
||||||
data['lastStarport']['ships']
|
ships
|
||||||
)
|
)
|
||||||
|
|
||||||
to_search: Iterator[Mapping[str, Any]] = filter(
|
to_search: Iterator[Mapping[str, Any]] = filter(
|
||||||
lambda m: self.MODULE_RE.search(m['name']) and m.get('sku') in (None, HORIZ_SKU) and
|
lambda m: self.MODULE_RE.search(m['name']) and m.get('sku') in (None, HORIZ_SKU) and
|
||||||
m['name'] != 'Int_PlanetApproachSuite',
|
m['name'] != 'Int_PlanetApproachSuite',
|
||||||
data['lastStarport']['modules'].values()
|
modules.values()
|
||||||
)
|
)
|
||||||
|
|
||||||
outfitting: List[str] = sorted(
|
outfitting: List[str] = sorted(
|
||||||
@ -350,12 +381,11 @@ Msg:\n{msg}'''
|
|||||||
:param data: dict containing the shipyard data
|
:param data: dict containing the shipyard data
|
||||||
:param is_beta: whether or not we are in beta mode
|
:param is_beta: whether or not we are in beta mode
|
||||||
"""
|
"""
|
||||||
|
modules, ships = self.safe_modules_and_ships(data)
|
||||||
ships = data['lastStarport']['ships']
|
|
||||||
|
|
||||||
horizons: bool = is_horizons(
|
horizons: bool = is_horizons(
|
||||||
data['lastStarport'].get('economies', {}),
|
data['lastStarport'].get('economies', {}),
|
||||||
data['lastStarport']['modules'],
|
modules,
|
||||||
ships
|
ships
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -832,4 +862,3 @@ def is_horizons(economies: MAP_STR_ANY, modules: MAP_STR_ANY, ships: MAP_STR_ANY
|
|||||||
logger.error(f'ships type is {type(ships)}')
|
logger.error(f'ships type is {type(ships)}')
|
||||||
|
|
||||||
return economies_colony or modules_horizons or ship_horizons
|
return economies_colony or modules_horizons or ship_horizons
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user