mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-25 16:33:20 +08:00
more still
This commit is contained in:
parent
b329d10c61
commit
77dc36f8d0
@ -6,9 +6,9 @@ from __future__ import annotations
|
||||
import time
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import _babase
|
||||
import _bauiv1
|
||||
import _bascenev1
|
||||
import babase
|
||||
import bauiv1
|
||||
import bascenev1
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Callable, Any
|
||||
@ -37,15 +37,15 @@ class AdsSubsystem:
|
||||
from babase._language import Lstr
|
||||
|
||||
# Print this message once every 10 minutes at most.
|
||||
tval = _babase.apptime()
|
||||
tval = babase.apptime()
|
||||
if self.last_in_game_ad_remove_message_show_time is None or (
|
||||
tval - self.last_in_game_ad_remove_message_show_time > 60 * 10
|
||||
):
|
||||
self.last_in_game_ad_remove_message_show_time = tval
|
||||
with _babase.ContextRef.empty():
|
||||
_babase.apptimer(
|
||||
with babase.ContextRef.empty():
|
||||
babase.apptimer(
|
||||
1.0,
|
||||
lambda: _babase.screenmessage(
|
||||
lambda: babase.screenmessage(
|
||||
Lstr(
|
||||
resource='removeInGameAdsText',
|
||||
subs=[
|
||||
@ -65,7 +65,7 @@ class AdsSubsystem:
|
||||
) -> None:
|
||||
"""(internal)"""
|
||||
self.last_ad_purpose = purpose
|
||||
_bauiv1.show_ad(purpose, on_completion_call)
|
||||
bauiv1.show_ad(purpose, on_completion_call)
|
||||
|
||||
def show_ad_2(
|
||||
self,
|
||||
@ -74,7 +74,7 @@ class AdsSubsystem:
|
||||
) -> None:
|
||||
"""(internal)"""
|
||||
self.last_ad_purpose = purpose
|
||||
_bauiv1.show_ad_2(purpose, on_completion_call)
|
||||
bauiv1.show_ad_2(purpose, on_completion_call)
|
||||
|
||||
def call_after_ad(self, call: Callable[[], Any]) -> None:
|
||||
"""Run a call after potentially showing an ad."""
|
||||
@ -82,7 +82,7 @@ class AdsSubsystem:
|
||||
# pylint: disable=too-many-branches
|
||||
# pylint: disable=too-many-locals
|
||||
|
||||
app = _babase.app
|
||||
app = babase.app
|
||||
plus = app.plus
|
||||
classic = app.classic
|
||||
assert plus is not None
|
||||
@ -90,12 +90,12 @@ class AdsSubsystem:
|
||||
show = True
|
||||
|
||||
# No ads without net-connections, etc.
|
||||
if not _bauiv1.can_show_ad():
|
||||
if not bauiv1.can_show_ad():
|
||||
show = False
|
||||
if classic.accounts.have_pro():
|
||||
show = False # Pro disables interstitials.
|
||||
try:
|
||||
session = _bascenev1.get_foreground_host_session()
|
||||
session = bascenev1.get_foreground_host_session()
|
||||
assert session is not None
|
||||
is_tournament = session.tournament_id is not None
|
||||
except Exception:
|
||||
@ -128,7 +128,7 @@ class AdsSubsystem:
|
||||
# ad-show-threshold and see if we should *actually* show
|
||||
# (we reach our threshold faster the longer we've been
|
||||
# playing).
|
||||
base = 'ads' if _bauiv1.has_video_ads() else 'ads2'
|
||||
base = 'ads' if bauiv1.has_video_ads() else 'ads2'
|
||||
min_lc = plus.get_v1_account_misc_read_val(base + '.minLC', 0.0)
|
||||
max_lc = plus.get_v1_account_misc_read_val(base + '.maxLC', 5.0)
|
||||
min_lc_scale = plus.get_v1_account_misc_read_val(
|
||||
@ -166,7 +166,7 @@ class AdsSubsystem:
|
||||
self.last_ad_completion_time is None
|
||||
or (
|
||||
interval is not None
|
||||
and _babase.apptime() - self.last_ad_completion_time
|
||||
and babase.apptime() - self.last_ad_completion_time
|
||||
> (interval * interval_mult)
|
||||
)
|
||||
):
|
||||
@ -201,12 +201,12 @@ class AdsSubsystem:
|
||||
+ 's ago); purpose='
|
||||
+ app.classic.ads.last_ad_purpose
|
||||
)
|
||||
_babase.pushcall(self._call)
|
||||
babase.pushcall(self._call)
|
||||
self._ran = True
|
||||
|
||||
payload = _Payload(call)
|
||||
with _babase.ContextRef.empty():
|
||||
_babase.apptimer(5.0, lambda: payload.run(fallback=True))
|
||||
with babase.ContextRef.empty():
|
||||
babase.apptimer(5.0, lambda: payload.run(fallback=True))
|
||||
self.show_ad('between_game', on_completion_call=payload.run)
|
||||
else:
|
||||
_babase.pushcall(call) # Just run the callback without the ad.
|
||||
babase.pushcall(call) # Just run the callback without the ad.
|
||||
|
||||
@ -6,8 +6,8 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import _babase
|
||||
import _bascenev1
|
||||
import babase
|
||||
import bascenev1
|
||||
|
||||
if TYPE_CHECKING:
|
||||
pass
|
||||
@ -17,15 +17,17 @@ def game_begin_analytics() -> None:
|
||||
"""Update analytics events for the start of a game."""
|
||||
# pylint: disable=too-many-branches
|
||||
# pylint: disable=cyclic-import
|
||||
from bascenev1._dualteamsession import DualTeamSession
|
||||
from bascenev1._freeforallsession import FreeForAllSession
|
||||
from bascenev1._coopsession import CoopSession
|
||||
from bascenev1._gameactivity import GameActivity
|
||||
from bascenev1 import (
|
||||
DualTeamSession,
|
||||
FreeForAllSession,
|
||||
CoopSession,
|
||||
GameActivity,
|
||||
)
|
||||
|
||||
assert _babase.app.classic is not None
|
||||
assert babase.app.classic is not None
|
||||
|
||||
activity = _bascenev1.getactivity(False)
|
||||
session = _bascenev1.getsession(False)
|
||||
activity = bascenev1.getactivity(False)
|
||||
session = bascenev1.getsession(False)
|
||||
|
||||
# Fail gracefully if we didn't cleanly get a session and game activity.
|
||||
if not activity or not session or not isinstance(activity, GameActivity):
|
||||
@ -34,64 +36,60 @@ def game_begin_analytics() -> None:
|
||||
if isinstance(session, CoopSession):
|
||||
campaign = session.campaign
|
||||
assert campaign is not None
|
||||
_babase.set_analytics_screen(
|
||||
babase.set_analytics_screen(
|
||||
'Coop Game: '
|
||||
+ campaign.name
|
||||
+ ' '
|
||||
+ campaign.getlevel(
|
||||
_babase.app.classic.coop_session_args['level']
|
||||
babase.app.classic.coop_session_args['level']
|
||||
).name
|
||||
)
|
||||
_babase.increment_analytics_count('Co-op round start')
|
||||
babase.increment_analytics_count('Co-op round start')
|
||||
if len(activity.players) == 1:
|
||||
_babase.increment_analytics_count(
|
||||
'Co-op round start 1 human player'
|
||||
)
|
||||
babase.increment_analytics_count('Co-op round start 1 human player')
|
||||
elif len(activity.players) == 2:
|
||||
_babase.increment_analytics_count(
|
||||
babase.increment_analytics_count(
|
||||
'Co-op round start 2 human players'
|
||||
)
|
||||
elif len(activity.players) == 3:
|
||||
_babase.increment_analytics_count(
|
||||
babase.increment_analytics_count(
|
||||
'Co-op round start 3 human players'
|
||||
)
|
||||
elif len(activity.players) >= 4:
|
||||
_babase.increment_analytics_count(
|
||||
babase.increment_analytics_count(
|
||||
'Co-op round start 4+ human players'
|
||||
)
|
||||
|
||||
elif isinstance(session, DualTeamSession):
|
||||
_babase.set_analytics_screen('Teams Game: ' + activity.getname())
|
||||
_babase.increment_analytics_count('Teams round start')
|
||||
babase.set_analytics_screen('Teams Game: ' + activity.getname())
|
||||
babase.increment_analytics_count('Teams round start')
|
||||
if len(activity.players) == 1:
|
||||
_babase.increment_analytics_count(
|
||||
'Teams round start 1 human player'
|
||||
)
|
||||
babase.increment_analytics_count('Teams round start 1 human player')
|
||||
elif 1 < len(activity.players) < 8:
|
||||
_babase.increment_analytics_count(
|
||||
babase.increment_analytics_count(
|
||||
'Teams round start '
|
||||
+ str(len(activity.players))
|
||||
+ ' human players'
|
||||
)
|
||||
elif len(activity.players) >= 8:
|
||||
_babase.increment_analytics_count(
|
||||
babase.increment_analytics_count(
|
||||
'Teams round start 8+ human players'
|
||||
)
|
||||
|
||||
elif isinstance(session, FreeForAllSession):
|
||||
_babase.set_analytics_screen('FreeForAll Game: ' + activity.getname())
|
||||
_babase.increment_analytics_count('Free-for-all round start')
|
||||
babase.set_analytics_screen('FreeForAll Game: ' + activity.getname())
|
||||
babase.increment_analytics_count('Free-for-all round start')
|
||||
if len(activity.players) == 1:
|
||||
_babase.increment_analytics_count(
|
||||
babase.increment_analytics_count(
|
||||
'Free-for-all round start 1 human player'
|
||||
)
|
||||
elif 1 < len(activity.players) < 8:
|
||||
_babase.increment_analytics_count(
|
||||
babase.increment_analytics_count(
|
||||
'Free-for-all round start '
|
||||
+ str(len(activity.players))
|
||||
+ ' human players'
|
||||
)
|
||||
elif len(activity.players) >= 8:
|
||||
_babase.increment_analytics_count(
|
||||
babase.increment_analytics_count(
|
||||
'Free-for-all round start 8+ human players'
|
||||
)
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
@ -123,9 +124,7 @@ class MusicSubsystem:
|
||||
]:
|
||||
self.get_music_player()
|
||||
except Exception:
|
||||
from babase import _error
|
||||
|
||||
_error.print_exception('error prepping music-player')
|
||||
logging.exception('Error prepping music-player.')
|
||||
|
||||
def on_app_shutdown(self) -> None:
|
||||
"""Should be called when the app is shutting down."""
|
||||
@ -213,9 +212,7 @@ class MusicSubsystem:
|
||||
return entry_type
|
||||
raise ValueError('invalid soundtrack entry:' + str(entry))
|
||||
except Exception:
|
||||
from babase import _error
|
||||
|
||||
_error.print_exception()
|
||||
logging.exception('Error in get_soundtrack_entry_type.')
|
||||
return 'default'
|
||||
|
||||
def get_soundtrack_entry_name(self, entry: Any) -> str:
|
||||
@ -239,9 +236,7 @@ class MusicSubsystem:
|
||||
return entry['name']
|
||||
raise ValueError('invalid soundtrack entry:' + str(entry))
|
||||
except Exception:
|
||||
from babase import _error
|
||||
|
||||
_error.print_exception()
|
||||
logging.exception('Error in get_soundtrack_entry_name.')
|
||||
return 'default'
|
||||
|
||||
def on_app_resume(self) -> None:
|
||||
|
||||
@ -19,7 +19,7 @@ from bacommon.servermanager import (
|
||||
ClientListCommand,
|
||||
KickCommand,
|
||||
)
|
||||
import _babase
|
||||
import babase
|
||||
import bascenev1
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -33,30 +33,30 @@ def _cmd(command_data: bytes) -> None:
|
||||
"""Handle commands coming in from our server manager parent process."""
|
||||
import pickle
|
||||
|
||||
assert _babase.app.classic is not None
|
||||
assert babase.app.classic is not None
|
||||
|
||||
command = pickle.loads(command_data)
|
||||
assert isinstance(command, ServerCommand)
|
||||
|
||||
if isinstance(command, StartServerModeCommand):
|
||||
assert _babase.app.classic.server is None
|
||||
_babase.app.classic.server = ServerController(command.config)
|
||||
assert babase.app.classic.server is None
|
||||
babase.app.classic.server = ServerController(command.config)
|
||||
return
|
||||
|
||||
if isinstance(command, ShutdownCommand):
|
||||
assert _babase.app.classic.server is not None
|
||||
_babase.app.classic.server.shutdown(
|
||||
assert babase.app.classic.server is not None
|
||||
babase.app.classic.server.shutdown(
|
||||
reason=command.reason, immediate=command.immediate
|
||||
)
|
||||
return
|
||||
|
||||
if isinstance(command, ChatMessageCommand):
|
||||
assert _babase.app.classic.server is not None
|
||||
assert babase.app.classic.server is not None
|
||||
bascenev1.chatmessage(command.message, clients=command.clients)
|
||||
return
|
||||
|
||||
if isinstance(command, ScreenMessageCommand):
|
||||
assert _babase.app.classic.server is not None
|
||||
assert babase.app.classic.server is not None
|
||||
|
||||
# Note: we have to do transient messages if
|
||||
# clients is specified, so they won't show up
|
||||
@ -70,13 +70,13 @@ def _cmd(command_data: bytes) -> None:
|
||||
return
|
||||
|
||||
if isinstance(command, ClientListCommand):
|
||||
assert _babase.app.classic.server is not None
|
||||
_babase.app.classic.server.print_client_list()
|
||||
assert babase.app.classic.server is not None
|
||||
babase.app.classic.server.print_client_list()
|
||||
return
|
||||
|
||||
if isinstance(command, KickCommand):
|
||||
assert _babase.app.classic.server is not None
|
||||
_babase.app.classic.server.kick(
|
||||
assert babase.app.classic.server is not None
|
||||
babase.app.classic.server.kick(
|
||||
client_id=command.client_id, ban_time=command.ban_time
|
||||
)
|
||||
return
|
||||
@ -113,8 +113,8 @@ class ServerController:
|
||||
# Now sit around doing any pre-launch prep such as waiting for
|
||||
# account sign-in or fetching playlists; this will kick off the
|
||||
# session once done.
|
||||
with _babase.ContextRef.empty():
|
||||
self._prep_timer = _babase.AppTimer(
|
||||
with babase.ContextRef.empty():
|
||||
self._prep_timer = babase.AppTimer(
|
||||
0.25, self._prepare_to_serve, repeat=True
|
||||
)
|
||||
|
||||
@ -184,15 +184,13 @@ class ServerController:
|
||||
return False
|
||||
|
||||
def _execute_shutdown(self) -> None:
|
||||
from babase._language import Lstr
|
||||
|
||||
if self._executing_shutdown:
|
||||
return
|
||||
self._executing_shutdown = True
|
||||
timestrval = time.strftime('%c')
|
||||
if self._shutdown_reason is ShutdownReason.RESTARTING:
|
||||
_babase.screenmessage(
|
||||
Lstr(resource='internal.serverRestartingText'),
|
||||
babase.screenmessage(
|
||||
babase.Lstr(resource='internal.serverRestartingText'),
|
||||
color=(1, 0.5, 0.0),
|
||||
)
|
||||
print(
|
||||
@ -200,24 +198,24 @@ class ServerController:
|
||||
f' at {timestrval}.{Clr.RST}'
|
||||
)
|
||||
else:
|
||||
_babase.screenmessage(
|
||||
Lstr(resource='internal.serverShuttingDownText'),
|
||||
babase.screenmessage(
|
||||
babase.Lstr(resource='internal.serverShuttingDownText'),
|
||||
color=(1, 0.5, 0.0),
|
||||
)
|
||||
print(
|
||||
f'{Clr.SBLU}Exiting for server-shutdown'
|
||||
f' at {timestrval}.{Clr.RST}'
|
||||
)
|
||||
with _babase.ContextRef.empty():
|
||||
_babase.apptimer(2.0, _babase.quit)
|
||||
with babase.ContextRef.empty():
|
||||
babase.apptimer(2.0, babase.quit)
|
||||
|
||||
def _run_access_check(self) -> None:
|
||||
"""Check with the master server to see if we're likely joinable."""
|
||||
assert _babase.app.classic is not None
|
||||
assert babase.app.classic is not None
|
||||
|
||||
_babase.app.classic.master_server_v1_get(
|
||||
babase.app.classic.master_server_v1_get(
|
||||
'bsAccessCheck',
|
||||
{'port': bascenev1.get_game_port(), 'b': _babase.app.build_number},
|
||||
{'port': bascenev1.get_game_port(), 'b': babase.app.build_number},
|
||||
callback=self._access_check_response,
|
||||
)
|
||||
|
||||
@ -256,7 +254,7 @@ class ServerController:
|
||||
|
||||
def _prepare_to_serve(self) -> None:
|
||||
"""Run in a timer to do prep before beginning to serve."""
|
||||
plus = _babase.app.plus
|
||||
plus = babase.app.plus
|
||||
assert plus is not None
|
||||
signed_in = plus.get_v1_account_state() == 'signed_in'
|
||||
if not signed_in:
|
||||
@ -296,7 +294,7 @@ class ServerController:
|
||||
|
||||
if can_launch:
|
||||
self._prep_timer = None
|
||||
_babase.pushcall(self._launch_server_session)
|
||||
babase.pushcall(self._launch_server_session)
|
||||
|
||||
def _on_playlist_fetch_response(
|
||||
self,
|
||||
@ -337,7 +335,7 @@ class ServerController:
|
||||
"""Kick off a host-session based on the current server config."""
|
||||
# pylint: disable=too-many-branches
|
||||
# pylint: disable=too-many-statements
|
||||
app = _babase.app
|
||||
app = babase.app
|
||||
classic = app.classic
|
||||
plus = app.plus
|
||||
assert plus is not None
|
||||
@ -382,7 +380,7 @@ class ServerController:
|
||||
if self._first_run:
|
||||
curtimestr = time.strftime('%c')
|
||||
startupmsg = (
|
||||
f'{Clr.BLD}{Clr.BLU}{_babase.appnameupper()} {app.version}'
|
||||
f'{Clr.BLD}{Clr.BLU}{babase.appnameupper()} {app.version}'
|
||||
f' ({app.build_number})'
|
||||
f' entering server-mode {curtimestr}{Clr.RST}'
|
||||
)
|
||||
@ -426,8 +424,8 @@ class ServerController:
|
||||
# And here.. we.. go.
|
||||
if self._config.stress_test_players is not None:
|
||||
# Special case: run a stress test.
|
||||
assert _babase.app.classic is not None
|
||||
_babase.app.classic.run_stress_test(
|
||||
assert babase.app.classic is not None
|
||||
babase.app.classic.run_stress_test(
|
||||
playlist_type='Random',
|
||||
playlist_name='__default__',
|
||||
player_count=self._config.stress_test_players,
|
||||
|
||||
@ -145,8 +145,6 @@ class ClassicSubsystem(babase.AppSubsystem):
|
||||
return self._env['user_agent_string']
|
||||
|
||||
def on_app_loading(self) -> None:
|
||||
from bascenev1 import _campaign
|
||||
from bascenev1 import _map
|
||||
from bascenev1lib.actor import spazappearance
|
||||
from bascenev1lib import maps as stdmaps
|
||||
|
||||
@ -190,10 +188,10 @@ class ClassicSubsystem(babase.AppSubsystem):
|
||||
stdmaps.Courtyard,
|
||||
stdmaps.Rampage,
|
||||
]:
|
||||
_map.register_map(maptype)
|
||||
bascenev1.register_map(maptype)
|
||||
|
||||
spazappearance.register_appearances()
|
||||
_campaign.init_campaigns()
|
||||
bascenev1.init_campaigns()
|
||||
|
||||
launch_count = cfg.get('launchCount', 0)
|
||||
launch_count += 1
|
||||
@ -345,10 +343,10 @@ class ClassicSubsystem(babase.AppSubsystem):
|
||||
self.coop_session_args[arg_name] = arg_val
|
||||
|
||||
def _fade_end() -> None:
|
||||
from bascenev1 import _coopsession
|
||||
from bascenev1 import CoopSession
|
||||
|
||||
try:
|
||||
bascenev1.new_host_session(_coopsession.CoopSession)
|
||||
bascenev1.new_host_session(CoopSession)
|
||||
except Exception:
|
||||
logging.exception('Error creating coopsession after fade end.')
|
||||
from bascenev1lib.mainmenu import MainMenuSession
|
||||
|
||||
@ -146,9 +146,10 @@ from bascenev1._profile import (
|
||||
get_player_profile_icon,
|
||||
get_player_profile_colors,
|
||||
)
|
||||
from bascenev1._campaign import init_campaigns
|
||||
from bascenev1._appmode import SceneV1AppMode
|
||||
from bascenev1._session import Session
|
||||
from bascenev1._map import Map
|
||||
from bascenev1._map import Map, register_map
|
||||
from bascenev1._coopsession import CoopSession
|
||||
from bascenev1._debug import print_live_object_warnings
|
||||
from bascenev1._multiteamsession import MultiTeamSession
|
||||
@ -410,6 +411,8 @@ __all__ = [
|
||||
'get_player_profile_icon',
|
||||
'get_player_profile_colors',
|
||||
'set_master_server_source',
|
||||
'init_campaigns',
|
||||
'register_map',
|
||||
]
|
||||
|
||||
# We want stuff here to show up as bascenev1.Foo instead of
|
||||
|
||||
@ -83,6 +83,9 @@ from babase import (
|
||||
is_browser_likely_available,
|
||||
)
|
||||
from _bauiv1 import (
|
||||
show_ad,
|
||||
show_ad_2,
|
||||
can_show_ad,
|
||||
show_online_score_ui,
|
||||
uibounds,
|
||||
set_party_window_open,
|
||||
@ -211,6 +214,9 @@ __all__ = [
|
||||
'AppIntentExec',
|
||||
'AppMode',
|
||||
'UIV1Subsystem',
|
||||
'show_ad',
|
||||
'show_ad_2',
|
||||
'can_show_ad',
|
||||
]
|
||||
|
||||
# We want stuff to show up as bauiv1.Foo instead of bauiv1._sub.Foo.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user