mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-25 08:23:35 +08:00
Merge pull request #42 from Dliwk/pr42
Exceptions cleanup and fix FFA spawn
This commit is contained in:
commit
354ba3e997
@ -83,7 +83,7 @@ def get_league_rank_points(data: Optional[Dict[str, Any]],
|
||||
assert isinstance(trophies_total, int)
|
||||
return trophies_total
|
||||
if subset is not None:
|
||||
raise Exception('invalid subset value: ' + str(subset))
|
||||
raise ValueError('invalid subset value: ' + str(subset))
|
||||
|
||||
if data['p']:
|
||||
pro_mult = 1.0 + float(
|
||||
|
||||
@ -140,7 +140,7 @@ def get_achievement(name: str) -> Achievement:
|
||||
achs = [a for a in _ba.app.achievements if a.name == name]
|
||||
assert len(achs) < 2
|
||||
if not achs:
|
||||
raise Exception("Invalid achievement name: '" + name + "'")
|
||||
raise ValueError("Invalid achievement name: '" + name + "'")
|
||||
return achs[0]
|
||||
|
||||
|
||||
@ -396,7 +396,7 @@ class Achievement:
|
||||
v_attach = Text.VAttach.TOP
|
||||
attach = Image.Attach.TOP_CENTER
|
||||
else:
|
||||
raise Exception('invalid style "' + style + '"')
|
||||
raise ValueError('invalid style "' + style + '"')
|
||||
|
||||
# Attempt to determine what campaign we're in
|
||||
# (so we know whether to show "hard mode only").
|
||||
|
||||
@ -166,14 +166,14 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]):
|
||||
|
||||
session = _ba.getsession()
|
||||
if session is None:
|
||||
raise Exception('No current session')
|
||||
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 Exception('expected dict for settings')
|
||||
raise TypeError('expected dict for settings')
|
||||
if _ba.getactivity(doraise=False) is not self:
|
||||
raise Exception('invalid context state')
|
||||
|
||||
@ -292,8 +292,8 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]):
|
||||
(internal)
|
||||
"""
|
||||
if self.has_begun():
|
||||
raise Exception('This should only be called for Activities'
|
||||
'that have not yet begun.')
|
||||
raise RuntimeError('This should only be called for Activities'
|
||||
'that have not yet begun.')
|
||||
if not self._should_end_immediately or force:
|
||||
self._should_end_immediately = True
|
||||
self._should_end_immediately_results = results
|
||||
@ -340,7 +340,7 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]):
|
||||
"""
|
||||
from ba import _actor as bsactor
|
||||
if not isinstance(actor, bsactor.Actor):
|
||||
raise Exception('non-actor passed to _retain_actor')
|
||||
raise TypeError('non-actor passed to retain_actor')
|
||||
if (self.has_transitioned_in()
|
||||
and _ba.time() - self._last_prune_dead_actors_time > 10.0):
|
||||
print_error('it looks like nodes/actors are not'
|
||||
@ -356,7 +356,7 @@ class Activity(DependencyComponent, Generic[PlayerType, TeamType]):
|
||||
"""
|
||||
from ba import _actor as bsactor
|
||||
if not isinstance(actor, bsactor.Actor):
|
||||
raise Exception('non-actor passed to _add_actor_weak_ref')
|
||||
raise TypeError('non-actor passed to add_actor_weak_ref')
|
||||
if (self.has_transitioned_in()
|
||||
and _ba.time() - self._last_prune_dead_actors_time > 10.0):
|
||||
print_error('it looks like nodes/actors are '
|
||||
|
||||
@ -729,7 +729,7 @@ class App:
|
||||
if args is None:
|
||||
args = {}
|
||||
if game == '':
|
||||
raise Exception('empty game name')
|
||||
raise ValueError('empty game name')
|
||||
campaignname, levelname = game.split(':')
|
||||
campaign = get_campaign(campaignname)
|
||||
levels = campaign.get_levels()
|
||||
|
||||
@ -64,7 +64,7 @@ class Campaign:
|
||||
def add_level(self, level: ba.Level) -> None:
|
||||
"""Adds a ba.Level to the Campaign."""
|
||||
if level.get_campaign() is not None:
|
||||
raise Exception('level already belongs to a campaign')
|
||||
raise RuntimeError('level already belongs to a campaign')
|
||||
level.set_campaign(self, len(self._levels))
|
||||
self._levels.append(level)
|
||||
|
||||
@ -74,11 +74,13 @@ class Campaign:
|
||||
|
||||
def get_level(self, name: str) -> ba.Level:
|
||||
"""Return a contained ba.Level by name."""
|
||||
from ba import _error
|
||||
for level in self._levels:
|
||||
if level.name == name:
|
||||
return level
|
||||
raise Exception("Level '" + name + "' not found in campaign '" +
|
||||
self.name + "'")
|
||||
raise _error.NotFoundError("Level '" + name +
|
||||
"' not found in campaign '" + self.name +
|
||||
"'")
|
||||
|
||||
def reset(self) -> None:
|
||||
"""Reset state for the Campaign."""
|
||||
|
||||
@ -292,7 +292,7 @@ class CoopSession(Session):
|
||||
and self.campaign_state['level'] == 'Onslaught Training'
|
||||
and not app.kiosk_mode):
|
||||
if self._tutorial_activity is None:
|
||||
raise Exception('tutorial not preloaded properly')
|
||||
raise RuntimeError('tutorial not preloaded properly')
|
||||
self.set_activity(self._tutorial_activity)
|
||||
self._tutorial_activity = None
|
||||
self._ran_tutorial_activity = True
|
||||
|
||||
@ -283,7 +283,7 @@ class DependencySet(Generic[T]):
|
||||
|
||||
# Watch for wacky infinite dep loops.
|
||||
if recursion > 10:
|
||||
raise Exception('Max recursion reached')
|
||||
raise RecursionError('Max recursion reached')
|
||||
|
||||
hashval = dep.get_hash()
|
||||
|
||||
|
||||
@ -140,7 +140,7 @@ def print_exception(*args: Any, **keywds: Any) -> None:
|
||||
if keywds:
|
||||
allowed_keywds = ['once']
|
||||
if any(keywd not in allowed_keywds for keywd in keywds):
|
||||
raise Exception('invalid keyword(s)')
|
||||
raise TypeError('invalid keyword(s)')
|
||||
try:
|
||||
# If we're only printing once and already have, bail.
|
||||
if keywds.get('once', False):
|
||||
|
||||
@ -693,7 +693,7 @@ class GameActivity(Activity[PlayerType, TeamType]):
|
||||
else:
|
||||
sb_desc_l = sb_desc_in
|
||||
if not isinstance(sb_desc_l[0], str):
|
||||
raise Exception('Invalid format for instance description')
|
||||
raise TypeError('Invalid format for instance description')
|
||||
|
||||
is_empty = (sb_desc_l[0] == '')
|
||||
subs = []
|
||||
@ -781,7 +781,7 @@ class GameActivity(Activity[PlayerType, TeamType]):
|
||||
else:
|
||||
desc_l = desc_in
|
||||
if not isinstance(desc_l[0], str):
|
||||
raise Exception('Invalid format for instance description')
|
||||
raise TypeError('Invalid format for instance description')
|
||||
subs = []
|
||||
for i in range(len(desc_l) - 1):
|
||||
subs.append(('${ARG' + str(i + 1) + '}', str(desc_l[i + 1])))
|
||||
@ -965,7 +965,7 @@ class GameActivity(Activity[PlayerType, TeamType]):
|
||||
The default implementation simply calls spawn_player_spaz().
|
||||
"""
|
||||
if not player:
|
||||
raise Exception('spawn_player() called for nonexistent player')
|
||||
raise TypeError('spawn_player() called for nonexistent player')
|
||||
|
||||
return self.spawn_player_spaz(player)
|
||||
|
||||
|
||||
@ -137,7 +137,7 @@ def sharedobj(name: str) -> Any:
|
||||
True), ('modify_part_collision',
|
||||
'friction', 0.0)))
|
||||
else:
|
||||
raise Exception(
|
||||
raise ValueError(
|
||||
"unrecognized shared object (activity context): '" + name +
|
||||
"'")
|
||||
else:
|
||||
@ -156,10 +156,10 @@ def sharedobj(name: str) -> Any:
|
||||
if name == 'globals':
|
||||
obj = _ba.newnode('sessionglobals')
|
||||
else:
|
||||
raise Exception('unrecognized shared object '
|
||||
"(session context): '" + name + "'")
|
||||
raise ValueError('unrecognized shared object '
|
||||
"(session context): '" + name + "'")
|
||||
else:
|
||||
raise Exception('no current activity or session context')
|
||||
raise RuntimeError('no current activity or session context')
|
||||
|
||||
# Ok, got a shiny new shared obj; store it for quick access next time.
|
||||
sharedobjs[name] = obj
|
||||
@ -208,7 +208,7 @@ def animate(node: ba.Node,
|
||||
elif timeformat is TimeFormat.MILLISECONDS:
|
||||
mult = 1
|
||||
else:
|
||||
raise Exception(f'invalid timeformat value: {timeformat}')
|
||||
raise ValueError(f'invalid timeformat value: {timeformat}')
|
||||
|
||||
curve.times = [int(mult * time) for time, val in items]
|
||||
curve.offset = _ba.time(timeformat=TimeFormat.MILLISECONDS) + int(
|
||||
@ -269,7 +269,7 @@ def animate_array(node: ba.Node,
|
||||
elif timeformat is TimeFormat.MILLISECONDS:
|
||||
mult = 1
|
||||
else:
|
||||
raise Exception('invalid timeformat value: "' + str(timeformat) + '"')
|
||||
raise ValueError('invalid timeformat value: "' + str(timeformat) + '"')
|
||||
|
||||
for i in range(size):
|
||||
curve = _ba.newnode('animcurve',
|
||||
@ -390,7 +390,7 @@ def timestring(timeval: float,
|
||||
elif timeformat is TimeFormat.MILLISECONDS:
|
||||
pass
|
||||
else:
|
||||
raise Exception(f'invalid timeformat: {timeformat}')
|
||||
raise ValueError(f'invalid timeformat: {timeformat}')
|
||||
if not isinstance(timeval, int):
|
||||
timeval = int(timeval)
|
||||
bits = []
|
||||
|
||||
@ -111,7 +111,7 @@ class Lstr:
|
||||
"""
|
||||
# pylint: disable=too-many-branches
|
||||
if args:
|
||||
raise Exception('Lstr accepts only keyword arguments')
|
||||
raise TypeError('Lstr accepts only keyword arguments')
|
||||
|
||||
# Basically just store the exact args they passed.
|
||||
# However if they passed any Lstr values for subs,
|
||||
@ -120,7 +120,7 @@ class Lstr:
|
||||
our_type = type(self)
|
||||
|
||||
if isinstance(self.args.get('value'), our_type):
|
||||
raise Exception("'value' must be a regular string; not an Lstr")
|
||||
raise TypeError("'value' must be a regular string; not an Lstr")
|
||||
|
||||
if 'subs' in self.args:
|
||||
subs_new = []
|
||||
@ -301,7 +301,7 @@ def _add_to_attr_dict(dst: AttrDict, src: Dict) -> None:
|
||||
_add_to_attr_dict(dst_dict, value)
|
||||
else:
|
||||
if not isinstance(value, (float, int, bool, str, str, type(None))):
|
||||
raise Exception("invalid value type for res '" + key + "': " +
|
||||
raise TypeError("invalid value type for res '" + key + "': " +
|
||||
str(type(value)))
|
||||
dst[key] = value
|
||||
|
||||
@ -401,9 +401,10 @@ def get_resource(resource: str,
|
||||
# Ok, looks like we couldn't find our main or fallback resource
|
||||
# anywhere. Now if we've been given a fallback value, return it;
|
||||
# otherwise fail.
|
||||
from ba import _error
|
||||
if fallback_value is not None:
|
||||
return fallback_value
|
||||
raise Exception("resource not found: '" + resource + "'")
|
||||
raise _error.NotFoundError("resource not found: '" + resource + "'")
|
||||
|
||||
|
||||
def translate(category: str,
|
||||
@ -466,5 +467,5 @@ def is_custom_unicode_char(char: str) -> bool:
|
||||
"""Return whether a char is in the custom unicode range we use."""
|
||||
assert isinstance(char, str)
|
||||
if len(char) != 1:
|
||||
raise Exception('Invalid Input; must be length 1')
|
||||
raise ValueError('Invalid Input; must be length 1')
|
||||
return 0xE000 <= ord(char) <= 0xF8FF
|
||||
|
||||
@ -169,7 +169,7 @@ class Level:
|
||||
can be modified in place."""
|
||||
campaign = self.get_campaign()
|
||||
if campaign is None:
|
||||
raise Exception('level is not in a campaign')
|
||||
raise TypeError('level is not in a campaign')
|
||||
campaign_config = campaign.get_config_dict()
|
||||
val: Dict[str,
|
||||
Any] = campaign_config.setdefault(self._name, {
|
||||
|
||||
@ -353,7 +353,8 @@ class Chooser:
|
||||
"""The chooser's ba.Lobby."""
|
||||
lobby = self._lobby()
|
||||
if lobby is None:
|
||||
raise Exception('Lobby does not exist.')
|
||||
from ba import _error
|
||||
raise _error.NotFoundError('Lobby does not exist.')
|
||||
return lobby
|
||||
|
||||
def get_lobby(self) -> Optional[ba.Lobby]:
|
||||
|
||||
@ -144,7 +144,8 @@ def get_map_class(name: str) -> Type[ba.Map]:
|
||||
try:
|
||||
return _ba.app.maps[name]
|
||||
except Exception:
|
||||
raise Exception("Map not found: '" + name + "'")
|
||||
from ba import _error
|
||||
raise _error.NotFoundError("Map not found: '" + name + "'")
|
||||
|
||||
|
||||
class Map(Actor):
|
||||
@ -218,9 +219,11 @@ class Map(Actor):
|
||||
try:
|
||||
self.preloaddata = _ba.getactivity().preloads[type(self)]
|
||||
except Exception:
|
||||
raise Exception('Preload data not found for ' + str(type(self)) +
|
||||
'; make sure to call the type\'s preload()'
|
||||
' staticmethod in the activity constructor')
|
||||
from ba import _error
|
||||
raise _error.NotFoundError(
|
||||
'Preload data not found for ' + str(type(self)) +
|
||||
'; make sure to call the type\'s preload()'
|
||||
' staticmethod in the activity constructor')
|
||||
|
||||
# Set various globals.
|
||||
gnode = _gameutils.sharedobj('globals')
|
||||
@ -339,7 +342,7 @@ class Map(Actor):
|
||||
point_list.append(pts)
|
||||
else:
|
||||
if len(pts) != 3:
|
||||
raise Exception('invalid point')
|
||||
raise ValueError('invalid point')
|
||||
point_list.append(pts + (0, 0, 0))
|
||||
i += 1
|
||||
return point_list
|
||||
@ -365,11 +368,12 @@ class Map(Actor):
|
||||
player_pts = []
|
||||
for player in players:
|
||||
try:
|
||||
if player.node:
|
||||
if player and player.node:
|
||||
pnt = _ba.Vec3(player.node.position)
|
||||
player_pts.append(pnt)
|
||||
except Exception as exc:
|
||||
print('EXC in get_ffa_start_position:', exc)
|
||||
except Exception:
|
||||
from ba import _error
|
||||
_error.print_exception()
|
||||
|
||||
def _getpt() -> Sequence[float]:
|
||||
point = self.ffa_spawn_points[self._next_ffa_start_index]
|
||||
@ -427,5 +431,5 @@ class Map(Actor):
|
||||
def register_map(maptype: Type[Map]) -> None:
|
||||
"""Register a map class with the game."""
|
||||
if maptype.name in _ba.app.maps:
|
||||
raise Exception('map "' + maptype.name + '" already registered')
|
||||
raise RuntimeError('map "' + maptype.name + '" already registered')
|
||||
_ba.app.maps[maptype.name] = maptype
|
||||
|
||||
@ -326,7 +326,8 @@ def get_scan_results() -> ScanResults:
|
||||
while app.metascan is None:
|
||||
time.sleep(0.05)
|
||||
if time.time() - starttime > 10.0:
|
||||
raise Exception('timeout waiting for meta scan to complete.')
|
||||
raise TimeoutError(
|
||||
'timeout waiting for meta scan to complete.')
|
||||
return app.metascan
|
||||
|
||||
|
||||
|
||||
@ -191,7 +191,7 @@ class MusicController:
|
||||
"""Returns the system music player, instantiating if necessary."""
|
||||
if self._music_player is None:
|
||||
if self._music_player_type is None:
|
||||
raise Exception('no music player type set')
|
||||
raise TypeError('no music player type set')
|
||||
self._music_player = self._music_player_type()
|
||||
return self._music_player
|
||||
|
||||
@ -248,20 +248,21 @@ class MusicController:
|
||||
and isinstance(entry['name'], str)):
|
||||
entry_type = entry['type']
|
||||
else:
|
||||
raise Exception('invalid soundtrack entry: ' + str(entry) +
|
||||
raise TypeError('invalid soundtrack entry: ' + str(entry) +
|
||||
' (type ' + str(type(entry)) + ')')
|
||||
if self.supports_soundtrack_entry_type(entry_type):
|
||||
return entry_type
|
||||
raise Exception('invalid soundtrack entry:' + str(entry))
|
||||
except Exception as exc:
|
||||
print('EXC on get_soundtrack_entry_type', exc)
|
||||
raise ValueError('invalid soundtrack entry:' + str(entry))
|
||||
except Exception:
|
||||
from ba import _error
|
||||
_error.print_exception()
|
||||
return 'default'
|
||||
|
||||
def get_soundtrack_entry_name(self, entry: Any) -> str:
|
||||
"""Given a soundtrack entry, returns its name."""
|
||||
try:
|
||||
if entry is None:
|
||||
raise Exception('entry is None')
|
||||
raise TypeError('entry is None')
|
||||
|
||||
# Simple string denotes an iTunesPlaylist name (legacy entry).
|
||||
if isinstance(entry, str):
|
||||
@ -272,7 +273,7 @@ class MusicController:
|
||||
and isinstance(entry['type'], str) and 'name' in entry
|
||||
and isinstance(entry['name'], str)):
|
||||
return entry['name']
|
||||
raise Exception('invalid soundtrack entry:' + str(entry))
|
||||
raise ValueError('invalid soundtrack entry:' + str(entry))
|
||||
except Exception:
|
||||
from ba import _error
|
||||
_error.print_exception()
|
||||
|
||||
@ -56,7 +56,7 @@ def get_ip_address_type(addr: str) -> socket.AddressFamily:
|
||||
except OSError:
|
||||
pass
|
||||
if socket_type is None:
|
||||
raise Exception('addr seems to be neither v4 or v6: ' + str(addr))
|
||||
raise ValueError('addr seems to be neither v4 or v6: ' + str(addr))
|
||||
return socket_type
|
||||
|
||||
|
||||
@ -76,7 +76,7 @@ class ServerCallThread(threading.Thread):
|
||||
self._request = request
|
||||
self._request_type = request_type
|
||||
if not isinstance(response_type, ServerResponseType):
|
||||
raise Exception(f'Invalid response type: {response_type}')
|
||||
raise TypeError(f'Invalid response type: {response_type}')
|
||||
self._response_type = response_type
|
||||
self._data = {} if data is None else copy.deepcopy(data)
|
||||
self._callback: Optional[ServerCallbackType] = callback
|
||||
@ -128,7 +128,7 @@ class ServerCallThread(threading.Thread):
|
||||
parse.urlencode(self._data).encode(),
|
||||
{'User-Agent': _ba.app.user_agent_string}))
|
||||
else:
|
||||
raise Exception('Invalid request_type: ' + self._request_type)
|
||||
raise TypeError('Invalid request_type: ' + self._request_type)
|
||||
|
||||
# If html request failed.
|
||||
if response.getcode() != 200:
|
||||
@ -144,7 +144,7 @@ class ServerCallThread(threading.Thread):
|
||||
raw_data_s = raw_data.decode()
|
||||
response_data = json.loads(raw_data_s)
|
||||
else:
|
||||
raise Exception(f'invalid responsetype: {self._response_type}')
|
||||
raise TypeError(f'invalid responsetype: {self._response_type}')
|
||||
except (urllib.error.URLError, ConnectionError):
|
||||
# Server rejected us, broken pipe, etc. It happens. Ignoring.
|
||||
response_data = None
|
||||
|
||||
@ -181,7 +181,7 @@ class Player(Generic[TeamType]):
|
||||
self._sessionplayer.reset_input()
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return self._sessionplayer.exists()
|
||||
return self.exists()
|
||||
|
||||
|
||||
def playercast(totype: Type[PlayerType], player: ba.Player) -> PlayerType:
|
||||
|
||||
@ -80,7 +80,7 @@ def filter_playlist(playlist: PlaylistType,
|
||||
# the actual game class. add successful ones to our initial list
|
||||
# to present to the user.
|
||||
if not isinstance(entry['type'], str):
|
||||
raise Exception('invalid entry format')
|
||||
raise TypeError('invalid entry format')
|
||||
try:
|
||||
# Do some type filters for backwards compat.
|
||||
if entry['type'] in ('Assault.AssaultGame',
|
||||
|
||||
@ -56,7 +56,7 @@ def get_store_item_name_translated(item_name: str) -> ba.Lstr:
|
||||
return gametype.get_display_string()
|
||||
if item_name.startswith('icons.'):
|
||||
return _lang.Lstr(resource='editProfileWindow.iconText')
|
||||
raise Exception('unrecognized item: ' + item_name)
|
||||
raise ValueError('unrecognized item: ' + item_name)
|
||||
|
||||
|
||||
def get_store_item_display_size(item_name: str) -> Tuple[float, float]:
|
||||
|
||||
@ -127,7 +127,7 @@ class UIEntry:
|
||||
if self._name == 'mainmenu':
|
||||
from bastd.ui import mainmenu
|
||||
return cast(Type[UILocation], mainmenu.MainMenuWindow)
|
||||
raise Exception('unknown ui class ' + str(self._name))
|
||||
raise ValueError('unknown ui class ' + str(self._name))
|
||||
|
||||
|
||||
class UIController:
|
||||
@ -192,7 +192,7 @@ def uicleanupcheck(obj: Any, widget: ba.Widget) -> None:
|
||||
if DEBUG_UI_CLEANUP_CHECKS:
|
||||
print(f'adding uicleanup to {obj}')
|
||||
if not isinstance(widget, _ba.Widget):
|
||||
raise Exception('widget arg is not a ba.Widget')
|
||||
raise TypeError('widget arg is not a ba.Widget')
|
||||
|
||||
def foobar() -> None:
|
||||
"""Just testing."""
|
||||
|
||||
@ -149,8 +149,8 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
||||
self._score_order: str
|
||||
if 'score_order' in settings:
|
||||
if not settings['score_order'] in ['increasing', 'decreasing']:
|
||||
raise Exception('Invalid score order: ' +
|
||||
settings['score_order'])
|
||||
raise ValueError('Invalid score order: ' +
|
||||
settings['score_order'])
|
||||
self._score_order = settings['score_order']
|
||||
else:
|
||||
self._score_order = 'increasing'
|
||||
@ -159,8 +159,8 @@ class CoopScoreScreen(ba.Activity[ba.Player, ba.Team]):
|
||||
self._score_type: str
|
||||
if 'score_type' in settings:
|
||||
if not settings['score_type'] in ['points', 'time']:
|
||||
raise Exception('Invalid score type: ' +
|
||||
settings['score_type'])
|
||||
raise ValueError('Invalid score type: ' +
|
||||
settings['score_type'])
|
||||
self._score_type = settings['score_type']
|
||||
else:
|
||||
self._score_type = 'points'
|
||||
|
||||
@ -665,7 +665,7 @@ class Bomb(ba.Actor):
|
||||
|
||||
if bomb_type not in ('ice', 'impact', 'land_mine', 'normal', 'sticky',
|
||||
'tnt'):
|
||||
raise Exception('invalid bomb type: ' + bomb_type)
|
||||
raise ValueError('invalid bomb type: ' + bomb_type)
|
||||
self.bomb_type = bomb_type
|
||||
|
||||
self._exploded = False
|
||||
|
||||
@ -95,7 +95,7 @@ class OnScreenTimer(ba.Actor):
|
||||
assert isinstance(endtime, int)
|
||||
endtime_ms = endtime
|
||||
else:
|
||||
raise Exception(f'invalid timeformat: {timeformat}')
|
||||
raise ValueError(f'invalid timeformat: {timeformat}')
|
||||
|
||||
self.inputnode.timemax = endtime_ms - self._starttime
|
||||
|
||||
@ -119,7 +119,7 @@ class OnScreenTimer(ba.Actor):
|
||||
return 0.001 * val_ms
|
||||
if timeformat is ba.TimeFormat.MILLISECONDS:
|
||||
return val_ms
|
||||
raise Exception(f'invalid timeformat: {timeformat}')
|
||||
raise ValueError(f'invalid timeformat: {timeformat}')
|
||||
|
||||
def handlemessage(self, msg: Any) -> Any:
|
||||
# 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."""
|
||||
activity = ba.getactivity()
|
||||
if activity is None:
|
||||
raise Exception('no current activity')
|
||||
raise RuntimeError('no current activity')
|
||||
try:
|
||||
# FIXME: et better way to store stuff with activity
|
||||
# pylint: disable=protected-access
|
||||
@ -252,10 +252,10 @@ class PowerupBox(ba.Actor):
|
||||
elif poweruptype == 'curse':
|
||||
tex = factory.tex_curse
|
||||
else:
|
||||
raise Exception('invalid poweruptype: ' + str(poweruptype))
|
||||
raise ValueError('invalid poweruptype: ' + str(poweruptype))
|
||||
|
||||
if len(position) != 3:
|
||||
raise Exception('expected 3 floats for position')
|
||||
raise ValueError('expected 3 floats for position')
|
||||
|
||||
self.node = ba.newnode(
|
||||
'prop',
|
||||
|
||||
@ -1384,7 +1384,7 @@ class Spaz(ba.Actor):
|
||||
return bomb_factory.tex_ice_bombs
|
||||
if self.bomb_type == 'impact':
|
||||
return bomb_factory.tex_impact_bombs
|
||||
raise Exception()
|
||||
raise ValueError('invalid bomb type')
|
||||
|
||||
def _flash_billboard(self, tex: ba.Texture) -> None:
|
||||
assert self.node
|
||||
|
||||
@ -224,7 +224,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
||||
]},
|
||||
{'entries': [
|
||||
{'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},
|
||||
{'type': spazbot.BrawlerBot, 'path': 2},
|
||||
@ -273,7 +273,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
||||
{'type': spazbot.TriggerBot, 'path': 2},
|
||||
{'type': spazbot.TriggerBot, 'path': 3},
|
||||
{'type': spazbot.BrawlerBotPro if hard
|
||||
else spazbot.BrawlerBot, 'point': 'bottom_left'},
|
||||
else spazbot.BrawlerBot, 'point': 'bottom_left'},
|
||||
{'type': spazbot.BrawlerBotPro, 'point': 'bottom_right'}
|
||||
if player_count > 2 else None,
|
||||
]},
|
||||
@ -312,7 +312,7 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
||||
]},
|
||||
{'entries': [
|
||||
{'type': spazbot.TriggerBotProShielded if hard
|
||||
else spazbot.TriggerBotPro, 'point': 'bottom_left'},
|
||||
else spazbot.TriggerBotPro, 'point': 'bottom_left'},
|
||||
{'type': spazbot.TriggerBotProShielded,
|
||||
'point': 'bottom_right'}
|
||||
if hard else None,
|
||||
@ -1110,7 +1110,6 @@ class RunaroundGame(ba.CoopGameActivity[Player, Team]):
|
||||
if ((ba.is_point_in_box(pos, boxes['b8'])
|
||||
and not ba.is_point_in_box(pos, boxes['b9']))
|
||||
or pos == (0.0, 0.0, 0.0)):
|
||||
|
||||
# Default to walking right if we're still in the walking area.
|
||||
bot.node.move_left_right = speed
|
||||
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:
|
||||
speed = self._bot_speed_map.get(bot_type)
|
||||
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))
|
||||
return speed
|
||||
|
||||
|
||||
@ -627,8 +627,8 @@ class AccountSettingsWindow(ba.Window):
|
||||
elif account_type == 'Game Circle':
|
||||
account_type_name = ba.Lstr(resource='gameCircleText')
|
||||
else:
|
||||
raise Exception("unknown account type: '" + str(account_type) +
|
||||
"'")
|
||||
raise ValueError("unknown account type: '" +
|
||||
str(account_type) + "'")
|
||||
self._game_service_button = btn = ba.buttonwidget(
|
||||
parent=self._subcontainer,
|
||||
position=((self._sub_width - button_width) * 0.5, v),
|
||||
@ -1105,7 +1105,7 @@ class AccountSettingsWindow(ba.Window):
|
||||
elif sel == self._scrollwidget:
|
||||
sel_name = 'Scroll'
|
||||
else:
|
||||
raise Exception('unrecognized selection')
|
||||
raise ValueError('unrecognized selection')
|
||||
ba.app.window_states[self.__class__.__name__] = sel_name
|
||||
except Exception:
|
||||
ba.print_exception('exception saving state for', self.__class__)
|
||||
|
||||
@ -50,7 +50,7 @@ class ColorPicker(popup.PopupWindow):
|
||||
|
||||
c_raw = get_player_colors()
|
||||
if len(c_raw) != 16:
|
||||
raise Exception('expected 16 player colors')
|
||||
raise ValueError('expected 16 player colors')
|
||||
self.colors = [c_raw[0:4], c_raw[4:8], c_raw[8:12], c_raw[12:16]]
|
||||
|
||||
if scale is None:
|
||||
@ -189,7 +189,7 @@ class ColorPickerExact(popup.PopupWindow):
|
||||
from ba.internal import get_player_colors
|
||||
c_raw = get_player_colors()
|
||||
if len(c_raw) != 16:
|
||||
raise Exception('expected 16 player colors')
|
||||
raise ValueError('expected 16 player colors')
|
||||
self.colors = [c_raw[0:4], c_raw[4:8], c_raw[8:12], c_raw[12:16]]
|
||||
|
||||
if scale is None:
|
||||
|
||||
@ -1555,7 +1555,7 @@ class CoopBrowserWindow(ba.Window):
|
||||
elif sel == self._scrollwidget:
|
||||
sel_name = 'Scroll'
|
||||
else:
|
||||
raise Exception('unrecognized selection')
|
||||
raise ValueError('unrecognized selection')
|
||||
ba.app.window_states[self.__class__.__name__] = {
|
||||
'sel_name': sel_name
|
||||
}
|
||||
|
||||
@ -807,11 +807,8 @@ class GatherWindow(ba.Window):
|
||||
color=(1, 0, 0))
|
||||
ba.playsound(ba.getsound('error'))
|
||||
return
|
||||
try:
|
||||
port = int(cast(str, ba.textwidget(query=port_textwidget)))
|
||||
if port > 65535 or port < 0:
|
||||
raise Exception()
|
||||
except Exception:
|
||||
port = int(cast(str, ba.textwidget(query=port_textwidget)))
|
||||
if port > 65535 or port < 0:
|
||||
ba.screenmessage(
|
||||
ba.Lstr(resource='internal.invalidPortErrorText'),
|
||||
color=(1, 0, 0))
|
||||
@ -1958,7 +1955,7 @@ class GatherWindow(ba.Window):
|
||||
elif sel == self._tab_container:
|
||||
sel_name = 'TabContainer'
|
||||
else:
|
||||
raise Exception('unrecognized selection: ' + str(sel))
|
||||
raise ValueError(f'unrecognized selection: \'{sel}\'')
|
||||
ba.app.window_states[self.__class__.__name__] = {
|
||||
'sel_name': sel_name,
|
||||
'tab': self._current_tab,
|
||||
|
||||
@ -673,8 +673,8 @@ class MainMenuWindow(ba.Window):
|
||||
if (not isinstance(cme, dict) or 'label' not in cme
|
||||
or not isinstance(cme['label'], (str, ba.Lstr))
|
||||
or 'call' not in cme or not callable(cme['call'])):
|
||||
raise Exception('invalid custom menu entry: ' +
|
||||
str(cme))
|
||||
raise ValueError('invalid custom menu entry: ' +
|
||||
str(cme))
|
||||
except Exception:
|
||||
custom_menu_entries = []
|
||||
ba.print_exception('exception getting custom menu entries for',
|
||||
|
||||
@ -538,7 +538,7 @@ class PlayWindow(ba.Window):
|
||||
elif sel == self._back_button:
|
||||
sel_name = 'Back'
|
||||
else:
|
||||
raise Exception('unrecognized selected widget')
|
||||
raise ValueError(f'unrecognized selection {sel}')
|
||||
ba.app.window_states[self.__class__.__name__] = sel_name
|
||||
except Exception:
|
||||
ba.print_exception('error saving state for', self.__class__)
|
||||
|
||||
@ -58,7 +58,7 @@ class PlaylistTypeVars:
|
||||
fallback_resource='freeForAllText')
|
||||
self.sessiontype = ba.FreeForAllSession
|
||||
else:
|
||||
raise Exception('playlist type vars undefined for session type: ' +
|
||||
raise TypeError('playlist type vars undefined for session type: ' +
|
||||
str(sessiontype))
|
||||
self.default_list_name = ba.Lstr(resource='defaultGameListNameText',
|
||||
subs=[('${PLAYMODE}', play_mode_name)
|
||||
|
||||
@ -62,7 +62,7 @@ class PlaylistBrowserWindow(ba.Window):
|
||||
ba.app.main_window = 'Free-for-All Game Select'
|
||||
ba.set_analytics_screen('FreeForAll Window')
|
||||
else:
|
||||
raise Exception(f'invalid sessiontype: {sessiontype}')
|
||||
raise TypeError(f'invalid sessiontype: {sessiontype}')
|
||||
self._pvars = playlist.PlaylistTypeVars(sessiontype)
|
||||
|
||||
self._sessiontype = sessiontype
|
||||
|
||||
@ -264,19 +264,19 @@ class PlaylistEditGameWindow(ba.Window):
|
||||
if 'choices' in setting:
|
||||
for choice in setting['choices']:
|
||||
if len(choice) != 2:
|
||||
raise Exception(
|
||||
raise ValueError(
|
||||
"Expected 2-member tuples for 'choices'; got: " +
|
||||
repr(choice))
|
||||
if not isinstance(choice[0], str):
|
||||
raise Exception(
|
||||
raise TypeError(
|
||||
'First value for choice tuple must be a str; got: '
|
||||
+ repr(choice))
|
||||
if not isinstance(choice[1], value_type):
|
||||
raise Exception(
|
||||
raise TypeError(
|
||||
'Choice type does not match default value; choice:'
|
||||
+ repr(choice) + '; setting:' + repr(setting))
|
||||
if value_type not in (int, float):
|
||||
raise Exception(
|
||||
raise TypeError(
|
||||
'Choice type setting must have int or float default; '
|
||||
'got: ' + repr(setting))
|
||||
|
||||
@ -509,5 +509,5 @@ class PlaylistEditGameWindow(ba.Window):
|
||||
elif setting_type == int:
|
||||
ba.textwidget(edit=ctrl, text=str(int(val)))
|
||||
else:
|
||||
raise Exception('invalid vartype: ' + str(setting_type))
|
||||
raise TypeError('invalid vartype: ' + str(setting_type))
|
||||
self._settings[setting_name] = val
|
||||
|
||||
@ -93,7 +93,7 @@ class PlayOptionsWindow(popup.PopupWindow):
|
||||
elif self._sessiontype is ba.DualTeamSession:
|
||||
plst = get_default_teams_playlist()
|
||||
else:
|
||||
raise Exception('unrecognized session-type: ' +
|
||||
raise TypeError('unrecognized session-type: ' +
|
||||
str(self._sessiontype))
|
||||
else:
|
||||
try:
|
||||
|
||||
@ -153,7 +153,7 @@ class PopupMenuWindow(PopupWindow):
|
||||
self._choices_disabled = list(choices_disabled)
|
||||
self._done_building = False
|
||||
if not choices:
|
||||
raise Exception('Must pass at least one choice')
|
||||
raise TypeError('Must pass at least one choice')
|
||||
self._width = width
|
||||
self._scale = scale
|
||||
if len(choices) > 8:
|
||||
@ -302,7 +302,7 @@ class PopupMenu:
|
||||
current_choice = None
|
||||
self._choices = list(choices)
|
||||
if not choices:
|
||||
raise Exception('no choices given')
|
||||
raise TypeError('no choices given')
|
||||
self._choices_display = list(choices_display)
|
||||
self._choices_disabled = list(choices_disabled)
|
||||
self._width = width
|
||||
@ -313,7 +313,7 @@ class PopupMenu:
|
||||
self._position = position
|
||||
self._parent = parent
|
||||
if not choices:
|
||||
raise Exception('Must pass at least one choice')
|
||||
raise TypeError('Must pass at least one choice')
|
||||
self._parent = parent
|
||||
self._button_size = button_size
|
||||
|
||||
|
||||
@ -546,7 +546,7 @@ class EditProfileWindow(ba.Window):
|
||||
elif picker_type == 'highlight':
|
||||
initial_color = self._highlight
|
||||
else:
|
||||
raise Exception('invalid picker_type: ' + picker_type)
|
||||
raise ValueError('invalid picker_type: ' + picker_type)
|
||||
colorpicker.ColorPicker(
|
||||
parent=self._root_widget,
|
||||
position=origin,
|
||||
|
||||
@ -44,7 +44,7 @@ class PurchaseWindow(ba.Window):
|
||||
header_text = ba.Lstr(resource='unlockThisText',
|
||||
fallback_resource='unlockThisInTheStoreText')
|
||||
if len(items) != 1:
|
||||
raise Exception('expected exactly 1 item')
|
||||
raise ValueError('expected exactly 1 item')
|
||||
self._items = list(items)
|
||||
self._width = 580
|
||||
self._height = 520
|
||||
|
||||
@ -596,11 +596,11 @@ class AdvancedSettingsWindow(ba.Window):
|
||||
elif sel == self._language_inform_checkbox:
|
||||
sel_name = 'LangInform'
|
||||
else:
|
||||
raise Exception('unrecognized selection')
|
||||
raise ValueError(f'unrecognized selection \'{sel}\'')
|
||||
elif sel == self._back_button:
|
||||
sel_name = 'Back'
|
||||
else:
|
||||
raise Exception('unrecognized selection')
|
||||
raise ValueError(f'unrecognized selection \'{sel}\'')
|
||||
ba.app.window_states[self.__class__.__name__] = {
|
||||
'sel_name': sel_name
|
||||
}
|
||||
|
||||
@ -252,7 +252,7 @@ class AllSettingsWindow(ba.Window):
|
||||
elif sel == self._back_button:
|
||||
sel_name = 'Back'
|
||||
else:
|
||||
raise Exception('unrecognized selection')
|
||||
raise ValueError(f'unrecognized selection \'{sel}\'')
|
||||
ba.app.window_states[self.__class__.__name__] = {
|
||||
'sel_name': sel_name
|
||||
}
|
||||
|
||||
@ -266,7 +266,7 @@ class AudioSettingsWindow(ba.Window):
|
||||
elif sel == self._vr_head_relative_audio_button:
|
||||
sel_name = 'VRHeadRelative'
|
||||
else:
|
||||
raise Exception('unrecognized selected widget')
|
||||
raise ValueError(f'unrecognized selection \'{sel}\'')
|
||||
ba.app.window_states[self.__class__.__name__] = sel_name
|
||||
except Exception:
|
||||
ba.print_exception('error saving state for', self.__class__)
|
||||
|
||||
@ -167,7 +167,7 @@ class TestingWindow(ba.Window):
|
||||
for entry in self._entries:
|
||||
if entry['name'] == name:
|
||||
return entry
|
||||
raise Exception(f'Entry not found: {name}')
|
||||
raise ba.NotFoundError(f'Entry not found: {name}')
|
||||
|
||||
def _on_reset_press(self) -> None:
|
||||
for entry in self._entries:
|
||||
|
||||
@ -485,7 +485,7 @@ class SoundtrackBrowserWindow(ba.Window):
|
||||
elif sel == self._back_button:
|
||||
sel_name = 'Back'
|
||||
else:
|
||||
raise Exception('unrecognized selection')
|
||||
raise ValueError(f'unrecognized selection \'{sel}\'')
|
||||
ba.app.window_states[self.__class__.__name__] = sel_name
|
||||
except Exception:
|
||||
ba.print_exception('error saving state for', self.__class__)
|
||||
|
||||
@ -1002,7 +1002,7 @@ class StoreBrowserWindow(ba.Window):
|
||||
sel_name = 'Tab:' + list(self._tab_buttons.keys())[list(
|
||||
self._tab_buttons.values()).index(sel)]
|
||||
else:
|
||||
raise Exception('unrecognized selection')
|
||||
raise ValueError(f'unrecognized selection \'{sel}\'')
|
||||
ba.app.window_states[self.__class__.__name__] = {
|
||||
'sel_name': sel_name,
|
||||
'tab': self._current_tab
|
||||
|
||||
@ -69,7 +69,7 @@ class TournamentEntryWindow(popup.PopupWindow):
|
||||
self._purchase_price_name = 'price.tournament_entry_1'
|
||||
else:
|
||||
if self._fee != 0:
|
||||
raise Exception('invalid fee: ' + str(self._fee))
|
||||
raise ValueError('invalid fee: ' + str(self._fee))
|
||||
self._purchase_name = 'tournament_entry_0'
|
||||
self._purchase_price_name = 'price.tournament_entry_0'
|
||||
|
||||
|
||||
@ -482,7 +482,7 @@ class WatchWindow(ba.Window):
|
||||
elif sel == self._tab_container:
|
||||
sel_name = 'TabContainer'
|
||||
else:
|
||||
raise Exception('unrecognized selection')
|
||||
raise ValueError(f'unrecognized selection {sel}')
|
||||
ba.app.window_states[self.__class__.__name__] = {
|
||||
'sel_name': sel_name,
|
||||
'tab': self._current_tab
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user