def __init__(self) -> None: """Instantiate a co-op mode session.""" # pylint: disable=cyclic-import from ba._campaign import get_campaign from bastd.activity.coopjoin import CoopJoinActivity _ba.increment_analytics_count('Co-op session start') app = _ba.app # If they passed in explicit min/max, honor that. # Otherwise defer to user overrides or defaults. if 'min_players' in app.coop_session_args: min_players = app.coop_session_args['min_players'] else: min_players = 1 if 'max_players' in app.coop_session_args: max_players = app.coop_session_args['max_players'] else: max_players = app.config.get('Coop Game Max Players', 4) # print('FIXME: COOP SESSION WOULD CALC DEPS.') depsets: Sequence[ba.DependencySet] = [] super().__init__(depsets, team_names=TEAM_NAMES, team_colors=TEAM_COLORS, min_players=min_players, max_players=max_players) # Tournament-ID if we correspond to a co-op tournament (otherwise None) self.tournament_id = (app.coop_session_args['tournament_id'] if 'tournament_id' in app.coop_session_args else None) # FIXME: Could be nice to pass this in as actual args. self.campaign_state = { 'campaign': (app.coop_session_args['campaign']), 'level': app.coop_session_args['level'] } self.campaign = get_campaign(self.campaign_state['campaign']) self._ran_tutorial_activity = False self._tutorial_activity: Optional[ba.Activity] = None self._custom_menu_ui: List[Dict[str, Any]] = [] # Start our joining screen. self.set_activity(_ba.new_activity(CoopJoinActivity)) self._next_game_instance: Optional[ba.GameActivity] = None self._next_game_name: Optional[str] = None self._update_on_deck_game_instances()
def launch_coop_game(self, game: str, force: bool = False, args: Dict = None) -> bool: """High level way to launch a local co-op session.""" # pylint: disable=cyclic-import from ba._campaign import get_campaign from bastd.ui.coop.level import CoopLevelLockedWindow if args is None: args = {} if game == '': raise ValueError('empty game name') campaignname, levelname = game.split(':') campaign = get_campaign(campaignname) levels = campaign.get_levels() # If this campaign is sequential, make sure we've completed the # one before this. if campaign.sequential and not force: for level in levels: if level.name == levelname: break if not level.complete: CoopLevelLockedWindow( campaign.get_level(levelname).displayname, campaign.get_level(level.name).displayname) return False # Ok, we're good to go. self.coop_session_args = { 'campaign': campaignname, 'level': levelname, } for arg_name, arg_val in list(args.items()): self.coop_session_args[arg_name] = arg_val def _fade_end() -> None: from ba import _coopsession try: _ba.new_host_session(_coopsession.CoopSession) except Exception: from ba import _error _error.print_exception() from bastd.mainmenu import MainMenuSession _ba.new_host_session(MainMenuSession) _ba.fade_screen(False, endcall=_fade_end) return True
def display_name(self) -> ba.Lstr: """Return a ba.Lstr for this Achievement's name.""" from ba._lang import Lstr name: Union[ba.Lstr, str] try: if self._level_name != '': from ba._campaign import get_campaign campaignname, campaign_level = self._level_name.split(':') name = get_campaign(campaignname).get_level( campaign_level).displayname else: name = '' except Exception: from ba import _error name = '' _error.print_exception() return Lstr(resource='achievements.' + self._name + '.name', subs=[('${LEVEL}', name)])