def lobby(self) -> ba.Lobby: """The chooser's ba.Lobby.""" lobby = self._lobby() if lobby is None: from ba import _error raise _error.NotFoundError('Lobby does not exist.') return lobby
def getlevel(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 _error.NotFoundError("Level '" + name + "' not found in campaign '" + self.name + "'")
def get_map_class(name: str) -> Type[ba.Map]: """Return a map type given a name. Category: Asset Functions """ name = get_filtered_map_name(name) try: return _ba.app.maps[name] except KeyError: from ba import _error raise _error.NotFoundError(f"Map not found: '{name}'") from None
def get_resource(resource: str, fallback_resource: str = None, fallback_value: Any = None) -> Any: """Return a translation resource by name.""" try: # If we have no language set, go ahead and set it. if _ba.app.language_merged is None: language = _ba.app.language try: setlanguage(language, print_change=False, store_to_config=False) except Exception: from ba import _error _error.print_exception('exception setting language to', language) # Try english as a fallback. if language != 'English': print('Resorting to fallback language (English)') try: setlanguage('English', print_change=False, store_to_config=False) except Exception: _error.print_exception( 'error setting language to english fallback') # If they provided a fallback_resource value, try the # target-language-only dict first and then fall back to trying the # fallback_resource value in the merged dict. if fallback_resource is not None: try: values = _ba.app.language_target splits = resource.split('.') dicts = splits[:-1] key = splits[-1] for dct in dicts: assert values is not None values = values[dct] assert values is not None val = values[key] return val except Exception: # FIXME: Shouldn't we try the fallback resource in the merged # dict AFTER we try the main resource in the merged dict? try: values = _ba.app.language_merged splits = fallback_resource.split('.') dicts = splits[:-1] key = splits[-1] for dct in dicts: assert values is not None values = values[dct] assert values is not None val = values[key] return val except Exception: # If we got nothing for fallback_resource, default to the # normal code which checks or primary value in the merge # dict; there's a chance we can get an english value for # it (which we weren't looking for the first time through). pass values = _ba.app.language_merged splits = resource.split('.') dicts = splits[:-1] key = splits[-1] for dct in dicts: assert values is not None values = values[dct] assert values is not None val = values[key] return val except Exception: # 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 _error.NotFoundError( f"Resource not found: '{resource}'") from None
def __init__(self, vr_overlay_offset: Optional[Sequence[float]] = None) -> None: """Instantiate a map.""" from ba import _gameutils super().__init__() # This is expected to always be a ba.Node object (whether valid or not) # should be set to something meaningful by child classes. self.node: Optional[_ba.Node] = None # Make our class' preload-data available to us # (and instruct the user if we weren't preloaded properly). try: self.preloaddata = _ba.getactivity().preloads[type(self)] except Exception: 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 = _ba.getactivity().globalsnode # Set area-of-interest bounds. aoi_bounds = self.get_def_bound_box('area_of_interest_bounds') if aoi_bounds is None: print('WARNING: no "aoi_bounds" found for map:', self.getname()) aoi_bounds = (-1, -1, -1, 1, 1, 1) gnode.area_of_interest_bounds = aoi_bounds # Set map bounds. map_bounds = self.get_def_bound_box('map_bounds') if map_bounds is None: print('WARNING: no "map_bounds" found for map:', self.getname()) map_bounds = (-30, -10, -30, 30, 100, 30) _ba.set_map_bounds(map_bounds) # Set shadow ranges. try: gnode.shadow_range = [ self.defs.points[v][1] for v in [ 'shadow_lower_bottom', 'shadow_lower_top', 'shadow_upper_bottom', 'shadow_upper_top' ] ] except Exception: pass # In vr, set a fixed point in space for the overlay to show up at. # By default we use the bounds center but allow the map to override it. center = ((aoi_bounds[0] + aoi_bounds[3]) * 0.5, (aoi_bounds[1] + aoi_bounds[4]) * 0.5, (aoi_bounds[2] + aoi_bounds[5]) * 0.5) if vr_overlay_offset is not None: center = (center[0] + vr_overlay_offset[0], center[1] + vr_overlay_offset[1], center[2] + vr_overlay_offset[2]) gnode.vr_overlay_center = center gnode.vr_overlay_center_enabled = True self.spawn_points = (self.get_def_points('spawn') or [(0, 0, 0, 0, 0, 0)]) self.ffa_spawn_points = (self.get_def_points('ffa_spawn') or [(0, 0, 0, 0, 0, 0)]) self.spawn_by_flag_points = (self.get_def_points('spawn_by_flag') or [(0, 0, 0, 0, 0, 0)]) self.flag_points = self.get_def_points('flag') or [(0, 0, 0)] # We just want points. self.flag_points = [p[:3] for p in self.flag_points] self.flag_points_default = (self.get_def_point('flag_default') or (0, 1, 0)) self.powerup_spawn_points = self.get_def_points('powerup_spawn') or [ (0, 0, 0) ] # We just want points. self.powerup_spawn_points = ([ p[:3] for p in self.powerup_spawn_points ]) self.tnt_points = self.get_def_points('tnt') or [] # We just want points. self.tnt_points = [p[:3] for p in self.tnt_points] self.is_hockey = False self.is_flying = False # FIXME: this should be part of game; not map. self._next_ffa_start_index = 0