From 83e7388d497101d3e9aceb4b5fcce6545862d5a6 Mon Sep 17 00:00:00 2001 From: Eric Froemling Date: Sat, 30 May 2020 12:21:44 -0700 Subject: [PATCH] Tidying --- assets/src/ba_data/python/ba/_activity.py | 9 ++------ .../src/ba_data/python/ba/_activitytypes.py | 6 ++--- assets/src/ba_data/python/ba/_actor.py | 1 - assets/src/ba_data/python/ba/_benchmark.py | 12 +++++----- assets/src/ba_data/python/ba/_gameactivity.py | 23 ++++--------------- .../ba_data/python/ba/_multiteamsession.py | 23 ++++++++++--------- assets/src/ba_data/python/ba/_session.py | 5 +--- assets/src/ba_data/python/ba/_teamgame.py | 5 ++-- .../python/bastd/activity/coopscore.py | 2 +- .../python/bastd/activity/drawscore.py | 9 ++------ .../ba_data/python/bastd/game/runaround.py | 2 +- docs/ba_module.md | 2 +- 12 files changed, 37 insertions(+), 62 deletions(-) diff --git a/assets/src/ba_data/python/ba/_activity.py b/assets/src/ba_data/python/ba/_activity.py index fb02787c..95a1ae80 100644 --- a/assets/src/ba_data/python/ba/_activity.py +++ b/assets/src/ba_data/python/ba/_activity.py @@ -118,7 +118,7 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]): # Set this to true to inherit VR camera offsets from the previous # activity (useful for preventing sporadic camera movement # during transitions). - inherits_camera_vr_offset = False + inherits_vr_camera_offset = False # Set this to true to inherit (non-fixed) VR overlay positioning from # the previous activity (useful for prevent sporadic overlay jostling @@ -168,7 +168,6 @@ class Activity(DependencyComponent, Generic[PlayerType, 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] @@ -188,10 +187,6 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]): 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._activity_death_check_timer: Optional[ba.Timer] = None self._expired = False @@ -463,7 +458,7 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]): glb.music_continuous = True # Prevent restarting same music. glb.music = prev_globals.music glb.music_count += 1 - if self.inherits_camera_vr_offset and prev_globals is not None: + if self.inherits_vr_camera_offset and prev_globals is not None: glb.vr_camera_offset = prev_globals.vr_camera_offset if self.inherits_vr_overlay_center and prev_globals is not None: glb.vr_overlay_center = prev_globals.vr_overlay_center diff --git a/assets/src/ba_data/python/ba/_activitytypes.py b/assets/src/ba_data/python/ba/_activitytypes.py index 20986457..be0b79d8 100644 --- a/assets/src/ba_data/python/ba/_activitytypes.py +++ b/assets/src/ba_data/python/ba/_activitytypes.py @@ -46,7 +46,7 @@ class EndSessionActivity(Activity[Player, Team]): self.transition_time = 0.25 self.inherits_tint = True self.inherits_slow_motion = True - self.inherits_camera_vr_offset = True + self.inherits_vr_camera_offset = True self.inherits_vr_overlay_center = True def on_transition_in(self) -> None: @@ -114,7 +114,7 @@ class TransitionActivity(Activity[Player, Team]): self.transition_time = 0.5 self.inherits_slow_motion = True # Don't change. self.inherits_tint = True # Don't change. - self.inherits_camera_vr_offset = True # Don't change. + self.inherits_vr_camera_offset = True # Don't change. self.inherits_vr_overlay_center = True self.use_fixed_vr_overlay = True self._background: Optional[ba.Actor] = None @@ -144,7 +144,7 @@ class ScoreScreenActivity(Activity[Player, Team]): super().__init__(settings) self.transition_time = 0.5 self.inherits_tint = True - self.inherits_camera_vr_offset = True + self.inherits_vr_camera_offset = True self.use_fixed_vr_overlay = True self.default_music: Optional[MusicType] = MusicType.SCORES self._birth_time = _ba.time() diff --git a/assets/src/ba_data/python/ba/_actor.py b/assets/src/ba_data/python/ba/_actor.py index 2121940e..6fa9ea57 100644 --- a/assets/src/ba_data/python/ba/_actor.py +++ b/assets/src/ba_data/python/ba/_actor.py @@ -171,7 +171,6 @@ class Actor: so a simple "if myactor" test will conveniently do the right thing even if myactor is set to None. """ - return True def __bool__(self) -> bool: diff --git a/assets/src/ba_data/python/ba/_benchmark.py b/assets/src/ba_data/python/ba/_benchmark.py index ac9fb011..31be7db1 100644 --- a/assets/src/ba_data/python/ba/_benchmark.py +++ b/assets/src/ba_data/python/ba/_benchmark.py @@ -78,7 +78,7 @@ def run_stress_test(playlist_type: str = 'Random', from ba._enums import TimeType _ba.screenmessage( 'Beginning stress test.. use ' - '\'End Game\' to stop testing.', + "'End Game' to stop testing.", color=(1, 1, 0)) with _ba.Context('ui'): start_stress_test({ @@ -112,7 +112,7 @@ def start_stress_test(args: Dict[str, Any]) -> None: from ba._dualteamsession import DualTeamSession from ba._freeforallsession import FreeForAllSession from ba._enums import TimeType, TimeFormat - bs_config = _ba.app.config + appconfig = _ba.app.config playlist_type = args['playlist_type'] if playlist_type == 'Random': if random.random() < 0.5: @@ -122,15 +122,15 @@ def start_stress_test(args: Dict[str, Any]) -> None: _ba.screenmessage('Running Stress Test (listType="' + playlist_type + '", listName="' + args['playlist_name'] + '")...') if playlist_type == 'Teams': - bs_config['Team Tournament Playlist Selection'] = args['playlist_name'] - bs_config['Team Tournament Playlist Randomize'] = 1 + appconfig['Team Tournament Playlist Selection'] = args['playlist_name'] + appconfig['Team Tournament Playlist Randomize'] = 1 _ba.timer(1.0, Call(_ba.pushcall, Call(_ba.new_host_session, DualTeamSession)), timetype=TimeType.REAL) else: - bs_config['Free-for-All Playlist Selection'] = args['playlist_name'] - bs_config['Free-for-All Playlist Randomize'] = 1 + appconfig['Free-for-All Playlist Selection'] = args['playlist_name'] + appconfig['Free-for-All Playlist Randomize'] = 1 _ba.timer(1.0, Call(_ba.pushcall, Call(_ba.new_host_session, FreeForAllSession)), diff --git a/assets/src/ba_data/python/ba/_gameactivity.py b/assets/src/ba_data/python/ba/_gameactivity.py index a46c5367..1fdd940f 100644 --- a/assets/src/ba_data/python/ba/_gameactivity.py +++ b/assets/src/ba_data/python/ba/_gameactivity.py @@ -549,20 +549,6 @@ class GameActivity(Activity[PlayerType, TeamType]): # By default, just spawn a dude. self.spawn_player(player) - # def on_player_leave(self, player: PlayerType) -> None: - # super().on_player_leave(player) - - # # If the player has an actor, send it a deferred die message. - # # This way the player will be completely gone from the game - # # when the message goes through, making it less likely games - # # will incorrectly try to respawn them, etc. - # actor = player.actor - # if actor is not None: - # _ba.pushcall( - # Call(actor.handlemessage, - # DieMessage(how=DeathType.LEFT_GAME))) - # player.actor = None - def handlemessage(self, msg: Any) -> Any: if isinstance(msg, PlayerDiedMessage): # pylint: disable=cyclic-import @@ -759,7 +745,7 @@ class GameActivity(Activity[PlayerType, TeamType]): tip = tip['tip'] assert isinstance(tip, str) - # A few substitutions... + # Do a few substitutions. tip_lstr = Lstr(translate=('tips', tip), subs=[('${PICKUP}', _ba.charstr(SpecialChar.TOP_BUTTON))]) @@ -1104,10 +1090,11 @@ class GameActivity(Activity[PlayerType, TeamType]): if duration <= 0.0: return self._tournament_time_limit = int(duration) - # we want this timer to match the server's time as close as possible, - # so lets go with base-time.. theoretically we should do real-time but + + # We want this timer to match the server's time as close as possible, + # so lets go with base-time. Theoretically we should do real-time but # then we have to mess with contexts and whatnot since its currently - # not available in activity contexts... :-/ + # not available in activity contexts. :-/ self._tournament_time_limit_timer = _ba.Timer( 1.0, WeakCall(self._tournament_time_limit_tick), diff --git a/assets/src/ba_data/python/ba/_multiteamsession.py b/assets/src/ba_data/python/ba/_multiteamsession.py index d25165f1..25f5ab9f 100644 --- a/assets/src/ba_data/python/ba/_multiteamsession.py +++ b/assets/src/ba_data/python/ba/_multiteamsession.py @@ -254,14 +254,14 @@ class MultiTeamSession(Session): """ # pylint: disable=cyclic-import # pylint: disable=too-many-locals - from ba import _math - from ba import _general + from ba._math import normalized_color + from ba._general import Call from ba._gameutils import cameraflash - from ba import _lang + from ba._lang import Lstr from ba._freeforallsession import FreeForAllSession from ba._messages import CelebrateMessage - _ba.timer(delay, - _general.Call(_ba.playsound, _ba.getsound('boxingBell'))) + _ba.timer(delay, Call(_ba.playsound, _ba.getsound('boxingBell'))) + if announce_winning_team: winning_team = results.get_winning_team() if winning_team is not None: @@ -278,12 +278,13 @@ class MultiTeamSession(Session): wins_resource = 'winsPlayerText' else: wins_resource = 'winsTeamText' - wins_text = _lang.Lstr(resource=wins_resource, - subs=[('${NAME}', winning_team.name)]) - activity.show_zoom_message(wins_text, - scale=0.85, - color=_math.normalized_color( - winning_team.color)) + wins_text = Lstr(resource=wins_resource, + subs=[('${NAME}', winning_team.name)]) + activity.show_zoom_message( + wins_text, + scale=0.85, + color=normalized_color(winning_team.color), + ) class ShuffleList: diff --git a/assets/src/ba_data/python/ba/_session.py b/assets/src/ba_data/python/ba/_session.py index 12be8c93..61154cca 100644 --- a/assets/src/ba_data/python/ba/_session.py +++ b/assets/src/ba_data/python/ba/_session.py @@ -158,10 +158,8 @@ class Session: # Init our C++ layer data. self._sessiondata = _ba.register_session(self) - # Stuff in this section should be removed from this class if possible. + # Should remove this if possible. self.tournament_id: Optional[str] = None - self.sharedobjs: Dict[str, Any] = {} - self.have_shown_controls_help_overlay = False self.teams = [] self.players = [] @@ -193,7 +191,6 @@ class Session: color=color) self.teams.append(team) self._next_team_id += 1 - try: with _ba.Context(self): self.on_team_join(team) diff --git a/assets/src/ba_data/python/ba/_teamgame.py b/assets/src/ba_data/python/ba/_teamgame.py index 47c86520..c34a67b4 100644 --- a/assets/src/ba_data/python/ba/_teamgame.py +++ b/assets/src/ba_data/python/ba/_teamgame.py @@ -77,7 +77,8 @@ class TeamGameActivity(GameActivity[PlayerType, TeamType]): # (unless we're being run in co-op mode, in which case we leave # it up to them) if not isinstance(self.session, CoopSession): - if not self.session.have_shown_controls_help_overlay: + attrname = '_have_shown_ctrl_help_overlay' + if not getattr(self.session, attrname, False): delay = 4.0 lifespan = 10.0 if self.slow_motion: @@ -87,7 +88,7 @@ class TeamGameActivity(GameActivity[PlayerType, TeamType]): scale=0.8, position=(380, 200), bright=True).autoretain() - self.session.have_shown_controls_help_overlay = True + setattr(self.session, attrname, True) def on_begin(self) -> None: super().on_begin() diff --git a/assets/src/ba_data/python/bastd/activity/coopscore.py b/assets/src/ba_data/python/bastd/activity/coopscore.py index 4e1bacdb..e09d8d4c 100644 --- a/assets/src/ba_data/python/bastd/activity/coopscore.py +++ b/assets/src/ba_data/python/bastd/activity/coopscore.py @@ -48,7 +48,7 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]): # Keep prev activity alive while we fade in self.transition_time = 0.5 self.inherits_tint = True - self.inherits_camera_vr_offset = True + self.inherits_vr_camera_offset = True self.inherits_music = True self.use_fixed_vr_overlay = True diff --git a/assets/src/ba_data/python/bastd/activity/drawscore.py b/assets/src/ba_data/python/bastd/activity/drawscore.py index 4c5a5658..9508325e 100644 --- a/assets/src/ba_data/python/bastd/activity/drawscore.py +++ b/assets/src/ba_data/python/bastd/activity/drawscore.py @@ -26,6 +26,7 @@ from typing import TYPE_CHECKING import ba from bastd.activity.multiteamscore import MultiTeamScoreScreenActivity +from bastd.actor.zoomtext import ZoomText if TYPE_CHECKING: from typing import Any, Dict @@ -34,15 +35,9 @@ if TYPE_CHECKING: class DrawScoreScreenActivity(MultiTeamScoreScreenActivity): """Score screen shown after a draw.""" - def __init__(self, settings: Dict[str, Any]): - super().__init__(settings=settings) - - def on_transition_in(self) -> None: - self.default_music = None # Awkward silence... - super().on_transition_in() + default_music = None # Awkward silence... def on_begin(self) -> None: - from bastd.actor.zoomtext import ZoomText ba.set_analytics_screen('Draw Score Screen') super().on_begin() ZoomText(ba.Lstr(resource='drawText'), diff --git a/assets/src/ba_data/python/bastd/game/runaround.py b/assets/src/ba_data/python/bastd/game/runaround.py index b268fe4f..c303f557 100644 --- a/assets/src/ba_data/python/bastd/game/runaround.py +++ b/assets/src/ba_data/python/bastd/game/runaround.py @@ -90,7 +90,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]): settings['map'] = 'Tower D' super().__init__(settings) shared = SharedObjects.get() - self._preset = self.settings_raw.get('preset', 'pro') + self._preset = str(settings.get('preset', 'pro')) self._player_death_sound = ba.getsound('playerDeath') self._new_wave_sound = ba.getsound('scoreHit01') diff --git a/docs/ba_module.md b/docs/ba_module.md index 71e4cb0a..ae19599f 100644 --- a/docs/ba_module.md +++ b/docs/ba_module.md @@ -1,5 +1,5 @@ -

last updated on 2020-05-29 for Ballistica version 1.5.0 build 20035

+

last updated on 2020-05-30 for Ballistica version 1.5.0 build 20035

This page documents the Python classes and functions in the 'ba' module, which are the ones most relevant to modding in Ballistica. If you come across something you feel should be included here or could be better explained, please let me know. Happy modding!