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

Scorescreen between rounds of a dual-team session.

TeamVictoryScoreScreenActivity(settings: dict)
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)

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:
 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()

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