Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
 def _delete_replay(self, replay: str) -> None:
     try:
         _ba.increment_analytics_count('Replay delete')
         os.remove((_ba.get_replays_dir() + '/' + replay).encode('utf-8'))
         self._refresh_my_replays()
         ba.playsound(ba.getsound('shieldDown'))
         if replay == self._my_replay_selected:
             self._my_replay_selected = None
     except Exception:
         ba.print_exception("exception deleting replay '" + replay + "'")
         ba.playsound(ba.getsound('error'))
         ba.screenmessage(ba.Lstr(resource=self._r +
                                  '.replayDeleteErrorText'),
                          color=(1, 0, 0))
Ejemplo n.º 3
0
    def _rename_my_replay(self, replay: str) -> None:
        new_name = None
        try:
            if not self._my_replay_rename_text:
                return
            new_name_raw = cast(
                str, ba.textwidget(query=self._my_replay_rename_text))
            new_name = new_name_raw + '.brp'

            # Ignore attempts to change it to what it already is
            # (or what it looks like to the user).
            if (replay != new_name
                    and self._get_replay_display_name(replay) != new_name_raw):
                old_name_full = (_ba.get_replays_dir() + '/' +
                                 replay).encode('utf-8')
                new_name_full = (_ba.get_replays_dir() + '/' +
                                 new_name).encode('utf-8')
                # False alarm; ba.textwidget can return non-None val.
                # pylint: disable=unsupported-membership-test
                if os.path.exists(new_name_full):
                    ba.playsound(ba.getsound('error'))
                    ba.screenmessage(
                        ba.Lstr(resource=self._r +
                                '.replayRenameErrorAlreadyExistsText'),
                        color=(1, 0, 0))
                elif any(char in new_name_raw for char in ['/', '\\', ':']):
                    ba.playsound(ba.getsound('error'))
                    ba.screenmessage(ba.Lstr(resource=self._r +
                                             '.replayRenameErrorInvalidName'),
                                     color=(1, 0, 0))
                else:
                    _ba.increment_analytics_count('Replay rename')
                    os.rename(old_name_full, new_name_full)
                    self._refresh_my_replays()
                    ba.playsound(ba.getsound('gunCocking'))
        except Exception:
            ba.print_exception(
                f"Error renaming replay '{replay}' to '{new_name}'.")
            ba.playsound(ba.getsound('error'))
            ba.screenmessage(
                ba.Lstr(resource=self._r + '.replayRenameErrorText'),
                color=(1, 0, 0),
            )

        ba.containerwidget(edit=self._my_replays_rename_window,
                           transition='out_scale')
Ejemplo n.º 4
0
    def _on_my_replay_play_press(self) -> None:
        if self._my_replay_selected is None:
            self._no_replay_selected_error()
            return
        _ba.increment_analytics_count('Replay watch')

        def do_it() -> None:
            try:
                # reset to normal speed
                _ba.set_replay_speed_exponent(0)
                _ba.fade_screen(True)
                assert self._my_replay_selected is not None
                _ba.new_replay_session(_ba.get_replays_dir() + '/' +
                                       self._my_replay_selected)
            except Exception:
                ba.print_exception('exception running replay session')
                # drop back into a fresh main menu session
                # in case we half-launched or something..
                from bastd import mainmenu
                _ba.new_host_session(mainmenu.MainMenuSession)

        _ba.fade_screen(False, endcall=ba.Call(ba.pushcall, do_it))
        ba.containerwidget(edit=self._root_widget, transition='out_left')
Ejemplo n.º 5
0
 def __init__(self) -> None:
     _ba.increment_analytics_count('Free-for-all session start')
     super().__init__()
Ejemplo n.º 6
0
 def _on_activate(self) -> None:
     _ba.increment_analytics_count('Store button press')
     self._on_activate_call()
Ejemplo n.º 7
0
 def __init__(self) -> None:
     _ba.increment_analytics_count('Teams session start')
     super().__init__()
Ejemplo n.º 8
0
def game_begin_analytics() -> None:
    """Update analytics events for the start of a game."""
    # pylint: disable=too-many-branches
    # pylint: disable=cyclic-import
    from ba._dualteamsession import DualTeamSession
    from ba._freeforallsession import FreeForAllSession
    from ba._coopsession import CoopSession
    from ba._gameactivity import GameActivity
    activity = _ba.getactivity(False)
    session = _ba.getsession(False)

    # Fail gracefully if we didn't cleanly get a session and game activity.
    if not activity or not session or not isinstance(activity, GameActivity):
        return

    if isinstance(session, CoopSession):
        campaign = session.campaign
        assert campaign is not None
        _ba.set_analytics_screen(
            'Coop Game: ' + campaign.name + ' ' +
            campaign.getlevel(_ba.app.coop_session_args['level']).name)
        _ba.increment_analytics_count('Co-op round start')
        if len(activity.players) == 1:
            _ba.increment_analytics_count('Co-op round start 1 human player')
        elif len(activity.players) == 2:
            _ba.increment_analytics_count('Co-op round start 2 human players')
        elif len(activity.players) == 3:
            _ba.increment_analytics_count('Co-op round start 3 human players')
        elif len(activity.players) >= 4:
            _ba.increment_analytics_count('Co-op round start 4+ human players')

    elif isinstance(session, DualTeamSession):
        _ba.set_analytics_screen('Teams Game: ' + activity.getname())
        _ba.increment_analytics_count('Teams round start')
        if len(activity.players) == 1:
            _ba.increment_analytics_count('Teams round start 1 human player')
        elif 1 < len(activity.players) < 8:
            _ba.increment_analytics_count('Teams round start ' +
                                          str(len(activity.players)) +
                                          ' human players')
        elif len(activity.players) >= 8:
            _ba.increment_analytics_count('Teams round start 8+ human players')

    elif isinstance(session, FreeForAllSession):
        _ba.set_analytics_screen('FreeForAll Game: ' + activity.getname())
        _ba.increment_analytics_count('Free-for-all round start')
        if len(activity.players) == 1:
            _ba.increment_analytics_count(
                'Free-for-all round start 1 human player')
        elif 1 < len(activity.players) < 8:
            _ba.increment_analytics_count('Free-for-all round start ' +
                                          str(len(activity.players)) +
                                          ' human players')
        elif len(activity.players) >= 8:
            _ba.increment_analytics_count(
                'Free-for-all round start 8+ human players')

    # For some analytics tracking on the c layer.
    _ba.reset_game_activity_tracking()