bascenev1lib.activity.dualteamscore

Functionality related to the end screen in dual-team mode.

  1# Released under the MIT License. See LICENSE for details.
  2#
  3"""Functionality related to the end screen in dual-team mode."""
  4
  5from __future__ import annotations
  6
  7from typing import override
  8
  9import bascenev1 as bs
 10
 11from bascenev1lib.activity.multiteamscore import MultiTeamScoreScreenActivity
 12from bascenev1lib.actor.zoomtext import ZoomText
 13
 14
 15class TeamVictoryScoreScreenActivity(MultiTeamScoreScreenActivity):
 16    """Scorescreen between rounds of a dual-team session."""
 17
 18    def __init__(self, settings: dict):
 19        super().__init__(settings=settings)
 20        self._winner: bs.SessionTeam = settings['winner']
 21        assert isinstance(self._winner, bs.SessionTeam)
 22
 23    @override
 24    def on_begin(self) -> None:
 25        bs.set_analytics_screen('Teams Score Screen')
 26        super().on_begin()
 27
 28        height = 130
 29        active_team_count = len(self.teams)
 30        vval = (height * active_team_count) / 2 - height / 2
 31        i = 0
 32        shift_time = 2.5
 33
 34        # Usually we say 'Best of 7', but if the language prefers we can say
 35        # 'First to 4'.
 36        session = self.session
 37        assert isinstance(session, bs.MultiTeamSession)
 38        if bs.app.lang.get_resource('bestOfUseFirstToInstead'):
 39            best_txt = bs.Lstr(
 40                resource='firstToSeriesText',
 41                subs=[('${COUNT}', str(session.get_series_length() / 2 + 1))],
 42            )
 43        else:
 44            best_txt = bs.Lstr(
 45                resource='bestOfSeriesText',
 46                subs=[('${COUNT}', str(session.get_series_length()))],
 47            )
 48
 49        ZoomText(
 50            best_txt,
 51            position=(0, 175),
 52            shiftposition=(-250, 175),
 53            shiftdelay=2.5,
 54            flash=False,
 55            trail=False,
 56            h_align='center',
 57            scale=0.25,
 58            color=(0.5, 0.5, 0.5, 1.0),
 59            jitter=3.0,
 60        ).autoretain()
 61        for team in self.session.sessionteams:
 62            bs.timer(
 63                i * 0.15 + 0.15,
 64                bs.WeakCall(
 65                    self._show_team_name,
 66                    vval - i * height,
 67                    team,
 68                    i * 0.2,
 69                    shift_time - (i * 0.150 + 0.150),
 70                ),
 71            )
 72            bs.timer(i * 0.150 + 0.5, self._score_display_sound_small.play)
 73            scored = team is self._winner
 74            delay = 0.2
 75            if scored:
 76                delay = 1.2
 77                bs.timer(
 78                    i * 0.150 + 0.2,
 79                    bs.WeakCall(
 80                        self._show_team_old_score,
 81                        vval - i * height,
 82                        team,
 83                        shift_time - (i * 0.15 + 0.2),
 84                    ),
 85                )
 86                bs.timer(i * 0.15 + 1.5, self._score_display_sound.play)
 87
 88            bs.timer(
 89                i * 0.150 + delay,
 90                bs.WeakCall(
 91                    self._show_team_score,
 92                    vval - i * height,
 93                    team,
 94                    scored,
 95                    i * 0.2 + 0.1,
 96                    shift_time - (i * 0.15 + delay),
 97                ),
 98            )
 99            i += 1
100        self.show_player_scores()
101
102    def _show_team_name(
103        self,
104        pos_v: float,
105        team: bs.SessionTeam,
106        kill_delay: float,
107        shiftdelay: float,
108    ) -> None:
109        del kill_delay  # Unused arg.
110        ZoomText(
111            bs.Lstr(value='${A}:', subs=[('${A}', team.name)]),
112            position=(100, pos_v),
113            shiftposition=(-150, pos_v),
114            shiftdelay=shiftdelay,
115            flash=False,
116            trail=False,
117            h_align='right',
118            maxwidth=300,
119            color=team.color,
120            jitter=1.0,
121        ).autoretain()
122
123    def _show_team_old_score(
124        self, pos_v: float, sessionteam: bs.SessionTeam, shiftdelay: float
125    ) -> None:
126        ZoomText(
127            str(sessionteam.customdata['score'] - 1),
128            position=(150, pos_v),
129            maxwidth=100,
130            color=(0.6, 0.6, 0.7),
131            shiftposition=(-100, pos_v),
132            shiftdelay=shiftdelay,
133            flash=False,
134            trail=False,
135            lifespan=1.0,
136            h_align='left',
137            jitter=1.0,
138        ).autoretain()
139
140    def _show_team_score(
141        self,
142        pos_v: float,
143        sessionteam: bs.SessionTeam,
144        scored: bool,
145        kill_delay: float,
146        shiftdelay: float,
147    ) -> None:
148        # pylint: disable=too-many-positional-arguments
149        del kill_delay  # Unused arg.
150        ZoomText(
151            str(sessionteam.customdata['score']),
152            position=(150, pos_v),
153            maxwidth=100,
154            color=(1.0, 0.9, 0.5) if scored else (0.6, 0.6, 0.7),
155            shiftposition=(-100, pos_v),
156            shiftdelay=shiftdelay,
157            flash=scored,
158            trail=scored,
159            h_align='left',
160            jitter=1.0,
161            trailcolor=(1, 0.8, 0.0, 0),
162        ).autoretain()
class TeamVictoryScoreScreenActivity(bascenev1._activity.Activity[bascenev1._player.EmptyPlayer, bascenev1._team.EmptyTeam]):
 16class TeamVictoryScoreScreenActivity(MultiTeamScoreScreenActivity):
 17    """Scorescreen between rounds of a dual-team session."""
 18
 19    def __init__(self, settings: dict):
 20        super().__init__(settings=settings)
 21        self._winner: bs.SessionTeam = settings['winner']
 22        assert isinstance(self._winner, bs.SessionTeam)
 23
 24    @override
 25    def on_begin(self) -> None:
 26        bs.set_analytics_screen('Teams Score Screen')
 27        super().on_begin()
 28
 29        height = 130
 30        active_team_count = len(self.teams)
 31        vval = (height * active_team_count) / 2 - height / 2
 32        i = 0
 33        shift_time = 2.5
 34
 35        # Usually we say 'Best of 7', but if the language prefers we can say
 36        # 'First to 4'.
 37        session = self.session
 38        assert isinstance(session, bs.MultiTeamSession)
 39        if bs.app.lang.get_resource('bestOfUseFirstToInstead'):
 40            best_txt = bs.Lstr(
 41                resource='firstToSeriesText',
 42                subs=[('${COUNT}', str(session.get_series_length() / 2 + 1))],
 43            )
 44        else:
 45            best_txt = bs.Lstr(
 46                resource='bestOfSeriesText',
 47                subs=[('${COUNT}', str(session.get_series_length()))],
 48            )
 49
 50        ZoomText(
 51            best_txt,
 52            position=(0, 175),
 53            shiftposition=(-250, 175),
 54            shiftdelay=2.5,
 55            flash=False,
 56            trail=False,
 57            h_align='center',
 58            scale=0.25,
 59            color=(0.5, 0.5, 0.5, 1.0),
 60            jitter=3.0,
 61        ).autoretain()
 62        for team in self.session.sessionteams:
 63            bs.timer(
 64                i * 0.15 + 0.15,
 65                bs.WeakCall(
 66                    self._show_team_name,
 67                    vval - i * height,
 68                    team,
 69                    i * 0.2,
 70                    shift_time - (i * 0.150 + 0.150),
 71                ),
 72            )
 73            bs.timer(i * 0.150 + 0.5, self._score_display_sound_small.play)
 74            scored = team is self._winner
 75            delay = 0.2
 76            if scored:
 77                delay = 1.2
 78                bs.timer(
 79                    i * 0.150 + 0.2,
 80                    bs.WeakCall(
 81                        self._show_team_old_score,
 82                        vval - i * height,
 83                        team,
 84                        shift_time - (i * 0.15 + 0.2),
 85                    ),
 86                )
 87                bs.timer(i * 0.15 + 1.5, self._score_display_sound.play)
 88
 89            bs.timer(
 90                i * 0.150 + delay,
 91                bs.WeakCall(
 92                    self._show_team_score,
 93                    vval - i * height,
 94                    team,
 95                    scored,
 96                    i * 0.2 + 0.1,
 97                    shift_time - (i * 0.15 + delay),
 98                ),
 99            )
100            i += 1
101        self.show_player_scores()
102
103    def _show_team_name(
104        self,
105        pos_v: float,
106        team: bs.SessionTeam,
107        kill_delay: float,
108        shiftdelay: float,
109    ) -> None:
110        del kill_delay  # Unused arg.
111        ZoomText(
112            bs.Lstr(value='${A}:', subs=[('${A}', team.name)]),
113            position=(100, pos_v),
114            shiftposition=(-150, pos_v),
115            shiftdelay=shiftdelay,
116            flash=False,
117            trail=False,
118            h_align='right',
119            maxwidth=300,
120            color=team.color,
121            jitter=1.0,
122        ).autoretain()
123
124    def _show_team_old_score(
125        self, pos_v: float, sessionteam: bs.SessionTeam, shiftdelay: float
126    ) -> None:
127        ZoomText(
128            str(sessionteam.customdata['score'] - 1),
129            position=(150, pos_v),
130            maxwidth=100,
131            color=(0.6, 0.6, 0.7),
132            shiftposition=(-100, pos_v),
133            shiftdelay=shiftdelay,
134            flash=False,
135            trail=False,
136            lifespan=1.0,
137            h_align='left',
138            jitter=1.0,
139        ).autoretain()
140
141    def _show_team_score(
142        self,
143        pos_v: float,
144        sessionteam: bs.SessionTeam,
145        scored: bool,
146        kill_delay: float,
147        shiftdelay: float,
148    ) -> None:
149        # pylint: disable=too-many-positional-arguments
150        del kill_delay  # Unused arg.
151        ZoomText(
152            str(sessionteam.customdata['score']),
153            position=(150, pos_v),
154            maxwidth=100,
155            color=(1.0, 0.9, 0.5) if scored else (0.6, 0.6, 0.7),
156            shiftposition=(-100, pos_v),
157            shiftdelay=shiftdelay,
158            flash=scored,
159            trail=scored,
160            h_align='left',
161            jitter=1.0,
162            trailcolor=(1, 0.8, 0.0, 0),
163        ).autoretain()

Scorescreen between rounds of a dual-team session.

TeamVictoryScoreScreenActivity(settings: dict)
19    def __init__(self, settings: dict):
20        super().__init__(settings=settings)
21        self._winner: bs.SessionTeam = settings['winner']
22        assert isinstance(self._winner, bs.SessionTeam)

Creates an Activity in the current bascenev1.Session.

The activity will not be actually run until bascenev1.Session.setactivity is called. 'settings' should be a dict of key/value pairs specific to the activity.

Activities should preload as much of their media/etc as possible in their constructor, but none of it should actually be used until they are transitioned in.

@override
def on_begin(self) -> None:
 24    @override
 25    def on_begin(self) -> None:
 26        bs.set_analytics_screen('Teams Score Screen')
 27        super().on_begin()
 28
 29        height = 130
 30        active_team_count = len(self.teams)
 31        vval = (height * active_team_count) / 2 - height / 2
 32        i = 0
 33        shift_time = 2.5
 34
 35        # Usually we say 'Best of 7', but if the language prefers we can say
 36        # 'First to 4'.
 37        session = self.session
 38        assert isinstance(session, bs.MultiTeamSession)
 39        if bs.app.lang.get_resource('bestOfUseFirstToInstead'):
 40            best_txt = bs.Lstr(
 41                resource='firstToSeriesText',
 42                subs=[('${COUNT}', str(session.get_series_length() / 2 + 1))],
 43            )
 44        else:
 45            best_txt = bs.Lstr(
 46                resource='bestOfSeriesText',
 47                subs=[('${COUNT}', str(session.get_series_length()))],
 48            )
 49
 50        ZoomText(
 51            best_txt,
 52            position=(0, 175),
 53            shiftposition=(-250, 175),
 54            shiftdelay=2.5,
 55            flash=False,
 56            trail=False,
 57            h_align='center',
 58            scale=0.25,
 59            color=(0.5, 0.5, 0.5, 1.0),
 60            jitter=3.0,
 61        ).autoretain()
 62        for team in self.session.sessionteams:
 63            bs.timer(
 64                i * 0.15 + 0.15,
 65                bs.WeakCall(
 66                    self._show_team_name,
 67                    vval - i * height,
 68                    team,
 69                    i * 0.2,
 70                    shift_time - (i * 0.150 + 0.150),
 71                ),
 72            )
 73            bs.timer(i * 0.150 + 0.5, self._score_display_sound_small.play)
 74            scored = team is self._winner
 75            delay = 0.2
 76            if scored:
 77                delay = 1.2
 78                bs.timer(
 79                    i * 0.150 + 0.2,
 80                    bs.WeakCall(
 81                        self._show_team_old_score,
 82                        vval - i * height,
 83                        team,
 84                        shift_time - (i * 0.15 + 0.2),
 85                    ),
 86                )
 87                bs.timer(i * 0.15 + 1.5, self._score_display_sound.play)
 88
 89            bs.timer(
 90                i * 0.150 + delay,
 91                bs.WeakCall(
 92                    self._show_team_score,
 93                    vval - i * height,
 94                    team,
 95                    scored,
 96                    i * 0.2 + 0.1,
 97                    shift_time - (i * 0.15 + delay),
 98                ),
 99            )
100            i += 1
101        self.show_player_scores()

Called once the previous Activity has finished transitioning out.

At this point the activity's initial players and teams are filled in and it should begin its actual game logic.

Inherited Members
bascenev1lib.activity.multiteamscore.MultiTeamScoreScreenActivity
show_player_scores
bascenev1._activitytypes.ScoreScreenActivity
transition_time
inherits_tint
inherits_vr_camera_offset
use_fixed_vr_overlay
default_music
on_player_join
on_transition_in
bascenev1._activity.Activity
settings_raw
teams
players
announce_player_deaths
is_joining_activity
allow_pausing
allow_kick_idle_players
slow_motion
inherits_slow_motion
inherits_music
inherits_vr_overlay_center
allow_mid_activity_joins
can_show_ad_on_death
paused_text
preloads
lobby
context
globalsnode
stats
on_expire
customdata
expired
playertype
teamtype
retain_actor
add_actor_weak_ref
session
on_player_leave
on_team_join
on_team_leave
on_transition_out
handlemessage
has_transitioned_in
has_begun
has_ended
is_transitioning_out
transition_out
end
create_player
create_team
bascenev1._dependency.DependencyComponent
dep_is_present
get_dynamic_deps