From b329d10c610d9b627f9fa2744901b599799f5800 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 10 Jun 2023 20:38:47 -0700 Subject: [PATCH] more --- src/assets/ba_data/python/babase/__init__.py | 8 +++++ .../ba_data/python/baclassic/_benchmark.py | 24 +++++-------- src/assets/ba_data/python/baclassic/_music.py | 34 +++++++++---------- src/assets/ba_data/python/baclassic/_net.py | 6 ++-- .../ba_data/python/baclassic/macmusicapp.py | 22 ++++-------- .../ba_data/python/baclassic/osmusic.py | 10 +++--- .../ba_data/python/bascenev1/__init__.py | 2 ++ 7 files changed, 50 insertions(+), 56 deletions(-) diff --git a/src/assets/ba_data/python/babase/__init__.py b/src/assets/ba_data/python/babase/__init__.py index 42f651f4..c72c0cff 100644 --- a/src/assets/ba_data/python/babase/__init__.py +++ b/src/assets/ba_data/python/babase/__init__.py @@ -12,6 +12,9 @@ from efro.util import set_canonical_module_names import _babase from _babase import ( + android_get_external_files_dir, + is_os_playing_music, + getsimplesound, music_player_set_volume, music_player_play, music_player_stop, @@ -122,6 +125,7 @@ from babase._apputils import ( get_remote_app_name, ) from babase._general import ( + utf8_all, DisplayTime, AppTime, WeakCall, @@ -267,6 +271,10 @@ __all__ = [ 'mac_music_app_set_volume', 'mac_music_app_get_playlists', 'mac_music_app_play_playlist', + 'utf8_all', + 'getsimplesound', + 'is_os_playing_music', + 'android_get_external_files_dir', ] # We want stuff to show up as babase.Foo instead of babase._sub.Foo. diff --git a/src/assets/ba_data/python/baclassic/_benchmark.py b/src/assets/ba_data/python/baclassic/_benchmark.py index 4c583cb1..18e04335 100644 --- a/src/assets/ba_data/python/baclassic/_benchmark.py +++ b/src/assets/ba_data/python/baclassic/_benchmark.py @@ -96,9 +96,7 @@ def stop_stress_test() -> None: def start_stress_test(args: dict[str, Any]) -> None: """(internal)""" - from babase._general import Call - from bascenev1._dualteamsession import DualTeamSession - from bascenev1._freeforallsession import FreeForAllSession + from bascenev1 import DualTeamSession, FreeForAllSession assert babase.app.classic is not None @@ -121,9 +119,9 @@ def start_stress_test(args: dict[str, Any]) -> None: appconfig['Team Tournament Playlist Randomize'] = 1 babase.apptimer( 1.0, - Call( + babase.Call( babase.pushcall, - Call(bascenev1.new_host_session, DualTeamSession), + babase.Call(bascenev1.new_host_session, DualTeamSession), ), ) else: @@ -131,26 +129,24 @@ def start_stress_test(args: dict[str, Any]) -> None: appconfig['Free-for-All Playlist Randomize'] = 1 babase.apptimer( 1.0, - Call( + babase.Call( babase.pushcall, - Call(bascenev1.new_host_session, FreeForAllSession), + babase.Call(bascenev1.new_host_session, FreeForAllSession), ), ) babase.set_stress_testing(True, args['player_count']) babase.app.classic.stress_test_reset_timer = babase.AppTimer( - args['round_duration'], Call(_reset_stress_test, args) + args['round_duration'], babase.Call(_reset_stress_test, args) ) def _reset_stress_test(args: dict[str, Any]) -> None: - from babase._general import Call - babase.set_stress_testing(False, args['player_count']) babase.screenmessage('Resetting stress test...') session = bascenev1.get_foreground_host_session() assert session is not None session.end() - babase.apptimer(1.0, Call(start_stress_test, args)) + babase.apptimer(1.0, babase.Call(start_stress_test, args)) def run_gpu_benchmark() -> None: @@ -161,8 +157,6 @@ def run_gpu_benchmark() -> None: def run_media_reload_benchmark() -> None: """Kick off a benchmark to test media reloading speeds.""" - from babase._general import Call - babase.reload_media() babase.show_progress_bar() @@ -182,8 +176,8 @@ def run_media_reload_benchmark() -> None: color=(1, 1, 0), ) - babase.add_clean_frame_callback(Call(doit, start_time)) + babase.add_clean_frame_callback(babase.Call(doit, start_time)) # The reload starts (should add a completion callback to the # reload func to fix this). - babase.apptimer(0.05, Call(delay_add, babase.apptime())) + babase.apptimer(0.05, babase.Call(delay_add, babase.apptime())) diff --git a/src/assets/ba_data/python/baclassic/_music.py b/src/assets/ba_data/python/baclassic/_music.py index de979ab7..69dbe356 100644 --- a/src/assets/ba_data/python/baclassic/_music.py +++ b/src/assets/ba_data/python/baclassic/_music.py @@ -8,9 +8,9 @@ from typing import TYPE_CHECKING from dataclasses import dataclass from enum import Enum -import _babase -import _bascenev1 -from bascenev1._music import MusicType +import babase +import bascenev1 +from bascenev1 import MusicType if TYPE_CHECKING: from typing import Callable, Any @@ -116,7 +116,7 @@ class MusicSubsystem: # music-player going since it may hitch (better while we're faded # out than later). try: - cfg = _babase.app.config + cfg = babase.app.config if 'Soundtrack' in cfg and cfg['Soundtrack'] not in [ '__default__', 'Default Soundtrack', @@ -166,7 +166,7 @@ class MusicSubsystem: def supports_soundtrack_entry_type(self, entry_type: str) -> bool: """Return whether provided soundtrack entry type is supported here.""" - uas = _babase.env()['user_agent_string'] + uas = babase.env()['user_agent_string'] assert isinstance(uas, str) # FIXME: Generalize this. @@ -175,7 +175,7 @@ class MusicSubsystem: if entry_type in ('musicFile', 'musicFolder'): return ( 'android' in uas - and _babase.android_get_external_files_dir() is not None + and babase.android_get_external_files_dir() is not None ) if entry_type == 'default': return True @@ -246,7 +246,7 @@ class MusicSubsystem: def on_app_resume(self) -> None: """Should be run when the app resumes from a suspended state.""" - if _babase.is_os_playing_music(): + if babase.is_os_playing_music(): self.do_play_music(None) def do_play_music( @@ -272,7 +272,7 @@ class MusicSubsystem: print(f"Invalid music type: '{musictype}'") musictype = None - with _babase.ContextRef.empty(): + with babase.ContextRef.empty(): # If they don't want to restart music and we're already # playing what's requested, we're done. if continuous and self.music_types[mode] is musictype: @@ -281,7 +281,7 @@ class MusicSubsystem: # If the OS tells us there's currently music playing, # all our operations default to playing nothing. - if _babase.is_os_playing_music(): + if babase.is_os_playing_music(): musictype = None # If we're not in the mode this music is being set for, @@ -312,7 +312,7 @@ class MusicSubsystem: def _get_user_soundtrack(self) -> dict[str, Any]: """Return current user soundtrack or empty dict otherwise.""" - cfg = _babase.app.config + cfg = babase.app.config soundtrack: dict[str, Any] = {} soundtrackname = cfg.get('Soundtrack') if soundtrackname is not None and soundtrackname != '__default__': @@ -329,7 +329,7 @@ class MusicSubsystem: # self._music_node.delete() # self._music_node = None if self._playing_internal_music: - _bascenev1.set_internal_music(None) + bascenev1.set_internal_music(None) self._playing_internal_music = False # Do the thing. @@ -345,7 +345,7 @@ class MusicSubsystem: # self._music_node.delete() # self._music_node = None if self._playing_internal_music: - _bascenev1.set_internal_music(None) + bascenev1.set_internal_music(None) self._playing_internal_music = False # Start up new internal music. @@ -365,8 +365,8 @@ class MusicSubsystem: # 'loop': entry.loop, # }, # ) - _bascenev1.set_internal_music( - _babase.getsimplesound(entry.assetname), + bascenev1.set_internal_music( + babase.getsimplesound(entry.assetname), volume=entry.volume * 5.0, loop=entry.loop, ) @@ -408,7 +408,7 @@ class MusicPlayer: def play(self, entry: Any) -> None: """Play provided entry.""" if not self._have_set_initial_volume: - self._volume = _babase.app.config.resolve('Music Volume') + self._volume = babase.app.config.resolve('Music Volume') self.on_set_volume(self._volume) self._have_set_initial_volume = True self._entry_to_play = copy.deepcopy(entry) @@ -470,5 +470,5 @@ class MusicPlayer: def do_play_music(*args: Any, **keywds: Any) -> None: """A passthrough used by the C++ layer.""" - assert _babase.app.classic is not None - _babase.app.classic.music.do_play_music(*args, **keywds) + assert babase.app.classic is not None + babase.app.classic.music.do_play_music(*args, **keywds) diff --git a/src/assets/ba_data/python/baclassic/_net.py b/src/assets/ba_data/python/baclassic/_net.py index 4d7cbeb8..0eaece13 100644 --- a/src/assets/ba_data/python/baclassic/_net.py +++ b/src/assets/ba_data/python/baclassic/_net.py @@ -75,7 +75,6 @@ class MasterServerV1CallThread(threading.Thread): import json from efro.error import is_urllib_communication_error - from babase._general import Call, utf8_all plus = babase.app.plus assert plus is not None @@ -83,7 +82,7 @@ class MasterServerV1CallThread(threading.Thread): url: str | None = None try: assert babase.app.classic is not None - self._data = utf8_all(self._data) + self._data = babase.utf8_all(self._data) babase.set_thread_name('BA_ServerCallThread') if self._request_type == 'get': url = ( @@ -149,5 +148,6 @@ class MasterServerV1CallThread(threading.Thread): if self._callback is not None: babase.pushcall( - Call(self._run_callback, response_data), from_other_thread=True + babase.Call(self._run_callback, response_data), + from_other_thread=True, ) diff --git a/src/assets/ba_data/python/baclassic/macmusicapp.py b/src/assets/ba_data/python/baclassic/macmusicapp.py index 81fde026..1b87fbf1 100644 --- a/src/assets/ba_data/python/baclassic/macmusicapp.py +++ b/src/assets/ba_data/python/baclassic/macmusicapp.py @@ -3,6 +3,7 @@ """Music playback functionality using the Mac Music (formerly iTunes) app.""" from __future__ import annotations +import logging import threading from collections import deque from typing import TYPE_CHECKING @@ -78,9 +79,6 @@ class _MacMusicAppThread(threading.Thread): def run(self) -> None: """Run the Music.app thread.""" - from babase._general import Call - from babase._language import Lstr - babase.set_thread_name('BA_MacMusicAppThread') babase.mac_music_app_init() @@ -90,9 +88,9 @@ class _MacMusicAppThread(threading.Thread): def do_print() -> None: babase.apptimer( 1.0, - Call( + babase.Call( babase.screenmessage, - Lstr(resource='usingItunesText'), + babase.Lstr(resource='usingItunesText'), (0, 1, 0), ), ) @@ -169,8 +167,6 @@ class _MacMusicAppThread(threading.Thread): def _handle_get_playlists_command( self, target: Callable[[list[str]], None] ) -> None: - from babase._general import Call - try: playlists = babase.mac_music_app_get_playlists() playlists = [ @@ -196,7 +192,7 @@ class _MacMusicAppThread(threading.Thread): except Exception as exc: print('Error getting iTunes playlists:', exc) playlists = [] - babase.pushcall(Call(target, playlists), from_other_thread=True) + babase.pushcall(babase.Call(target, playlists), from_other_thread=True) def _handle_play_command(self, target: str | None) -> None: if target is None: @@ -239,14 +235,12 @@ class _MacMusicAppThread(threading.Thread): def _play_current_playlist(self) -> None: try: - from babase._general import Call - assert self._current_playlist is not None if babase.mac_music_app_play_playlist(self._current_playlist): pass else: babase.pushcall( - Call( + babase.Call( babase.screenmessage, babase.app.lang.get_resource('playlistNotFoundText') + ': \'' @@ -257,10 +251,8 @@ class _MacMusicAppThread(threading.Thread): from_other_thread=True, ) except Exception: - from babase import _error - - _error.print_exception( - f'error playing playlist {self._current_playlist}' + logging.exception( + "Error playing playlist '%s'.", self._current_playlist ) def _update_mac_music_app_volume(self) -> None: diff --git a/src/assets/ba_data/python/baclassic/osmusic.py b/src/assets/ba_data/python/baclassic/osmusic.py index fe3c15d4..d808000d 100644 --- a/src/assets/ba_data/python/baclassic/osmusic.py +++ b/src/assets/ba_data/python/baclassic/osmusic.py @@ -121,9 +121,6 @@ class _PickFolderSongThread(threading.Thread): self._path = path def run(self) -> None: - from babase import _language - from babase._general import Call - do_log_error = True try: babase.set_thread_name('BA_PickFolderSongThread') @@ -141,12 +138,13 @@ class _PickFolderSongThread(threading.Thread): if not all_files: do_log_error = False raise RuntimeError( - _language.Lstr( + babase.Lstr( resource='internal.noMusicFilesInFolderText' ).evaluate() ) babase.pushcall( - Call(self._callback, all_files, None), from_other_thread=True + babase.Call(self._callback, all_files, None), + from_other_thread=True, ) except Exception as exc: if do_log_error: @@ -156,6 +154,6 @@ class _PickFolderSongThread(threading.Thread): except Exception: err_str = '' babase.pushcall( - Call(self._callback, self._path, err_str), + babase.Call(self._callback, self._path, err_str), from_other_thread=True, ) diff --git a/src/assets/ba_data/python/bascenev1/__init__.py b/src/assets/ba_data/python/bascenev1/__init__.py index dd8f17e7..21f802bb 100644 --- a/src/assets/ba_data/python/bascenev1/__init__.py +++ b/src/assets/ba_data/python/bascenev1/__init__.py @@ -62,6 +62,7 @@ from babase._mgen.enums import ( ) from _bascenev1 import ( + set_internal_music, set_master_server_source, get_foreground_host_session, get_foreground_host_activity, @@ -216,6 +217,7 @@ from bascenev1._dependency import ( from bascenev1._gameutils import get_trophy_string __all__ = [ + 'set_internal_music', 'get_trophy_string', 'app', 'get_local_active_input_devices_count',