mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-24 16:06:51 +08:00
and more
This commit is contained in:
parent
08bcf88929
commit
0bf2eeb0e3
@ -12,6 +12,18 @@ from efro.util import set_canonical_module_names
|
||||
|
||||
import _babase
|
||||
from _babase import (
|
||||
music_player_set_volume,
|
||||
music_player_play,
|
||||
music_player_stop,
|
||||
music_player_shutdown,
|
||||
mac_music_app_init,
|
||||
mac_music_app_get_volume,
|
||||
mac_music_app_get_library_source,
|
||||
mac_music_app_stop,
|
||||
mac_music_app_set_volume,
|
||||
mac_music_app_get_playlists,
|
||||
mac_music_app_play_playlist,
|
||||
set_thread_name,
|
||||
show_progress_bar,
|
||||
print_load_info,
|
||||
reload_media,
|
||||
@ -131,6 +143,7 @@ _babase.app = app = App()
|
||||
app.postinit()
|
||||
|
||||
__all__ = [
|
||||
'set_thread_name',
|
||||
'app',
|
||||
'AccountV2Handle',
|
||||
'AccountV2Subsystem',
|
||||
@ -243,6 +256,17 @@ __all__ = [
|
||||
'print_load_info',
|
||||
'show_progress_bar',
|
||||
'handle_leftover_v1_cloud_log_file',
|
||||
'music_player_set_volume',
|
||||
'music_player_play',
|
||||
'music_player_stop',
|
||||
'music_player_shutdown',
|
||||
'mac_music_app_init',
|
||||
'mac_music_app_get_volume',
|
||||
'mac_music_app_get_library_source',
|
||||
'mac_music_app_stop',
|
||||
'mac_music_app_set_volume',
|
||||
'mac_music_app_get_playlists',
|
||||
'mac_music_app_play_playlist',
|
||||
]
|
||||
|
||||
# We want stuff to show up as babase.Foo instead of babase._sub.Foo.
|
||||
|
||||
@ -9,9 +9,9 @@ import weakref
|
||||
from enum import Enum
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import _babase
|
||||
import _bascenev1
|
||||
import babase
|
||||
from babase.internal import DEFAULT_REQUEST_TIMEOUT_SECONDS
|
||||
import bascenev1
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any, Callable
|
||||
@ -44,10 +44,10 @@ class MasterServerV1CallThread(threading.Thread):
|
||||
self._response_type = response_type
|
||||
self._data = {} if data is None else copy.deepcopy(data)
|
||||
self._callback: MasterServerCallback | None = callback
|
||||
self._context = _babase.ContextRef()
|
||||
self._context = babase.ContextRef()
|
||||
|
||||
# Save and restore the context we were created from.
|
||||
activity = _bascenev1.getactivity(doraise=False)
|
||||
activity = bascenev1.getactivity(doraise=False)
|
||||
self._activity = weakref.ref(activity) if activity is not None else None
|
||||
|
||||
def _run_callback(self, arg: None | dict[str, Any]) -> None:
|
||||
@ -77,14 +77,14 @@ class MasterServerV1CallThread(threading.Thread):
|
||||
from efro.error import is_urllib_communication_error
|
||||
from babase._general import Call, utf8_all
|
||||
|
||||
plus = _babase.app.plus
|
||||
plus = babase.app.plus
|
||||
assert plus is not None
|
||||
response_data: Any = None
|
||||
url: str | None = None
|
||||
try:
|
||||
assert _babase.app.classic is not None
|
||||
assert babase.app.classic is not None
|
||||
self._data = utf8_all(self._data)
|
||||
_babase.set_thread_name('BA_ServerCallThread')
|
||||
babase.set_thread_name('BA_ServerCallThread')
|
||||
if self._request_type == 'get':
|
||||
url = (
|
||||
plus.get_master_server_address()
|
||||
@ -98,9 +98,9 @@ class MasterServerV1CallThread(threading.Thread):
|
||||
urllib.request.Request(
|
||||
url,
|
||||
None,
|
||||
{'User-Agent': _babase.app.classic.user_agent_string},
|
||||
{'User-Agent': babase.app.classic.user_agent_string},
|
||||
),
|
||||
context=_babase.app.net.sslcontext,
|
||||
context=babase.app.net.sslcontext,
|
||||
timeout=DEFAULT_REQUEST_TIMEOUT_SECONDS,
|
||||
)
|
||||
elif self._request_type == 'post':
|
||||
@ -110,9 +110,9 @@ class MasterServerV1CallThread(threading.Thread):
|
||||
urllib.request.Request(
|
||||
url,
|
||||
urllib.parse.urlencode(self._data).encode(),
|
||||
{'User-Agent': _babase.app.classic.user_agent_string},
|
||||
{'User-Agent': babase.app.classic.user_agent_string},
|
||||
),
|
||||
context=_babase.app.net.sslcontext,
|
||||
context=babase.app.net.sslcontext,
|
||||
timeout=DEFAULT_REQUEST_TIMEOUT_SECONDS,
|
||||
)
|
||||
else:
|
||||
@ -148,6 +148,6 @@ class MasterServerV1CallThread(threading.Thread):
|
||||
response_data = None
|
||||
|
||||
if self._callback is not None:
|
||||
_babase.pushcall(
|
||||
babase.pushcall(
|
||||
Call(self._run_callback, response_data), from_other_thread=True
|
||||
)
|
||||
|
||||
@ -6,7 +6,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import _babase
|
||||
import babase
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Any
|
||||
@ -15,8 +15,7 @@ if TYPE_CHECKING:
|
||||
def get_tournament_prize_strings(entry: dict[str, Any]) -> list[str]:
|
||||
"""Given a tournament entry, return strings for its prize levels."""
|
||||
# pylint: disable=too-many-locals
|
||||
from babase._mgen.enums import SpecialChar
|
||||
from bascenev1._gameutils import get_trophy_string
|
||||
from bascenev1 import get_trophy_string
|
||||
|
||||
range1 = entry.get('prizeRange1')
|
||||
range2 = entry.get('prizeRange2')
|
||||
@ -48,7 +47,9 @@ def get_tournament_prize_strings(entry: dict[str, Any]) -> list[str]:
|
||||
# in to compensate so the ticket counts line up.
|
||||
if prize is not None:
|
||||
pvval = (
|
||||
_babase.charstr(SpecialChar.TICKET_BACKING) + str(prize) + pvval
|
||||
babase.charstr(babase.SpecialChar.TICKET_BACKING)
|
||||
+ str(prize)
|
||||
+ pvval
|
||||
)
|
||||
out_vals.append(prval)
|
||||
out_vals.append(pvval)
|
||||
|
||||
@ -7,9 +7,9 @@ import threading
|
||||
from collections import deque
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import _babase
|
||||
import babase
|
||||
|
||||
from baclassic._music import MusicPlayer
|
||||
import bauiv1 as bui
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Callable, Any
|
||||
@ -47,8 +47,8 @@ class MacMusicAppMusicPlayer(MusicPlayer):
|
||||
self._thread.get_playlists(callback)
|
||||
|
||||
def on_play(self, entry: Any) -> None:
|
||||
assert _babase.app.classic is not None
|
||||
music = _babase.app.classic.music
|
||||
assert babase.app.classic is not None
|
||||
music = babase.app.classic.music
|
||||
entry_type = music.get_soundtrack_entry_type(entry)
|
||||
if entry_type == 'iTunesPlaylist':
|
||||
self._thread.play_playlist(music.get_soundtrack_entry_name(entry))
|
||||
@ -81,27 +81,27 @@ class _MacMusicAppThread(threading.Thread):
|
||||
from babase._general import Call
|
||||
from babase._language import Lstr
|
||||
|
||||
_babase.set_thread_name('BA_MacMusicAppThread')
|
||||
_babase.mac_music_app_init()
|
||||
babase.set_thread_name('BA_MacMusicAppThread')
|
||||
babase.mac_music_app_init()
|
||||
|
||||
# Let's mention to the user we're launching Music.app in case
|
||||
# it causes any funny business (this used to background the app
|
||||
# sometimes, though I think that is fixed now)
|
||||
def do_print() -> None:
|
||||
bui.apptimer(
|
||||
babase.apptimer(
|
||||
1.0,
|
||||
Call(
|
||||
_babase.screenmessage,
|
||||
babase.screenmessage,
|
||||
Lstr(resource='usingItunesText'),
|
||||
(0, 1, 0),
|
||||
),
|
||||
)
|
||||
|
||||
_babase.pushcall(do_print, from_other_thread=True)
|
||||
babase.pushcall(do_print, from_other_thread=True)
|
||||
|
||||
# Here we grab this to force the actual launch.
|
||||
_babase.mac_music_app_get_volume()
|
||||
_babase.mac_music_app_get_library_source()
|
||||
babase.mac_music_app_get_volume()
|
||||
babase.mac_music_app_get_library_source()
|
||||
done = False
|
||||
while not done:
|
||||
self._commands_available.wait()
|
||||
@ -137,15 +137,15 @@ class _MacMusicAppThread(threading.Thread):
|
||||
if old_volume > 0.0 and volume == 0.0:
|
||||
try:
|
||||
assert self._orig_volume is not None
|
||||
_babase.mac_music_app_stop()
|
||||
_babase.mac_music_app_set_volume(self._orig_volume)
|
||||
babase.mac_music_app_stop()
|
||||
babase.mac_music_app_set_volume(self._orig_volume)
|
||||
except Exception as exc:
|
||||
print('Error stopping iTunes music:', exc)
|
||||
elif self._volume > 0:
|
||||
# If volume was zero, store pre-playing volume and start
|
||||
# playing.
|
||||
if old_volume == 0.0:
|
||||
self._orig_volume = _babase.mac_music_app_get_volume()
|
||||
self._orig_volume = babase.mac_music_app_get_volume()
|
||||
self._update_mac_music_app_volume()
|
||||
if old_volume == 0.0:
|
||||
self._play_current_playlist()
|
||||
@ -172,7 +172,7 @@ class _MacMusicAppThread(threading.Thread):
|
||||
from babase._general import Call
|
||||
|
||||
try:
|
||||
playlists = _babase.mac_music_app_get_playlists()
|
||||
playlists = babase.mac_music_app_get_playlists()
|
||||
playlists = [
|
||||
p
|
||||
for p in playlists
|
||||
@ -196,15 +196,15 @@ 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(Call(target, playlists), from_other_thread=True)
|
||||
|
||||
def _handle_play_command(self, target: str | None) -> None:
|
||||
if target is None:
|
||||
if self._current_playlist is not None and self._volume > 0:
|
||||
try:
|
||||
assert self._orig_volume is not None
|
||||
_babase.mac_music_app_stop()
|
||||
_babase.mac_music_app_set_volume(self._orig_volume)
|
||||
babase.mac_music_app_stop()
|
||||
babase.mac_music_app_set_volume(self._orig_volume)
|
||||
except Exception as exc:
|
||||
print('Error stopping iTunes music:', exc)
|
||||
self._current_playlist = None
|
||||
@ -214,15 +214,15 @@ class _MacMusicAppThread(threading.Thread):
|
||||
if self._current_playlist is not None and self._volume > 0:
|
||||
try:
|
||||
assert self._orig_volume is not None
|
||||
_babase.mac_music_app_stop()
|
||||
_babase.mac_music_app_set_volume(self._orig_volume)
|
||||
babase.mac_music_app_stop()
|
||||
babase.mac_music_app_set_volume(self._orig_volume)
|
||||
except Exception as exc:
|
||||
print('Error stopping iTunes music:', exc)
|
||||
|
||||
# Set our playlist and play it if our volume is up.
|
||||
self._current_playlist = target
|
||||
if self._volume > 0:
|
||||
self._orig_volume = _babase.mac_music_app_get_volume()
|
||||
self._orig_volume = babase.mac_music_app_get_volume()
|
||||
self._update_mac_music_app_volume()
|
||||
self._play_current_playlist()
|
||||
|
||||
@ -232,8 +232,8 @@ class _MacMusicAppThread(threading.Thread):
|
||||
if self._current_playlist is not None and self._volume > 0:
|
||||
try:
|
||||
assert self._orig_volume is not None
|
||||
_babase.mac_music_app_stop()
|
||||
_babase.mac_music_app_set_volume(self._orig_volume)
|
||||
babase.mac_music_app_stop()
|
||||
babase.mac_music_app_set_volume(self._orig_volume)
|
||||
except Exception as exc:
|
||||
print('Error stopping iTunes music:', exc)
|
||||
|
||||
@ -242,13 +242,13 @@ class _MacMusicAppThread(threading.Thread):
|
||||
from babase._general import Call
|
||||
|
||||
assert self._current_playlist is not None
|
||||
if _babase.mac_music_app_play_playlist(self._current_playlist):
|
||||
if babase.mac_music_app_play_playlist(self._current_playlist):
|
||||
pass
|
||||
else:
|
||||
_babase.pushcall(
|
||||
babase.pushcall(
|
||||
Call(
|
||||
_babase.screenmessage,
|
||||
_babase.app.lang.get_resource('playlistNotFoundText')
|
||||
babase.screenmessage,
|
||||
babase.app.lang.get_resource('playlistNotFoundText')
|
||||
+ ': \''
|
||||
+ self._current_playlist
|
||||
+ '\'',
|
||||
@ -264,6 +264,6 @@ class _MacMusicAppThread(threading.Thread):
|
||||
)
|
||||
|
||||
def _update_mac_music_app_volume(self) -> None:
|
||||
_babase.mac_music_app_set_volume(
|
||||
babase.mac_music_app_set_volume(
|
||||
max(0, min(100, int(100.0 * self._volume)))
|
||||
)
|
||||
|
||||
@ -5,10 +5,12 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import random
|
||||
import logging
|
||||
import threading
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import _babase
|
||||
import babase
|
||||
|
||||
from baclassic._music import MusicPlayer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -47,17 +49,17 @@ class OSMusicPlayer(MusicPlayer):
|
||||
)
|
||||
|
||||
def on_set_volume(self, volume: float) -> None:
|
||||
_babase.music_player_set_volume(volume)
|
||||
babase.music_player_set_volume(volume)
|
||||
|
||||
def on_play(self, entry: Any) -> None:
|
||||
assert _babase.app.classic is not None
|
||||
music = _babase.app.classic.music
|
||||
assert babase.app.classic is not None
|
||||
music = babase.app.classic.music
|
||||
entry_type = music.get_soundtrack_entry_type(entry)
|
||||
name = music.get_soundtrack_entry_name(entry)
|
||||
assert name is not None
|
||||
if entry_type == 'musicFile':
|
||||
self._want_to_play = self._actually_playing = True
|
||||
_babase.music_player_play(name)
|
||||
babase.music_player_play(name)
|
||||
elif entry_type == 'musicFolder':
|
||||
# Launch a thread to scan this folder and give us a random
|
||||
# valid file within it.
|
||||
@ -72,10 +74,8 @@ class OSMusicPlayer(MusicPlayer):
|
||||
def _on_play_folder_cb(
|
||||
self, result: str | list[str], error: str | None = None
|
||||
) -> None:
|
||||
from babase import _language
|
||||
|
||||
if error is not None:
|
||||
rstr = _language.Lstr(
|
||||
rstr = babase.Lstr(
|
||||
resource='internal.errorPlayingMusicText'
|
||||
).evaluate()
|
||||
if isinstance(result, str):
|
||||
@ -88,7 +88,7 @@ class OSMusicPlayer(MusicPlayer):
|
||||
err_str = (
|
||||
rstr.replace('${MUSIC}', '<multiple>') + '; ' + str(error)
|
||||
)
|
||||
_babase.screenmessage(err_str, color=(1, 0, 0))
|
||||
babase.screenmessage(err_str, color=(1, 0, 0))
|
||||
return
|
||||
|
||||
# There's a chance a stop could have been issued before our thread
|
||||
@ -97,15 +97,15 @@ class OSMusicPlayer(MusicPlayer):
|
||||
print('_on_play_folder_cb called with _want_to_play False')
|
||||
else:
|
||||
self._actually_playing = True
|
||||
_babase.music_player_play(result)
|
||||
babase.music_player_play(result)
|
||||
|
||||
def on_stop(self) -> None:
|
||||
self._want_to_play = False
|
||||
self._actually_playing = False
|
||||
_babase.music_player_stop()
|
||||
babase.music_player_stop()
|
||||
|
||||
def on_app_shutdown(self) -> None:
|
||||
_babase.music_player_shutdown()
|
||||
babase.music_player_shutdown()
|
||||
|
||||
|
||||
class _PickFolderSongThread(threading.Thread):
|
||||
@ -124,9 +124,9 @@ class _PickFolderSongThread(threading.Thread):
|
||||
from babase import _language
|
||||
from babase._general import Call
|
||||
|
||||
do_print_error = True
|
||||
do_log_error = True
|
||||
try:
|
||||
_babase.set_thread_name('BA_PickFolderSongThread')
|
||||
babase.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):
|
||||
@ -139,25 +139,23 @@ class _PickFolderSongThread(threading.Thread):
|
||||
root + '/' + fname,
|
||||
)
|
||||
if not all_files:
|
||||
do_print_error = False
|
||||
do_log_error = False
|
||||
raise RuntimeError(
|
||||
_language.Lstr(
|
||||
resource='internal.noMusicFilesInFolderText'
|
||||
).evaluate()
|
||||
)
|
||||
_babase.pushcall(
|
||||
babase.pushcall(
|
||||
Call(self._callback, all_files, None), from_other_thread=True
|
||||
)
|
||||
except Exception as exc:
|
||||
from babase import _error
|
||||
|
||||
if do_print_error:
|
||||
_error.print_exception()
|
||||
if do_log_error:
|
||||
logging.exception('Error in _PickFolderSongThread')
|
||||
try:
|
||||
err_str = str(exc)
|
||||
except Exception:
|
||||
err_str = '<ENCERR4523>'
|
||||
_babase.pushcall(
|
||||
babase.pushcall(
|
||||
Call(self._callback, self._path, err_str),
|
||||
from_other_thread=True,
|
||||
)
|
||||
|
||||
@ -213,8 +213,10 @@ from bascenev1._dependency import (
|
||||
DependencySet,
|
||||
AssetPackage,
|
||||
)
|
||||
from bascenev1._gameutils import get_trophy_string
|
||||
|
||||
__all__ = [
|
||||
'get_trophy_string',
|
||||
'app',
|
||||
'get_local_active_input_devices_count',
|
||||
'lock_all_input',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user