def __init__(self, settings: Dict[str, Any]): """Creates an activity in the current ba.Session. The activity will not be actually run until ba.Session.set_activity() 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. """ super().__init__() # FIXME: Relocate this stuff. self.sharedobjs: Dict[str, Any] = {} self.paused_text: Optional[ba.Actor] = None self.spaz_respawn_icons_right: Dict[int, RespawnIcon] # Create our internal engine data. self._activity_data = _ba.register_activity(self) session = _ba.getsession() if session is None: raise Exception("No current session") self._session = weakref.ref(session) # Preloaded data for actors, maps, etc; indexed by type. self.preloads: Dict[Type, Any] = {} if not isinstance(settings, dict): raise Exception("expected dict for settings") if _ba.getactivity(doraise=False) is not self: raise Exception('invalid context state') self.settings = settings self._has_transitioned_in = False self._has_begun = False self._has_ended = False self._should_end_immediately = False self._should_end_immediately_results: ( Optional[ba.TeamGameResults]) = None self._should_end_immediately_delay = 0.0 self._called_activity_on_transition_in = False self._called_activity_on_begin = False self._activity_death_check_timer: Optional[ba.Timer] = None self._expired = False # Whether to print every time a player dies. This can be pertinent # in games such as Death-Match but can be annoying in games where it # doesn't matter. self.announce_player_deaths = False # Joining activities are for waiting for initial player joins. # They are treated slightly differently than regular activities, # mainly in that all players are passed to the activity at once # instead of as each joins. self.is_joining_activity = False # Whether game-time should still progress when in menus/etc. self.allow_pausing = False # Whether idle players can potentially be kicked (should not happen in # menus/etc). self.allow_kick_idle_players = True # In vr mode, this determines whether overlay nodes (text, images, etc) # are created at a fixed position in space or one that moves based on # the current map. Generally this should be on for games and off for # transitions/score-screens/etc. that persist between maps. self.use_fixed_vr_overlay = False # If True, runs in slow motion and turns down sound pitch. self.slow_motion = False # Set this to True to inherit slow motion setting from previous # activity (useful for transitions to avoid hitches). self.inherits_slow_motion = False # Set this to True to keep playing the music from the previous activity # (without even restarting it). self.inherits_music = False # Set this to true to inherit VR camera offsets from the previous # activity (useful for preventing sporadic camera movement # during transitions). self.inherits_camera_vr_offset = False # Set this to true to inherit (non-fixed) VR overlay positioning from # the previous activity (useful for prevent sporadic overlay jostling # during transitions). self.inherits_vr_overlay_center = False # Set this to true to inherit screen tint/vignette colors from the # previous activity (useful to prevent sudden color changes during # transitions). self.inherits_tint = False # If the activity fades or transitions in, it should set the length of # time here so that previous activities will be kept alive for that # long (avoiding 'holes' in the screen) # This value is given in real-time seconds. self.transition_time = 0.0 # Is it ok to show an ad after this activity ends before showing # the next activity? self.can_show_ad_on_death = False # This gets set once another activity has begun transitioning in but # before this one is killed. The on_transition_out() method is also # called at this time. Make sure to not assign player inputs, # change music, or anything else with global implications once this # happens. self._transitioning_out = False # A handy place to put most actors; this list is pruned of dead # actors regularly and these actors are insta-killed as the activity # is dying. self._actor_refs: List[ba.Actor] = [] self._actor_weak_refs: List[ReferenceType[ba.Actor]] = [] self._last_dead_object_prune_time = _ba.time() # This stuff gets filled in just before on_begin() is called. self.teams = [] self.players = [] self._stats: Optional[ba.Stats] = None self.lobby = None self._prune_dead_objects_timer: Optional[ba.Timer] = None
def __init__(self, settings: dict): """Creates an Activity in the current ba.Session. The activity will not be actually run until ba.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. """ super().__init__() # Create our internal engine data. self._activity_data = _ba.register_activity(self) assert isinstance(settings, dict) assert _ba.getactivity() is self self._globalsnode: Optional[ba.Node] = None # Player/Team types should have been specified as type args; # grab those. self._playertype: type[PlayerType] self._teamtype: type[TeamType] self._setup_player_and_team_types() # FIXME: Relocate or remove the need for this stuff. self.paused_text: Optional[ba.Actor] = None self._session = weakref.ref(_ba.getsession()) # Preloaded data for actors, maps, etc; indexed by type. self.preloads: dict[type, Any] = {} # Hopefully can eventually kill this; activities should # validate/store whatever settings they need at init time # (in a more type-safe way). self.settings_raw = settings self._has_transitioned_in = False self._has_begun = False self._has_ended = False self._activity_death_check_timer: Optional[ba.Timer] = None self._expired = False self._delay_delete_players: list[PlayerType] = [] self._delay_delete_teams: list[TeamType] = [] self._players_that_left: list[weakref.ref[PlayerType]] = [] self._teams_that_left: list[weakref.ref[TeamType]] = [] self._transitioning_out = False # A handy place to put most actors; this list is pruned of dead # actors regularly and these actors are insta-killed as the activity # is dying. self._actor_refs: list[ba.Actor] = [] self._actor_weak_refs: list[weakref.ref[ba.Actor]] = [] self._last_prune_dead_actors_time = _ba.time() self._prune_dead_actors_timer: Optional[ba.Timer] = None self.teams = [] self.players = [] self.lobby = None self._stats: Optional[ba.Stats] = None self._customdata: Optional[dict] = {}
def __init__(self, settings: Dict[str, Any]): """Creates an Activity in the current ba.Session. The activity will not be actually run until ba.Session.set_activity() 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. """ super().__init__() # Create our internal engine data. self._activity_data = _ba.register_activity(self) # Player/Team types should have been specified as type args; # grab those. self._playertype: Type[PlayerType] self._teamtype: Type[TeamType] self._setup_player_and_team_types() # FIXME: Relocate or remove the need for this stuff. self.sharedobjs: Dict[str, Any] = {} self.paused_text: Optional[ba.Actor] = None self.spaz_respawn_icons_right: Dict[int, RespawnIcon] session = _ba.getsession() if session is None: raise RuntimeError('No current session') self._session = weakref.ref(session) # Preloaded data for actors, maps, etc; indexed by type. self.preloads: Dict[Type, Any] = {} if not isinstance(settings, dict): raise TypeError('expected dict for settings') if _ba.getactivity(doraise=False) is not self: raise Exception('invalid context state') # Hopefully can eventually kill this; activities should # validate/store whatever settings they need at init time # (in a more type-safe way). self.settings_raw = settings self._has_transitioned_in = False self._has_begun = False self._has_ended = False self._should_end_immediately = False self._should_end_immediately_results: ( Optional[ba.TeamGameResults]) = None self._should_end_immediately_delay = 0.0 self._called_activity_on_transition_in = False self._called_activity_on_begin = False self._activity_death_check_timer: Optional[ba.Timer] = None self._expired = False # This gets set once another activity has begun transitioning in but # before this one is killed. The on_transition_out() method is also # called at this time. Make sure to not assign player inputs, # change music, or anything else with global implications once this # happens. self._transitioning_out = False # A handy place to put most actors; this list is pruned of dead # actors regularly and these actors are insta-killed as the activity # is dying. self._actor_refs: List[ba.Actor] = [] self._actor_weak_refs: List[ReferenceType[ba.Actor]] = [] self._last_prune_dead_actors_time = _ba.time() self._prune_dead_actors_timer: Optional[ba.Timer] = None # This stuff gets filled in just before on_begin() is called. self.teams = [] self.players = [] self.lobby = None self._stats: Optional[ba.Stats] = None