More subsystem cleanup

This commit is contained in:
Eric Froemling 2020-10-16 12:12:51 -07:00
parent 05c93cc776
commit 8c6ec14208
4 changed files with 37 additions and 18 deletions

View File

@ -3,6 +3,7 @@
- ba.get_valid_languages() is now an attr: ba.app.lang.available_languages
- Achievement functionality has been consolidated into an AchievementSubsystem object at ba.app.ach
- Plugin functionality has been consolidated into a PluginSubsystem obj at ba.app.plugins
- Ditto with AccountSubsystem and ba.app.accounts
### 1.5.26 (20217)
- Simplified licensing header on python scripts.

View File

@ -10,7 +10,31 @@ from typing import TYPE_CHECKING
import _ba
if TYPE_CHECKING:
from typing import Any, Optional, Dict, List
from typing import Any, Optional, Dict, List, Tuple
import ba
class AccountSubsystem:
"""Subsystem for account handling in the app.
Category: App Classes
Access the single shared instance of this class at 'ba.app.plugins'.
"""
def __init__(self) -> None:
self.account_tournament_list: Optional[Tuple[int, List[str]]] = None
def on_app_launch(self) -> None:
"""Called when the app is done bootstrapping."""
# Auto-sign-in to a local account in a moment if we're set to.
def do_auto_sign_in() -> None:
if _ba.app.headless_mode or _ba.app.config.get(
'Auto Account State') == 'Local':
_ba.sign_in('Local')
_ba.pushcall(do_auto_sign_in)
def handle_account_gained_tickets(count: int) -> None:

View File

@ -176,6 +176,7 @@ class App:
from ba._ui import UISubsystem
from ba._achievement import AchievementSubsystem
from ba._plugin import PluginSubsystem
from ba._account import AccountSubsystem
# Config.
self.config_file_healthy = False
@ -238,6 +239,7 @@ class App:
self.last_ad_purpose = 'invalid'
self.attempted_first_ad = False
self.accounts = AccountSubsystem()
self.plugins = PluginSubsystem()
self.music = MusicSubsystem()
self.lang = LanguageSubsystem()
@ -273,7 +275,6 @@ class App:
self.special_offer: Optional[Dict] = None
self.league_rank_cache: Dict = {}
self.tournament_info: Dict = {}
self.account_tournament_list: Optional[Tuple[int, List[str]]] = None
self.ping_thread_count = 0
self.invite_confirm_windows: List[Any] = [] # FIXME: Don't use Any.
self.store_layout: Optional[Dict[str, List[Dict[str, Any]]]] = None
@ -306,7 +307,6 @@ class App:
self.ui.on_app_launch()
# _achievement.init_achievements()
spazappearance.register_appearances()
_campaign.init_campaigns()
@ -391,13 +391,7 @@ class App:
# Start scanning for things exposed via ba_meta.
_meta.start_scan()
# Auto-sign-in to a local account in a moment if we're set to.
def do_auto_sign_in() -> None:
if self.headless_mode or cfg.get('Auto Account State') == 'Local':
_ba.sign_in('Local')
_ba.pushcall(do_auto_sign_in)
self.accounts.on_app_launch()
self.plugins.on_app_launch()
self.ran_on_app_launch = True

View File

@ -250,15 +250,15 @@ class CoopBrowserWindow(ba.Window):
# If we've got a cached tournament list for our account and info for
# each one of those tournaments, go ahead and display it as a
# starting point.
if (app.account_tournament_list is not None and
app.account_tournament_list[0] == _ba.get_account_state_num()
and all([
if (app.accounts.account_tournament_list is not None
and app.accounts.account_tournament_list[0]
== _ba.get_account_state_num() and all([
t_id in app.tournament_info
for t_id in app.account_tournament_list[1]
for t_id in app.accounts.account_tournament_list[1]
])):
tourney_data = [
app.tournament_info[t_id]
for t_id in app.account_tournament_list[1]
for t_id in app.accounts.account_tournament_list[1]
]
self._update_for_data(tourney_data)
@ -601,9 +601,9 @@ class CoopBrowserWindow(ba.Window):
cache_tournament_info(tournament_data)
# Also cache the current tourney list/order for this account.
app.account_tournament_list = (_ba.get_account_state_num(), [
e['tournamentID'] for e in tournament_data
])
app.accounts.account_tournament_list = (
_ba.get_account_state_num(),
[e['tournamentID'] for e in tournament_data])
self._doing_tournament_query = False
self._update_for_data(tournament_data)