def on_begin(self) -> None: # pylint: disable=cyclic-import from bastd.actor.text import Text from ba import _language super().on_begin() import custom_hooks custom_hooks.score_screen_on_begin(self._stats) # Pop up a 'press any button to continue' statement after our # min-view-time show a 'press any button to continue..' # thing after a bit. if _ba.app.ui.uiscale is UIScale.LARGE: # FIXME: Need a better way to determine whether we've probably # got a keyboard. sval = _language.Lstr(resource='pressAnyKeyButtonText') else: sval = _language.Lstr(resource='pressAnyButtonText') Text(self._custom_continue_message if self._custom_continue_message is not None else sval, v_attach=Text.VAttach.BOTTOM, h_align=Text.HAlign.CENTER, flash=True, vr_depth=50, position=(0, 10), scale=0.8, color=(0.5, 0.7, 0.5, 0.5), transition=Text.Transition.IN_BOTTOM_SLOW, transition_delay=self._min_view_time).autoretain()
def run(self) -> None: from ba import _language from ba._general import Call do_print_error = True try: _ba.set_thread_name('BA_PickFolderSongThread') all_files: list[str] = [] valid_extensions = ['.' + x for x in self._valid_extensions] for root, _subdirs, filenames in os.walk(self._path): for fname in filenames: if any(fname.lower().endswith(ext) for ext in valid_extensions): all_files.insert(random.randrange(len(all_files) + 1), root + '/' + fname) if not all_files: do_print_error = False raise RuntimeError( _language.Lstr(resource='internal.noMusicFilesInFolderText' ).evaluate()) _ba.pushcall(Call(self._callback, all_files, None), from_other_thread=True) except Exception as exc: from ba import _error if do_print_error: _error.print_exception() try: err_str = str(exc) except Exception: err_str = '<ENCERR4523>' _ba.pushcall(Call(self._callback, self._path, err_str), from_other_thread=True)
def get_map_display_string(name: str) -> ba.Lstr: """Return a ba.Lstr for displaying a given map\'s name. Category: Asset Functions """ from ba import _language return _language.Lstr(translate=('mapsNames', name))
def pause(self) -> None: """Pause the game due to a user request or menu popping up. If there's a foreground host-activity that says it's pausable, tell it to pause ..we now no longer pause if there are connected clients. """ activity: Optional[ba.Activity] = _ba.get_foreground_host_activity() if (activity is not None and activity.allow_pausing and not _ba.have_connected_clients()): from ba import _gameutils, _language from ba._nodeactor import NodeActor # FIXME: Shouldn't be touching scene stuff here; # should just pass the request on to the host-session. with _ba.Context(activity): globs = activity.globalsnode if not globs.paused: _ba.playsound(_ba.getsound('refWhistle')) globs.paused = True # FIXME: This should not be an attr on Actor. activity.paused_text = NodeActor( _ba.newnode( 'text', attrs={ 'text': _language.Lstr(resource='pausedByHostText'), 'client_only': True, 'flatness': 1.0, 'h_align': 'center' }))
def displayname(self) -> ba.Lstr: """The localized name for this Level.""" from ba import _language return _language.Lstr( translate=('coopLevelNames', self._displayname if self._displayname is not None else self._name), subs=[('${GAME}', self._gametype.get_display_string(self._settings))])
def get_store_item_name_translated(item_name: str) -> ba.Lstr: """Return a ba.Lstr for a store item name.""" # pylint: disable=cyclic-import from ba import _language from ba import _map item_info = get_store_item(item_name) if item_name.startswith('characters.'): return _language.Lstr(translate=('characterNames', item_info['character'])) if item_name in ['upgrades.pro', 'pro']: return _language.Lstr(resource='store.bombSquadProNameText', subs=[('${APP_NAME}', _language.Lstr(resource='titleText'))]) if item_name.startswith('maps.'): map_type: Type[ba.Map] = item_info['map_type'] return _map.get_map_display_string(map_type.name) if item_name.startswith('games.'): gametype: Type[ba.GameActivity] = item_info['gametype'] return gametype.get_display_string() if item_name.startswith('icons.'): return _language.Lstr(resource='editProfileWindow.iconText') raise ValueError('unrecognized item: ' + item_name)
def _on_play_folder_cb(self, result: Union[str, list[str]], error: Optional[str] = None) -> None: from ba import _language if error is not None: rstr = (_language.Lstr( resource='internal.errorPlayingMusicText').evaluate()) if isinstance(result, str): err_str = (rstr.replace('${MUSIC}', os.path.basename(result)) + '; ' + str(error)) else: err_str = (rstr.replace('${MUSIC}', '<multiple>') + '; ' + str(error)) _ba.screenmessage(err_str, color=(1, 0, 0)) return # There's a chance a stop could have been issued before our thread # returned. If that's the case, don't play. if not self._want_to_play: print('_on_play_folder_cb called with _want_to_play False') else: self._actually_playing = True _ba.music_player_play(result)
def get_human_readable_user_scripts_path() -> str: """Return a human readable location of user-scripts. This is NOT a valid filesystem path; may be something like "(SD Card)". """ from ba import _language app = _ba.app path: Optional[str] = app.python_directory_user if path is None: return '<Not Available>' # On newer versions of android, the user's external storage dir is probably # only visible to the user's processes and thus not really useful printed # in its entirety; lets print it as <External Storage>/myfilepath. if app.platform == 'android': ext_storage_path: Optional[str] = ( _ba.android_get_external_storage_path()) if (ext_storage_path is not None and app.python_directory_user.startswith(ext_storage_path)): path = ('<' + _language.Lstr(resource='externalStorageText').evaluate() + '>' + app.python_directory_user[len(ext_storage_path):]) return path
def get_remote_app_name() -> ba.Lstr: """(internal)""" from ba import _language return _language.Lstr(resource='remote_app.app_name')