mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-07 08:03:30 +08:00
Exceptions typing in bastd module
This commit is contained in:
parent
5b5aee6faf
commit
9143415308
@ -149,8 +149,8 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
self._score_order: str
|
self._score_order: str
|
||||||
if 'score_order' in settings:
|
if 'score_order' in settings:
|
||||||
if not settings['score_order'] in ['increasing', 'decreasing']:
|
if not settings['score_order'] in ['increasing', 'decreasing']:
|
||||||
raise Exception('Invalid score order: ' +
|
raise ValueError('Invalid score order: ' +
|
||||||
settings['score_order'])
|
settings['score_order'])
|
||||||
self._score_order = settings['score_order']
|
self._score_order = settings['score_order']
|
||||||
else:
|
else:
|
||||||
self._score_order = 'increasing'
|
self._score_order = 'increasing'
|
||||||
@ -159,8 +159,8 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
self._score_type: str
|
self._score_type: str
|
||||||
if 'score_type' in settings:
|
if 'score_type' in settings:
|
||||||
if not settings['score_type'] in ['points', 'time']:
|
if not settings['score_type'] in ['points', 'time']:
|
||||||
raise Exception('Invalid score type: ' +
|
raise ValueError('Invalid score type: ' +
|
||||||
settings['score_type'])
|
settings['score_type'])
|
||||||
self._score_type = settings['score_type']
|
self._score_type = settings['score_type']
|
||||||
else:
|
else:
|
||||||
self._score_type = 'points'
|
self._score_type = 'points'
|
||||||
@ -172,7 +172,7 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
self._game_name_str = self._campaign.name + ':' + self._level_name
|
self._game_name_str = self._campaign.name + ':' + self._level_name
|
||||||
self._game_config_str = str(len(
|
self._game_config_str = str(len(
|
||||||
self._player_info)) + 'p' + self._campaign.get_level(
|
self._player_info)) + 'p' + self._campaign.get_level(
|
||||||
self._level_name).get_score_version_string().replace(' ', '_')
|
self._level_name).get_score_version_string().replace(' ', '_')
|
||||||
|
|
||||||
# If game-center/etc scores are available we show our friends'
|
# If game-center/etc scores are available we show our friends'
|
||||||
# scores. Otherwise we show our local high scores.
|
# scores. Otherwise we show our local high scores.
|
||||||
@ -265,7 +265,7 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
# If we didn't just complete this level but are choosing to play the
|
# If we didn't just complete this level but are choosing to play the
|
||||||
# next one, set it as current (this won't happen otherwise).
|
# next one, set it as current (this won't happen otherwise).
|
||||||
if (self._is_complete and self._is_more_levels
|
if (self._is_complete and self._is_more_levels
|
||||||
and not self._newly_complete):
|
and not self._newly_complete):
|
||||||
assert self._next_level_name is not None
|
assert self._next_level_name is not None
|
||||||
self._campaign.set_selected_level(self._next_level_name)
|
self._campaign.set_selected_level(self._next_level_name)
|
||||||
ba.containerwidget(edit=self._root_ui, transition='out_left')
|
ba.containerwidget(edit=self._root_ui, transition='out_left')
|
||||||
@ -387,7 +387,8 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
label=ba.Lstr(resource='tournamentStandingsText')
|
label=ba.Lstr(resource='tournamentStandingsText')
|
||||||
if self.session.tournament_id is not None else ba.Lstr(
|
if self.session.tournament_id is not None else ba.Lstr(
|
||||||
resource='worldsBestScoresText') if self._score_type
|
resource='worldsBestScoresText') if self._score_type
|
||||||
== 'points' else ba.Lstr(resource='worldsBestTimesText'),
|
== 'points' else ba.Lstr(
|
||||||
|
resource='worldsBestTimesText'),
|
||||||
autoselect=True,
|
autoselect=True,
|
||||||
on_activate_call=ba.WeakCall(self._ui_worlds_best),
|
on_activate_call=ba.WeakCall(self._ui_worlds_best),
|
||||||
transition_delay=delay + 1.9,
|
transition_delay=delay + 1.9,
|
||||||
@ -548,7 +549,7 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
ba.timer(1.0, ba.WeakCall(self.request_ui))
|
ba.timer(1.0, ba.WeakCall(self.request_ui))
|
||||||
|
|
||||||
if (self._is_complete and self._victory and self._is_more_levels
|
if (self._is_complete and self._victory and self._is_more_levels
|
||||||
and not ba.app.kiosk_mode):
|
and not ba.app.kiosk_mode):
|
||||||
Text(ba.Lstr(value='${A}:\n',
|
Text(ba.Lstr(value='${A}:\n',
|
||||||
subs=[('${A}', ba.Lstr(resource='levelUnlockedText'))
|
subs=[('${A}', ba.Lstr(resource='levelUnlockedText'))
|
||||||
]) if self._newly_complete else
|
]) if self._newly_complete else
|
||||||
@ -646,11 +647,11 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
transition_delay=2.0)
|
transition_delay=2.0)
|
||||||
self._score_loading_status = Text(ba.Lstr(
|
self._score_loading_status = Text(ba.Lstr(
|
||||||
value='${A}...', subs=[('${A}', ba.Lstr(resource='loadingText'))]),
|
value='${A}...', subs=[('${A}', ba.Lstr(resource='loadingText'))]),
|
||||||
position=(280, 150 + 30),
|
position=(280, 150 + 30),
|
||||||
color=(1, 1, 1, 0.4),
|
color=(1, 1, 1, 0.4),
|
||||||
transition=Text.Transition.FADE_IN,
|
transition=Text.Transition.FADE_IN,
|
||||||
scale=0.7,
|
scale=0.7,
|
||||||
transition_delay=2.0)
|
transition_delay=2.0)
|
||||||
|
|
||||||
if self._score is not None:
|
if self._score is not None:
|
||||||
ba.timer(0.4, ba.WeakCall(self._play_drumroll))
|
ba.timer(0.4, ba.WeakCall(self._play_drumroll))
|
||||||
@ -727,8 +728,9 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
v_offs = 40
|
v_offs = 40
|
||||||
txt = Text(ba.Lstr(resource='tournamentStandingsText')
|
txt = Text(ba.Lstr(resource='tournamentStandingsText')
|
||||||
if self.session.tournament_id is not None else ba.Lstr(
|
if self.session.tournament_id is not None else ba.Lstr(
|
||||||
resource='worldsBestScoresText') if self._score_type
|
resource='worldsBestScoresText') if self._score_type
|
||||||
== 'points' else ba.Lstr(resource='worldsBestTimesText'),
|
== 'points' else ba.Lstr(
|
||||||
|
resource='worldsBestTimesText'),
|
||||||
maxwidth=210,
|
maxwidth=210,
|
||||||
position=(ts_h_offs - 10, ts_height / 2 + 25 + v_offs + 20),
|
position=(ts_h_offs - 10, ts_height / 2 + 25 + v_offs + 20),
|
||||||
transition=Text.Transition.IN_LEFT,
|
transition=Text.Transition.IN_LEFT,
|
||||||
@ -764,7 +766,8 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
ts_h_offs = -480
|
ts_h_offs = -480
|
||||||
v_offs = 40
|
v_offs = 40
|
||||||
Text(ba.Lstr(resource='yourBestScoresText') if self._score_type
|
Text(ba.Lstr(resource='yourBestScoresText') if self._score_type
|
||||||
== 'points' else ba.Lstr(resource='yourBestTimesText'),
|
== 'points' else ba.Lstr(
|
||||||
|
resource='yourBestTimesText'),
|
||||||
maxwidth=210,
|
maxwidth=210,
|
||||||
position=(ts_h_offs - 10, ts_height / 2 + 25 + v_offs + 20),
|
position=(ts_h_offs - 10, ts_height / 2 + 25 + v_offs + 20),
|
||||||
transition=Text.Transition.IN_RIGHT,
|
transition=Text.Transition.IN_RIGHT,
|
||||||
@ -1396,12 +1399,12 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
|||||||
str(int(self._show_info['results']['rank']))),
|
str(int(self._show_info['results']['rank']))),
|
||||||
('${ALL}', str(self._show_info['results']['total']))
|
('${ALL}', str(self._show_info['results']['total']))
|
||||||
]),
|
]),
|
||||||
position=(0, -155 if self._newly_complete else -145),
|
position=(0, -155 if self._newly_complete else -145),
|
||||||
color=(1, 1, 1, 0.7),
|
color=(1, 1, 1, 0.7),
|
||||||
h_align=Text.HAlign.CENTER,
|
h_align=Text.HAlign.CENTER,
|
||||||
transition=Text.Transition.FADE_IN,
|
transition=Text.Transition.FADE_IN,
|
||||||
scale=0.55,
|
scale=0.55,
|
||||||
transition_delay=1.0).autoretain()
|
transition_delay=1.0).autoretain()
|
||||||
|
|
||||||
new_best = (best_rank > self._old_best_rank and best_rank > 0.0)
|
new_best = (best_rank > self._old_best_rank and best_rank > 0.0)
|
||||||
was_string = ba.Lstr(value=' ${A}',
|
was_string = ba.Lstr(value=' ${A}',
|
||||||
|
|||||||
@ -665,7 +665,7 @@ class Bomb(ba.Actor):
|
|||||||
|
|
||||||
if bomb_type not in ('ice', 'impact', 'land_mine', 'normal', 'sticky',
|
if bomb_type not in ('ice', 'impact', 'land_mine', 'normal', 'sticky',
|
||||||
'tnt'):
|
'tnt'):
|
||||||
raise Exception('invalid bomb type: ' + bomb_type)
|
raise ValueError('invalid bomb type: ' + bomb_type)
|
||||||
self.bomb_type = bomb_type
|
self.bomb_type = bomb_type
|
||||||
|
|
||||||
self._exploded = False
|
self._exploded = False
|
||||||
|
|||||||
@ -95,7 +95,7 @@ class OnScreenTimer(ba.Actor):
|
|||||||
assert isinstance(endtime, int)
|
assert isinstance(endtime, int)
|
||||||
endtime_ms = endtime
|
endtime_ms = endtime
|
||||||
else:
|
else:
|
||||||
raise Exception(f'invalid timeformat: {timeformat}')
|
raise ValueError(f'invalid timeformat: {timeformat}')
|
||||||
|
|
||||||
self.inputnode.timemax = endtime_ms - self._starttime
|
self.inputnode.timemax = endtime_ms - self._starttime
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ class OnScreenTimer(ba.Actor):
|
|||||||
return 0.001 * val_ms
|
return 0.001 * val_ms
|
||||||
if timeformat is ba.TimeFormat.MILLISECONDS:
|
if timeformat is ba.TimeFormat.MILLISECONDS:
|
||||||
return val_ms
|
return val_ms
|
||||||
raise Exception(f'invalid timeformat: {timeformat}')
|
raise ValueError(f'invalid timeformat: {timeformat}')
|
||||||
|
|
||||||
def handlemessage(self, msg: Any) -> Any:
|
def handlemessage(self, msg: Any) -> Any:
|
||||||
# if we're asked to die, just kill our node/timer
|
# if we're asked to die, just kill our node/timer
|
||||||
|
|||||||
@ -187,7 +187,7 @@ def get_factory() -> PowerupBoxFactory:
|
|||||||
"""Return a shared ba.PowerupBoxFactory object, creating if necessary."""
|
"""Return a shared ba.PowerupBoxFactory object, creating if necessary."""
|
||||||
activity = ba.getactivity()
|
activity = ba.getactivity()
|
||||||
if activity is None:
|
if activity is None:
|
||||||
raise Exception('no current activity')
|
raise RuntimeError('no current activity')
|
||||||
try:
|
try:
|
||||||
# FIXME: et better way to store stuff with activity
|
# FIXME: et better way to store stuff with activity
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
@ -252,10 +252,10 @@ class PowerupBox(ba.Actor):
|
|||||||
elif poweruptype == 'curse':
|
elif poweruptype == 'curse':
|
||||||
tex = factory.tex_curse
|
tex = factory.tex_curse
|
||||||
else:
|
else:
|
||||||
raise Exception('invalid poweruptype: ' + str(poweruptype))
|
raise ValueError('invalid poweruptype: ' + str(poweruptype))
|
||||||
|
|
||||||
if len(position) != 3:
|
if len(position) != 3:
|
||||||
raise Exception('expected 3 floats for position')
|
raise ValueError('expected 3 floats for position')
|
||||||
|
|
||||||
self.node = ba.newnode(
|
self.node = ba.newnode(
|
||||||
'prop',
|
'prop',
|
||||||
|
|||||||
@ -1384,7 +1384,7 @@ class Spaz(ba.Actor):
|
|||||||
return bomb_factory.tex_ice_bombs
|
return bomb_factory.tex_ice_bombs
|
||||||
if self.bomb_type == 'impact':
|
if self.bomb_type == 'impact':
|
||||||
return bomb_factory.tex_impact_bombs
|
return bomb_factory.tex_impact_bombs
|
||||||
raise Exception()
|
raise ValueError('invalid bomb type')
|
||||||
|
|
||||||
def _flash_billboard(self, tex: ba.Texture) -> None:
|
def _flash_billboard(self, tex: ba.Texture) -> None:
|
||||||
assert self.node
|
assert self.node
|
||||||
|
|||||||
@ -224,7 +224,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
|||||||
]},
|
]},
|
||||||
{'entries': [
|
{'entries': [
|
||||||
{'type': spazbot.ChargerBotProShielded if hard
|
{'type': spazbot.ChargerBotProShielded if hard
|
||||||
else spazbot.ChargerBot, 'path': 1},
|
else spazbot.ChargerBot, 'path': 1},
|
||||||
{'type': spazbot.BrawlerBot, 'path': 2} if hard else None,
|
{'type': spazbot.BrawlerBot, 'path': 2} if hard else None,
|
||||||
{'type': spazbot.BrawlerBot, 'path': 2},
|
{'type': spazbot.BrawlerBot, 'path': 2},
|
||||||
{'type': spazbot.BrawlerBot, 'path': 2},
|
{'type': spazbot.BrawlerBot, 'path': 2},
|
||||||
@ -273,7 +273,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
|||||||
{'type': spazbot.TriggerBot, 'path': 2},
|
{'type': spazbot.TriggerBot, 'path': 2},
|
||||||
{'type': spazbot.TriggerBot, 'path': 3},
|
{'type': spazbot.TriggerBot, 'path': 3},
|
||||||
{'type': spazbot.BrawlerBotPro if hard
|
{'type': spazbot.BrawlerBotPro if hard
|
||||||
else spazbot.BrawlerBot, 'point': 'bottom_left'},
|
else spazbot.BrawlerBot, 'point': 'bottom_left'},
|
||||||
{'type': spazbot.BrawlerBotPro, 'point': 'bottom_right'}
|
{'type': spazbot.BrawlerBotPro, 'point': 'bottom_right'}
|
||||||
if player_count > 2 else None,
|
if player_count > 2 else None,
|
||||||
]},
|
]},
|
||||||
@ -312,7 +312,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
|||||||
]},
|
]},
|
||||||
{'entries': [
|
{'entries': [
|
||||||
{'type': spazbot.TriggerBotProShielded if hard
|
{'type': spazbot.TriggerBotProShielded if hard
|
||||||
else spazbot.TriggerBotPro, 'point': 'bottom_left'},
|
else spazbot.TriggerBotPro, 'point': 'bottom_left'},
|
||||||
{'type': spazbot.TriggerBotProShielded,
|
{'type': spazbot.TriggerBotProShielded,
|
||||||
'point': 'bottom_right'}
|
'point': 'bottom_right'}
|
||||||
if hard else None,
|
if hard else None,
|
||||||
@ -526,7 +526,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
|||||||
position=pos,
|
position=pos,
|
||||||
poweruptype=powerupbox.get_factory().get_random_powerup_type(
|
poweruptype=powerupbox.get_factory().get_random_powerup_type(
|
||||||
excludetypes=self._exclude_powerups +
|
excludetypes=self._exclude_powerups +
|
||||||
extra_excludes)).autoretain()
|
extra_excludes)).autoretain()
|
||||||
|
|
||||||
def end_game(self) -> None:
|
def end_game(self) -> None:
|
||||||
|
|
||||||
@ -574,7 +574,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
|||||||
|
|
||||||
# If we have no living bots, go to the next wave.
|
# If we have no living bots, go to the next wave.
|
||||||
if (self._can_end_wave and not self._bots.have_living_bots()
|
if (self._can_end_wave and not self._bots.have_living_bots()
|
||||||
and not self._game_over and self._lives > 0):
|
and not self._game_over and self._lives > 0):
|
||||||
|
|
||||||
self._can_end_wave = False
|
self._can_end_wave = False
|
||||||
self._time_bonus_timer = None
|
self._time_bonus_timer = None
|
||||||
@ -653,9 +653,9 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
|||||||
value='+${A} ${B}',
|
value='+${A} ${B}',
|
||||||
subs=[('${A}', str(bonus)),
|
subs=[('${A}', str(bonus)),
|
||||||
('${B}', ba.Lstr(resource='completionBonusText'))]),
|
('${B}', ba.Lstr(resource='completionBonusText'))]),
|
||||||
color=(0.7, 0.7, 1.0, 1),
|
color=(0.7, 0.7, 1.0, 1),
|
||||||
scale=1.6,
|
scale=1.6,
|
||||||
position=(0, 1.5, -1)).autoretain()
|
position=(0, 1.5, -1)).autoretain()
|
||||||
self._score += bonus
|
self._score += bonus
|
||||||
self._update_scores()
|
self._update_scores()
|
||||||
|
|
||||||
@ -839,7 +839,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
|||||||
len(defender_types))]
|
len(defender_types))]
|
||||||
defender1 = defender2 = None
|
defender1 = defender2 = None
|
||||||
if ((group == 0) or (group == 1 and level > 3)
|
if ((group == 0) or (group == 1 and level > 3)
|
||||||
or (group == 2 and level > 5)):
|
or (group == 2 and level > 5)):
|
||||||
if random.random() < min(0.75, (level - 1) * 0.11):
|
if random.random() < min(0.75, (level - 1) * 0.11):
|
||||||
this_target_point_s, defender1 = _add_defender(
|
this_target_point_s, defender1 = _add_defender(
|
||||||
defender_type1, 'bottom_left')
|
defender_type1, 'bottom_left')
|
||||||
@ -1109,8 +1109,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
|||||||
return True
|
return True
|
||||||
if ((ba.is_point_in_box(pos, boxes['b8'])
|
if ((ba.is_point_in_box(pos, boxes['b8'])
|
||||||
and not ba.is_point_in_box(pos, boxes['b9']))
|
and not ba.is_point_in_box(pos, boxes['b9']))
|
||||||
or pos == (0.0, 0.0, 0.0)):
|
or pos == (0.0, 0.0, 0.0)):
|
||||||
|
|
||||||
# Default to walking right if we're still in the walking area.
|
# Default to walking right if we're still in the walking area.
|
||||||
bot.node.move_left_right = speed
|
bot.node.move_left_right = speed
|
||||||
bot.node.move_up_down = 0
|
bot.node.move_up_down = 0
|
||||||
@ -1177,7 +1176,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
|||||||
def _get_bot_speed(self, bot_type: Type[spazbot.SpazBot]) -> float:
|
def _get_bot_speed(self, bot_type: Type[spazbot.SpazBot]) -> float:
|
||||||
speed = self._bot_speed_map.get(bot_type)
|
speed = self._bot_speed_map.get(bot_type)
|
||||||
if speed is None:
|
if speed is None:
|
||||||
raise Exception('Invalid bot type to _get_bot_speed(): ' +
|
raise TypeError('Invalid bot type to _get_bot_speed(): ' +
|
||||||
str(bot_type))
|
str(bot_type))
|
||||||
return speed
|
return speed
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user