mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-23 15:33:26 +08:00
Add should_allow_mid_activity_joins(activity: Activity) -> bool
This commit is contained in:
parent
843d064bd2
commit
fed8ca9400
@ -113,7 +113,7 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]):
|
||||
inherits_tint = False
|
||||
|
||||
# Whether players should be allowed to join in the middle of
|
||||
# activities.
|
||||
# activity.
|
||||
allow_mid_activity_joins: bool = True
|
||||
|
||||
# If the activity fades or transitions in, it should set the length of
|
||||
|
||||
@ -27,8 +27,6 @@ class CoopGameActivity(GameActivity[PlayerType, TeamType]):
|
||||
# We can assume our session is a CoopSession.
|
||||
session: ba.CoopSession
|
||||
|
||||
allow_mid_activity_joins = False
|
||||
|
||||
@classmethod
|
||||
def supports_session_type(cls, sessiontype: Type[ba.Session]) -> bool:
|
||||
from ba._coopsession import CoopSession
|
||||
|
||||
@ -90,6 +90,16 @@ class CoopSession(Session):
|
||||
"""Get the game instance currently being played."""
|
||||
return self._current_game_instance
|
||||
|
||||
def should_allow_mid_activity_joins(self, activity: Activity) -> bool:
|
||||
# pylint: disable=cyclic-import
|
||||
from ba._gameactivity import GameActivity
|
||||
|
||||
# Disallow any joins in the middle of the game.
|
||||
if isinstance(activity, GameActivity):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def _update_on_deck_game_instances(self) -> None:
|
||||
# pylint: disable=cyclic-import
|
||||
from ba._gameactivity import GameActivity
|
||||
|
||||
@ -205,6 +205,14 @@ class Session:
|
||||
raise NodeNotFoundError()
|
||||
return node
|
||||
|
||||
def should_allow_mid_activity_joins(self, activity: Activity) -> bool:
|
||||
"""Returned value is used by the Session to determine
|
||||
whether to allow players to join in the middle of activity.
|
||||
|
||||
Activity.allow_mid_activity_joins is also required to allow these
|
||||
joins."""
|
||||
return True
|
||||
|
||||
def on_player_request(self, player: ba.SessionPlayer) -> bool:
|
||||
"""Called when a new ba.Player wants to join the Session.
|
||||
|
||||
@ -651,7 +659,8 @@ class Session:
|
||||
# However, if we're not allowing mid-game joins, don't actually pass;
|
||||
# just announce the arrival and say they'll partake next round.
|
||||
if pass_to_activity:
|
||||
if not activity.allow_mid_activity_joins:
|
||||
if not (activity.allow_mid_activity_joins
|
||||
and self.should_allow_mid_activity_joins(activity)):
|
||||
pass_to_activity = False
|
||||
with _ba.Context(self):
|
||||
_ba.screenmessage(
|
||||
|
||||
@ -44,7 +44,11 @@ class MeteorShowerGame(ba.TeamGameActivity[Player, Team]):
|
||||
# Print messages when players die (since its meaningful in this game).
|
||||
announce_player_deaths = True
|
||||
|
||||
# we're currently hard-coded for one map..
|
||||
# Don't allow joining after we start
|
||||
# (would enable leave/rejoin tomfoolery).
|
||||
allow_mid_activity_joins = False
|
||||
|
||||
# We're currently hard-coded for one map.
|
||||
@classmethod
|
||||
def get_supported_maps(cls, sessiontype: Type[ba.Session]) -> List[str]:
|
||||
return ['Rampage']
|
||||
@ -93,22 +97,6 @@ class MeteorShowerGame(ba.TeamGameActivity[Player, Team]):
|
||||
# Check for immediate end (if we've only got 1 player, etc).
|
||||
ba.timer(5.0, self._check_end_game)
|
||||
|
||||
def on_player_join(self, player: Player) -> None:
|
||||
# Don't allow joining after we start
|
||||
# (would enable leave/rejoin tomfoolery).
|
||||
if self.has_begun():
|
||||
ba.screenmessage(
|
||||
ba.Lstr(resource='playerDelayedJoinText',
|
||||
subs=[('${PLAYER}', player.getname(full=True))]),
|
||||
color=(0, 1, 0),
|
||||
)
|
||||
# For score purposes, mark them as having died right as the
|
||||
# game started.
|
||||
assert self._timer is not None
|
||||
player.death_time = self._timer.getstarttime()
|
||||
return
|
||||
self.spawn_player(player)
|
||||
|
||||
def on_player_leave(self, player: Player) -> None:
|
||||
# Augment default behavior.
|
||||
super().on_player_leave(player)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user