2022-06-19 06:45:36 +12:00
|
|
|
"""
|
|
|
|
Shared controller resources module
|
|
|
|
|
|
|
|
Each of the objects in this module should be instantiated ONCE
|
|
|
|
and only ONCE!
|
|
|
|
"""
|
|
|
|
|
2021-10-08 07:19:24 +13:00
|
|
|
from argparse import Namespace
|
2022-05-05 08:11:41 +12:00
|
|
|
from typing import Optional
|
2021-10-08 07:19:24 +13:00
|
|
|
|
2022-04-19 02:51:51 +12:00
|
|
|
from rare.lgndr.core import LegendaryCore
|
2022-05-05 08:11:41 +12:00
|
|
|
|
2022-06-19 06:45:36 +12:00
|
|
|
from rare.models.apiresults import ApiResults
|
|
|
|
from rare.models.signals import GlobalSignals
|
2021-10-08 07:19:24 +13:00
|
|
|
|
2022-05-05 08:11:41 +12:00
|
|
|
_legendary_core_singleton: Optional[LegendaryCore] = None
|
|
|
|
_global_signals_singleton: Optional[GlobalSignals] = None
|
|
|
|
_arguments_singleton: Optional[Namespace] = None
|
|
|
|
_api_results_singleton: Optional[ApiResults] = None
|
2021-10-08 07:19:24 +13:00
|
|
|
|
|
|
|
|
2022-05-05 08:11:41 +12:00
|
|
|
def LegendaryCoreSingleton(init: bool = False) -> LegendaryCore:
|
2022-02-26 06:43:27 +13:00
|
|
|
global _legendary_core_singleton
|
2022-05-05 08:11:41 +12:00
|
|
|
if _legendary_core_singleton is None and not init:
|
|
|
|
raise RuntimeError("Uninitialized use of LegendaryCoreSingleton")
|
2022-02-26 06:43:27 +13:00
|
|
|
if _legendary_core_singleton is None:
|
|
|
|
_legendary_core_singleton = LegendaryCore()
|
|
|
|
return _legendary_core_singleton
|
2021-10-08 07:19:24 +13:00
|
|
|
|
|
|
|
|
2022-05-05 08:11:41 +12:00
|
|
|
def GlobalSignalsSingleton(init: bool = False) -> GlobalSignals:
|
2022-02-26 06:43:27 +13:00
|
|
|
global _global_signals_singleton
|
2022-05-05 08:11:41 +12:00
|
|
|
if _global_signals_singleton is None and not init:
|
|
|
|
raise RuntimeError("Uninitialized use of GlobalSignalsSingleton")
|
2022-02-26 06:43:27 +13:00
|
|
|
if _global_signals_singleton is None:
|
|
|
|
_global_signals_singleton = GlobalSignals()
|
|
|
|
return _global_signals_singleton
|
2021-10-08 07:19:24 +13:00
|
|
|
|
|
|
|
|
2022-05-05 08:11:41 +12:00
|
|
|
def ArgumentsSingleton(args: Namespace = None) -> Optional[Namespace]:
|
2022-02-26 06:43:27 +13:00
|
|
|
global _arguments_singleton
|
2022-05-05 08:11:41 +12:00
|
|
|
if _arguments_singleton is None and args is None:
|
|
|
|
raise RuntimeError("Uninitialized use of ArgumentsSingleton")
|
2022-02-26 06:43:27 +13:00
|
|
|
if _arguments_singleton is None:
|
|
|
|
_arguments_singleton = args
|
|
|
|
return _arguments_singleton
|
2021-10-08 07:19:24 +13:00
|
|
|
|
|
|
|
|
2022-05-05 08:11:41 +12:00
|
|
|
def ApiResultsSingleton(res: ApiResults = None) -> Optional[ApiResults]:
|
2022-02-26 06:43:27 +13:00
|
|
|
global _api_results_singleton
|
2022-05-05 08:11:41 +12:00
|
|
|
if _api_results_singleton is None and res is None:
|
|
|
|
raise RuntimeError("Uninitialized use of ApiResultsSingleton")
|
2022-02-26 06:43:27 +13:00
|
|
|
if _api_results_singleton is None:
|
|
|
|
_api_results_singleton = res
|
|
|
|
return _api_results_singleton
|
|
|
|
|